* [PATCH v8 0/4] of_iommu: add support for "iommu-ranges"
@ 2026-11-20 10:35 Vikash Garodia
2026-11-20 10:35 ` [PATCH v8 1/4] iommu/dma: Keep reserved regions below the IOVA rbtree anchor Vikash Garodia
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Vikash Garodia @ 2026-11-20 10:35 UTC (permalink / raw)
To: Joerg Roedel (AMD), Vasant Hegde, Suravee Suthikulpanit,
Will Deacon, Robin Murphy, David Woodhouse, Lu Baolu,
Jean-Philippe Brucker, Rob Herring, Saravana Kannan,
Tomasz Nowicki, Eric Auger, Bryan O'Donoghue, Joerg Roedel,
Srinath Mannam, Oza Pawandeep, Lorenzo Pieralisi, Bjorn Helgaas,
Alex Williamson
Cc: iommu, linux-kernel, virtualization, devicetree, kvm,
linux-arm-msm, linux-media, Vikash Garodia, Sashiko, stable,
Krzysztof Kozlowski, Dmitry Baryshkov, Vishnu Reddy
The series adds support for recently introduced property
"iommu-ranges". It adds the required checks to error out for cases
which are not following the schema definition.
Iommu-ranges was defined in schema with this PR
https://github.com/devicetree-org/dt-schema/pull/207
These changes are required for following clients
DCP display controller
https://lore.kernel.org/all/20261026-jshekhar-dcp-hlos-v2-0-7cf014efdee1@oss.qualcomm.com
fastrpc
https://lore.kernel.org/all/20261007-extended-mapping-v2-0-5dca3aa2c2d3@oss.qualcomm.com
Iris video
https://lore.kernel.org/all/20261103-vpu_iommu_iova_handling-v6-0-e4b6ad864f8f@oss.qualcomm.com
This patch series is being posted as revision v6 onwards, since the
patches were initially part of the media series [1]. The patches were
moved out to get review comments from iommu reviewers, which was
otherwise looking as a media series. Happy to move this back to media
series if anyone have any concerns.
[1]
https://lore.kernel.org/linux-media/20260926-vpu_iommu_iova_handling-v5-0-0322ca5dc10c@oss.qualcomm.com
Dear IOMMU maintainers,
If there are no review comments, could you kindly apply the patches to a
tree and share an immutable tag. Other media patches can proceed with
that tag. Otherwise, if you prefer to have any other approach, kindly
suggest.
Signed-off-by: Vikash Garodia <vikash.garodia@oss.qualcomm.com>
---
Changes in v8:
- Drop patch#4 to avoid ABI break (Krzysztof)
- Update commit description for #3 (Dmitry)
- Link to v7: https://lore.kernel.org/r/20261106-add_iommu_ranges-v7-0-5c0f72083e52@oss.qualcomm.com
Changes in v7:
- Move the "iommu-addresses" behaviour change ("reg" required, non-direct
mappings rejected) into its own patch before the iommu-ranges patch (Bryan)
- Make OF_IOMMU depend on OF_ADDRESS and drop the #if guards (Rob)
- Use resource_size_t for the size in vfio_find_dma() (Sashiko)
- End the derived trailing reserved region at PHYS_ADDR_MAX - 1 to avoid
overflow (Sashiko)
- Add a dma-iommu fix to protect the IOVA rbtree anchor on 32-bit with
64-bit dma_addr_t (Sashiko)
- Use the "iommu/of:" prefix and fix the subject case
- Link to v6: https://lore.kernel.org/r/20261103-add_iommu_ranges-v6-0-361f3921a133@oss.qualcomm.com
Changes in v6:
- Addressed sashiko comments.
- Addressed comment from Bryan.
- Link to v5: https://lore.kernel.org/all/20260926-vpu_iommu_iova_handling-v5-4-0322ca5dc10c@oss.qualcomm.com/
---
Vikash Garodia (4):
iommu/dma: Keep reserved regions below the IOVA rbtree anchor
iommu: Use resource_size_t for reserved region length
iommu/of: Make OF_IOMMU depend on OF_ADDRESS
iommu/of: Add support for "iommu-ranges" on a device node
drivers/iommu/Kconfig | 2 +-
drivers/iommu/amd/iommu.c | 2 +-
drivers/iommu/dma-iommu.c | 32 ++++++-----
drivers/iommu/intel/iommu.c | 2 +-
drivers/iommu/iommu.c | 2 +-
drivers/iommu/of_iommu.c | 115 ++++++++++++++++++++++++++++++++++++++--
drivers/iommu/virtio-iommu.c | 2 +-
drivers/of/address.c | 2 +-
drivers/vfio/vfio_iommu_type1.c | 2 +-
include/linux/iommu.h | 4 +-
include/linux/of_address.h | 2 +-
11 files changed, 140 insertions(+), 27 deletions(-)
---
base-commit: adcad7f4e6332cff3d6d7165f41584899f598534
change-id: 20261103-add_iommu_ranges-549cf3fb0867
Best regards,
--
Vikash Garodia <vikash.garodia@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v8 1/4] iommu/dma: Keep reserved regions below the IOVA rbtree anchor
2026-11-20 10:35 [PATCH v8 0/4] of_iommu: add support for "iommu-ranges" Vikash Garodia
@ 2026-11-20 10:35 ` Vikash Garodia
2026-11-20 10:43 ` sashiko-bot
2026-11-20 10:35 ` [PATCH v8 2/4] iommu: Use resource_size_t for reserved region length Vikash Garodia
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Vikash Garodia @ 2026-11-20 10:35 UTC (permalink / raw)
To: Joerg Roedel (AMD), Vasant Hegde, Suravee Suthikulpanit,
Will Deacon, Robin Murphy, David Woodhouse, Lu Baolu,
Jean-Philippe Brucker, Rob Herring, Saravana Kannan,
Tomasz Nowicki, Eric Auger, Bryan O'Donoghue, Joerg Roedel,
Srinath Mannam, Oza Pawandeep, Lorenzo Pieralisi, Bjorn Helgaas,
Alex Williamson
Cc: iommu, linux-kernel, virtualization, devicetree, kvm,
linux-arm-msm, linux-media, Vikash Garodia, Sashiko, stable,
Krzysztof Kozlowski, Dmitry Baryshkov, Vishnu Reddy
The IOVA allocator tracks address ranges by page frame number (PFN).
The highest node in its rbtree is a fixed anchor at PFN ~0UL, which is
embedded in the DMA cookie. dma-iommu converts reserved regions to PFNs
with iova_pfn(), which returns unsigned long. On x86-32 with PAE,
addresses are 64-bit but unsigned long is 32-bit, so the upper bits of
the PFN are lost.
A reserved region that ends at the top of the address space then gets
the anchor's PFN. reserve_iova() merges it into the anchor and lowers
the anchor's pfn_lo. At teardown, free_iova_mem() no longer recognises
the anchor and frees it to iova_cache, which corrupts the slab. PCI host
bridge windows above 16TiB and the reservation after the last PCI DMA
window hit the same problem.
Compute the PFNs in u64. Skip ranges that start above the PFN space and
clamp the end one PFN below the anchor. The allocator never hands out
those IOVAs, so nothing is lost. On 64-bit, PFNs never reach ~0UL, so
nothing changes there.
Fixes: fade1ec055dc ("iommu/dma: Avoid PCI host bridge windows")
Fixes: 7c1b058c8b5a ("iommu/dma: Handle IOMMU API reserved regions")
Fixes: aadad097cd46 ("iommu/dma: Reserve IOVA for PCIe inaccessible DMA address")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-195658@kernel.org/
Cc: stable@vger.kernel.org
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Co-developed-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
Signed-off-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
Signed-off-by: Vikash Garodia <vikash.garodia@oss.qualcomm.com>
---
drivers/iommu/dma-iommu.c | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index b66e83cfbc5f195a46d286d376068fcc13148611..2ee30df470730fd03b5dc46b46e3eaba2df130d6 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -505,21 +505,34 @@ static int iommu_dma_ranges_sort(void *priv, const struct list_head *a,
return res_a->res->start > res_b->res->start;
}
+/*
+ * IOVA PFNs are unsigned long, and ~0UL is the rbtree anchor. On 32-bit
+ * with a 64-bit dma_addr_t, iova_pfn() would truncate the range. Compute
+ * the PFNs in u64 instead, skip a range that starts beyond the PFN space
+ * and clamp its end below the anchor. Such IOVAs cannot be allocated.
+ */
+static void iova_reserve_range(struct iova_domain *iovad, u64 start, u64 end)
+{
+ u64 lo = start >> iova_shift(iovad);
+ u64 hi = end >> iova_shift(iovad);
+
+ if (lo < ULONG_MAX)
+ reserve_iova(iovad, lo, min(hi, ULONG_MAX - 1));
+}
+
static int iova_reserve_pci_windows(struct pci_dev *dev,
struct iova_domain *iovad)
{
struct pci_host_bridge *bridge = pci_find_host_bridge(dev->bus);
struct resource_entry *window;
- unsigned long lo, hi;
phys_addr_t start = 0, end;
resource_list_for_each_entry(window, &bridge->windows) {
if (resource_type(window->res) != IORESOURCE_MEM)
continue;
- lo = iova_pfn(iovad, window->res->start - window->offset);
- hi = iova_pfn(iovad, window->res->end - window->offset);
- reserve_iova(iovad, lo, hi);
+ iova_reserve_range(iovad, window->res->start - window->offset,
+ window->res->end - window->offset);
}
/* Get reserved DMA windows from host bridge */
@@ -528,9 +541,7 @@ static int iova_reserve_pci_windows(struct pci_dev *dev,
end = window->res->start - window->offset;
resv_iova:
if (end > start) {
- lo = iova_pfn(iovad, start);
- hi = iova_pfn(iovad, end);
- reserve_iova(iovad, lo, hi);
+ iova_reserve_range(iovad, start, end);
} else if (end < start) {
/* DMA ranges should be non-overlapping */
dev_err(&dev->dev,
@@ -568,15 +579,12 @@ static int iova_reserve_iommu_regions(struct device *dev,
iommu_get_resv_regions(dev, &resv_regions);
list_for_each_entry(region, &resv_regions, list) {
- unsigned long lo, hi;
-
/* We ARE the software that manages these! */
if (region->type == IOMMU_RESV_SW_MSI)
continue;
- lo = iova_pfn(iovad, region->start);
- hi = iova_pfn(iovad, region->start + region->length - 1);
- reserve_iova(iovad, lo, hi);
+ iova_reserve_range(iovad, region->start,
+ region->start + region->length - 1);
if (region->type == IOMMU_RESV_MSI)
ret = cookie_init_hw_msi_region(cookie, region->start,
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v8 2/4] iommu: Use resource_size_t for reserved region length
2026-11-20 10:35 [PATCH v8 0/4] of_iommu: add support for "iommu-ranges" Vikash Garodia
2026-11-20 10:35 ` [PATCH v8 1/4] iommu/dma: Keep reserved regions below the IOVA rbtree anchor Vikash Garodia
@ 2026-11-20 10:35 ` Vikash Garodia
2026-11-20 10:45 ` sashiko-bot
2026-11-20 10:35 ` [PATCH v8 3/4] iommu/of: Make OF_IOMMU depend on OF_ADDRESS Vikash Garodia
2026-11-20 10:35 ` [PATCH v8 4/4] iommu/of: Add support for "iommu-ranges" on a device node Vikash Garodia
3 siblings, 1 reply; 9+ messages in thread
From: Vikash Garodia @ 2026-11-20 10:35 UTC (permalink / raw)
To: Joerg Roedel (AMD), Vasant Hegde, Suravee Suthikulpanit,
Will Deacon, Robin Murphy, David Woodhouse, Lu Baolu,
Jean-Philippe Brucker, Rob Herring, Saravana Kannan,
Tomasz Nowicki, Eric Auger, Bryan O'Donoghue, Joerg Roedel,
Srinath Mannam, Oza Pawandeep, Lorenzo Pieralisi, Bjorn Helgaas,
Alex Williamson
Cc: iommu, linux-kernel, virtualization, devicetree, kvm,
linux-arm-msm, linux-media, Vikash Garodia, Sashiko, stable,
Krzysztof Kozlowski, Dmitry Baryshkov, Vishnu Reddy
On 32-bit systems with LPAE, physical addresses are 64-bit. A reserved
region can be larger than 4GiB, but its length is stored as size_t,
which is only 32-bit there. The length gets truncated.
Use resource_size_t for the length so it matches the width of
phys_addr_t and holds the full size of the region.
Fixes: 2b20cbba3390 ("iommu: iommu_alloc_resv_region")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/d223ee9f-b262-408a-a201-8b16d310bbe0@oss.qualcomm.com
Cc: stable@vger.kernel.org
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Acked-by: Rob Herring (Arm) <robh@kernel.org>
Co-developed-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
Signed-off-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
Signed-off-by: Vikash Garodia <vikash.garodia@oss.qualcomm.com>
---
drivers/iommu/amd/iommu.c | 2 +-
drivers/iommu/intel/iommu.c | 2 +-
drivers/iommu/iommu.c | 2 +-
drivers/iommu/of_iommu.c | 4 ++--
drivers/iommu/virtio-iommu.c | 2 +-
drivers/of/address.c | 2 +-
drivers/vfio/vfio_iommu_type1.c | 2 +-
include/linux/iommu.h | 4 ++--
include/linux/of_address.h | 2 +-
9 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 41ee4ad1dcf826cc765c6f198d487620be60281d..f9f8ef919236a28c6514609d2710b7801a67834f 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -3146,7 +3146,7 @@ static void amd_iommu_get_resv_regions(struct device *dev,
list_for_each_entry(entry, &pci_seg->unity_map, list) {
int type, prot = 0;
- size_t length;
+ resource_size_t length;
if (devid < entry->devid_start || devid > entry->devid_end)
continue;
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index 5a2e705a2f2e025245d4b42c4a9f765c67d708d4..70e210ca085ff52519376358a3e3b7a01619d7a8 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -3535,7 +3535,7 @@ static void intel_iommu_get_resv_regions(struct device *device,
i, i_dev) {
struct iommu_resv_region *resv;
enum iommu_resv_type type;
- size_t length;
+ resource_size_t length;
if (i_dev != device &&
!is_downstream_to_pci_bridge(device, i_dev))
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 8da858154949e849ef6bc1d303271883fa4762fc..4412dc39a5e87900f3a22e824a99babdcc9f695f 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -3010,7 +3010,7 @@ void iommu_put_resv_regions(struct device *dev, struct list_head *list)
EXPORT_SYMBOL(iommu_put_resv_regions);
struct iommu_resv_region *iommu_alloc_resv_region(phys_addr_t start,
- size_t length, int prot,
+ resource_size_t length, int prot,
enum iommu_resv_type type,
gfp_t gfp)
{
diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c
index a18bb60f6f3dfdba853b6e16dd2a8616f6a731c7..5c266511db78910d6fd221af5437cecff4931c22 100644
--- a/drivers/iommu/of_iommu.c
+++ b/drivers/iommu/of_iommu.c
@@ -170,7 +170,7 @@ int of_iommu_configure(struct device *dev, struct device_node *master_np,
static enum iommu_resv_type __maybe_unused
iommu_resv_region_get_type(struct device *dev,
struct resource *phys,
- phys_addr_t start, size_t length)
+ phys_addr_t start, resource_size_t length)
{
phys_addr_t end = start + length - 1;
@@ -246,7 +246,7 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
struct iommu_resv_region *region;
enum iommu_resv_type type;
phys_addr_t iova;
- size_t length;
+ resource_size_t length;
if (of_dma_is_coherent(dev->of_node))
prot |= IOMMU_CACHE;
diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
index 7fde3ddf231af7fcb6571e3daeaf227552eb17bc..37c48d05c73bf9bab85ed134eac6c6998191405c 100644
--- a/drivers/iommu/virtio-iommu.c
+++ b/drivers/iommu/virtio-iommu.c
@@ -483,7 +483,7 @@ static int viommu_add_resv_mem(struct viommu_endpoint *vdev,
struct virtio_iommu_probe_resv_mem *mem,
size_t len)
{
- size_t size;
+ resource_size_t size;
u64 start64, end64;
phys_addr_t start, end;
struct iommu_resv_region *region = NULL, *next;
diff --git a/drivers/of/address.c b/drivers/of/address.c
index 499d37ceae210ac844eef853aeecbfabaaa5e138..f665432638a6d1cc1ebfc0d2356b813c8c584910 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -655,7 +655,7 @@ EXPORT_SYMBOL(of_translate_dma_address);
* Returns a pointer to the cell immediately following the translated DMA region.
*/
const __be32 *of_translate_dma_region(struct device_node *dev, const __be32 *prop,
- phys_addr_t *start, size_t *length)
+ phys_addr_t *start, resource_size_t *length)
{
struct device_node *parent __free(device_node) = __of_get_dma_parent(dev);
u64 address, size;
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index f7addfbe1aab4f6fb662b8b2fa66bc02d98b5f03..9f508143505ad9e603af1730e811c30bd5edce16 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -164,7 +164,7 @@ vfio_iommu_find_iommu_group(struct vfio_iommu *iommu,
*/
static struct vfio_dma *vfio_find_dma(struct vfio_iommu *iommu,
- dma_addr_t start, size_t size)
+ dma_addr_t start, resource_size_t size)
{
struct rb_node *node = iommu->dma_list.rb_node;
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index ef5043752a3651419679316c5a20cdf049efeaba..1d8f9381a358ec2309503bfe2866f08a1f236b2b 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -306,7 +306,7 @@ enum iommu_resv_type {
struct iommu_resv_region {
struct list_head list;
phys_addr_t start;
- size_t length;
+ resource_size_t length;
int prot;
enum iommu_resv_type type;
void (*free)(struct device *dev, struct iommu_resv_region *region);
@@ -968,7 +968,7 @@ extern void iommu_set_default_passthrough(bool cmd_line);
extern void iommu_set_default_translated(bool cmd_line);
extern bool iommu_default_passthrough(void);
extern struct iommu_resv_region *
-iommu_alloc_resv_region(phys_addr_t start, size_t length, int prot,
+iommu_alloc_resv_region(phys_addr_t start, resource_size_t length, int prot,
enum iommu_resv_type type, gfp_t gfp);
extern int iommu_get_group_resv_regions(struct iommu_group *group,
struct list_head *head);
diff --git a/include/linux/of_address.h b/include/linux/of_address.h
index 0cff9036539168b0cf2826ee34417738a4836ace..ae6d96c8c110adad966f2c1bad2cbefaf55e5c57 100644
--- a/include/linux/of_address.h
+++ b/include/linux/of_address.h
@@ -56,7 +56,7 @@ static inline int of_range_count(const struct of_range_parser *parser)
extern u64 of_translate_dma_address(struct device_node *dev,
const __be32 *in_addr);
extern const __be32 *of_translate_dma_region(struct device_node *dev, const __be32 *addr,
- phys_addr_t *start, size_t *length);
+ phys_addr_t *start, resource_size_t *length);
#ifdef CONFIG_OF_ADDRESS
extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v8 3/4] iommu/of: Make OF_IOMMU depend on OF_ADDRESS
2026-11-20 10:35 [PATCH v8 0/4] of_iommu: add support for "iommu-ranges" Vikash Garodia
2026-11-20 10:35 ` [PATCH v8 1/4] iommu/dma: Keep reserved regions below the IOVA rbtree anchor Vikash Garodia
2026-11-20 10:35 ` [PATCH v8 2/4] iommu: Use resource_size_t for reserved region length Vikash Garodia
@ 2026-11-20 10:35 ` Vikash Garodia
2026-11-20 10:42 ` sashiko-bot
2026-11-20 10:35 ` [PATCH v8 4/4] iommu/of: Add support for "iommu-ranges" on a device node Vikash Garodia
3 siblings, 1 reply; 9+ messages in thread
From: Vikash Garodia @ 2026-11-20 10:35 UTC (permalink / raw)
To: Joerg Roedel (AMD), Vasant Hegde, Suravee Suthikulpanit,
Will Deacon, Robin Murphy, David Woodhouse, Lu Baolu,
Jean-Philippe Brucker, Rob Herring, Saravana Kannan,
Tomasz Nowicki, Eric Auger, Bryan O'Donoghue, Joerg Roedel,
Srinath Mannam, Oza Pawandeep, Lorenzo Pieralisi, Bjorn Helgaas,
Alex Williamson
Cc: iommu, linux-kernel, virtualization, devicetree, kvm,
linux-arm-msm, linux-media, Vikash Garodia, Krzysztof Kozlowski,
Vishnu Reddy
Currently, the OF_IOMMU code is built when OF and IOMMU_API are enabled.
However, the code also uses OF address parsing helpers, which are only
available when OF_ADDRESS is enabled. Since this dependency is not
expressed in Kconfig, when OF_ADDRESS is disabled the code relies on
CONFIG_OF_ADDRESS guards and a __maybe_unused annotation to avoid
compilation issues.
The only architecture supporting OF without OF_ADDRESS is SPARC, which
does not use OF_IOMMU. Therefore, make the OF_IOMMU code depend on
OF_ADDRESS so that it is built only when the required address parsing
support is available, avoiding the CONFIG_OF_ADDRESS guards and
__maybe_unused annotation in the code. No functional change is intended.
Suggested-by: Rob Herring <robh@kernel.org>
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
Co-developed-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
Signed-off-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
Signed-off-by: Vikash Garodia <vikash.garodia@oss.qualcomm.com>
---
drivers/iommu/Kconfig | 2 +-
drivers/iommu/of_iommu.c | 4 +---
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index 85a8d7fdfa30b64e21b8db0db1d5bc268c04f24b..c1e97bd885f933cae45fb7806183477f2d64cd5d 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -147,7 +147,7 @@ endchoice
config OF_IOMMU
def_bool y
- depends on OF && IOMMU_API
+ depends on OF_ADDRESS && IOMMU_API
# IOMMU-agnostic DMA-mapping layer
config IOMMU_DMA
diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c
index 5c266511db78910d6fd221af5437cecff4931c22..6675fc900e6c2d55b34c61dc9effaeb48e24f18f 100644
--- a/drivers/iommu/of_iommu.c
+++ b/drivers/iommu/of_iommu.c
@@ -167,7 +167,7 @@ int of_iommu_configure(struct device *dev, struct device_node *master_np,
return err;
}
-static enum iommu_resv_type __maybe_unused
+static enum iommu_resv_type
iommu_resv_region_get_type(struct device *dev,
struct resource *phys,
phys_addr_t start, resource_size_t length)
@@ -203,7 +203,6 @@ iommu_resv_region_get_type(struct device *dev,
*/
void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
{
-#if IS_ENABLED(CONFIG_OF_ADDRESS)
struct of_phandle_iterator it;
int err;
@@ -265,6 +264,5 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
}
}
}
-#endif
}
EXPORT_SYMBOL(of_iommu_get_resv_regions);
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v8 4/4] iommu/of: Add support for "iommu-ranges" on a device node
2026-11-20 10:35 [PATCH v8 0/4] of_iommu: add support for "iommu-ranges" Vikash Garodia
` (2 preceding siblings ...)
2026-11-20 10:35 ` [PATCH v8 3/4] iommu/of: Make OF_IOMMU depend on OF_ADDRESS Vikash Garodia
@ 2026-11-20 10:35 ` Vikash Garodia
2026-11-20 10:50 ` sashiko-bot
3 siblings, 1 reply; 9+ messages in thread
From: Vikash Garodia @ 2026-11-20 10:35 UTC (permalink / raw)
To: Joerg Roedel (AMD), Vasant Hegde, Suravee Suthikulpanit,
Will Deacon, Robin Murphy, David Woodhouse, Lu Baolu,
Jean-Philippe Brucker, Rob Herring, Saravana Kannan,
Tomasz Nowicki, Eric Auger, Bryan O'Donoghue, Joerg Roedel,
Srinath Mannam, Oza Pawandeep, Lorenzo Pieralisi, Bjorn Helgaas,
Alex Williamson
Cc: iommu, linux-kernel, virtualization, devicetree, kvm,
linux-arm-msm, linux-media, Vikash Garodia, Dmitry Baryshkov,
Krzysztof Kozlowski, Vishnu Reddy
Reserving an IOVA address using "iommu-addresses" requires it to be
placed in the reserved-memory node. But when "iommu-addresses" is the
only property being described and there is no backing "reg" (i.e. no
actual reserved system memory), it does not really belong under
/reserved-memory. A device IOVA range is specific to its own address
space, and does not describe the system physical memory to make it
qualify under reserved-memory. Given this, place "iommu-addresses"
inside reserved-memory only when it is paired with a "reg", otherwise,
define it within the device own node. It was discussed here:
https://lore.kernel.org/all/662f7093-fb0a-4564-9ca0-98e03e68ba9a@kernel.org
Existing "iommu-addresses" property expects a phandle, which does
not make sense when the property is defined within the device node.
"iommu-ranges" was introduced to specify the device specific IOVA ranges
when there is no backing "reg".
Suggested-by: Rob Herring <robh@kernel.org>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
Co-developed-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
Signed-off-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
Signed-off-by: Vikash Garodia <vikash.garodia@oss.qualcomm.com>
---
drivers/iommu/of_iommu.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 107 insertions(+)
diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c
index 6675fc900e6c2d55b34c61dc9effaeb48e24f18f..2ee5490ba3572cd9f2d2b7655cbe93055ac87d03 100644
--- a/drivers/iommu/of_iommu.c
+++ b/drivers/iommu/of_iommu.c
@@ -190,6 +190,111 @@ iommu_resv_region_get_type(struct device *dev,
return IOMMU_RESV_RESERVED;
}
+/**
+ * of_iommu_derive_resv_regions - derive reserved regions which
+ * are outside of iommu-ranges
+ * @dev: device for which to get reserved regions
+ * @list: reserved region list
+ *
+ * A device can describe its own usable IOVA ranges directly on its node
+ * via "iommu-ranges". Everything not under those ranges is derived
+ * as a reserved region so the IOMMU allocator won't use it. Entries may
+ * appear in any order in the property.
+ */
+static void of_iommu_derive_resv_regions(struct device *dev, struct list_head *list)
+{
+ struct of_iommu_range {
+ struct list_head node;
+ phys_addr_t start;
+ phys_addr_t end;
+ } *pos, *new, *next_range;
+ int size, prot = IOMMU_READ | IOMMU_WRITE;
+ struct iommu_resv_region *region;
+ const __be32 *maps, *end;
+ struct list_head *prev;
+ phys_addr_t next = 0;
+ LIST_HEAD(ranges);
+
+ maps = of_get_property(dev->of_node, "iommu-ranges", &size);
+ if (!maps)
+ return;
+
+ end = maps + size / sizeof(__be32);
+
+ while (maps < end) {
+ phys_addr_t iova, iova_end;
+ resource_size_t length;
+
+ maps = of_translate_dma_region(dev->of_node, maps, &iova, &length);
+ if (!maps) {
+ dev_err(dev, "%pOF: failed to parse iommu-ranges\n",
+ dev->of_node);
+ goto exit;
+ }
+
+ if (!length)
+ continue;
+
+ iova_end = iova + length - 1;
+
+ if (iova_end < iova) {
+ dev_err(dev, "%pOF: iommu-ranges overflows address space\n",
+ dev->of_node);
+ goto exit;
+ }
+
+ prev = &ranges;
+ list_for_each_entry(pos, &ranges, node) {
+ if (pos->start > iova)
+ break;
+ prev = &pos->node;
+ }
+
+ new = kmalloc_obj(*new);
+ if (!new)
+ goto exit;
+
+ new->start = iova;
+ new->end = iova_end;
+ list_add(&new->node, prev);
+ }
+
+ if (list_empty(&ranges))
+ return;
+
+ if (of_dma_is_coherent(dev->of_node))
+ prot |= IOMMU_CACHE;
+
+ list_for_each_entry_safe(pos, next_range, &ranges, node) {
+ if (pos->start > next) {
+ region = iommu_alloc_resv_region(next, pos->start - next, prot,
+ IOMMU_RESV_RESERVED, GFP_KERNEL);
+ if (region)
+ list_add_tail(®ion->list, list);
+ }
+
+ if (pos->end >= PHYS_ADDR_MAX - 1)
+ goto exit;
+
+ if (pos->end >= next)
+ next = pos->end + 1;
+
+ list_del(&pos->node);
+ kfree(pos);
+ }
+
+ region = iommu_alloc_resv_region(next, PHYS_ADDR_MAX - next,
+ prot, IOMMU_RESV_RESERVED, GFP_KERNEL);
+ if (region)
+ list_add_tail(®ion->list, list);
+
+exit:
+ list_for_each_entry_safe(pos, next_range, &ranges, node) {
+ list_del(&pos->node);
+ kfree(pos);
+ }
+}
+
/**
* of_iommu_get_resv_regions - reserved region driver helper for device tree
* @dev: device for which to get reserved regions
@@ -264,5 +369,7 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
}
}
}
+
+ of_iommu_derive_resv_regions(dev, list);
}
EXPORT_SYMBOL(of_iommu_get_resv_regions);
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v8 3/4] iommu/of: Make OF_IOMMU depend on OF_ADDRESS
2026-11-20 10:35 ` [PATCH v8 3/4] iommu/of: Make OF_IOMMU depend on OF_ADDRESS Vikash Garodia
@ 2026-11-20 10:42 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-20 10:42 UTC (permalink / raw)
To: Vikash Garodia; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
> Currently, the OF_IOMMU code is built when OF and IOMMU_API are enabled.
> However, the code also uses OF address parsing helpers, which are only
> available when OF_ADDRESS is enabled. Since this dependency is not
> expressed in Kconfig, when OF_ADDRESS is disabled the code relies on
> CONFIG_OF_ADDRESS guards and a __maybe_unused annotation to avoid
> compilation issues.
>
> The only architecture supporting OF without OF_ADDRESS is SPARC, which
> does not use OF_IOMMU. Therefore, make the OF_IOMMU code depend on
> OF_ADDRESS so that it is built only when the required address parsing
> support is available, avoiding the CONFIG_OF_ADDRESS guards and
> __maybe_unused annotation in the code. No functional change is intended.
>
> Suggested-by: Rob Herring <robh@kernel.org>
> Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
> Co-developed-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
> Signed-off-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
> Signed-off-by: Vikash Garodia <vikash.garodia@oss.qualcomm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-add_iommu_ranges-v8-0-d90486973b73@oss.qualcomm.com?part=3
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v8 1/4] iommu/dma: Keep reserved regions below the IOVA rbtree anchor
2026-11-20 10:35 ` [PATCH v8 1/4] iommu/dma: Keep reserved regions below the IOVA rbtree anchor Vikash Garodia
@ 2026-11-20 10:43 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-20 10:43 UTC (permalink / raw)
To: Vikash Garodia; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
> The IOVA allocator tracks address ranges by page frame number (PFN).
> The highest node in its rbtree is a fixed anchor at PFN ~0UL, which is
> embedded in the DMA cookie. dma-iommu converts reserved regions to PFNs
> with iova_pfn(), which returns unsigned long. On x86-32 with PAE,
> addresses are 64-bit but unsigned long is 32-bit, so the upper bits of
> the PFN are lost.
> A reserved region that ends at the top of the address space then gets
> the anchor's PFN. reserve_iova() merges it into the anchor and lowers
> the anchor's pfn_lo. At teardown, free_iova_mem() no longer recognises
> the anchor and frees it to iova_cache, which corrupts the slab. PCI host
> bridge windows above 16TiB and the reservation after the last PCI DMA
> window hit the same problem.
> Compute the PFNs in u64. Skip ranges that start above the PFN space and
> clamp the end one PFN below the anchor. The allocator never hands out
> those IOVAs, so nothing is lost. On 64-bit, PFNs never reach ~0UL, so
> nothing changes there.
>
> Fixes: fade1ec055dc ("iommu/dma: Avoid PCI host bridge windows")
> Fixes: 7c1b058c8b5a ("iommu/dma: Handle IOMMU API reserved regions")
> Fixes: aadad097cd46 ("iommu/dma: Reserve IOVA for PCIe inaccessible DMA address")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://lore.kernel.org/all/sashiko-outbox-195658@kernel.org/
> Cc: stable@vger.kernel.org
> Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
> Co-developed-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
> Signed-off-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
> Signed-off-by: Vikash Garodia <vikash.garodia@oss.qualcomm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-add_iommu_ranges-v8-0-d90486973b73@oss.qualcomm.com?part=1
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v8 2/4] iommu: Use resource_size_t for reserved region length
2026-11-20 10:35 ` [PATCH v8 2/4] iommu: Use resource_size_t for reserved region length Vikash Garodia
@ 2026-11-20 10:45 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-20 10:45 UTC (permalink / raw)
To: Vikash Garodia; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
> On 32-bit systems with LPAE, physical addresses are 64-bit. A reserved
> region can be larger than 4GiB, but its length is stored as size_t,
> which is only 32-bit there. The length gets truncated.
> Use resource_size_t for the length so it matches the width of
> phys_addr_t and holds the full size of the region.
>
> Fixes: 2b20cbba3390 ("iommu: iommu_alloc_resv_region")
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://lore.kernel.org/all/d223ee9f-b262-408a-a201-8b16d310bbe0@oss.qualcomm.com
> Cc: stable@vger.kernel.org
> Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
> Acked-by: Rob Herring (Arm) <robh@kernel.org>
> Co-developed-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
> Signed-off-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
> Signed-off-by: Vikash Garodia <vikash.garodia@oss.qualcomm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-add_iommu_ranges-v8-0-d90486973b73@oss.qualcomm.com?part=2
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v8 4/4] iommu/of: Add support for "iommu-ranges" on a device node
2026-11-20 10:35 ` [PATCH v8 4/4] iommu/of: Add support for "iommu-ranges" on a device node Vikash Garodia
@ 2026-11-20 10:50 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-20 10:50 UTC (permalink / raw)
To: Vikash Garodia; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez
> Reserving an IOVA address using "iommu-addresses" requires it to be
> placed in the reserved-memory node. But when "iommu-addresses" is the
> only property being described and there is no backing "reg" (i.e. no
> actual reserved system memory), it does not really belong under
> /reserved-memory. A device IOVA range is specific to its own address
> space, and does not describe the system physical memory to make it
> qualify under reserved-memory. Given this, place "iommu-addresses"
> inside reserved-memory only when it is paired with a "reg", otherwise,
> define it within the device own node. It was discussed here:
> https://lore.kernel.org/all/662f7093-fb0a-4564-9ca0-98e03e68ba9a@kernel.org
>
> Existing "iommu-addresses" property expects a phandle, which does
> not make sense when the property is defined within the device node.
> "iommu-ranges" was introduced to specify the device specific IOVA ranges
> when there is no backing "reg".
>
> Suggested-by: Rob Herring <robh@kernel.org>
> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
> Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
> Co-developed-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
> Signed-off-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
> Signed-off-by: Vikash Garodia <vikash.garodia@oss.qualcomm.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-add_iommu_ranges-v8-0-d90486973b73@oss.qualcomm.com?part=4
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-20 10:50 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 10:35 [PATCH v8 0/4] of_iommu: add support for "iommu-ranges" Vikash Garodia
2026-11-20 10:35 ` [PATCH v8 1/4] iommu/dma: Keep reserved regions below the IOVA rbtree anchor Vikash Garodia
2026-11-20 10:43 ` sashiko-bot
2026-11-20 10:35 ` [PATCH v8 2/4] iommu: Use resource_size_t for reserved region length Vikash Garodia
2026-11-20 10:45 ` sashiko-bot
2026-11-20 10:35 ` [PATCH v8 3/4] iommu/of: Make OF_IOMMU depend on OF_ADDRESS Vikash Garodia
2026-11-20 10:42 ` sashiko-bot
2026-11-20 10:35 ` [PATCH v8 4/4] iommu/of: Add support for "iommu-ranges" on a device node Vikash Garodia
2026-11-20 10:50 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.