Re: [PATCH] KVM: x86/mmu: Embed direct bits into gpa for KVM_PRE_FAULT_MEMORY
From: Edgecombe, Rick P
Date: Wed Jun 11 2025 - 17:16:35 EST
On Wed, 2025-06-11 at 13:43 -0700, Sean Christopherson wrote:
> > 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;
Oh, how embarrassing. Yes, I misread the code, but the way it's working is, oh
man...
TDX isn't setting PFERR_WRITE_MASK or PFERR_PRESENT_MASK in the error_code
passed into the fault handler. So page_fault_can_be_fast() should return false
for that reason for private/mirror faults.