From: Isaku Yamahata 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 Co-developed-by: Sagi Shahar Signed-off-by: Sagi Shahar Reviewed-by: Binbin Wu Reviewed-by: Ira Weiny Signed-off-by: Lisa Wang Reviewed-by: Xiaoyao Li --- tools/testing/selftests/kvm/lib/x86/tdx/tdx_util.c | 12 ++++++++++++ 1 file changed, 12 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 e1ffb67a106c..c01a26567b73 100644 --- a/tools/testing/selftests/kvm/lib/x86/tdx/tdx_util.c +++ b/tools/testing/selftests/kvm/lib/x86/tdx/tdx_util.c @@ -93,6 +93,16 @@ static void tdx_filter_cpuid(struct kvm_vm *vm, } } +static void tdx_check_attributes(struct kvm_vm *vm, u64 attributes) +{ + struct kvm_tdx_capabilities *tdx_cap; + + tdx_cap = tdx_read_capabilities(vm); + + /* Make sure all the attributes are reported as supported */ + TEST_ASSERT_EQ(attributes & tdx_cap->supported_attrs, attributes); +} + void tdx_init_vm(struct kvm_vm *vm, u64 attributes) { struct kvm_tdx_init_vm *init_vm; @@ -112,6 +122,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); -- 2.55.0.229.g6434b31f56-goog