* [PATCH v2 04/12] iommu/amd: Restore an SVA PASID after PCI reset
[not found] <20261127115447.209792-1-vasant.hegde@amd.com>
@ 2026-11-27 11:54 ` Vasant Hegde
2026-11-27 11:54 ` [PATCH v2 05/12] iommu/amd: Keep the GCR3 table while PASIDs are attached Vasant Hegde
1 sibling, 0 replies; 2+ messages in thread
From: Vasant Hegde @ 2026-11-27 11:54 UTC (permalink / raw)
To: iommu, joro
Cc: will, robin.murphy, suravee.suthikulpanit, jgg, Santosh Shukla,
stable, Vasant Hegde
From: Santosh Shukla <santosh.shukla@amd.com>
pci_dev_reset_iommu_done() re-attaches every PASID with old set to the
group's blocking domain. iommu_sva_set_dev_pasid() rejects any old
domain, so the core warns and the PASID stays unprogrammed until the
device is unbound.
prepare() has already cleared the GCR3 entry and dropped the SVA
tracking record. A blocking old domain is therefore a fresh attach.
Replacing one attached domain with another still returns -EOPNOTSUPP.
Fixes: c279e83953d9 ("iommu: Introduce pci_dev_reset_iommu_prepare/done()")
Signed-off-by: Santosh Shukla <santosh.shukla@amd.com>
Cc: stable@vger.kernel.org
[Updated description - Vasant]
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
---
drivers/iommu/amd/pasid.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/amd/pasid.c b/drivers/iommu/amd/pasid.c
index 40be5902087c..87fd2688574c 100644
--- a/drivers/iommu/amd/pasid.c
+++ b/drivers/iommu/amd/pasid.c
@@ -109,7 +109,12 @@ static int iommu_sva_set_dev_pasid(struct iommu_domain *domain,
unsigned long flags;
int ret = -EINVAL;
- if (old)
+ /*
+ * pci_dev_reset_iommu_done() passes the blocking domain. prepare()
+ * has already cleared this PASID, so program it again. Replacing
+ * one attached domain with another is not supported.
+ */
+ if (old && old->type != IOMMU_DOMAIN_BLOCKED)
return -EOPNOTSUPP;
/* PASID zero is used for requests from the I/O device without PASID */
--
2.31.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH v2 05/12] iommu/amd: Keep the GCR3 table while PASIDs are attached
[not found] <20261127115447.209792-1-vasant.hegde@amd.com>
2026-11-27 11:54 ` [PATCH v2 04/12] iommu/amd: Restore an SVA PASID after PCI reset Vasant Hegde
@ 2026-11-27 11:54 ` Vasant Hegde
1 sibling, 0 replies; 2+ messages in thread
From: Vasant Hegde @ 2026-11-27 11:54 UTC (permalink / raw)
To: iommu, joro
Cc: will, robin.murphy, suravee.suthikulpanit, jgg, Vasant Hegde,
stable, Santosh Shukla
pci_dev_reset_iommu_prepare() attaches the blocked domain before clearing
the device's PASIDs. detach_device() frees the GCR3 table during that
transition, so a later amd_iommu_clear_gcr3() dereferences a NULL root.
Do not free the GCR3 table while it still has attached PASIDs. The RID
GCR3[0] entry is still cleared before detach, and setup_gcr3_table()
reuses the retained table on re-attach. Free it from
amd_iommu_release_device() instead, after the blocked-domain attach has
cleared the DTE.
Fixes: c9e8701132e6 ("iommu/amd: Setup GCR3 table in advance if domain is SVA capable")
Cc: stable@vger.kernel.org
Reported-by: Santosh Shukla <santosh.shukla@amd.com>
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
---
drivers/iommu/amd/iommu.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 0a1722110934..9c32dcb921f3 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -1949,12 +1949,12 @@ static int setup_gcr3_table(struct gcr3_tbl_info *gcr3_info,
int nid = iommu ? dev_to_node(&iommu->dev->dev) : NUMA_NO_NODE;
int domid;
+ if (gcr3_info->gcr3_tbl)
+ return 0;
+
if (levels > amd_iommu_max_glx_val)
return -EINVAL;
- if (gcr3_info->gcr3_tbl)
- return -EBUSY;
-
/* Allocate per device domain ID */
domid = amd_iommu_pdom_id_alloc();
if (domid <= 0)
@@ -2247,7 +2247,7 @@ static void destroy_gcr3_table(struct iommu_dev_data *dev_data,
if (pdom_is_v2_pgtbl_mode(pdom))
update_gcr3(dev_data, 0, 0, false);
- if (gcr3_info->gcr3_tbl == NULL)
+ if (gcr3_info->gcr3_tbl == NULL || gcr3_info->pasid_cnt)
return;
free_gcr3_table(gcr3_info);
@@ -2523,6 +2523,21 @@ static struct iommu_device *amd_iommu_probe_device(struct device *dev)
return iommu_dev;
}
+static void amd_iommu_release_device(struct device *dev)
+{
+ struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev);
+
+ /*
+ * A device that requires direct mappings is released to the identity
+ * domain, whose DTE can still point at the GCR3 table. Keep the table
+ * in that case; a later probe reuses it.
+ */
+ if (dev_data->domain)
+ return;
+
+ destroy_gcr3_table(dev_data, NULL);
+}
+
static struct iommu_group *amd_iommu_device_group(struct device *dev)
{
if (dev_is_pci(dev))
@@ -3227,6 +3242,7 @@ const struct iommu_ops amd_iommu_ops = {
.domain_alloc_paging_flags = amd_iommu_domain_alloc_paging_flags,
.domain_alloc_sva = amd_iommu_domain_alloc_sva,
.probe_device = amd_iommu_probe_device,
+ .release_device = amd_iommu_release_device,
.device_group = amd_iommu_device_group,
.get_resv_regions = amd_iommu_get_resv_regions,
.is_attach_deferred = amd_iommu_is_attach_deferred,
--
2.31.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-27 11:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261127115447.209792-1-vasant.hegde@amd.com>
2026-11-27 11:54 ` [PATCH v2 04/12] iommu/amd: Restore an SVA PASID after PCI reset Vasant Hegde
2026-11-27 11:54 ` [PATCH v2 05/12] iommu/amd: Keep the GCR3 table while PASIDs are attached Vasant Hegde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox