From: Vasant Hegde <vasant.hegde@amd.com>
To: Sairaj Kodilkar <sarunkod@amd.com>,
"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>,
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>
Subject: Re: [PATCH v4 2/3] iommu/amd: Do not convert IVMD exclusion range to unity range
Date: Fri, 20 Nov 2026 22:21:47 +0530 [thread overview]
Message-ID: <29610488-73c7-4ce0-9ddf-d0b56be10a19@amd.com> (raw)
In-Reply-To: <20261117070654.3699-3-sarunkod@amd.com>
On 11/17/2026 12:36 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 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>
> ---
> drivers/iommu/amd/amd_iommu_types.h | 12 ++++++-----
> drivers/iommu/amd/init.c | 31 ++++++++++++++---------------
> drivers/iommu/amd/iommu.c | 12 +++++++++--
> 3 files changed, 32 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
> index 678ceddd711c..122eac81d4e3 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_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
> @@ -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..de8e4ba2ccd0 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,20 @@ 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_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))) {
Spec says IR, IW, and Unity are ignored when ExclusionRange is
set, not that the entry is invalid.
> + pr_err(FW_BUG "IVMD type %#x devid %#x range %#llx+%#llx: Invalid IOMMU flags %#x, ignoring\n",
> + m->type, m->devid, m->range_start, m->range_length, m->flags);
> + return -EINVAL;
> + }
> +
> pci_seg = get_pci_segment(m->pci_seg, ivrs_base);
> if (pci_seg == NULL)
> return -ENOMEM;
> @@ -2665,17 +2674,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.
I'd say update above comment and keep it. So that we know why we removed
exclusion_range register and used this method.
> - */
> - 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 56262f6b1f70..7edaf99a1ecb 100644
> --- a/drivers/iommu/amd/iommu.c
> +++ b/drivers/iommu/amd/iommu.c
> @@ -3120,12 +3120,20 @@ static void amd_iommu_get_resv_regions(struct device *dev,
> if (devid < entry->devid_start || devid > entry->devid_end)
> continue;
>
> + if (entry->flags & ~IVMD_FLAG_MASK)
> + pr_err("%s: Unknown flags: %#02x for sbdf=%#x\n",
> + __func__, entry->flags & ~IVMD_FLAG_MASK, sbdf);
init_unity_map_range() is the right place to add this check.
-Vasant
next prev parent reply other threads:[~2026-11-20 16:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 7:06 [PATCH v4 0/3] iommu/amd: IVMD handling cleanup and ivmd= boot override Sairaj Kodilkar
2026-11-17 7:06 ` [PATCH v4 1/3] iommu/amd: Drop unused global exclusion range fields and init Sairaj Kodilkar
2026-11-20 16:38 ` Vasant Hegde
2026-11-17 7:06 ` [PATCH v4 2/3] iommu/amd: Do not convert IVMD exclusion range to unity range Sairaj Kodilkar
2026-11-20 16:51 ` Vasant Hegde [this message]
2026-11-17 7:06 ` [PATCH v4 3/3] iommu/amd: Rename unity_map_entry and unit_map to ivmd_entry and ivhd_entry_list Sairaj Kodilkar
2026-11-20 16:57 ` Vasant Hegde
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=29610488-73c7-4ce0-9ddf-d0b56be10a19@amd.com \
--to=vasant.hegde@amd.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=sarunkod@amd.com \
--cc=suravee.suthikulpanit@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®