From: Manali Shukla <manali.shukla@amd.com>
To: <kvm@vger.kernel.org>
Subject: [kvm-unit-tests PATCH 1/3] x86: nSVM: Check #NM exception handling in L2
Date: Wed, 29 Dec 2021 06:21:59 +0000 [thread overview]
Message-ID: <20211229062201.26269-2-manali.shukla@amd.com> (raw)
In-Reply-To: <20211229062201.26269-1-manali.shukla@amd.com>
Add coverage for NM exception handling in L2 when only L2 NM
exception handler is registered
Verifies 3 different conditions for which #NM is generated and
handled in L2
1) CR0.TS is set - #NM is generated and handled in L2 exception
handler
2) CR0.TS is cleared and CR0.EM is set - #NM is generated and
handled in L2 exception handler
3) CR0.TS and CR0.EM are cleared - #NM is not generated
Signed-off-by: Manali Shukla <manali.shukla@amd.com>
---
x86/svm_tests.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/x86/svm_tests.c b/x86/svm_tests.c
index 8ad6122..681272c 100644
--- a/x86/svm_tests.c
+++ b/x86/svm_tests.c
@@ -2962,6 +2962,50 @@ static bool vgif_check(struct svm_test *test)
return get_test_stage(test) == 3;
}
+static int nm_test_counter;
+
+static void guest_test_nm_handler(struct ex_regs *r)
+{
+ nm_test_counter++;
+ write_cr0(read_cr0() & ~X86_CR0_TS);
+ write_cr0(read_cr0() & ~X86_CR0_EM);
+}
+
+static void svm_nm_test_guest(struct svm_test *test)
+{
+ asm volatile("fnop");
+}
+
+/* This test checks that:
+ *
+ * (a) If CR0.TS is set in L2, #NM is handled by L2 when
+ * just an L2 handler is registered.
+ *
+ * (b) If CR0.TS is cleared and CR0.EM is set, #NM is handled
+ * by L2 when just an l2 handler is registered.
+ *
+ * (c) If CR0.TS and CR0.EM are cleared in L2, no exception
+ * is generated.
+ */
+
+static void svm_nm_test(void)
+{
+ handle_exception(NM_VECTOR, guest_test_nm_handler);
+ write_cr0(read_cr0() & ~X86_CR0_TS);
+ test_set_guest(svm_nm_test_guest);
+
+ vmcb->save.cr0 = vmcb->save.cr0 | X86_CR0_TS;
+ report(svm_vmrun() == SVM_EXIT_VMMCALL && nm_test_counter == 1,
+ "fnop with CR0.TS set in L2, #NM is triggered");
+
+ vmcb->save.cr0 = (vmcb->save.cr0 & ~X86_CR0_TS) | X86_CR0_EM;
+ report(svm_vmrun() == SVM_EXIT_VMMCALL && nm_test_counter == 2,
+ "fnop with CR0.EM set in L2, #NM is triggered");
+
+ vmcb->save.cr0 = vmcb->save.cr0 & ~(X86_CR0_TS | X86_CR0_EM);
+ report(svm_vmrun() == SVM_EXIT_VMMCALL && nm_test_counter == 2,
+ "fnop with CR0.TS and CR0.EM unset no #NM excpetion");
+}
struct svm_test svm_tests[] = {
{ "null", default_supported, default_prepare,
@@ -3082,5 +3126,6 @@ struct svm_test svm_tests[] = {
TEST(svm_vmrun_errata_test),
TEST(svm_vmload_vmsave),
TEST(svm_test_singlestep),
+ TEST(svm_nm_test),
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL }
};
--
2.30.2
next prev parent reply other threads:[~2021-12-29 6:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-29 6:21 [kvm-unit-tests PATCH 0/3] Add L2 exception handling KVM unit tests for nSVM Manali Shukla
2021-12-29 6:21 ` Manali Shukla [this message]
2021-12-29 6:22 ` [kvm-unit-tests PATCH 2/3] x86: nSVM: Check #BP exception handling in L2 Manali Shukla
2021-12-29 6:22 ` [kvm-unit-tests PATCH 3/3] x86: nSVM: Check #OF " Manali Shukla
2022-01-07 4:05 ` [kvm-unit-tests PATCH 0/3] Add L2 exception handling KVM unit tests for nSVM Shukla, Manali
2022-01-12 21:29 ` Sean Christopherson
2022-01-18 11:11 ` Shukla, Manali
2022-01-18 11:38 ` Paolo Bonzini
2022-01-18 9:21 ` 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=20211229062201.26269-2-manali.shukla@amd.com \
--to=manali.shukla@amd.com \
--cc=kvm@vger.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;
as well as URLs for NNTP newsgroup(s).