[kvm-unit-tests RFC PATCH 03/13] x86/efi: Add support for running tests with UEFI in SEV-SNP environment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



SEV-SNP no longer supports using pflash unit=0 for loading the OVMF bios, and
instead relies on -bios parameter. So add support for this in the runner script
(x86/efi/run).

Signed-off-by: Pavan Kumar Paluri <papaluri@xxxxxxx>
---
 x86/efi/README.md |  6 ++++++
 x86/efi/run       | 37 +++++++++++++++++++++++++++++--------
 2 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/x86/efi/README.md b/x86/efi/README.md
index af6e339c2cca..1653bf60cd13 100644
--- a/x86/efi/README.md
+++ b/x86/efi/README.md
@@ -34,6 +34,12 @@ the env variable `EFI_UEFI`:
 
     EFI_UEFI=/path/to/OVMF.fd ./x86/efi/run ./x86/msr.efi
 
+### Run test cases with UEFI in SEV-SNP environment
+
+To run a test case with UEFI and AMD SEV-SNP enabled:
+
+    EFI_SNP=y ./x86/efi/run ./x86/amd_sev.efi
+
 ## Code structure
 
 ### Code from GNU-EFI
diff --git a/x86/efi/run b/x86/efi/run
index 85aeb94fe605..2e8e29b947be 100755
--- a/x86/efi/run
+++ b/x86/efi/run
@@ -15,9 +15,11 @@ source config.mak
 
 : "${EFI_SRC:=$TEST_DIR}"
 : "${EFI_UEFI:=/usr/share/ovmf/OVMF.fd}"
+: "${EFI_VARS:=/usr/share/ovmf/OVMF_VARS.fd}"
 : "${EFI_TEST:=efi-tests}"
 : "${EFI_SMP:=1}"
 : "${EFI_CASE:=$(basename $1 .efi)}"
+: "${EFI_SNP:=n}"
 
 if [ ! -f "$EFI_UEFI" ]; then
 	echo "UEFI firmware not found: $EFI_UEFI"
@@ -43,6 +45,24 @@ fi
 mkdir -p "$EFI_CASE_DIR"
 cp "$EFI_SRC/$EFI_CASE.efi" "$EFI_CASE_BINARY"
 
+# SEV-SNP no longer supports using pflash unit=0 for loading the bios,
+# and instead relies on -bios parameter. pflash unit=0 will instead only
+# be used for OVMF_VARS image, if present.
+if [ "$EFI_SNP" == "y" ]; then
+	"$TEST_DIR/run" \
+	-bios "${EFI_UEFI}" \
+	-drive file="$EFI_VARS",format=raw,if=pflash,unit=0 \
+	-drive file.dir="$EFI_TEST/$EFI_CASE/",file.driver=vvfat,file.rw=on,format=raw,if=virtio \
+	-net none \
+	-nographic \
+	-m 512M \
+	-object memory-backend-memfd,id=ram1,size=512M,share=true,prealloc=false \
+	-machine q35,confidential-guest-support=sev0,memory-backend=ram1 \
+	-object sev-snp-guest,id=sev0,cbitpos=51,reduced-phys-bits=1 \
+	-cpu EPYC-v4
+
+	exit $?
+else
 # Run test case with 256MiB QEMU memory. QEMU default memory size is 128MiB.
 # After UEFI boot up and we call `LibMemoryMap()`, the largest consecutive
 # memory region is ~42MiB. Although this is sufficient for many test cases to
@@ -54,11 +74,12 @@ cp "$EFI_SRC/$EFI_CASE.efi" "$EFI_CASE_BINARY"
 # to x86/run. This `smp` flag overrides any previous `smp` flags (e.g.,
 # `-smp 4`). This is necessary because KVM-Unit-Tests do not currently support
 # SMP under UEFI. This last flag should be removed when this issue is resolved.
-"$TEST_DIR/run" \
-	-drive file="$EFI_UEFI",format=raw,if=pflash,readonly=on \
-	-drive file.dir="$EFI_TEST/$EFI_CASE/",file.driver=vvfat,file.rw=on,format=raw,if=virtio \
-	-net none \
-	-nographic \
-	-m 256 \
-	"$@" \
-	-smp "$EFI_SMP"
+	"$TEST_DIR/run" \
+		-drive file="$EFI_UEFI",format=raw,if=pflash,readonly=on \
+		-drive file.dir="$EFI_TEST/$EFI_CASE/",file.driver=vvfat,file.rw=on,format=raw,if=virtio \
+		-net none \
+		-nographic \
+		-m 256 \
+		"$@" \
+		-smp "$EFI_SMP"
+fi
-- 
2.34.1





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux