All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] KVM: x86: Fix dangling page reference in TDP MMU
@ 2021-12-13 11:25 Paolo Bonzini
  2021-12-13 11:25 ` [PATCH 1/2] KVM: x86: allow kvm_tdp_mmu_zap_invalidated_roots with write-locked mmu_lock Paolo Bonzini
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Paolo Bonzini @ 2021-12-13 11:25 UTC (permalink / raw)
  To: linux-kernel, kvm; +Cc: seanjc, ignat, bgardon, dmatlack, stevensd, kernel-team

kvm_tdp_mmu_zap_all is intended to visit all roots and zap their page
tables, which flushes the accessed and dirty bits out to the Linux
"struct page"s.  Missing some of the roots has catastrophic effects,
because kvm_tdp_mmu_zap_all is called when the MMU notifier is being
removed and any PTEs left behind might become dangling by the time
kvm-arch_destroy_vm tears down the roots for good.

Unfortunately that is exactly what kvm_tdp_mmu_zap_all is doing: it
visits all roots via for_each_tdp_mmu_root_yield_safe, which in turn
uses kvm_tdp_mmu_get_root to skip invalid roots.  If the current root is
invalid at the time of kvm_tdp_mmu_zap_all, its page tables will remain
in place but will later be zapped during kvm_arch_destroy_vm.

To fix this, ensure that kvm_tdp_mmu_zap_all goes over all
roots, including the invalid ones.  The easiest way to do so is for
kvm_tdp_mmu_zap_all to do the same as kvm_mmu_zap_all_fast: invalidate
all roots, and then zap the invalid roots.  The only difference is that
there is no need to go through tdp_mmu_zap_spte_atomic.

Paolo

Paolo Bonzini (2):
  KVM: x86: allow kvm_tdp_mmu_zap_invalidated_roots with write-locked
    mmu_lock
  KVM: x86: zap invalid roots in kvm_tdp_mmu_zap_all

 arch/x86/kvm/mmu/mmu.c     |  2 +-
 arch/x86/kvm/mmu/tdp_mmu.c | 42 ++++++++++++++++++++------------------
 arch/x86/kvm/mmu/tdp_mmu.h |  2 +-
 3 files changed, 24 insertions(+), 22 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-12-14 19:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-13 11:25 [PATCH 0/2] KVM: x86: Fix dangling page reference in TDP MMU Paolo Bonzini
2021-12-13 11:25 ` [PATCH 1/2] KVM: x86: allow kvm_tdp_mmu_zap_invalidated_roots with write-locked mmu_lock Paolo Bonzini
2021-12-13 11:25 ` [PATCH 2/2] KVM: x86: zap invalid roots in kvm_tdp_mmu_zap_all Paolo Bonzini
2021-12-13 16:36   ` Sean Christopherson
2021-12-14 19:45     ` Sean Christopherson
2021-12-13 13:43 ` [PATCH 0/2] KVM: x86: Fix dangling page reference in TDP MMU Ignat Korchagin
2021-12-13 15:06   ` Paolo Bonzini
2021-12-13 16:47   ` Sean Christopherson
2021-12-13 18:28     ` Paolo Bonzini
2021-12-13 19:44     ` Sean Christopherson
2021-12-13 20:18       ` Ignat Korchagin
2021-12-14  3:12       ` Sean Christopherson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.