* [PATCH 01/10] KVM: nVMX: Allow CET entry/exit controls with enlightened VMCS
2026-12-03 23:49 [PATCH 00/10] KVM: nVMX: Supervisor shadow-stack control for nested EPT and CET with eVMCS Dennis Reußwig
@ 2026-12-03 23:49 ` Dennis Reußwig
2026-12-03 23:49 ` [PATCH 02/10] KVM: x86/mmu: Move TDP A/D tracking type to SPTE bits 56-57 Dennis Reußwig
` (8 subsequent siblings)
9 siblings, 0 replies; 22+ messages in thread
From: Dennis Reußwig @ 2026-12-03 23:49 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Jon Kohler,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Shuah Khan
Cc: kvm, linux-kernel, linux-doc, linux-kselftest, Chao Gao,
Maxim Levitsky, Vitaly Kuznetsov, Panayotis Katsaloulis,
Dennis Reußwig
Since commit 55a71224bd90 ("KVM: nVMX: allow MBEC with EVMCS"), L1 is
offered mode-based execute control also when it uses the enlightened
VMCS. Windows Hyper-V then enables CET for its guests and needs the
VM-entry and VM-exit controls that load CET state. With eVMCS,
nested_evmcs_filter_control_msr() hides them from L1, because they are
missing from EVMCS1_SUPPORTED_VMENTRY_CTRL and
EVMCS1_SUPPORTED_VMEXIT_CTRL, and the CET fields of the eVMCS are
neither in vmcs_field_to_evmcs_1[] nor copied to and from vmcs12.
Add the CET fields (GUEST_S_CET, GUEST_SSP, GUEST_INTR_SSP_TABLE,
HOST_S_CET, HOST_SSP, HOST_INTR_SSP_TABLE) to the field table, using
the clean-field groups of the entries that were commented out, copy
them in copy_enlightened_to_vmcs12() and the guest fields back in
copy_vmcs12_to_enlightened(), and allow the two controls.
This alone does not make Windows boot: Hyper-V also needs supervisor
shadow-stack control for nested EPT, which is added later in this
series.
Fixes: 55a71224bd90 ("KVM: nVMX: allow MBEC with EVMCS")
Reported-by: Panayotis Katsaloulis <panayotis@panayotis.com>
Closes: https://lore.kernel.org/kvm/58dcd595e3187d335e103a042d196cb7@panayotis.com/
Signed-off-by: Dennis Reußwig <dennis@reusswig.codes>
---
arch/x86/kvm/vmx/hyperv_evmcs.c | 24 ++++++++++++------------
arch/x86/kvm/vmx/hyperv_evmcs.h | 6 ++++--
arch/x86/kvm/vmx/nested.c | 31 +++++++++++++------------------
3 files changed, 29 insertions(+), 32 deletions(-)
diff --git a/arch/x86/kvm/vmx/hyperv_evmcs.c b/arch/x86/kvm/vmx/hyperv_evmcs.c
index cc728c9a3de5..f00e4edf1e6c 100644
--- a/arch/x86/kvm/vmx/hyperv_evmcs.c
+++ b/arch/x86/kvm/vmx/hyperv_evmcs.c
@@ -128,23 +128,23 @@ const struct evmcs_field vmcs_field_to_evmcs_1[] = {
HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2),
EVMCS1_FIELD(TSC_MULTIPLIER, tsc_multiplier,
HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2),
+ EVMCS1_FIELD(GUEST_S_CET, guest_ia32_s_cet,
+ HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
+ EVMCS1_FIELD(GUEST_SSP, guest_ssp,
+ HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_BASIC),
+ EVMCS1_FIELD(GUEST_INTR_SSP_TABLE, guest_ia32_int_ssp_table_addr,
+ HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
+ EVMCS1_FIELD(HOST_S_CET, host_ia32_s_cet,
+ HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+ EVMCS1_FIELD(HOST_SSP, host_ssp,
+ HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
+ EVMCS1_FIELD(HOST_INTR_SSP_TABLE, host_ia32_int_ssp_table_addr,
+ HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
/*
* Not used by KVM:
*
- * EVMCS1_FIELD(0x00006828, guest_ia32_s_cet,
- * HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
- * EVMCS1_FIELD(0x0000682A, guest_ssp,
- * HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_BASIC),
- * EVMCS1_FIELD(0x0000682C, guest_ia32_int_ssp_table_addr,
- * HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
* EVMCS1_FIELD(0x00002816, guest_ia32_lbr_ctl,
* HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1),
- * EVMCS1_FIELD(0x00006C18, host_ia32_s_cet,
- * HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
- * EVMCS1_FIELD(0x00006C1A, host_ssp,
- * HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
- * EVMCS1_FIELD(0x00006C1C, host_ia32_int_ssp_table_addr,
- * HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1),
*/
/* 64 bit read only */
diff --git a/arch/x86/kvm/vmx/hyperv_evmcs.h b/arch/x86/kvm/vmx/hyperv_evmcs.h
index 052b62b8ed8e..a6e9210e4fa5 100644
--- a/arch/x86/kvm/vmx/hyperv_evmcs.h
+++ b/arch/x86/kvm/vmx/hyperv_evmcs.h
@@ -104,7 +104,8 @@
VM_EXIT_LOAD_IA32_EFER | \
VM_EXIT_CLEAR_BNDCFGS | \
VM_EXIT_PT_CONCEAL_PIP | \
- VM_EXIT_CLEAR_IA32_RTIT_CTL)
+ VM_EXIT_CLEAR_IA32_RTIT_CTL | \
+ VM_EXIT_LOAD_CET_STATE)
#define EVMCS1_SUPPORTED_VMENTRY_CTRL \
(VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR | \
@@ -115,7 +116,8 @@
VM_ENTRY_LOAD_IA32_EFER | \
VM_ENTRY_LOAD_BNDCFGS | \
VM_ENTRY_PT_CONCEAL_PIP | \
- VM_ENTRY_LOAD_IA32_RTIT_CTL)
+ VM_ENTRY_LOAD_IA32_RTIT_CTL | \
+ VM_ENTRY_LOAD_CET_STATE)
#define EVMCS1_SUPPORTED_VMFUNC (0)
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index 1a98f28651f7..a7c8bbdfe4ca 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -1758,10 +1758,7 @@ static void copy_enlightened_to_vmcs12(struct vcpu_vmx *vmx, u32 hv_clean_fields
vmcs12->guest_rflags = evmcs->guest_rflags;
vmcs12->guest_interruptibility_info =
evmcs->guest_interruptibility_info;
- /*
- * Not present in struct vmcs12:
- * vmcs12->guest_ssp = evmcs->guest_ssp;
- */
+ vmcs12->guest_ssp = evmcs->guest_ssp;
}
if (unlikely(!(hv_clean_fields &
@@ -1809,12 +1806,9 @@ static void copy_enlightened_to_vmcs12(struct vcpu_vmx *vmx, u32 hv_clean_fields
vmcs12->host_gs_selector = evmcs->host_gs_selector;
vmcs12->host_tr_selector = evmcs->host_tr_selector;
vmcs12->host_ia32_perf_global_ctrl = evmcs->host_ia32_perf_global_ctrl;
- /*
- * Not present in struct vmcs12:
- * vmcs12->host_ia32_s_cet = evmcs->host_ia32_s_cet;
- * vmcs12->host_ssp = evmcs->host_ssp;
- * vmcs12->host_ia32_int_ssp_table_addr = evmcs->host_ia32_int_ssp_table_addr;
- */
+ vmcs12->host_s_cet = evmcs->host_ia32_s_cet;
+ vmcs12->host_ssp = evmcs->host_ssp;
+ vmcs12->host_ssp_tbl = evmcs->host_ia32_int_ssp_table_addr;
}
if (unlikely(!(hv_clean_fields &
@@ -1932,11 +1926,11 @@ static void copy_enlightened_to_vmcs12(struct vcpu_vmx *vmx, u32 hv_clean_fields
vmcs12->guest_activity_state = evmcs->guest_activity_state;
vmcs12->guest_sysenter_cs = evmcs->guest_sysenter_cs;
vmcs12->guest_ia32_perf_global_ctrl = evmcs->guest_ia32_perf_global_ctrl;
+ vmcs12->guest_s_cet = evmcs->guest_ia32_s_cet;
+ vmcs12->guest_ssp_tbl = evmcs->guest_ia32_int_ssp_table_addr;
/*
* Not present in struct vmcs12:
- * vmcs12->guest_ia32_s_cet = evmcs->guest_ia32_s_cet;
* vmcs12->guest_ia32_lbr_ctl = evmcs->guest_ia32_lbr_ctl;
- * vmcs12->guest_ia32_int_ssp_table_addr = evmcs->guest_ia32_int_ssp_table_addr;
*/
}
@@ -2046,6 +2040,9 @@ static void copy_vmcs12_to_enlightened(struct vcpu_vmx *vmx)
* evmcs->vm_entry_msr_load_count = vmcs12->vm_entry_msr_load_count;
* evmcs->guest_ia32_perf_global_ctrl = vmcs12->guest_ia32_perf_global_ctrl;
* evmcs->host_ia32_perf_global_ctrl = vmcs12->host_ia32_perf_global_ctrl;
+ * evmcs->host_ia32_s_cet = vmcs12->host_s_cet;
+ * evmcs->host_ssp = vmcs12->host_ssp;
+ * evmcs->host_ia32_int_ssp_table_addr = vmcs12->host_ssp_tbl;
* evmcs->encls_exiting_bitmap = vmcs12->encls_exiting_bitmap;
* evmcs->tsc_multiplier = vmcs12->tsc_multiplier;
*
@@ -2054,13 +2051,7 @@ static void copy_vmcs12_to_enlightened(struct vcpu_vmx *vmx)
* evmcs->exit_io_instruction_esi = vmcs12->exit_io_instruction_esi;
* evmcs->exit_io_instruction_edi = vmcs12->exit_io_instruction_edi;
* evmcs->exit_io_instruction_eip = vmcs12->exit_io_instruction_eip;
- * evmcs->host_ia32_s_cet = vmcs12->host_ia32_s_cet;
- * evmcs->host_ssp = vmcs12->host_ssp;
- * evmcs->host_ia32_int_ssp_table_addr = vmcs12->host_ia32_int_ssp_table_addr;
- * evmcs->guest_ia32_s_cet = vmcs12->guest_ia32_s_cet;
* evmcs->guest_ia32_lbr_ctl = vmcs12->guest_ia32_lbr_ctl;
- * evmcs->guest_ia32_int_ssp_table_addr = vmcs12->guest_ia32_int_ssp_table_addr;
- * evmcs->guest_ssp = vmcs12->guest_ssp;
*/
evmcs->guest_es_selector = vmcs12->guest_es_selector;
@@ -2154,6 +2145,10 @@ static void copy_vmcs12_to_enlightened(struct vcpu_vmx *vmx)
evmcs->guest_bndcfgs = vmcs12->guest_bndcfgs;
+ evmcs->guest_ia32_s_cet = vmcs12->guest_s_cet;
+ evmcs->guest_ssp = vmcs12->guest_ssp;
+ evmcs->guest_ia32_int_ssp_table_addr = vmcs12->guest_ssp_tbl;
+
return;
#else /* CONFIG_KVM_HYPERV */
KVM_BUG_ON(1, vmx->vcpu.kvm);
--
2.53.0
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 02/10] KVM: x86/mmu: Move TDP A/D tracking type to SPTE bits 56-57
2026-12-03 23:49 [PATCH 00/10] KVM: nVMX: Supervisor shadow-stack control for nested EPT and CET with eVMCS Dennis Reußwig
2026-12-03 23:49 ` [PATCH 01/10] KVM: nVMX: Allow CET entry/exit controls with enlightened VMCS Dennis Reußwig
@ 2026-12-03 23:49 ` Dennis Reußwig
2026-12-03 23:49 ` [PATCH 03/10] KVM: VMX: Report shadow-stack accesses in EPT violations as PFERR_SS Dennis Reußwig
` (7 subsequent siblings)
9 siblings, 0 replies; 22+ messages in thread
From: Dennis Reußwig @ 2026-12-03 23:49 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Jon Kohler,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Shuah Khan
Cc: kvm, linux-kernel, linux-doc, linux-kselftest, Chao Gao,
Maxim Levitsky, Vitaly Kuznetsov, Panayotis Katsaloulis,
Dennis Reußwig
Bits 60 and 61 of TDP SPTEs hold the type of A/D tracking. If bit 7 of
the EPTP is set, the CPU uses bit 60 of an EPT leaf as the supervisor
shadow-stack permission (SDM Vol. 3C, 31.3.3.2). KVM needs to set that
bit in shadow EPT SPTEs to support supervisor shadow-stack control for
nested EPT, so it cannot hold software state.
Move the A/D tracking type to bits 56 and 57, which are unused since
commit be4e45f360a2 ("KVM: x86/mmu: shuffle high bits of SPTEs in
preparation for MBEC"). The CPU ignores bit 56. Bit 57 is "verify
guest paging" only if the guest-paging verification VM-execution
control is set, which KVM never does; bit 61 was in the same situation
with the sub-page write permission control. The existing static
asserts against the host-writable, MMU-writable and access-tracking
bits still hold.
No functional change intended.
Signed-off-by: Dennis Reußwig <dennis@reusswig.codes>
---
arch/x86/kvm/mmu/spte.h | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h
index e730717824b3..237a0484367a 100644
--- a/arch/x86/kvm/mmu/spte.h
+++ b/arch/x86/kvm/mmu/spte.h
@@ -22,16 +22,19 @@
* - bits 52, 54: saved X-R bits for access tracking when EPT does not have A/D
* - bits 53 (EPT only): host writable
* - bits 55 (EPT only): MMU-writable
- * - bits 56-59: unused
- * - bits 60-61: type of A/D tracking
+ * - bits 56-57: type of A/D tracking
+ * - bits 58-61: unused; bit 60 is the EPT supervisor shadow-stack page bit
+ * when EPTP[7] is set, so it must not be used for software state
* - bits 62 (EPT only): saved XU bit for disabled AD
*/
/*
* TDP SPTES (more specifically, EPT SPTEs) may not have A/D bits, and may also
* be restricted to using write-protection (for L2 when CPU dirty logging, i.e.
- * PML, is enabled). Use bits 60 and 61 to hold the type of A/D tracking that
- * is must be employed for a given TDP SPTE.
+ * PML, is enabled). Use bits 56 and 57 to hold the type of A/D tracking that
+ * is must be employed for a given TDP SPTE. Bit 57 is "verify guest paging"
+ * only if the guest-paging verification VM-execution control is set, which
+ * KVM never does.
*
* Note, the "enabled" mask must be '0', as bits 62:52 are _reserved_ for PAE
* paging, including NPT PAE. This scheme works because legacy shadow paging
@@ -39,7 +42,7 @@
* TDP with CPU dirty logging (PML). If NPT ever gains PML-like support, it
* must be restricted to 64-bit KVM.
*/
-#define SPTE_TDP_AD_SHIFT 60
+#define SPTE_TDP_AD_SHIFT 56
#define SPTE_TDP_AD_MASK (3ULL << SPTE_TDP_AD_SHIFT)
#define SPTE_TDP_AD_ENABLED (0ULL << SPTE_TDP_AD_SHIFT)
#define SPTE_TDP_AD_DISABLED (1ULL << SPTE_TDP_AD_SHIFT)
--
2.53.0
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 03/10] KVM: VMX: Report shadow-stack accesses in EPT violations as PFERR_SS
2026-12-03 23:49 [PATCH 00/10] KVM: nVMX: Supervisor shadow-stack control for nested EPT and CET with eVMCS Dennis Reußwig
2026-12-03 23:49 ` [PATCH 01/10] KVM: nVMX: Allow CET entry/exit controls with enlightened VMCS Dennis Reußwig
2026-12-03 23:49 ` [PATCH 02/10] KVM: x86/mmu: Move TDP A/D tracking type to SPTE bits 56-57 Dennis Reußwig
@ 2026-12-03 23:49 ` Dennis Reußwig
2026-12-03 23:59 ` sashiko-bot
2026-12-03 23:49 ` [PATCH 04/10] KVM: x86/mmu: Handle the EPT supervisor shadow-stack bit like a write bit Dennis Reußwig
` (6 subsequent siblings)
9 siblings, 1 reply; 22+ messages in thread
From: Dennis Reußwig @ 2026-12-03 23:49 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Jon Kohler,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Shuah Khan
Cc: kvm, linux-kernel, linux-doc, linux-kselftest, Chao Gao,
Maxim Levitsky, Vitaly Kuznetsov, Panayotis Katsaloulis,
Dennis Reußwig
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@redhat.com>
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
^ permalink raw reply related [flat|nested] 22+ messages in thread* Re: [PATCH 03/10] KVM: VMX: Report shadow-stack accesses in EPT violations as PFERR_SS
2026-12-03 23:49 ` [PATCH 03/10] KVM: VMX: Report shadow-stack accesses in EPT violations as PFERR_SS Dennis Reußwig
@ 2026-12-03 23:59 ` sashiko-bot
0 siblings, 0 replies; 22+ messages in thread
From: sashiko-bot @ 2026-12-03 23:59 UTC (permalink / raw)
To: Dennis Reußwig; +Cc: kvm
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] KVM: x86/mmu: stale comment in permission_fault() about EPT
PFERR_SS_MASK
--
commit c0dab1dec45e42b4de309f5d5842522ed551086c
Author: Dennis Reußwig <dennis@reusswig.codes>
KVM: VMX: Report shadow-stack accesses in EPT violations as PFERR_SS
This commit defines EPT_VIOLATION_SHADOW_STACK for bit 13 of the EPT
violation exit qualification and translates it into PFERR_SS_MASK in
__vt_handle_ept_violation().
> diff --git a/arch/x86/kvm/vmx/common.h b/arch/x86/kvm/vmx/common.h
> index b2905335a2d21..eb60ba97074cf 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))
[Severity: Low]
Should the comment in permission_fault() be updated now that EPT
violations pass PFERR_SS_MASK through kvm_mmu_page_fault()?
arch/x86/kvm/mmu.h:permission_fault() {
...
/*
* 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.
*/
unsigned int pfec = access & ~PFERR_SS_MASK;
...
}
With this change, PFERR_SS_MASK is now provided on EPT violations as well
as NPT exit codes, so the comment is stale (though permission_fault()
already masks off PFERR_SS_MASK, so there is no functional impact).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes?part=3
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 04/10] KVM: x86/mmu: Handle the EPT supervisor shadow-stack bit like a write bit
2026-12-03 23:49 [PATCH 00/10] KVM: nVMX: Supervisor shadow-stack control for nested EPT and CET with eVMCS Dennis Reußwig
` (2 preceding siblings ...)
2026-12-03 23:49 ` [PATCH 03/10] KVM: VMX: Report shadow-stack accesses in EPT violations as PFERR_SS Dennis Reußwig
@ 2026-12-03 23:49 ` Dennis Reußwig
2026-12-04 0:16 ` sashiko-bot
2026-12-03 23:49 ` [PATCH 05/10] KVM: nVMX: Shadow supervisor shadow-stack control of nested EPT Dennis Reußwig
` (5 subsequent siblings)
9 siblings, 1 reply; 22+ messages in thread
From: Dennis Reußwig @ 2026-12-03 23:49 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Jon Kohler,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Shuah Khan
Cc: kvm, linux-kernel, linux-doc, linux-kselftest, Chao Gao,
Maxim Levitsky, Vitaly Kuznetsov, Panayotis Katsaloulis,
Dennis Reußwig
With supervisor shadow-stack control (EPTP bit 7), bit 60 of an EPT
leaf allows supervisor shadow-stack accesses, including shadow-stack
writes, even if the write bit of the leaf is clear (SDM Vol. 3C,
31.3.3.2). An SPTE with bit 60 set therefore lets the guest write the
page, and the MMU must handle the bit like the writable bit:
- make_spte() grants it only where writes are allowed, unsyncs the
shadowed page tables, sets the Dirty bit and marks the page dirty in
the dirty log;
- spte_write_protect() and write-protection based dirty logging clear
it, and losing it requires a TLB flush;
- spte_needs_atomic_update() covers such SPTEs without the Dirty bit,
and prefetch looks up the memslot for dirty logging.
The new ACC_EPT_SSS_MASK carries the permission from the guest walker
to make_spte() and in shadowed_translation[]. It is never part of
role.access or of the permission bitmasks.
Nothing sets ACC_EPT_SSS_MASK yet; nested EPT supervisor shadow-stack
control does in the next patch.
Signed-off-by: Dennis Reußwig <dennis@reusswig.codes>
---
checkpatch --strict suggests BIT_ULL() for the (1ull << n) definitions that
this patch and the next two add to arch/x86/include/asm/vmx.h; they follow
the style of the neighbouring EPT definitions.
---
arch/x86/include/asm/vmx.h | 1 +
arch/x86/kvm/mmu.h | 6 ++++++
arch/x86/kvm/mmu/mmu.c | 23 ++++++++++++++++-------
arch/x86/kvm/mmu/spte.c | 34 ++++++++++++++++++++++++----------
arch/x86/kvm/mmu/spte.h | 21 ++++++++++++++++++++-
5 files changed, 67 insertions(+), 18 deletions(-)
diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
index 20e2ad19d65b..79646365369f 100644
--- a/arch/x86/include/asm/vmx.h
+++ b/arch/x86/include/asm/vmx.h
@@ -570,6 +570,7 @@ enum vmcs_field {
#define VMX_EPT_ACCESS_BIT (1ull << 8)
#define VMX_EPT_DIRTY_BIT (1ull << 9)
#define VMX_EPT_SUPPRESS_VE_BIT (1ull << 63)
+#define VMX_EPT_SSS_MASK (1ull << 60)
#define VMX_EPT_RWX_MASK (VMX_EPT_READABLE_MASK | \
VMX_EPT_WRITABLE_MASK | \
diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index 2f0a6f2f5021..3d4de461e948 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -56,6 +56,12 @@ extern bool __read_mostly eager_page_split;
#define ACC_USER_EXEC_MASK ACC_USER_MASK /* EPT only */
#define ACC_EXEC_MASK 8
#define ACC_ALL (ACC_EXEC_MASK | ACC_WRITE_MASK | ACC_USER_MASK | ACC_READ_MASK)
+/*
+ * Nested EPT only: the leaf grants supervisor shadow-stack accesses (EPT bit
+ * 60 with EPTP bit 7 set). Passed with the access of a leaf SPTE and stored
+ * with it, but never part of role.access or of the permission bitmasks.
+ */
+#define ACC_EPT_SSS_MASK 16
#define KVM_MMU_CR4_ROLE_BITS (X86_CR4_PSE | X86_CR4_PAE | X86_CR4_LA57 | \
X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_PKE)
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index f89e9f8a6cc2..d2aa576f97cd 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -672,7 +672,7 @@ static gfn_t kvm_mmu_page_get_gfn(struct kvm_mmu_page *sp, int index)
static u32 kvm_mmu_page_get_access(struct kvm_mmu_page *sp, int index)
{
if (sp->shadowed_translation)
- return sp->shadowed_translation[index] & ACC_ALL;
+ return sp->shadowed_translation[index] & (ACC_ALL | ACC_EPT_SSS_MASK);
/*
* For direct MMUs (e.g. TDP or non-paging guests) or passthrough SPs,
@@ -697,7 +697,12 @@ static void kvm_mmu_page_set_translation(struct kvm_mmu_page *sp, int index,
return;
}
- WARN_ONCE(access != kvm_mmu_page_get_access(sp, index),
+ /*
+ * role.access cannot hold ACC_EPT_SSS_MASK. Direct SPs that shadow a
+ * guest huge page carry the supervisor shadow-stack grant only in
+ * their SPTEs, which inherit it on splits.
+ */
+ WARN_ONCE((access & ~ACC_EPT_SSS_MASK) != kvm_mmu_page_get_access(sp, index),
"access mismatch under %s page %llx (expected %u, got %u)\n",
sp->role.passthrough ? "passthrough" : "direct",
sp->gfn, kvm_mmu_page_get_access(sp, index), access);
@@ -1377,13 +1382,13 @@ static bool spte_write_protect(u64 *sptep, bool pt_protect)
{
u64 spte = *sptep;
- if (!is_writable_pte(spte) &&
+ if (!is_writable_pte(spte) && !is_sss_spte(spte) &&
!(pt_protect && is_mmu_writable_spte(spte)))
return false;
if (pt_protect)
spte &= ~shadow_mmu_writable_mask;
- spte = spte & ~PT_WRITABLE_MASK;
+ spte &= ~(PT_WRITABLE_MASK | VMX_EPT_SSS_MASK);
return mmu_spte_update(sptep, spte);
}
@@ -1424,11 +1429,14 @@ static bool __rmap_clear_dirty(struct kvm *kvm, struct kvm_rmap_head *rmap_head,
bool flush = false;
for_each_rmap_spte(rmap_head, &iter, sptep) {
- if (spte_ad_need_write_protect(*sptep))
+ if (spte_ad_need_write_protect(*sptep)) {
flush |= test_and_clear_bit(PT_WRITABLE_SHIFT,
(unsigned long *)sptep);
- else
+ flush |= test_and_clear_bit(SPTE_EPT_SSS_SHIFT,
+ (unsigned long *)sptep);
+ } else {
flush |= spte_clear_dirty(sptep);
+ }
}
return flush;
@@ -3245,7 +3253,8 @@ static bool kvm_mmu_prefetch_sptes(struct kvm_vcpu *vcpu, gfn_t gfn, u64 *sptep,
if (WARN_ON_ONCE(nr_pages > PTE_PREFETCH_NUM))
return false;
- slot = gfn_to_memslot_dirty_bitmap(vcpu, gfn, access & ACC_WRITE_MASK);
+ slot = gfn_to_memslot_dirty_bitmap(vcpu, gfn,
+ access & (ACC_WRITE_MASK | ACC_EPT_SSS_MASK));
if (!slot)
return false;
diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c
index 5fc27e9733b3..5251d0384181 100644
--- a/arch/x86/kvm/mmu/spte.c
+++ b/arch/x86/kvm/mmu/spte.c
@@ -180,9 +180,11 @@ bool spte_needs_atomic_update(u64 spte)
* Dirty and Accessed bits can be set by the CPU. Ignore the Accessed
* bit, as KVM tolerates false negatives/positives, e.g. KVM doesn't
* invalidate TLBs when aging SPTEs, and so it's safe to clobber the
- * Accessed bit (and rare in practice).
+ * Accessed bit (and rare in practice). Shadow-stack writes through a
+ * supervisor shadow-stack SPTE also set the Dirty bit.
*/
- return is_writable_pte(spte) && !(spte & shadow_dirty_mask);
+ return (is_writable_pte(spte) || is_sss_spte(spte)) &&
+ !(spte & shadow_dirty_mask);
}
bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
@@ -249,14 +251,18 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
if (host_writable)
spte |= shadow_host_writable_mask;
else
- pte_access &= ~ACC_WRITE_MASK;
+ pte_access &= ~(ACC_WRITE_MASK | ACC_EPT_SSS_MASK);
if (shadow_me_value && !kvm_is_mmio_pfn(pfn, &is_host_mmio))
spte |= shadow_me_value;
spte |= (u64)pfn << PAGE_SHIFT;
- if (pte_access & ACC_WRITE_MASK) {
+ /*
+ * A supervisor shadow-stack SPTE lets L2 write the page with shadow-stack
+ * accesses, so it is subject to the same rules as a writable SPTE.
+ */
+ if (pte_access & (ACC_WRITE_MASK | ACC_EPT_SSS_MASK)) {
/*
* Unsync shadow pages that are reachable by the new, writable
* SPTE. Write-protect the SPTE if the page can't be unsync'd,
@@ -270,12 +276,19 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
* changing PFNs without first zapping the old SPTE, which is
* guaranteed by both the shadow MMU and the TDP MMU.
*/
- if ((!is_last_spte(old_spte, level) || !is_writable_pte(old_spte)) &&
- mmu_try_to_unsync_pages(vcpu->kvm, slot, gfn, synchronizing, prefetch))
+ if ((!is_last_spte(old_spte, level) ||
+ !(is_writable_pte(old_spte) ||
+ (is_shadow_present_pte(old_spte) && is_sss_spte(old_spte)))) &&
+ mmu_try_to_unsync_pages(vcpu->kvm, slot, gfn, synchronizing, prefetch)) {
wrprot = true;
- else
- spte |= PT_WRITABLE_MASK | shadow_mmu_writable_mask |
- shadow_dirty_mask;
+ } else {
+ if (pte_access & ACC_WRITE_MASK)
+ spte |= PT_WRITABLE_MASK | shadow_mmu_writable_mask;
+ if (pte_access & ACC_EPT_SSS_MASK)
+ spte |= VMX_EPT_SSS_MASK;
+
+ spte |= shadow_dirty_mask;
+ }
}
if (prefetch && !synchronizing)
@@ -290,7 +303,8 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
* Unlike folios, memslots can be safely marked dirty out of mmu_lock,
* i.e. in the fast page fault handler.
*/
- if ((spte & PT_WRITABLE_MASK) && kvm_slot_dirty_track_enabled(slot)) {
+ if ((spte & (PT_WRITABLE_MASK | VMX_EPT_SSS_MASK)) &&
+ kvm_slot_dirty_track_enabled(slot)) {
/* Enforced by kvm_mmu_hugepage_adjust. */
WARN_ON_ONCE(level > PG_LEVEL_4K);
mark_page_dirty_in_slot(vcpu->kvm, slot, gfn);
diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h
index 237a0484367a..fa586c84204a 100644
--- a/arch/x86/kvm/mmu/spte.h
+++ b/arch/x86/kvm/mmu/spte.h
@@ -97,6 +97,10 @@ static_assert(!(EPT_SPTE_MMU_WRITABLE & SPTE_TDP_AD_MASK));
static_assert(!(EPT_SPTE_HOST_WRITABLE & SHADOW_ACC_TRACK_SAVED_MASK));
static_assert(!(EPT_SPTE_MMU_WRITABLE & SHADOW_ACC_TRACK_SAVED_MASK));
+/* Bit 60 is the EPT supervisor shadow-stack bit, see is_sss_spte(). */
+static_assert(!(VMX_EPT_SSS_MASK & (SPTE_TDP_AD_MASK | SHADOW_ACC_TRACK_SAVED_MASK |
+ EPT_SPTE_HOST_WRITABLE | EPT_SPTE_MMU_WRITABLE)));
+
/* Defined only to keep the above static asserts readable. */
#undef SHADOW_ACC_TRACK_SAVED_MASK
@@ -487,6 +491,20 @@ static inline bool is_mmu_writable_spte(u64 spte)
return spte & shadow_mmu_writable_mask;
}
+/*
+ * Bit 60 of a shadow-present SPTE is set only by nested EPT with supervisor
+ * shadow-stack control, where it lets L2 write supervisor shadow stacks even
+ * if PT_WRITABLE_MASK is clear. KVM must treat it like a write permission:
+ * grant it only where writes are allowed and drop it when write-protecting.
+ */
+#define SPTE_EPT_SSS_SHIFT 60
+static_assert(BIT_ULL(SPTE_EPT_SSS_SHIFT) == VMX_EPT_SSS_MASK);
+
+static inline bool is_sss_spte(u64 spte)
+{
+ return spte & VMX_EPT_SSS_MASK;
+}
+
/*
* Returns true if the access indicated by @fault is forbidden by the existing
* SPTE protections.
@@ -548,7 +566,8 @@ static inline bool spte_permission_fault(struct kvm_mmu *mmu, u64 spte,
*/
static inline bool leaf_spte_change_needs_tlb_flush(u64 old_spte, u64 new_spte)
{
- return is_mmu_writable_spte(old_spte) && !is_mmu_writable_spte(new_spte);
+ return (is_mmu_writable_spte(old_spte) && !is_mmu_writable_spte(new_spte)) ||
+ (is_sss_spte(old_spte) && !is_sss_spte(new_spte));
}
static inline u64 get_mmio_spte_generation(u64 spte)
--
2.53.0
^ permalink raw reply related [flat|nested] 22+ messages in thread* Re: [PATCH 04/10] KVM: x86/mmu: Handle the EPT supervisor shadow-stack bit like a write bit
2026-12-03 23:49 ` [PATCH 04/10] KVM: x86/mmu: Handle the EPT supervisor shadow-stack bit like a write bit Dennis Reußwig
@ 2026-12-04 0:16 ` sashiko-bot
2026-12-04 0:41 ` Dennis Reußwig
0 siblings, 1 reply; 22+ messages in thread
From: sashiko-bot @ 2026-12-04 0:16 UTC (permalink / raw)
To: Dennis Reußwig; +Cc: kvm
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] KVM: x86/mmu: Direct shadow page aliasing leaks EPT SSS
permission
- [High] KVM: x86/mmu: omit shadow_mmu_writable_mask on SSS SPTEs skips
TLB flushes
- [High] KVM: x86/mmu: SSS read faults livelock when make_spte() strips
bit 60
- [Medium] KVM: x86/mmu: Unconditional second LOCK BTR in
__rmap_clear_dirty()
--
commit 60a373f236eec5c8d97428ecb5498541f1b762a3
Author: Dennis Reußwig <dennis@reusswig.codes>
KVM: x86/mmu: Handle the EPT supervisor shadow-stack bit like a write bit
This commit introduces ACC_EPT_SSS_MASK and updates the x86 MMU to treat
EPT bit 60 (supervisor shadow-stack) like the writable bit during SPTE
creation, write-protection, dirty logging, and TLB flushing.
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index f89e9f8a6cc2f..d2aa576f97cdf 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
[ ... ]
> @@ -697,7 +697,12 @@ static void kvm_mmu_page_set_translation(struct kvm_mmu_page *sp, int index,
> return;
> }
>
> - WARN_ONCE(access != kvm_mmu_page_get_access(sp, index),
> + /*
> + * role.access cannot hold ACC_EPT_SSS_MASK. Direct SPs that shadow a
> + * guest huge page carry the supervisor shadow-stack grant only in
> + * their SPTEs, which inherit it on splits.
> + */
> + WARN_ONCE((access & ~ACC_EPT_SSS_MASK) != kvm_mmu_page_get_access(sp, index),
> "access mismatch under %s page %llx (expected %u, got %u)\n",
> sp->role.passthrough ? "passthrough" : "direct",
> sp->gfn, kvm_mmu_page_get_access(sp, index), access);
[Severity: High]
Can excluding ACC_EPT_SSS_MASK from role.access cause direct shadow pages to
alias across SSS=1 and SSS=0 guest huge pages?
When L1 maps the same 2MiB or 1GiB GFN at two L2 GPAs with matching R/W/X/XU
bits, one with VMX_EPT_SSS_MASK set and one with it clear,
shadow_mmu_get_sp_for_split() passes access to kvm_mmu_child_role(), where
role.access = access truncates bit 4. Both huge pages then hash to the same
(gfn, role.word) key and share a single direct struct kvm_mmu_page.
If the SSS=1 huge page is split first, shadow_mmu_split_huge_page() populates
sp->spt[] with VMX_EPT_SSS_MASK set; splitting the SSS=0 huge page reuses
that SP, skips the already-present SPTEs, and links them under the SSS=0
parent. L2 then gets supervisor shadow-stack write access on an L2 GPA where
L1 cleared bit 60.
Separately, direct_pte_prefetch_many() reads only sp->role.access, so
prefetching sibling 4KiB SPTEs under a direct SP shadowing an SSS=1 huge page
silently drops ACC_EPT_SSS_MASK.
Storing the SSS permission in union kvm_mmu_page_role (which still has spare
padding bits) would keep SSS=1 and SSS=0 direct SPs distinct and preserve the
bit during prefetch.
[ ... ]
> @@ -1424,11 +1429,14 @@ static bool __rmap_clear_dirty(struct kvm *kvm, struct kvm_rmap_head *rmap_head,
> bool flush = false;
>
> for_each_rmap_spte(rmap_head, &iter, sptep) {
> - if (spte_ad_need_write_protect(*sptep))
> + if (spte_ad_need_write_protect(*sptep)) {
> flush |= test_and_clear_bit(PT_WRITABLE_SHIFT,
> (unsigned long *)sptep);
> - else
> + flush |= test_and_clear_bit(SPTE_EPT_SSS_SHIFT,
> + (unsigned long *)sptep);
> + } else {
> flush |= spte_clear_dirty(sptep);
> + }
> }
>
> return flush;
[Severity: Medium]
Does this unconditionally issue a second locked atomic RMW on every
write-protect-mode SPTE even when VMX_EPT_SSS_MASK is clear?
__rmap_clear_dirty() runs under exclusive write_lock(&kvm->mmu_lock) across
every 4KiB SPTE in a memslot during dirty-logging setup and dirty-log
clearing (kvm_mmu_slot_leaf_clear_dirty() and
kvm_mmu_clear_dirty_pt_masked()). Doubling the serializing bit-clear
operations per SPTE extends mmu_lock hold time and stalls concurrent vCPU
page faults even when EPT SSS is unused.
Since VMX_EPT_SSS_MASK is never set by hardware or locklessly in
fast_page_fault(), loading spte = *sptep once and guarding the second
test_and_clear_bit() with is_sss_spte(spte) avoids the extra atomic on
non-SSS SPTEs.
[ ... ]
> diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c
> index 5fc27e9733b38..5251d03841815 100644
> --- a/arch/x86/kvm/mmu/spte.c
> +++ b/arch/x86/kvm/mmu/spte.c
[ ... ]
> @@ -249,14 +251,18 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
> if (host_writable)
> spte |= shadow_host_writable_mask;
> else
> - pte_access &= ~ACC_WRITE_MASK;
> + pte_access &= ~(ACC_WRITE_MASK | ACC_EPT_SSS_MASK);
[Severity: High]
Can clearing ACC_EPT_SSS_MASK when !host_writable livelock L2 on supervisor
shadow-stack read faults?
With EPTP bit 7 set, EPT leaf bit 60 is required for supervisor shadow-stack
reads (such as RET or RSTORSSP), which raise an EPT violation with
EPT_VIOLATION_SHADOW_STACK set and EPT_VIOLATION_ACC_WRITE clear.
__vt_handle_ept_violation() leaves fault->write false, so
__kvm_mmu_faultin_pfn() omits FOLL_WRITE and fails to break COW/KSM/zero
pages. make_spte() then strips ACC_EPT_SSS_MASK and installs an SPTE without
bit 60, causing L2 to re-fault forever.
The same livelock happens on a write-tracked GFN when
mmu_try_to_unsync_pages() fails and make_spte() sets wrprot = true: both
page_fault_handle_page_track() and mmu_set_spte() gate on fault->write, so
KVM returns RET_PF_FIXED or RET_PF_SPURIOUS instead of
RET_PF_WRITE_PROTECTED.
[ ... ]
> - if ((!is_last_spte(old_spte, level) || !is_writable_pte(old_spte)) &&
> - mmu_try_to_unsync_pages(vcpu->kvm, slot, gfn, synchronizing, prefetch))
> + if ((!is_last_spte(old_spte, level) ||
> + !(is_writable_pte(old_spte) ||
> + (is_shadow_present_pte(old_spte) && is_sss_spte(old_spte)))) &&
> + mmu_try_to_unsync_pages(vcpu->kvm, slot, gfn, synchronizing, prefetch)) {
> wrprot = true;
> - else
> - spte |= PT_WRITABLE_MASK | shadow_mmu_writable_mask |
> - shadow_dirty_mask;
> + } else {
> + if (pte_access & ACC_WRITE_MASK)
> + spte |= PT_WRITABLE_MASK | shadow_mmu_writable_mask;
> + if (pte_access & ACC_EPT_SSS_MASK)
> + spte |= VMX_EPT_SSS_MASK;
> +
> + spte |= shadow_dirty_mask;
> + }
> }
[Severity: High]
Can omitting shadow_mmu_writable_mask on SSS-only SPTEs cause
write-protection to skip a required remote TLB flush?
For a read-only supervisor shadow-stack leaf (ACC_EPT_SSS_MASK without
ACC_WRITE_MASK), make_spte() sets VMX_EPT_SSS_MASK while leaving
shadow_mmu_writable_mask clear. Dirty-logging paths clear VMX_EPT_SSS_MASK
under mmu_lock and drop the lock before flushing remote TLBs:
CPU0 (dirty logging) CPU1 (pt_protect)
kvm_mmu_slot_apply_flags()
kvm_mmu_slot_leaf_clear_dirty()
write_lock(&kvm->mmu_lock)
__rmap_clear_dirty()
clear VMX_EPT_SSS_MASK
write_unlock(&kvm->mmu_lock)
account_shadowed()
write_lock(&kvm->mmu_lock)
spte_write_protect(..., true)
returns false <-- skips TLB flush
write_unlock(&kvm->mmu_lock)
kvm_flush_remote_tlbs_memslot()
Because PT_WRITABLE_MASK, VMX_EPT_SSS_MASK, and shadow_mmu_writable_mask are
all clear in that window, spte_write_protect() returns false and
account_shadowed() skips kvm_flush_remote_tlbs_gfn(). A remote vCPU can
still hold a stale TLB entry with bit 60 set and write directly into a
shadowed guest page table via shadow-stack accesses.
FNAME(sync_spte) -> leaf_spte_change_needs_tlb_flush() misses the flush in
the same window, and check_spte_writable_invariants() does not check that
is_sss_spte() entries are MMU-writable and host-writable.
Setting shadow_mmu_writable_mask whenever ACC_EPT_SSS_MASK is granted
preserves KVM's MMU-writable TLB flush invariant.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes?part=4
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [PATCH 04/10] KVM: x86/mmu: Handle the EPT supervisor shadow-stack bit like a write bit
2026-12-04 0:16 ` sashiko-bot
@ 2026-12-04 0:41 ` Dennis Reußwig
0 siblings, 0 replies; 22+ messages in thread
From: Dennis Reußwig @ 2026-12-04 0:41 UTC (permalink / raw)
To: sashiko-bot; +Cc: kvm, Dennis Reußwig
> [Severity: High]
> Can excluding ACC_EPT_SSS_MASK from role.access cause direct shadow pages to
> alias across SSS=1 and SSS=0 guest huge pages?
Good catch, real bug, fixed in v2.
> [Severity: High]
> Can clearing ACC_EPT_SSS_MASK when !host_writable livelock L2 on supervisor
> shadow-stack read faults?
Good catch, real bug, fixed in v2.
> [Severity: High]
> Can omitting shadow_mmu_writable_mask on SSS-only SPTEs cause
> write-protection to skip a required remote TLB flush?
Good catch, real bug, fixed in v2.
Setting shadow_mmu_writable_mask on these SPTEs would not work,
though: fast_page_fault() makes an MMU-writable SPTE writable on a
write fault without taking mmu_lock, while bit 60 must not allow
ordinary writes. v2 adds a separate software bit (MMU-SSS, bit 59)
that is set with bit 60 and that write-protection for shadow paging
checks and clears, with a flush.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 05/10] KVM: nVMX: Shadow supervisor shadow-stack control of nested EPT
2026-12-03 23:49 [PATCH 00/10] KVM: nVMX: Supervisor shadow-stack control for nested EPT and CET with eVMCS Dennis Reußwig
` (3 preceding siblings ...)
2026-12-03 23:49 ` [PATCH 04/10] KVM: x86/mmu: Handle the EPT supervisor shadow-stack bit like a write bit Dennis Reußwig
@ 2026-12-03 23:49 ` Dennis Reußwig
2026-12-04 0:17 ` sashiko-bot
2026-12-03 23:49 ` [PATCH 06/10] KVM: nVMX: Advertise supervisor shadow-stack control for " Dennis Reußwig
` (4 subsequent siblings)
9 siblings, 1 reply; 22+ messages in thread
From: Dennis Reußwig @ 2026-12-03 23:49 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Jon Kohler,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Shuah Khan
Cc: kvm, linux-kernel, linux-doc, linux-kselftest, Chao Gao,
Maxim Levitsky, Vitaly Kuznetsov, Panayotis Katsaloulis,
Dennis Reußwig
If bit 7 of L1's EPTP is set, supervisor shadow-stack accesses of L2
are allowed if every entry of the walk is readable, every non-leaf
entry is writable and the leaf sets bit 60; the write bit of the leaf
does not matter (SDM Vol. 3C, 31.3.3.2). User shadow-stack accesses
and the accesses to the guest paging structures follow the normal
rules.
Implement this in the nested EPT MMU:
- add role.ept_sss, so that shadow pages for EPTP bit 7 set and clear
are not shared, and set bit 7 in the EPTP of such roots so that the
CPU enforces bit 60 of the shadow SPTEs;
- in FNAME(walk_addr_generic), check supervisor shadow-stack accesses
against bit 60 and set the Dirty flag for them like for writes, and
pass the permission to the SPTEs in FNAME(fetch),
FNAME(prefetch_gpte) and FNAME(sync_spte);
- report bit 13 (shadow-stack access) and bit 14 (bit 60 of the leaf)
in the exit qualification of EPT violations reflected to L1.
The role grows to 22 bits. Update the comment that bounds the number
of shadow pages per gfn: it was already one bit low (21 - 2 - 2 - 2 =
15, not 14) and named execonly, which is in the extended role.
L1 cannot set EPTP bit 7 yet, because nested_vmx_check_eptp() rejects
it; the next patch allows it.
Signed-off-by: Dennis Reußwig <dennis@reusswig.codes>
---
Documentation/virt/kvm/x86/mmu.rst | 4 ++
arch/x86/include/asm/kvm_host.h | 18 +++++---
arch/x86/include/asm/vmx.h | 2 +
arch/x86/kvm/mmu.h | 2 +-
arch/x86/kvm/mmu/mmu.c | 12 +++--
arch/x86/kvm/mmu/paging_tmpl.h | 90 +++++++++++++++++++++++++++++++++++---
arch/x86/kvm/vmx/nested.c | 1 +
arch/x86/kvm/vmx/vmx.c | 4 ++
8 files changed, 119 insertions(+), 14 deletions(-)
diff --git a/Documentation/virt/kvm/x86/mmu.rst b/Documentation/virt/kvm/x86/mmu.rst
index 666aa179601a..4067b483876e 100644
--- a/Documentation/virt/kvm/x86/mmu.rst
+++ b/Documentation/virt/kvm/x86/mmu.rst
@@ -206,6 +206,10 @@ Shadow pages contain the following information:
The page is not backed by a guest page table, but its first entry
points to one. This is set if NPT uses 5-level page tables (host
CR4.LA57=1) and is shadowing L1's 4-level NPT (L1 CR4.LA57=0).
+ role.ept_sss:
+ Is 1 if the page shadows L1 EPT with supervisor shadow-stack control
+ (EPTP bit 7). Bit 60 of a leaf SPTE then grants L2 supervisor
+ shadow-stack accesses, and KVM treats it like a write permission.
mmu_valid_gen:
The MMU generation of this page, used to fast zap of all MMU pages within a
VM without blocking vCPUs too long. Specifically, KVM updates the per-VM
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 3efef3415f8e..43e582507e39 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -319,14 +319,14 @@ extern struct kvm_host_values kvm_host;
* the number of unique SPs that can theoretically be created is 2^n, where n
* is the number of bits that are used to compute the role.
*
- * But, even though there are 21 bits in the mask below, not all combinations
+ * But, even though there are 22 bits in the mask below, not all combinations
* of modes and flags are possible:
*
* - invalid shadow pages are not accounted, mirror pages are not shadowed,
- * so the bits are effectively 19.
+ * so the bits are effectively 20.
*
* - quadrant will only be used if has_4_byte_gpte=1 (non-PAE paging);
- * execonly and ad_disabled are only used for nested EPT which has
+ * ad_disabled and ept_sss are only used for nested EPT which has
* has_4_byte_gpte=0. Therefore, 2 bits are always unused.
*
* - the 4 bits of level are effectively limited to the values 2/3/4/5,
@@ -338,7 +338,7 @@ extern struct kvm_host_values kvm_host;
* therefore these two bits only give rise to 3 possibilities.
*
* Therefore, the maximum number of possible upper-level shadow pages for a
- * single gfn is a bit less than 2^14.
+ * single gfn is a bit less than 2^16.
*/
union kvm_mmu_page_role {
u32 word;
@@ -366,7 +366,15 @@ union kvm_mmu_page_role {
*/
unsigned cr4_smep:1;
- unsigned:3;
+ /*
+ * Nested EPT with supervisor shadow-stack control (EPTP bit 7).
+ * EPT bit 60 of a leaf SPTE grants supervisor shadow-stack
+ * accesses only if the EPTP sets bit 7, so SPTEs built for one
+ * setting are not valid for the other.
+ */
+ unsigned ept_sss:1;
+
+ unsigned:2;
/*
* This is left at the top of the word so that
diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
index 79646365369f..df6feba112f7 100644
--- a/arch/x86/include/asm/vmx.h
+++ b/arch/x86/include/asm/vmx.h
@@ -559,6 +559,7 @@ enum vmcs_field {
#define VMX_EPTP_PWL_4 0x18ull
#define VMX_EPTP_PWL_5 0x20ull
#define VMX_EPTP_AD_ENABLE_BIT (1ull << 6)
+#define VMX_EPTP_SSS_BIT (1ull << 7)
/* The EPTP memtype is encoded in bits 2:0, i.e. doesn't need to be shifted. */
#define VMX_EPTP_MT_MASK 0x7ull
#define VMX_EPTP_MT_WB X86_MEMTYPE_WB
@@ -632,6 +633,7 @@ enum vm_entry_failure_code {
#define EPT_VIOLATION_GVA_WRITABLE BIT(10)
#define EPT_VIOLATION_GVA_NX BIT(11)
#define EPT_VIOLATION_SHADOW_STACK BIT(13)
+#define EPT_VIOLATION_SSS_PAGE BIT(14)
#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 3d4de461e948..09f6f48ebc5f 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -151,7 +151,7 @@ void kvm_init_shadow_npt_mmu(struct kvm_vcpu *vcpu, unsigned long cr4,
u64 efer, gpa_t nested_cr3, u64 misc_ctl);
void kvm_init_shadow_ept_mmu(struct kvm_vcpu *vcpu, bool execonly,
int huge_page_level, bool accessed_dirty,
- bool mbec, gpa_t new_eptp);
+ bool mbec, bool sss, gpa_t new_eptp);
int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u64 error_code,
void *insn, int insn_len);
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index d2aa576f97cd..39637dca870f 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -246,6 +246,11 @@ static inline bool has_pferr_fetch(struct kvm_pagewalk *w)
return w->cpu_role.ext.has_pferr_fetch;
}
+static inline bool is_ept_sss(struct kvm_pagewalk *w)
+{
+ return w->cpu_role.base.ept_sss;
+}
+
static inline bool is_cr0_pg(struct kvm_pagewalk *w)
{
return w->cpu_role.base.level > 0;
@@ -6217,7 +6222,7 @@ EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_init_shadow_npt_mmu);
static union kvm_cpu_role
kvm_calc_shadow_ept_root_page_role(struct kvm_vcpu *vcpu, bool accessed_dirty,
- bool execonly, u8 level, bool mbec)
+ bool execonly, u8 level, bool mbec, bool sss)
{
union kvm_cpu_role role = {0};
@@ -6228,6 +6233,7 @@ kvm_calc_shadow_ept_root_page_role(struct kvm_vcpu *vcpu, bool accessed_dirty,
WARN_ON_ONCE(is_smm(vcpu));
role.base.level = level;
role.base.cr4_smep = mbec;
+ role.base.ept_sss = sss;
role.base.has_4_byte_gpte = false;
role.base.direct = false;
role.base.ad_disabled = !accessed_dirty;
@@ -6243,13 +6249,13 @@ kvm_calc_shadow_ept_root_page_role(struct kvm_vcpu *vcpu, bool accessed_dirty,
void kvm_init_shadow_ept_mmu(struct kvm_vcpu *vcpu, bool execonly,
int huge_page_level, bool accessed_dirty,
- bool mbec, gpa_t new_eptp)
+ bool mbec, bool sss, gpa_t new_eptp)
{
struct kvm_mmu *context = &vcpu->arch.guest_mmu;
u8 level = vmx_eptp_page_walk_level(new_eptp);
union kvm_cpu_role new_mode =
kvm_calc_shadow_ept_root_page_role(vcpu, accessed_dirty,
- execonly, level, mbec);
+ execonly, level, mbec, sss);
struct kvm_pagewalk *ngpa_walk = &vcpu->arch.ngpa_walk;
diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h
index 939a10fc1110..02421e74ec36 100644
--- a/arch/x86/kvm/mmu/paging_tmpl.h
+++ b/arch/x86/kvm/mmu/paging_tmpl.h
@@ -88,6 +88,8 @@ struct guest_walker {
bool pte_writable[PT_MAX_FULL_LEVELS];
unsigned int pt_access[PT_MAX_FULL_LEVELS];
unsigned int pte_access;
+ /* ACC_EPT_SSS_MASK if the leaf grants supervisor shadow-stack accesses. */
+ unsigned int sss_access;
gfn_t gfn;
struct x86_exception fault;
};
@@ -124,6 +126,55 @@ static inline void FNAME(protect_clean_gpte)(struct kvm_pagewalk *w, unsigned *a
*access &= mask;
}
+/*
+ * Supervisor shadow-stack accesses through nested EPT with EPTP bit 7 set are
+ * governed by bit 60 of the leaf instead of its write bit: the access is
+ * allowed if the leaf sets bit 60, every entry is readable and every non-leaf
+ * entry is writable (SDM Vol. 3C 31.3.3.2). User shadow-stack accesses keep
+ * the normal rules. For EPT, PFERR_USER_MASK reports a user-mode linear
+ * address (advanced VM-exit information). The CPU also reports the guest
+ * paging-structure accesses of a shadow-stack access as shadow-stack
+ * accesses; those are ordinary reads and writes of the paging structure.
+ */
+static inline bool FNAME(is_sss_access)(struct kvm_pagewalk *w, u64 access)
+{
+#if PTTYPE == PTTYPE_EPT
+ return is_ept_sss(w) && (access & PFERR_SS_MASK) &&
+ !(access & (PFERR_USER_MASK | PFERR_GUEST_PAGE_MASK));
+#else
+ return false;
+#endif
+}
+
+/*
+ * Return ACC_EPT_SSS_MASK if @gpte grants supervisor shadow-stack accesses.
+ * @pt_access holds the ACC_* permissions of the non-leaf entries above it.
+ * Bit 60 also allows shadow-stack writes, so it is withheld from leaves whose
+ * Dirty flag is clear unless @dirty: the first shadow-stack access then
+ * faults and the walker sets the Dirty flag, as for writes.
+ */
+static inline unsigned int FNAME(gpte_sss_access)(struct kvm_pagewalk *w,
+ unsigned int pt_access,
+ pt_element_t gpte, bool dirty)
+{
+#if PTTYPE == PTTYPE_EPT
+ if (!is_ept_sss(w) || !(gpte & VMX_EPT_SSS_MASK) ||
+ !(gpte & VMX_EPT_READABLE_MASK))
+ return 0;
+
+ if ((pt_access & (ACC_READ_MASK | ACC_WRITE_MASK)) !=
+ (ACC_READ_MASK | ACC_WRITE_MASK))
+ return 0;
+
+ if (!dirty && PT_HAVE_ACCESSED_DIRTY(w) && !(gpte & PT_GUEST_DIRTY_MASK))
+ return 0;
+
+ return ACC_EPT_SSS_MASK;
+#else
+ return 0;
+#endif
+}
+
static inline int FNAME(is_present_gpte)(struct kvm_pagewalk *w,
unsigned long pte)
{
@@ -329,6 +380,12 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
u64 walk_nx_mask = 0;
const int write_fault = access & PFERR_WRITE_MASK;
const int fetch_fault = access & PFERR_FETCH_MASK;
+ /*
+ * Supervisor shadow-stack accesses under EPTP bit 7 can write the page,
+ * so they set the Dirty flag even when they only read the shadow stack.
+ */
+ const bool sss_fault = FNAME(is_sss_access)(w, access);
+ const bool dirty_fault = write_fault || sss_fault;
/*
* Note! Track the error_code that's common to legacy shadow paging
* and NPT shadow paging as a u16 to guard against unintentionally
@@ -452,7 +509,13 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
/* Convert to ACC_*_MASK flags for struct guest_walker. */
walker->pte_access = FNAME(gpte_access)(pte_access ^ walk_nx_mask);
- errcode = permission_fault(vcpu, w, walker->pte_access, pte_pkey, access);
+ walker->sss_access = FNAME(gpte_sss_access)(w,
+ walker->pt_access[walker->level - 1],
+ pte, true);
+ if (sss_fault)
+ errcode = walker->sss_access ? 0 : PFERR_PRESENT_MASK;
+ else
+ errcode = permission_fault(vcpu, w, walker->pte_access, pte_pkey, access);
if (unlikely(errcode))
goto error;
@@ -472,9 +535,12 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
walker->gfn = real_gpa >> PAGE_SHIFT;
- if (!write_fault)
+ if (!dirty_fault) {
FNAME(protect_clean_gpte)(w, &walker->pte_access, pte);
- else
+ walker->sss_access = FNAME(gpte_sss_access)(w,
+ walker->pt_access[walker->level - 1],
+ pte, false);
+ } else {
/*
* On a write fault, fold the dirty bit into accessed_dirty.
* For modes without A/D bits support accessed_dirty will be
@@ -482,10 +548,11 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
*/
accessed_dirty &= pte >>
(PT_GUEST_DIRTY_SHIFT - PT_GUEST_ACCESSED_SHIFT);
+ }
if (unlikely(!accessed_dirty)) {
ret = FNAME(update_accessed_dirty_bits)(vcpu, w, walker,
- addr, write_fault);
+ addr, dirty_fault);
if (unlikely(ret < 0))
goto error;
else if (ret) {
@@ -556,6 +623,14 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
if (is_cr4_smep(w))
walker->fault.exit_qualification |=
EPT_VIOLATION_USER_EXEC_TO_PROT(pte_access);
+ if (access & PFERR_SS_MASK)
+ walker->fault.exit_qualification |= EPT_VIOLATION_SHADOW_STACK;
+ /*
+ * Bit 14 mirrors bit 60 of the leaf; it is undefined if the walk
+ * stopped earlier, so report the last entry read either way.
+ */
+ if (is_ept_sss(w) && (pte & VMX_EPT_SSS_MASK))
+ walker->fault.exit_qualification |= EPT_VIOLATION_SSS_PAGE;
}
#endif
walker->fault.address = addr;
@@ -591,6 +666,8 @@ FNAME(prefetch_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
gfn = gpte_to_gfn(gpte);
pte_access = sp->role.access & FNAME(gpte_access)(gpte);
FNAME(protect_clean_gpte)(vcpu->arch.mmu->w, &pte_access, gpte);
+ pte_access |= FNAME(gpte_sss_access)(vcpu->arch.mmu->w, sp->role.access,
+ gpte, false);
return kvm_mmu_prefetch_sptes(vcpu, gfn, spte, 1, pte_access);
}
@@ -789,7 +866,8 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault,
if (KVM_BUG_ON(it.level != fault->goal_level, vcpu->kvm))
return -EIO;
- ret = mmu_set_spte(vcpu, fault->slot, it.sptep, gw->pte_access,
+ ret = mmu_set_spte(vcpu, fault->slot, it.sptep,
+ gw->pte_access | gw->sss_access,
base_gfn, fault->pfn, fault);
if (ret == RET_PF_SPURIOUS)
return ret;
@@ -973,6 +1051,8 @@ static int FNAME(sync_spte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, int
pte_access = sp->role.access;
pte_access &= FNAME(gpte_access)(gpte);
FNAME(protect_clean_gpte)(vcpu->arch.mmu->w, &pte_access, gpte);
+ pte_access |= FNAME(gpte_sss_access)(vcpu->arch.mmu->w, sp->role.access,
+ gpte, false);
if (sync_mmio_spte(vcpu, &sp->spt[i], gfn, pte_access))
return 0;
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index a7c8bbdfe4ca..dc7199855497 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -519,6 +519,7 @@ static void nested_ept_new_eptp(struct kvm_vcpu *vcpu)
kvm_init_shadow_ept_mmu(vcpu, execonly, ept_lpage_level,
nested_ept_ad_enabled(vcpu),
nested_ept_mbec_enabled(vcpu),
+ nested_ept_get_eptp(vcpu) & VMX_EPTP_SSS_BIT,
nested_ept_get_eptp(vcpu));
}
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 68fa251dda60..57aa8b3be509 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -3361,6 +3361,10 @@ static u64 construct_eptp(hpa_t root_hpa)
if (enable_ept_ad_bits && !root->role.ad_disabled)
eptp |= VMX_EPTP_AD_ENABLE_BIT;
+ /* Only nested EPT roots for an L1 EPTP with bit 7 set. */
+ if (root->role.ept_sss)
+ eptp |= VMX_EPTP_SSS_BIT;
+
return eptp;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 22+ messages in thread* Re: [PATCH 05/10] KVM: nVMX: Shadow supervisor shadow-stack control of nested EPT
2026-12-03 23:49 ` [PATCH 05/10] KVM: nVMX: Shadow supervisor shadow-stack control of nested EPT Dennis Reußwig
@ 2026-12-04 0:17 ` sashiko-bot
2026-12-04 0:41 ` Dennis Reußwig
0 siblings, 1 reply; 22+ messages in thread
From: sashiko-bot @ 2026-12-04 0:17 UTC (permalink / raw)
To: Dennis Reußwig; +Cc: kvm
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] KVM: nVMX: supervisor shadow-stack reads livelock with
fault->write=false
- [High] KVM: nVMX: direct SP role omits ACC_EPT_SSS_MASK, aliasing huge
EPT pages
- [High] KVM: x86/mmu: missing TLB flush on write-protect of SSS-only
SPTEs
- [Medium] KVM: x86/mmu: FNAME(sync_spte)() uses active MMU ept_sss
instead of sp->role
--
commit 54eeafaa463b601d88199d358ce23d372c136cef
Author: Dennis Reußwig <dennis@reusswig.codes>
KVM: nVMX: Shadow supervisor shadow-stack control of nested EPT
This commit adds shadow MMU support for nested EPT supervisor shadow-stack
control (EPTP bit 7), including a new role.ept_sss bit, walker checks and
dirty-bit updates for supervisor shadow-stack accesses, bit 60 propagation
to shadow SPTEs, and EPT violation exit qualification bits 13 and 14.
> diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h
> index 939a10fc11107..02421e74ec369 100644
> --- a/arch/x86/kvm/mmu/paging_tmpl.h
> +++ b/arch/x86/kvm/mmu/paging_tmpl.h
[ ... ]
> @@ -329,6 +380,12 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
> u64 walk_nx_mask = 0;
> const int write_fault = access & PFERR_WRITE_MASK;
> const int fetch_fault = access & PFERR_FETCH_MASK;
> + /*
> + * Supervisor shadow-stack accesses under EPTP bit 7 can write the page,
> + * so they set the Dirty flag even when they only read the shadow stack.
> + */
> + const bool sss_fault = FNAME(is_sss_access)(w, access);
> + const bool dirty_fault = write_fault || sss_fault;
> /*
> * Note! Track the error_code that's common to legacy shadow paging
> * and NPT shadow paging as a u16 to guard against unintentionally
[Severity: High]
Can supervisor shadow-stack reads livelock L2 because fault->write stays
false after FNAME(walk_addr_generic)() returns?
A supervisor shadow-stack read under EPTP bit 7 arrives with PFERR_SS_MASK
set and PFERR_WRITE_MASK clear, so kvm_mmu_do_page_fault() sets
fault->write = false. When the backing host page is read-only (such as the
shared zero page or a CoW page), __kvm_mmu_faultin_pfn() omits FOLL_WRITE
and leaves fault->map_writable = false. make_spte() then clears
ACC_EPT_SSS_MASK and installs a shadow SPTE with bit 60 clear, so L2
immediately takes the same EPT violation in an infinite loop.
The same livelock occurs on a write-tracked or non-unsyncable L1 GFN:
page_fault_handle_page_track() and mmu_set_spte() both gate write-protect
handling on fault->write, so KVM ignores wrprot and returns RET_PF_FIXED
(then RET_PF_SPURIOUS) instead of RET_PF_WRITE_PROTECTED.
[ ... ]
> @@ -789,7 +866,8 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault,
> if (KVM_BUG_ON(it.level != fault->goal_level, vcpu->kvm))
> return -EIO;
>
> - ret = mmu_set_spte(vcpu, fault->slot, it.sptep, gw->pte_access,
> + ret = mmu_set_spte(vcpu, fault->slot, it.sptep,
> + gw->pte_access | gw->sss_access,
> base_gfn, fault->pfn, fault);
> if (ret == RET_PF_SPURIOUS)
> return ret;
[Severity: High]
Can omitting gw->sss_access from direct_access and role.access allow direct
shadow pages of huge EPT leaves to alias across bit 60 settings?
FNAME(fetch)() initializes direct_access from gw->pte_access without
gw->sss_access, and role.access is only 4 bits wide while role.ept_sss is
unconditionally inherited by every child SP in kvm_mmu_child_role(). Two
2MB/1GB L1 EPT leaves mapping the same L1 base_gfn with identical RWX bits
under EPTP bit 7 -- one with bit 60 set and one with bit 60 clear -- compute
the same role.word and share one direct SP in mmu_page_hash. Once
mmu_set_spte() installs VMX_EPT_SSS_MASK via the bit-60-set mapping, L2
gains unauthorized supervisor shadow-stack access through the bit-60-clear
mapping, bypassing L1 EPT isolation.
shadow_mmu_get_sp_for_split() hits the same aliasing because passing
ACC_EPT_SSS_MASK into kvm_mmu_child_role() silently truncates bit 4.
validate_direct_spte() also cannot distinguish clean (D=0) from dirty (D=1)
huge EPT leaves, leaking bit 60 to clean aliases and bypassing L1 Dirty/PML
tracking. Finally, direct_pte_prefetch_many() prefetches with
sp->role.access, omitting bit 60 on prefetched 4KB siblings of a huge
supervisor shadow stack.
[Severity: High]
Can installing an ACC_EPT_SSS_MASK-only SPTE without shadow_mmu_writable_mask
miss a required remote TLB flush during write-protection?
For a standard supervisor shadow-stack EPT leaf (R=1, W=0, bit 60=1),
make_spte() sets VMX_EPT_SSS_MASK while leaving PT_WRITABLE_MASK and
shadow_mmu_writable_mask clear. If dirty logging clears VMX_EPT_SSS_MASK
under mmu_lock and defers its TLB flush until after dropping mmu_lock, a
concurrent write-protect sees all three checks in spte_write_protect()
evaluate to false:
CPU0 (dirty logging) CPU1 (shadowing)
lock(mmu_lock)
__rmap_clear_dirty()
clear VMX_EPT_SSS_MASK
unlock(mmu_lock)
lock(mmu_lock)
account_shadowed()
kvm_mmu_slot_gfn_write_protect()
spte_write_protect(..., true)
returns false <-- skips TLB flush
unlock(mmu_lock)
kvm_flush_remote_tlbs_memslot()
Because account_shadowed() (and __kvm_write_track_add_gfn()) omits
kvm_flush_remote_tlbs_gfn(), a remote vCPU with a stale TLB entry carrying
VMX_EPT_SSS_MASK can still write into the newly shadowed guest page table
via supervisor shadow-stack accesses without trapping, corrupting shadow
MMU coherence.
[ ... ]
> @@ -973,6 +1051,8 @@ static int FNAME(sync_spte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, int
> pte_access = sp->role.access;
> pte_access &= FNAME(gpte_access)(gpte);
> FNAME(protect_clean_gpte)(vcpu->arch.mmu->w, &pte_access, gpte);
> + pte_access |= FNAME(gpte_sss_access)(vcpu->arch.mmu->w, sp->role.access,
> + gpte, false);
>
> if (sync_mmio_spte(vcpu, &sp->spt[i], gfn, pte_access))
> return 0;
[Severity: Medium]
Should FNAME(sync_spte)() check sp->role.ept_sss instead of reading
is_ept_sss(vcpu->arch.mmu->w) from the active MMU?
If L1 switches between two EPTPs with the same EP4TA (bits 51:12) and
opposite bit 7 settings, the previous root remains cached in prev_roots[].
When an EPT violation is reflected to L1, nested_ept_invalidate_addr()
matches prev_roots[] solely by EPTP_PA_MASK in nested_ept_root_matches()
and calls kvm_mmu_invalidate_addr() -> __kvm_mmu_invalidate_addr() ->
kvm_sync_spte() without verifying that sp->role matches the active MMU.
Syncing an ept_sss=0 cached shadow page while the active MMU has ept_sss=1
installs ACC_EPT_SSS_MASK and VMX_EPT_SSS_MASK (plus shadow_dirty_mask)
onto a non-SSS shadow page, violating sync_spte()'s read-only invariant and
triggering spurious dirty marking. In the opposite direction, it strips
VMX_EPT_SSS_MASK from an ept_sss=1 cached shadow page and causes
unnecessary EPT violations when switching back.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes?part=5
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [PATCH 05/10] KVM: nVMX: Shadow supervisor shadow-stack control of nested EPT
2026-12-04 0:17 ` sashiko-bot
@ 2026-12-04 0:41 ` Dennis Reußwig
0 siblings, 0 replies; 22+ messages in thread
From: Dennis Reußwig @ 2026-12-04 0:41 UTC (permalink / raw)
To: sashiko-bot; +Cc: kvm, Dennis Reußwig
> [Severity: High]
> Can supervisor shadow-stack reads livelock L2 because fault->write stays
> false after FNAME(walk_addr_generic)() returns?
Good catch, real bug, fixed in v2.
> [Severity: High]
> Can omitting gw->sss_access from direct_access and role.access allow direct
> shadow pages of huge EPT leaves to alias across bit 60 settings?
Good catch, real bug, fixed in v2.
> [Severity: High]
> Can installing an ACC_EPT_SSS_MASK-only SPTE without shadow_mmu_writable_mask
> miss a required remote TLB flush during write-protection?
Good catch, real bug, fixed in v2.
Setting shadow_mmu_writable_mask on these SPTEs would not work,
though: fast_page_fault() makes an MMU-writable SPTE writable on a
write fault without taking mmu_lock, while bit 60 must not allow
ordinary writes. v2 adds a separate software bit (MMU-SSS, bit 59)
that is set with bit 60 and that write-protection for shadow paging
checks and clears, with a flush.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 06/10] KVM: nVMX: Advertise supervisor shadow-stack control for nested EPT
2026-12-03 23:49 [PATCH 00/10] KVM: nVMX: Supervisor shadow-stack control for nested EPT and CET with eVMCS Dennis Reußwig
` (4 preceding siblings ...)
2026-12-03 23:49 ` [PATCH 05/10] KVM: nVMX: Shadow supervisor shadow-stack control of nested EPT Dennis Reußwig
@ 2026-12-03 23:49 ` Dennis Reußwig
2026-12-04 0:13 ` sashiko-bot
2026-12-03 23:49 ` [PATCH 07/10] KVM: selftests: Add helpers for nested EPT shadow-stack and MBEC tests Dennis Reußwig
` (3 subsequent siblings)
9 siblings, 1 reply; 22+ messages in thread
From: Dennis Reußwig @ 2026-12-03 23:49 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Jon Kohler,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Shuah Khan
Cc: kvm, linux-kernel, linux-doc, linux-kselftest, Chao Gao,
Maxim Levitsky, Vitaly Kuznetsov, Panayotis Katsaloulis,
Dennis Reußwig
Since commit 606ddbfb4c02 ("KVM: nVMX: advertise MBEC to nested
guests"), Windows Hyper-V is offered MBEC and then enables CET for its
guests. It requires supervisor shadow-stack control for EPT
(IA32_VMX_EPT_VPID_CAP bit 23), which KVM never advertised, and Windows
with virtualization-based security stops booting (Automatic Repair).
Advertise the capability if the CPU supports it, KVM supports shadow
stacks and advanced VM-exit information is offered, which is needed to
tell supervisor from user shadow-stack accesses. Accept EPTP bit 7 in
nested_vmx_check_eptp() only if the capability is offered; bits 11:8
stay reserved.
The VMM must also expose bit 23 to L1; QEMU names it separately.
Fixes: 606ddbfb4c02 ("KVM: nVMX: advertise MBEC to nested guests")
Reported-by: Panayotis Katsaloulis <panayotis@panayotis.com>
Closes: https://lore.kernel.org/kvm/58dcd595e3187d335e103a042d196cb7@panayotis.com/
Signed-off-by: Dennis Reußwig <dennis@reusswig.codes>
---
arch/x86/include/asm/vmx.h | 1 +
arch/x86/kvm/vmx/nested.c | 20 ++++++++++++++++++--
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
index df6feba112f7..22e890f35435 100644
--- a/arch/x86/include/asm/vmx.h
+++ b/arch/x86/include/asm/vmx.h
@@ -545,6 +545,7 @@ enum vmcs_field {
#define VMX_EPT_INVEPT_BIT (1ull << 20)
#define VMX_EPT_AD_BIT (1ull << 21)
#define VMX_EPT_ADVANCED_VMEXIT_INFO_BIT (1ull << 22)
+#define VMX_EPT_SSS_BIT (1ull << 23)
#define VMX_EPT_EXTENT_CONTEXT_BIT (1ull << 25)
#define VMX_EPT_EXTENT_GLOBAL_BIT (1ull << 26)
diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index dc7199855497..f7bcf1891716 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -2930,7 +2930,12 @@ static bool nested_vmx_check_eptp(struct kvm_vcpu *vcpu, u64 new_eptp)
}
/* Reserved bits should not be set */
- if (CC(!kvm_vcpu_is_legal_gpa(vcpu, new_eptp) || ((new_eptp >> 7) & 0x1f)))
+ if (CC(!kvm_vcpu_is_legal_gpa(vcpu, new_eptp) || ((new_eptp >> 8) & 0xf)))
+ return false;
+
+ /* Supervisor shadow-stack control, if set, should be supported */
+ if (CC((new_eptp & VMX_EPTP_SSS_BIT) &&
+ !(vmx->nested.msrs.ept_caps & VMX_EPT_SSS_BIT)))
return false;
/* AD, if set, should be supported */
@@ -7251,9 +7256,20 @@ static void nested_vmx_setup_secondary_ctls(u32 ept_caps,
VMX_EPTP_WB_BIT |
VMX_EPT_INVEPT_BIT |
VMX_EPT_EXECUTE_ONLY_BIT |
- VMX_EPT_ADVANCED_VMEXIT_INFO_BIT;
+ VMX_EPT_ADVANCED_VMEXIT_INFO_BIT |
+ VMX_EPT_SSS_BIT;
msrs->ept_caps &= ept_caps;
+
+ /*
+ * Supervisor shadow-stack control needs shadow stacks for the
+ * guest, and advanced VM-exit information to tell supervisor
+ * from user shadow-stack accesses in EPT violations.
+ */
+ if (!kvm_cpu_cap_has(X86_FEATURE_SHSTK) ||
+ !(msrs->ept_caps & VMX_EPT_ADVANCED_VMEXIT_INFO_BIT))
+ msrs->ept_caps &= ~VMX_EPT_SSS_BIT;
+
msrs->ept_caps |= VMX_EPT_EXTENT_GLOBAL_BIT |
VMX_EPT_EXTENT_CONTEXT_BIT | VMX_EPT_2MB_PAGE_BIT |
VMX_EPT_1GB_PAGE_BIT;
--
2.53.0
^ permalink raw reply related [flat|nested] 22+ messages in thread* Re: [PATCH 06/10] KVM: nVMX: Advertise supervisor shadow-stack control for nested EPT
2026-12-03 23:49 ` [PATCH 06/10] KVM: nVMX: Advertise supervisor shadow-stack control for " Dennis Reußwig
@ 2026-12-04 0:13 ` sashiko-bot
2026-12-04 0:41 ` Dennis Reußwig
0 siblings, 1 reply; 22+ messages in thread
From: sashiko-bot @ 2026-12-04 0:13 UTC (permalink / raw)
To: Dennis Reußwig; +Cc: kvm
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] KVM: x86/mmu: EPT violation livelock on supervisor shadow-stack
read faults
- [High] KVM: x86/mmu: direct shadow page role omits ACC_EPT_SSS_MASK on
huge pages
- [Medium] KVM: x86/mmu: make_spte() omits shadow_mmu_writable_mask on
SSS-only SPTEs
--
commit e65818dd0c34cc8796a7568dea29e47732d607e4
Author: Dennis Reußwig <dennis@reusswig.codes>
KVM: nVMX: Advertise supervisor shadow-stack control for nested EPT
This commit advertises VMX_EPT_SSS_BIT in IA32_VMX_EPT_VPID_CAP when the
host supports shadow stacks and advanced VM-exit information, and allows
L1 to set VMX_EPTP_SSS_BIT in nested_vmx_check_eptp().
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index dc71998554977..f7bcf18917167 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -2930,7 +2930,12 @@ static bool nested_vmx_check_eptp(struct kvm_vcpu *vcpu, u64 new_eptp)
> }
>
> /* Reserved bits should not be set */
> - if (CC(!kvm_vcpu_is_legal_gpa(vcpu, new_eptp) || ((new_eptp >> 7) & 0x1f)))
> + if (CC(!kvm_vcpu_is_legal_gpa(vcpu, new_eptp) || ((new_eptp >> 8) & 0xf)))
> + return false;
> +
> + /* Supervisor shadow-stack control, if set, should be supported */
> + if (CC((new_eptp & VMX_EPTP_SSS_BIT) &&
> + !(vmx->nested.msrs.ept_caps & VMX_EPT_SSS_BIT)))
> return false;
>
> /* AD, if set, should be supported */
[Severity: High]
Can allowing VMX_EPTP_SSS_BIT trigger an infinite EPT violation livelock
on supervisor shadow-stack read faults?
With EPTP bit 7 set, hardware requires VMX_EPT_SSS_MASK (bit 60) on EPT02
leaf SPTEs even for read-only supervisor shadow-stack operations such as
RET or RSTORSSP. On an EPT violation for such a read,
__vt_handle_ept_violation() sets PFERR_SS_MASK without PFERR_WRITE_MASK,
so kvm_mmu_do_page_fault() leaves fault.write false.
Downstream MMU fault handling checks only fault->write:
__kvm_mmu_faultin_pfn() omits FOLL_WRITE, so a read-only host backing page
(such as a CoW page or shared zero page) resolves with map_writable = false
and make_spte() strips ACC_EPT_SSS_MASK. Similarly, on a write-tracked or
shadowed L1 GFN, page_fault_handle_page_track() returns false,
FNAME(fetch)() skips fault->write_fault_to_shadow_pgtable, and
mmu_set_spte() returns RET_PF_FIXED (then RET_PF_SPURIOUS) instead of
RET_PF_WRITE_PROTECTED while leaving bit 60 clear.
In both cases KVM resumes L2 on the same instruction with bit 60 still 0,
hanging the L2 vCPU and spinning the host CPU in an endless fault loop.
[ ... ]
> @@ -7251,9 +7256,20 @@ static void nested_vmx_setup_secondary_ctls(u32 ept_caps,
> VMX_EPTP_WB_BIT |
> VMX_EPT_INVEPT_BIT |
> VMX_EPT_EXECUTE_ONLY_BIT |
> - VMX_EPT_ADVANCED_VMEXIT_INFO_BIT;
> + VMX_EPT_ADVANCED_VMEXIT_INFO_BIT |
> + VMX_EPT_SSS_BIT;
>
> msrs->ept_caps &= ept_caps;
> +
> + /*
> + * Supervisor shadow-stack control needs shadow stacks for the
> + * guest, and advanced VM-exit information to tell supervisor
> + * from user shadow-stack accesses in EPT violations.
> + */
> + if (!kvm_cpu_cap_has(X86_FEATURE_SHSTK) ||
> + !(msrs->ept_caps & VMX_EPT_ADVANCED_VMEXIT_INFO_BIT))
> + msrs->ept_caps &= ~VMX_EPT_SSS_BIT;
[Severity: Medium]
Now that VMX_EPT_SSS_BIT is exposed, can dirty logging race with guest
page-table shadowing and skip a required remote TLB flush on SSS-only
SPTEs?
In commit "KVM: x86/mmu: Handle the EPT supervisor shadow-stack bit like a
write bit", make_spte() sets VMX_EPT_SSS_MASK for SSS-only SPTEs
(ACC_EPT_SSS_MASK without ACC_WRITE_MASK) without setting
shadow_mmu_writable_mask. Dirty-logging paths such as
kvm_get_dirty_log_protect() and kvm_mmu_slot_apply_flags() clear
VMX_EPT_SSS_MASK under mmu_lock and defer remote TLB flushes until after
dropping mmu_lock:
CPU0 CPU1
kvm_get_dirty_log_protect()
KVM_MMU_LOCK(kvm)
... -> spte_write_protect()
clears VMX_EPT_SSS_MASK
KVM_MMU_UNLOCK(kvm)
KVM_MMU_LOCK(kvm)
account_shadowed()
spte_write_protect(..., true)
returns false <-- skips TLB flush
KVM_MMU_UNLOCK(kvm)
kvm_flush_remote_tlbs_memslot()
Because shadow_mmu_writable_mask is clear, spte_write_protect(..., true)
sees is_writable_pte(), is_sss_spte(), and is_mmu_writable_spte() all
false and returns false. A remote vCPU running L2 with a stale
VMX_EPT_SSS_MASK=1 TLB entry can then perform supervisor shadow-stack
writes into the shadowed guest page table without trapping, desynchronizing
KVM's shadow page tables (and bypassing kvm_write_track consumers).
Setting shadow_mmu_writable_mask whenever make_spte() grants
VMX_EPT_SSS_MASK would preserve the dirty-logging write-protect invariant.
> msrs->ept_caps |= VMX_EPT_EXTENT_GLOBAL_BIT |
> VMX_EPT_EXTENT_CONTEXT_BIT | VMX_EPT_2MB_PAGE_BIT |
> VMX_EPT_1GB_PAGE_BIT;
[Severity: High]
Does advertising VMX_EPT_SSS_BIT alongside 2MB and 1GB nested EPT huge
pages allow L2 to bypass EPT supervisor shadow-stack isolation?
In union kvm_mmu_page_role, role.access is only 4 bits wide and cannot
store ACC_EPT_SSS_MASK (bit 4). FNAME(fetch)() omits gw->sss_access from
direct_access, and kvm_mmu_child_role() silently truncates bit 4 when
assigning role.access.
When KVM shadows L1 2MB/1GB huge pages with 4KB direct shadow pages, two
huge-page mappings of the same L1 base GFN with identical RWX bits — one
with bit 60 set and one with bit 60 clear, such as Hyper-V VTL1 vs VTL0
EPTs — collide in mmu_page_hash on the same direct shadow page. Any 4KB
SPTE populated with VMX_EPT_SSS_MASK via the SSS=1 mapping (including
across shadow_mmu_split_huge_page()) is exposed through the SSS=0 mapping,
letting L2 perform supervisor shadow-stack writes where L1 forbade them.
For the same reason, validate_direct_spte() fails to drop a cached direct
shadow page when L1 clears bit 60 without changing RWX, and INVEPT via
mmu_free_root_page() leaves those stale direct shadow pages in
mmu_page_hash for reuse.
Finally, direct_pte_prefetch_many() seeds access from sp->role.access
without ACC_EPT_SSS_MASK, so prefetched 4KB SPTEs under an SSS=1 huge page
lose bit 60 and incur extra EPT violation VM-exits.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes?part=6
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [PATCH 06/10] KVM: nVMX: Advertise supervisor shadow-stack control for nested EPT
2026-12-04 0:13 ` sashiko-bot
@ 2026-12-04 0:41 ` Dennis Reußwig
0 siblings, 0 replies; 22+ messages in thread
From: Dennis Reußwig @ 2026-12-04 0:41 UTC (permalink / raw)
To: sashiko-bot; +Cc: kvm, Dennis Reußwig
> [Severity: High]
> Can allowing VMX_EPTP_SSS_BIT trigger an infinite EPT violation livelock
> on supervisor shadow-stack read faults?
Good catch, real bug, fixed in v2.
> [Severity: Medium]
> Now that VMX_EPT_SSS_BIT is exposed, can dirty logging race with guest
> page-table shadowing and skip a required remote TLB flush on SSS-only
> SPTEs?
Good catch, real bug, fixed in v2.
Setting shadow_mmu_writable_mask on these SPTEs would not work,
though: fast_page_fault() makes an MMU-writable SPTE writable on a
write fault without taking mmu_lock, while bit 60 must not allow
ordinary writes. v2 adds a separate software bit (MMU-SSS, bit 59)
that is set with bit 60 and that write-protection for shadow paging
checks and clears, with a flush.
> [Severity: High]
> Does advertising VMX_EPT_SSS_BIT alongside 2MB and 1GB nested EPT huge
> pages allow L2 to bypass EPT supervisor shadow-stack isolation?
Good catch, real bug, fixed in v2.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 07/10] KVM: selftests: Add helpers for nested EPT shadow-stack and MBEC tests
2026-12-03 23:49 [PATCH 00/10] KVM: nVMX: Supervisor shadow-stack control for nested EPT and CET with eVMCS Dennis Reußwig
` (5 preceding siblings ...)
2026-12-03 23:49 ` [PATCH 06/10] KVM: nVMX: Advertise supervisor shadow-stack control for " Dennis Reußwig
@ 2026-12-03 23:49 ` Dennis Reußwig
2026-12-03 23:49 ` [PATCH 08/10] KVM: selftests: Add nested EPT supervisor shadow-stack test Dennis Reußwig
` (2 subsequent siblings)
9 siblings, 0 replies; 22+ messages in thread
From: Dennis Reußwig @ 2026-12-03 23:49 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Jon Kohler,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Shuah Khan
Cc: kvm, linux-kernel, linux-doc, linux-kselftest, Chao Gao,
Maxim Levitsky, Vitaly Kuznetsov, Panayotis Katsaloulis,
Dennis Reußwig
Add __tdp_get_pte() to look up the EPT entry of an L2 GPA, and the VMX
definitions the following tests use: the CET VMCS fields and VM-entry
and VM-exit controls, mode-based execute control, the EPT capabilities
for advanced VM-exit information and supervisor shadow-stack control,
X86_CR4_CET and the EPT violation exit qualification bits for user
execute, shadow-stack access and supervisor shadow-stack page.
Signed-off-by: Dennis Reußwig <dennis@reusswig.codes>
---
tools/testing/selftests/kvm/include/x86/processor.h | 5 +++++
tools/testing/selftests/kvm/include/x86/vmx.h | 11 +++++++++++
tools/testing/selftests/kvm/lib/x86/processor.c | 9 ++++++---
3 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/kvm/include/x86/processor.h b/tools/testing/selftests/kvm/include/x86/processor.h
index 3e4351ccb359..79f399a40333 100644
--- a/tools/testing/selftests/kvm/include/x86/processor.h
+++ b/tools/testing/selftests/kvm/include/x86/processor.h
@@ -93,6 +93,7 @@ const char *ex_str(int vector);
#define X86_CR4_SMEP (1ul << 20)
#define X86_CR4_SMAP (1ul << 21)
#define X86_CR4_PKE (1ul << 22)
+#define X86_CR4_CET (1ul << 23)
struct xstate_header {
u64 xstate_bv;
@@ -1641,6 +1642,7 @@ void tdp_map(struct kvm_vm *vm, gpa_t l2_gpa, gpa_t gpa, u64 size);
void tdp_identity_map_default_memslots(struct kvm_vm *vm);
void tdp_identity_map_1g(struct kvm_vm *vm, u64 addr, u64 size);
u64 *tdp_get_pte(struct kvm_vm *vm, u64 l2_gpa);
+u64 *__tdp_get_pte(struct kvm_vm *vm, u64 l2_gpa, int level);
/*
* Basic CPU control in CR0
@@ -1685,8 +1687,11 @@ u64 *tdp_get_pte(struct kvm_vm *vm, u64 l2_gpa);
#define EPT_VIOLATION_PROT_READ BIT(3)
#define EPT_VIOLATION_PROT_WRITE BIT(4)
#define EPT_VIOLATION_PROT_EXEC BIT(5)
+#define EPT_VIOLATION_PROT_USER_EXEC BIT(6)
#define EPT_VIOLATION_GVA_IS_VALID BIT(7)
#define EPT_VIOLATION_GVA_TRANSLATED BIT(8)
+#define EPT_VIOLATION_SHADOW_STACK BIT(13)
+#define EPT_VIOLATION_SSS_PAGE BIT(14)
bool sys_clocksource_is_based_on_tsc(void);
diff --git a/tools/testing/selftests/kvm/include/x86/vmx.h b/tools/testing/selftests/kvm/include/x86/vmx.h
index 8fd97434eee5..3cf3766f335c 100644
--- a/tools/testing/selftests/kvm/include/x86/vmx.h
+++ b/tools/testing/selftests/kvm/include/x86/vmx.h
@@ -61,6 +61,7 @@
#define SECONDARY_EXEC_ENABLE_PML 0x00020000
#define SECONDARY_EPT_VE 0x00040000
#define SECONDARY_ENABLE_XSAV_RESTORE 0x00100000
+#define SECONDARY_EXEC_MODE_BASED_EPT_EXEC 0x00400000
#define SECONDARY_EXEC_TSC_SCALING 0x02000000
#define PIN_BASED_EXT_INTR_MASK 0x00000001
@@ -80,6 +81,7 @@
#define VM_EXIT_SAVE_IA32_EFER 0x00100000
#define VM_EXIT_LOAD_IA32_EFER 0x00200000
#define VM_EXIT_SAVE_VMX_PREEMPTION_TIMER 0x00400000
+#define VM_EXIT_LOAD_CET_STATE 0x10000000
#define VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR 0x00036dff
@@ -90,6 +92,7 @@
#define VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL 0x00002000
#define VM_ENTRY_LOAD_IA32_PAT 0x00004000
#define VM_ENTRY_LOAD_IA32_EFER 0x00008000
+#define VM_ENTRY_LOAD_CET_STATE 0x00100000
#define VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR 0x000011ff
@@ -98,6 +101,8 @@
#define VMX_EPT_VPID_CAP_1G_PAGES 0x00020000
#define VMX_EPT_VPID_CAP_AD_BITS 0x00200000
+#define VMX_EPT_VPID_CAP_ADVANCED_VMEXIT_INFO 0x00400000
+#define VMX_EPT_VPID_CAP_SSS 0x00800000
#define EXIT_REASON_FAILED_VMENTRY 0x80000000
@@ -270,6 +275,9 @@ enum vmcs_field {
GUEST_PENDING_DBG_EXCEPTIONS = 0x00006822,
GUEST_SYSENTER_ESP = 0x00006824,
GUEST_SYSENTER_EIP = 0x00006826,
+ GUEST_S_CET = 0x00006828,
+ GUEST_SSP = 0x0000682a,
+ GUEST_INTR_SSP_TABLE = 0x0000682c,
HOST_CR0 = 0x00006c00,
HOST_CR3 = 0x00006c02,
HOST_CR4 = 0x00006c04,
@@ -282,6 +290,9 @@ enum vmcs_field {
HOST_IA32_SYSENTER_EIP = 0x00006c12,
HOST_RSP = 0x00006c14,
HOST_RIP = 0x00006c16,
+ HOST_S_CET = 0x00006c18,
+ HOST_SSP = 0x00006c1a,
+ HOST_INTR_SSP_TABLE = 0x00006c1c,
};
struct vmx_msr_entry {
diff --git a/tools/testing/selftests/kvm/lib/x86/processor.c b/tools/testing/selftests/kvm/lib/x86/processor.c
index ee8a1715d844..fdf39dcea3c3 100644
--- a/tools/testing/selftests/kvm/lib/x86/processor.c
+++ b/tools/testing/selftests/kvm/lib/x86/processor.c
@@ -389,13 +389,16 @@ static u64 *__vm_get_page_table_entry(struct kvm_vm *vm,
return virt_get_pte(vm, mmu, pte, gva, PG_LEVEL_4K);
}
-u64 *tdp_get_pte(struct kvm_vm *vm, u64 l2_gpa)
+u64 *__tdp_get_pte(struct kvm_vm *vm, u64 l2_gpa, int level)
{
- int level = PG_LEVEL_4K;
-
return __vm_get_page_table_entry(vm, &vm->stage2_mmu, l2_gpa, &level);
}
+u64 *tdp_get_pte(struct kvm_vm *vm, u64 l2_gpa)
+{
+ return __tdp_get_pte(vm, l2_gpa, PG_LEVEL_4K);
+}
+
u64 *vm_get_pte(struct kvm_vm *vm, gva_t gva)
{
int level = PG_LEVEL_4K;
--
2.53.0
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH 08/10] KVM: selftests: Add nested EPT supervisor shadow-stack test
2026-12-03 23:49 [PATCH 00/10] KVM: nVMX: Supervisor shadow-stack control for nested EPT and CET with eVMCS Dennis Reußwig
` (6 preceding siblings ...)
2026-12-03 23:49 ` [PATCH 07/10] KVM: selftests: Add helpers for nested EPT shadow-stack and MBEC tests Dennis Reußwig
@ 2026-12-03 23:49 ` Dennis Reußwig
2026-12-04 0:00 ` sashiko-bot
2026-12-03 23:49 ` [PATCH 09/10] KVM: selftests: Add nested EPT mode-based execute control test Dennis Reußwig
2026-12-03 23:49 ` [PATCH 10/10] KVM: selftests: Check VMX capabilities for CET in L2 with MBEC Dennis Reußwig
9 siblings, 1 reply; 22+ messages in thread
From: Dennis Reußwig @ 2026-12-03 23:49 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Jon Kohler,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Shuah Khan
Cc: kvm, linux-kernel, linux-doc, linux-kselftest, Chao Gao,
Maxim Levitsky, Vitaly Kuznetsov, Panayotis Katsaloulis,
Dennis Reußwig
L1 runs L2 with supervisor shadow stacks. L2 does a CALL and RET whose
shadow-stack push and pop hit a page whose L1 EPT permissions vary per
case, with and without EPTP bit 7. Check that the accesses succeed or
cause EPT violations as the SDM defines, and that the violations reach
L1 with exit qualification bits 13 and 14 set as expected.
Signed-off-by: Dennis Reußwig <dennis@reusswig.codes>
---
tools/testing/selftests/kvm/Makefile.kvm | 1 +
.../selftests/kvm/x86/vmx_nested_sss_test.c | 213 +++++++++++++++++++++
2 files changed, 214 insertions(+)
diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
index 95867977beb3..dc890dbe48d1 100644
--- a/tools/testing/selftests/kvm/Makefile.kvm
+++ b/tools/testing/selftests/kvm/Makefile.kvm
@@ -146,6 +146,7 @@ TEST_GEN_PROGS_x86 += x86/vmx_exception_with_invalid_guest_state
TEST_GEN_PROGS_x86 += x86/vmx_msrs_test
TEST_GEN_PROGS_x86 += x86/vmx_invalid_nested_guest_state
TEST_GEN_PROGS_x86 += x86/vmx_nested_la57_state_test
+TEST_GEN_PROGS_x86 += x86/vmx_nested_sss_test
TEST_GEN_PROGS_x86 += x86/apic_bus_clock_test
TEST_GEN_PROGS_x86 += x86/apic_id_routing_test
TEST_GEN_PROGS_x86 += x86/xapic_ipi_test
diff --git a/tools/testing/selftests/kvm/x86/vmx_nested_sss_test.c b/tools/testing/selftests/kvm/x86/vmx_nested_sss_test.c
new file mode 100644
index 000000000000..a685fba0af7f
--- /dev/null
+++ b/tools/testing/selftests/kvm/x86/vmx_nested_sss_test.c
@@ -0,0 +1,213 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Nested EPT supervisor shadow-stack control (EPTP bit 7, EPT bit 60).
+ *
+ * L1 runs L2 with supervisor shadow stacks enabled; L2 does a CALL/RET whose
+ * shadow-stack push and pop hit a page whose L1 EPT permissions vary per test.
+ * With EPTP bit 7 set, supervisor shadow-stack accesses are allowed iff every
+ * EPT entry is readable, every non-leaf entry is writable and the leaf sets
+ * bit 60; the write bit of the leaf does not matter. Without EPTP bit 7 they
+ * follow the normal write rules. Denied accesses must reach L1 as EPT
+ * violations with exit qualification bit 13 (shadow-stack access) and, with
+ * EPTP bit 7, bit 14 (bit 60 of the leaf).
+ */
+#include "test_util.h"
+#include "kvm_util.h"
+#include "processor.h"
+#include "vmx.h"
+
+#define SS_GVA 0x30000000ULL
+/* Alone in its 2M region, so the non-leaf EPT entries above it are its own. */
+#define SS_L2_GPA 0x80000000ULL
+
+#define EPT_SSS_PAGE BIT_ULL(60)
+#define VMX_EPTP_SSS BIT_ULL(7)
+
+/* Paging attributes of L2's linear address, not under test. */
+#define QUAL_IGNORE (BIT_ULL(9) | BIT_ULL(10) | BIT_ULL(11))
+
+#define QUAL_SS_WRITE (EPT_VIOLATION_ACC_WRITE | EPT_VIOLATION_GVA_IS_VALID | \
+ EPT_VIOLATION_GVA_TRANSLATED | EPT_VIOLATION_SHADOW_STACK)
+
+struct sss_test {
+ const char *name;
+ bool eptp_sss;
+ bool leaf_writable;
+ bool leaf_sss;
+ bool pde_writable;
+ /* 0 if L2 must reach its VMCALL. */
+ u64 qual;
+ u64 qual_ignore;
+};
+
+static const struct sss_test tests[] = {
+ {
+ .name = "SSS page, leaf read-only",
+ .eptp_sss = true, .leaf_writable = false, .leaf_sss = true,
+ .pde_writable = true,
+ },
+ {
+ .name = "not an SSS page, leaf read-only",
+ .eptp_sss = true, .leaf_writable = false, .leaf_sss = false,
+ .pde_writable = true,
+ .qual = QUAL_SS_WRITE | EPT_VIOLATION_PROT_READ | EPT_VIOLATION_PROT_EXEC,
+ },
+ {
+ .name = "not an SSS page, leaf writable",
+ .eptp_sss = true, .leaf_writable = true, .leaf_sss = false,
+ .pde_writable = true,
+ .qual = QUAL_SS_WRITE | EPT_VIOLATION_PROT_READ |
+ EPT_VIOLATION_PROT_WRITE | EPT_VIOLATION_PROT_EXEC,
+ },
+ {
+ .name = "SSS page, non-leaf read-only",
+ .eptp_sss = true, .leaf_writable = false, .leaf_sss = true,
+ .pde_writable = false,
+ .qual = QUAL_SS_WRITE | EPT_VIOLATION_PROT_READ | EPT_VIOLATION_PROT_EXEC |
+ EPT_VIOLATION_SSS_PAGE,
+ },
+ {
+ .name = "no EPTP bit 7, leaf read-only",
+ .eptp_sss = false, .leaf_writable = false, .leaf_sss = true,
+ .pde_writable = true,
+ .qual = QUAL_SS_WRITE | EPT_VIOLATION_PROT_READ | EPT_VIOLATION_PROT_EXEC,
+ /* Bit 14 is undefined without EPTP bit 7. */
+ .qual_ignore = EPT_VIOLATION_SSS_PAGE,
+ },
+ {
+ .name = "no EPTP bit 7, leaf writable",
+ .eptp_sss = false, .leaf_writable = true, .leaf_sss = true,
+ .pde_writable = true,
+ },
+};
+
+static void l2_guest_code(void)
+{
+ /* The CALL pushes to and the RET pops from the shadow stack. */
+ asm volatile("call 1f\n\t"
+ "jmp 2f\n\t"
+ "1: ret\n\t"
+ "2:" ::: "memory");
+ vmcall();
+}
+
+static void l1_guest_code(struct vmx_pages *vmx, u64 eptp_sss, u64 qual,
+ u64 qual_ignore)
+{
+ u64 actual;
+
+ prepare_for_vmx_operation(vmx);
+ load_vmcs(vmx);
+ prepare_vmcs(vmx, l2_guest_code);
+
+ if (eptp_sss)
+ vmwrite(EPT_POINTER, vmread(EPT_POINTER) | VMX_EPTP_SSS);
+
+ /* CR4.CET requires CR0.WP. */
+ vmwrite(GUEST_CR0, vmread(GUEST_CR0) | X86_CR0_WP);
+ vmwrite(GUEST_CR4, vmread(GUEST_CR4) | X86_CR4_CET);
+ vmwrite(GUEST_S_CET, CET_SHSTK_EN);
+ vmwrite(GUEST_SSP, SS_GVA + PAGE_SIZE);
+ vmwrite(GUEST_INTR_SSP_TABLE, 0);
+ vmwrite(VM_ENTRY_CONTROLS, vmread(VM_ENTRY_CONTROLS) | VM_ENTRY_LOAD_CET_STATE);
+ vmwrite(HOST_S_CET, 0);
+ vmwrite(HOST_SSP, 0);
+ vmwrite(HOST_INTR_SSP_TABLE, 0);
+ vmwrite(VM_EXIT_CONTROLS, vmread(VM_EXIT_CONTROLS) | VM_EXIT_LOAD_CET_STATE);
+
+ vmlaunch();
+
+ if (!qual) {
+ __GUEST_ASSERT(vmread(VM_EXIT_REASON) == EXIT_REASON_VMCALL,
+ "Expected VMCALL, got exit reason 0x%lx, qualification 0x%lx",
+ vmread(VM_EXIT_REASON), vmread(EXIT_QUALIFICATION));
+ GUEST_DONE();
+ }
+
+ __GUEST_ASSERT(vmread(VM_EXIT_REASON) == EXIT_REASON_EPT_VIOLATION,
+ "Expected EPT violation, got exit reason 0x%lx",
+ vmread(VM_EXIT_REASON));
+
+ /* The CALL pushes the return address just below the top of the page. */
+ __GUEST_ASSERT(vmread(GUEST_PHYSICAL_ADDRESS) == SS_L2_GPA + PAGE_SIZE - 8,
+ "Expected GPA 0x%llx, got 0x%lx", SS_L2_GPA + PAGE_SIZE - 8,
+ vmread(GUEST_PHYSICAL_ADDRESS));
+
+ actual = vmread(EXIT_QUALIFICATION) & ~(QUAL_IGNORE | qual_ignore);
+ __GUEST_ASSERT(actual == qual, "Expected qualification 0x%lx, got 0x%lx",
+ qual, actual);
+ GUEST_DONE();
+}
+
+static void run_test(const struct sss_test *t)
+{
+ struct kvm_mmu *ept;
+ struct kvm_vcpu *vcpu;
+ struct kvm_vm *vm;
+ gva_t vmx_gva;
+ struct ucall uc;
+ gpa_t ss_gpa;
+ u64 *pte;
+
+ pr_info("%s\n", t->name);
+
+ vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code);
+ vm_enable_tdp(vm);
+ vcpu_alloc_vmx(vm, &vmx_gva);
+ ept = &vm->stage2_mmu;
+
+ /*
+ * Map the shadow-stack page into L2's (and L1's) page tables as a
+ * supervisor shadow-stack page: read-only and dirty.
+ */
+ ss_gpa = vm_phy_page_alloc(vm, MEM_REGION_DATA);
+ virt_pg_map(vm, SS_GVA, SS_L2_GPA);
+ pte = vm_get_pte(vm, SS_GVA);
+ *pte &= ~(PTE_WRITABLE_MASK(&vm->mmu) | PTE_USER_MASK(&vm->mmu));
+ *pte |= PTE_DIRTY_MASK(&vm->mmu);
+
+ tdp_identity_map_default_memslots(vm);
+ tdp_map(vm, SS_L2_GPA, ss_gpa, PAGE_SIZE);
+
+ pte = tdp_get_pte(vm, SS_L2_GPA);
+ if (!t->leaf_writable)
+ *pte &= ~PTE_WRITABLE_MASK(ept);
+ if (t->leaf_sss)
+ *pte |= EPT_SSS_PAGE;
+
+ if (!t->pde_writable) {
+ pte = __tdp_get_pte(vm, SS_L2_GPA, PG_LEVEL_2M);
+ *pte &= ~PTE_WRITABLE_MASK(ept);
+ }
+
+ vcpu_args_set(vcpu, 4, vmx_gva, (u64)t->eptp_sss, t->qual, t->qual_ignore);
+ vcpu_run(vcpu);
+ TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
+
+ switch (get_ucall(vcpu, &uc)) {
+ case UCALL_DONE:
+ break;
+ case UCALL_ABORT:
+ REPORT_GUEST_ASSERT(uc);
+ default:
+ TEST_FAIL("Unexpected ucall %lu", uc.cmd);
+ }
+
+ kvm_vm_free(vm);
+}
+
+int main(int argc, char *argv[])
+{
+ int i;
+
+ TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
+ TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SHSTK));
+ TEST_REQUIRE(kvm_cpu_has_ept());
+ TEST_REQUIRE(kvm_get_feature_msr(MSR_IA32_VMX_EPT_VPID_CAP) &
+ VMX_EPT_VPID_CAP_SSS);
+
+ for (i = 0; i < ARRAY_SIZE(tests); i++)
+ run_test(&tests[i]);
+
+ return 0;
+}
--
2.53.0
^ permalink raw reply related [flat|nested] 22+ messages in thread* Re: [PATCH 08/10] KVM: selftests: Add nested EPT supervisor shadow-stack test
2026-12-03 23:49 ` [PATCH 08/10] KVM: selftests: Add nested EPT supervisor shadow-stack test Dennis Reußwig
@ 2026-12-04 0:00 ` sashiko-bot
0 siblings, 0 replies; 22+ messages in thread
From: sashiko-bot @ 2026-12-04 0:00 UTC (permalink / raw)
To: Dennis Reußwig; +Cc: kvm
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] KVM: selftests: report results via kselftest.h in main() and
run_test()
--
commit da1c3dab9ca5b6b5323764b1720e87df6b6df5b9
Author: Dennis Reußwig <dennis@reusswig.codes>
KVM: selftests: Add nested EPT supervisor shadow-stack test
This commit adds a KVM x86 selftest that runs an L2 guest with supervisor
shadow stacks enabled across different L1 EPT permissions and verifies that
accesses succeed or trigger the expected EPT violations.
> diff --git a/tools/testing/selftests/kvm/x86/vmx_nested_sss_test.c b/tools/testing/selftests/kvm/x86/vmx_nested_sss_test.c
> new file mode 100644
> index 0000000000000..a685fba0af7f7
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/x86/vmx_nested_sss_test.c
> @@ -0,0 +1,213 @@
[ ... ]
> +static void run_test(const struct sss_test *t)
> +{
[ ... ]
> + pr_info("%s\n", t->name);
[ ... ]
> +int main(int argc, char *argv[])
> +{
> + int i;
> +
> + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
> + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SHSTK));
> + TEST_REQUIRE(kvm_cpu_has_ept());
> + TEST_REQUIRE(kvm_get_feature_msr(MSR_IA32_VMX_EPT_VPID_CAP) &
> + VMX_EPT_VPID_CAP_SSS);
> +
> + for (i = 0; i < ARRAY_SIZE(tests); i++)
> + run_test(&tests[i]);
> +
> + return 0;
> +}
[Severity: Low]
Should this test report its subtest results through kselftest.h instead of
pr_info() and a bare return 0 from main()?
Calling ksft_print_header(), ksft_set_plan(ARRAY_SIZE(tests)),
ksft_test_result_pass() for each subtest in run_test(), and ksft_finished()
at the end of main() lets the kselftest runner track each subtest outcome
individually, matching other multi-case x86 KVM selftests such as
svm_nested_efer_test.c and apic_id_routing_test.c.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes?part=8
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 09/10] KVM: selftests: Add nested EPT mode-based execute control test
2026-12-03 23:49 [PATCH 00/10] KVM: nVMX: Supervisor shadow-stack control for nested EPT and CET with eVMCS Dennis Reußwig
` (7 preceding siblings ...)
2026-12-03 23:49 ` [PATCH 08/10] KVM: selftests: Add nested EPT supervisor shadow-stack test Dennis Reußwig
@ 2026-12-03 23:49 ` Dennis Reußwig
2026-12-04 0:07 ` sashiko-bot
2026-12-03 23:49 ` [PATCH 10/10] KVM: selftests: Check VMX capabilities for CET in L2 with MBEC Dennis Reußwig
9 siblings, 1 reply; 22+ messages in thread
From: Dennis Reußwig @ 2026-12-03 23:49 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Jon Kohler,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Shuah Khan
Cc: kvm, linux-kernel, linux-doc, linux-kselftest, Chao Gao,
Maxim Levitsky, Vitaly Kuznetsov, Panayotis Katsaloulis,
Dennis Reußwig
L1 runs L2 with L1 EPT entries that vary the supervisor and user
execute bits, with and without mode-based execute control, and checks
that supervisor instruction fetches of L2 succeed or cause EPT
violations with the expected exit qualification.
Signed-off-by: Dennis Reußwig <dennis@reusswig.codes>
---
tools/testing/selftests/kvm/Makefile.kvm | 1 +
.../selftests/kvm/x86/vmx_nested_mbec_test.c | 189 +++++++++++++++++++++
2 files changed, 190 insertions(+)
diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
index dc890dbe48d1..2b502c9ec7cb 100644
--- a/tools/testing/selftests/kvm/Makefile.kvm
+++ b/tools/testing/selftests/kvm/Makefile.kvm
@@ -146,6 +146,7 @@ TEST_GEN_PROGS_x86 += x86/vmx_exception_with_invalid_guest_state
TEST_GEN_PROGS_x86 += x86/vmx_msrs_test
TEST_GEN_PROGS_x86 += x86/vmx_invalid_nested_guest_state
TEST_GEN_PROGS_x86 += x86/vmx_nested_la57_state_test
+TEST_GEN_PROGS_x86 += x86/vmx_nested_mbec_test
TEST_GEN_PROGS_x86 += x86/vmx_nested_sss_test
TEST_GEN_PROGS_x86 += x86/apic_bus_clock_test
TEST_GEN_PROGS_x86 += x86/apic_id_routing_test
diff --git a/tools/testing/selftests/kvm/x86/vmx_nested_mbec_test.c b/tools/testing/selftests/kvm/x86/vmx_nested_mbec_test.c
new file mode 100644
index 000000000000..652b685466d5
--- /dev/null
+++ b/tools/testing/selftests/kvm/x86/vmx_nested_mbec_test.c
@@ -0,0 +1,189 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Nested EPT mode-based execute control (MBEC).
+ *
+ * L1 runs L2, which calls a one-byte RET at a fixed linear address in
+ * supervisor mode. L1's EPT entries for that page vary per test: XS (bit 2,
+ * supervisor-executable) and XU (bit 10, user-executable), with and without
+ * MBEC enabled in vmcs12. With MBEC, a supervisor fetch is allowed iff XS is
+ * set; XU must not grant it. Without MBEC, bit 2 alone decides and bit 10 is
+ * ignored. A denied fetch must reach L1 as an EPT violation for the code page,
+ * with the exit qualification describing the fetch and L1's permissions.
+ */
+#include "test_util.h"
+#include "kvm_util.h"
+#include "processor.h"
+#include "vmx.h"
+
+#define CODE_GVA 0x38000000ULL
+/* Alone in its 1G region, so the non-leaf EPT entries below the PML4E are its own. */
+#define CODE_L2_GPA 0x80000000ULL
+
+#define EPT_XS BIT_ULL(2)
+#define EPT_XU BIT_ULL(10)
+
+/* Paging attributes of L2's linear address, not under test. */
+#define QUAL_IGNORE (BIT_ULL(9) | BIT_ULL(10) | BIT_ULL(11))
+
+#define QUAL_FETCH (EPT_VIOLATION_ACC_INSTR | EPT_VIOLATION_PROT_READ | \
+ EPT_VIOLATION_GVA_IS_VALID | EPT_VIOLATION_GVA_TRANSLATED)
+
+struct mbec_test {
+ const char *name;
+ bool mbec;
+ bool xs;
+ bool xu;
+ /* 0 if L2 must reach its VMCALL. */
+ u64 qual;
+ u64 qual_ignore;
+};
+
+static const struct mbec_test tests[] = {
+ {
+ .name = "MBEC, user-executable only: supervisor fetch denied",
+ .mbec = true, .xs = false, .xu = true,
+ .qual = QUAL_FETCH | EPT_VIOLATION_PROT_USER_EXEC,
+ },
+ {
+ .name = "MBEC, supervisor-executable only: supervisor fetch allowed",
+ .mbec = true, .xs = true, .xu = false,
+ },
+ {
+ .name = "MBEC, executable for both: supervisor fetch allowed",
+ .mbec = true, .xs = true, .xu = true,
+ },
+ {
+ .name = "MBEC, not executable: supervisor fetch denied",
+ .mbec = true, .xs = false, .xu = false,
+ .qual = QUAL_FETCH,
+ },
+ {
+ .name = "no MBEC, bit 10 only: fetch denied",
+ .mbec = false, .xs = false, .xu = true,
+ .qual = QUAL_FETCH,
+ /* Bit 6 is undefined without MBEC. */
+ .qual_ignore = EPT_VIOLATION_PROT_USER_EXEC,
+ },
+ {
+ .name = "no MBEC, bit 2 only: fetch allowed",
+ .mbec = false, .xs = true, .xu = false,
+ },
+};
+
+static void l2_guest_code(void)
+{
+ ((void (*)(void))CODE_GVA)();
+ vmcall();
+}
+
+static void l1_guest_code(struct vmx_pages *vmx, u64 mbec, u64 qual, u64 qual_ignore)
+{
+ u64 actual;
+
+ prepare_for_vmx_operation(vmx);
+ load_vmcs(vmx);
+ prepare_vmcs(vmx, l2_guest_code);
+
+ if (mbec)
+ vmwrite(SECONDARY_VM_EXEC_CONTROL,
+ vmread(SECONDARY_VM_EXEC_CONTROL) | SECONDARY_EXEC_MODE_BASED_EPT_EXEC);
+
+ vmlaunch();
+
+ if (!qual) {
+ __GUEST_ASSERT(vmread(VM_EXIT_REASON) == EXIT_REASON_VMCALL,
+ "Expected VMCALL, got exit reason 0x%lx, qualification 0x%lx",
+ vmread(VM_EXIT_REASON), vmread(EXIT_QUALIFICATION));
+ GUEST_DONE();
+ }
+
+ __GUEST_ASSERT(vmread(VM_EXIT_REASON) == EXIT_REASON_EPT_VIOLATION,
+ "Expected EPT violation, got exit reason 0x%lx",
+ vmread(VM_EXIT_REASON));
+ __GUEST_ASSERT(vmread(GUEST_PHYSICAL_ADDRESS) == CODE_L2_GPA,
+ "Expected GPA 0x%llx, got 0x%lx", CODE_L2_GPA,
+ vmread(GUEST_PHYSICAL_ADDRESS));
+ __GUEST_ASSERT(vmread(GUEST_LINEAR_ADDRESS) == CODE_GVA,
+ "Expected linear address 0x%llx, got 0x%lx", CODE_GVA,
+ vmread(GUEST_LINEAR_ADDRESS));
+
+ actual = vmread(EXIT_QUALIFICATION) & ~(QUAL_IGNORE | qual_ignore);
+ __GUEST_ASSERT(actual == qual, "Expected qualification 0x%lx, got 0x%lx",
+ qual, actual);
+ GUEST_DONE();
+}
+
+static void run_test(const struct mbec_test *t)
+{
+ struct kvm_mmu *ept;
+ struct kvm_vcpu *vcpu;
+ struct kvm_vm *vm;
+ gva_t vmx_gva;
+ struct ucall uc;
+ gpa_t code_gpa;
+ u64 *pte;
+ int level;
+
+ pr_info("%s\n", t->name);
+
+ vm = vm_create_with_one_vcpu(&vcpu, l1_guest_code);
+ vm_enable_tdp(vm);
+ vcpu_alloc_vmx(vm, &vmx_gva);
+ ept = &vm->stage2_mmu;
+
+ /* A supervisor, executable mapping of the code page in L2's page tables. */
+ code_gpa = vm_phy_page_alloc(vm, MEM_REGION_DATA);
+ *(u8 *)addr_gpa2hva(vm, code_gpa) = 0xc3; /* RET */
+ virt_pg_map(vm, CODE_GVA, CODE_L2_GPA);
+
+ tdp_identity_map_default_memslots(vm);
+ tdp_map(vm, CODE_L2_GPA, code_gpa, PAGE_SIZE);
+
+ /* Leaf: readable, never writable, XS and XU per test. */
+ pte = tdp_get_pte(vm, CODE_L2_GPA);
+ *pte &= ~(PTE_WRITABLE_MASK(ept) | EPT_XS);
+ if (t->xs)
+ *pte |= EPT_XS;
+ if (t->xu)
+ *pte |= EPT_XU;
+
+ /* XU counts only if set at every level; the library leaves it clear in non-leaf entries. */
+ for (level = PG_LEVEL_2M; level <= PG_LEVEL_512G; level++)
+ *__tdp_get_pte(vm, CODE_L2_GPA, level) |= EPT_XU;
+
+ vcpu_args_set(vcpu, 4, vmx_gva, (u64)t->mbec, t->qual, t->qual_ignore);
+ vcpu_run(vcpu);
+ TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
+
+ switch (get_ucall(vcpu, &uc)) {
+ case UCALL_DONE:
+ break;
+ case UCALL_ABORT:
+ REPORT_GUEST_ASSERT(uc);
+ default:
+ TEST_FAIL("Unexpected ucall %lu", uc.cmd);
+ }
+
+ kvm_vm_free(vm);
+}
+
+int main(int argc, char *argv[])
+{
+ bool has_mbec;
+ int i;
+
+ TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
+ TEST_REQUIRE(kvm_cpu_has_ept());
+
+ has_mbec = kvm_cpu_has_secondary_exec_control(SECONDARY_EXEC_MODE_BASED_EPT_EXEC);
+ if (!has_mbec)
+ pr_info("MBEC not offered to L1, running only the cases without MBEC\n");
+
+ for (i = 0; i < ARRAY_SIZE(tests); i++) {
+ if (tests[i].mbec && !has_mbec)
+ continue;
+ run_test(&tests[i]);
+ }
+
+ return 0;
+}
--
2.53.0
^ permalink raw reply related [flat|nested] 22+ messages in thread* Re: [PATCH 09/10] KVM: selftests: Add nested EPT mode-based execute control test
2026-12-03 23:49 ` [PATCH 09/10] KVM: selftests: Add nested EPT mode-based execute control test Dennis Reußwig
@ 2026-12-04 0:07 ` sashiko-bot
0 siblings, 0 replies; 22+ messages in thread
From: sashiko-bot @ 2026-12-04 0:07 UTC (permalink / raw)
To: Dennis Reußwig; +Cc: kvm
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] KVM: selftests: vmx_nested_mbec_test omits user-mode linear
address fetches
- [Low] KVM: selftests: vmx_nested_mbec_test lacks kselftest TAP and
skip reporting
--
commit d5eb6cc0d63627ad6ee5a99f17c015398b86328a
Author: Dennis Reußwig <dennis@reusswig.codes>
KVM: selftests: Add nested EPT mode-based execute control test
This commit adds a KVM x86 selftest that runs an L2 guest under L1 EPT
entries with varying supervisor and user execute permissions, with and
without mode-based execute control enabled, and checks the resulting
instruction fetches and EPT violation exit qualifications.
> diff --git a/tools/testing/selftests/kvm/x86/vmx_nested_mbec_test.c b/tools/testing/selftests/kvm/x86/vmx_nested_mbec_test.c
> new file mode 100644
> index 0000000000000..652b685466d57
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/x86/vmx_nested_mbec_test.c
[ ... ]
> +static void run_test(const struct mbec_test *t)
> +{
[ ... ]
> + /* A supervisor, executable mapping of the code page in L2's page tables. */
> + code_gpa = vm_phy_page_alloc(vm, MEM_REGION_DATA);
> + *(u8 *)addr_gpa2hva(vm, code_gpa) = 0xc3; /* RET */
> + virt_pg_map(vm, CODE_GVA, CODE_L2_GPA);
[Severity: Medium]
Should this test also exercise user-mode linear address fetches?
virt_pg_map() leaves PTE_USER_MASK clear at every L2 paging level, so
CODE_GVA is always a supervisor-mode linear address. Across tests[],
the fetch succeeds iff xs is set, and the only difference with mbec
enabled is EPT_VIOLATION_PROT_USER_EXEC on one case.
As a result, the test still passes if KVM fails to enable MBEC in
vmcs02, fails to translate EPT_VIOLATION_GVA_USER to PFERR_USER_MASK in
__vt_handle_ept_violation(), or never selects ~xu in
__update_permission_bitmask().
Since kvm_get_default_cr4() leaves X86_CR4_SMEP clear, setting
PTE_USER_MASK on all L2 paging levels for CODE_GVA would let L2 at
CPL 0 test user-mode linear address fetches without switching to
ring 3.
[ ... ]
> +int main(int argc, char *argv[])
> +{
> + bool has_mbec;
> + int i;
> +
> + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
> + TEST_REQUIRE(kvm_cpu_has_ept());
> +
> + has_mbec = kvm_cpu_has_secondary_exec_control(SECONDARY_EXEC_MODE_BASED_EPT_EXEC);
> + if (!has_mbec)
> + pr_info("MBEC not offered to L1, running only the cases without MBEC\n");
> +
> + for (i = 0; i < ARRAY_SIZE(tests); i++) {
> + if (tests[i].mbec && !has_mbec)
> + continue;
> + run_test(&tests[i]);
> + }
> +
> + return 0;
> +}
[Severity: Low]
Could this report subtest results through kselftest.h instead of
pr_info() and a bare return 0?
When MBEC is not offered to L1 (such as on CPUs without MBEC or with
kvm_intel.mbec=0), all four MBEC cases are silently skipped and make
run_tests records an unconditional pass with no TAP skip status or
reason.
Using the kselftest.h wrappers already pulled in by test_util.h
(ksft_print_header(), ksft_set_plan(), ksft_test_result_pass(),
ksft_test_result_skip(), and ksft_finished()) would emit structured
pass and skip results for each subtest.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes?part=9
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 10/10] KVM: selftests: Check VMX capabilities for CET in L2 with MBEC
2026-12-03 23:49 [PATCH 00/10] KVM: nVMX: Supervisor shadow-stack control for nested EPT and CET with eVMCS Dennis Reußwig
` (8 preceding siblings ...)
2026-12-03 23:49 ` [PATCH 09/10] KVM: selftests: Add nested EPT mode-based execute control test Dennis Reußwig
@ 2026-12-03 23:49 ` Dennis Reußwig
2026-12-04 0:10 ` sashiko-bot
9 siblings, 1 reply; 22+ messages in thread
From: Dennis Reußwig @ 2026-12-03 23:49 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, x86, H. Peter Anvin, Jon Kohler,
Jonathan Corbet, Shuah Khan, Randy Dunlap, Shuah Khan
Cc: kvm, linux-kernel, linux-doc, linux-kselftest, Chao Gao,
Maxim Levitsky, Vitaly Kuznetsov, Panayotis Katsaloulis,
Dennis Reußwig
Hyper-V enables CET for its guests when L1 is offered mode-based
execute control. It then needs supervisor shadow-stack control for
nested EPT and the VM-entry and VM-exit controls that load CET state,
with and without the enlightened VMCS. Read the capabilities from L1,
once without and once with eVMCS, since KVM filters the control MSRs
for eVMCS only for reads by the guest.
Without the fixes in this series the test fails: supervisor
shadow-stack control is missing, and with eVMCS also the CET controls.
Signed-off-by: Dennis Reußwig <dennis@reusswig.codes>
---
tools/testing/selftests/kvm/Makefile.kvm | 1 +
.../selftests/kvm/x86/vmx_nested_cet_caps_test.c | 90 ++++++++++++++++++++++
2 files changed, 91 insertions(+)
diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
index 2b502c9ec7cb..9e62ed2bec1a 100644
--- a/tools/testing/selftests/kvm/Makefile.kvm
+++ b/tools/testing/selftests/kvm/Makefile.kvm
@@ -148,6 +148,7 @@ TEST_GEN_PROGS_x86 += x86/vmx_invalid_nested_guest_state
TEST_GEN_PROGS_x86 += x86/vmx_nested_la57_state_test
TEST_GEN_PROGS_x86 += x86/vmx_nested_mbec_test
TEST_GEN_PROGS_x86 += x86/vmx_nested_sss_test
+TEST_GEN_PROGS_x86 += x86/vmx_nested_cet_caps_test
TEST_GEN_PROGS_x86 += x86/apic_bus_clock_test
TEST_GEN_PROGS_x86 += x86/apic_id_routing_test
TEST_GEN_PROGS_x86 += x86/xapic_ipi_test
diff --git a/tools/testing/selftests/kvm/x86/vmx_nested_cet_caps_test.c b/tools/testing/selftests/kvm/x86/vmx_nested_cet_caps_test.c
new file mode 100644
index 000000000000..cb9135df5d13
--- /dev/null
+++ b/tools/testing/selftests/kvm/x86/vmx_nested_cet_caps_test.c
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * VMX capabilities that L1 needs to run L2 guests with CET.
+ *
+ * Hyper-V enables CET for its guests when L1 is offered mode-based execute
+ * control (MBEC). It then needs supervisor shadow-stack control for nested
+ * EPT (IA32_VMX_EPT_VPID_CAP bit 23) and the VM-entry/VM-exit controls that
+ * load CET state, with and without the enlightened VMCS. KVM filters the
+ * control MSRs for eVMCS only when the guest reads them, so L1 reads them
+ * itself.
+ */
+#include "test_util.h"
+#include "kvm_util.h"
+#include "processor.h"
+#include "hyperv.h"
+#include "vmx.h"
+
+static void guest_code(void)
+{
+ u64 ctls2 = rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2);
+ u64 ept_cap = rdmsr(MSR_IA32_VMX_EPT_VPID_CAP);
+ u64 exit_ctls = rdmsr(MSR_IA32_VMX_TRUE_EXIT_CTLS);
+ u64 entry_ctls = rdmsr(MSR_IA32_VMX_TRUE_ENTRY_CTLS);
+
+ /* Without MBEC, Hyper-V does not enable CET and nothing is required. */
+ if (!((ctls2 >> 32) & SECONDARY_EXEC_MODE_BASED_EPT_EXEC))
+ GUEST_DONE();
+
+ __GUEST_ASSERT((exit_ctls >> 32) & VM_EXIT_LOAD_CET_STATE,
+ "MBEC offered but the VM-exit control to load CET state is not, exit controls 0x%lx",
+ exit_ctls);
+ __GUEST_ASSERT((entry_ctls >> 32) & VM_ENTRY_LOAD_CET_STATE,
+ "MBEC offered but the VM-entry control to load CET state is not, entry controls 0x%lx",
+ entry_ctls);
+
+ /* Supervisor shadow-stack control needs advanced VM-exit information. */
+ if (ept_cap & VMX_EPT_VPID_CAP_ADVANCED_VMEXIT_INFO)
+ __GUEST_ASSERT(ept_cap & VMX_EPT_VPID_CAP_SSS,
+ "MBEC offered but supervisor shadow-stack control is not, EPT capabilities 0x%lx",
+ ept_cap);
+
+ GUEST_DONE();
+}
+
+static void run_test(bool evmcs)
+{
+ struct kvm_vcpu *vcpu;
+ struct kvm_vm *vm;
+ struct ucall uc;
+
+ pr_info("Checking the VMX capabilities L1 sees %s eVMCS\n", evmcs ? "with" : "without");
+
+ vm = vm_create_with_one_vcpu(&vcpu, guest_code);
+ if (evmcs) {
+ vcpu_set_hv_cpuid(vcpu);
+ vcpu_enable_evmcs(vcpu);
+ }
+
+ vcpu_run(vcpu);
+ TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
+
+ switch (get_ucall(vcpu, &uc)) {
+ case UCALL_ABORT:
+ REPORT_GUEST_ASSERT(uc);
+ break;
+ case UCALL_DONE:
+ break;
+ default:
+ TEST_FAIL("Unexpected ucall %lu", uc.cmd);
+ }
+
+ kvm_vm_free(vm);
+}
+
+int main(int argc, char *argv[])
+{
+ TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX));
+ TEST_REQUIRE(kvm_cpu_has_ept());
+ TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SHSTK));
+ TEST_REQUIRE(kvm_cpu_has_secondary_exec_control(SECONDARY_EXEC_MODE_BASED_EPT_EXEC));
+
+ run_test(false);
+
+ if (kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS))
+ run_test(true);
+ else
+ pr_info("eVMCS not supported, skipping the eVMCS case\n");
+
+ return 0;
+}
--
2.53.0
^ permalink raw reply related [flat|nested] 22+ messages in thread* Re: [PATCH 10/10] KVM: selftests: Check VMX capabilities for CET in L2 with MBEC
2026-12-03 23:49 ` [PATCH 10/10] KVM: selftests: Check VMX capabilities for CET in L2 with MBEC Dennis Reußwig
@ 2026-12-04 0:10 ` sashiko-bot
2026-12-04 0:41 ` Dennis Reußwig
0 siblings, 1 reply; 22+ messages in thread
From: sashiko-bot @ 2026-12-04 0:10 UTC (permalink / raw)
To: Dennis Reußwig; +Cc: kvm
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] kvm: vmx_nested_cet_caps_test fails when host or L0 lacks EPT
SSS bit 23
- [Low] kvm: vmx_nested_cet_caps_test omits kselftest.h TAP reporting in
main()
- [Low] kvm: standalone vmx_nested_cet_caps_test instead of extending
existing test
--
commit 103206ea7ff8c4b0693e6b14fe9e0d35ad3cd5d8
Author: Dennis Reußwig <dennis@reusswig.codes>
KVM: selftests: Check VMX capabilities for CET in L2 with MBEC
This commit adds a new x86 KVM selftest, vmx_nested_cet_caps_test, that
checks whether L1 sees the VMX CET load controls and EPT supervisor
shadow-stack capability when mode-based execute control (MBEC) is
advertised, both with and without the enlightened VMCS.
> diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm
> index 2b502c9ec7cb8..9e62ed2bec1a3 100644
> --- a/tools/testing/selftests/kvm/Makefile.kvm
> +++ b/tools/testing/selftests/kvm/Makefile.kvm
> @@ -148,6 +148,7 @@ TEST_GEN_PROGS_x86 += x86/vmx_invalid_nested_guest_state
> TEST_GEN_PROGS_x86 += x86/vmx_nested_la57_state_test
> TEST_GEN_PROGS_x86 += x86/vmx_nested_mbec_test
> TEST_GEN_PROGS_x86 += x86/vmx_nested_sss_test
> +TEST_GEN_PROGS_x86 += x86/vmx_nested_cet_caps_test
> TEST_GEN_PROGS_x86 += x86/apic_bus_clock_test
> TEST_GEN_PROGS_x86 += x86/apic_id_routing_test
> TEST_GEN_PROGS_x86 += x86/xapic_ipi_test
[Severity: Low]
Could this check be added to an existing test such as vmx_msrs_test.c or
vmx_nested_sss_test.c instead of adding a new standalone binary? It only
reads four VMX capability MSRs from a minimal guest with and without
eVMCS.
> diff --git a/tools/testing/selftests/kvm/x86/vmx_nested_cet_caps_test.c b/tools/testing/selftests/kvm/x86/vmx_nested_cet_caps_test.c
> new file mode 100644
> index 0000000000000..cb9135df5d133
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/x86/vmx_nested_cet_caps_test.c
[ ... ]
> + /* Supervisor shadow-stack control needs advanced VM-exit information. */
> + if (ept_cap & VMX_EPT_VPID_CAP_ADVANCED_VMEXIT_INFO)
> + __GUEST_ASSERT(ept_cap & VMX_EPT_VPID_CAP_SSS,
> + "MBEC offered but supervisor shadow-stack control is not, EPT capabilities 0x%lx",
> + ept_cap);
[Severity: Medium]
Can this assertion fail on hosts or nested L1 environments where hardware
or the L0 hypervisor does not expose VMX_EPT_SSS_BIT?
In nested_vmx_setup_secondary_ctls(), KVM masks msrs->ept_caps against the
underlying MSR_IA32_VMX_EPT_VPID_CAP without clearing X86_FEATURE_SHSTK or
SECONDARY_EXEC_MODE_BASED_EPT_EXEC.
On an older L0 hypervisor or VMM that exposes SHSTK, MBEC, and advanced
VM-exit info without EPT SSS, all TEST_REQUIRE() checks in main() pass and
this assertion fails instead of skipping, breaking make run_tests.
[ ... ]
> + run_test(false);
> +
> + if (kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS))
> + run_test(true);
> + else
> + pr_info("eVMCS not supported, skipping the eVMCS case\n");
> +
> + return 0;
> +}
[Severity: Low]
Should main() report results through kselftest.h TAP helpers such as
ksft_print_header(), ksft_set_plan(), ksft_test_result_pass(),
ksft_test_result_skip(), and ksft_finished() instead of pr_info() and a
bare return 0?
Without structured TAP output, test runners cannot distinguish the skipped
eVMCS subcase from a full pass.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes?part=10
^ permalink raw reply [flat|nested] 22+ messages in thread* Re: [PATCH 10/10] KVM: selftests: Check VMX capabilities for CET in L2 with MBEC
2026-12-04 0:10 ` sashiko-bot
@ 2026-12-04 0:41 ` Dennis Reußwig
0 siblings, 0 replies; 22+ messages in thread
From: Dennis Reußwig @ 2026-12-04 0:41 UTC (permalink / raw)
To: sashiko-bot; +Cc: kvm, Dennis Reußwig
> [Severity: Low]
> Could this check be added to an existing test such as vmx_msrs_test.c or
> vmx_nested_sss_test.c instead of adding a new standalone binary?
Kept separate, because vmx_msrs_test checks the MSR ABI.
> [Severity: Medium]
> Can this assertion fail on hosts or nested L1 environments where hardware
> or the L0 hypervisor does not expose VMX_EPT_SSS_BIT?
Good catch, real bug, fixed in v2.
^ permalink raw reply [flat|nested] 22+ messages in thread