* [PATCH v5 1/3] iommu/amd: Rename exclusion range base and limit macros
2026-11-27 10:04 [PATCH v5 0/3] iommu/amd: IVMD handling cleanup and ivmd= boot override Sairaj Kodilkar
@ 2026-11-27 10:04 ` Sairaj Kodilkar
2026-11-27 10:04 ` [PATCH v5 2/3] iommu/amd: Do not convert IVMD exclusion range to unity range Sairaj Kodilkar
2026-11-27 10:04 ` [PATCH v5 3/3] iommu/amd: Rename unity_map symbols to ivmd_entry Sairaj Kodilkar
2 siblings, 0 replies; 7+ messages in thread
From: Sairaj Kodilkar @ 2026-11-27 10:04 UTC (permalink / raw)
To: Joerg Roedel (AMD), Adrian Huang, Joerg Roedel, Robin Murphy,
Suravee Suthikulpanit, Vasant Hegde, Will Deacon, iommu
Cc: Vasant.Hegde, Suravee.Suthikulpanit, Sairaj Kodilkar,
Akshay Jindal
From: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
The exclusion range registers have been repurposed to SNP completion-wait
store base / limit registers. So, rename MMIO_EXCL_BASE/LIMIT via to
MMIO_COMPL_STORE_BASE/LIMIT instead.
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Signed-off-by: Sairaj Kodilkar <sarunkod@amd.com>
Reviewed-by: Akshay Jindal <Akshay.Jindal@amd.com>
---
drivers/iommu/amd/amd_iommu_types.h | 4 ++--
drivers/iommu/amd/init.c | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
index f98770db0090..d1602144c160 100644
--- a/drivers/iommu/amd/amd_iommu_types.h
+++ b/drivers/iommu/amd/amd_iommu_types.h
@@ -44,8 +44,8 @@
#define MMIO_CMD_BUF_OFFSET 0x0008
#define MMIO_EVT_BUF_OFFSET 0x0010
#define MMIO_CONTROL_OFFSET 0x0018
-#define MMIO_EXCL_BASE_OFFSET 0x0020
-#define MMIO_EXCL_LIMIT_OFFSET 0x0028
+#define MMIO_COMPL_STORE_BASE_OFFSET 0x0020
+#define MMIO_COMPL_STORE_LIMIT_OFFSET 0x0028
#define MMIO_EXT_FEATURES 0x0030
#define MMIO_PPR_LOG_OFFSET 0x0038
#define MMIO_GA_LOG_BASE_OFFSET 0x00e0
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index 58f63298493b..f8cf37a471f8 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -369,14 +369,14 @@ static void iommu_set_cwwb_range(struct amd_iommu *iommu)
* Re-purpose Exclusion base/limit registers for Completion wait
* write-back base/limit.
*/
- memcpy_toio(iommu->mmio_base + MMIO_EXCL_BASE_OFFSET,
+ memcpy_toio(iommu->mmio_base + MMIO_COMPL_STORE_BASE_OFFSET,
&entry, sizeof(entry));
/* Note:
* Default to 4 Kbytes, which can be specified by setting base
* address equal to the limit address.
*/
- memcpy_toio(iommu->mmio_base + MMIO_EXCL_LIMIT_OFFSET,
+ memcpy_toio(iommu->mmio_base + MMIO_COMPL_STORE_LIMIT_OFFSET,
&entry, sizeof(entry));
}
@@ -1071,7 +1071,7 @@ static int __init remap_or_alloc_cwwb_sem(struct amd_iommu *iommu)
* completion wait buffer (CWB) address. Read and re-use it.
*/
pr_info_once("Re-using CWB buffers from the previous kernel\n");
- paddr = readq(iommu->mmio_base + MMIO_EXCL_BASE_OFFSET) & PM_ADDR_MASK;
+ paddr = readq(iommu->mmio_base + MMIO_COMPL_STORE_BASE_OFFSET) & PM_ADDR_MASK;
iommu->cmd_sem = iommu_memremap(paddr, PAGE_SIZE);
if (!iommu->cmd_sem)
return -ENOMEM;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v5 2/3] iommu/amd: Do not convert IVMD exclusion range to unity range
2026-11-27 10:04 [PATCH v5 0/3] iommu/amd: IVMD handling cleanup and ivmd= boot override Sairaj Kodilkar
2026-11-27 10:04 ` [PATCH v5 1/3] iommu/amd: Rename exclusion range base and limit macros Sairaj Kodilkar
@ 2026-11-27 10:04 ` Sairaj Kodilkar
2026-12-01 8:50 ` Vasant Hegde
2026-11-27 10:04 ` [PATCH v5 3/3] iommu/amd: Rename unity_map symbols to ivmd_entry Sairaj Kodilkar
2 siblings, 1 reply; 7+ messages in thread
From: Sairaj Kodilkar @ 2026-11-27 10:04 UTC (permalink / raw)
To: Joerg Roedel (AMD), Adrian Huang, Joerg Roedel, Robin Murphy,
Suravee Suthikulpanit, Vasant Hegde, Will Deacon, iommu
Cc: Vasant.Hegde, Suravee.Suthikulpanit, Baoquan He, Jerry Snitselaar,
Sairaj Kodilkar
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 entries with unknown flag bits. Warn about invalid flag
combinations.
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>
---
drivers/iommu/amd/amd_iommu_types.h | 12 ++++++----
drivers/iommu/amd/init.c | 36 ++++++++++++++++-------------
drivers/iommu/amd/iommu.c | 24 +++++++++++++++++--
3 files changed, 49 insertions(+), 23 deletions(-)
diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
index d1602144c160..0f4c3c65188c 100644
--- a/drivers/iommu/amd/amd_iommu_types.h
+++ b/drivers/iommu/amd/amd_iommu_types.h
@@ -371,9 +371,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_MAP BIT(0)
+#define IVMD_FLAG_IR BIT(1)
+#define IVMD_FLAG_IW BIT(2)
+#define IVMD_FLAG_EXCL_RANGE BIT(3)
+#define IVMD_FLAG_MASK GENMASK_U32(3, 0)
/* IOMMU capabilities */
#define IOMMU_CAP_IOTLB 24
@@ -890,8 +892,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 f8cf37a471f8..6d92fb5c81a7 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
@@ -2742,6 +2737,25 @@ 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_MASK) {
+ pr_err(FW_BUG "IVMD type %#x devid %#x range %#llx+%#llx: Unknown flags\n",
+ m->type, m->devid, m->range_start, m->range_length);
+ return -EINVAL;
+ }
+
+ if ((m->flags & IVMD_FLAG_UNITY_MAP) &&
+ !(m->flags & (IVMD_FLAG_IR | IVMD_FLAG_IW))) {
+ 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;
+ }
+
+ if ((m->flags & IVMD_FLAG_EXCL_RANGE) &&
+ (m->flags & (IVMD_FLAG_UNITY_MAP | IVMD_FLAG_IR | IVMD_FLAG_IW))) {
+ pr_err(FW_BUG "IVMD type %#x devid %#x range %#llx+%#llx: Invalid IVMD flag combination %#x\n",
+ m->type, m->devid, m->range_start, m->range_length, m->flags);
+ }
+
pci_seg = get_pci_segment(m->pci_seg, ivrs_base);
if (pci_seg == NULL)
return -ENOMEM;
@@ -2771,17 +2785,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"
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 41ee4ad1dcf8..a417bfce0c89 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -3153,10 +3153,30 @@ static void amd_iommu_get_resv_regions(struct device *dev,
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_RANGE) {
+ /*
+ * Each IOMMU has only one exclusion base/limit
+ * register pair (MMIO 0x0020/0x0028). Older kernels
+ * programmed that pair with the exclusion range,
+ * which assumed at most one range per IOMMU. Some
+ * buggy BIOSes list several exclusion IVMD entries for
+ * the same IOMMU. Writing them all to the single
+ * register overwrites the earlier ranges, so they
+ * were lost.
+ *
+ * Reporting each range as a reserved region removes
+ * the one-range limit. The IOMMU core keeps these
+ * IOVAs out of allocation and never maps them, so any
+ * number of exclusion ranges is supported without
+ * touching the register.
+ */
+ type = IOMMU_RESV_RESERVED;
+ prot = 0;
+ }
region = iommu_alloc_resv_region(entry->address_start,
length, prot, type,
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v5 2/3] iommu/amd: Do not convert IVMD exclusion range to unity range
2026-11-27 10:04 ` [PATCH v5 2/3] iommu/amd: Do not convert IVMD exclusion range to unity range Sairaj Kodilkar
@ 2026-12-01 8:50 ` Vasant Hegde
2026-12-01 12:01 ` Sairaj Kodilkar
0 siblings, 1 reply; 7+ messages in thread
From: Vasant Hegde @ 2026-12-01 8:50 UTC (permalink / raw)
To: Sairaj Kodilkar, Joerg Roedel (AMD), Adrian Huang, Joerg Roedel,
Robin Murphy, Suravee Suthikulpanit, Will Deacon, iommu
Cc: Baoquan He, Jerry Snitselaar
Hi All,
On 11/27/2026 3:34 PM, Sairaj Kodilkar wrote:
> 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 entries with unknown flag bits. Warn about invalid flag
> combinations.
>
> 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>
> ---
> drivers/iommu/amd/amd_iommu_types.h | 12 ++++++----
> drivers/iommu/amd/init.c | 36 ++++++++++++++++-------------
> drivers/iommu/amd/iommu.c | 24 +++++++++++++++++--
> 3 files changed, 49 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
> index d1602144c160..0f4c3c65188c 100644
> --- a/drivers/iommu/amd/amd_iommu_types.h
> +++ b/drivers/iommu/amd/amd_iommu_types.h
> @@ -371,9 +371,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_MAP BIT(0)
> +#define IVMD_FLAG_IR BIT(1)
> +#define IVMD_FLAG_IW BIT(2)
> +#define IVMD_FLAG_EXCL_RANGE BIT(3)
> +#define IVMD_FLAG_MASK GENMASK_U32(3, 0)
>
> /* IOMMU capabilities */
> #define IOMMU_CAP_IOTLB 24
> @@ -890,8 +892,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 f8cf37a471f8..6d92fb5c81a7 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
> @@ -2742,6 +2737,25 @@ 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_MASK) {
> + pr_err(FW_BUG "IVMD type %#x devid %#x range %#llx+%#llx: Unknown flags\n",
> + m->type, m->devid, m->range_start, m->range_length);
> + return -EINVAL;
We should print the actual flags here.
> + }
> +
> + if ((m->flags & IVMD_FLAG_UNITY_MAP) &&
> + !(m->flags & (IVMD_FLAG_IR | IVMD_FLAG_IW))) {
> + 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;
> + }
> +
> + if ((m->flags & IVMD_FLAG_EXCL_RANGE) &&
> + (m->flags & (IVMD_FLAG_UNITY_MAP | IVMD_FLAG_IR | IVMD_FLAG_IW))) {
> + pr_err(FW_BUG "IVMD type %#x devid %#x range %#llx+%#llx: Invalid IVMD flag combination %#x\n",
> + m->type, m->devid, m->range_start, m->range_length, m->flags);
> + }
May be I was not clear last time. Spec doesn't stop adding other flags, but it
says all other flags are ignored. So above error message is not valid. Please drop.
> +
> pci_seg = get_pci_segment(m->pci_seg, ivrs_base);
> if (pci_seg == NULL)
> return -ENOMEM;
> @@ -2771,17 +2785,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"
> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
> index 41ee4ad1dcf8..a417bfce0c89 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -3153,10 +3153,30 @@ static void amd_iommu_get_resv_regions(struct device *dev,
>
> 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_RANGE) {
> + /*
> + * Each IOMMU has only one exclusion base/limit
> + * register pair (MMIO 0x0020/0x0028). Older kernels
> + * programmed that pair with the exclusion range,
> + * which assumed at most one range per IOMMU. Some
> + * buggy BIOSes list several exclusion IVMD entries for
> + * the same IOMMU. Writing them all to the single
> + * register overwrites the earlier ranges, so they
> + * were lost.
> + *
> + * Reporting each range as a reserved region removes
> + * the one-range limit. The IOMMU core keeps these
> + * IOVAs out of allocation and never maps them, so any
> + * number of exclusion ranges is supported without
> + * touching the register.
> + */
> + type = IOMMU_RESV_RESERVED;
> + prot = 0;
Last time, I didn't realize that this flag causes us to skip populating the page
table.
Below comment is generated using AI:
The spec describes the exclusion range register (MMIO 0020h) like this:
"Device accesses that target addresses in the exclusion range are
neither translated nor access checked". So an exclusion IVMD asks for
untranslated access to that range, which in a paging domain means a
read/write identity mapping. That is what 387caf0b759a ("iommu/amd:
Treat per-device exclusion ranges as r/w unity-mapped regions") emulated.
IOMMU_RESV_RESERVED does the opposite. The range is left out of the
IOVA allocator and never mapped, so a device in a DMA domain that
accesses it now gets an IO_PAGE_FAULT. 387caf0b759a fixed exactly that
for the Broadcom RAID controllers, whose disks were not detected.
The spec does define a "never map" IVMD, but it uses different flags.
The text above Table 111 says: "If IR = 0b and IW = 0b in the IVMD flags
field, then the memory range is not to be mapped into the peripheral
device address space". It is not ExclusionRange.
So the comment's claim that any number of exclusion ranges "is
supported" does not seem right. The ranges are no longer clobbered, but
the access they ask for is now blocked instead of granted.
--
May be we should use IOMMU_RESV_DIRECT_RELAXABLE so that we can handle handle
both buggy BIOS (See commit 387caf0b759a) and ability to passthrough device.
Is that fine? Anyone sees issue with this?
-Vasant
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v5 2/3] iommu/amd: Do not convert IVMD exclusion range to unity range
2026-12-01 8:50 ` Vasant Hegde
@ 2026-12-01 12:01 ` Sairaj Kodilkar
2026-12-01 12:33 ` Sairaj Kodilkar
0 siblings, 1 reply; 7+ messages in thread
From: Sairaj Kodilkar @ 2026-12-01 12:01 UTC (permalink / raw)
To: Vasant Hegde, Joerg Roedel (AMD), Adrian Huang, Joerg Roedel,
Robin Murphy, Suravee Suthikulpanit, Will Deacon, iommu
Cc: sarunkod, Baoquan He, Jerry Snitselaar
On 12/1/2026 2:20 PM, Vasant Hegde wrote:
> Hi All,
>
>
> On 11/27/2026 3:34 PM, Sairaj Kodilkar wrote:
>> 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 entries with unknown flag bits. Warn about invalid flag
>> combinations.
>>
>> 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>
>> ---
>> drivers/iommu/amd/amd_iommu_types.h | 12 ++++++----
>> drivers/iommu/amd/init.c | 36 ++++++++++++++++-------------
>> drivers/iommu/amd/iommu.c | 24 +++++++++++++++++--
>> 3 files changed, 49 insertions(+), 23 deletions(-)
>>
>> diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
>> index d1602144c160..0f4c3c65188c 100644
>> --- a/drivers/iommu/amd/amd_iommu_types.h
>> +++ b/drivers/iommu/amd/amd_iommu_types.h
>> @@ -371,9 +371,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_MAP BIT(0)
>> +#define IVMD_FLAG_IR BIT(1)
>> +#define IVMD_FLAG_IW BIT(2)
>> +#define IVMD_FLAG_EXCL_RANGE BIT(3)
>> +#define IVMD_FLAG_MASK GENMASK_U32(3, 0)
>>
>> /* IOMMU capabilities */
>> #define IOMMU_CAP_IOTLB 24
>> @@ -890,8 +892,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 f8cf37a471f8..6d92fb5c81a7 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
>> @@ -2742,6 +2737,25 @@ 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_MASK) {
>> + pr_err(FW_BUG "IVMD type %#x devid %#x range %#llx+%#llx: Unknown flags\n",
>> + m->type, m->devid, m->range_start, m->range_length);
>> + return -EINVAL;
>
> We should print the actual flags here.
>
>> + }
>> +
>> + if ((m->flags & IVMD_FLAG_UNITY_MAP) &&
>> + !(m->flags & (IVMD_FLAG_IR | IVMD_FLAG_IW))) {
>> + 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;
>> + }
>> +
>> + if ((m->flags & IVMD_FLAG_EXCL_RANGE) &&
>> + (m->flags & (IVMD_FLAG_UNITY_MAP | IVMD_FLAG_IR | IVMD_FLAG_IW))) {
>> + pr_err(FW_BUG "IVMD type %#x devid %#x range %#llx+%#llx: Invalid IVMD flag combination %#x\n",
>> + m->type, m->devid, m->range_start, m->range_length, m->flags);
>> + }
>
> May be I was not clear last time. Spec doesn't stop adding other flags, but it
> says all other flags are ignored. So above error message is not valid. Please drop.
>
>
>> +
>> pci_seg = get_pci_segment(m->pci_seg, ivrs_base);
>> if (pci_seg == NULL)
>> return -ENOMEM;
>> @@ -2771,17 +2785,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"
>> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
>> index 41ee4ad1dcf8..a417bfce0c89 100644
>> --- a/drivers/iommu/amd/iommu.c
>> +++ b/drivers/iommu/amd/iommu.c
>> @@ -3153,10 +3153,30 @@ static void amd_iommu_get_resv_regions(struct device *dev,
>>
>> 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_RANGE) {
>> + /*
>> + * Each IOMMU has only one exclusion base/limit
>> + * register pair (MMIO 0x0020/0x0028). Older kernels
>> + * programmed that pair with the exclusion range,
>> + * which assumed at most one range per IOMMU. Some
>> + * buggy BIOSes list several exclusion IVMD entries for
>> + * the same IOMMU. Writing them all to the single
>> + * register overwrites the earlier ranges, so they
>> + * were lost.
>> + *
>> + * Reporting each range as a reserved region removes
>> + * the one-range limit. The IOMMU core keeps these
>> + * IOVAs out of allocation and never maps them, so any
>> + * number of exclusion ranges is supported without
>> + * touching the register.
>> + */
>> + type = IOMMU_RESV_RESERVED;
>> + prot = 0;
>
> Last time, I didn't realize that this flag causes us to skip populating the page
> table.
>
> Below comment is generated using AI:
>
> The spec describes the exclusion range register (MMIO 0020h) like this:
> "Device accesses that target addresses in the exclusion range are
> neither translated nor access checked". So an exclusion IVMD asks for
> untranslated access to that range, which in a paging domain means a
> read/write identity mapping. That is what 387caf0b759a ("iommu/amd:
> Treat per-device exclusion ranges as r/w unity-mapped regions") emulated.
>
> IOMMU_RESV_RESERVED does the opposite. The range is left out of the
> IOVA allocator and never mapped, so a device in a DMA domain that
> accesses it now gets an IO_PAGE_FAULT. 387caf0b759a fixed exactly that
> for the Broadcom RAID controllers, whose disks were not detected.
>
> The spec does define a "never map" IVMD, but it uses different flags.
> The text above Table 111 says: "If IR = 0b and IW = 0b in the IVMD flags
> field, then the memory range is not to be mapped into the peripheral
> device address space". It is not ExclusionRange.
>
> So the comment's claim that any number of exclusion ranges "is
> supported" does not seem right. The ranges are no longer clobbered, but
> the access they ask for is now blocked instead of granted.
>
> --
>
> May be we should use IOMMU_RESV_DIRECT_RELAXABLE so that we can handle handle
> both buggy BIOS (See commit 387caf0b759a) and ability to passthrough device.
>
> Is that fine? Anyone sees issue with this?
AI reported same thing in review for me. But I was not sure about this
issue, I confused P2P DMAs with the exclusion range DMA accesses.
This makes sense and we should use IOMMU_RESV_DIRECT_RELAXABLE flag
Thanks
Sairaj
>
> -Vasant
>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v5 2/3] iommu/amd: Do not convert IVMD exclusion range to unity range
2026-12-01 12:01 ` Sairaj Kodilkar
@ 2026-12-01 12:33 ` Sairaj Kodilkar
0 siblings, 0 replies; 7+ messages in thread
From: Sairaj Kodilkar @ 2026-12-01 12:33 UTC (permalink / raw)
To: Vasant Hegde, Joerg Roedel (AMD), Adrian Huang, Joerg Roedel,
Robin Murphy, Suravee Suthikulpanit, Will Deacon, iommu
Cc: sarunkod, Baoquan He, Jerry Snitselaar
On 12/1/2026 5:31 PM, Sairaj Kodilkar wrote:
>
>
> On 12/1/2026 2:20 PM, Vasant Hegde wrote:
>> Hi All,
>>
>>
>> On 11/27/2026 3:34 PM, Sairaj Kodilkar wrote:
>>> 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 entries with unknown flag bits. Warn about invalid flag
>>> combinations.
>>>
>>> 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>
>>> ---
>>> drivers/iommu/amd/amd_iommu_types.h | 12 ++++++----
>>> drivers/iommu/amd/init.c | 36 ++++++++++++++++-------------
>>> drivers/iommu/amd/iommu.c | 24 +++++++++++++++++--
>>> 3 files changed, 49 insertions(+), 23 deletions(-)
>>>
>>> diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
>>> index d1602144c160..0f4c3c65188c 100644
>>> --- a/drivers/iommu/amd/amd_iommu_types.h
>>> +++ b/drivers/iommu/amd/amd_iommu_types.h
>>> @@ -371,9 +371,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_MAP BIT(0)
>>> +#define IVMD_FLAG_IR BIT(1)
>>> +#define IVMD_FLAG_IW BIT(2)
>>> +#define IVMD_FLAG_EXCL_RANGE BIT(3)
>>> +#define IVMD_FLAG_MASK GENMASK_U32(3, 0)
>>>
>>> /* IOMMU capabilities */
>>> #define IOMMU_CAP_IOTLB 24
>>> @@ -890,8 +892,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 f8cf37a471f8..6d92fb5c81a7 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
>>> @@ -2742,6 +2737,25 @@ 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_MASK) {
>>> + pr_err(FW_BUG "IVMD type %#x devid %#x range %#llx+%#llx: Unknown flags\n",
>>> + m->type, m->devid, m->range_start, m->range_length);
>>> + return -EINVAL;
>>
>> We should print the actual flags here.
>>
>>> + }
>>> +
>>> + if ((m->flags & IVMD_FLAG_UNITY_MAP) &&
>>> + !(m->flags & (IVMD_FLAG_IR | IVMD_FLAG_IW))) {
>>> + 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;
>>> + }
>>> +
>>> + if ((m->flags & IVMD_FLAG_EXCL_RANGE) &&
>>> + (m->flags & (IVMD_FLAG_UNITY_MAP | IVMD_FLAG_IR | IVMD_FLAG_IW))) {
>>> + pr_err(FW_BUG "IVMD type %#x devid %#x range %#llx+%#llx: Invalid IVMD flag combination %#x\n",
>>> + m->type, m->devid, m->range_start, m->range_length, m->flags);
>>> + }
>>
>> May be I was not clear last time. Spec doesn't stop adding other flags, but it
>> says all other flags are ignored. So above error message is not valid. Please drop.
>>
>>
>>> +
>>> pci_seg = get_pci_segment(m->pci_seg, ivrs_base);
>>> if (pci_seg == NULL)
>>> return -ENOMEM;
>>> @@ -2771,17 +2785,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"
>>> diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
>>> index 41ee4ad1dcf8..a417bfce0c89 100644
>>> --- a/drivers/iommu/amd/iommu.c
>>> +++ b/drivers/iommu/amd/iommu.c
>>> @@ -3153,10 +3153,30 @@ static void amd_iommu_get_resv_regions(struct device *dev,
>>>
>>> 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_RANGE) {
>>> + /*
>>> + * Each IOMMU has only one exclusion base/limit
>>> + * register pair (MMIO 0x0020/0x0028). Older kernels
>>> + * programmed that pair with the exclusion range,
>>> + * which assumed at most one range per IOMMU. Some
>>> + * buggy BIOSes list several exclusion IVMD entries for
>>> + * the same IOMMU. Writing them all to the single
>>> + * register overwrites the earlier ranges, so they
>>> + * were lost.
>>> + *
>>> + * Reporting each range as a reserved region removes
>>> + * the one-range limit. The IOMMU core keeps these
>>> + * IOVAs out of allocation and never maps them, so any
>>> + * number of exclusion ranges is supported without
>>> + * touching the register.
>>> + */
>>> + type = IOMMU_RESV_RESERVED;
>>> + prot = 0;
>>
>> Last time, I didn't realize that this flag causes us to skip populating the page
>> table.
>>
>> Below comment is generated using AI:
>>
>> The spec describes the exclusion range register (MMIO 0020h) like this:
>> "Device accesses that target addresses in the exclusion range are
>> neither translated nor access checked". So an exclusion IVMD asks for
>> untranslated access to that range, which in a paging domain means a
>> read/write identity mapping. That is what 387caf0b759a ("iommu/amd:
>> Treat per-device exclusion ranges as r/w unity-mapped regions") emulated.
>>
>> IOMMU_RESV_RESERVED does the opposite. The range is left out of the
>> IOVA allocator and never mapped, so a device in a DMA domain that
>> accesses it now gets an IO_PAGE_FAULT. 387caf0b759a fixed exactly that
>> for the Broadcom RAID controllers, whose disks were not detected.
>>
>> The spec does define a "never map" IVMD, but it uses different flags.
>> The text above Table 111 says: "If IR = 0b and IW = 0b in the IVMD flags
>> field, then the memory range is not to be mapped into the peripheral
>> device address space". It is not ExclusionRange.
>>
>> So the comment's claim that any number of exclusion ranges "is
>> supported" does not seem right. The ranges are no longer clobbered, but
>> the access they ask for is now blocked instead of granted.
>>
>> --
>>
>> May be we should use IOMMU_RESV_DIRECT_RELAXABLE so that we can handle handle
>> both buggy BIOS (See commit 387caf0b759a) and ability to passthrough device.
>>
>> Is that fine? Anyone sees issue with this?
>
> AI reported same thing in review for me. But I was not sure about this
> issue, I confused P2P DMAs with the exclusion range DMA accesses.
>
> This makes sense and we should use IOMMU_RESV_DIRECT_RELAXABLE flag
Hi Vasant,
After looking at the VFIO/IOMMUFD kernel code, I dont think we can use
IOMMU_RESV_DIRECT_RELAXABLE. The VFIO (vfio_iommu_resv_exclude()) and
IOMMUFD (iopt_table_enforce_dev_resv_regions()) driver do not reserve
the IOVAs of direct relaxable region, because of which guest can change
the mappings of exclusion region as vfio_iommu_iova_dma_valid() returns
true for it.
I am not sure whats the best approach here, maybe we can introduce a new
flag IOMMU_RESV_DIRECT_EXCL.
Thanks
Sairaj
>
> Thanks
> Sairaj
>
>>
>> -Vasant
>>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v5 3/3] iommu/amd: Rename unity_map symbols to ivmd_entry
2026-11-27 10:04 [PATCH v5 0/3] iommu/amd: IVMD handling cleanup and ivmd= boot override Sairaj Kodilkar
2026-11-27 10:04 ` [PATCH v5 1/3] iommu/amd: Rename exclusion range base and limit macros Sairaj Kodilkar
2026-11-27 10:04 ` [PATCH v5 2/3] iommu/amd: Do not convert IVMD exclusion range to unity range Sairaj Kodilkar
@ 2026-11-27 10:04 ` Sairaj Kodilkar
2 siblings, 0 replies; 7+ messages in thread
From: Sairaj Kodilkar @ 2026-11-27 10:04 UTC (permalink / raw)
To: Joerg Roedel (AMD), Adrian Huang, Joerg Roedel, Robin Murphy,
Suravee Suthikulpanit, Vasant Hegde, Will Deacon, iommu
Cc: Vasant.Hegde, Suravee.Suthikulpanit, Sairaj Kodilkar
Rename unity_map_entry, unity_map, free_unity_maps, init_unity_map_range to
ivmd_entry, ivmd_entry_list, free_ivmd_entry_list, init_ivmd_entry
respectively.
No functional change intended.
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Signed-off-by: Sairaj Kodilkar <sarunkod@amd.com>
---
drivers/iommu/amd/amd_iommu_types.h | 12 ++++++------
drivers/iommu/amd/init.c | 30 ++++++++++++++---------------
drivers/iommu/amd/iommu.c | 6 +++---
3 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
index 0f4c3c65188c..f4790af97d6e 100644
--- a/drivers/iommu/amd/amd_iommu_types.h
+++ b/drivers/iommu/amd/amd_iommu_types.h
@@ -615,11 +615,11 @@ struct amd_iommu_pci_seg {
u16 *alias_table;
/*
- * A list of required unity mappings we find in ACPI. It is not locked
+ * A list of required IVMD mappings we find in ACPI. It is not locked
* because as runtime it is only read. It is created at ACPI table
* parsing time.
*/
- struct list_head unity_map;
+ struct list_head ivmd_entry_list;
};
/*
@@ -877,9 +877,9 @@ struct ivhd_dte_flags {
};
/*
- * One entry for unity mappings parsed out of the ACPI table.
+ * One entry for unity/exclusion ranges parsed out of the ACPI table.
*/
-struct unity_map_entry {
+struct ivmd_entry {
struct list_head list;
/* starting device id this entry is used for (including) */
@@ -887,9 +887,9 @@ struct unity_map_entry {
/* end device id this entry is used for (including) */
u16 devid_end;
- /* start address to unity map (including) */
+ /* start address to unity/exclusion range (including) */
u64 address_start;
- /* end address to unity map (including) */
+ /* end address to unity/exclusion range (including) */
u64 address_end;
/* IVMD flags for the entry */
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index 6d92fb5c81a7..46483fdfba82 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -132,7 +132,7 @@ int amd_iommu_pprlog_size = PPRLOG_SIZE_DEF;
/*
* An AMD IOMMU memory definition structure. It defines things like exclusion
- * ranges for devices and regions that should be unity mapped.
+ * ranges, unity mapping for device and regions.
*/
struct ivmd_header {
u8 type;
@@ -1796,7 +1796,7 @@ static struct amd_iommu_pci_seg *__init alloc_pci_segment(u16 id,
pci_seg->id = id;
init_llist_head(&pci_seg->dev_data_list);
- INIT_LIST_HEAD(&pci_seg->unity_map);
+ INIT_LIST_HEAD(&pci_seg->ivmd_entry_list);
list_add_tail(&pci_seg->list, &amd_iommu_pci_seg_list);
if (alloc_dev_table(pci_seg))
@@ -2425,8 +2425,8 @@ static int __init amd_iommu_init_pci(void)
}
/*
- * Order is important here to make sure any unity map requirements are
- * fulfilled. The unity mappings are created and written to the device
+ * Order is important here to make sure any ivmd map requirements are
+ * fulfilled. The ivmd mappings are created and written to the device
* table during the iommu_init_pci() call.
*
* After that we call init_device_table_dma() to make sure any
@@ -2712,28 +2712,28 @@ static int iommu_init_irq(struct amd_iommu *iommu)
*
* The next functions belong to the third pass of parsing the ACPI
* table. In this last pass the memory mapping requirements are
- * gathered (like exclusion and unity mapping ranges).
+ * gathered (like exclusion and ivmd mapping ranges).
*
****************************************************************************/
-static void __init free_unity_maps(void)
+static void __init free_ivmd_entry_list(void)
{
- struct unity_map_entry *entry, *next;
+ struct ivmd_entry *entry, *next;
struct amd_iommu_pci_seg *p, *pci_seg;
for_each_pci_segment_safe(pci_seg, p) {
- list_for_each_entry_safe(entry, next, &pci_seg->unity_map, list) {
+ list_for_each_entry_safe(entry, next, &pci_seg->ivmd_entry_list, list) {
list_del(&entry->list);
kfree(entry);
}
}
}
-/* called for unity map ACPI definition */
-static int __init init_unity_map_range(struct ivmd_header *m,
- struct acpi_table_header *ivrs_base)
+/* called for ivmd entry mapping in IVRS */
+static int __init init_ivmd_entry(struct ivmd_header *m,
+ struct acpi_table_header *ivrs_base)
{
- struct unity_map_entry *e = NULL;
+ struct ivmd_entry *e = NULL;
struct amd_iommu_pci_seg *pci_seg;
char *s;
@@ -2796,7 +2796,7 @@ static int __init init_unity_map_range(struct ivmd_header *m,
PCI_SLOT(e->devid_end), PCI_FUNC(e->devid_end),
e->address_start, e->address_end, m->flags);
- list_add_tail(&e->list, &pci_seg->unity_map);
+ list_add_tail(&e->list, &pci_seg->ivmd_entry_list);
return 0;
}
@@ -2825,7 +2825,7 @@ static int __init init_memory_definitions(struct acpi_table_header *table)
if (!ivrs_block_type_ivmd(m->type))
continue;
if (m->flags & (IVMD_FLAG_UNITY_MAP | IVMD_FLAG_EXCL_RANGE))
- init_unity_map_range(m, table);
+ init_ivmd_entry(m, table);
}
return 0;
@@ -3299,7 +3299,7 @@ static bool __init check_ioapic_information(void)
static void __init free_dma_resources(void)
{
amd_iommu_pdom_id_destroy();
- free_unity_maps();
+ free_ivmd_entry_list();
}
static void __init ivinfo_init(void *ivrs)
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index a417bfce0c89..493c66b6b794 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -3131,7 +3131,7 @@ static void amd_iommu_get_resv_regions(struct device *dev,
struct list_head *head)
{
struct iommu_resv_region *region;
- struct unity_map_entry *entry;
+ struct ivmd_entry *entry;
struct amd_iommu *iommu;
struct amd_iommu_pci_seg *pci_seg;
int devid, sbdf;
@@ -3144,7 +3144,7 @@ static void amd_iommu_get_resv_regions(struct device *dev,
iommu = get_amd_iommu_from_dev(dev);
pci_seg = iommu->pci_seg;
- list_for_each_entry(entry, &pci_seg->unity_map, list) {
+ list_for_each_entry(entry, &pci_seg->ivmd_entry_list, list) {
int type, prot = 0;
size_t length;
@@ -3182,7 +3182,7 @@ static void amd_iommu_get_resv_regions(struct device *dev,
length, prot, type,
GFP_KERNEL);
if (!region) {
- dev_err(dev, "Out of memory allocating dm-regions\n");
+ dev_err(dev, "Out of memory allocating reserved regions\n");
return;
}
list_add_tail(®ion->list, head);
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread