kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH v2 0/4] x86: nSVM: Add testing for routing L2 exceptions
@ 2022-08-10  5:07 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
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Manali Shukla @ 2022-08-10  5:07 UTC (permalink / raw)
  To: pbonzini, seanjc; +Cc: kvm, aaronlewis

Series is inspired by vmx exception test framework series[1].

Set up a test framework that verifies an exception occurring in L2 is
forwarded to the right place (L1 or L2).

Tests two conditions for each exception.
1) Exception generated in L2, is handled by L2 when L2 exception handler
   is registered.
2) Exception generated in L2, is handled by L1 when intercept exception
   bit map is set in L1.

Above tests were added to verify 8 different exceptions.
#GP, #UD, #DE, #DB, #AC, #OF, #BP, #NM.

There are 4 patches in this series
1) Added test infrastructure and exception tests.
2) Move #BP test to exception test framework.
3) Move #OF test to exception test framework.
4) Move part of #NM test to exception test framework because
   #NM has a test case which checks the condition for which #NM should not
   be generated, all the test cases under #NM test except this test case have been
   moved to exception test framework because of the exception test framework
   design.

v1->v2
1) Rebased to latest kvm-unit-tests. 
2) Move 3 different exception test cases #BP, #OF and #NM exception to
   exception test framework.

[1] https://lore.kernel.org/all/20220125203127.1161838-1-aaronlewis@google.com/
[2] https://lore.kernel.org/kvm/a090c16f-c307-9548-9739-ceb71687514f@amd.com/

Manali Shukla (4):
  x86: nSVM: Add an exception test framework and tests
  x86: nSVM: Move #BP test to exception test framework
  x86: nSVM: Move #OF test to exception test framework
  x86: nSVM: Move part of #NM test to exception test framework

 x86/svm_tests.c | 197 ++++++++++++++++++++++++++++++++++--------------
 1 file changed, 142 insertions(+), 55 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [kvm-unit-tests PATCH v2 1/4] x86: nSVM: Add an exception test framework and tests
  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 ` 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
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: Manali Shukla @ 2022-08-10  5:20 UTC (permalink / raw)
  To: pbonzini, seanjc; +Cc: kvm, aaronlewis

Set up a test framework that verifies an exception occurring
in L2 is forwarded to the right place (L1 or L2).
It adds an exception test array and exception callbacks to that array.

Tests two conditions for each exception.
1) Exception generated in L2, is handled by L2 when L2 exception handler
   is registered.
2) Exception generated in L2, is handled by L1 when intercept exception
   bit map is set in L1.

Add testing for below exceptions:
(#GP, #UD, #DE, #DB, #AC)
1. #GP is generated in c by non-canonical access in L2.
2. #UD is generated by calling "ud2" instruction in L2.
3. #DE is generated using instrumented code which generates
   divide by zero condition.
4. #DB is generated by setting TF bit before entering to L2.
5. #AC is genrated by writing 8 bytes to 4 byte aligned address in L2
   user mode when AM bit is set in CR0 register and AC bit is set in
   RFLAGS.

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

diff --git a/x86/svm_tests.c b/x86/svm_tests.c
index e2ec954..7544034 100644
--- a/x86/svm_tests.c
+++ b/x86/svm_tests.c
@@ -10,6 +10,7 @@
 #include "isr.h"
 #include "apic.h"
 #include "delay.h"
+#include "x86/usermode.h"
 
 #define SVM_EXIT_MAX_DR_INTERCEPT 0x3f
 
@@ -3289,6 +3290,118 @@ static void svm_intr_intercept_mix_smi(void)
 	svm_intr_intercept_mix_run_guest(NULL, SVM_EXIT_SMI);
 }
 
+static void svm_l2_gp_test(struct svm_test *test)
+{
+	*(volatile u64 *)NONCANONICAL = 0;
+}
+
+static void svm_l2_ud_test(struct svm_test *test)
+{
+	asm volatile ("ud2");
+}
+
+static void svm_l2_de_test(struct svm_test *test)
+{
+	asm volatile (
+		"xor %%eax, %%eax\n\t"
+		"xor %%ebx, %%ebx\n\t"
+		"xor %%edx, %%edx\n\t"
+		"idiv %%ebx\n\t"
+		::: "eax", "ebx", "edx");
+}
+
+static void svm_l2_db_test(struct svm_test *test)
+{
+	write_rflags(read_rflags() | X86_EFLAGS_TF);
+}
+
+static uint64_t usermode_callback(void)
+{
+	/*
+	 * Trigger an #AC by writing 8 bytes to a 4-byte aligned address.
+	 * Disclaimer: It is assumed that the stack pointer is aligned
+	 * on a 16-byte boundary as x86_64 stacks should be.
+	 */
+	asm volatile("movq $0, -0x4(%rsp)");
+
+	return 0;
+}
+
+static void svm_l2_ac_test(struct svm_test *test)
+{
+	bool hit_ac = false;
+
+	write_cr0(read_cr0() | X86_CR0_AM);
+	write_rflags(read_rflags() | X86_EFLAGS_AC);
+
+	run_in_user(usermode_callback, AC_VECTOR, 0, 0, 0, 0, &hit_ac);
+	report(hit_ac, "Usermode #AC handled in L2");
+	vmmcall();
+}
+
+struct svm_exception_test {
+	u8 vector;
+	void (*guest_code)(struct svm_test*);
+};
+
+struct svm_exception_test svm_exception_tests[] = {
+	{ GP_VECTOR, svm_l2_gp_test },
+	{ UD_VECTOR, svm_l2_ud_test },
+	{ DE_VECTOR, svm_l2_de_test },
+	{ DB_VECTOR, svm_l2_db_test },
+	{ AC_VECTOR, svm_l2_ac_test },
+};
+
+static u8 svm_exception_test_vector;
+
+static void svm_exception_handler(struct ex_regs *regs)
+{
+	report(regs->vector == svm_exception_test_vector,
+		"Handling %s in L2's exception handler",
+		exception_mnemonic(svm_exception_test_vector));
+	vmmcall();
+}
+
+static void handle_exception_in_l2(u8 vector)
+{
+	handler old_handler = handle_exception(vector, svm_exception_handler);
+	svm_exception_test_vector = vector;
+
+	report(svm_vmrun() == SVM_EXIT_VMMCALL,
+		"%s handled by L2", exception_mnemonic(vector));
+
+	handle_exception(vector, old_handler);
+}
+
+static void handle_exception_in_l1(u32 vector)
+{
+	u32 old_ie = vmcb->control.intercept_exceptions;
+
+	vmcb->control.intercept_exceptions |= (1ULL << vector);
+
+	report(svm_vmrun() == (SVM_EXIT_EXCP_BASE + vector),
+		"%s handled by L1",  exception_mnemonic(vector));
+
+	vmcb->control.intercept_exceptions = old_ie;
+}
+
+static void svm_exception_test(void)
+{
+	struct svm_exception_test *t;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(svm_exception_tests); i++) {
+		t = &svm_exception_tests[i];
+		test_set_guest(t->guest_code);
+
+		handle_exception_in_l2(t->vector);
+		vmcb_ident(vmcb);
+
+		handle_exception_in_l1(t->vector);
+		vmcb_ident(vmcb);
+	}
+}
+
 struct svm_test svm_tests[] = {
 	{ "null", default_supported, default_prepare,
 	  default_prepare_gif_clear, null_test,
@@ -3389,6 +3502,7 @@ struct svm_test svm_tests[] = {
 	TEST(svm_nm_test),
 	TEST(svm_int3_test),
 	TEST(svm_into_test),
+	TEST(svm_exception_test),
 	TEST(svm_lbrv_test0),
 	TEST(svm_lbrv_test1),
 	TEST(svm_lbrv_test2),
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [kvm-unit-tests PATCH v2 2/4] x86: nSVM: Move #BP test to exception test framework
  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-08-10  5:21 ` Manali Shukla
  2022-08-10  5:22 ` [kvm-unit-tests PATCH v2 3/4] x86: nSVM: Move #OF " Manali Shukla
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Manali Shukla @ 2022-08-10  5:21 UTC (permalink / raw)
  To: pbonzini, seanjc; +Cc: kvm, aaronlewis

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

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

diff --git a/x86/svm_tests.c b/x86/svm_tests.c
index 7544034..b36aec1 100644
--- a/x86/svm_tests.c
+++ b/x86/svm_tests.c
@@ -2804,26 +2804,11 @@ static void svm_into_test(void)
 	       "#OF is generated in L2 exception handler");
 }
 
-static int bp_test_counter;
-
-static void guest_test_bp_handler(struct ex_regs *r)
-{
-	bp_test_counter++;
-}
-
-static void svm_bp_test_guest(struct svm_test *test)
+static void svm_l2_bp_test(struct svm_test *test)
 {
 	asm volatile("int3");
 }
 
-static void svm_int3_test(void)
-{
-	handle_exception(BP_VECTOR, guest_test_bp_handler);
-	test_set_guest(svm_bp_test_guest);
-	report(svm_vmrun() == SVM_EXIT_VMMCALL && bp_test_counter == 1,
-	       "#BP is handled in L2 exception handler");
-}
-
 static int nm_test_counter;
 
 static void guest_test_nm_handler(struct ex_regs *r)
@@ -3350,6 +3335,7 @@ struct svm_exception_test svm_exception_tests[] = {
 	{ DE_VECTOR, svm_l2_de_test },
 	{ DB_VECTOR, svm_l2_db_test },
 	{ AC_VECTOR, svm_l2_ac_test },
+	{ BP_VECTOR, svm_l2_bp_test },
 };
 
 static u8 svm_exception_test_vector;
@@ -3500,7 +3486,6 @@ struct svm_test svm_tests[] = {
 	TEST(svm_vmload_vmsave),
 	TEST(svm_test_singlestep),
 	TEST(svm_nm_test),
-	TEST(svm_int3_test),
 	TEST(svm_into_test),
 	TEST(svm_exception_test),
 	TEST(svm_lbrv_test0),
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [kvm-unit-tests PATCH v2 3/4] x86: nSVM: Move #OF test to exception test framework
  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-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 ` Manali Shukla
  2022-08-10  5:23 ` [kvm-unit-tests PATCH v2 4/4] x86: nSVM: Move part of #NM " Manali Shukla
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 13+ messages in thread
From: Manali Shukla @ 2022-08-10  5:22 UTC (permalink / raw)
  To: pbonzini, seanjc; +Cc: kvm, aaronlewis

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

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

diff --git a/x86/svm_tests.c b/x86/svm_tests.c
index b36aec1..b0f0980 100644
--- a/x86/svm_tests.c
+++ b/x86/svm_tests.c
@@ -2756,15 +2756,7 @@ static void pause_filter_test(void)
 	}
 }
 
-
-static int of_test_counter;
-
-static void guest_test_of_handler(struct ex_regs *r)
-{
-	of_test_counter++;
-}
-
-static void svm_of_test_guest(struct svm_test *test)
+static void svm_l2_of_test(struct svm_test *test)
 {
 	struct far_pointer32 fp = {
 		.offset = (uintptr_t)&&into,
@@ -2796,14 +2788,6 @@ into:
 	__builtin_unreachable();
 }
 
-static void svm_into_test(void)
-{
-	handle_exception(OF_VECTOR, guest_test_of_handler);
-	test_set_guest(svm_of_test_guest);
-	report(svm_vmrun() == SVM_EXIT_VMMCALL && of_test_counter == 1,
-	       "#OF is generated in L2 exception handler");
-}
-
 static void svm_l2_bp_test(struct svm_test *test)
 {
 	asm volatile("int3");
@@ -3336,6 +3320,7 @@ struct svm_exception_test svm_exception_tests[] = {
 	{ DB_VECTOR, svm_l2_db_test },
 	{ AC_VECTOR, svm_l2_ac_test },
 	{ BP_VECTOR, svm_l2_bp_test },
+	{ OF_VECTOR, svm_l2_of_test },
 };
 
 static u8 svm_exception_test_vector;
@@ -3486,7 +3471,6 @@ struct svm_test svm_tests[] = {
 	TEST(svm_vmload_vmsave),
 	TEST(svm_test_singlestep),
 	TEST(svm_nm_test),
-	TEST(svm_into_test),
 	TEST(svm_exception_test),
 	TEST(svm_lbrv_test0),
 	TEST(svm_lbrv_test1),
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [kvm-unit-tests PATCH v2 4/4] x86: nSVM: Move part of #NM test to exception test framework
  2022-08-10  5:07 [kvm-unit-tests PATCH v2 0/4] x86: nSVM: Add testing for routing L2 exceptions Manali Shukla
                   ` (2 preceding siblings ...)
  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
  2022-10-05 21:17   ` 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-10-05 21:14 ` Sean Christopherson
  5 siblings, 1 reply; 13+ messages in thread
