x86/test: Add a test for AMD SEV-ES #VC handling
v5 cover x86/test: Add a test for AMD SEV-ES #VC handling
Hello!
This is the version 5 of the patch written to add a test for AMD SEV-ES #VC handling. This version attempts to address review comments to the previous version of the patch in
https://lore.kernel.org/kvm/[email protected]/.
Following changes have been made to address the comments:
1. Changed the subject to x86/test from x86.
2. In file arch/x86/Kconfig.debug enclosed the config AMD_SEV_TEST_VC inside the guard X86_TESTS.
3. Renamed the test file to sev-test-vc.c to indicate that file includes all the #VC handling related tests.
4. Memory barries are apparently not necessary and have been removed.
Thanks,
Vasant
----------------------------------------------------------------------
arch/x86/Kbuild | 2 + arch/x86/Kconfig.debug | 16 ++++ arch/x86/kernel/Makefile | 7 ++ arch/x86/tests/Makefile | 3 + arch/x86/tests/sev-test-vc.c | 154 +++++++++++++++++++++++++++++++++++ 5 files changed, 182 insertions(+) create mode 100644 arch/x86/tests/Makefile create mode 100644 arch/x86/tests/sev-test-vc.c
base-commit: dfd42facf1e4ada021b939b4e19c935dcdd55566
prerequisite-patch-id: 660950af15f9a972b1f71aa7702ebebe7dd9636b
prerequisite-patch-id: 9635b44cd178a2ee20d83acbc7a07101fd7e81a3
prerequisite-patch-id: 3a7cfa2a885ad20a9f325febcbe31ef53b41e0b1
prerequisite-patch-id: 5e48ede5d4df9de5df3d483874b4aa1711b5dcf0
prerequisite-patch-id: b66ebf185fceb6e8e98b466c974ed777f0200787
prerequisite-patch-id: d5bde21908fbada516dc757e29c6ad70926ab5bf
prerequisite-patch-id: ed38b7fc213fa66845dc25502f18b79e3dc907db
prerequisite-patch-id: 053546f9741643d742f5149c8441f8484e1918d1
prerequisite-patch-id: a20f9a6fd1ad2db0bae2550d5442d7275c481b01
prerequisite-patch-id: bde103392dd4c0a5c360446dbc8d2e5f82671575
prerequisite-patch-id: af44d5e0a6f51e1fe5cf6aef7d0be36e201663b4
prerequisite-patch-id: 952ebde20c8c084f43523f8230ced76beae08b3e
prerequisite-patch-id: 0b295c1545756626a9bca5bce8be4557742b7a56
prerequisite-patch-id: 98bf6777201eeab52938c28de1090387d454ef55
prerequisite-patch-id: d64628531375578e4bc6de3bcba1a3de658e28d8
prerequisite-patch-id: 752ea9954abeb624b803ad86e4974769f97ddd6e
Signature · 1 line
2.32.0
PATCH v5 1/1 x86/test: Add a test for AMD SEV-ES #VC handling
From: Varad Gautam <[email protected]>
Add a KUnit based test to validate Linux's VC handling, and introduce a new CONFIG_X86_TESTS to cover such tests. The test:
1. installs a kretprobe on the #VC handler (sev_es_ghcb_hv_call, to access GHCB before/after the resulting VMGEXIT).
2. triggers an NAE.
3. checks that the kretprobe was hit with the right exit_code available in GHCB.
Since relying on kprobes, the test does not cover NMI contexts.
--- arch/x86/Kbuild | 2 + arch/x86/Kconfig.debug | 16 ++++ arch/x86/kernel/Makefile | 7 ++ arch/x86/tests/Makefile | 3 + arch/x86/tests/sev-test-vc.c | 154 +++++++++++++++++++++++++++++++++++ 5 files changed, 182 insertions(+) create mode 100644 arch/x86/tests/Makefile create mode 100644 arch/x86/tests/sev-test-vc.c
arch/x86/Kbuild +2 -0
@@ -26,5 +26,7 @@ obj-y += net/ obj-$(CONFIG_KEXEC_FILE) += purgatory/ +obj-y += tests/ + # for cleaning subdir- += boot tools
arch/x86/Kconfig.debug +16 -0
@@ -279,3 +279,19 @@ endchoice config FRAME_POINTER depends on !UNWINDER_ORC && !UNWINDER_GUESS bool + +config X86_TESTS + bool "Tests for x86" + help + This enables building the tests under arch/x86/tests. + +if X86_TESTS +config AMD_SEV_TEST_VC + bool "Test for AMD SEV VC exception handling" + depends on AMD_MEM_ENCRYPT + select FUNCTION_TRACER + select KPROBES + select KUNIT + help + Enable KUnit-based testing for AMD SEV #VC exception handling. +endif # X86_TESTS
arch/x86/kernel/Makefile +7 -0
@@ -24,6 +24,13 @@ CFLAGS_REMOVE_sev.o = -pg CFLAGS_REMOVE_cc_platform.o = -pg endif +# AMD_SEV_TEST_VC registers a kprobe by function name. IPA-SRA creates +# function copies and renames them to have an .isra suffix, which breaks kprobes' +# lookup. Build with -fno-ipa-sra for the test. +ifdef CONFIG_AMD_SEV_TEST_VC +CFLAGS_sev.o += -fno-ipa-sra +endif + KASAN_SANITIZE_head$(BITS).o := n KASAN_SANITIZE_dumpstack.o := n KASAN_SANITIZE_dumpstack_$(BITS).o := n
arch/x86/tests/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_AMD_SEV_TEST_VC) += sev-test-vc.o
arch/x86/tests/sev-test-vc.c new file +154 -0
154 lines not on this page · raw message
Signature · 1 line
2.32.0
Hi Vasant,
thanks for submitting this.
Quoted 14 lines · Vasant Karasulli
From: Varad Gautam <[email protected]>
Add a KUnit based test to validate Linux's VC handling, and introduce a new
CONFIG_X86_TESTSto cover such tests. The test:
1. installs a kretprobe on the #VC handler (sev_es_ghcb_hv_call, to access GHCB before/after the resulting VMGEXIT).
2. triggers an NAE.
3. checks that the kretprobe was hit with the rightexit_codeavailable in GHCB.Since relying on kprobes, the test does not cover NMI contexts.
Signed-off-by Varad Gautam <[email protected]>Signed-off-by Vasant Karasulli <[email protected]>
Quoted 9 lines
--- arch/x86/Kbuild | 2 + arch/x86/Kconfig.debug | 16 ++++ arch/x86/kernel/Makefile | 7 ++ arch/x86/tests/Makefile | 3 + arch/x86/tests/sev-test-vc.c | 154 +++++++++++++++++++++++++++++++++++ 5 files changed, 182 insertions(+) create mode 100644 arch/x86/tests/Makefile create mode 100644 arch/x86/tests/sev-test-vc.c
Can we split this up a bit? Say into an initial patch which adds arch/x86/tests/ and the Kconfig option and then three patches adding the tests:
1. Infrastructure and instruction-based tests (cpuid, wbinvd)
2. Register access tests (MSR, DR7)
3. IO tests (mmio, ioio)
arch/x86/tests/sev-test-vc.c line 128
Quoted 3 lines
arch/x86/tests/sev-test-vc.c new file +3
-0+static void sev_es_nae_mmio (struct kunit *test) +{ +unsigned long lapic_ver_pa =0xfee00030 ;/* APIC_DEFAULT_PHYS_BASE + APIC_LVR */
Instead of the comment, please use the values directly to assign the variable.
Regards,
Signature · 10 lines
Jörg Rödel [email protected] SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Ivo Totev