diff mbox series

[kvm-unit-tests,v2,4/4] x86: nSVM: Move part of #NM test to exception test framework

Message ID 20220810052313.7630-1-manali.shukla@amd.com (mailing list archive)
State New, archived
Headers show
Series x86: nSVM: Add testing for routing L2 exceptions | expand

Commit Message

Manali Shukla Aug. 10, 2022, 5:23 a.m. UTC
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(-)

Comments

Sean Christopherson Oct. 5, 2022, 9:17 p.m. UTC | #1
On Wed, Aug 10, 2022, Manali Shukla wrote:
>  static void svm_nm_test(void)

IMO, this should be renamed to svm_no_nm_test().

>  {
>  	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");

No need to keep the #NM handler, just rely on the VMMCAL assertion and the fact
that an unexpected #NM will also cause a test failure.
diff mbox series

Patch

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;