From: Manali Shukla @ 2022-08-10  5:23 UTC (permalink / raw)
  To: pbonzini, seanjc; +Cc: kvm, aaronlewis

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


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [kvm-unit-tests PATCH v2 0/4] x86: nSVM: Add testing for routing L2 exceptions
  2022-08-10  5:07 [kvm-unit-tests PATCH v2 0/4] x86: nSVM: Add testing for routing L2 exceptions Manali Shukla
                   ` (3 preceding siblings ...)
  2022-08-10  5:23 ` [kvm-unit-tests PATCH v2 4/4] x86: nSVM: Move part of #NM " Manali Shukla
@ 2022-08-29  4:11 ` Manali Shukla
  2022-09-19  4:41   ` Manali Shukla
  2022-10-05 21:14 ` Sean Christopherson
  5 siblings, 1 reply; 13+ messages in thread
From: Manali Shukla @ 2022-08-29  4:11 UTC (permalink / raw)
  To: pbonzini, seanjc; +Cc: kvm, aaronlewis

On 8/10/2022 10:37 AM, Manali Shukla wrote:
> Series is inspired by vmx exception test framework series[1].
> 
> Set up a test framework that verifies an exception occurring in L2 is
> forwarded to the right place (L1 or L2).
> 
> Tests two conditions for each exception.
> 1) Exception generated in L2, is handled by L2 when L2 exception handler
>    is registered.
> 2) Exception generated in L2, is handled by L1 when intercept exception
>    bit map is set in L1.
> 
> Above tests were added to verify 8 different exceptions.
> #GP, #UD, #DE, #DB, #AC, #OF, #BP, #NM.
> 
> There are 4 patches in this series
> 1) Added test infrastructure and exception tests.
> 2) Move #BP test to exception test framework.
> 3) Move #OF test to exception test framework.
> 4) Move part of #NM test to exception test framework because
>    #NM has a test case which checks the condition for which #NM should not
>    be generated, all the test cases under #NM test except this test case have been
>    moved to exception test framework because of the exception test framework
>    design.
> 
> v1->v2
> 1) Rebased to latest kvm-unit-tests. 
> 2) Move 3 different exception test cases #BP, #OF and #NM exception to
>    exception test framework.
> 
> [1] https://lore.kernel.org/all/20220125203127.1161838-1-aaronlewis@google.com/
> [2] https://lore.kernel.org/kvm/a090c16f-c307-9548-9739-ceb71687514f@amd.com/
> 
> Manali Shukla (4):
>   x86: nSVM: Add an exception test framework and tests
>   x86: nSVM: Move #BP test to exception test framework
>   x86: nSVM: Move #OF test to exception test framework
>   x86: nSVM: Move part of #NM test to exception test framework
> 
>  x86/svm_tests.c | 197 ++++++++++++++++++++++++++++++++++--------------
>  1 file changed, 142 insertions(+), 55 deletions(-)
> 

A gentle reminder for the review

-Manali

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [kvm-unit-tests PATCH v2 0/4] x86: nSVM: Add testing for routing L2 exceptions
  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
  0 siblings, 1 reply; 13+ messages in thread
From: Manali Shukla @ 2022-09-19  4:41 UTC (permalink / raw)
  To: pbonzini, seanjc; +Cc: kvm, aaronlewis

On 8/29/2022 9:41 AM, Manali Shukla wrote:
> On 8/10/2022 10:37 AM, Manali Shukla wrote:
>> Series is inspired by vmx exception test framework series[1].
>>
>> Set up a test framework that verifies an exception occurring in L2 is
>> forwarded to the right place (L1 or L2).
>>
>> Tests two conditions for each exception.
>> 1) Exception generated in L2, is handled by L2 when L2 exception handler
>>    is registered.
>> 2) Exception generated in L2, is handled by L1 when intercept exception
>>    bit map is set in L1.
>>
>> Above tests were added to verify 8 different exceptions.
>> #GP, #UD, #DE, #DB, #AC, #OF, #BP, #NM.
>>
>> There are 4 patches in this series
>> 1) Added test infrastructure and exception tests.
>> 2) Move #BP test to exception test framework.
>> 3) Move #OF test to exception test framework.
>> 4) Move part of #NM test to exception test framework because
>>    #NM has a test case which checks the condition for which #NM should not
>>    be generated, all the test cases under #NM test except this test case have been
>>    moved to exception test framework because of the exception test framework
>>    design.
>>
>> v1->v2
>> 1) Rebased to latest kvm-unit-tests. 
>> 2) Move 3 different exception test cases #BP, #OF and #NM exception to
>>    exception test framework.
>>
>> [1] https://lore.kernel.org/all/20220125203127.1161838-1-aaronlewis@google.com/
>> [2] https://lore.kernel.org/kvm/a090c16f-c307-9548-9739-ceb71687514f@amd.com/
>>
>> Manali Shukla (4):
>>   x86: nSVM: Add an exception test framework and tests
>>   x86: nSVM: Move #BP test to exception test framework
>>   x86: nSVM: Move #OF test to exception test framework
>>   x86: nSVM: Move part of #NM test to exception test framework
>>
>>  x86/svm_tests.c | 197 ++++++++++++++++++++++++++++++++++--------------
>>  1 file changed, 142 insertions(+), 55 deletions(-)
>>
> 
> A gentle reminder for the review
> 
> -Manali

A gentle reminder for the review

-Manali

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [kvm-unit-tests PATCH v2 0/4] x86: nSVM: Add testing for routing L2 exceptions
  2022-09-19  4:41   ` Manali Shukla
