From: Sairaj Kodilkar <sarunkod@amd.com>
To: <iommu@lists.linux.dev>, <linux-kernel@vger.kernel.org>
Cc: <joro@8bytes.org>, <suravee.suthikulpanit@amd.com>,
<vasant.hegde@amd.com>, <robin.murphy@arm.com>,
<ashish.kalra@amd.com>, <will@kernel.org>, <jgg@nvidia.com>,
Sairaj Kodilkar <sarunkod@amd.com>
Subject: [PATCH v2 1/2] amd/iommu: Preserve domain ids inside the kdump kernel
Date: Fri, 21 Nov 2025 14:41:15 +0530 [thread overview]
Message-ID: <20251121091116.25663-2-sarunkod@amd.com> (raw)
In-Reply-To: <20251121091116.25663-1-sarunkod@amd.com>
Currently AMD IOMMU driver does not reserve domain ids programmed in the
DTE while reusing the device table inside kdump kernel. This can cause
reallocation of these domain ids for newer domains that are created by
the kdump kernel, which can lead to potential IO_PAGE_FAULTs
Hence reserve these ids inside pdom_ids.
Fixes: 38e5f33ee359 ("iommu/amd: Reuse device table for kdump")
Signed-off-by: Sairaj Kodilkar <sarunkod@amd.com>
Reported-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
---
drivers/iommu/amd/init.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index f2991c11867c..14eb9de33ccb 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -1136,9 +1136,13 @@ static void set_dte_bit(struct dev_table_entry *dte, u8 bit)
static bool __reuse_device_table(struct amd_iommu *iommu)
{
struct amd_iommu_pci_seg *pci_seg = iommu->pci_seg;
- u32 lo, hi, old_devtb_size;
+ struct dev_table_entry *old_dev_tbl_entry;
+ u32 lo, hi, old_devtb_size, devid;
phys_addr_t old_devtb_phys;
+ u16 dom_id;
+ bool dte_v;
u64 entry;
+ int ret;
/* Each IOMMU use separate device table with the same size */
lo = readl(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET);
@@ -1173,6 +1177,23 @@ static bool __reuse_device_table(struct amd_iommu *iommu)
return false;
}
+ for (devid = 0; devid <= pci_seg->last_bdf; devid++) {
+ old_dev_tbl_entry = &pci_seg->old_dev_tbl_cpy[devid];
+ dte_v = FIELD_GET(DTE_FLAG_V, old_dev_tbl_entry->data[0]);
+ dom_id = FIELD_GET(DEV_DOMID_MASK, old_dev_tbl_entry->data[1]);
+
+ if (!dte_v || !dom_id)
+ continue;
+ /*
+ * ID reservation can fail with -ENOSPC when there
+ * are multiple devices present in the same domain,
+ * hence check only for -ENOMEM.
+ */
+ ret = ida_alloc_range(&pdom_ids, dom_id, dom_id, GFP_KERNEL);
+ if (ret == -ENOMEM)
+ return false;
+ }
+
return true;
}
--
2.34.1
next prev parent reply other threads:[~2025-11-21 9:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-21 9:11 [PATCH v2 0/2] amd/iommu: Preserve domain ids inside the kdump kernel Sairaj Kodilkar
2025-11-21 9:11 ` Sairaj Kodilkar [this message]
2025-11-24 14:44 ` [PATCH v2 1/2] " Jason Gunthorpe
2025-11-25 6:32 ` Sairaj Kodilkar
2025-11-26 8:21 ` Vasant Hegde
2025-11-26 15:20 ` Jason Gunthorpe
2025-12-02 5:21 ` Vasant Hegde
2025-11-21 9:11 ` [PATCH v2 2/2] amd/iommu: Make protection domain ID functions non-static Sairaj Kodilkar
2025-12-02 5:23 ` [PATCH v2 0/2] amd/iommu: Preserve domain ids inside the kdump kernel Vasant Hegde
2025-12-19 10:29 ` Joerg Roedel
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=20251121091116.25663-2-sarunkod@amd.com \
--to=sarunkod@amd.com \
--cc=ashish.kalra@amd.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=vasant.hegde@amd.com \
--cc=will@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