mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Dennis Reußwig" <dennis@reusswig.codes>
To: Sean Christopherson <seanjc@google.com>,
	 Paolo Bonzini <pbonzini@redhat.com>,
	Thomas Gleixner <tglx@kernel.org>,
	 Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	 Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org,  "H. Peter Anvin" <hpa@zytor.com>,
	Jon Kohler <jon@nutanix.com>,  Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	 Randy Dunlap <rdunlap@infradead.org>,
	Shuah Khan <shuah@kernel.org>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org,
	"Chao Gao" <chao.gao@intel.com>,
	"Maxim Levitsky" <mlevitsk@redhat.com>,
	"Vitaly Kuznetsov" <vkuznets@redhat.com>,
	"Panayotis Katsaloulis" <panayotis@panayotis.com>,
	"Dennis Reußwig" <dennis@reusswig.codes>
Subject: [PATCH 07/10] KVM: selftests: Add helpers for nested EPT shadow-stack and MBEC tests
Date: Fri, 04 Dec 2026 00:49:20 +0100	[thread overview]
Message-ID: <20261204-nested-sss-v1-7-57de06f58b2b@reusswig.codes> (raw)
In-Reply-To: <20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes>

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


  parent reply	other threads:[~2026-12-03 23:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` [PATCH 03/10] KVM: VMX: Report shadow-stack accesses in EPT violations as PFERR_SS Dennis Reußwig
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 ` [PATCH 05/10] KVM: nVMX: Shadow supervisor shadow-stack control of nested EPT Dennis Reußwig
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 [this message]
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 ` [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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204-nested-sss-v1-7-57de06f58b2b@reusswig.codes \
    --to=dennis@reusswig.codes \
    --cc=bp@alien8.de \
    --cc=chao.gao@intel.com \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jon@nutanix.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mlevitsk@redhat.com \
    --cc=panayotis@panayotis.com \
    --cc=pbonzini@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=tglx@kernel.org \
    --cc=vkuznets@redhat.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®