Skip to content

Commit

Permalink
KVM: Add TDX module check test case
Browse files Browse the repository at this point in the history
Signed-off-by: Xudong Hao <[email protected]>
  • Loading branch information
xhao22 authored Dec 27, 2024
1 parent 3e92d06 commit bdaa244
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
20 changes: 20 additions & 0 deletions KVM/qemu/tdx_seam_module.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- tdx_seam_module:
type = tdx_seam_module
virt_test_type = qemu
vm_accelerator = kvm
machine_type_extra_params = "kernel-irqchip=split"
vm_secure_guest_type = tdx
# Don't create/remove guest images
force_create_image = no
remove_image = no
start_vm = no
# Stop VM after testing
kill_vm = yes
shell_prompt = "^\[.*\][\#\$]\s*$"
vga = std
auto_cpu_model = "no"
cpu_model = host
read_cmd = "cat /sys/module/kvm_intel/parameters/%s"
rdmsr_cmd = "rdmsr 0xfe --bitfield 15:15"
tdx_module_pattern = "tdx: module initialized"
tdx_negative_pattern = "No TDX module loaded by BIOS"
43 changes: 43 additions & 0 deletions KVM/qemu/tests/tdx_seam_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/python3

# SPDX-License-Identifier: GPL-2.0-only
# Copyright (c) 2024 Intel Corporation

# Author: Xudong Hao <[email protected]>
#
# History: Dec. 2024 - Xudong Hao - creation

import re

from avocado.utils import process, cpu


def run(test, params, env):
"""
TDX module test:
1. Check host TDX capability
2. Check TDX module load status
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment.
"""
if cpu.get_cpu_vendor_name() != 'intel':
test.cancel("This test is supposed to run on Intel host")

rdmsr_cmd = params["rdmsr_cmd"]
if process.getoutput(rdmsr_cmd) != "1":
test.fail("Platform does not support TDX-SEAM")

read_cmd = params["read_cmd"]
tdx_value = process.getoutput(read_cmd % "tdx")
if tdx_value != "Y":
test.fail("TDX is not supported in KVM")

module_pattern = params["tdx_module_pattern"]
negative_pattern = params["tdx_negative_pattern"]
dmesg = process.system_output("dmesg")
module_str = re.findall(r'%s' % module_pattern, dmesg.decode('utf-8'))
negative_str = re.findall(r'%s' % negative_pattern, dmesg.decode('utf-8'))
if negative_str or not module_str:
test.fail("TDX module isn't initialized")

0 comments on commit bdaa244

Please sign in to comment.