Re: [PATCH v5 1/6] x86/virt/tdx: Move TDH.SYS.CONFIG operations into a wrapper

From: Edgecombe, Rick P

Date: Wed Nov 18 2026 - 13:51:47 EST


On Wed, 2026-11-11 at 11:48 +0800, Xu Yilun wrote:
> TDH.SYS.CONFIG is currently not wrapped in a SEAMCALL wrapper because it
> is not exposed to external callers (such as KVM), also because the
> level of TDX ABI details needed to perform the call is low enough to
> flow well with the calling code.
>
> But as more configurations are being added to this SEAMCALL leaf, more
> ABI details are leaked into the surrounding caller code, which decreases
> the readability of the caller logic. The first case is that the Dynamic
> PAMT (DPAMT) change [1] tweaks the R8 argument based on whether DPAMT is
> supported by the loaded TDX module.
>
> A follow-up case comes as the TDX architecture has evolved the ABI to
> introduce new leaf versions. The host must select the version to call
> based on what new features are supported by the loaded TDX module.

It is not totally clear to me what a leaf version is here. Like is it a new leaf
or (as it actually is) a new variant of a single leaf.

>
> Before the version selection makes the caller logic even messier, move
> the register ABI operations into a wrapper.
>
> The original changelog was written by hand. AI was used to help correct
> grammatical errors and polish individual sentences for better
> readability.

Looks good overall, but weren't we going to drop the AI blurb? Oh oops that was
a comment on a different series:
https://lore.kernel.org/lkml/03cdc774-7fef-4d0b-82f7-126288636f3d@xxxxxxxxx/

>
> Signed-off-by: Xu Yilun <yilun.xu@xxxxxxxxxxxxxxx>
> Link:
> https://lore.kernel.org/all/20260904215841.303070-10-rick.p.edgecombe@xxxxxxxxx/
>  # [1]
> ---
> v5:
>  - Drop the tdmr_info_pa_array stuff (Dave)
>  - Simplify the changelog (Dave)
>  - Remove all Reviewed-by tags due to code change
>  - Better clarify the AI usage
>
> v4:
>  - Cut the redundant opening words in the 1st paragraph (Rick)
>  - Collect Reviewed-by tags
>
> v3:
>  - sizeof(tdmr_pa_array->phys[0]) instead of sizeof(u64) (Rick)
>  - Re-phrase the code comments for struct tdmr_info_pa_array (Tony)
>  - Refactor the changelog
>  - Collect Reviewed-by tags
>
> v2:
>  - Remove TDH.SYS.UPDATE wrapper (Dave & Rick)
>  - Talk about the handling of in-memory ABIs for SEAMCALL wrappers
>    (Rick)
>  - Refactor the entire changelog according to Rick's suggestion (Rick)
>  - Add code comment for struct tdmr_info_pa_array (AI nitpicker)
>  - Use kernel data type for nr_tdmr_pa parameter (AI nitpicker)
>
> v1:
>  - This patch is split out from the last series (Rick)
> ---
>  arch/x86/virt/vmx/tdx/tdx.c | 30 +++++++++++++++++++-----------
>  1 file changed, 19 insertions(+), 11 deletions(-)
>
> diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
> index 96ced0494b68..c7bd0b01786d 100644
> --- a/arch/x86/virt/vmx/tdx/tdx.c
> +++ b/arch/x86/virt/vmx/tdx/tdx.c
> @@ -1033,10 +1033,26 @@ static __init int construct_tdmrs(struct list_head
> *tmb_list,
>  
>  #define TDX_SYS_CONFIG_DYNAMIC_PAMT BIT(16)
>  
> +static __init int tdx_sys_config(u64 *tdmr_pa_array, unsigned int nr_tdmr_pa,
> + u64 global_keyid)
> +{
> + struct tdx_module_args args = {
> + .rcx = __pa(tdmr_pa_array),
> + .rdx = nr_tdmr_pa,
> + .r8 = global_keyid,
> + };
> +
> + if (tdx_supports_dynamic_pamt(&tdx_sysinfo)) {
> + pr_info("Enable Dynamic PAMT\n");
> + args.r8 |= TDX_SYS_CONFIG_DYNAMIC_PAMT;
> + }
> +
> + return seamcall_prerr(TDH_SYS_CONFIG, &args);
> +}
> +
>  static __init int config_tdx_module(struct tdmr_info_list *tdmr_list,
>       u64 global_keyid)
>  {
> - struct tdx_module_args args = {};
>   u64 *tdmr_pa_array;
>   size_t array_sz;
>   int i, ret;
> @@ -1058,16 +1074,8 @@ static __init int config_tdx_module(struct
> tdmr_info_list *tdmr_list,
>   for (i = 0; i < tdmr_list->nr_consumed_tdmrs; i++)
>   tdmr_pa_array[i] = __pa(tdmr_entry(tdmr_list, i));
>  
> - args.rcx = __pa(tdmr_pa_array);
> - args.rdx = tdmr_list->nr_consumed_tdmrs;
> - args.r8 = global_keyid;
> -
> - if (tdx_supports_dynamic_pamt(&tdx_sysinfo)) {
> - pr_info("Enable Dynamic PAMT\n");
> - args.r8 |= TDX_SYS_CONFIG_DYNAMIC_PAMT;
> - }
> -
> - ret = seamcall_prerr(TDH_SYS_CONFIG, &args);
> + ret = tdx_sys_config(tdmr_pa_array, tdmr_list->nr_consumed_tdmrs,
> +      global_keyid);
>  
>   /* Free the array as it is not required anymore. */
>   kfree(tdmr_pa_array);
>