@ 2022-09-26  4:34     ` Manali Shukla
  2022-10-03  4:15       ` Manali Shukla
  0 siblings, 1 reply; 13+ messages in thread
From: Manali Shukla @ 2022-09-26  4:34 UTC (permalink / raw)
  To: pbonzini, seanjc; +Cc: kvm, aaronlewis

On 9/19/2022 10:11 AM, Manali Shukla wrote:
> On 8/29/2022 9:41 AM, Manali Shukla wrote:
>> On 8/10/2022 10:37 AM, Manali Shukla wrote:
>>> Series is inspired by vmx exception test framework series[1].
>>>
>>> Set up a test framework that verifies an exception occurring in L2 is
>>> forwarded to the right place (L1 or L2).
>>>
>>> Tests two conditions for each exception.
>>> 1) Exception generated in L2, is handled by L2 when L2 exception handler
>>>    is registered.
>>> 2) Exception generated in L2, is handled by L1 when intercept exception
>>>    bit map is set in L1.
>>>
>>> Above tests were added to verify 8 different exceptions.
>>> #GP, #UD, #DE, #DB, #AC, #OF, #BP, #NM.
>>>
>>> There are 4 patches in this series
>>> 1) Added test infrastructure and exception tests.
>>> 2) Move #BP test to exception test framework.
>>> 3) Move #OF test to exception test framework.
>>> 4) Move part of #NM test to exception test framework because
>>>    #NM has a test case which checks the condition for which #NM should not
>>>    be generated, all the test cases under #NM test except this test case have been
>>>    moved to exception test framework because of the exception test framework
>>>    design.
>>>
>>> v1->v2
>>> 1) Rebased to latest kvm-unit-tests. 
>>> 2) Move 3 different exception test cases #BP, #OF and #NM exception to
>>>    exception test framework.
>>>
>>> [1] https://lore.kernel.org/all/20220125203127.1161838-1-aaronlewis@google.com/
>>> [2] https://lore.kernel.org/kvm/a090c16f-c307-9548-9739-ceb71687514f@amd.com/
>>>
>>> Manali Shukla (4):
>>>   x86: nSVM: Add an exception test framework and tests
>>>   x86: nSVM: Move #BP test to exception test framework
>>>   x86: nSVM: Move #OF test to exception test framework
>>>   x86: nSVM: Move part of #NM test to exception test framework
>>>
>>>  x86/svm_tests.c | 197 ++++++++++++++++++++++++++++++++++--------------
>>>  1 file changed, 142 insertions(+), 55 deletions(-)
>>>
>>
>> A gentle reminder for the review
>>
>> -Manali
> 
> A gentle reminder for the review
> 
> -Manali

