linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: x86/mmu: Don't WARN on a NULL shadow page in TDP MMU check
@ 2021-06-22  7:24 Sean Christopherson
  2021-06-22 22:38 ` David Matlack
  2021-06-23 13:26 ` Paolo Bonzini
  0 siblings, 2 replies; 3+ messages in thread
From: Sean Christopherson @ 2021-06-22  7:24 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel, David Matlack

Treat a NULL shadow page in the "is a TDP MMU" check as valid, non-TDP
root.  KVM uses a "direct" PAE paging MMU when TDP is disabled and the
guest is running with paging disabled.  In that case, root_hpa points at
the pae_root page (of which only 32 bytes are used), not a standard
shadow page, and the WARN fires (a lot).

Fixes: 0b873fd7fb53 ("KVM: x86/mmu: Remove redundant is_tdp_mmu_enabled check")
Cc: David Matlack <dmatlack@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/mmu/tdp_mmu.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/mmu/tdp_mmu.h b/arch/x86/kvm/mmu/tdp_mmu.h
index b981a044ab55..1cae4485b3bc 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.h
+++ b/arch/x86/kvm/mmu/tdp_mmu.h
@@ -94,11 +94,13 @@ static inline bool is_tdp_mmu(struct kvm_mmu *mmu)
 	if (WARN_ON(!VALID_PAGE(hpa)))
 		return false;
 
+	/*
+	 * A NULL shadow page is legal when shadowing a non-paging guest with
+	 * PAE paging, as the MMU will be direct with root_hpa pointing at the
+	 * pae_root page, not a shadow page.
+	 */
 	sp = to_shadow_page(hpa);
-	if (WARN_ON(!sp))
-		return false;
-
-	return is_tdp_mmu_page(sp) && sp->root_count;
+	return sp && is_tdp_mmu_page(sp) && sp->root_count;
 }
 #else
 static inline bool kvm_mmu_init_tdp_mmu(struct kvm *kvm) { return false; }
-- 
2.32.0.288.g62a8d224e6-goog


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

* Re: [PATCH] KVM: x86/mmu: Don't WARN on a NULL shadow page in TDP MMU check
  2021-06-22  7:24 [PATCH] KVM: x86/mmu: Don't WARN on a NULL shadow page in TDP MMU check Sean Christopherson
@ 2021-06-22 22:38 ` David Matlack
  2021-06-23 13:26 ` Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: David Matlack @ 2021-06-22 22:38 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Paolo Bonzini, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm list, LKML

On Tue, Jun 22, 2021 at 12:24 AM Sean Christopherson <seanjc@google.com> wrote:
>
> Treat a NULL shadow page in the "is a TDP MMU" check as valid, non-TDP
> root.  KVM uses a "direct" PAE paging MMU when TDP is disabled and the
> guest is running with paging disabled.  In that case, root_hpa points at
> the pae_root page (of which only 32 bytes are used), not a standard
> shadow page, and the WARN fires (a lot).
>
> Fixes: 0b873fd7fb53 ("KVM: x86/mmu: Remove redundant is_tdp_mmu_enabled check")
> Cc: David Matlack <dmatlack@google.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>

Thanks for the fix. I was able to reproduce the issue by running a
kvm-unit-test with EPT=N. I'll add that to my "pre-send-email"
workflow in the future.

Reviewed-by: David Matlack <dmatlack@google.com>

> ---
>  arch/x86/kvm/mmu/tdp_mmu.h | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/arch/x86/kvm/mmu/tdp_mmu.h b/arch/x86/kvm/mmu/tdp_mmu.h
> index b981a044ab55..1cae4485b3bc 100644
> --- a/arch/x86/kvm/mmu/tdp_mmu.h
> +++ b/arch/x86/kvm/mmu/tdp_mmu.h
> @@ -94,11 +94,13 @@ static inline bool is_tdp_mmu(struct kvm_mmu *mmu)
>         if (WARN_ON(!VALID_PAGE(hpa)))
>                 return false;
>
> +       /*
> +        * A NULL shadow page is legal when shadowing a non-paging guest with
> +        * PAE paging, as the MMU will be direct with root_hpa pointing at the
> +        * pae_root page, not a shadow page.
> +        */
>         sp = to_shadow_page(hpa);
> -       if (WARN_ON(!sp))
> -               return false;
> -
> -       return is_tdp_mmu_page(sp) && sp->root_count;
> +       return sp && is_tdp_mmu_page(sp) && sp->root_count;
>  }
>  #else
>  static inline bool kvm_mmu_init_tdp_mmu(struct kvm *kvm) { return false; }
> --
> 2.32.0.288.g62a8d224e6-goog
>

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

* Re: [PATCH] KVM: x86/mmu: Don't WARN on a NULL shadow page in TDP MMU check
  2021-06-22  7:24 [PATCH] KVM: x86/mmu: Don't WARN on a NULL shadow page in TDP MMU check Sean Christopherson
  2021-06-22 22:38 ` David Matlack
@ 2021-06-23 13:26 ` Paolo Bonzini
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2021-06-23 13:26 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
	linux-kernel, David Matlack

On 22/06/21 09:24, Sean Christopherson wrote:
> Treat a NULL shadow page in the "is a TDP MMU" check as valid, non-TDP
> root.  KVM uses a "direct" PAE paging MMU when TDP is disabled and the
> guest is running with paging disabled.  In that case, root_hpa points at
> the pae_root page (of which only 32 bytes are used), not a standard
> shadow page, and the WARN fires (a lot).
> 
> Fixes: 0b873fd7fb53 ("KVM: x86/mmu: Remove redundant is_tdp_mmu_enabled check")
> Cc: David Matlack <dmatlack@google.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>   arch/x86/kvm/mmu/tdp_mmu.h | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)

Queued, thanks.

Paolo

> 
> diff --git a/arch/x86/kvm/mmu/tdp_mmu.h b/arch/x86/kvm/mmu/tdp_mmu.h
> index b981a044ab55..1cae4485b3bc 100644
> --- a/arch/x86/kvm/mmu/tdp_mmu.h
> +++ b/arch/x86/kvm/mmu/tdp_mmu.h
> @@ -94,11 +94,13 @@ static inline bool is_tdp_mmu(struct kvm_mmu *mmu)
>   	if (WARN_ON(!VALID_PAGE(hpa)))
>   		return false;
>   
> +	/*
> +	 * A NULL shadow page is legal when shadowing a non-paging guest with
> +	 * PAE paging, as the MMU will be direct with root_hpa pointing at the
> +	 * pae_root page, not a shadow page.
> +	 */
>   	sp = to_shadow_page(hpa);
> -	if (WARN_ON(!sp))
> -		return false;
> -
> -	return is_tdp_mmu_page(sp) && sp->root_count;
> +	return sp && is_tdp_mmu_page(sp) && sp->root_count;
>   }
>   #else
>   static inline bool kvm_mmu_init_tdp_mmu(struct kvm *kvm) { return false; }
> 


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

end of thread, other threads:[~2021-06-23 13:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-22  7:24 [PATCH] KVM: x86/mmu: Don't WARN on a NULL shadow page in TDP MMU check Sean Christopherson
2021-06-22 22:38 ` David Matlack
2021-06-23 13:26 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).