]> git.itanic.dy.fi Git - linux-stable/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)
commitb64d740ea7ddc929d97b28de4c0665f7d5db9e2a
tree671bb2795093290203d8473e28a900967525712b
parent1441ca1494d74a2c9d6c9bd8dd633d9ebff1daba
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