From: Maxim Levitsky <mlevitsk@redhat.com>
To: kvm@vger.kernel.org
Cc: Maxim Levitsky <mlevitsk@redhat.com>,
Cathy Avery <cavery@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [kvm-unit-tests PATCH 08/16] svm: add nested shutdown test.
Date: Thu, 20 Oct 2022 18:23:56 +0300 [thread overview]
Message-ID: <20221020152404.283980-9-mlevitsk@redhat.com> (raw)
In-Reply-To: <20221020152404.283980-1-mlevitsk@redhat.com>
Test that if L2 triggers a shutdown, this VM exits to L1
and doesn't crash the host.
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
---
x86/svm_tests.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/x86/svm_tests.c b/x86/svm_tests.c
index 19b35e95..2c29c2b0 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 "vmalloc.h"
#define SVM_EXIT_MAX_DR_INTERCEPT 0x3f
@@ -3270,6 +3271,55 @@ static void svm_intr_intercept_mix_smi(void)
svm_intr_intercept_mix_run_guest(NULL, SVM_EXIT_SMI);
}
+
+static void shutdown_intercept_test_guest(struct svm_test *test)
+{
+ asm volatile ("int3");
+ report_fail("should not reach here\n");
+
+}
+
+static void shutdown_intercept_test_guest2(struct svm_test *test)
+{
+ asm volatile ("ud2");
+ report_fail("should not reach here\n");
+
+}
+
+static void svm_shutdown_intercept_test(void)
+{
+ void* unmapped_address = alloc_vpage();
+
+ /*
+ * Test that shutdown vm exit doesn't crash L0
+ *
+ * Test both native and emulated triple fault
+ * (due to exception merging)
+ */
+
+
+ /*
+ * This will usually cause native SVM_EXIT_SHUTDOWN
+ * (KVM usually doesn't intercept #PF)
+ * */
+ test_set_guest(shutdown_intercept_test_guest);
+ vmcb->save.idtr.base = (u64)unmapped_address;
+ vmcb->control.intercept |= (1ULL << INTERCEPT_SHUTDOWN);
+ svm_vmrun();
+ report (vmcb->control.exit_code == SVM_EXIT_SHUTDOWN, "shutdown (BP->PF->DF->TRIPLE_FAULT) test passed");
+
+ /*
+ * This will usually cause emulated SVM_EXIT_SHUTDOWN
+ * (KVM usually intercepts #UD)
+ */
+ test_set_guest(shutdown_intercept_test_guest2);
+ vmcb_ident(vmcb);
+ vmcb->save.idtr.limit = 0;
+ vmcb->control.intercept |= (1ULL << INTERCEPT_SHUTDOWN);
+ svm_vmrun();
+ report (vmcb->control.exit_code == SVM_EXIT_SHUTDOWN, "shutdown (UD->DF->TRIPLE_FAULT) test passed");
+}
+
struct svm_test svm_tests[] = {
{ "null", default_supported, default_prepare,
default_prepare_gif_clear, null_test,
@@ -3382,6 +3432,7 @@ struct svm_test svm_tests[] = {
TEST(svm_intr_intercept_mix_smi),
TEST(svm_tsc_scale_test),
TEST(pause_filter_test),
+ TEST(svm_shutdown_intercept_test),
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL }
};
--
2.26.3
next prev parent reply other threads:[~2022-10-20 15:25 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-20 15:23 [kvm-unit-tests PATCH 00/16] kvm-unit-tests: set of fixes and new tests Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 01/16] x86: make irq_enable avoid the interrupt shadow Maxim Levitsky
2022-10-20 18:01 ` Sean Christopherson
2022-10-24 12:36 ` Maxim Levitsky
2022-10-24 22:49 ` Sean Christopherson
2022-10-27 10:16 ` Maxim Levitsky
2022-10-27 15:50 ` Sean Christopherson
2022-10-27 17:10 ` Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 02/16] x86: add few helper functions for apic local timer Maxim Levitsky
2022-10-20 19:14 ` Sean Christopherson
2022-10-24 12:37 ` Maxim Levitsky
2022-10-24 16:10 ` Sean Christopherson
2022-10-27 10:19 ` Maxim Levitsky
2022-10-27 15:54 ` Sean Christopherson
2022-10-27 17:11 ` Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 03/16] svm: use irq_enable instead of sti/nop Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 04/16] svm: make svm_intr_intercept_mix_if/gif test a bit more robust Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 05/16] svm: use apic_start_timer/apic_stop_timer instead of open coding it Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 06/16] x86: Add test for #SMI during interrupt window Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 07/16] x86: Add a simple test for SYSENTER instruction Maxim Levitsky
2022-10-20 19:25 ` Sean Christopherson
2022-10-24 12:38 ` Maxim Levitsky
2022-10-20 15:23 ` Maxim Levitsky [this message]
2022-10-20 15:26 ` [kvm-unit-tests PATCH 08/16] svm: add nested shutdown test Maxim Levitsky
2022-10-20 19:06 ` Sean Christopherson
2022-10-24 12:39 ` Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 09/16] svm: move svm spec definitions to lib/x86/svm.h Maxim Levitsky
2022-10-20 19:08 ` Sean Christopherson
2022-10-20 15:23 ` [kvm-unit-tests PATCH 10/16] svm: move some svm support functions into lib/x86/svm_lib.h Maxim Levitsky
2022-10-20 15:23 ` [kvm-unit-tests PATCH 11/16] svm: add svm_suported Maxim Levitsky
2022-10-20 18:21 ` Sean Christopherson
2022-10-24 12:40 ` Maxim Levitsky
2022-10-20 15:24 ` [kvm-unit-tests PATCH 12/16] svm: move setup_svm to svm_lib.c Maxim Levitsky
2022-10-20 15:24 ` [kvm-unit-tests PATCH 13/16] svm: move vmcb_ident " Maxim Levitsky
2022-10-20 18:37 ` Sean Christopherson
2022-10-24 12:46 ` Maxim Levitsky
2022-10-20 15:24 ` [kvm-unit-tests PATCH 14/16] svm: rewerite vm entry macros Maxim Levitsky
2022-10-20 18:55 ` Sean Christopherson
2022-10-24 12:45 ` Maxim Levitsky
2022-10-24 19:56 ` Sean Christopherson
2022-10-27 12:07 ` Maxim Levitsky
2022-10-27 19:39 ` Sean Christopherson
2022-10-20 15:24 ` [kvm-unit-tests PATCH 15/16] svm: introduce svm_vcpu Maxim Levitsky
2022-10-20 19:02 ` Sean Christopherson
2022-10-24 12:46 ` Maxim Levitsky
2022-10-20 15:24 ` [kvm-unit-tests PATCH 16/16] add IPI loss stress test Maxim Levitsky
2022-10-20 20:23 ` Sean Christopherson
2022-10-24 12:54 ` Maxim Levitsky
2022-10-24 17:19 ` Sean Christopherson
2022-10-27 11:00 ` Maxim Levitsky
2022-10-27 18:41 ` 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=20221020152404.283980-9-mlevitsk@redhat.com \
--to=mlevitsk@redhat.com \
--cc=cavery@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox