--- a/vmmon/Makefile +++ b/vmmon/Makefile @@ -43,7 +43,11 @@ endif +ifdef KVERSION +VM_UNAME = $(KVERSION) +else VM_UNAME = $(shell uname -r) +endif # Header directory for the running kernel ifdef LINUXINCLUDE From 4c2a103fd2d71f2084f1fe7ceacb816b9832ffa2 Mon Sep 17 00:00:00 2001 From: Michal Kubecek Date: Sun, 22 Oct 2023 23:24:05 +0200 Subject: [PATCH] vmmon: use get_user_pages to get page PFN As a side effect of mainline commit 0d940a9b270b ("mm/pgtable: allow pte_offset_map[_lock]() to fail") in 6.5-rc1, __pte_offset_map(), called by pte_offset_map(), is no longer exported. WMware developers decided to hack around this by replacing pte_offset_map() by pte_offset_kernel() which does not seem to be a good idea and apparently may trigger warn checks in RCU code on some systems as mentioned in the discussion on issue #223. Therefore let's use the same solution as we had for 17.0.2 and older versions as it does not show these problems. Based on an upstream IRC discussion and the hva_to_pfn_*() family of functions in KVM code, what PgtblVa2MPNLocked() does seems to be an incomplete and partial open coded logic of get_user_pages() and as it is only used to get PFN from a virtual address, it can be easily implemented using get_user_pages() family. Without knowledge what exactly are the PFNs used for in VMware, it is hard to guess the right flags, these seem to work and have been tested by multiple users over last few weeks. We could likely use get_user_pages() also on older kernels and it might be actually cleaner and more reliable as existing open coded implementation does not seem to handle some corner cases but without knowledge of VMware internals, it will be safer to stick to existing code where possible. --- vmmon-only/include/pgtbl.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/vmmon-only/include/pgtbl.h b/vmmon-only/include/pgtbl.h index 3f43c62..7eaa49a 100644 --- a/vmmon-only/include/pgtbl.h +++ b/vmmon-only/include/pgtbl.h @@ -25,6 +25,7 @@ #include "compat_pgtable.h" #include "compat_spinlock.h" #include "compat_page.h" +#include "compat_version.h" /* @@ -45,6 +46,7 @@ *----------------------------------------------------------------------------- */ +#if COMPAT_LINUX_VERSION_CHECK_LT(6, 5, 0) // only used by PgtblVa2MPN() below static INLINE MPN PgtblVa2MPNLocked(struct mm_struct *mm, // IN: Mm structure of a process VA addr) // IN: Address in the virtual address @@ -106,6 +108,7 @@ PgtblVa2MPNLocked(struct mm_struct *mm, // IN: Mm structure of a process } return mpn; } +#endif /* @@ -125,6 +128,8 @@ PgtblVa2MPNLocked(struct mm_struct *mm, // IN: Mm structure of a process *----------------------------------------------------------------------------- */ +#if COMPAT_LINUX_VERSION_CHECK_LT(6, 5, 0) + static INLINE MPN PgtblVa2MPN(VA addr) // IN { @@ -139,4 +144,24 @@ PgtblVa2MPN(VA addr) // IN return mpn; } +#else /* COMPAT_LINUX_VERSION_CHECK_LT(6, 5, 0) */ + +static INLINE MPN +PgtblVa2MPN(VA addr) // IN +{ + struct page *page; + int npages; + MPN mpn; + + npages = get_user_pages_unlocked(addr, 1, &page, FOLL_HWPOISON); + if (npages != 1) + return INVALID_MPN; + mpn = page_to_pfn(page); + put_page(page); + + return mpn; +} + +#endif /* COMPAT_LINUX_VERSION_CHECK_LT(6, 5, 0) */ + #endif /* __PGTBL_H__ */ From 2c6d66f3f1947384038b765c897b102ecdb18298 Mon Sep 17 00:00:00 2001 From: Michal Kubecek Date: Fri, 12 Jan 2024 08:30:33 +0100 Subject: [PATCH] modules: fix build with -Wmissing-prototypes Mainline commit 0fcb70851fbf ("Makefile.extrawarn: turn on missing-prototypes globally") in 6.8-rc1 enables -Wmissing-prototypes globally, revealing a lot of unclean code and also some actual problems. This is also the case in vmmon and vmnet modules. Most of them are addressed by making functions used only within one file static. The missing prototype of random_get_entropy_fallback() is handled by including rather than . Finally, there are four functions in vmnet module which are actually used in multiple files but instead of proper declarations, their prototype is duplicated in vmnet-only/driver.c, risking that the two copies won't match (which actually happened in one case). The cleanest solution would be creating separate header files for them (bridge.h, netif.h, userif.h and vnetUserListener.h) and including them in the respective source file and driver.c. As the developers already handle similar cases by simply putting the declarations into vnetInt.h, let us do the same to keep things simple. --- vmmon-only/common/task.c | 2 +- vmmon-only/common/vmx86.c | 6 +++--- vmmon-only/linux/driver.c | 4 ++-- vmmon-only/linux/hostif.c | 6 +++--- vmnet-only/bridge.c | 2 +- vmnet-only/driver.c | 16 ++-------------- vmnet-only/vnetInt.h | 7 +++++++ 7 files changed, 19 insertions(+), 24 deletions(-) diff --git a/vmmon-only/common/task.c b/vmmon-only/common/task.c index 5d34cf4d..f3752069 100644 --- a/vmmon-only/common/task.c +++ b/vmmon-only/common/task.c @@ -544,7 +544,7 @@ Task_Terminate(void) *----------------------------------------------------------------------------- */ -Selector +static Selector TaskGetFlatWriteableDataSegment(void) { DTR hostGDTR; diff --git a/vmmon-only/common/vmx86.c b/vmmon-only/common/vmx86.c index 86e52fb4..cf64b123 100644 --- a/vmmon-only/common/vmx86.c +++ b/vmmon-only/common/vmx86.c @@ -49,7 +49,7 @@ #include "x86svm.h" #include "x86cpuid_asm.h" #if defined(__linux__) -#include +#include #endif #include "perfctr.h" #include "x86vtinstr.h" @@ -696,7 +696,7 @@ Vmx86FreeCrossPages(VMDriver *vm) *----------------------------------------------------------------------------- */ -void +static void Vmx86FreeVMDriver(VMDriver *vm) { Vmx86_Free(vm->ptRootMpns); @@ -729,7 +729,7 @@ Vmx86FreeVMDriver(VMDriver *vm) *----------------------------------------------------------------------------- */ -VMDriver * +static VMDriver * Vmx86AllocVMDriver(uint32 numVCPUs) { VMDriver *vm = Vmx86_Calloc(1, sizeof *vm, TRUE); diff --git a/vmmon-only/linux/driver.c b/vmmon-only/linux/driver.c index 3d8b7228..ab8e2dc4 100644 --- a/vmmon-only/linux/driver.c +++ b/vmmon-only/linux/driver.c @@ -267,7 +267,7 @@ LinuxDriverInitTSCkHz(void) *---------------------------------------------------------------------- */ -int +static int LinuxDriverInit(void) { int retval; @@ -335,7 +335,7 @@ LinuxDriverInit(void) *---------------------------------------------------------------------- */ -void +static void LinuxDriverExit(void) { /* diff --git a/vmmon-only/linux/hostif.c b/vmmon-only/linux/hostif.c index 5d08f33a..c1e6c671 100644 --- a/vmmon-only/linux/hostif.c +++ b/vmmon-only/linux/hostif.c @@ -2922,7 +2922,7 @@ HostIF_CallOnEachCPU(void (*func)(void*), // IN: function to call *----------------------------------------------------------------------------- */ -Bool +static Bool HostIFCheckTrackedMPN(VMDriver *vm, // IN: The VM instance MPN mpn) // IN: The MPN { @@ -3042,7 +3042,7 @@ HostIF_ReadPhysical(VMDriver *vm, // IN: The VM instance *---------------------------------------------------------------------- */ -int +static int HostIFWritePhysicalWork(MA ma, // MA to be written to VA64 addr, // src data to write Bool kernelBuffer, // is the buffer in kernel space? @@ -3201,7 +3201,7 @@ HostIF_GetCurrentPCPU(void) *---------------------------------------------------------------------- */ -int +static int HostIFStartTimer(Bool rateChanged, //IN: Did rate change? unsigned int rate) //IN: current clock rate { Fix from https://communities.vmware.com/t5/VMware-Workstation-Pro/Workstation-17-5-0-vmware-clk-spinning-on-CPU-when-Linux-VMs-are/m-p/2996282 --- a/vmmon-only/linux/hostif.c +++ b/vmmon-only/linux/hostif.c @@ -3350,7 +3350,7 @@ * threads running in the monitor on all physical CPUs. */ - if (rate > MIN_RATE) { + if (false) { if (!linuxState.fastClockThread) { struct task_struct *rtcTask;