Skip to content

Commit 5754589

Browse files
committed
Update SNP guest attestation
1. Update SEV-SNP testcase and config to support snpguest tool installation from source. 2. Enhance CPU model detection for broader platform support. 3. Update SNP policy values, add a debug policy variant 4. Improve error handling in the testcase script. 5. Add snp_attestation.cfg to include newly introduced parameters. Signed-off-by: Srikanth Aithal <[email protected]>
1 parent 3fb4171 commit 5754589

File tree

2 files changed

+75
-8
lines changed

2 files changed

+75
-8
lines changed

qemu/tests/cfg/snp_attestation.cfg

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
- snp_attestation:
2+
type = snp_basic_config
3+
only Linux
4+
kill_vm = yes
5+
login_timeout = 240
6+
start_vm = no
7+
image_snapshot = yes
8+
mem = 8192
9+
smp = 8
10+
required_qemu = [9.1.0, )
11+
vm_secure_guest_type = snp
12+
vm_sev_reduced_phys_bits = 1
13+
vm_sev_cbitpos = 51
14+
virtio_dev_disable_legacy = on
15+
vm_mem_backend = memory-backend-memfd
16+
bios_path = /usr/share/edk2/ovmf/OVMF.amdsev.fd
17+
snp_module_path = "/sys/module/kvm_amd/parameters/sev_snp"
18+
module_status = Y y 1
19+
snp_guest_check = "journalctl|grep -i -w snp"
20+
guest_tool_install = "dnf install -y snpguest"
21+
snpguest_sourcebuild = 1
22+
attestation_script = regular_attestation_workflow.sh
23+
snpguest_install_script = snpguest_install.sh
24+
guest_dir = /home
25+
guest_cmd = ${guest_dir}/${attestation_script}
26+
host_script = sev-snp/${attestation_script}
27+
snpguest_buildcmd = "${guest_dir}/${snpguest_install_script} --repo https://github.com/virtee/snpguest.git --tag v0.9.1"
28+
snpguest_build_location = sev-snp/${snpguest_install_script}
29+
variants:
30+
- policy_default:
31+
snp_policy = 196608
32+
vm_secure_guest_object_options = "policy=${snp_policy}"
33+
- policy_debug:
34+
snp_policy = 720896
35+
vm_secure_guest_object_options = "policy=${snp_policy}"
36+
- policy_singlesocket:
37+
socket_count_cmd = 'lscpu |grep Socket|head -1 | cut -d ":" -f 2 | tr -d " "'
38+
snp_policy = 1245184
39+
vm_secure_guest_object_options = "policy=${snp_policy}"
40+
- policy_singlesocket_debug:
41+
socket_count_cmd = 'lscpu |grep Socket|head -1 | cut -d ":" -f 2 | tr -d " "'
42+
snp_policy = 1769472
43+
vm_secure_guest_object_options = "policy=${snp_policy}"

qemu/tests/snp_basic_config.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,36 @@ def run(test, params, env):
3636
if int(process.getoutput(socket_count_cmd, shell=True)) != 1:
3737
test.cancel("Host cpu has more than 1 socket, skip the case.")
3838

39-
family_id = cpu.get_family()
40-
model_id = cpu.get_model()
41-
dict_cpu = {"251": "milan", "2517": "genoa", "2617": "turin"}
42-
key = str(family_id) + str(model_id)
43-
host_cpu_model = dict_cpu.get(key, "unknown")
44-
39+
family_id = int(cpu.get_family())
40+
model_id = int(cpu.get_model())
41+
dict_cpu = {
42+
"milan": [25, 0, 15],
43+
"genoa": [25, 16, 31],
44+
"bergamo": [25, 160, 175],
45+
"turin": [26, 0, 31],
46+
}
47+
host_cpu_model = None
48+
for platform, values in dict_cpu.items():
49+
if values[0] == family_id:
50+
if model_id >= values[1] and model_id <= values[2]:
51+
host_cpu_model = platform
52+
if not host_cpu_model:
53+
test.cancel("Unsupported paltform. Requires milan or above.")
54+
test.log.info("Detected platform: %s", host_cpu_model)
4555
vm_name = params["main_vm"]
4656
vm = env.get_vm(vm_name)
4757
vm.create()
4858
vm.verify_alive()
4959
session = vm.wait_for_login(timeout=timeout)
5060
verify_dmesg()
61+
# Check for /dev/sev-guest inside the guest
62+
test.log.info("Checking for SNP attestation support in guest")
63+
rc_code = session.cmd_status("ls /dev/sev-guest")
64+
if rc_code:
65+
test.cancel(
66+
"Error: Unable to open /dev/sev-guest. Guest kernel support for "
67+
"SNP attestation is missing."
68+
)
5169
vm_policy = vm.params.get_numeric("snp_policy")
5270
guest_check_cmd = params["snp_guest_check"]
5371
sev_guest_info = vm.monitor.query_sev()
@@ -67,14 +85,20 @@ def run(test, params, env):
6785
host_file = os.path.join(deps_dir, host_script)
6886
try:
6987
vm.copy_files_to(host_file, guest_dir)
70-
session.cmd_output(params["guest_tool_install"], timeout=240)
88+
if params.get("snpguest_sourcebuild", "0") == "1":
89+
snpguest_build_location = params["snpguest_build_location"]
90+
install_snpguest = os.path.join(deps_dir, snpguest_build_location)
91+
vm.copy_files_to(install_snpguest, guest_dir)
92+
session.cmd_output(params["snpguest_buildcmd"], timeout=360)
93+
else:
94+
session.cmd_output(params["guest_tool_install"], timeout=240)
7195
session.cmd_output("chmod 755 %s" % guest_cmd)
7296
except Exception as e:
7397
test.fail("Guest test preperation fail: %s" % str(e))
7498
guest_cmd = guest_cmd + " " + host_cpu_model
7599
s = session.cmd_status(guest_cmd, timeout=360)
76100
if s:
77-
test.fail("Guest script error")
101+
test.fail("Guest script error, check the session logs for further details")
78102
finally:
79103
session.close()
80104
vm.destroy()

0 commit comments

Comments
 (0)