Re: [PATCH] KVM: x86/mmu: Embed direct bits into gpa for KVM_PRE_FAULT_MEMORY
From: Sean Christopherson
Date: Wed Jun 11 2025 - 16:43:38 EST
On Wed, Jun 11, 2025, Rick P Edgecombe wrote:
> On Wed, 2025-06-11 at 12:37 -0700, Sean Christopherson wrote:
> > Ugh, and the whole tdp_mmu_get_root_for_fault() handling is broken.
> > is_page_fault_stale() only looks at mmu->root.hpa, i.e. could theoretically blow
> > up if the shared root is somehow valid but the mirror root is not. Probably can't
> > happen in practice, but it's ugly.
>
> We had some discussion on this root valid/invalid pattern:
> https://lore.kernel.org/kvm/d33d00b88707961126a24b19f940de43ba6e6c56.camel@xxxxxxxxx/
>
> It's brittle though.
Hmm, yeah, the is_page_fault_stale() thing is definitely benign, just odd.
> > Oof, and I've no idea what kvm_tdp_mmu_fast_pf_get_last_sptep() is doing. It
> > says:
> >
> > /* Fast pf is not supported for mirrored roots */
> >
> > but I don't see anything that actually enforces that.
>
> Functionally, page_fault_can_be_fast() should prevented this with the check of
> kvm->arch.has_private_mem.
No? I see this:
if (kvm->arch.has_private_mem &&
fault->is_private != kvm_mem_is_private(kvm, fault->gfn))
return false;
I.e. a private fault can be fast, so long as the page is already in the correct
shared vs. private state. I can imagine that it's impossible for TDX to generate
protection violations, but I think kvm_tdp_mmu_fast_pf_get_last_sptep() could be
reached with a mirror root if kvm_ad_enabled=false.
if (!fault->present)
return !kvm_ad_enabled;
/*
* Note, instruction fetches and writes are mutually exclusive, ignore
* the "exec" flag.
*/
return fault->write;
> But, yea it's not correct for being readable. The mirror/external concepts
> only work if they make sense as independent concepts. Otherwise it's just
> naming obfuscation.