All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm: x86/mmu: Fix is_tdp_mmu_check when using PAE
@ 2020-11-11 18:53 Ben Gardon
  2020-11-11 22:57 ` Jamie Heilman
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ben Gardon @ 2020-11-11 18:53 UTC (permalink / raw)
  To: linux-kernel, kvm
  Cc: Paolo Bonzini, Sean Christopherson, Peter Shier, Jim Mattson,
	Zdenek Kaspar, Ben Gardon

When PAE is in use, the root_hpa will not have a shadow page assoicated
with it. In this case the kernel will crash with a NULL pointer
dereference. Add checks to ensure is_tdp_mmu_root works as intended even
when using PAE.

Tested: compiles

Fixes: 02c00b3a2f7e ("kvm: x86/mmu: Allocate and free TDP MMU roots")
Reported-by: Zdenek Kaspar <zkaspar82@gmail.com>
Signed-off-by: Ben Gardon <bgardon@google.com>
---
 arch/x86/kvm/mmu/tdp_mmu.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
index 27e381c9da6c..13013f4d98ad 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.c
+++ b/arch/x86/kvm/mmu/tdp_mmu.c
@@ -49,8 +49,18 @@ bool is_tdp_mmu_root(struct kvm *kvm, hpa_t hpa)
 {
 	struct kvm_mmu_page *sp;
 
+	if (WARN_ON(!VALID_PAGE(hpa)))
+		return false;
+
 	sp = to_shadow_page(hpa);
 
+	/*
+	 * If this VM is being run with PAE, the TDP MMU will not be enabled
+	 * and the root HPA will not have a shadow page associated with it.
+	 */
+	if (!sp)
+		return false;
+
 	return sp->tdp_mmu_page && sp->root_count;
 }
 
-- 
2.29.2.222.g5d2a92d10f8-goog


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

end of thread, other threads:[~2020-11-16 17:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-11 18:53 [PATCH] kvm: x86/mmu: Fix is_tdp_mmu_check when using PAE Ben Gardon
2020-11-11 22:57 ` Jamie Heilman
2020-11-11 23:46 ` Zdenek Kaspar
2020-11-13 20:58 ` Paolo Bonzini
2020-11-16 17:18   ` Ben Gardon

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.