From: Sairaj Kodilkar <sarunkod@amd.com>
To: "Joerg Roedel (AMD)" <joro@8bytes.org>,
Adrian Huang <ahuang12@lenovo.com>,
Joerg Roedel <jroedel@suse.de>,
Robin Murphy <robin.murphy@arm.com>,
Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
Vasant Hegde <vasant.hegde@amd.com>,
"Will Deacon" <will@kernel.org>, <iommu@lists.linux.dev>,
<linux-kernel@vger.kernel.org>
Cc: Baoquan He <bhe@redhat.com>,
Jerry Snitselaar <jsnitsel@redhat.com>,
Sairaj Kodilkar <sarunkod@amd.com>,
Adam Pelka <adampelka26@gmail.com>
Subject: [PATCH v3 2/3] iommu/amd: Do not convert IVMD exclusion range to unity range
Date: Fri, 6 Nov 2026 09:46:49 +0530 [thread overview]
Message-ID: <20261106041650.24076-3-sarunkod@amd.com> (raw)
In-Reply-To: <20261106041650.24076-1-sarunkod@amd.com>
From: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Original problem was there could be multiple IVMD exclusion entries
conflicting over a single exclusion range supported in older Linux
kernel. The fix was first introduced in commit 387caf0b759a ("iommu/amd:
Treat per-device exclusion ranges as r/w unity-mapped regions") and in
commit 0bbe4ced53e3 ("iommu/amd: Fix the overwritten field in IVMD header")
, where IVMD exclusions are converted to separate unity_map_entry objects
in pci_seg->unity_map so amd_iommu_get_resv_regions() treated every such
entry as IOMMU_RESV_DIRECT with R/W.
The driver no longer programs the exclusion base/limit registers and
relies on the kernel to keep the IOVA ranges named by exclusion IVMDs
unmapped. Stop forcing exclusion entries to RW-unity. Store the raw
IVMD flags in struct unity_map_entry instead of a pre-shifted
protection value, and derive the reserved region from those flags.
Exclusion entries are now reported as IOMMU_RESV_RESERVED with no
read/write permission.
Reject unity entries that grant neither IR nor IW with a FW_BUG
message, and warn about invalid flag combinations and unknown flag bits
Fixes: 0bbe4ced53e3 ("iommu/amd: Fix the overwritten field in IVMD header")
Cc: Baoquan He <bhe@redhat.com>
Cc: Adrian Huang <ahuang12@lenovo.com>
Cc: Jerry Snitselaar <jsnitsel@redhat.com>
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Signed-off-by: Sairaj Kodilkar <sarunkod@amd.com>
Reviewed-by: Adrian Huang <ahuang12@lenovo.com>
Tested-by: Adam Pelka <adampelka26@gmail.com>
---
drivers/iommu/amd/amd_iommu_types.h | 12 +++++++-----
drivers/iommu/amd/init.c | 26 +++++++++-----------------
drivers/iommu/amd/iommu.c | 21 +++++++++++++++++++--
3 files changed, 35 insertions(+), 24 deletions(-)
diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
index 678ceddd711c..bcb88b476167 100644
--- a/drivers/iommu/amd/amd_iommu_types.h
+++ b/drivers/iommu/amd/amd_iommu_types.h
@@ -368,9 +368,11 @@
/* DTE[128:179] | DTE[184:191] */
#define DTE_DATA2_INTR_MASK ~GENMASK_ULL(55, 52)
-#define IOMMU_PROT_MASK 0x03
-#define IOMMU_PROT_IR 0x01
-#define IOMMU_PROT_IW 0x02
+#define IVMD_FLAG_UNITY BIT(0)
+#define IVMD_FLAG_IR BIT(1)
+#define IVMD_FLAG_IW BIT(2)
+#define IVMD_FLAG_EXCL BIT(3)
+#define IVMD_FLAG_MASK GENMASK_U32(3, 0)
/* IOMMU capabilities */
#define IOMMU_CAP_IOTLB 24
@@ -880,8 +882,8 @@ struct unity_map_entry {
/* end address to unity map (including) */
u64 address_end;
- /* required protection */
- int prot;
+ /* IVMD flags for the entry */
+ u8 flags;
};
/*
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index 13c96feed64f..1f0ca675df1c 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -70,11 +70,6 @@
#define IVHD_FLAG_RESPASSPW_EN_MASK 0x04
#define IVHD_FLAG_ISOC_EN_MASK 0x08
-#define IVMD_FLAG_EXCL_RANGE 0x08
-#define IVMD_FLAG_IW 0x04
-#define IVMD_FLAG_IR 0x02
-#define IVMD_FLAG_UNITY_MAP 0x01
-
#define ACPI_DEVFLAG_INITPASS 0x01
#define ACPI_DEVFLAG_EXTINT 0x02
#define ACPI_DEVFLAG_NMI 0x04
@@ -2636,6 +2631,13 @@ static int __init init_unity_map_range(struct ivmd_header *m,
struct amd_iommu_pci_seg *pci_seg;
char *s;
+ if ((m->flags & IVMD_FLAG_UNITY) &&
+ !(m->flags & (IVMD_FLAG_IR | IVMD_FLAG_IW | IVMD_FLAG_EXCL))) {
+ pr_err(FW_BUG "IVMD type %#x devid %#x range %#llx+%#llx: Unity set without IR/IW, ignoring\n",
+ m->type, m->devid, m->range_start, m->range_length);
+ return -EINVAL;
+ }
+
pci_seg = get_pci_segment(m->pci_seg, ivrs_base);
if (pci_seg == NULL)
return -ENOMEM;
@@ -2665,17 +2667,7 @@ static int __init init_unity_map_range(struct ivmd_header *m,
}
e->address_start = PAGE_ALIGN(m->range_start);
e->address_end = e->address_start + PAGE_ALIGN(m->range_length);
- e->prot = m->flags >> 1;
-
- /*
- * Treat per-device exclusion ranges as r/w unity-mapped regions
- * since some buggy BIOSes might lead to the overwritten exclusion
- * range (exclusion_start and exclusion_length members). This
- * happens when there are multiple exclusion ranges (IVMD entries)
- * defined in ACPI table.
- */
- if (m->flags & IVMD_FLAG_EXCL_RANGE)
- e->prot = (IVMD_FLAG_IW | IVMD_FLAG_IR) >> 1;
+ e->flags = m->flags;
DUMP_printk("%s devid_start: %04x:%02x:%02x.%x devid_end: "
"%04x:%02x:%02x.%x range_start: %016llx range_end: %016llx"
@@ -2702,7 +2694,7 @@ static int __init init_memory_definitions(struct acpi_table_header *table)
while (p < end) {
m = (struct ivmd_header *)p;
- if (m->flags & (IVMD_FLAG_UNITY_MAP | IVMD_FLAG_EXCL_RANGE))
+ if (m->flags & (IVMD_FLAG_UNITY | IVMD_FLAG_EXCL))
init_unity_map_range(m, table);
p += m->length;
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 56262f6b1f70..699b5f530f11 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -3120,12 +3120,29 @@ static void amd_iommu_get_resv_regions(struct device *dev,
if (devid < entry->devid_start || devid > entry->devid_end)
continue;
+ /*
+ * IVMD_FLAG_UNITY, IVMD_FLAG_IR, IVMD_FLAG_IW are ignored if
+ * IVMD_FLAG_EXCL is set.
+ */
+ if ((entry->flags & IVMD_FLAG_EXCL) &&
+ (entry->flags & (IVMD_FLAG_UNITY | IVMD_FLAG_IR | IVMD_FLAG_IW)))
+ pr_err(FW_BUG "%s: Invalid IVMD flags combination: %#02x for sbdf=%#x. Ignore IW/IR/Unity flags\n",
+ __func__, entry->flags, sbdf);
+
+ if (entry->flags & ~IVMD_FLAG_MASK)
+ pr_err("%s: Unknown flags: %#02x for sbdf=%#x\n",
+ __func__, entry->flags & ~IVMD_FLAG_MASK, sbdf);
+
type = IOMMU_RESV_DIRECT;
length = entry->address_end - entry->address_start;
- if (entry->prot & IOMMU_PROT_IR)
+ if (entry->flags & IVMD_FLAG_IR)
prot |= IOMMU_READ;
- if (entry->prot & IOMMU_PROT_IW)
+ if (entry->flags & IVMD_FLAG_IW)
prot |= IOMMU_WRITE;
+ if (entry->flags & IVMD_FLAG_EXCL) {
+ type = IOMMU_RESV_RESERVED;
+ prot = 0;
+ }
region = iommu_alloc_resv_region(entry->address_start,
length, prot, type,
--
2.34.1
next prev parent reply other threads:[~2026-11-06 4:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 4:16 [PATCH v3 0/3] iommu/amd: IVMD handling cleanup and ivmd= boot override Sairaj Kodilkar
2026-11-06 4:16 ` [PATCH v3 1/3] iommu/amd: Drop unused global exclusion range fields and init Sairaj Kodilkar
2026-11-06 8:45 ` Jindal, Akshay
2026-11-06 4:16 ` Sairaj Kodilkar [this message]
2026-11-06 10:02 ` [PATCH v3 2/3] iommu/amd: Do not convert IVMD exclusion range to unity range Jindal, Akshay
2026-11-06 4:16 ` [PATCH v3 3/3] iommu/amd: Rename unity_map_entry and unit_map to ivmd_entry and ivhd_entry_map Sairaj Kodilkar
2026-11-06 10:15 ` Jindal, Akshay
2026-11-06 8:34 ` [PATCH v3 0/3] iommu/amd: IVMD handling cleanup and ivmd= boot override Jindal, Akshay
2026-11-06 8:36 ` Sairaj Kodilkar
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=20261106041650.24076-3-sarunkod@amd.com \
--to=sarunkod@amd.com \
--cc=adampelka26@gmail.com \
--cc=ahuang12@lenovo.com \
--cc=bhe@redhat.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=jroedel@suse.de \
--cc=jsnitsel@redhat.com \
--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
all inboxes | Powered by JetHome®