Re: [PATCH V2 4/4] KVM: selftests: Add nested page fault injection test
From: Kevin Cheng
Date: Wed Mar 04 2026 - 22:54:28 EST
On Tue, Feb 24, 2026 at 12:37 PM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
>
> On Tue, Feb 24, 2026, Kevin Cheng wrote:
> > Add a test that exercises nested page fault injection during L2
> > execution. L2 executes I/O string instructions (OUTSB/INSB) that access
> > memory restricted in L1's nested page tables (NPT/EPT), triggering a
> > nested page fault that L0 must inject to L1.
> >
> > The test supports both AMD SVM (NPF) and Intel VMX (EPT violation) and
> > verifies that:
> > - The exit reason is an NPF/EPT violation
> > - The access type and permission bits are correct
> > - The faulting GPA is correct
> >
> > Three test cases are implemented:
> > - Unmap the final data page (final translation fault, OUTSB read)
> > - Unmap a PT page (page walk fault, OUTSB read)
> > - Write-protect the final data page (protection violation, INSB write)
> > - Write-protect a PT page (protection violation on A/D update, OUTSB
> > read)
>
> Either in this test or in KUT, we need coverage for validating faults that are
> reported by hardware, i.e. for faults that _don't_ go through the emulator.
>
> E.g. there's this "todo" of sorts in KUT:
>
> case VMX_EPT_VIOLATION:
> /*
> * Exit-qualifications are masked not to account for advanced
> * VM-exit information. Once KVM supports this feature, this
> * masking should be removed.
> */
> exit_qual &= ~EPT_VLT_GUEST_MASK;
>
>
> Or maybe both? I generally prefer selftests for maintenance purposes, and you've
> already written this test...
Does https://lore.kernel.org/all/20260113003153.3344500-9-chengkev@xxxxxxxxxx/
count :) These exercise nested_svm_inject_npf_exit()
Actually running these tests, I realized that the expected_fault is
incorrect in those KVM unit tests. Because PFERR_GUEST_PAGE_MASK was
previously hardcorded, the KUTs had that set in the expected_fault.
However, with the NPF injection fixes, I will need to change the KUTs
to expect PFERR_GUEST_FINAL_MASK to be set for the different test
cases which is actually the correct expectation.