Skip to content

Commit f3fc812

Browse files
committed
Add snp direct kernel boot case
Signed-off-by: Jin Liu <[email protected]>
1 parent ee2d00e commit f3fc812

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
- snp_direct_kernel_boot:
2+
type = snp_direct_kernel_boot
3+
only Linux
4+
kill_vm = yes
5+
login_timeout = 240
6+
start_vm = no
7+
mem = 2048
8+
smp = 8
9+
vm_secure_guest_type = snp
10+
vm_sev_reduced_phys_bits = 1
11+
vm_sev_cbitpos = 51
12+
virtio_dev_disable_legacy = on
13+
bios_path = /usr/share/edk2/ovmf/OVMF.amdsev.fd
14+
snp_module_path = "/sys/module/kvm_amd/parameters/sev_snp"
15+
module_status = Y y 1
16+
snp_guest_check = "journalctl|grep -i -w snp"
17+
guest_tool_install = "dnf install -y snpguest"
18+
attestation_script = regular_attestation_workflow.sh
19+
guest_dir = /home
20+
guest_cmd = ${guest_dir}/${attestation_script}
21+
host_script = sev-snp/${attestation_script}
22+
vm_mem_backend = memory-backend-memfd
23+
vm_sev_kernel_hashes = on
24+
kernel_params = "root=/dev/mapper/rhel-root ro console=tty0 rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap net.ifnames=0 console=ttyS0,115200"
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import os
2+
3+
from avocado.utils import cpu
4+
from virttest import data_dir as virttest_data_dir
5+
from virttest import env_process, error_context
6+
from virttest.utils_misc import verify_dmesg
7+
8+
9+
@error_context.context_aware
10+
def run(test, params, env):
11+
"""
12+
Snp direct kernel boot test:
13+
1. Check host snp capability
14+
2. Boot snp VM with direct kernel boot
15+
3. Verify snp enabled in guest
16+
4. Verify attestation
17+
18+
:param test: QEMU test object
19+
:param params: Dictionary with the test parameters
20+
:param env: Dictionary with test environment.
21+
"""
22+
23+
error_context.context("Start sev-snp test", test.log.info)
24+
timeout = params.get_numeric("login_timeout", 240)
25+
26+
snp_module_path = params["snp_module_path"]
27+
if os.path.exists(snp_module_path):
28+
with open(snp_module_path) as f:
29+
output = f.read().strip()
30+
if output not in params.objects("module_status"):
31+
test.cancel("Host sev-snp support check fail.")
32+
else:
33+
test.cancel("Host sev-snp support check fail.")
34+
35+
family_id = cpu.get_family()
36+
model_id = cpu.get_model()
37+
dict_cpu = {"251": "milan", "2517": "genoa", "2617": "turin"}
38+
key = str(family_id) + str(model_id)
39+
host_cpu_model = dict_cpu.get(key, "unknown")
40+
41+
params["start_vm"] = "yes"
42+
guest_name = params.get("guest_name")
43+
params["kernel"] = f"images/{guest_name}/vmlinuz"
44+
params["initrd"] = f"images/{guest_name}/initrd.img"
45+
46+
vm_name = params["main_vm"]
47+
env_process.preprocess_vm(test, params, env, vm_name)
48+
vm = env.get_vm(vm_name)
49+
vm.verify_alive()
50+
session = vm.wait_for_login(timeout=timeout)
51+
verify_dmesg()
52+
guest_check_cmd = params["snp_guest_check"]
53+
try:
54+
session.cmd_output(guest_check_cmd, timeout=240)
55+
except Exception as e:
56+
test.fail("Guest snp verify fail: %s" % str(e))
57+
else:
58+
# Verify attestation
59+
error_context.context("Start to do attestation", test.log.info)
60+
guest_dir = params["guest_dir"]
61+
host_script = params["host_script"]
62+
guest_cmd = params["guest_cmd"]
63+
deps_dir = virttest_data_dir.get_deps_dir()
64+
host_file = os.path.join(deps_dir, host_script)
65+
try:
66+
vm.copy_files_to(host_file, guest_dir)
67+
session.cmd_output(params["guest_tool_install"], timeout=240)
68+
session.cmd_output("chmod 755 %s" % guest_cmd)
69+
except Exception as e:
70+
test.fail("Guest test preparation fail: %s" % str(e))
71+
guest_cmd = guest_cmd + " " + host_cpu_model
72+
s = session.cmd_status(guest_cmd, timeout=360)
73+
if s:
74+
test.fail("Guest script error")
75+
finally:
76+
session.close()
77+
vm.destroy()

0 commit comments

Comments
 (0)