Re: [PATCH 04/28] KVM: x86/mmu: Retry page fault if root is invalidated by memslot update

Sean Christopherson
2021-12-08T19:17:18Z

On Sat, Nov 20, 2021, Sean Christopherson wrote:
> @@ -3976,6 +3980,20 @@ static bool kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault,
> return true;
> }
>
> +/*
> + * Returns true if the page fault is stale and needs to be retried, i.e. if the
> + * root was invalidated by a memslot update or a relevant mmu_notifier fired.
> + */
> +static bool is_page_fault_stale(struct kvm_vcpu *vcpu,
> + struct kvm_page_fault *fault, int mmu_seq)
> +{
> + if (is_obsolete_sp(vcpu->kvm, to_shadow_page(vcpu->arch.mmu->root_hpa)))

Ugh, I got so focused on TDP MMU that I completely forgot to test this with shadow
paging. PAE roots are not backed by shadow pages, which means this explodes on the
very first page fault with TDP disabled. Nested NPT will suffer the same fate.

I'll figure out a patch for 5.16. Long term, it might be nice to actually allocate
shadow pages for the special roots.

> + return true;
> +
> + return fault->slot &&
> + mmu_notifier_retry_hva(vcpu->kvm, mmu_seq, fault->hva);
> +}