Re: [PATCH v3 07/10] x86/virt/tdx: Convert the td_conf metadata reader

From: Chao Gao

Date: Thu Oct 01 2026 - 08:34:46 EST


On Thu, Oct 01, 2026 at 07:54:43AM +0800, Edgecombe, Rick P wrote:
>On Tue, 2026-09-29 at 22:38 -0700, Chao Gao wrote:
>> + /*
>> + * TDX_FIELD_CPUID_CONFIG_LEAVES and TDX_FIELD_CPUID_CONFIG_VALUES
>> + * give the field ID of each array's first element. The remaining
>> + * elements follow consecutively, in the order they appear in the
>> + * structure.
>> + */
>> + for (i = 0; i < td_conf->num_cpuid_config; i++) {
>> + ret = read_sys_metadata_field(TDX_FIELD_CPUID_CONFIG_LEAVES + i,
>> +       &td_conf->cpuid_config_leaves[i]);
>> + if (ret)
>> + return ret;
>> +
>> + /* Each config has two u64s of CPUID values. */
>> + for (j = 0; j < 2; j++) {
>> + ret = read_sys_metadata_field(
>> + TDX_FIELD_CPUID_CONFIG_VALUES + i * 2 + j,
>> + &td_conf->cpuid_config_values[i][j]);
>> + if (ret)
>> + return ret;
>> + }
>> + }
>> +
>> + return 0;
>> +}
>
>The comments are not strictly required, but probably fit into turning this thing
>into "hand coding". I think it's a nice addition. I wonder if we should make the
>"i * 2 + j" a bit clearer though?
>

How about:

/*
* cpuid_config_leaves[i] holds a CPUID leaf and sub-leaf number,
* and the two u64s of cpuid_config_values[i] mark which bits of
* that leaf's EAX/EBX/ECX/EDX the host can set to 0 or 1 for a TD.
*
* TDX_FIELD_CPUID_CONFIG_LEAVES and TDX_FIELD_CPUID_CONFIG_VALUES
* give the field ID of each array's first element, and the rest
* follow in order.
*/