On 5/22/2026 7:16 AM, Lisa Wang wrote:
From: Isaku Yamahata <[email protected]>
Make sure that all the attributes enabled by the test are reported as
supported by both the TDX module and KVM. KVM filters out the attributes
not supported by itself.
This also exercises the KVM_TDX_CAPABILITIES ioctl.
Signed-off-by: Isaku Yamahata <[email protected]>
Co-developed-by: Sagi Shahar <[email protected]>
Signed-off-by: Sagi Shahar <[email protected]>
Reviewed-by: Binbin Wu <[email protected]>
Reviewed-by: Ira Weiny <[email protected]>
Signed-off-by: Lisa Wang <[email protected]>
Reviewed-by: Xiaoyao Li <[email protected]>
---
tools/testing/selftests/kvm/lib/x86/tdx/tdx_util.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/tools/testing/selftests/kvm/lib/x86/tdx/tdx_util.c
b/tools/testing/selftests/kvm/lib/x86/tdx/tdx_util.c
index 868ff62e22f2..e5c998874a0d 100644
--- a/tools/testing/selftests/kvm/lib/x86/tdx/tdx_util.c
+++ b/tools/testing/selftests/kvm/lib/x86/tdx/tdx_util.c
@@ -110,6 +110,18 @@ static void tdx_filter_cpuid(struct kvm_vm *vm,
free(tdx_cap);
}
+static void tdx_check_attributes(struct kvm_vm *vm, u64 attributes)
+{
+ struct kvm_tdx_capabilities *tdx_cap;
+
+ tdx_cap = tdx_read_capabilities(vm);
well, this is another caller of tdx_read_capabilities().
As I commented in the previous patch, it's worth caching the result in
tdx_read_capabilities() like what kvm_get_supported_cpuid() does for
kvm_supported_cpuid.
And it can help only print the debug once.
+ /* Make sure all the attributes are reported as supported */
+ TEST_ASSERT_EQ(attributes & tdx_cap->supported_attrs, attributes);
+
+ free(tdx_cap);
+}
+
void tdx_init_vm(struct kvm_vm *vm, u64 attributes)
{
struct kvm_tdx_init_vm *init_vm;
@@ -129,6 +141,8 @@ void tdx_init_vm(struct kvm_vm *vm, u64 attributes)
memcpy(&init_vm->cpuid, cpuid, kvm_cpuid2_size(cpuid->nent));
free(cpuid);
+ tdx_check_attributes(vm, attributes);
+
init_vm->attributes = attributes;
tdx_vm_ioctl(vm, KVM_TDX_INIT_VM, 0, init_vm);