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]> --- 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); + + /* 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); -- 2.54.0.746.g67dd491aae-goog

