Re: [RFC PATCH 6/6] KVM: X86: Use level_promoted and pae_root shadow page for 32bit guests

From: Sean Christopherson
Date: Tue Jan 04 2022 - 15:55:14 EST


On Fri, Dec 10, 2021, Lai Jiangshan wrote:
> diff --git a/arch/x86/kvm/mmu/tdp_mmu.h b/arch/x86/kvm/mmu/tdp_mmu.h
> index 476b133544dd..822ff5d76b91 100644
> --- a/arch/x86/kvm/mmu/tdp_mmu.h
> +++ b/arch/x86/kvm/mmu/tdp_mmu.h
> @@ -100,13 +100,8 @@ 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);
> - return sp && is_tdp_mmu_page(sp) && sp->root_count;
> + return is_tdp_mmu_page(sp) && sp->root_count;
> }

is_page_fault_stale() can get similar treatment

diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index e8c69c2dfbd9..9ff8e228b55e 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -3855,19 +3855,7 @@ static bool is_page_fault_stale(struct kvm_vcpu *vcpu,
{
struct kvm_mmu_page *sp = to_shadow_page(vcpu->arch.mmu->root_hpa);

- /* Special roots, e.g. pae_root, are not backed by shadow pages. */
- if (sp && is_obsolete_sp(vcpu->kvm, sp))
- return true;
-
- /*
- * Roots without an associated shadow page are considered invalid if
- * there is a pending request to free obsolete roots. The request is
- * only a hint that the current root _may_ be obsolete and needs to be
- * reloaded, e.g. if the guest frees a PGD that KVM is tracking as a
- * previous root, then __kvm_mmu_prepare_zap_page() signals all vCPUs
- * to reload even if no vCPU is actively using the root.
- */
- if (!sp && kvm_test_request(KVM_REQ_MMU_RELOAD, vcpu))
+ if (is_obsolete_sp(vcpu->kvm, sp))
return true;

return fault->slot &&

> #else
> static inline bool kvm_mmu_init_tdp_mmu(struct kvm *kvm) { return false; }
> --
> 2.19.1.6.gb485710b
>