[PATCH v5 09/13] KVM: selftests: Do not intercept #PF by default in nVMX tests

From: Yosry Ahmed

Date: Tue Jul 28 2026 - 13:56:30 EST


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.

Signed-off-by: Yosry Ahmed <yosry@xxxxxxxxxx>
---
tools/testing/selftests/kvm/lib/x86/vmx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kvm/lib/x86/vmx.c b/tools/testing/selftests/kvm/lib/x86/vmx.c
index cd09c9de4485a..089e1a8af53fc 100644
--- a/tools/testing/selftests/kvm/lib/x86/vmx.c
+++ b/tools/testing/selftests/kvm/lib/x86/vmx.c
@@ -232,7 +232,7 @@ static inline void init_vmcs_control_fields(struct vmx_pages *vmx)

vmwrite(EXCEPTION_BITMAP, 0);
vmwrite(PAGE_FAULT_ERROR_CODE_MASK, 0);
- vmwrite(PAGE_FAULT_ERROR_CODE_MATCH, -1); /* Never match */
+ vmwrite(PAGE_FAULT_ERROR_CODE_MATCH, 0);
vmwrite(CR3_TARGET_COUNT, 0);
vmwrite(VM_EXIT_CONTROLS, rdmsr(MSR_IA32_VMX_EXIT_CTLS) |
VM_EXIT_HOST_ADDR_SPACE_SIZE); /* 64-bit host */
--
2.55.0.487.gaf234c4eb3-goog