Skip to contentSkip to conversation

x86/svm: add comprehensive tests for GMET

PATCH New Jon Kohler 1 participant 1 message May 28 KVM

lore
Share & tools
lore

Jon Kohler

author
#0 lore raw

PATCH 1/1 x86/svm: add comprehensive tests for GMET

Enhancements:
- Improve code comments on all GMET tests explaining the setup rationale and polishing up here and there.
- Update npt_prepare_gmet_pte() comment in svm.c to document GMET U-bit semantics (U=0 allows, U=1 traps).
- Add report_info() calls to every GMET check function logging exit_code, exit_info_1, and expected values so failures are immediately diagnosable from test output.

New tests:
- npt_gmet_rw: verify GMET does not affect data reads/writes (U=0 data page with GMET enabled should succeed).
- npt_gmet_ring3: verify user-mode (ring 3) instruction fetches are not affected by GMET regardless of the NPT U bit, similar to the MBEC OP_EXEC_USER -> run_in_user() behavior.
- npt_gmet_large: verify GMET traps on a 2M large page with U=1.
- gmet_transition_v2: verify GMET on/off transitions with U=1 code.
- gmet_matrix_v2: systematic NX/U/access-type permission matrix.

---
 x86/svm.c     |   9 +-
 x86/svm_npt.c | 384 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 389 insertions(+), 4 deletions(-)
x86/svm.c +5 -4
index beb57f33..283d14ed 100644
@@ -43,6 +43,11 @@ u64 *npt_get_pml4e(void)
 	return pml4e;
 }
 
+/*
+ * Set or clear the NPT U bit on the 2 MiB code region.  With GMET enabled,
+ * U=0 allows supervisor instruction fetches and U=1 traps them (#NPF).
+ * GMET does not affect data accesses, so page table walks ignore U.
+ */
 void npt_prepare_gmet_pte(bool user)
 {
 	extern u8 start;
@@ -51,10 +56,6 @@ void npt_prepare_gmet_pte(bool user)
 	u64 *pte;
 	int i;
 
-
-	/* flip the U bit on the 2 MiB region where the code is loaded.
-	 * the U bit is only used for execution, therefore page table accesses ignore it
-	 */
 	pte = npt_get_pte(address);
 	for (i = 0; i < 512; i++)
 		pte[i] = (pte[i] & ~PT_USER_MASK) | mask;
x86/svm_npt.c +384 -0

426 lines not on this page · raw message

Signature · 1 line
2.43.0