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

From: Binbin Wu

Date: Tue Oct 13 2026 - 06:10:59 EST


On 10/12/2026 5:47 PM, Chao Gao wrote:
> Continue converting the metadata readers to the table-driven helper.
>
> The "TD Configurability" class holds several scalar fields plus two CPUID
> arrays. The arrays have a fixed capacity, but the number of entries to
> read is variable and reported by the num_cpuid_config scalar field.
>
> Add a table that pairs each scalar field ID with the 'struct
> tdx_sys_info_td_conf' member that holds its value, and read those fields
> by walking that table.
>
> Annotate the table as __initconst as it is referenced only during init.
>
> Leave the two arrays open coded. 'struct field_mapping' pairs one field ID
> with one structure member, so describing an array would require a field ID
> per field plus an entry count that is unknown until num_cpuid_config has
> been read. That is not worth building for the only two arrays the kernel
> reads.
>
> Read both arrays in a single loop, as both have num_cpuid_config
> entries. Store each value directly into its array member instead of
> into a temporary u64 first. The members are u64 already, so the extra
> copies serve no purpose.
>
> The inner dimension of cpuid_config_values[] is fixed at 2. Read the
> two values with two calls instead of an inner loop. This saves a level
> of indentation and is simpler to read.
>
> AI was used under supervision to review code and workshop logs.
>
> Signed-off-by: Chao Gao <chao.gao@xxxxxxxxx>
> ---

Reviewed-by: Binbin Wu <binbin.wu@xxxxxxxxxxxxxxx>

> +static __init int get_tdx_sys_info_td_conf(struct tdx_sys_info_td_conf *td_conf)
> +{
> + int ret, i;
> +
> + ret = read_sys_metadata_table(td_conf_mappings, td_conf);
> + if (ret)
> + return ret;
> +
> + /*
> + * The number of CPUID config entries must not exceed the array
> + * sizes.
> + */

Nit:
The comment seems to be redundant since the code itself tells it.

> + if (td_conf->num_cpuid_config > ARRAY_SIZE(td_conf->cpuid_config_leaves) ||
> + td_conf->num_cpuid_config > ARRAY_SIZE(td_conf->cpuid_config_values))
> + return -EINVAL;
> +

[...]