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>, <ashish.kalra@amd.com>,
<robin.murphy@arm.com>, <will@kernel.org>,
Sairaj Kodilkar <sarunkod@amd.com>
Subject: [PATCH 1/2] amd/iommu: Preserve domain ids inside the kdump kernel
Date: Fri, 14 Nov 2025 16:14:41 +0530 [thread overview]
Message-ID: <20251114104442.23296-2-sarunkod@amd.com> (raw)
In-Reply-To: <20251114104442.23296-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>
---
drivers/iommu/amd/init.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index f2991c11867c..9375fba1071c 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,25 @@ 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 = old_dev_tbl_entry->data[0] & DTE_FLAG_V;
+ dom_id = old_dev_tbl_entry->data[1] & DEV_DOMID_MASK;
+
+ if (!dte_v || !dom_id)
+ continue;
+ /*
+ * ID reseveration 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_ATOMIC);
+ if (ret == -ENOMEM) {
+ pr_err("Failed to reserve domain ID 0x%x\n", dom_id);
+ return false;
+ }
+ }
+
return true;
}
--
2.34.1
next prev parent reply other threads:[~2025-11-14 10:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 10:44 [PATCH 0/2] amd/iommu: Preserve domain ids inside the kdump kernel Sairaj Kodilkar
2025-11-14 10:44 ` Sairaj Kodilkar [this message]
2025-11-17 5:21 ` [PATCH 1/2] " Ankit Soni
2025-11-19 10:50 ` Vasant Hegde
2025-11-19 13:43 ` Jason Gunthorpe
2025-11-20 5:02 ` Sairaj Kodilkar
2025-11-20 12:56 ` Jason Gunthorpe
2025-11-21 5:21 ` Sairaj Kodilkar
2025-11-20 6:22 ` Vasant Hegde
2025-11-20 6:56 ` Vasant Hegde
2025-11-14 10:44 ` [PATCH 2/2] amd/iommu: Make protection domain ID functions non-static Sairaj Kodilkar
2025-11-19 10:47 ` Vasant Hegde
2025-11-19 13:47 ` Jason Gunthorpe
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=20251114104442.23296-2-sarunkod@amd.com \
--to=sarunkod@amd.com \
--cc=ashish.kalra@amd.com \
--cc=iommu@lists.linux.dev \
--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