mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vasant Karasulli <vkarasulli@suse.de>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: bp@alien8.de, jroedel@suse.de, thomas.lendacky@amd.com,
	x86@kernel.org, seanjc@google.com,
	Vasant Karasulli <vkarasulli@suse.de>
Subject: [PATCH v7 3/4] KVM: SEV-ES: Add tests to validate VC handling for MSR and DR7 register accesses
Date: Mon, 13 Jun 2022 19:04:19 +0200	[thread overview]
Message-ID: <20220613170420.18521-4-vkarasulli@suse.de> (raw)
In-Reply-To: <20220613170420.18521-1-vkarasulli@suse.de>

These tests:
   1. install a kretprobe on the #VC handler (sev_es_ghcb_hv_call, to
       access GHCB before/after the resulting VMGEXIT).
   2. trigger an NAE by accessing either MSR or DR7.
   3. check that the kretprobe was hit with the right exit_code available
      in GHCB.

To run these tests, configuration options CONFIG_X86_TESTS and
CONFIG_AMD_SEV_ES_TEST_VC have to be enabled. These tests run
at the kernel boot time. Result of the test execution can be
monitored in the kernel log.

Signed-off-by: Vasant Karasulli <vkarasulli@suse.de>
---
 arch/x86/tests/sev-test-vc.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/arch/x86/tests/sev-test-vc.c b/arch/x86/tests/sev-test-vc.c
index 900ca357a273..629aa0ca1c86 100644
--- a/arch/x86/tests/sev-test-vc.c
+++ b/arch/x86/tests/sev-test-vc.c
@@ -7,6 +7,7 @@

 #include <asm/cpufeature.h>
 #include <asm/sev-common.h>
+#include <asm/debugreg.h>
 #include <asm/svm.h>
 #include <kunit/test.h>
 #include <linux/kprobes.h>
@@ -89,9 +90,22 @@ static void sev_es_nae_wbinvd(struct kunit *test)
 	check_op(test, SVM_EXIT_WBINVD, wbinvd());
 }

+static void sev_es_nae_msr(struct kunit *test)
+{
+	check_op(test, SVM_EXIT_MSR, __rdmsr(MSR_IA32_TSC));
+}
+
+static void sev_es_nae_dr7_rw(struct kunit *test)
+{
+	check_op(test, SVM_EXIT_WRITE_DR7,
+		   native_set_debugreg(7, native_get_debugreg(7)));
+}
+
 static struct kunit_case sev_es_vc_testcases[] = {
 	KUNIT_CASE(sev_es_nae_cpuid),
 	KUNIT_CASE(sev_es_nae_wbinvd),
+	KUNIT_CASE(sev_es_nae_msr),
+	KUNIT_CASE(sev_es_nae_dr7_rw),
 	{}
 };

--
2.32.0


  parent reply	other threads:[~2022-06-13 19:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-13 17:04 [PATCH v7 0/4] KVM: SEV-ES: Add tests to validate #VC handling Vasant Karasulli
2022-06-13 17:04 ` [PATCH v7 1/4] KVM: SEV-ES: Add configuration options to test " Vasant Karasulli
2022-06-13 17:04 ` [PATCH v7 2/4] KVM: SEV-ES: Add tests to validate VC handling for CPUID and WBINVD Vasant Karasulli
2022-06-13 17:04 ` Vasant Karasulli [this message]
2022-06-13 17:04 ` [PATCH v7 4/4] KVM SEV-ES: Add tests to validate VC handling for IO instructions Vasant Karasulli

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=20220613170420.18521-4-vkarasulli@suse.de \
    --to=vkarasulli@suse.de \
    --cc=bp@alien8.de \
    --cc=jroedel@suse.de \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=seanjc@google.com \
    --cc=thomas.lendacky@amd.com \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®