All of lore.kernel.org
 help / color / mirror / Atom feed
From: Manali Shukla <manali.shukla@amd.com>
To: <pbonzini@redhat.com>, <seanjc@google.com>
Cc: <kvm@vger.kernel.org>, <aaronlewis@google.com>
Subject: [kvm-unit-tests PATCH v2 4/4] x86: nSVM: Move part of #NM test to exception test framework
Date: Wed, 10 Aug 2022 05:23:13 +0000	[thread overview]
Message-ID: <20220810052313.7630-1-manali.shukla@amd.com> (raw)
In-Reply-To: <20220810050738.7442-1-manali.shukla@amd.com>

Remove the boiler plate code for #NM test and move #NM exception test in
exception test framework.

Keep the test case for the condition where #NM exception is not
generated as it is.

Signed-off-by: Manali Shukla <manali.shukla@amd.com>
---
 x86/svm_tests.c | 44 ++++++++++++++++++++++++--------------------
 1 file changed, 24 insertions(+), 20 deletions(-)

diff --git a/x86/svm_tests.c b/x86/svm_tests.c
index b0f0980..2ed65c3 100644
--- a/x86/svm_tests.c
+++ b/x86/svm_tests.c
@@ -2807,34 +2807,18 @@ 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.
+/*
+ * 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,
+	report(svm_vmrun() == SVM_EXIT_VMMCALL && nm_test_counter == 0,
 	       "fnop with CR0.TS and CR0.EM unset no #NM excpetion");
 }
 
@@ -3308,6 +3292,24 @@ static void svm_l2_ac_test(struct svm_test *test)
 	vmmcall();
 }
 
+/*
+ * If CR0.TS is set in L2, #NM is generared
+ */
+static void svm_l2_nm_test(struct svm_test *svm)
+{
+	write_cr0(read_cr0() | X86_CR0_TS);
+	asm volatile("fnop");
+}
+
+/*
+ * If CR0.TS is cleared and CR0.EM is set, #NM is generated
+ */
+static void svm_l2_nm_test1(struct svm_test *svm)
+{
+	write_cr0((read_cr0() & ~X86_CR0_TS) | X86_CR0_EM);
+	asm volatile("fnop");
+}
+
 struct svm_exception_test {
 	u8 vector;
 	void (*guest_code)(struct svm_test*);
@@ -3321,6 +3323,8 @@ struct svm_exception_test svm_exception_tests[] = {
 	{ AC_VECTOR, svm_l2_ac_test },
 	{ BP_VECTOR, svm_l2_bp_test },
 	{ OF_VECTOR, svm_l2_of_test },
+	{ NM_VECTOR, svm_l2_nm_test },
+	{ NM_VECTOR, svm_l2_nm_test1 },
 };
 
 static u8 svm_exception_test_vector;
-- 
2.34.1


  parent reply	other threads:[~2022-08-10  5:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-10  5:07 [kvm-unit-tests PATCH v2 0/4] x86: nSVM: Add testing for routing L2 exceptions Manali Shukla
2022-08-10  5:20 ` [kvm-unit-tests PATCH v2 1/4] x86: nSVM: Add an exception test framework and tests Manali Shukla
2022-10-05 21:16   ` Sean Christopherson
2022-08-10  5:21 ` [kvm-unit-tests PATCH v2 2/4] x86: nSVM: Move #BP test to exception test framework Manali Shukla
2022-08-10  5:22 ` [kvm-unit-tests PATCH v2 3/4] x86: nSVM: Move #OF " Manali Shukla
2022-08-10  5:23 ` Manali Shukla [this message]
2022-10-05 21:17   ` [kvm-unit-tests PATCH v2 4/4] x86: nSVM: Move part of #NM " Sean Christopherson
2022-08-29  4:11 ` [kvm-unit-tests PATCH v2 0/4] x86: nSVM: Add testing for routing L2 exceptions Manali Shukla
2022-09-19  4:41   ` Manali Shukla
2022-09-26  4:34     ` Manali Shukla
2022-10-03  4:15       ` Manali Shukla
2022-10-03  7:07         ` Maxim Levitsky
2022-10-05 21:14 ` Sean Christopherson

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=20220810052313.7630-1-manali.shukla@amd.com \
    --to=manali.shukla@amd.com \
    --cc=aaronlewis@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.