Re: [PATCH v2 02/17] x86/virt/tdx: Configure add-on features on TDX module init and update
From: Peter Fang
Date: Wed Jun 24 2026 - 18:11:39 EST
On Wed, Jun 24, 2026 at 08:00:39PM +0800, Xu Yilun wrote:
> > There's also zero stopping us from putting version in args:
> >
> > struct tdx_module_args args = {};
> > int ret;
> >
> > if (tdx_addon_feature0) {
> > args.r9 = tdx_addon_feature0;
> > args.version = 1;
> > }
> >
> > ret = seamcall_prerr(TDH_SYS_UPDATE, &args);
> >
> > Eh?
> >
> > That gives args.version==0 in all the normal cases which just happens to
> > be the exact behavior we want. It also avoids having to plumb version
> > through all the seamcall*() wrappers.
>
> Ah, on 2nd reading, I'm pretty sure now I understand your logical argument in
> patch 1 and 2. It's good to me. I append my diff at the end.
>
[ ... ]
> diff --git a/arch/x86/virt/vmx/tdx/tdxcall.S b/arch/x86/virt/vmx/tdx/tdxcall.S
> index 016a2a1ec1d6..d1d3d40c5614 100644
> --- a/arch/x86/virt/vmx/tdx/tdxcall.S
> +++ b/arch/x86/virt/vmx/tdx/tdxcall.S
> @@ -48,6 +48,14 @@
> /* Move Leaf ID to RAX */
> mov %rdi, %rax
>
> + /*
> + * Extract the version from 'struct tdx_module_args', append it to
> + * RAX[23:16]
> + */
> + movzbl TDX_MODULE_version(%rsi), %ecx
> + shll $16, %ecx
> + orq %rcx, %rax
> +
> /* Move other input regs from 'struct tdx_module_args' */
> movq TDX_MODULE_rcx(%rsi), %rcx
> movq TDX_MODULE_rdx(%rsi), %rdx
This approach looks much cleaner to me. Would it be better to have a
small C helper to encode the final RAX value instead of operating on RAX
directly in asm? Looking at the May 2026 edition of the ABI spec,
SEAMCALL RAX encoding is starting to get quite complex. Just thinking
about this from a readability standpoint.