Skip to content

Commit

Permalink
misc: add Fedora/RHEL akmod support.
Browse files Browse the repository at this point in the history
Similar to mkubecek#214, add
akmod configuration/support to vmware-host-modules.

This will ensure Fedora users are able to get a fresh build of
vmware-host-modules each time the kernel updates.

Spec configuration and installation based on
https://github.com/Fred78290/nct6687d.

Installation for RPM:

```
make akmod
```

Test/Dev flow:

```
make clean
make akmod/clean && make akmod && sudo akmods
sudo systemctl start vmware.service
```

Applied fix for newer kernel:

mkubecek#239
  • Loading branch information
J-Pai committed Aug 15, 2024
1 parent 2c6d66f commit 40c8ec7
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.*.cmd
*.mod.c
*.tar
.tmp
.tmp_versions
.cache.mk
Module.symvers
Expand Down
39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ TARBALLS = $(MODULES:%=%.tar)
MODFILES = $(foreach mod,$(MODULES),$(mod)-only/$(mod).ko)
VM_UNAME = $(shell uname -r)
MODDIR = /lib/modules/$(VM_UNAME)/misc
CURPWD = $(shell pwd)
COMMITCOUNT = $(shell git rev-list --all --count)
COMMITHASH = $(shell git rev-parse --short HEAD)

MODINFO = /sbin/modinfo
DEPMOD = /sbin/depmod
Expand Down Expand Up @@ -45,5 +48,41 @@ install: retiredcheck $(MODFILES)
clean: $(SUBDIRS)
rm -f *.o

akmod/build:
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y rpmdevtools kmodtool
mkdir -p $(CURPWD)/.tmp/vmware-host-modules-1.0.${COMMITCOUNT}/vmware-host-modules
cp -r LICENSE Makefile vmmon-only vmnet-only $(CURPWD)/.tmp/vmware-host-modules-1.0.${COMMITCOUNT}/vmware-host-modules
cd .tmp && tar -czvf vmware-host-modules-1.0.${COMMITCOUNT}.tar.gz vmware-host-modules-1.0.${COMMITCOUNT} && cd -
mkdir -p $(CURPWD)/.tmp/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
cp $(CURPWD)/.tmp/vmware-host-modules-1.0.${COMMITCOUNT}.tar.gz $(CURPWD)/.tmp/rpmbuild/SOURCES/
echo 'vmware-host-modules' | tee $(CURPWD)/.tmp/rpmbuild/SOURCES/vmware-host-modules.conf
cp fedora/*.spec $(CURPWD)/.tmp/rpmbuild/SPECS/
sed -i "s/MAKEFILE_PKGVER/$(COMMITCOUNT)/g" $(CURPWD)/.tmp/rpmbuild/SPECS/*
sed -i "s/MAKEFILE_COMMITHASH/$(COMMITHASH)/g" $(CURPWD)/.tmp/rpmbuild/SPECS/*
rpmbuild -ba --define "_topdir $(CURPWD)/.tmp/rpmbuild" $(CURPWD)/.tmp/rpmbuild/SPECS/vmware-host-modules.spec
rpmbuild -ba --define "_topdir $(CURPWD)/.tmp/rpmbuild" $(CURPWD)/.tmp/rpmbuild/SPECS/vmware-host-modules-kmod.spec

akmod/install: akmod/build
sudo dnf install $(CURPWD)/.tmp/rpmbuild/RPMS/*/*.rpm

akmod/akmod-install: retiredcheck $(MODFILES)
@for f in $(MODFILES); do \
mver=$$($(MODINFO) -F vermagic $$f);\
mver=$${mver%% *};\
test "$${mver}" = "$(VM_UNAME)" \
|| ( echo "Version mismatch: module $$f $${mver}, kernel $(VM_UNAME)" ; exit 1 );\
done
mkdir -p $(KMOD_INSTALL_DIR)
install -D -m 755 $(MODFILES) $(KMOD_INSTALL_DIR)
strip --strip-debug $(MODULES:%=$(KMOD_INSTALL_DIR)/%.ko)
if test -z "$(KMOD_INSTALL_DIR)"; then $(DEPMOD) -a $(VM_UNAME); fi

