]> git.baikalelectronics.ru Git - kernel.git/commit
kvm: x86: mmu: Always flush TLBs when enabling dirty logging
authorJunaid Shahid <junaids@google.com>
Wed, 10 Aug 2022 22:49:39 +0000 (15:49 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 19 Aug 2022 11:38:03 +0000 (07:38 -0400)
commit599bc67087dd349445b8be214c0ca868837160d5
tree671bb2795093290203d8473e28a900967525712b
parent685d76e9fdb07f1054fd9d665e1b6f8450093b9f
kvm: x86: mmu: Always flush TLBs when enabling dirty logging

When A/D bits are not available, KVM uses a software access tracking
mechanism, which involves making the SPTEs inaccessible. However,
the clear_young() MMU notifier does not flush TLBs. So it is possible
that there may still be stale, potentially writable, TLB entries.
This is usually fine, but can be problematic when enabling dirty
logging, because it currently only does a TLB flush if any SPTEs were
modified. But if all SPTEs are in access-tracked state, then there
won't be a TLB flush, which means that the guest could still possibly
write to memory and not have it reflected in the dirty bitmap.

So just unconditionally flush the TLBs when enabling dirty logging.
As an alternative, KVM could explicitly check the MMU-Writable bit when
write-protecting SPTEs to decide if a flush is needed (instead of
checking the Writable bit), but given that a flush almost always happens
anyway, so just making it unconditional seems simpler.

Signed-off-by: Junaid Shahid <junaids@google.com>
Message-Id: <20220810224939.2611160-1-junaids@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/mmu/mmu.c
arch/x86/kvm/mmu/spte.h
arch/x86/kvm/x86.c