A gentle reminder for the review

-Manali

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [kvm-unit-tests PATCH v2 0/4] x86: nSVM: Add testing for routing L2 exceptions
  2022-09-26  4:34     ` Manali Shukla
@ 2022-10-03  4:15       ` Manali Shukla
  2022-10-03  7:07         ` Maxim Levitsky
  0 siblings, 1 reply; 13+ messages in thread
From: Manali Shukla @ 2022-10-03  4:15 UTC (permalink / raw)
  To: pbonzini, seanjc; +Cc: kvm, aaronlewis

On 9/26/2022 10:04 AM, Manali Shukla wrote:
> On 9/19/2022 10:11 AM, Manali Shukla wrote:
>> On 8/29/2022 9:41 AM, Manali Shukla wrote:
>>> On 8/10/2022 10:37 AM, Manali Shukla wrote:
>>>> Series is inspired by vmx exception test framework series[1].
>>>>
>>>> Set up a test framework that verifies an exception occurring in L2 is
>>>> forwarded to the right place (L1 or L2).
>>>>
>>>> Tests two conditions for each exception.
>>>> 1) Exception generated in L2, is handled by L2 when L2 exception handler
>>>>    is registered.
>>>> 2) Exception generated in L2, is handled by L1 when intercept exception
>>>>    bit map is set in L1.
>>>>
>>>> Above tests were added to verify 8 different exceptions.
>>>> #GP, #UD, #DE, #DB, #AC, #OF, #BP, #NM.
>>>>
>>>> There are 4 patches in this series
>>>> 1) Added test infrastructure and exception tests.
>>>> 2) Move #BP test to exception test framework.
>>>> 3) Move #OF test to exception test framework.
>>>> 4) Move part of #NM test to exception test framework because
>>>>    #NM has a test case which checks the condition for which #NM should not
>>>>    be generated, all the test cases under #NM test except this test case have been
>>>>    moved to exception test framework because of the exception test framework
>>>>    design.
>>>>
>>>> v1->v2
>>>> 1) Rebased to latest kvm-unit-tests. 
>>>> 2) Move 3 different exception test cases #BP, #OF and #NM exception to
>>>>    exception test framework.
>>>>
>>>> [1] https://lore.kernel.org/all/20220125203127.1161838-1-aaronlewis@google.com/
>>>> [2] https://lore.kernel.org/kvm/a090c16f-c307-9548-9739-ceb71687514f@amd.com/
>>>>
>>>> Manali Shukla (4):
>>>>   x86: nSVM: Add an exception test framework and tests
>>>>   x86: nSVM: Move #BP test to exception test framework
>>>>   x86: nSVM: Move #OF test to exception test framework
>>>>   x86: nSVM: Move part of #NM test to exception test framework
>>>>
>>>>  x86/svm_tests.c | 197 ++++++++++++++++++++++++++++++++++--------------
>>>>  1 file changed, 142 insertions(+), 55 deletions(-)
>>>>
>>>
>>> A gentle reminder for the review
>>>
>>> -Manali
>>
>> A gentle reminder for the review
>>
>> -Manali
> 
> A gentle reminder for the review
> 
> -Manali

A gentle remider for the review

-Manali


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [kvm-unit-tests PATCH v2 0/4] x86: nSVM: Add testing for routing L2 exceptions
  2022-10-03  4:15       ` Manali Shukla
