From: Paolo Bonzini <pbonzini@redhat.com>
To: kvm@vger.kernel.org
Cc: Jon Kohler <jon@nutanix.com>, Nikunj A Dadhania <nikunj@amd.com>,
Amit Shah <amit.shah@amd.com>,
Sean Christopherson <seanjc@google.com>
Subject: [PATCH kvm-unit-tests 5/9] x86/vmx: diagnose unexpected EPT violations
Date: Thu, 26 Mar 2026 10:50:31 -0400 [thread overview]
Message-ID: <20260326145035.119519-6-pbonzini@redhat.com> (raw)
In-Reply-To: <20260326145035.119519-1-pbonzini@redhat.com>
Knowing the exit qualification when a test incorrectly raises an
EPT violation greatly simplifies debugging. This requires a tweak to
__TEST_EQ, allowing any code block instead of just a function name for
the abort code.
For this particular case, include advanced vmexit info in the diagnosis.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
lib/util.h | 10 +++-----
x86/vmx.h | 8 +++---
x86/vmx_tests.c | 65 ++++++++++++++++++++++++++++---------------------
3 files changed, 44 insertions(+), 39 deletions(-)
diff --git a/lib/util.h b/lib/util.h
index 00d0b47d..93f16410 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -41,17 +41,13 @@ do { \
(unsigned long) _b, _bin_b, (unsigned long) _b, \
fmt[0] == '\0' ? "" : "\n", ## args); \
dump_stack(); \
- if (assertion) \
- do_abort(); \
+ if (assertion) { do_abort; } \
} \
report_passed(); \
} while (0)
-/* FIXME: Extend VMX's assert/abort framework to SVM and other environs. */
-static inline void dummy_abort(void) {}
-
-#define TEST_EXPECT_EQ(a, b) __TEST_EQ(a, b, #a, #b, 0, dummy_abort, "")
+#define TEST_EXPECT_EQ(a, b) __TEST_EQ(a, b, #a, #b, 0, , "")
#define TEST_EXPECT_EQ_MSG(a, b, fmt, args...) \
- __TEST_EQ(a, b, #a, #b, 0, dummy_abort fmt, ## args)
+ __TEST_EQ(a, b, #a, #b, 0, fmt, ## args)
#endif
diff --git a/x86/vmx.h b/x86/vmx.h
index d9f493d3..0e29a57d 100644
--- a/x86/vmx.h
+++ b/x86/vmx.h
@@ -37,9 +37,9 @@ do { \
report_passed(); \
} while (0)
-#define TEST_ASSERT_EQ(a, b) __TEST_EQ(a, b, #a, #b, 1, __abort_test, "")
+#define TEST_ASSERT_EQ(a, b) __TEST_EQ(a, b, #a, #b, 1, __abort_test(), "")
#define TEST_ASSERT_EQ_MSG(a, b, fmt, args...) \
- __TEST_EQ(a, b, #a, #b, 1, __abort_test, fmt, ## args)
+ __TEST_EQ(a, b, #a, #b, 1, __abort_test(), fmt, ## args)
struct vmcs_hdr {
u32 revision_id:31;
@@ -718,9 +718,9 @@ enum vm_entry_failure_code {
#define EPT_VLT_PADDR (1ull << 8)
#define EPT_VLT_GUEST_USER (1ull << 9)
#define EPT_VLT_GUEST_RW (1ull << 10)
-#define EPT_VLT_GUEST_EX (1ull << 11)
+#define EPT_VLT_GUEST_NX (1ull << 11)
#define EPT_VLT_GUEST_MASK (EPT_VLT_GUEST_USER | EPT_VLT_GUEST_RW | \
- EPT_VLT_GUEST_EX)
+ EPT_VLT_GUEST_NX)
#define MAGIC_VAL_1 0x12345678ul
#define MAGIC_VAL_2 0x87654321ul
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 707e8ca4..0e3dca3c 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -2157,13 +2157,46 @@ static int exit_monitor_from_l2_handler(union exit_reason exit_reason)
return VMX_TEST_EXIT;
}
+static void
+diagnose_ept_violation_qual(u64 expected, u64 actual)
+{
+
+#define DIAGNOSE(flag) \
+do { \
+ if ((expected & flag) != (actual & flag)) \
+ printf(#flag " %sexpected\n", \
+ (expected & flag) ? "" : "un"); \
+} while (0)
+
+ DIAGNOSE(EPT_VLT_RD);
+ DIAGNOSE(EPT_VLT_WR);
+ DIAGNOSE(EPT_VLT_FETCH);
+ DIAGNOSE(EPT_VLT_PERM_RD);
+ DIAGNOSE(EPT_VLT_PERM_WR);
+ DIAGNOSE(EPT_VLT_PERM_EX);
+ DIAGNOSE(EPT_VLT_LADDR_VLD);
+ DIAGNOSE(EPT_VLT_PADDR);
+ DIAGNOSE(EPT_VLT_GUEST_USER);
+ DIAGNOSE(EPT_VLT_GUEST_RW);
+ DIAGNOSE(EPT_VLT_GUEST_NX);
+
+#undef DIAGNOSE
+}
+
static void assert_exit_reason(u64 expected)
{
u64 actual = vmcs_read(EXI_REASON);
- TEST_ASSERT_EQ_MSG(expected, actual, "Expected %s, got %s.",
- exit_reason_description(expected),
- exit_reason_description(actual));
+ __TEST_EQ(expected, actual, "expected", "actual", 1, {
+ printf("guest linear address %lx\n", vmcs_read(GUEST_LINEAR_ADDRESS));
+ if (actual == VMX_EPT_VIOLATION) {
+ u64 qual = vmcs_read(EXI_QUALIFICATION);
+ diagnose_ept_violation_qual(0, qual);
+ }
+ __abort_test();
+ }, "Expected %s, got %s.",
+ exit_reason_description(expected),
+ exit_reason_description(actual));
}
static void skip_exit_insn(void)
@@ -2276,29 +2309,6 @@ asm(
"ret42_end:\n"
);
-static void
-diagnose_ept_violation_qual(u64 expected, u64 actual)
-{
-
-#define DIAGNOSE(flag) \
-do { \
- if ((expected & flag) != (actual & flag)) \
- printf(#flag " %sexpected\n", \
- (expected & flag) ? "" : "un"); \
-} while (0)
-
- DIAGNOSE(EPT_VLT_RD);
- DIAGNOSE(EPT_VLT_WR);
- DIAGNOSE(EPT_VLT_FETCH);
- DIAGNOSE(EPT_VLT_PERM_RD);
- DIAGNOSE(EPT_VLT_PERM_WR);
- DIAGNOSE(EPT_VLT_PERM_EX);
- DIAGNOSE(EPT_VLT_LADDR_VLD);
- DIAGNOSE(EPT_VLT_PADDR);
-
-#undef DIAGNOSE
-}
-
static void do_ept_access_op(enum ept_access_op op)
{
ept_access_test_data.op = op;
@@ -2360,8 +2370,7 @@ static void do_ept_violation(bool leaf, enum ept_access_op op,
qual = vmcs_read(EXI_QUALIFICATION);
/* Mask undefined bits (which may later be defined in certain cases). */
- qual &= ~(EPT_VLT_GUEST_USER | EPT_VLT_GUEST_RW | EPT_VLT_GUEST_EX |
- EPT_VLT_PERM_USER_EX);
+ qual &= ~(EPT_VLT_GUEST_MASK | EPT_VLT_PERM_USER_EX);
diagnose_ept_violation_qual(expected_qual, qual);
TEST_EXPECT_EQ(expected_qual, qual);
--
2.52.0
next prev parent reply other threads:[~2026-03-26 14:50 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 14:50 [PATCH kvm-unit-tests 0/9] Combined GMET and MBEC tests Paolo Bonzini
2026-03-26 14:50 ` [PATCH kvm-unit-tests 1/9] move PFERR_* constants to lib Paolo Bonzini
2026-03-26 14:50 ` [PATCH kvm-unit-tests 2/9] add definitions for nested_ctl Paolo Bonzini
2026-03-26 14:50 ` [PATCH kvm-unit-tests 3/9] svm: add basic GMET tests Paolo Bonzini
2026-03-27 16:03 ` Jon Kohler
2026-03-26 14:50 ` [PATCH kvm-unit-tests 4/9] x86/vmx: update EPT installation to use EPT_PRESENT flag Paolo Bonzini
2026-03-26 14:50 ` Paolo Bonzini [this message]
2026-03-26 14:50 ` [PATCH kvm-unit-tests 6/9] x86/vmx: add mode-based execute control test for Skylake and above Paolo Bonzini
2026-03-27 15:57 ` Jon Kohler
2026-03-26 14:50 ` [PATCH kvm-unit-tests 7/9] x86/vmx: add user execution operation to EPT access tests Paolo Bonzini
2026-03-26 14:50 ` [PATCH kvm-unit-tests 8/9] x86/vmx: run EPT tests with MBEC enabled when available Paolo Bonzini
2026-03-26 16:13 ` Paolo Bonzini
2026-03-27 15:57 ` Jon Kohler
2026-03-27 15:57 ` Jon Kohler
2026-03-26 14:50 ` [PATCH kvm-unit-tests 9/9] x86/vmx: add EPT tests covering XU permission Paolo Bonzini
2026-03-27 15:56 ` Jon Kohler
2026-05-12 11:06 ` [PATCH kvm-unit-tests 0/9] Combined GMET and MBEC tests Paolo Bonzini
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=20260326145035.119519-6-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=amit.shah@amd.com \
--cc=jon@nutanix.com \
--cc=kvm@vger.kernel.org \
--cc=nikunj@amd.com \
--cc=seanjc@google.com \
/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