freebsd-dev/sys/amd64/vmm/amd
Mark Johnston 6f5a960678 vmm: Make pmap_invalidate_ept() wait synchronously for guest exits
Currently EPT TLB invalidation is done by incrementing a generation
counter and issuing an IPI to all CPUs currently running vCPU threads.
The VMM inner loop caches the most recently observed generation on each
host CPU and invalidates TLB entries before executing the VM if the
cached generation number is not the most recent value.
pmap_invalidate_ept() issues IPIs to force each vCPU to stop executing
guest instructions and reload the generation number.  However, it does
not actually wait for vCPUs to exit, potentially creating a window where
guests may continue to reference stale TLB entries.

Fix the problem by bracketing guest execution with an SMR read section
which is entered before loading the invalidation generation.  Then,
pmap_invalidate_ept() increments the current write sequence before
loading pm_active and sending IPIs, and polls readers to ensure that all
vCPUs potentially operating with stale TLB entries have exited before
pmap_invalidate_ept() returns.

Also ensure that unsynchronized loads of the generation counter are
wrapped with atomic(9), and stop (inconsistently) updating the
invalidation counter and pm_active bitmask with acquire semantics.

Reviewed by:	grehan, kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D26910
2020-11-11 15:01:17 +00:00
..
amdv.c sys/amd64: further adoption of SPDX licensing ID tags. 2017-11-27 15:03:07 +00:00
amdvi_hw.c amd64: clean up empty lines in .c and .h files 2020-09-01 21:16:54 +00:00
amdvi_priv.h Remove svn:executable from a couple of vmm(4) source files. 2020-10-01 22:20:29 +00:00
ivrs_drv.c Remove svn:executable from a couple of vmm(4) source files. 2020-10-01 22:20:29 +00:00
npt.c amd64: clean up empty lines in .c and .h files 2020-09-01 21:16:54 +00:00
npt.h Add SPDX tags to vmm(4). 2018-06-13 07:02:58 +00:00
svm_genassym.c Add SPDX tags to vmm(4). 2018-06-13 07:02:58 +00:00
svm_msr.c Initial support for bhyve save and restore. 2020-05-05 00:02:04 +00:00
svm_msr.h Add SPDX tags to vmm(4). 2018-06-13 07:02:58 +00:00
svm_softc.h Add SPDX tags to vmm(4). 2018-06-13 07:02:58 +00:00
svm_support.S Add SPDX tags to vmm(4). 2018-06-13 07:02:58 +00:00
svm.c vmm: Make pmap_invalidate_ept() wait synchronously for guest exits 2020-11-11 15:01:17 +00:00
svm.h Initial support for bhyve save and restore. 2020-05-05 00:02:04 +00:00
vmcb.c Use vmcb_read/write for the vmcb snapshot functions. 2020-09-10 22:22:23 +00:00
vmcb.h bhyve: intercept AMD SVM instructions. 2020-09-15 20:22:50 +00:00