From: Baolu Lu <baolu.lu@linux.intel.com>
To: Xu Yilun <yilun.xu@linux.intel.com>
Cc: baolu.lu@linux.intel.com, iommu@lists.linux.dev, x86@kernel.org,
linux-coco@lists.linux.dev, kvm@vger.kernel.org,
Jason Gunthorpe <jgg@ziepe.ca>, Kevin Tian <kevin.tian@intel.com>,
Kiryl Shutsemau <kas@kernel.org>,
Rick Edgecombe <rick.p.edgecombe@intel.com>,
xiaoyao.li@intel.com, Chao Gao <chao.gao@intel.com>,
Binbin Wu <binbin.wu@linux.intel.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/9] x86/virt/tdx: Add SEAMCALL wrappers for IOMMU setup/clear
Date: Tue, 24 Nov 2026 13:46:31 +0800 [thread overview]
Message-ID: <ac7208aa-04a0-4fd6-bb32-b9478678fd19@linux.intel.com> (raw)
In-Reply-To: <awQNpgjgIlwhXrqT@yilunxu-OptiPlex-7050>
On 11/23/2026 5:55 PM, Xu Yilun wrote:
>> diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
>> index 4cce77b6a31f..a1f35188a272 100644
>> --- a/arch/x86/virt/vmx/tdx/tdx.c
>> +++ b/arch/x86/virt/vmx/tdx/tdx.c
>> @@ -2567,3 +2567,56 @@ void tdx_sys_disable(void)
>> if (ret && (ret & TDX_SW_ERROR) != TDX_SW_ERROR)
>> pr_err("TDH.SYS.DISABLE failed: 0x%016llx\n", ret);
>> }
>> +
>> +/* No cache flush is needed; hardware keeps caches coherent across KeyIDs. */
>> +u64 tdh_iommu_setup(u64 reg_base, struct tdx_iommu_mt_param *param,
>
> param is too general, name it iommu_mt, is it better?
Agreed. In a function whose arguments are all parameters, @param doesn't
say anything. I will rename param to iommu_mt.
>
>> + u64 *tdx_iommu_id)
>> +{
>> + struct tdx_module_args args = {
>> + .rcx = reg_base,
>> + .rdx = __pa(param),
>> + };
>> + u64 ret;
>> +
>> + /*
>> + * Retry only on TDX_INTERRUPTED_RESUMABLE:
>> + *
>> + * - TDX_INTERRUPTED_RESUMABLE guarantees forward progress between
>> + * calls.
>> + * - On TDX_INTERRUPTED_RESUMABLE, all registers except RAX remain
>> + * unchanged.
>> + *
>> + * The ABI spec also allows retrying on TDX_OPERAND_BUSY, but that
>> + * status doesn't guarantee forward progress, so retrying could spin
>> + * forever. The host serializes all TDH.IOMMU.SETUP and
>> + * TDH.IOMMU.CLEAR calls for an IOMMU, so the TDX module should never
>> + * report the operand as busy.
>
> Many SEAMCALLs return TDX_OPERAND_BUSY, and this is the generally expected
> handling. I don't think we don't need the comment if nothing special.
I'd like to keep a shorter note. It's the usual handling for TDX folks,
but people outside TDX may read this path too.
>
>> + */
>> + do {
>> + ret = seamcall_ret(TDH_IOMMU_SETUP, &args);
>> + } while (ret == TDX_INTERRUPTED_RESUMABLE);
>> +
>> + *tdx_iommu_id = args.rcx;
>
> I remember there was an internal debate about whether to only assign the
> output upon success.
>
> There are several examples in tdx.c that assign the output regardless.
> But all of them holds error information, which makes total sense to
> assign on error.
Oh, I overlooked this.
>
> This rcx output however doesn't hold info on error. So I think early
> exit is the right choice. Also see tdh_phymem_pamt_remove()
Agreed. rcx carries nothing useful on failure. Will return early and
only set tdx_iommu_id on success.
>> +
>> + return ret;
>> +}
>> +EXPORT_SYMBOL_FOR_MODULES(tdh_iommu_setup, "tdx-host");
>> +
>> +u64 tdh_iommu_clear(u64 tdx_iommu_id)
>> +{
>> + struct tdx_module_args args = {
>> + .rcx = tdx_iommu_id,
>> + };
>> + u64 ret;
>> +
>> + /*
>> + * Don't retry on TDX_OPERAND_BUSY. See the comment in
>> + * tdh_iommu_setup().
>> + */
>
> ditto
>
>> + do {
>> + ret = seamcall(TDH_IOMMU_CLEAR, &args);
>> + } while (ret == TDX_INTERRUPTED_RESUMABLE);
>> +
>> + return ret;
>> +}
>> +EXPORT_SYMBOL_FOR_MODULES(tdh_iommu_clear, "tdx-host");
>> --
>> 2.43.0
>>
Thanks,
baolu
next prev parent reply other threads:[~2026-11-24 5:46 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 4:30 [PATCH v3 0/9] coco/tdx-host: Introduce trusted DMA initialization support Lu Baolu
2026-11-12 4:30 ` [PATCH v3 1/9] x86/virt/tdx: Add SEAMCALL wrappers for IOMMU setup/clear Lu Baolu
2026-11-18 11:02 ` Binbin Wu
2026-11-23 4:03 ` Baolu Lu
2026-11-23 9:55 ` Xu Yilun
2026-11-24 5:46 ` Baolu Lu [this message]
2026-11-12 4:30 ` [PATCH v3 2/9] x86/virt/tdx: Read global metadata for trusted IOMMU Lu Baolu
2026-11-18 13:39 ` Binbin Wu
2026-11-23 4:09 ` Baolu Lu
2026-11-12 4:30 ` [PATCH v3 3/9] x86/virt/tdx: Export Dynamic PAMT helpers to tdx-host Lu Baolu
2026-11-23 10:25 ` Xu Yilun
2026-11-23 16:28 ` Edgecombe, Rick P
2026-11-24 6:07 ` Baolu Lu
2026-11-12 4:30 ` [PATCH v3 4/9] iommu/vt-d: Add interface for tdx-host when enabling trusted DMA Lu Baolu
2026-11-23 15:08 ` Xu Yilun
2026-11-12 4:30 ` [PATCH v3 5/9] iommu/vt-d: Block GCMD and ECMD while acquired by the TDX module Lu Baolu
2026-11-12 4:30 ` [PATCH v3 6/9] iommu/vt-d: Refuse system suspend " Lu Baolu
2026-11-12 4:30 ` [PATCH v3 7/9] coco/tdx-host: Add skeleton to support PCI link encryption Lu Baolu
2026-11-18 7:16 ` Chao Gao
2026-11-23 3:30 ` Baolu Lu
2026-11-23 15:26 ` Xu Yilun
2026-11-19 2:52 ` Binbin Wu
2026-11-23 4:18 ` Baolu Lu
2026-11-23 15:43 ` Xu Yilun
2026-11-12 4:30 ` [PATCH v3 8/9] coco/tdx-host: Rename tdx-host.c to main.c Lu Baolu
2026-11-12 4:30 ` [PATCH v3 9/9] coco/tdx-host: Enable trusted DMA on IOMMUs on device connect Lu Baolu
2026-11-18 8:11 ` Chao Gao
2026-11-23 4:51 ` Baolu Lu
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=ac7208aa-04a0-4fd6-bb32-b9478678fd19@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=binbin.wu@linux.intel.com \
--cc=chao.gao@intel.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=kas@kernel.org \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=rick.p.edgecombe@intel.com \
--cc=x86@kernel.org \
--cc=xiaoyao.li@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
all inboxes | Powered by JetHome®