]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
vmm: Make pmap_invalidate_ept() wait synchronously for guest exits
authorMark Johnston <markj@FreeBSD.org>
Wed, 11 Nov 2020 15:01:17 +0000 (15:01 +0000)
committerMark Johnston <markj@FreeBSD.org>
Wed, 11 Nov 2020 15:01:17 +0000 (15:01 +0000)
commit6f5a960678dd5330f71100ae379410199e97c665
tree9248f12b1410bc8ebb58d7416074c6e00c972fe7
parenta4848c103cc4bafe1fad5c902072e2ab5523543a
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
sys/amd64/amd64/pmap.c
sys/amd64/include/pmap.h
sys/amd64/vmm/amd/svm.c
sys/amd64/vmm/intel/vmx.c