From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, Sean Christopherson <seanjc@google.com>,
Manali Shukla <manali.shukla@amd.com>
Subject: [kvm-unit-tests PATCH v3 9/9] nVMX: Move #NM test to generic exception test framework
Date: Wed, 5 Oct 2022 23:52:12 +0000 [thread overview]
Message-ID: <20221005235212.57836-10-seanjc@google.com> (raw)
In-Reply-To: <20221005235212.57836-1-seanjc@google.com>
Move the #NM test cases to the generic exception test framework, and
rename the dedicated test to note that it tests the "no #NM" case.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
x86/vmx_tests.c | 67 ++++++-------------------------------------------
1 file changed, 8 insertions(+), 59 deletions(-)
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 368ad43..2438022 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -8359,67 +8359,14 @@ static void vmx_cr4_osxsave_test(void)
TEST_ASSERT(this_cpu_has(X86_FEATURE_OSXSAVE));
}
-static void vmx_nm_test_guest(void)
-{
- write_cr0(read_cr0() | X86_CR0_TS);
- asm volatile("fnop");
-}
-
-static void check_nm_exit(const char *test)
-{
- u32 reason = vmcs_read(EXI_REASON);
- u32 intr_info = vmcs_read(EXI_INTR_INFO);
- const u32 expected = INTR_INFO_VALID_MASK | INTR_TYPE_HARD_EXCEPTION |
- NM_VECTOR;
-
- report(reason == VMX_EXC_NMI && intr_info == expected, "%s", test);
-}
-
/*
- * This test checks that:
- *
- * (a) If L2 launches with CR0.TS clear, but later sets CR0.TS, then
- * a subsequent #NM VM-exit is reflected to L1.
- *
- * (b) If L2 launches with CR0.TS clear and CR0.EM set, then a
- * subsequent #NM VM-exit is reflected to L1.
+ * FNOP with both CR0.TS and CR0.EM clear should not generate #NM, and the L2
+ * guest should exit normally.
*/
-static void vmx_nm_test(void)
+static void vmx_no_nm_test(void)
{
- unsigned long cr0 = read_cr0();
-
- test_set_guest(vmx_nm_test_guest);
-
- /*
- * L1 wants to intercept #NM exceptions encountered in L2.
- */
- vmcs_write(EXC_BITMAP, 1 << NM_VECTOR);
-
- /*
- * Launch L2 with CR0.TS clear, but don't claim host ownership of
- * any CR0 bits. L2 will set CR0.TS and then try to execute fnop,
- * which will raise #NM. L0 should reflect the #NM VM-exit to L1.
- */
- vmcs_write(CR0_MASK, 0);
- vmcs_write(GUEST_CR0, cr0 & ~X86_CR0_TS);
- enter_guest();
- check_nm_exit("fnop with CR0.TS set in L2 triggers #NM VM-exit to L1");
-
- /*
- * Re-enter L2 at the fnop instruction, with CR0.TS clear but
- * CR0.EM set. The fnop will still raise #NM, and L0 should
- * reflect the #NM VM-exit to L1.
- */
- vmcs_write(GUEST_CR0, (cr0 & ~X86_CR0_TS) | X86_CR0_EM);
- enter_guest();
- check_nm_exit("fnop with CR0.EM set in L2 triggers #NM VM-exit to L1");
-
- /*
- * Re-enter L2 at the fnop instruction, with both CR0.TS and
- * CR0.EM clear. There will be no #NM, and the L2 guest should
- * exit normally.
- */
- vmcs_write(GUEST_CR0, cr0 & ~(X86_CR0_TS | X86_CR0_EM));
+ test_set_guest(fnop);
+ vmcs_write(GUEST_CR0, read_cr0() & ~(X86_CR0_TS | X86_CR0_EM));
enter_guest();
}
@@ -10666,6 +10613,8 @@ struct vmx_exception_test vmx_exception_tests[] = {
{ BP_VECTOR, generate_bp },
{ AC_VECTOR, vmx_l2_ac_test },
{ OF_VECTOR, generate_of },
+ { NM_VECTOR, generate_cr0_ts_nm },
+ { NM_VECTOR, generate_cr0_em_nm },
};
static u8 vmx_exception_test_vector;
@@ -10804,7 +10753,7 @@ struct vmx_test vmx_tests[] = {
TEST(vmx_ldtr_test),
TEST(vmx_cr_load_test),
TEST(vmx_cr4_osxsave_test),
- TEST(vmx_nm_test),
+ TEST(vmx_no_nm_test),
TEST(vmx_db_test),
TEST(vmx_nmi_window_test),
TEST(vmx_intr_window_test),
--
2.38.0.rc1.362.ged0d419d3c-goog
next prev parent reply other threads:[~2022-10-05 23:52 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-05 23:52 [kvm-unit-tests PATCH v3 0/9] x86: n{VMX,SVM} exception tests Sean Christopherson
2022-10-05 23:52 ` [kvm-unit-tests PATCH v3 1/9] nVMX: Add "nop" after setting EFLAGS.TF to guarantee single-step #DB Sean Christopherson
2022-10-05 23:52 ` [kvm-unit-tests PATCH v3 2/9] x86: Move helpers to generate misc exceptions to processor.h Sean Christopherson
2022-10-05 23:52 ` [kvm-unit-tests PATCH v3 3/9] nVMX: Move #OF test to generic exceptions test Sean Christopherson
2022-10-05 23:52 ` [kvm-unit-tests PATCH v3 4/9] nVMX: Drop one-off INT3=>#BP test Sean Christopherson
2022-10-05 23:52 ` [kvm-unit-tests PATCH v3 5/9] x86: nSVM: Add an exception test framework and tests Sean Christopherson
2022-10-05 23:52 ` [kvm-unit-tests PATCH v3 6/9] x86: nSVM: Move #BP test to exception test framework Sean Christopherson
2022-10-05 23:52 ` [kvm-unit-tests PATCH v3 7/9] x86: nSVM: Move #OF " Sean Christopherson
2022-10-05 23:52 ` [kvm-unit-tests PATCH v3 8/9] x86: nSVM: Move part of #NM " Sean Christopherson
2022-10-05 23:52 ` Sean Christopherson [this message]
2022-10-12 4:17 ` [kvm-unit-tests PATCH v3 0/9] x86: n{VMX,SVM} exception tests Manali Shukla
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=20221005235212.57836-10-seanjc@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=manali.shukla@amd.com \
--cc=pbonzini@redhat.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;
as well as URLs for NNTP newsgroup(s).