On 8/8/2025 4:16 AM, Sagi Shahar wrote:
> From: Ackerley Tng <ackerley...@google.com>
>
> This also exercises the KVM_TDX_CAPABILITIES ioctl.
>
> Suggested-by: Isaku Yamahata <isaku.yamah...@intel.com>
> Co-developed-by: Isaku Yamahata <isaku.yamah...@intel.com>
> Signed-off-by: Isaku Yamahata <isaku.yamah...@intel.com>
> Signed-off-by: Ackerley Tng <ackerley...@google.com>
> Signed-off-by: Sagi Shahar <sa...@google.com>
> ---
> .../selftests/kvm/lib/x86/tdx/tdx_util.c | 17 +++++++++++++++++
> 1 file changed, 17 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 392d6272d17e..bb074af4a476 100644
> --- a/tools/testing/selftests/kvm/lib/x86/tdx/tdx_util.c
> +++ b/tools/testing/selftests/kvm/lib/x86/tdx/tdx_util.c
> @@ -140,6 +140,21 @@ static void tdx_apply_cpuid_restrictions(struct
> kvm_cpuid2 *cpuid_data)
> }
> }
>
> +static void tdx_check_attributes(struct kvm_vm *vm, uint64_t attributes)
> +{
> + struct kvm_tdx_capabilities *tdx_cap;
> +
> + tdx_cap = tdx_read_capabilities(vm);
> +
> + /* TDX spec: any bits 0 in supported_attrs must be 0 in attributes */
> + TEST_ASSERT_EQ(attributes & ~tdx_cap->supported_attrs, 0);
> +
> + /* TDX spec: any bits 1 in attributes must be 1 in supported_attrs */
> + TEST_ASSERT_EQ(attributes & tdx_cap->supported_attrs, attributes);
> +
> + free(tdx_cap);
> +}
> +
> #define KVM_MAX_CPUID_ENTRIES 256
>
> #define CPUID_EXT_VMX BIT(5)
> @@ -256,6 +271,8 @@ static void tdx_td_init(struct kvm_vm *vm, uint64_t
> attributes)
> memcpy(&init_vm->cpuid, cpuid, kvm_cpuid2_size(cpuid->nent));
> free(cpuid);
>
> + tdx_check_attributes(vm, attributes);
> +
> init_vm->attributes = attributes;
>
> tdx_apply_cpuid_restrictions(&init_vm->cpuid);
Do we need to set the init_vm->xfam based on cpuid.0xd and validate it with
tdx_cap->supported_xfam?