@ 2022-10-03  7:07         ` Maxim Levitsky
  0 siblings, 0 replies; 13+ messages in thread
From: Maxim Levitsky @ 2022-10-03  7:07 UTC (permalink / raw)
  To: Manali Shukla, pbonzini, seanjc; +Cc: kvm, aaronlewis

On Mon, 2022-10-03 at 09:45 +0530, Manali Shukla wrote:
> On 9/26/2022 10:04 AM, Manali Shukla wrote:
> > On 9/19/2022 10:11 AM, Manali Shukla wrote:
> > > On 8/29/2022 9:41 AM, Manali Shukla wrote:
> > > > On 8/10/2022 10:37 AM, Manali Shukla wrote:
> > > > > Series is inspired by vmx exception test framework series[1].
> > > > > 
> > > > > Set up a test framework that verifies an exception occurring in L2 is
> > > > > forwarded to the right place (L1 or L2).
> > > > > 
> > > > > Tests two conditions for each exception.
> > > > > 1) Exception generated in L2, is handled by L2 when L2 exception handler
> > > > >    is registered.
> > > > > 2) Exception generated in L2, is handled by L1 when intercept exception
> > > > >    bit map is set in L1.
> > > > > 
> > > > > Above tests were added to verify 8 different exceptions.
> > > > > #GP, #UD, #DE, #DB, #AC, #OF, #BP, #NM.
> > > > > 
> > > > > There are 4 patches in this series
> > > > > 1) Added test infrastructure and exception tests.
> > > > > 2) Move #BP test to exception test framework.
> > > > > 3) Move #OF test to exception test framework.
> > > > > 4) Move part of #NM test to exception test framework because
> > > > >    #NM has a test case which checks the condition for which #NM should not
> > > > >    be generated, all the test cases under #NM test except this test case have been
> > > > >    moved to exception test framework because of the exception test framework
> > > > >    design.
> > > > > 
> > > > > v1->v2
> > > > > 1) Rebased to latest kvm-unit-tests. 
> > > > > 2) Move 3 different exception test cases #BP, #OF and #NM exception to
> > > > >    exception test framework.
> > > > > 
> > > > > [1] https://lore.kernel.org/all/20220125203127.1161838-1-aaronlewis@google.com/
> > > > > [2] https://lore.kernel.org/kvm/a090c16f-c307-9548-9739-ceb71687514f@amd.com/
> > > > > 
> > > > > Manali Shukla (4):
> > > > >   x86: nSVM: Add an exception test framework and tests
> > > > >   x86: nSVM: Move #BP test to exception test framework
> > > > >   x86: nSVM: Move #OF test to exception test framework
> > > > >   x86: nSVM: Move part of #NM test to exception test framework
> > > > > 
> > > > >  x86/svm_tests.c | 197 ++++++++++++++++++++++++++++++++++--------------
> > > > >  1 file changed, 142 insertions(+), 55 deletions(-)
> > > > > 
> > > > 
> > > > A gentle reminder for the review
> > > > 
> > > > -Manali
> > > 
> > > A gentle reminder for the review
> > > 
> > > -Manali
> > 
> > A gentle reminder for the review
> > 
> > -Manali
> 
> A gentle remider for the review
> 
> -Manali
> 
I will review this very soon. Sorry for not getting to it earlier.

Best regards,
	Maxim Levitsky


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [kvm-unit-tests PATCH v2 0/4] x86: nSVM: Add testing for routing L2 exceptions
  2022-08-10  5:07 [kvm-unit-tests PATCH v2 0/4] x86: nSVM: Add testing for routing L2 exceptions Manali Shukla
                   ` (4 preceding siblings ...)
  2022-08-29  4:11 ` [kvm-unit-tests PATCH v2 0/4] x86: nSVM: Add testing for routing L2 exceptions Manali Shukla
@ 2022-10-05 21:14 ` Sean Christopherson
  5 siblings, 0 replies; 13+ messages in thread
