[PATCH 03/10] KVM: VMX: Report shadow-stack accesses in EPT violations as PFERR_SS

From: Dennis Reußwig

Date: Thu Dec 03 2026 - 18:50:38 EST


Bit 13 of the exit qualification of an EPT violation is set if the
access was a shadow-stack access. __vt_handle_ept_violation() does not
pass it on, so the MMU cannot tell shadow-stack accesses from ordinary
ones. Translate it to PFERR_SS_MASK. This is the VMX counterpart of
commit e90ab3669181 ("KVM: x86/mmu: Cope with the SS bit being set
in #NPF exit codes").

No functional change on its own: permission_fault() ignores
PFERR_SS_MASK. Supervisor shadow-stack control for nested EPT uses the
bit in a later patch.

Suggested-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
Signed-off-by: Dennis Reußwig <dennis@reusswig.codes>
---
arch/x86/include/asm/vmx.h | 1 +
arch/x86/kvm/vmx/common.h | 3 +++
2 files changed, 4 insertions(+)

diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
index e49b836c7313..20e2ad19d65b 100644
--- a/arch/x86/include/asm/vmx.h
+++ b/arch/x86/include/asm/vmx.h
@@ -630,6 +630,7 @@ enum vm_entry_failure_code {
#define EPT_VIOLATION_GVA_USER BIT(9)
#define EPT_VIOLATION_GVA_WRITABLE BIT(10)
#define EPT_VIOLATION_GVA_NX BIT(11)
+#define EPT_VIOLATION_SHADOW_STACK BIT(13)

#define EPT_VIOLATION_RWX_TO_PROT(__epte) (((__epte) & VMX_EPT_RWX_MASK) << 3)
#define EPT_VIOLATION_USER_EXEC_TO_PROT(__epte) (((__epte) & VMX_EPT_USER_EXECUTABLE_MASK) >> 4)
diff --git a/arch/x86/kvm/vmx/common.h b/arch/x86/kvm/vmx/common.h
index b2905335a2d2..eb60ba97074c 100644
--- a/arch/x86/kvm/vmx/common.h
+++ b/arch/x86/kvm/vmx/common.h
@@ -144,6 +144,9 @@ static inline int __vt_handle_ept_violation(struct kvm_vcpu *vcpu, gpa_t gpa,
/* Is it a fetch fault? */
error_code |= (exit_qualification & EPT_VIOLATION_ACC_INSTR)
? PFERR_FETCH_MASK : 0;
+ /* Is it a shadow-stack access? */
+ error_code |= (exit_qualification & EPT_VIOLATION_SHADOW_STACK)
+ ? PFERR_SS_MASK : 0;
/* ept page table entry is present? */
error_code |= (exit_qualification &
(EPT_VIOLATION_PROT_MASK & ~EPT_VIOLATION_PROT_USER_EXEC))

--
2.53.0