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"). Update the comment in permission_fault(), which said that EPT violations do not provide the SS bit. 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 Signed-off-by: Dennis Reußwig --- arch/x86/include/asm/vmx.h | 1 + arch/x86/kvm/mmu.h | 7 ++++--- arch/x86/kvm/vmx/common.h | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) 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/mmu.h b/arch/x86/kvm/mmu.h index 2f0a6f2f5021..dda237a1ebd9 100644 --- a/arch/x86/kvm/mmu.h +++ b/arch/x86/kvm/mmu.h @@ -277,9 +277,10 @@ static inline u8 permission_fault(struct kvm_vcpu *vcpu, struct kvm_pagewalk *w, { /* * Of the error codes that do not contribute to the index in - * fmt->permissions, PK and SS are not supported by shadow paging - * and also not provided to EPT violations, but SS *is* included - * in the NPT exit code. RSVD faults are handled elsewhere. + * fmt->permissions, PK and SS are not supported by shadow paging. + * SS is included in the NPT exit code and in EPT violations, where + * only the nested EPT walker uses it for supervisor shadow-stack + * control. RSVD faults are handled elsewhere. */ unsigned int pfec = access & ~PFERR_SS_MASK; if (WARN_ON_ONCE(pfec & ~(PFERR_PRESENT_MASK | PFERR_WRITE_MASK | 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