linux/tools/testing/selftests/kvm/lib/x86
Yosry Ahmed 7317f5b143 KVM: selftests: Do not intercept #PF by default in nVMX tests
init_vmcs_control_fields() sets PFEC_MASK and PFEC_MATCH so that they
never match, which reverses the meaning of the PF_VECTOR bit in
EXCEPTION_BITMAP (which is zeroed), effectively enabling #PF
interception by default.

The relevant part of the SDM describes this:

  When a page fault occurs, a processor consults (1) bit 14 of the
  exception bitmap; (2) the error code produced with the page fault [PFEC];
  (3) the page-fault error-code mask field [PFEC_MASK]; and (4) the
  page-fault error-code match field [PFEC_MATCH].

  It checks if PFEC & PFEC_MASK = PFEC_MATCH.  If there is equality, the
  specification of bit 14 in the exception bitmap is followed (for example,
  a VM exit occurs if that bit is set). If there is inequality, the meaning
  of that bit is reversed (for example, a VM exit occurs if that bit is
  clear).

Clear PFEC_MATCH such that there is equality, and the #PF bit in the
exception bitmap is followed, so that #PFs are not intercepted by default,
same as every other exception.  This also allows tests to set the #PF bit
in the exception bitmap if they want to intercept #PFs, without having to
muck with the PFEC_{MASK,MATCH} fields.

Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Yosry Ahmed <yosry@kernel.org>
Link: https://patch.msgid.link/20260728174232.2423257-10-yosry@kernel.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
2026-07-29 05:45:52 -07:00
..
apic.c KVM: selftests: Use u64 instead of uint64_t 2026-04-20 14:54:16 -07:00
handlers.S
hyperv.c KVM: selftests: Drop "vaddr_" from APIs that allocate memory for a given VM 2026-04-20 14:54:17 -07:00
memstress.c KVM: selftests: Drop L1-provided stacks for L2 guests on x86 2026-06-17 17:56:15 -07:00
pmu.c KVM: selftests: Use u64 instead of uint64_t 2026-04-20 14:54:16 -07:00
processor.c KVM: selftests: Expose PTE masks to guests as part of an MMU 2026-07-29 05:45:27 -07:00
sev.c KVM: selftests: Use u8 instead of uint8_t 2026-04-20 14:54:17 -07:00
svm.c KVM: selftests: Handle rflags save/restore for SVM in guest_regs 2026-07-29 05:45:26 -07:00
ucall.c KVM: selftests: Drop HORRIFIC_L2_UCALL_CLOBBER_HACK 2026-07-29 05:45:26 -07:00
vmx.c KVM: selftests: Do not intercept #PF by default in nVMX tests 2026-07-29 05:45:52 -07:00