From: Nikolay Borisov <nik.borisov@suse.com>
To: Xu Yilun <yilun.xu@linux.intel.com>, Kiryl Shutsemau <kas@kernel.org>
Cc: Dave Hansen <dave.hansen@intel.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
rick.p.edgecombe@intel.com, dave.hansen@linux.intel.com,
yilun.xu@intel.com, chao.gao@intel.com, djbw@kernel.org,
linux-coco@lists.linux.dev, peter.fang@intel.com,
xiaoyao.li@intel.com
Subject: Re: [PATCH v2] x86/virt/tdx: Formalize SEAMCALL version encoding support
Date: Fri, 17 Jul 2026 11:21:34 +0300 [thread overview]
Message-ID: <90685b93-e13e-4509-98f3-4509381d4981@suse.com> (raw)
In-Reply-To: <almwGwoUzoA96XnG@yilunxu-OptiPlex-7050>
On 7/17/26 07:31, Xu Yilun wrote:
>>> struct tdx_module_args {
>>> union {
>>> u64 rax;
>>> struct {
>>> u16 function_nr;
>>> u8 version
>>> u8 padding0;
>>> u32 flags;
>>> };
>>> };
>>> u64 rcx;
>>> u64 rdx;
>>> ...
>>> }
>>
>> This union doesn't match the ABI it is supposed to represent.
>>
>> RAX is:
>>
>> 15:0 Leaf number
>> 23:16 Version number
>> 24 INTERRUPT_MODE
>> 62:25 Reserved
>> 63 P-SEAMLDR select
>>
>> In your layout INTERRUPT_MODE ends up somewhere in padding0 and the
>> P-SEAMLDR bit is BIT(31) of 'flags'. Nothing lines up with the spec.
>>
>> To describe the format properly the struct would need bitfields, and we
>> generally discourage bitfields for ABI-defined layouts. Without
>
> I agree that to describe each part of RAX clearly we need bitfields, and
> bitfields is not good for args.rax. So args.rax is not generally good
> to me, worse than a separate u64.
>
>> bitfields it degrades into masks and shifts on a u64 -- which is
>> exactly what composing 'fn' with a macro is. The union doesn't add
>> anything on top of that, it only hides where the bits are.
>
> [..]
>
>>> The truth of the matter is that 'fn' *IS* the RAX from the TDX ABI.
>>> We're carrying it around the kernel in that format, and it just doesn't
>>> work very well.
>>>
>>> The alternative is to carry the logical pieces of RAX around the kernel
>>> and them assemble RAX out of them in one (or very few) places. *Not* to
>>> build RAX in the TDX module ABI early far from the TDX module ABI layer
>>> itself.
>>
>> I don't see what delaying the assembly buys us.
>>
>> The SEAMCALL helper is where we decide what we want from the call: the
>> leaf, the version, the operands. Nothing below it adds information --
>> sc_retry() and __seamcall_dirty_cache() only retry on entropy failure
>> and track cache state. There is no layer further down that is in a
>> better position to compose RAX than the helper itself.
>>
>> And it is not "far from the TDX module ABI layer". The tdh_*() helpers
>> are the C representation of the ABI functions. They are the ABI layer.
>
> I wanna advance the progress, so if I have to choose I sort of like
> *args.version*, or even args.interrupt_mode in future. True this does
> not exactly match the registers' layout of TDX module ABI, but I also
> don't see big problems. Using fn instead of args.rax at the first place
> already shows we don't have to be too strictly aligned to ABI. We are
> defining SW APIs.
>
> To me the args.version scheme clearly defines 3 components that we want
> from SW POV:
>
> the leaf fn
> the version args.version
> the operands args.rcx
> ...
> args.r15
>
> The TDX module SPEC tells us each value of these components, we simply
> fill them in. No extra bit-or.
Just my .2 cent FWIW:
At the end of the day the layout of args is the software API that is
presented to the rest of the system, the ABI is a low level detail
handled in TDX_MODULE_CALL. Let's bury all the ugly handling in the asm
and present a simpler interface to the rest of the kernel
Exposing a raw representation of RAX is somewhat cumbersome because of
the reasons already listed so "converting" that to 3 variables in the
structure seems same to me.
<snip>
next prev parent reply other threads:[~2026-07-17 8:21 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 17:03 [PATCH v2] x86/virt/tdx: Formalize SEAMCALL version encoding support Xu Yilun
2026-07-08 18:03 ` Dave Hansen
2026-07-09 10:16 ` Xu Yilun
2026-07-10 16:21 ` Kiryl Shutsemau
2026-07-10 16:48 ` Dave Hansen
2026-07-13 9:40 ` Kiryl Shutsemau
2026-07-17 4:31 ` Xu Yilun
2026-07-17 8:21 ` Nikolay Borisov [this message]
2026-07-17 13:10 ` Dave Hansen
2026-07-10 15:56 ` Kiryl Shutsemau
2026-07-13 9:21 ` Xu Yilun
2026-07-13 11:38 ` Kiryl Shutsemau
2026-07-14 11:18 ` Xu Yilun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=90685b93-e13e-4509-98f3-4509381d4981@suse.com \
--to=nik.borisov@suse.com \
--cc=chao.gao@intel.com \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=djbw@kernel.org \
--cc=kas@kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=peter.fang@intel.com \
--cc=rick.p.edgecombe@intel.com \
--cc=x86@kernel.org \
--cc=xiaoyao.li@intel.com \
--cc=yilun.xu@intel.com \
--cc=yilun.xu@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox