lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250207030931.1902-1-yan.y.zhao@intel.com>
Date: Fri,  7 Feb 2025 11:09:31 +0800
From: Yan Zhao <yan.y.zhao@...el.com>
To: pbonzini@...hat.com,
	seanjc@...gle.com
Cc: rick.p.edgecombe@...el.com,
	linux-kernel@...r.kernel.org,
	kvm@...r.kernel.org,
	Yan Zhao <yan.y.zhao@...el.com>
Subject: [PATCH 4/4] KVM: x86/mmu: Free obsolete roots when pre-faulting SPTEs

Always free obsolete roots when pre-faulting SPTEs in case it's called
after a root is invalidated (e.g., by memslot removal) but before any
vcpu_enter_guest() processing of KVM_REQ_MMU_FREE_OBSOLETE_ROOTS.

Lack of kvm_mmu_free_obsolete_roots() in this scenario can lead to
kvm_mmu_reload() failing to load a new root if the current root hpa is an
obsolete root (which is not INVALID_PAGE). Consequently,
kvm_arch_vcpu_pre_fault_memory() will retry infinitely due to the checking
of is_page_fault_stale().

It's safe to call kvm_mmu_free_obsolete_roots() even if there are no
obsolete roots or if it's called a second time when vcpu_enter_guest()
later processes KVM_REQ_MMU_FREE_OBSOLETE_ROOTS. This is because
kvm_mmu_free_obsolete_roots() sets an obsolete root to INVALID_PAGE and
will do nothing to an INVALID_PAGE.

Signed-off-by: Yan Zhao <yan.y.zhao@...el.com>
---
 arch/x86/kvm/mmu/mmu.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index 47fd3712afe6..72f68458049a 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -4740,7 +4740,12 @@ long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
 	/*
 	 * reload is efficient when called repeatedly, so we can do it on
 	 * every iteration.
+	 * Before reload, free obsolete roots in case the prefault is called
+	 * after a root is invalidated (e.g., by memslot removal) but
+	 * before any vcpu_enter_guest() processing of
+	 * KVM_REQ_MMU_FREE_OBSOLETE_ROOTS.
 	 */
+	kvm_mmu_free_obsolete_roots(vcpu);
 	r = kvm_mmu_reload(vcpu);
 	if (r)
 		return r;
-- 
2.43.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