From: Chao Gao <chao.gao@intel.com>
To: Kiryl Shutsemau <kas@kernel.org>
Cc: Dave Hansen <dave.hansen@intel.com>, <linux-coco@lists.linux.dev>,
<linux-kernel@vger.kernel.org>, <x86@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>, Kai Huang <kai.huang@intel.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Dan Williams <dan.j.williams@intel.com>
Subject: Re: [PATCH 1/2] x86/virt/tdx: Retrieve TDX module version
Date: Fri, 24 Oct 2025 14:33:23 +0800 [thread overview]
Message-ID: <aPsds5SCmmoG4IJO@intel.com> (raw)
In-Reply-To: <nfos7qsdendp45avmlpbftmekckewwvbb6romybh2dnbvomfee@a5lqto3xkeak>
>I don't hate it. Seems more scalable than current approach.
>
>See some comments below.
>
>> diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
>> index 128e6ffba736..fa9bb6d47a87 100644
>> --- a/arch/x86/virt/vmx/tdx/tdx.c
>> +++ b/arch/x86/virt/vmx/tdx/tdx.c
>> @@ -226,22 +226,23 @@ static int build_tdx_memlist(struct list_head *tmb_list)
>> return ret;
>> }
>>
>> -static int read_sys_metadata_field(u64 field_id, u64 *data)
>> +static int read_sys_metadata_field(u64 *field_id, void *ptr)
>
>Keeping the same name for completely different functionality?
how about read_sys_metadata_fields() or read_sys_metadata_all()?
>
>> {
>> struct tdx_module_args args = {};
>> int ret;
>>
>> /*
>> - * TDH.SYS.RD -- reads one global metadata field
>> - * - RDX (in): the field to read
>> - * - R8 (out): the field data
>> + * TDH.SYS.RDALL -- reads all global metadata fields
>> + * - RDX (in): the physical address of the buffer to store
>> + * - R8 (in/out): the initial field ID to read (in) and
>> + * the next field ID to read (out).
>> */
>> - args.rdx = field_id;
>> - ret = seamcall_prerr_ret(TDH_SYS_RD, &args);
>> + args.rdx = __pa(ptr);
>
>Maybe take virtual address (unsigned long) of the buffer as an argument
>to the function. And use virt_to_phys() here.
>
>This way there's no need in cast on caller side.
Sure. Will do.
>
>> + args.r8 = *field_id;
>> + ret = seamcall_prerr_ret(TDH_SYS_RDALL, &args);
>> if (ret)
>> return ret;
>> -
>> - *data = args.r8;
>> + *field_id = args.r8;
>>
>> return 0;
>
>Hm. Isn't it buggy?
>
>Caller expects to see field_id == -1 to exit loop, but you never set it
>in case of an error. It will result in endless loop if error happens not on
>the first iteration.
The caller checks the return value and bails out if there was an error.
>
>Drop the branch and always return ret.
Setting field_id to -1 on error appears unnecessary since callers must check
the return value anyway. And, even if args.r8 were copied to field_id
on error, this wouldn't guarantee that field_id would be set to -1, as
SEAMCALLs may encounter #GP/#UD exceptions where r8 remains unchanged.
Given this, I prefer to leave field_id as an undefined value on error, and
callers should not read/use it when an error occurs.
What do you think?
next prev parent reply other threads:[~2025-10-24 6:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-01 2:22 [PATCH 0/2] Expose TDX Module version Chao Gao
2025-10-01 2:22 ` [PATCH 1/2] x86/virt/tdx: Retrieve TDX module version Chao Gao
2025-10-01 15:15 ` Dave Hansen
2025-10-22 7:54 ` Chao Gao
2025-10-22 10:26 ` Kiryl Shutsemau
2025-10-24 6:33 ` Chao Gao [this message]
2025-10-24 9:35 ` Kiryl Shutsemau
2025-10-24 10:04 ` Chao Gao
2025-11-13 1:24 ` Chao Gao
2025-10-24 14:20 ` Vishal Annapurve
2025-10-01 2:22 ` [PATCH 2/2] coco/tdx-host: Expose " Chao Gao
2025-10-01 4:12 ` Huang, Kai
2025-10-01 11:27 ` Kiryl Shutsemau
2025-10-01 21:41 ` Huang, Kai
2025-10-01 11:30 ` Kiryl Shutsemau
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=aPsds5SCmmoG4IJO@intel.com \
--to=chao.gao@intel.com \
--cc=bp@alien8.de \
--cc=dan.j.williams@intel.com \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kai.huang@intel.com \
--cc=kas@kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).