红联Linux门户
Linux帮助

由linux(4.4)切换linux(4.9),导致编译vmware内核模块vmnet出错

发布时间:2017-03-26 09:45:00来源:linux网站作者:whilst
印象中 Archlinux 下的 VMWare Workstation 总是出问题, 每次更新内核后可能需要重新编译 vmware 的内核模块, 并且可能会影响到 openconnect(VPN) 的使用, 因此只有在重启电脑前才更新内核, 其他情况下只更新应用程序:
yaourt -Syua --ignore linux* --noconfirm
 
内核由 linux-lts(4.4) 切换 linux(4.9), 导致编译 vmware 内核模块 vmnet 出错:
$ sudo vmware
Stopping VMware services:
VMware Authentication Daemon     done
VM communication interface socket family      done
Virtual machine communication interface      done
Virtual machine monitor      done
Blocking file system      done
make: 进入目录“/tmp/modconfig-8XIMI8/vmmon-only”
Using kernel build system.
/sbin/make -C /lib/modules/4.9.11-1-ARCH/build/include/.. SUBDIRS=$PWD SRCROOT=$PWD/. \
MODULEBUILDDIR= modules
make[1]: 进入目录“/usr/lib/modules/4.9.11-1-ARCH/build”
CC [M]  /tmp/modconfig-8XIMI8/vmmon-only/linux/driver.o
CC [M]  /tmp/modconfig-8XIMI8/vmmon-only/linux/hostif.o
CC [M]  /tmp/modconfig-8XIMI8/vmmon-only/linux/driverLog.o
CC [M]  /tmp/modconfig-8XIMI8/vmmon-only/common/memtrack.o
CC [M]  /tmp/modconfig-8XIMI8/vmmon-only/common/apic.o
CC [M]  /tmp/modconfig-8XIMI8/vmmon-only/common/vmx86.o
CC [M]  /tmp/modconfig-8XIMI8/vmmon-only/common/cpuid.o
/tmp/modconfig-8XIMI8/vmmon-only/linux/hostif.c: 在函数‘HostIFGetUserPages’中:
/tmp/modconfig-8XIMI8/vmmon-only/linux/hostif.c:1166:67: 错误:传递‘get_user_pages’的第 5 个参数时在不兼容的指针类型间转换 [-Werror=incompatible-pointer-types]
retval = get_user_pages((unsigned long)uvAddr, numPages, 0, 0, ppages, NULL);
^~~~~~
In file included from /tmp/modconfig-8XIMI8/vmmon-only/./include/compat_page.h:23:0,
from /tmp/modconfig-8XIMI8/vmmon-only/linux/hostif.c:32:
./include/linux/mm.h:1280:6: 附注:需要类型‘struct vm_area_struct **’,但实参的类型为‘struct page **’
long get_user_pages(unsigned long start, unsigned long nr_pages,
^~~~~~~~~~~~~~
/tmp/modconfig-8XIMI8/vmmon-only/linux/hostif.c:1166:13: 错误:提供给函数‘get_user_pages’的实参太多
retval = get_user_pages((unsigned long)uvAddr, numPages, 0, 0, ppages, NULL);
^~~~~~~~~~~~~~
In file included from /tmp/modconfig-8XIMI8/vmmon-only/./include/compat_page.h:23:0,
from /tmp/modconfig-8XIMI8/vmmon-only/linux/hostif.c:32:
./include/linux/mm.h:1280:6: 附注:在此声明
long get_user_pages(unsigned long start, unsigned long nr_pages,
^~~~~~~~~~~~~~
/tmp/modconfig-8XIMI8/vmmon-only/linux/driver.c:1283:1: 警告:always_inline function might not be inlinable [-Wattributes]
LinuxDriverSyncReadTSCs(uint64 *delta) // OUT: TSC max - TSC min
^~~~~~~~~~~~~~~~~~~~~~~
cc1:有些警告被当作是错误
make[2]: *** [scripts/Makefile.build:293:/tmp/modconfig-8XIMI8/vmmon-only/linux/hostif.o] 错误 1
make[2]: *** 正在等待未完成的任务....
make[1]: *** [Makefile:1490:_module_/tmp/modconfig-8XIMI8/vmmon-only] 错误 2
make[1]: 离开目录“/usr/lib/modules/4.9.11-1-ARCH/build”
make: *** [Makefile:120:vmmon.ko] 错误 2
make: 离开目录“/tmp/modconfig-8XIMI8/vmmon-only”
...
 
解决方案:
#!/bin/sh
cd /usr/lib/vmware/modules/source
tar xf vmmon.tar
mv vmmon.tar vmmon.old.tar
sed -r -i -e 's/KERNEL_VERSION\(4, 6, 0\)/KERNEL_VERSION\(4, 9, 0\)/g' vmmon-only/linux/hostif.c
sed -r -i -e 's/retval = get_user_pages\(\(unsigned long\)uvAddr, numPages, 0, 0, ppages, NULL\);/retval = get_user_pages\(\(unsigned long\)uvAddr, numPages, 0, ppages, NULL\);/g' vmmon-only/linux/hostif.c
tar cf vmmon.tar vmmon-only
rm -r vmmon-only
tar xf vmnet.tar
mv vmnet.tar vmnet.old.tar
sed -r -i -e 's/KERNEL_VERSION\(4, 6, 0\)/KERNEL_VERSION\(4, 9, 0\)/g' vmnet-only/userif.c
sed -r -i -e 's/retval = get_user_pages\(addr, 1, 1, 0, \&page, NULL\);/retval = get_user_pages\(addr, 1, 0, \&page, NULL\);/g' vmnet-only/userif.c
tar cf vmnet.tar vmnet-only
rm -r vmnet-only
 
本文永久更新地址:http://www.linuxdiyf.com/linux/29487.html