Compare commits

..
Author SHA1 Message Date
Michal Kubecek b2de0cb3b0 vmmon: avoid using alloc_vm_area() for crosspage allocation
Mainline commit 301fa9f2ddf7 ("mm: remove alloc_vm_area") in v5.10-rc1
removed alloc_vm_area() function used to allow allocating crosspage as
executable after vmap() started silently setting NX flag in kernel 5.8.

Similar to what upstream did in Xen code, use apply_to_page_range() to fix
the crosspage flags, except we don't need to use get_vm_area() which is not
exported. Thanks to virtualbox for the hint that current->mm can be used
instead of init_mm (which is not exported either).
2020-12-09 11:20:45 +01:00
Michal Kubecek 6af30addc0 vmmon: avoid kernel writes to eventfd
Starting with mainline commit 4d03e3cc5982 ("fs: don't allow kernel reads
and writes without iter ops") in 5.10-rc1, kernel writes are only allowed
for files providing ->write_iter() callback which eventfd does not.

As an attempt to address this issue on kernel side by providing
->write_iter() callback to eventfd was met with a pushback and it is
unlikely to be accepted any time soon, let's use a specific eventfd
interface eventfd_signal() instead. However, as the comments in
HostIF_SemaphoreSignal() indicate that the file descriptor may also be
a pipe (without telling when), let's keep kernel_write() as a fallback in
case the file descriptor is not eventfd.
2020-12-09 11:20:45 +01:00
Michal Kubecek 958895c49e vmmon: avoid set_fs() in HostIFFastClockThread()
The set_fs() function was dropped on x86_64 architecture by commit
47058bb54b57 ("x86: remove address space overrides using set_fs()") in
5.10-rc1. The only purpose of set_fs(KERNEL_DS) in HostIFFastClockThread()
seems to be to allow using ->read() file operation on /dev/rtc device.
There is also ioctl() but neither of the two (RTC_IRQP_SET and RTC_PIE_ON)
interprets its argument as a (user) pointer: RTC_IRQP_SET interprets it as
unsigned long, RTC_PIE_ON ignores it.

Replace the direct call to ->read() file op with kernel_read() wrapper
like we did/do in other places and drop the temporary set_fs(KERNEL_DS)
trick as it doesn't seem to be needed any more.
2020-12-09 11:20:45 +01:00
Michal Kubecek 4bd2fa1cbf vmmon: avoid set_fs() in isVAReadable()
The set_fs() function was dropped on x86_64 architecture by commit
47058bb54b57 ("x86: remove address space overrides using set_fs()") in
5.10-rc1. In isVAReadable() it is used to check if a kernel address can be
read from without risking a pagefault if the answer is negative by using
set_fs() to pretend it's a userspace address and checking with
copy_from_user(). Starting with 5.8, copy_from_kernel_nofault() does can be
used to copy from a kernel address with access check but without an actual
pagefault.
2020-12-09 11:20:45 +01:00
Michal Kubecek 1b40eae1af vmmon: avoid set_fs() in HostIF_SemaphoreWait() and HostIF_SemaphoreSignal()
The set_fs() function was dropped on x86_64 architecture by commit
47058bb54b57 ("x86: remove address space overrides using set_fs()") in
5.10-rc1. In HostIF_SemaphoreWait() it is used to allow calling read() file
op on a kernel pointer, in HostIF_SemaphoreSignal() to allow calling
write() file op on a kernel pointer. This is only the case for pre-5.8
kernels as we need to use kernel_read() and kernel_write() helpers on 5.8
and newer anyway.

Use kernel_read() and kernel_write() always, like Workstation 16.0.0 does,
so that we no longer need the set_fs(KERNEL_DS) trick. Make the code of
both functions look exactly like in Workstation 16.0.0 to make future
backports easier.
2020-12-09 11:20:45 +01:00
Michal Kubecek 44c7e02bc1 vmnet: use new compat_csum_and_copy_to_user() calling convention
Part of bigger csum_and_copy rework, commit c693cc4676a0 ("saner calling
conventions for csum_and_copy_..._user()") in 5.10-rc1 drops last two
arguments and changes the way errors are reported.

Provide a compat wrapper with new calling convention and rewrite callers in
vmnet to use it. Unfortunately there doesn't seem to be a way to recognize
which calling convention kernel has so version check is used.
2020-12-09 11:20:45 +01:00
Jan Andres 0ea341be15 Fix NULL pointer dereference in eventfd read call
Starting with commit 12aceb89b0bc ("eventfd: convert to f_op->read_iter()")
in 5.8-rc1, the "read" function pointer in eventfd's file_operations is
NULL, "read_iter" is available instead.

Use kernel_read() and kernel_write() instead of directly calling the
function pointers to handle this correctly. We can do that safely for
kernel 4.14 and newer (older versions have different arguments of
kernel_read() and kernel_write()).
2020-09-19 22:09:19 +02:00
Jan Andres 2252a21e80 Fix NX bit handling for Linux 5.8+
Do not use vmap() to map the cross page, it needs to be executable and
vmap() unconditionally sets the NX bit starting with commit cca98e9f8b5e
("mm: enforce that vmap can't map pages executable") in 5.8-rc1.

Emulate previous behavior of vmap() by using alloc_vm_area() and
explicitly setting the PTE.
2020-09-19 22:09:19 +02:00
Michal Kubecek 20c8c330ba vmmon: include <asm/irq_vectors.h> explicitly
After mainline commit 13c01139b171 ("x86/headers: Remove APIC headers from
<asm/smp.h>") in 5.9-rc1, APIC headers are no longer included via
<asm/smp.h> so that linux/hostif.c will lack the definition of
SPURIOUS_APIC_VECTOR.

Include <asm/irq_vectors.h> in linux/hostif.c explicitly to avoid that.

Note: unlike newer versions, Workstation 12.5.9 does not really need this
include as <asm/irq_vectors.h> is included via other kernel header files
but that might change if some more headers cleanup are done in mainline so
better include it here explicitly as well.
2020-08-20 12:11:58 +02:00
Michal Kubecek 3f5c9d694b vmmon: handle change of vmstat slab counters to bytes
Mainline commit d42f3245c7e2 ("mm: memcg: convert vmstat slab counters to
bytes") in kernel 5.9-rc1 changed vmstat accounting of slab to byte
counters. Unfortunately there doesn't seem to be any obvious way to check
for this change except version check.
2020-08-20 12:11:58 +02:00
Michal Kubecek 5d3d9347f4 modules: adapt to new mmap locking API
In 5.8-rc1, mmap locking was reworked to use wrappers around mmap_sem
(which was also renamed to mmap_lock). All code is now supposed to use
these wrappers as the internal implementation of the lock may change in
the future.

Add the wrappers to older kernels to keep the conditionals out of regular
code.
2020-06-12 11:15:02 +02:00
Michal Kubecek f4f6964c1f vmmon: get rid of do_gettimeofday() in linux/driver.c
The do_gettimeofday() helper was removed by commit e4b92b108c6c
("timekeeping: remove obsolete time accessors") in v5.0-rc1 and commit
c766d1472c70 ("y2038: hide timeval/timespec/itimerval/itimerspec types")
in v5.6-rc3 hides struct timeval from kernel code.

Replace the use of do_gettimeofday() and struct timeval in linux/driver.c.
While ktime_get_real_ns() would match do_gettimeofday() better, monotonic
timer seems more appropriate for poll timeouts so use ktime_get_ns()
instead.
2020-02-24 11:08:26 +01:00
Michal Kubecek c2ffc6093b vmmon: clean up the uptime handling
The do_gettimeofday() helper was removed by commit e4b92b108c6c
("timekeeping: remove obsolete time accessors") in v5.0-rc1 and commit
c766d1472c70 ("y2038: hide timeval/timespec/itimerval/itimerspec types") in
v5.6-rc3 hides struct timeval from kernel code.

Rather than copying what newer 15.5.x versions do, clean up the whole mess
of simultaneous crosschecking between jiffies and wall time. Apparently
this was introduced once to work around the absence of a high resolution
monotonic timer. As kernel provides one at least since version 2.6.17 and
64-bit interface for it since 3.17 and VMware is unlikely to ever release
any update for Workstation/Player 14.1.x or 12.5.x anyway, let's just drop
all of it and use ktime_get_ns() instead.
2020-02-24 11:08:26 +01:00
Michal Kubecek 093dd4fc3c vmnet: convert VNetBridge debugging code to ktime_get_ns()
The do_gettimeofday() helper was removed by commit e4b92b108c6c
("timekeeping: remove obsolete time accessors") in v5.0-rc1 and commit
c766d1472c70 ("y2038: hide timeval/timespec/itimerval/itimerspec types") in
v5.6-rc3 hides struct timeval from kernel code.

Convert the do_gettimeofday() relics in VNetBridge (which are only compiled
with LOGLEVEL >= 4) completely to ktime based interface.
2020-02-24 11:08:26 +01:00
Michal Kubecek b24f99bc14 vmnet: convert from file_operations to proc_ops
Manline commit 97a32539b956 ("proc: convert everything to "struct
proc_ops"") in v5.6-rc1 introduces struct proc_ops and converts procfs file
operations to it. Convert vmnet to do the same.

As the same commit also introduces DEFINE_PROC_SHOW_ATTRIBUTE macro, we can
use it for detection rather than rely on version comparison.
2020-02-10 07:12:11 +01:00
Michal Kubecek d1c9f72082 vmmon: replace ioremap_nocache() with ioremap()
Mainline commit 4bdc0d676a64 ("remove ioremap_nocache and
devm_ioremap_nocache") in v5.6-rc1 removes ioremap_nocache() and replaces
all uses with ioremap(). As the commit message says that "ioremap has
provided non-cached semantics by default since the Linux 2.6", do the same
unconditionally.
2020-02-10 07:12:11 +01:00
Michal Kubecek 18c2fe502a vmnet: work around skb_frag_t build failure for SLE15-SP2 and openSUSE-15.2
The kernels used in (upcoming) SLE15 SP2 and openSUSE Leap 15.2 are based
on upstream version 5.3 but have a backport of the skb_frag_t conversion to
bio_vec which reached mainline in v5.4-rc1. As we cannot easily check
availability compat_skb_frag_off() (which was also added in v5.4-rc1) and
have to resort to version check, add an exception for SLE15-SP2 and
openSUSE-15.2 kernels.
2019-11-25 08:25:50 +01:00
Michal Kubecek 7329228887 vmnet: handle switch of skb_frag_t to bio_vec
The switch from custom skb_frag_t implementation to bio_vec in v5.4-rc1 is
mostly transparent for modules which use accessor for skb_frag_t members.
Unfortunately many users access the members directly and function
VNetCsumCopyDatagram() in vmnet is one of those.

Use accessors everywhere so that vmnet code is compatible with kernel 5.4
and newer. Use "compat_" prefix to avoid clashes with backports adding the
accessors to older codebase.
2019-09-30 21:33:56 +02:00
Michal Kubecek 9f39254000 Merge branch 'master' into player-12.5.9 2019-09-09 08:42:55 +02:00
Michal Kubecek 4f3ac281ee vmmon: mark expected switch fall through
Since v5.3-rc2, kernel is built with -Wimplicit-fallthrough by default
so that compiler warns about switch fall thgrough unless it is marked as
expected. Add comment to mark one existing fall through as expected.

Note: this function is no longer present in 15.1.0 and it is probably
dead code anyway as hash2() is only called from HashFunc_HashPage()
which does not seem to be called anywhere. But to keep the code as close
to upstream as reasonably possible, just mark the fall through and keep
both functions in place.
2019-07-31 13:59:39 +02:00
Michal Kubecek 5ecf2faaa6 vmmon: fix HostIF_SetFastClockRate() not to use force_sig()
Commit 3cf5d076fb4d ("signal: Remove task parameter from force_sig") in
v5.3-rc1 drops second argument of force_sig(); before that, all callers
which passed something else than current task as second argument were
fixed, mostly to use send_sig() instead.

The situation in HostIF_SetFastClockRate() is the same as e.g. in bpfilter
call fixed by commit 1dfd1711de29 ("signal/bpfilter: Fix bpfilter_kernl to
use send_sig not force_sig"): locking in force_sig_info() cannot handle
task exiting and using force_sig() for SIGKILL is pointless anyway as this
signal cannot be blocked.

As send_sig() is present with unchanged signature since the pre-git era, we
can use send_sig() unconditionally, regardless of kernel version.
2019-07-22 06:57:54 +02:00
Michal Kubecek 48812705d7 vmmon: fix return type of vm_operations_struct::fault handler
Commit 3d3539018d2c ("mm: create the new vm_fault_t type") in mainline
5.1-rc1 changed the definition of vm_fault_t type to unsigned to catch
vm_operations_struct::fault handlers which still have int as return value.
LinuxDriverFault() in vmmon module is one of those.

As handler return type was changed by commit 1c8f422059ae ("mm: change
return type to vm_fault_t") in 4.17-rc1, make LinuxDriverFault() always
return vm_fault_t and define vm_fault_t as int when building against
a pre-4.17 kernel. (Except for the branch for really old kernels where
the handler was vm_operations_struct::nopage and returned a pointer to
struct page.)
2019-03-17 21:48:09 +01:00
Michal Kubecek c43ae31438 vmmon: use KERNEL_DS rather than get_ds()
Commit 736706bee329 ("get rid of legacy 'get_ds()' function") in v5.1-rc1
removed get_ds() helper. As this helper always returned KERNEL_DS on x86_64
since the architecture was introduced (and even on i386, it did so since
v2.1.0), simply use KERNEL_DS regardless of kernel version.
2019-03-17 21:48:09 +01:00
Michal Kubecek 6a5ae5be25 modules: handle access_ok() with two arguments
Since commit 96d4f267e40f ("Remove 'type' argument from access_ok()
function") in v5.0-rc1, the type argument of access_ok() was dropped.
The same commit also dropped macros VERIFY_READ and VERIFY_WRITE so check
for their existence on pre-5.0 kernels to allow build against kernels with
this change backported.
2019-01-07 13:55:34 +01:00
Michal Kubecek 688ba2efb3 vmmon: bring back the do_gettimeofday() helper
The do_gettimeofday() helper was removed by commit e4b92b108c6c
("timekeeping: remove obsolete time accessors") in v5.0-rc1. Bring it back
for users in vmmon-only/linux/hostif.c.

This feels like a quick and clumsy band aid to allow build with post-4.20
kernels. On a closer look, the whole gymnastics around uptimeState and
HostIFReadUptimeWork() with jiffies and wall time checking and correcting
each other seems to be a workaround for an absence of high resolution
monotonic time. Considering ktime_get_ts64() is available since 3.17 and
before that, ktime_get_ts() since 2.6.17, perhaps the time has come to
clean all this machinery up. But something like this would be beyond the
scope of this repository.
2019-01-07 13:55:34 +01:00
Michal Kubecek 95fa769616 vmmon: totalram_pages is a function since 5.0
Since commit ca79b0c211af ("mm: convert totalram_pages and totalhigh_pages
variables to atomic") in v5.0-rc1, totalram_pages() is an accessor function
and the actual variable is an atomic.
2019-01-07 13:55:34 +01:00
Michal Kubecek 8a9708499f modules: replace SUBDIRS with M
Since commit 0126be38d988 ("kbuild: announce removal of SUBDIRS if used")
in v5.0-rc1, using SUBDIRS when building out of tree modules produces
a deprecation warning. As M used to work since pretty much ever, use it
unconditionally.
2019-01-07 13:55:34 +01:00
Michal Kubecek aad370a5e2 vmmon: compatibility with eventpoll switch to poll_mask()
Since commit 11c5ad0ec441 ("eventpoll: switch to ->poll_mask") in
v4.18-rc1, eventpoll switched from ->poll() to ->poll_mask(). Rather than
calling the callback directly (which would result in null pointer
dereference), use vfs_poll() wrapper. As this wrapper is only available
since 4.18-rc1 cycle as well, provide a copy to use when building against
older kernels.
2018-06-17 15:57:46 +02:00
Michal Kubecek 5923003b57 Merge branch 'master' into player-12.5.9 2018-05-27 16:13:44 +02:00
Theo Bertacchini f6af9290e7 modules: remove .cache.mk on make clean
Remove .cache.mk inside vmmon-only and vmnet-only when executing
"make clean". This file can cause issues when upgrading gcc as make will
still look for includes inside older gcc includes directory.

File .cache.mk with cache of generated variables is created by build since
kernel v4.15-rc1, commit 3298b690b21c ("kbuild: Add a cache for generated
variables").
2018-05-27 16:07:00 +02:00
Michal Kubecek f9b614fbf9 Merge branch 'master' into player-12.5.9 2018-04-02 15:37:24 +02:00
Michal Kubecek b7b47d354b vmmon: fix indirect call with retpoline build
Build against kernel with retpoline support issues warning

  objtool: Task_Switch()+0x425: indirect call found in RETPOLINE build

This is because an indirect call in TaskSwitchToMonitor() is encoded using
inline assembler so that it bypasses retpoline generation. For this
purpose, macro CALL_NOSPEC exists since v4.15-rc8 (and has been backported
into some distribution kernels with the rest of retpoline support). Use the
macro if available and fallback to the original code if not.
2018-03-26 14:30:57 +02:00
Michal Kubecek 1eea8af1f8 vmmon: fix always_inline attribute usage
Function declared with __attribute__((always_inline)) should also be
declared as inline, otherwise gcc issues a warning "always_inline function
might not be inlinable". It's just cosmetic but getting rid of known
harmless warnings makes it easier to spot actual problems. Use the
__always_inline macro for LinuxDriverSyncReadTSCs() as this is how always
inline functions should be declared in kernel code.
2018-03-22 13:50:21 +01:00
Michal Kubecek a11ba8d6c6 vmmon: use standard definition of MSR_K7_HWCR_SMMLOCK if available
The MSR_K7_HWCR_SMMLOCK macro is defined in mainline since commit
18c71ce9c882 ("x86/CPU/AMD: Add the Secure Encrypted Virtualization CPU
feature") in v4.16-rc1.
2018-02-11 01:24:55 +01:00
Michal Kubecek d907ced352 Merge branch 'master' into player-12.5.9 2018-02-04 21:50:45 +01:00
Michal Kubecek 1497314820 vmmon: convert timers to use timer_setup()
With version 4.15-rc1, conversion to new timer interface is finished and
old interface using init_timer() is no longer available. Convert all users
to new one.
2018-01-18 08:25:44 +01:00
Michal Kubecek 446f5092d7 vmmon: quick workaround for objtool warnings
As discussed in

  https://bugzilla.suse.com/show_bug.cgi?id=1059674

the reason for multiple objtool warnings is the fact that vmmon module
defines its own Panic() function which never returns. While it is marked as
such which is used by the compiler for optimization, there is no way to
find this from object file.

While this seems innocuous, it might result in problems with unwinder
later. The quickest way around is to replace vmmon's own Panic() with
standard kernel panic() until a cleaner solution is found.
2018-01-18 08:25:44 +01:00
Michal Kubecek 7af65d06e9 vmmon: fix page accounting
global_page_state() was renamed to global_zone_page_state() by commit
c41f012ade0b ("mm: rename global_page_state to global_zone_page_state").
However, some more changes are needed (and were in fact needed even with
kernels older than 4.14.

Since commit 385386cff4c6 ("mm: vmstat: move slab statistics from zone to
node counters") in v4.13-rc1, NR_SLAB_UNRECLAIMABLE needs to be used with
global_node_page_state(), in-tree callers were fixed by commit d507e2ebd2c7
("mm: fix global NR_SLAB_.*CLAIMABLE counter reads").

Since commit 599d0c954f91 ("mm, vmscan: move LRU lists to node") in
v4.8-rc1, NR_UNEVICTABLE needs global_node_page_state() rather than
global_page_state().

Since commit 50658e2e04c1 ("mm: move page mapped accounting to the node")
in v4.8-rc1, NR_ANON_PAGES needs global_node_page_state() as well. This was
shortly before it was renamed to NR_ANON_MAPPED but as both got into
mainline in v4.8-rc1, we can do with one #ifdef.

To keep HostIF_EstimateLockedPageLimit() readable, extract the version
dependent calls into inline helpers.
2018-01-18 08:25:44 +01:00
Michal Kubecek b09b058b57 vmmon: use standard definition of CR3_PCID_MASK if available
The CR3_PCID_MASK is defined in mainline asm/processor-flags.h since
commit 6c690ee1039b ("x86/mm: Split read_cr3() into read_cr3_pa() and
__read_cr3()") in v4.13-rc1.
2018-01-18 08:25:44 +01:00
Michal Kubecek 383dbae078 vmnet: do not open code skb_get()
With commit 633547973ffc ("net: convert sk_buff.users from atomic_t to
refcount_t") in v4.13-rc1, sk_buff::users changed its type from atomic_t
to refcount_t. Use skb_get() to increment the counter as that's going to
work on both old and new kernels.
2018-01-18 08:25:44 +01:00
Michal Kubecek 8a6a4706e7 vmmon: use standard definition of MSR_MISC_FEATURES_ENABLES if available
The MSR_MISC_FEATURES_ENABLES macro is defined in mainline since commit
ab6d9468631a ("x86/msr: Rename MISC_FEATURE_ENABLES to
MISC_FEATURES_ENABLES") in v4.12-rc1.

The MSR_MISC_FEATURES_ENABLES_CPUID_FAULT macro is defined in mainline
since commit e9ea1e7f53b8 ("x86/arch_prctl: Add ARCH_[GET|SET]_CPUID") in
v4.12-rc1.
2018-01-18 08:25:44 +01:00
Michal Kubecek 666525a919 vmnet: use standard definition of PCI_VENDOR_ID_VMWARE_VMXNET3 if available
The PCI_DEVICE_ID_VMWARE_VMXNET3 macro is defined in mainline pci_ids.h
since commit b1226c7db1d9 ("vmxnet3: Move PCI Id to pci_ids.h") in
v4.10-rc1.
2018-01-18 08:25:44 +01:00
Michal Kubecek b5aff64550 vmnet: use standard definition of PCI_VENDOR_ID_VMWARE if available
The PCI_VENDOR_ID_VMWARE macro is defined in mainline pci_ids.h since
commit 94e57fea6202 ("PCI: Move PCI_VENDOR_ID_VMWARE to pci_ids.h")
in v3.18-rc1.
2018-01-18 08:25:44 +01:00
Michal Kubecek 3635eff81d import Player 12.5.9 module sources 2018-01-18 07:42:13 +01:00
Michal Kubecek 84f16afb1f import Player 12.5.8 module sources 2017-11-18 00:21:40 +01:00
Michal Kubecek 027dd56418 import Player 12.5.7 module sources 2017-06-30 19:11:22 +02:00
Michal Kubecek 0e634ffbf1 import Player 12.5.6 module sources 2017-05-31 10:06:51 +02:00
Michal Kubecek c62c78e908 import Player 12.5.5 module sources 2017-05-31 09:20:00 +02:00
Michal Kubecek 4f648692e4 import Player 12.5.2 module sources 2017-05-31 09:19:26 +02:00

Diff Content Not Available