From: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
To: robin.murphy@arm.com, joro@8bytes.org, will@kernel.org,
m.szyprowski@samsung.com
Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
vikash.garodia@oss.qualcomm.com,
dikshita.agarwal@oss.qualcomm.com
Subject: Re: [RFC PATCH] dma-iommu: Introduce API to reserve IOVA regions for dynamically created devices
Date: Mon, 5 Jan 2026 11:32:42 +0530 [thread overview]
Message-ID: <d28ba659-b085-a323-8630-c86dedfdfdea@oss.qualcomm.com> (raw)
In-Reply-To: <20251220023555.3017456-1-busanna.reddy@oss.qualcomm.com>
On 12/20/2025 8:05 AM, Vishnu Reddy wrote:
> Drivers can create child devices dynamically. These child devices often
> inherit parent device tree node, including its reserved iommu-address
> ranges. While device tree can declare the multiple iommu-address ranges,
> they still apply uniformly to any child inheriting the parent OF node.
>
> This creates a limitation when child requires a different iommu-address
> range than its parent, as device tree cannot express the reservation per
> child.
>
> Example layout and use case:
> ----------------------------
> A multimedia subsystem with multiple child devices and distinct ranges:
>
> +-----------------------------------------------------------+
> | Device A reserved region (256 MB) |
> | 0x00000000 - 0x10000000 |
> +-----------------------------------------------------------+
> | Device B reserved region (512 MB) |
> | 0x00000000 - 0x20000000 |
> +-----------------------------------------------------------+
> | Device C reserved region (600 MB) |
> | 0x00000000 - 0x25800000 |
> +-----------------------------------------------------------+
> | Other reserved regions |
> +-----------------------------------------------------------+
>
> If we add Device C's reserved range (0x0 to 0x025800000) into iommu
> address range into device tree and assign that OF node to Device B
> and C, it wastes memory:
> - Device A wastes ~344 MB
> - Device B wastes ~88 MB
>
> To avoid this, drivers can use the introduced API to set their device
> specific IOVA region at runtime, ensuring the DMA mapping without
> unnecessary address space reservation.
>
> Signed-off-by: Vishnu Reddy <busanna.reddy@oss.qualcomm.com>
> ---
> drivers/iommu/dma-iommu.c | 44 +++++++++++++++++++++++++++++++++++++
> include/linux/dma-mapping.h | 7 ++++++
> 2 files changed, 51 insertions(+)
>
> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> index c92088855450a..02c54cddf9417 100644
> --- a/drivers/iommu/dma-iommu.c
> +++ b/drivers/iommu/dma-iommu.c
> @@ -1743,6 +1743,50 @@ size_t iommu_dma_max_mapping_size(struct device *dev)
> return SIZE_MAX;
> }
>
> +/**
> + * dma_iova_set_resv_region - Set a reserved region in the IOVA space
> + * @dev: Device to set the reserved region for
> + * @start: Start of the reserved region
> + * @length: Length of the reserved region
> + *
> + * This function enables drivers to set device specific reservations at
> + * runtime, which is particularly useful for dynamically created child
> + * devices that requires distinct IOVA ranges than parent.
> + *
> + * Returns:
> + * 0 - Success
> + * -ENODEV - No valid IOMMU DMA domain for the device
> + * -EINVAL - Invalid domain or cookie type for this operation
> + * -ENOMEM - Failed to reserve the requested range
> + */
> +int dma_iova_set_resv_region(struct device *dev, unsigned long start,
> + unsigned long length)
> +{
> + struct iommu_dma_cookie *cookie;
> + struct iommu_domain *domain;
> + struct iova_domain *iovad;
> + unsigned long lo, hi;
> +
> + domain = iommu_get_dma_domain(dev);
> + if (!domain || domain->type != IOMMU_DOMAIN_DMA)
> + return -ENODEV;
> +
> + cookie = domain->iova_cookie;
> + if (!cookie || domain->cookie_type != IOMMU_COOKIE_DMA_IOVA)
> + return -EINVAL;
> +
> + iovad = &cookie->iovad;
> +
> + lo = iova_pfn(iovad, start);
> + hi = iova_pfn(iovad, start + length - 1);
> +
> + if (!reserve_iova(iovad, lo, hi))
> + return -ENOMEM;
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(dma_iova_set_resv_region);
> +
> /**
> * dma_iova_try_alloc - Try to allocate an IOVA space
> * @dev: Device to allocate the IOVA space for
> diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
> index aa36a0d1d9df6..c89147cf92231 100644
> --- a/include/linux/dma-mapping.h
> +++ b/include/linux/dma-mapping.h
> @@ -339,6 +339,8 @@ static inline bool dma_use_iova(struct dma_iova_state *state)
> return state->__size != 0;
> }
>
> +int dma_iova_set_resv_region(struct device *dev, unsigned long start,
> + unsigned long length);
> bool dma_iova_try_alloc(struct device *dev, struct dma_iova_state *state,
> phys_addr_t phys, size_t size);
> void dma_iova_free(struct device *dev, struct dma_iova_state *state);
> @@ -358,6 +360,11 @@ static inline bool dma_use_iova(struct dma_iova_state *state)
> {
> return false;
> }
> +static inline int dma_iova_set_resv_region(struct device *dev, unsigned long start,
> + unsigned long length)
> +{
> + return -ENODEV;
> +}
> static inline bool dma_iova_try_alloc(struct device *dev,
> struct dma_iova_state *state, phys_addr_t phys, size_t size)
> {
Reminder to review this patch.
Thanks
Vishnu Reddy
prev parent reply other threads:[~2026-01-05 6:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-20 2:35 Vishnu Reddy
2026-01-05 6:02 ` Vishnu Reddy [this message]
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=d28ba659-b085-a323-8630-c86dedfdfdea@oss.qualcomm.com \
--to=busanna.reddy@oss.qualcomm.com \
--cc=dikshita.agarwal@oss.qualcomm.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=robin.murphy@arm.com \
--cc=vikash.garodia@oss.qualcomm.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®