[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <55e8d6da-50e3-4916-a778-71da628cbc08@intel.com>
Date: Wed, 13 Aug 2025 21:34:19 +0800
From: Chenyi Qiang <chenyi.qiang@...el.com>
To: Sagi Shahar <sagis@...gle.com>, <linux-kselftest@...r.kernel.org>, "Paolo
Bonzini" <pbonzini@...hat.com>, Shuah Khan <shuah@...nel.org>, "Sean
Christopherson" <seanjc@...gle.com>, Ackerley Tng <ackerleytng@...gle.com>,
Ryan Afranji <afranji@...gle.com>, Andrew Jones <ajones@...tanamicro.com>,
Isaku Yamahata <isaku.yamahata@...el.com>, Erdem Aktas
<erdemaktas@...gle.com>, Rick Edgecombe <rick.p.edgecombe@...el.com>, "Roger
Wang" <runanwang@...gle.com>, Binbin Wu <binbin.wu@...ux.intel.com>, "Oliver
Upton" <oliver.upton@...ux.dev>, "Pratik R. Sampat"
<pratikrajesh.sampat@....com>, Reinette Chatre <reinette.chatre@...el.com>,
Ira Weiny <ira.weiny@...el.com>
CC: <linux-kernel@...r.kernel.org>, <kvm@...r.kernel.org>
Subject: Re: [PATCH v8 07/30] KVM: selftests: TDX: Use KVM_TDX_CAPABILITIES to
validate TDs' attribute configuration
On 8/8/2025 4:16 AM, Sagi Shahar wrote:
> From: Ackerley Tng <ackerleytng@...gle.com>
>
> This also exercises the KVM_TDX_CAPABILITIES ioctl.
>
> Suggested-by: Isaku Yamahata <isaku.yamahata@...el.com>
> Co-developed-by: Isaku Yamahata <isaku.yamahata@...el.com>
> Signed-off-by: Isaku Yamahata <isaku.yamahata@...el.com>
> Signed-off-by: Ackerley Tng <ackerleytng@...gle.com>
> Signed-off-by: Sagi Shahar <sagis@...gle.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?
Powered by blists - more mailing lists