From: Sean Christopherson @ 2022-10-05 21:14 UTC (permalink / raw)
  To: Manali Shukla; +Cc: pbonzini, kvm, aaronlewis

On Wed, Aug 10, 2022, Manali Shukla wrote:
> Series is inspired by vmx exception test framework series[1].
> 
> Set up a test framework that verifies an exception occurring in L2 is
> forwarded to the right place (L1 or L2).
> 
> Tests two conditions for each exception.
> 1) Exception generated in L2, is handled by L2 when L2 exception handler
>    is registered.
> 2) Exception generated in L2, is handled by L1 when intercept exception
>    bit map is set in L1.
> 
> Above tests were added to verify 8 different exceptions.
> #GP, #UD, #DE, #DB, #AC, #OF, #BP, #NM.
> 
> There are 4 patches in this series
> 1) Added test infrastructure and exception tests.
> 2) Move #BP test to exception test framework.
> 3) Move #OF test to exception test framework.
> 4) Move part of #NM test to exception test framework because
>    #NM has a test case which checks the condition for which #NM should not
>    be generated, all the test cases under #NM test except this test case have been
>    moved to exception test framework because of the exception test framework
>    design.

I know Paolo NACKed a full rework to share nVMX and nSVM code, but it's super easy
to share the helpers, get a net -100 LoC, and improve nVMX coverage.

