* [kvm-unit-tests PATCH 0/3] Add L2 exception handling KVM unit tests for nSVM
@ 2021-12-29 6:21 Manali Shukla
2021-12-29 6:21 ` [kvm-unit-tests PATCH 1/3] x86: nSVM: Check #NM exception handling in L2 Manali Shukla
` (5 more replies)
0 siblings, 6 replies; 9+ messages in thread
From: Manali Shukla @ 2021-12-29 6:21 UTC (permalink / raw)
To: kvm
This series adds 3 KVM Unit tests for nested SVM
1) Check #NM is handled in L2 when L2 #NM handler is registered
"fnop" instruction is called in L2 to generate the exception
2) Check #BP is handled in L2 when L2 #BP handler is registered
"int3" instruction is called in L2 to generate the exception
3) Check #OF is handled in L2 when L2 #OF handler is registered
"into" instruction with instrumented code is used in L2 to
generate the exception
Manali Shukla (3):
x86: nSVM: Check #NM exception handling in L2
x86: nSVM: Check #BP exception handling in L2
x86: nSVM: Check #OF exception handling in L2
x86/svm_tests.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 114 insertions(+)
--
2.30.2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [kvm-unit-tests PATCH 1/3] x86: nSVM: Check #NM exception handling in L2
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
2021-12-29 6:22 ` [kvm-unit-tests PATCH 2/3] x86: nSVM: Check #BP " Manali Shukla
` (4 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Manali Shukla @ 2021-12-29 6:21 UTC (permalink / raw)
To: kvm
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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [kvm-unit-tests PATCH 2/3] x86: nSVM: Check #BP exception handling in L2
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 ` [kvm-unit-tests PATCH 1/3] x86: nSVM: Check #NM exception handling in L2 Manali Shukla
@ 2021-12-29 6:22 ` Manali Shukla
2021-12-29 6:22 ` [kvm-unit-tests PATCH 3/3] x86: nSVM: Check #OF " Manali Shukla
` (3 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Manali Shukla @ 2021-12-29 6:22 UTC (permalink / raw)
To: kvm
Add coverage for BP exception handling in L2 when only L2 BP
exception handler is registered
BP exception is generated using int3 instruction and it is handled
by L2 BP exception handler.
Signed-off-by: Manali Shukla <manali.shukla@amd.com>
---
x86/svm_tests.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/x86/svm_tests.c b/x86/svm_tests.c
index 681272c..ed67ae1 100644
--- a/x86/svm_tests.c
+++ b/x86/svm_tests.c
@@ -2962,6 +2962,26 @@ static bool vgif_check(struct svm_test *test)
return get_test_stage(test) == 3;
}
+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)
+{
+ 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)
@@ -3127,5 +3147,6 @@ struct svm_test svm_tests[] = {
TEST(svm_vmload_vmsave),
TEST(svm_test_singlestep),
TEST(svm_nm_test),
+ TEST(svm_int3_test),
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL }
};
--
2.30.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [kvm-unit-tests PATCH 3/3] x86: nSVM: Check #OF exception handling in L2
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 ` [kvm-unit-tests PATCH 1/3] x86: nSVM: Check #NM exception handling in L2 Manali Shukla
2021-12-29 6:22 ` [kvm-unit-tests PATCH 2/3] x86: nSVM: Check #BP " Manali Shukla
@ 2021-12-29 6:22 ` Manali Shukla
2022-01-07 4:05 ` [kvm-unit-tests PATCH 0/3] Add L2 exception handling KVM unit tests for nSVM Shukla, Manali
` (2 subsequent siblings)
5 siblings, 0 replies; 9+ messages in thread
From: Manali Shukla @ 2021-12-29 6:22 UTC (permalink / raw)
To: kvm
Add coverage for OF exception handling in L2 when only L2 OF
exception handler is registered.
OF exception generated using instrumented code and it is handled
by L2 OF exception handler.
Signed-off-by: Manali Shukla <manali.shukla@amd.com>
---
x86/svm_tests.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/x86/svm_tests.c b/x86/svm_tests.c
index ed67ae1..0707786 100644
--- a/x86/svm_tests.c
+++ b/x86/svm_tests.c
@@ -2962,6 +2962,53 @@ static bool vgif_check(struct svm_test *test)
return get_test_stage(test) == 3;
}
+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)
+{
+ struct far_pointer32 fp = {
+ .offset = (uintptr_t)&&into,
+ .selector = KERNEL_CS32,
+ };
+ uintptr_t rsp;
+
+ asm volatile ("mov %%rsp, %0" : "=r"(rsp));
+
+ if (fp.offset != (uintptr_t)&&into) {
+ printf("Codee address too high.\n");
+ return;
+ }
+
+ if ((u32)rsp != rsp) {
+ printf("Stack address too high.\n");
+ }
+
+ asm goto("lcall *%0" : : "m" (fp) : "rax" : into);
+ return;
+into:
+
+ asm volatile (".code32;"
+ "movl $0x7fffffff, %eax;"
+ "addl %eax, %eax;"
+ "into;"
+ "lret;"
+ ".code64");
+ __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 handler0");
+}
+
static int bp_test_counter;
static void guest_test_bp_handler(struct ex_regs *r)
@@ -3148,5 +3195,6 @@ struct svm_test svm_tests[] = {
TEST(svm_test_singlestep),
TEST(svm_nm_test),
TEST(svm_int3_test),
+ TEST(svm_into_test),
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL }
};
--
2.30.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [kvm-unit-tests PATCH 0/3] Add L2 exception handling KVM unit tests for nSVM
2021-12-29 6:21 [kvm-unit-tests PATCH 0/3] Add L2 exception handling KVM unit tests for nSVM Manali Shukla
` (2 preceding siblings ...)
2021-12-29 6:22 ` [kvm-unit-tests PATCH 3/3] x86: nSVM: Check #OF " Manali Shukla
@ 2022-01-07 4:05 ` Shukla, Manali
2022-01-12 21:29 ` Sean Christopherson
2022-01-18 9:21 ` Paolo Bonzini
5 siblings, 0 replies; 9+ messages in thread
From: Shukla, Manali @ 2022-01-07 4:05 UTC (permalink / raw)
To: kvm
On 12/29/2021 11:51 AM, Manali Shukla wrote:
> This series adds 3 KVM Unit tests for nested SVM
> 1) Check #NM is handled in L2 when L2 #NM handler is registered
> "fnop" instruction is called in L2 to generate the exception
>
> 2) Check #BP is handled in L2 when L2 #BP handler is registered
> "int3" instruction is called in L2 to generate the exception
>
> 3) Check #OF is handled in L2 when L2 #OF handler is registered
> "into" instruction with instrumented code is used in L2 to
> generate the exception
>
> Manali Shukla (3):
> x86: nSVM: Check #NM exception handling in L2
> x86: nSVM: Check #BP exception handling in L2
> x86: nSVM: Check #OF exception handling in L2
>
> x86/svm_tests.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 114 insertions(+)
>
A gentle reminder for review
Thank you,
Manali
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [kvm-unit-tests PATCH 0/3] Add L2 exception handling KVM unit tests for nSVM
2021-12-29 6:21 [kvm-unit-tests PATCH 0/3] Add L2 exception handling KVM unit tests for nSVM Manali Shukla
` (3 preceding siblings ...)
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 9:21 ` Paolo Bonzini
5 siblings, 1 reply; 9+ messages in thread
From: Sean Christopherson @ 2022-01-12 21:29 UTC (permalink / raw)
To: Manali Shukla; +Cc: kvm, Aaron Lewis, pbonzini
+Aaron, and +Paolo who may or may not subsribe to kvm@ :-)
On Wed, Dec 29, 2021, Manali Shukla wrote:
> This series adds 3 KVM Unit tests for nested SVM
> 1) Check #NM is handled in L2 when L2 #NM handler is registered
> "fnop" instruction is called in L2 to generate the exception
>
> 2) Check #BP is handled in L2 when L2 #BP handler is registered
> "int3" instruction is called in L2 to generate the exception
>
> 3) Check #OF is handled in L2 when L2 #OF handler is registered
> "into" instruction with instrumented code is used in L2 to
> generate the exception
This is all basically identical in terms of desired functionality to existing or
in-flight nVMX tests, e.g. vmx_nm_test() and Aaron's vmx_exception_test() work[*].
And much of the feedback I provided to Aaron's earlier revisions applies to this
series as well, e.g. create a framework to test intercpetion of arbitrary exceptions
instead of writing the same boilerplate for each and every test.
It doesn't seem like it'd be _that_ difficult to turn vmx_exception_test into a
generic-ish l2_exception_test. To avoid too much scope creep, what if we first get
Aaron's code merged, and than attempt to extract the core functionality into a
shared library to reuse it for nSVM? If it turns out to be more trouble then its
worth, we can always fall back to something like this series.
[*] https://lore.kernel.org/all/20211214011823.3277011-1-aaronlewis@google.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [kvm-unit-tests PATCH 0/3] Add L2 exception handling KVM unit tests for nSVM
2021-12-29 6:21 [kvm-unit-tests PATCH 0/3] Add L2 exception handling KVM unit tests for nSVM Manali Shukla
` (4 preceding siblings ...)
2022-01-12 21:29 ` Sean Christopherson
@ 2022-01-18 9:21 ` Paolo Bonzini
5 siblings, 0 replies; 9+ messages in thread
From: Paolo Bonzini @ 2022-01-18 9:21 UTC (permalink / raw)
To: Manali Shukla, kvm
On 12/29/21 07:21, Manali Shukla wrote:
> This series adds 3 KVM Unit tests for nested SVM
> 1) Check #NM is handled in L2 when L2 #NM handler is registered
> "fnop" instruction is called in L2 to generate the exception
>
> 2) Check #BP is handled in L2 when L2 #BP handler is registered
> "int3" instruction is called in L2 to generate the exception
>
> 3) Check #OF is handled in L2 when L2 #OF handler is registered
> "into" instruction with instrumented code is used in L2 to
> generate the exception
>
> Manali Shukla (3):
> x86: nSVM: Check #NM exception handling in L2
> x86: nSVM: Check #BP exception handling in L2
> x86: nSVM: Check #OF exception handling in L2
>
> x86/svm_tests.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 114 insertions(+)
>
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [kvm-unit-tests PATCH 0/3] Add L2 exception handling KVM unit tests for nSVM
2022-01-12 21:29 ` Sean Christopherson
@ 2022-01-18 11:11 ` Shukla, Manali
2022-01-18 11:38 ` Paolo Bonzini
0 siblings, 1 reply; 9+ messages in thread
From: Shukla, Manali @ 2022-01-18 11:11 UTC (permalink / raw)
To: Sean Christopherson, Manali Shukla; +Cc: kvm, Aaron Lewis, pbonzini
On 1/13/2022 2:59 AM, Sean Christopherson wrote:
> +Aaron, and +Paolo who may or may not subsribe to kvm@ :-)
>
> On Wed, Dec 29, 2021, Manali Shukla wrote:
>> This series adds 3 KVM Unit tests for nested SVM
>> 1) Check #NM is handled in L2 when L2 #NM handler is registered
>> "fnop" instruction is called in L2 to generate the exception
>>
>> 2) Check #BP is handled in L2 when L2 #BP handler is registered
>> "int3" instruction is called in L2 to generate the exception
>>
>> 3) Check #OF is handled in L2 when L2 #OF handler is registered
>> "into" instruction with instrumented code is used in L2 to
>> generate the exception
>
> This is all basically identical in terms of desired functionality to existing or
> in-flight nVMX tests, e.g. vmx_nm_test() and Aaron's vmx_exception_test() work[*].
> And much of the feedback I provided to Aaron's earlier revisions applies to this
> series as well, e.g. create a framework to test intercpetion of arbitrary exceptions
> instead of writing the same boilerplate for each and every test.
>
> It doesn't seem like it'd be _that_ difficult to turn vmx_exception_test into a
> generic-ish l2_exception_test. To avoid too much scope creep, what if we first get
> Aaron's code merged, and than attempt to extract the core functionality into a
> shared library to reuse it for nSVM? If it turns out to be more trouble then its
> worth, we can always fall back to something like this series.
>
> [*] https://lore.kernel.org/all/20211214011823.3277011-1-aaronlewis@google.com
This patch has already been queued by Paolo.
I will wait till Aaron's code is merged and than do appropriate changes.
I hope this is fine.
Thank you
Manali
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [kvm-unit-tests PATCH 0/3] Add L2 exception handling KVM unit tests for nSVM
2022-01-18 11:11 ` Shukla, Manali
@ 2022-01-18 11:38 ` Paolo Bonzini
0 siblings, 0 replies; 9+ messages in thread
From: Paolo Bonzini @ 2022-01-18 11:38 UTC (permalink / raw)
To: Shukla, Manali, Sean Christopherson, Manali Shukla; +Cc: kvm, Aaron Lewis
On 1/18/22 12:11, Shukla, Manali wrote:
>>
>> It doesn't seem like it'd be_that_ difficult to turn vmx_exception_test into a
>> generic-ish l2_exception_test. To avoid too much scope creep, what if we first get
>> Aaron's code merged, and than attempt to extract the core functionality into a
>> shared library to reuse it for nSVM? If it turns out to be more trouble then its
>> worth, we can always fall back to something like this series.
>>
>> [*]https://lore.kernel.org/all/20211214011823.3277011-1-aaronlewis@google.com
> This patch has already been queued by Paolo.
> I will wait till Aaron's code is merged and than do appropriate changes.
> I hope this is fine.
Yes, it is. I am holding on Aaron's series because of the remarks from
Sean[1], on the other hand it's really difficult to share code between
VMX and SVM tests. So while I agree that a lot of code changes can be
done the same way to VMX and SVM tests, it's not really feasible to keep
them in sync.
Paolo
[1] https://lore.kernel.org/all/Yd8+n+%2F2GCZtIhaB@google.com/#t
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-01-18 11:38 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [kvm-unit-tests PATCH 1/3] x86: nSVM: Check #NM exception handling in L2 Manali Shukla
2021-12-29 6:22 ` [kvm-unit-tests PATCH 2/3] x86: nSVM: Check #BP " 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
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).