Re: [PATCH v4 07/10] x86/virt/tdx: Convert the td_conf metadata reader
From: Xu Yilun
Date: Wed Oct 14 2026 - 04:00:41 EST
On Mon, Oct 12, 2026 at 02:47:34AM -0700, 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: Xu Yilun <yilun.xu@xxxxxxxxxxxxxxx>