From: Nicolin Chen <nicolinc@nvidia.com>
To: <will@kernel.org>, <jgg@nvidia.com>
Cc: <robin.murphy@arm.com>, <joro@8bytes.org>, <praan@google.com>,
<kevin.tian@intel.com>, <smostafa@google.com>,
<linux-arm-kernel@lists.infradead.org>, <iommu@lists.linux.dev>,
<linux-kernel@vger.kernel.org>, <jamien@nvidia.com>,
<kas@kernel.org>, Cristian Prundeanu <cpru@amazon.com>,
Breno Leitao <leitao@kernel.org>, <xueshuai@linux.alibaba.com>,
<john.garry@arm.com>
Subject: [PATCH v12 01/12] iommu: Pass in NULL old_domain when attaching a deferred device
Date: Sun, 1 Nov 2026 21:19:09 -0800 [thread overview]
Message-ID: <963f674b92f28548e03d6fa83a950e93d81ca3de.1793593923.git.nicolinc@nvidia.com> (raw)
In-Reply-To: <cover.1793593923.git.nicolinc@nvidia.com>
When a driver defers the default domain attachment of a device, the IOMMU
core skips the attachment in __iommu_device_set_domain() but still sets the
group->domain to the group->default_domain. Since the driver has not seen
this attachment, iommu_deferred_attach() later finalizes it by passing in a
NULL old_domain.
However, two other paths pass in the group->domain as the old_domain for a
deferred device:
- __iommu_device_set_domain(), when attaching a non-default domain
- pci_dev_reset_iommu_prepare(), when attaching the group->blocking_domain
A driver uses the given old_domain to clean up the device's state in that
domain. However, a deferred device has no state in the group->domain, since
the driver has never attached the device to it. So, the driver would end up
cleaning up a state that does not exist.
In practice, the first path is unlikely, since it requires the device to be
attached to a non-default domain before its first DMA mapping. The second
path is reachable when an ATS supported device gets reset before its first
DMA mapping.
Pass in a NULL old_domain on both paths for a deferred device.
Note that pci_dev_reset_iommu_done() can keep using the group->domain for
recovering the device, because pci_dev_reset_iommu_prepare() has unset the
attach_deferred flag.
This will be needed for the SMMUv3 driver to support the kdump mode, where
it relies on the given old_domain to unreference the invalidation entries
of a master.
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
drivers/iommu/iommu.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index b486b8bbd1fcd..4585ffa9a73c9 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2420,6 +2420,8 @@ static int __iommu_device_set_domain(struct iommu_group *group,
if (new_domain == group->default_domain)
return 0;
dev->iommu->attach_deferred = 0;
+ /* The driver has never attached the device to old_domain */
+ old_domain = NULL;
}
ret = __iommu_attach_device(new_domain, dev, old_domain);
@@ -4059,8 +4061,13 @@ int pci_dev_reset_iommu_prepare(struct pci_dev *pdev)
/* Stage RID domain at blocking_domain while retaining group->domain */
if (group->domain != group->blocking_domain) {
+ struct iommu_domain *old_domain = group->domain;
+
+ /* The driver has never attached a deferred device */
+ if (pdev->dev.iommu->attach_deferred)
+ old_domain = NULL;
ret = __iommu_attach_device(group->blocking_domain, &pdev->dev,
- group->domain);
+ old_domain);
if (ret) {
gdev->reset_depth--;
return ret;
--
2.43.0
next prev parent reply other threads:[~2026-11-02 5:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 5:19 [PATCH v12 00/12] iommu/arm-smmu-v3: Adopt the crashed kernel's stream table for kdump Nicolin Chen
2026-11-02 5:19 ` Nicolin Chen [this message]
2026-11-02 5:19 ` [PATCH v12 02/12] iommu/arm-smmu-v3: Init the vmid_map ida before the stream table setup Nicolin Chen
2026-11-02 5:19 ` [PATCH v12 03/12] iommu/arm-smmu-v3: Make the ASID space per SMMU instance Nicolin Chen
2026-11-02 5:19 ` [PATCH v12 04/12] iommu/arm-smmu-v3: Pack the MSI vectors of the used sources Nicolin Chen
2026-11-02 5:19 ` [PATCH v12 05/12] iommu/arm-smmu-v3: Add ARM_SMMU_FEAT_EVTQ for the event queue Nicolin Chen
2026-11-02 5:19 ` [PATCH v12 06/12] iommu/arm-smmu-v3: Disable the EVTQ and the PRIQ in a kdump kernel Nicolin Chen
2026-11-02 5:19 ` [PATCH v12 07/12] iommu/arm-smmu-v3: Add ARM_SMMU_OPT_KDUMP_ADOPT for " Nicolin Chen
2026-11-02 5:19 ` [PATCH v12 08/12] iommu/arm-smmu-v3-kexec: Reserve crashed kernel's ASIDs and VMIDs Nicolin Chen
2026-11-02 5:19 ` [PATCH v12 09/12] iommu/arm-smmu-v3-kexec: Implement is_attach_deferred() Nicolin Chen
2026-11-02 5:19 ` [PATCH v12 10/12] iommu/arm-smmu-v3: Retain CR0_SMMUEN during kdump device reset Nicolin Chen
2026-11-02 5:19 ` [PATCH v12 11/12] iommu/arm-smmu-v3: Skip RMR bypass for kdump adoption Nicolin Chen
2026-11-02 5:19 ` [PATCH v12 12/12] iommu/arm-smmu-v3: Detect ARM_SMMU_OPT_KDUMP_ADOPT in probe() Nicolin Chen
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=963f674b92f28548e03d6fa83a950e93d81ca3de.1793593923.git.nicolinc@nvidia.com \
--to=nicolinc@nvidia.com \
--cc=cpru@amazon.com \
--cc=iommu@lists.linux.dev \
--cc=jamien@nvidia.com \
--cc=jgg@nvidia.com \
--cc=john.garry@arm.com \
--cc=joro@8bytes.org \
--cc=kas@kernel.org \
--cc=kevin.tian@intel.com \
--cc=leitao@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=praan@google.com \
--cc=robin.murphy@arm.com \
--cc=smostafa@google.com \
--cc=will@kernel.org \
--cc=xueshuai@linux.alibaba.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®