akmod/clean:
sudo dnf remove vmware-host-modules
rm -rf .tmp

akmod: akmod/install

tarballs: $(TARBALLS)

57 changes: 57 additions & 0 deletions fedora/vmware-host-modules-kmod.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
%if 0%{?fedora}
%global buildforkernels akmod
%global debug_package %{nil}
%endif

%global prjname vmware-host-modules
%global pkgver MAKEFILE_PKGVER
%global commithash MAKEFILE_COMMITHASH
%define buildforkernels akmod

Name: %{prjname}-kmod
Version: 1.0.%{pkgver}
Release: git%{commithash}
Summary: Kernel module (kmod) for %{prjname}
License: GPL-2.0
URL: https://github.com/mkubecek/vmware-host-modules
Source0: vmware-host-modules-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-root-%(%{__id_u} -n)


BuildRequires: gcc
BuildRequires: make
BuildRequires: elfutils-libelf-devel
BuildRequires: kmodtool
Conflicts: vmware-host-modules-kmod-common

%{expand:%(kmodtool --target %{_target_cpu} --kmodname %{prjname} %{?buildforkernels:--%{buildforkernels}} %{?kernels:--for-kernels "%{?kernels}"} 2>/dev/null) }

%description
%{prjname} kernel module

%prep
kmodtool --target %{_target_cpu} --kmodname %{prjname} %{?buildforkernels:--%{buildforkernels}} %{?kernels:--for-kernels "%{?kernels}"} 2>/dev/null

%autosetup -n vmware-host-modules-%{version}

for kernel_version in %{?kernel_versions} ; do
cp -a vmware-host-modules _kmod_build_${kernel_version%%___*}
done

%build
for kernel_version in %{?kernel_versions}; do
make %{?_smp_mflags} -C "${PWD}/_kmod_build_${kernel_version%%___*}" M=${PWD}/_kmod_build_${kernel_version%%___*} \
VM_UNAME=${kernel_version%%___*}
done

%install
for kernel_version in %{?kernel_versions}; do
make %{?_smp_mflags} -C "${PWD}/_kmod_build_${kernel_version%%___*}" M=${PWD}/_kmod_build_${kernel_version%%___*} \
KMOD_INSTALL_DIR=%{buildroot}%{kmodinstdir_prefix}/${kernel_version%%___*}/%{kmodinstdir_postfix} \
VM_UNAME=${kernel_version%%___*} akmod/akmod-install
done
%{?akmod_install}

%changelog
* Sat Apr 20 2024 j-pai <[email protected]> - %{version}
- AKMOD Support
36 changes: 36 additions & 0 deletions fedora/vmware-host-modules.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
%global prjname vmware-host-modules
%global pkgver MAKEFILE_PKGVER
%global commithash MAKEFILE_COMMITHASH

Name: vmware-host-modules
Version: 1.0.%{pkgver}
Release: git%{commithash}
Summary: Kernel module (kmod) for %{prjname}
License: GPL-2.0
URL: https://github.com/mkubecek/vmware-host-modules
Source0: vmware-host-modules.conf

# For kmod package
Provides: %{name}-kmod-common = %{version}-%{release}
Requires: %{name}-kmod >= %{version}

BuildArch: noarch

%description
%{prjname} kernel module

%prep

%build
# Nothing to build

%install

install -D -m 0644 %{SOURCE0} %{buildroot}%{_modulesloaddir}/vmware-host-modules.conf

%files
%{_modulesloaddir}/vmware-host-modules.conf

%changelog
* Sat Apr 20 2024 j-pai <[email protected]> - %{version}
- AKMOD Support
7 changes: 6 additions & 1 deletion vmnet-only/vmnetInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@
compat_skb_set_network_header(skb, sizeof (struct ethhdr)), \
dev_queue_xmit(skb) \
)

#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 9, 0)
#define dev_lock_list() rcu_read_lock()
#define dev_unlock_list() rcu_read_unlock()
#else
#define dev_lock_list() read_lock(&dev_base_lock)
#define dev_unlock_list() read_unlock(&dev_base_lock)

#endif

extern struct proto vmnet_proto;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) || defined(sk_net_refcnt)
Expand Down

0 comments on commit 40c8ec7

Please sign in to comment.