I've done the work, along with some misc cleanups.  I'll post a combined version
shortly.

 lib/x86/processor.h |  98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 x86/svm_tests.c     | 195 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------
 x86/vmx_tests.c     | 200 +++++++++++--------------------------------------------------------------------------------------------------------------------------------------
 3 files changed, 199 insertions(+), 294 deletions(-)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [kvm-unit-tests PATCH v2 1/4] x86: nSVM: Add an exception test framework and tests
  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
  0 siblings, 0 replies; 13+ messages in thread
From: Sean Christopherson @ 2022-10-05 21:16 UTC (permalink / raw)
  To: Manali Shukla; +Cc: pbonzini, kvm, aaronlewis

On Wed, Aug 10, 2022, Manali Shukla wrote:
> @@ -3289,6 +3290,118 @@ static void svm_intr_intercept_mix_smi(void)
>  	svm_intr_intercept_mix_run_guest(NULL, SVM_EXIT_SMI);
>  }
>  
> +static void svm_l2_gp_test(struct svm_test *test)

@test is garbage here.  This is a problem with the nSVM framework, the v2 tests
don't have a separate hook.  Without triggering a non-trivial overhaul, the easiest
way to avoid this weirdness is to cast when invoking test_set_guest().

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [kvm-unit-tests PATCH v2 4/4] x86: nSVM: Move part of #NM test to exception test framework
  2022-08-10  5:23 ` [kvm-unit-tests PATCH v2 4/4] x86: nSVM: Move part of #NM " Manali Shukla
@ 2022-10-05 21:17   ` Sean Christopherson
  0 siblings, 0 replies; 13+ messages in thread
From: Sean Christopherson @ 2022-10-05 21:17 UTC (permalink / raw)
  To: Manali Shukla; +Cc: pbonzini, kvm, aaronlewis

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.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-10-05 21:18 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [kvm-unit-tests PATCH v2 4/4] x86: nSVM: Move part of #NM " Manali Shukla
2022-10-05 21:17   ` 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

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).