From: Baolu Lu <baolu.lu@linux.intel.com>
To: sashiko-reviews@lists.linux.dev, kvm@vger.kernel.org
Cc: baolu.lu@linux.intel.com
Subject: Re: [PATCH v2 4/4] coco/tdx-host: Initialize trusted DMA on all capable IOMMUs
Date: Thu, 15 Oct 2026 13:58:49 +0800 [thread overview]
Message-ID: <a4f077a0-8b34-4eae-b5a0-567c706d0378@linux.intel.com> (raw)
In-Reply-To: <sashiko-outbox-172095@kernel.org>
On 10/15/2026 9:31 AM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] virt/coco/tdx-host: desynchronized host/hardware state on xa_insert failure
> --
>
> commit 83cda44603ec97cb10640905999d9a617eced100
> Author: Lu Baolu <baolu.lu@linux.intel.com>
>
> coco/tdx-host: Initialize trusted DMA on all capable IOMMUs
>
> Assigning a device to a TD for private memory access requires that DMA
> from that device be translated by structures the TDX module controls.
> An Intel IOMMU that implements the trusted DMA extension provides a
> parallel set of translation and invalidation resources for this purpose.
>
>> diff --git a/drivers/virt/coco/tdx-host/iommu.c b/drivers/virt/coco/tdx-host/iommu.c
>> new file mode 100644
>> index 0000000000000..a80e57bf26a12
>> --- /dev/null
>> +++ b/drivers/virt/coco/tdx-host/iommu.c
> [ ... ]
>> +static int tdx_iommu_setup(struct dmar_drhd_unit *drhd)
>> +{
> [ ... ]
>> + state = no_free_ptr(iommu_state);
>> + state->drhd = drhd;
>> + state->tdx_iommu_id = tdx_iommu_id;
>> + state->mt_pages = no_free_ptr(iommu_mt);
>> + ret = xa_insert(&tdx_iommu_xa, (unsigned long)tdx_iommu_id, state, GFP_KERNEL);
>> + if (ret) {
>> + WARN_ON(tdx_iommu_clear(state));
>> + kfree(state);
>> + return ret;
>> + }
>
> [Severity: High]
> If xa_insert() fails and tdx_iommu_clear(state) also fails, this code
> unconditionally frees state and returns an error. Does this leave the
> hardware state desynchronized?
>
> When this function returns an error, the caller dmar_tdxcs_iommu_init_all() in
> drivers/iommu/intel/dmar.c restores iommu->max_domain_id to its full un-halved
> range and leaves drhd->tdx_mode = false:
>
> ret = setup(drhd);
> ...
> if (ret) {
> scoped_guard(mutex, &iommu->did_lock)
> iommu->max_domain_id = ndoms;
> ...
> return ret;
> }
>
> Because tdx_iommu_clear() failed, the physical hardware is permanently left in
> Secure TDX Mode, but the software state now believes it is not. Will this
> cause hardware faults or fatal domain ID conflicts when the host attempts to
> use domain IDs that now belong exclusively to TDX?
>
> Unlike tdx_iommu_disable_all() which safely detects a clear failure and leaves
> tdx_mode true to confine the host to the lower half of the DID space, this
> error path completely loses track of the hardware state, breaking isolation.
That's correct in theory, but I don't think the extra complexity is
worth it here.
The path needs two independent failures happening together:
- xa_insert() has to fail. In practice that means a small GFP_KERNEL
allocation failing, or the TDX module returning a duplicate
tdx_iommu_id, which would be a TDX module bug.
- TDH.IOMMU.CLEAR then has to fail on an IOMMU the TDX module set up
successfully moments earlier, with nothing in between.
If both happen, the system is already badly broken, and the WARN_ON()
makes it loud. Adding more tracking just for this case would complicate
the code without making a working system more robust.
Thanks,
baolu
prev parent reply other threads:[~2026-10-15 5:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 1:07 [PATCH v2 0/4] coco/tdx-host: Introduce trusted DMA initialization support Lu Baolu
2026-10-15 1:07 ` [PATCH v2 1/4] x86/virt/tdx: Add SEAMCALL wrappers for IOMMU setup/clear Lu Baolu
2026-10-15 1:28 ` sashiko-bot
2026-10-15 5:36 ` Baolu Lu
2026-10-15 6:34 ` Xu Yilun
2026-10-15 1:07 ` [PATCH v2 2/4] x86/virt/tdx: Read global metadata for trusted IOMMU Lu Baolu
2026-10-15 6:47 ` Xu Yilun
2026-10-15 1:07 ` [PATCH v2 3/4] iommu/vt-d: Add an API for tdx-host when enabling trusted DMA Lu Baolu
2026-10-15 1:07 ` [PATCH v2 4/4] coco/tdx-host: Initialize trusted DMA on all capable IOMMUs Lu Baolu
2026-10-15 1:31 ` sashiko-bot
2026-10-15 5:58 ` Baolu Lu [this message]
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=a4f077a0-8b34-4eae-b5a0-567c706d0378@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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