* [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size
[not found] ` <20261127115849.2780625-1-m.szyprowski@samsung.com>
@ 2026-11-27 11:58 ` Marek Szyprowski
2026-11-27 12:41 ` Vikash Garodia
2026-11-27 14:29 ` Jason Gunthorpe
2026-11-27 11:58 ` [PATCH 2/4] media: iris: " Marek Szyprowski
` (2 subsequent siblings)
3 siblings, 2 replies; 25+ messages in thread
From: Marek Szyprowski @ 2026-11-27 11:58 UTC (permalink / raw)
To: iommu, linux-media, linux-arm-msm, kvm, linux-kernel
Cc: Marek Szyprowski, Robin Murphy, Joerg Roedel, Will Deacon,
Leon Romanovsky, Jason Gunthorpe, Sibi Sankar, Honglei Huang,
prakash.gupta, Alex Williamson, Vikash Garodia, Dikshita Agarwal,
Abhinav Kumar, Bryan O'Donoghue, Mauro Carvalho Chehab,
Hans Verkuil, stable
The IOVA reservation code compares dma_iova_state::__size directly with
the requested chunk size. __size is internal to the DMA IOVA API and may
carry flags in its upper bits, so use the dma_iova_size() accessor
instead.
Fixes: 953439251b59 ("media: venus: Fix iova allocation from restrict region")
Cc: stable@vger.kernel.org # v7.4+
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
drivers/media/platform/qcom/venus/core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c
index 7087af32060f..cec5db2bf755 100644
--- a/drivers/media/platform/qcom/venus/core.c
+++ b/drivers/media/platform/qcom/venus/core.c
@@ -408,7 +408,8 @@ static int venus_reserve_iova_region(struct device *dev, struct dma_iova_state *
if (!dma_iova_try_alloc(dev, &state[count], 0, chunk))
goto err_free_iova;
- if (state[count].addr != end - chunk || state[count].__size != chunk)
+ if (state[count].addr != end - chunk ||
+ dma_iova_size(&state[count]) != chunk)
goto err_free_iova;
rem -= chunk;
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH 2/4] media: iris: use dma_iova_size() to check the reserved IOVA size
[not found] ` <20261127115849.2780625-1-m.szyprowski@samsung.com>
2026-11-27 11:58 ` [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size Marek Szyprowski
@ 2026-11-27 11:58 ` Marek Szyprowski
2026-11-27 12:41 ` Vikash Garodia
2026-11-27 11:58 ` [PATCH 3/4] dma-mapping: add DMA_IOVA_FLAGS mask for the dma_iova_state size flags Marek Szyprowski
2026-11-27 11:58 ` [PATCH 4/4] iommu/dma: restore flush queue use in dma_iova_destroy() Marek Szyprowski
3 siblings, 1 reply; 25+ messages in thread
From: Marek Szyprowski @ 2026-11-27 11:58 UTC (permalink / raw)
To: iommu, linux-media, linux-arm-msm, kvm, linux-kernel
Cc: Marek Szyprowski, Robin Murphy, Joerg Roedel, Will Deacon,
Leon Romanovsky, Jason Gunthorpe, Sibi Sankar, Honglei Huang,
prakash.gupta, Alex Williamson, Vikash Garodia, Dikshita Agarwal,
Abhinav Kumar, Bryan O'Donoghue, Mauro Carvalho Chehab,
Hans Verkuil, stable
The IOVA reservation code compares dma_iova_state::__size directly with
the requested chunk size. __size is internal to the DMA IOVA API and may
carry flags in its upper bits, so use the dma_iova_size() accessor
instead.
Fixes: 200473c198b2 ("media: iris: Fix iova allocation from restrict region")
Cc: stable@vger.kernel.org # v7.4+
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
drivers/media/platform/qcom/iris/iris_probe.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/media/platform/qcom/iris/iris_probe.c b/drivers/media/platform/qcom/iris/iris_probe.c
index 41dec90f3e2b..0af913e40604 100644
--- a/drivers/media/platform/qcom/iris/iris_probe.c
+++ b/drivers/media/platform/qcom/iris/iris_probe.c
@@ -181,7 +181,8 @@ static int iris_reserve_iova_region(struct device *dev, struct dma_iova_state **
if (!dma_iova_try_alloc(dev, &state[count], 0, chunk))
goto err_free_iova;
- if (state[count].addr != end - chunk || state[count].__size != chunk)
+ if (state[count].addr != end - chunk ||
+ dma_iova_size(&state[count]) != chunk)
goto err_free_iova;
rem -= chunk;
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH 3/4] dma-mapping: add DMA_IOVA_FLAGS mask for the dma_iova_state size flags
[not found] ` <20261127115849.2780625-1-m.szyprowski@samsung.com>
2026-11-27 11:58 ` [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size Marek Szyprowski
2026-11-27 11:58 ` [PATCH 2/4] media: iris: " Marek Szyprowski
@ 2026-11-27 11:58 ` Marek Szyprowski
2026-11-27 14:37 ` Jason Gunthorpe
2026-11-27 11:58 ` [PATCH 4/4] iommu/dma: restore flush queue use in dma_iova_destroy() Marek Szyprowski
3 siblings, 1 reply; 25+ messages in thread
From: Marek Szyprowski @ 2026-11-27 11:58 UTC (permalink / raw)
To: iommu, linux-media, linux-arm-msm, kvm, linux-kernel
Cc: Marek Szyprowski, Robin Murphy, Joerg Roedel, Will Deacon,
Leon Romanovsky, Jason Gunthorpe, Sibi Sankar, Honglei Huang,
prakash.gupta, Alex Williamson, Vikash Garodia, Dikshita Agarwal,
Abhinav Kumar, Bryan O'Donoghue, Mauro Carvalho Chehab,
Hans Verkuil, stable
dma_iova_state::__size uses its top bit to record that SWIOTLB was used
for one of the linked ranges. Users that mask or validate sizes refer to
DMA_IOVA_USE_SWIOTLB directly, so adding another flag would require
updating all of them.
Add DMA_IOVA_FLAGS covering all flags kept in __size and use it in
dma_iova_size(), in the size check of dma_iova_try_alloc() and in the
vfio-pci dma-buf length validation. No functional change.
Cc: stable@vger.kernel.org # v7.3+
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
drivers/iommu/dma-iommu.c | 8 ++++----
drivers/vfio/pci/vfio_pci_dmabuf.c | 2 +-
include/linux/dma-mapping.h | 8 +++++++-
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 78742aeba932..99eb382a1359 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -1838,11 +1838,11 @@ bool dma_iova_try_alloc(struct device *dev, struct dma_iova_state *state,
return false;
/*
- * DMA_IOVA_USE_SWIOTLB is flag which is set by dma-iommu
- * internals, make sure that caller didn't set it and/or
- * didn't use this interface to map SIZE_MAX.
+ * DMA_IOVA_FLAGS are set by dma-iommu internals, make sure that
+ * caller didn't set them and/or didn't use this interface to map
+ * SIZE_MAX.
*/
- if (WARN_ON_ONCE((u64)size & DMA_IOVA_USE_SWIOTLB))
+ if (WARN_ON_ONCE((u64)size & DMA_IOVA_FLAGS))
return false;
addr = iommu_dma_alloc_iova(domain,
diff --git a/drivers/vfio/pci/vfio_pci_dmabuf.c b/drivers/vfio/pci/vfio_pci_dmabuf.c
index c16f460c01d6..8bda610dd988 100644
--- a/drivers/vfio/pci/vfio_pci_dmabuf.c
+++ b/drivers/vfio/pci/vfio_pci_dmabuf.c
@@ -211,7 +211,7 @@ static int validate_dmabuf_input(struct vfio_device_feature_dma_buf *dma_buf,
* dma_iova_try_alloc() will WARN on if userspace proposes a size that
* is too big, eg with lots of ranges.
*/
- if ((u64)(length) & DMA_IOVA_USE_SWIOTLB)
+ if ((u64)(length) & DMA_IOVA_FLAGS)
return -EINVAL;
*lengthp = length;
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index efde0e5a58dc..0ebf3090ea0f 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -135,10 +135,16 @@ struct dma_iova_state {
*/
#define DMA_IOVA_USE_SWIOTLB (1ULL << 63)
+/*
+ * All flags stored in the upper bits of dma_iova_state::__size. Sizes passed
+ * to dma_iova_try_alloc() must not overlap with them.
+ */
+#define DMA_IOVA_FLAGS DMA_IOVA_USE_SWIOTLB
+
static inline size_t dma_iova_size(struct dma_iova_state *state)
{
/* Casting is needed for 32-bits systems */
- return (size_t)(state->__size & ~DMA_IOVA_USE_SWIOTLB);
+ return (size_t)(state->__size & ~DMA_IOVA_FLAGS);
}
#ifdef CONFIG_DMA_API_DEBUG
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH 4/4] iommu/dma: restore flush queue use in dma_iova_destroy()
[not found] ` <20261127115849.2780625-1-m.szyprowski@samsung.com>
` (2 preceding siblings ...)
2026-11-27 11:58 ` [PATCH 3/4] dma-mapping: add DMA_IOVA_FLAGS mask for the dma_iova_state size flags Marek Szyprowski
@ 2026-11-27 11:58 ` Marek Szyprowski
2026-11-27 14:37 ` Jason Gunthorpe
2026-11-27 15:31 ` Leon Romanovsky
3 siblings, 2 replies; 25+ messages in thread
From: Marek Szyprowski @ 2026-11-27 11:58 UTC (permalink / raw)
To: iommu, linux-media, linux-arm-msm, kvm, linux-kernel
Cc: Marek Szyprowski, Robin Murphy, Joerg Roedel, Will Deacon,
Leon Romanovsky, Jason Gunthorpe, Sibi Sankar, Honglei Huang,
prakash.gupta, Alex Williamson, Vikash Garodia, Dikshita Agarwal,
Abhinav Kumar, Bryan O'Donoghue, Mauro Carvalho Chehab,
Hans Verkuil, stable
Commit 1acce29926d9 ("iommu/dma: simplify dma_iova_destroy() and drop
the free_iova helper") turned dma_iova_destroy() into dma_iova_unlink()
followed by dma_iova_free(). Before it, the destroy path marked its
IOTLB gather as queued for DMA-FQ domains, skipped iommu_iotlb_sync()
and handed the IOVA over to the flush queue, exactly like
__iommu_dma_unmap(). After it:
- dma_iova_unlink() never queues its gather and always calls
iommu_iotlb_sync() after iommu_unmap_fast(),
- dma_iova_free() passes a NULL gather to iommu_dma_free_iova(), so
the IOVA goes straight back to the allocator via free_iova_fast().
DMA-FQ domains therefore get strict invalidation on this path. This
includes blk_rq_dma_map(), which NVMe uses for all data transfers, so
iommu.strict=0 has no effect on NVMe I/O. On a Qualcomm Glymur CRD
(SMMUv3 without RANGE_INV, 4K pages, NVMe on PCIe Gen5 x4) sequential
fio throughput drops from 10.6/11.9 GiB/s (write/read) to the strict
mode level of ~2.7 GiB/s.
Instead of reverting, decide once in dma_iova_try_alloc() whether the
IOVA space is going to be released through the flush queue and record
it in a new DMA_IOVA_USE_FQ flag in dma_iova_state::__size, next to
DMA_IOVA_USE_SWIOTLB, so struct dma_iova_state does not grow.
dma_iova_destroy() then unmaps with a gather queued according to that
flag, skipping the sync for flush queue domains, and passes the same
gather to the IOVA free, so the IOVA space (and any page table pages
released by the unmap) goes through queue_iova() again. dma_iova_free()
honours the flag as well. The whole reservation is still freed, keeping
the size fix of the reverted commit.
A gather must always be retired, either by iommu_iotlb_sync() or by
handing it to the flush queue together with the IOVA, and the IOVA must
never be returned to the allocator while a queued invalidation for it is
still pending. To keep that obvious, the internal unlink helper only
unmaps into a gather supplied by its caller, and each caller retires it
right away: dma_iova_destroy() syncs or queues it together with the IOVA
free, exactly like __iommu_dma_unmap(), while dma_iova_unlink() always
uses a never queued gather and syncs it, as the unlinked range remains
owned by the caller and may be linked again immediately.
Fixes: 1acce29926d9 ("iommu/dma: simplify dma_iova_destroy() and drop the free_iova helper")
Reported-by: Sibi Sankar <sibi.sankar@oss.qualcomm.com>
Closes: https://lore.kernel.org/all/20261125135120.1126571-1-sibi.sankar@oss.qualcomm.com/
Suggested-by: Leon Romanovsky <leon@kernel.org>
Cc: stable@vger.kernel.org # v7.3+
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
---
drivers/iommu/dma-iommu.c | 103 ++++++++++++++++++++++++++----------
include/linux/dma-mapping.h | 8 ++-
2 files changed, 83 insertions(+), 28 deletions(-)
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 99eb382a1359..0e329ecd7dfa 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -1853,10 +1853,31 @@ bool dma_iova_try_alloc(struct device *dev, struct dma_iova_state *state,
state->addr = addr + iova_off;
state->__size = size;
+ /*
+ * Decide once, for the whole life cycle of @state, whether the IOVA
+ * space is going to be released through the flush queue. A domain
+ * can only move from strict to lazy mode, so a stale "not queued"
+ * value is always safe.
+ */
+ if (READ_ONCE(cookie->fq_domain))
+ state->__size |= DMA_IOVA_USE_FQ;
return true;
}
EXPORT_SYMBOL_GPL(dma_iova_try_alloc);
+static void __dma_iova_free(struct device *dev, struct dma_iova_state *state,
+ struct iommu_iotlb_gather *gather)
+{
+ struct iommu_domain *domain = iommu_get_dma_domain(dev);
+ struct iommu_dma_cookie *cookie = domain->iova_cookie;
+ struct iova_domain *iovad = &cookie->iovad;
+ size_t iova_start_pad = iova_offset(iovad, state->addr);
+ size_t size = dma_iova_size(state);
+
+ iommu_dma_free_iova(domain, state->addr - iova_start_pad,
+ iova_align(iovad, size + iova_start_pad), gather);
+}
+
/**
* dma_iova_free - Free an IOVA space
* @dev: Device to free the IOVA space for
@@ -1871,14 +1892,11 @@ EXPORT_SYMBOL_GPL(dma_iova_try_alloc);
*/
void dma_iova_free(struct device *dev, struct dma_iova_state *state)
{
- struct iommu_domain *domain = iommu_get_dma_domain(dev);
- struct iommu_dma_cookie *cookie = domain->iova_cookie;
- struct iova_domain *iovad = &cookie->iovad;
- size_t iova_start_pad = iova_offset(iovad, state->addr);
- size_t size = dma_iova_size(state);
+ struct iommu_iotlb_gather iotlb_gather;
- iommu_dma_free_iova(domain, state->addr - iova_start_pad,
- iova_align(iovad, size + iova_start_pad), NULL);
+ iommu_iotlb_gather_init(&iotlb_gather);
+ iotlb_gather.queued = state->__size & DMA_IOVA_USE_FQ;
+ __dma_iova_free(dev, state, &iotlb_gather);
}
EXPORT_SYMBOL_GPL(dma_iova_free);
@@ -2097,27 +2115,20 @@ static void iommu_dma_iova_unlink_range_slow(struct device *dev,
arch_sync_dma_flush();
}
-/**
- * dma_iova_unlink - Unlink a range of IOVA space
- * @dev: DMA device
- * @state: IOVA state
- * @offset: offset into the IOVA state to unlink
- * @size: size of the buffer
- * @dir: DMA direction
- * @attrs: attributes of mapping properties
- *
- * Unlink a range of IOVA space for the given IOVA state.
+/*
+ * Unmap a range of IOVA space into @gather. The caller owns @gather and must
+ * retire it, either by iommu_iotlb_sync() or, for a queued gather, by handing
+ * it over to the flush queue together with the IOVA via iommu_dma_free_iova().
*/
-void dma_iova_unlink(struct device *dev, struct dma_iova_state *state,
+static void __dma_iova_unlink(struct device *dev, struct dma_iova_state *state,
size_t offset, size_t size, enum dma_data_direction dir,
- unsigned long attrs)
+ unsigned long attrs, struct iommu_iotlb_gather *gather)
{
struct iommu_domain *domain = iommu_get_dma_domain(dev);
struct iommu_dma_cookie *cookie = domain->iova_cookie;
struct iova_domain *iovad = &cookie->iovad;
dma_addr_t addr = state->addr + offset;
size_t iova_start_pad = iova_offset(iovad, addr);
- struct iommu_iotlb_gather iotlb_gather;
size_t unmapped;
if ((state->__size & DMA_IOVA_USE_SWIOTLB) ||
@@ -2125,14 +2136,38 @@ void dma_iova_unlink(struct device *dev, struct dma_iova_state *state,
!(attrs & (DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_MMIO))))
iommu_dma_iova_unlink_range_slow(dev, addr, size, dir, attrs);
- iommu_iotlb_gather_init(&iotlb_gather);
-
size = iova_align(iovad, size + iova_start_pad);
addr -= iova_start_pad;
- unmapped = iommu_unmap_fast(domain, addr, size, &iotlb_gather);
+ unmapped = iommu_unmap_fast(domain, addr, size, gather);
WARN_ON(unmapped != size);
+}
- iommu_iotlb_sync(domain, &iotlb_gather);
+/**
+ * dma_iova_unlink - Unlink a range of IOVA space
+ * @dev: DMA device
+ * @state: IOVA state
+ * @offset: offset into the IOVA state to unlink
+ * @size: size of the buffer
+ * @dir: DMA direction
+ * @attrs: attributes of mapping properties
+ *
+ * Unlink a range of IOVA space for the given IOVA state.
+ */
+void dma_iova_unlink(struct device *dev, struct dma_iova_state *state,
+ size_t offset, size_t size, enum dma_data_direction dir,
+ unsigned long attrs)
+{
+ struct iommu_iotlb_gather iotlb_gather;
+
+ /*
+ * The IOVA range stays owned by the caller and may be linked again
+ * right away, so the IOTLB has to be invalidated synchronously even
+ * for flush queue domains. The gather is therefore never queued and
+ * is retired right here.
+ */
+ iommu_iotlb_gather_init(&iotlb_gather);
+ __dma_iova_unlink(dev, state, offset, size, dir, attrs, &iotlb_gather);
+ iommu_iotlb_sync(iommu_get_dma_domain(dev), &iotlb_gather);
}
EXPORT_SYMBOL_GPL(dma_iova_unlink);
@@ -2152,14 +2187,28 @@ void dma_iova_destroy(struct device *dev, struct dma_iova_state *state,
size_t mapped_len, enum dma_data_direction dir,
unsigned long attrs)
{
- if (mapped_len)
- dma_iova_unlink(dev, state, 0, mapped_len, dir, attrs);
+ struct iommu_iotlb_gather iotlb_gather;
+
+ iommu_iotlb_gather_init(&iotlb_gather);
+ iotlb_gather.queued = state->__size & DMA_IOVA_USE_FQ;
/*
* We can be here if the first call to dma_iova_link() failed and
* there is nothing to unlink, so let's be more clear.
*/
- dma_iova_free(dev, state);
+ if (mapped_len)
+ __dma_iova_unlink(dev, state, 0, mapped_len, dir, attrs,
+ &iotlb_gather);
+
+ /*
+ * Retire the gather together with the IOVA, like __iommu_dma_unmap()
+ * does: either invalidate the IOTLB now, or hand the IOVA space and
+ * any page table pages released by the unmap over to the flush queue,
+ * so the IOVA cannot be reused before the deferred invalidation.
+ */
+ if (!iotlb_gather.queued)
+ iommu_iotlb_sync(iommu_get_dma_domain(dev), &iotlb_gather);
+ __dma_iova_free(dev, state, &iotlb_gather);
}
EXPORT_SYMBOL_GPL(dma_iova_destroy);
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
index 0ebf3090ea0f..7524c14f1262 100644
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -135,11 +135,17 @@ struct dma_iova_state {
*/
#define DMA_IOVA_USE_SWIOTLB (1ULL << 63)
+/*
+ * Set when the IOVA space is going to be released through the IOMMU flush
+ * queue. Internal to dma-iommu.
+ */
+#define DMA_IOVA_USE_FQ (1ULL << 62)
+
/*
* All flags stored in the upper bits of dma_iova_state::__size. Sizes passed
* to dma_iova_try_alloc() must not overlap with them.
*/
-#define DMA_IOVA_FLAGS DMA_IOVA_USE_SWIOTLB
+#define DMA_IOVA_FLAGS (DMA_IOVA_USE_SWIOTLB | DMA_IOVA_USE_FQ)
static inline size_t dma_iova_size(struct dma_iova_state *state)
{
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size
2026-11-27 11:58 ` [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size Marek Szyprowski
@ 2026-11-27 12:41 ` Vikash Garodia
2026-11-27 14:29 ` Jason Gunthorpe
1 sibling, 0 replies; 25+ messages in thread
From: Vikash Garodia @ 2026-11-27 12:41 UTC (permalink / raw)
To: Marek Szyprowski, iommu, linux-media, linux-arm-msm, kvm,
linux-kernel
Cc: Robin Murphy, Joerg Roedel, Will Deacon, Leon Romanovsky,
Jason Gunthorpe, Sibi Sankar, Honglei Huang, prakash.gupta,
Alex Williamson, Dikshita Agarwal, Abhinav Kumar,
Bryan O'Donoghue, Mauro Carvalho Chehab, Hans Verkuil, stable
On 11/27/2026 5:28 PM, Marek Szyprowski wrote:
> The IOVA reservation code compares dma_iova_state::__size directly with
> the requested chunk size. __size is internal to the DMA IOVA API and may
> carry flags in its upper bits, so use the dma_iova_size() accessor
> instead.
>
> Fixes: 953439251b59 ("media: venus: Fix iova allocation from restrict region")
> Cc:stable@vger.kernel.org # v7.4+
> Signed-off-by: Marek Szyprowski<m.szyprowski@samsung.com>
> ---
> drivers/media/platform/qcom/venus/core.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
Reviewed-by: Vikash Garodia <vikash.garodia@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 2/4] media: iris: use dma_iova_size() to check the reserved IOVA size
2026-11-27 11:58 ` [PATCH 2/4] media: iris: " Marek Szyprowski
@ 2026-11-27 12:41 ` Vikash Garodia
0 siblings, 0 replies; 25+ messages in thread
From: Vikash Garodia @ 2026-11-27 12:41 UTC (permalink / raw)
To: Marek Szyprowski, iommu, linux-media, linux-arm-msm, kvm,
linux-kernel
Cc: Robin Murphy, Joerg Roedel, Will Deacon, Leon Romanovsky,
Jason Gunthorpe, Sibi Sankar, Honglei Huang, prakash.gupta,
Alex Williamson, Dikshita Agarwal, Abhinav Kumar,
Bryan O'Donoghue, Mauro Carvalho Chehab, Hans Verkuil, stable
On 11/27/2026 5:28 PM, Marek Szyprowski wrote:
> The IOVA reservation code compares dma_iova_state::__size directly with
> the requested chunk size. __size is internal to the DMA IOVA API and may
> carry flags in its upper bits, so use the dma_iova_size() accessor
> instead.
>
> Fixes: 200473c198b2 ("media: iris: Fix iova allocation from restrict region")
> Cc:stable@vger.kernel.org # v7.4+
> Signed-off-by: Marek Szyprowski<m.szyprowski@samsung.com>
> ---
> drivers/media/platform/qcom/iris/iris_probe.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
Reviewed-by: Vikash Garodia <vikash.garodia@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size
2026-11-27 11:58 ` [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size Marek Szyprowski
2026-11-27 12:41 ` Vikash Garodia
@ 2026-11-27 14:29 ` Jason Gunthorpe
2026-11-27 15:24 ` Leon Romanovsky
2026-11-27 17:21 ` Bryan O'Donoghue
1 sibling, 2 replies; 25+ messages in thread
From: Jason Gunthorpe @ 2026-11-27 14:29 UTC (permalink / raw)
To: Marek Szyprowski
Cc: iommu, linux-media, linux-arm-msm, kvm, linux-kernel,
Robin Murphy, Joerg Roedel, Will Deacon, Leon Romanovsky,
Sibi Sankar, Honglei Huang, prakash.gupta, Alex Williamson,
Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
Bryan O'Donoghue, Mauro Carvalho Chehab, Hans Verkuil, stable
On Fri, Nov 27, 2026 at 12:58:45PM +0100, Marek Szyprowski wrote:
> The IOVA reservation code compares dma_iova_state::__size directly with
> the requested chunk size. __size is internal to the DMA IOVA API and may
> carry flags in its upper bits, so use the dma_iova_size() accessor
> instead.
WTF is this even doing?
Fix this by reserving the 0-600MB range, below the boundary the
non-pixel stream cannot address, using dma_iova_try_alloc() so the
IOMMU-DMA core never hands that range out to a real DMA mapping. This
reserves only IOVA space, it does not allocate any physical memory.
That isn't what this API is for, and it isn't how it even works! It is
pure luck that the first call to it happens to take out the lower
address space.
We even had a long discussion about this driver and this need in
another thread and this is the hack job you guys merged?
And it couldn't even use the right APIs??!
Jason
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 3/4] dma-mapping: add DMA_IOVA_FLAGS mask for the dma_iova_state size flags
2026-11-27 11:58 ` [PATCH 3/4] dma-mapping: add DMA_IOVA_FLAGS mask for the dma_iova_state size flags Marek Szyprowski
@ 2026-11-27 14:37 ` Jason Gunthorpe
0 siblings, 0 replies; 25+ messages in thread
From: Jason Gunthorpe @ 2026-11-27 14:37 UTC (permalink / raw)
To: Marek Szyprowski
Cc: iommu, linux-media, linux-arm-msm, kvm, linux-kernel,
Robin Murphy, Joerg Roedel, Will Deacon, Leon Romanovsky,
Sibi Sankar, Honglei Huang, prakash.gupta, Alex Williamson,
Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
Bryan O'Donoghue, Mauro Carvalho Chehab, Hans Verkuil, stable
On Fri, Nov 27, 2026 at 12:58:47PM +0100, Marek Szyprowski wrote:
> dma_iova_state::__size uses its top bit to record that SWIOTLB was used
> for one of the linked ranges. Users that mask or validate sizes refer to
> DMA_IOVA_USE_SWIOTLB directly, so adding another flag would require
> updating all of them.
>
> Add DMA_IOVA_FLAGS covering all flags kept in __size and use it in
> dma_iova_size(), in the size check of dma_iova_try_alloc() and in the
> vfio-pci dma-buf length validation. No functional change.
>
> Cc: stable@vger.kernel.org # v7.3+
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> ---
> drivers/iommu/dma-iommu.c | 8 ++++----
> drivers/vfio/pci/vfio_pci_dmabuf.c | 2 +-
> include/linux/dma-mapping.h | 8 +++++++-
> 3 files changed, 12 insertions(+), 6 deletions(-)
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Jason
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 4/4] iommu/dma: restore flush queue use in dma_iova_destroy()
2026-11-27 11:58 ` [PATCH 4/4] iommu/dma: restore flush queue use in dma_iova_destroy() Marek Szyprowski
@ 2026-11-27 14:37 ` Jason Gunthorpe
2026-11-27 14:45 ` Marek Szyprowski
2026-11-27 15:31 ` Leon Romanovsky
1 sibling, 1 reply; 25+ messages in thread
From: Jason Gunthorpe @ 2026-11-27 14:37 UTC (permalink / raw)
To: Marek Szyprowski
Cc: iommu, linux-media, linux-arm-msm, kvm, linux-kernel,
Robin Murphy, Joerg Roedel, Will Deacon, Leon Romanovsky,
Sibi Sankar, Honglei Huang, prakash.gupta, Alex Williamson,
Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
Bryan O'Donoghue, Mauro Carvalho Chehab, Hans Verkuil, stable
On Fri, Nov 27, 2026 at 12:58:48PM +0100, Marek Szyprowski wrote:
> Commit 1acce29926d9 ("iommu/dma: simplify dma_iova_destroy() and drop
> the free_iova helper") turned dma_iova_destroy() into dma_iova_unlink()
> followed by dma_iova_free(). Before it, the destroy path marked its
> IOTLB gather as queued for DMA-FQ domains, skipped iommu_iotlb_sync()
> and handed the IOVA over to the flush queue, exactly like
> __iommu_dma_unmap(). After it:
>
> - dma_iova_unlink() never queues its gather and always calls
> iommu_iotlb_sync() after iommu_unmap_fast(),
> - dma_iova_free() passes a NULL gather to iommu_dma_free_iova(), so
> the IOVA goes straight back to the allocator via free_iova_fast().
>
> DMA-FQ domains therefore get strict invalidation on this path. This
> includes blk_rq_dma_map(), which NVMe uses for all data transfers, so
> iommu.strict=0 has no effect on NVMe I/O. On a Qualcomm Glymur CRD
> (SMMUv3 without RANGE_INV, 4K pages, NVMe on PCIe Gen5 x4) sequential
> fio throughput drops from 10.6/11.9 GiB/s (write/read) to the strict
> mode level of ~2.7 GiB/s.
>
> Instead of reverting, decide once in dma_iova_try_alloc() whether the
> IOVA space is going to be released through the flush queue and record
> it in a new DMA_IOVA_USE_FQ flag in dma_iova_state::__size, next to
> DMA_IOVA_USE_SWIOTLB, so struct dma_iova_state does not grow.
> dma_iova_destroy() then unmaps with a gather queued according to that
> flag, skipping the sync for flush queue domains, and passes the same
> gather to the IOVA free, so the IOVA space (and any page table pages
> released by the unmap) goes through queue_iova() again. dma_iova_free()
> honours the flag as well. The whole reservation is still freed, keeping
> the size fix of the reverted commit.
>
> A gather must always be retired, either by iommu_iotlb_sync() or by
> handing it to the flush queue together with the IOVA, and the IOVA must
> never be returned to the allocator while a queued invalidation for it is
> still pending. To keep that obvious, the internal unlink helper only
> unmaps into a gather supplied by its caller, and each caller retires it
> right away: dma_iova_destroy() syncs or queues it together with the IOVA
> free, exactly like __iommu_dma_unmap(), while dma_iova_unlink() always
> uses a never queued gather and syncs it, as the unlinked range remains
> owned by the caller and may be linked again immediately.
>
> Fixes: 1acce29926d9 ("iommu/dma: simplify dma_iova_destroy() and drop the free_iova helper")
> Reported-by: Sibi Sankar <sibi.sankar@oss.qualcomm.com>
> Closes: https://lore.kernel.org/all/20261125135120.1126571-1-sibi.sankar@oss.qualcomm.com/
> Suggested-by: Leon Romanovsky <leon@kernel.org>
> Cc: stable@vger.kernel.org # v7.3+
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> ---
> drivers/iommu/dma-iommu.c | 103 ++++++++++++++++++++++++++----------
> include/linux/dma-mapping.h | 8 ++-
> 2 files changed, 83 insertions(+), 28 deletions(-)
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Jason
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 4/4] iommu/dma: restore flush queue use in dma_iova_destroy()
2026-11-27 14:37 ` Jason Gunthorpe
@ 2026-11-27 14:45 ` Marek Szyprowski
2026-11-27 15:17 ` Jason Gunthorpe
0 siblings, 1 reply; 25+ messages in thread
From: Marek Szyprowski @ 2026-11-27 14:45 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: iommu, linux-media, linux-arm-msm, kvm, linux-kernel,
Robin Murphy, Joerg Roedel, Will Deacon, Leon Romanovsky,
Sibi Sankar, Honglei Huang, prakash.gupta, Alex Williamson,
Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
Bryan O'Donoghue, Mauro Carvalho Chehab, Hans Verkuil, stable
On 27.11.2026 15:37, Jason Gunthorpe wrote:
> On Fri, Nov 27, 2026 at 12:58:48PM +0100, Marek Szyprowski wrote:
>> Commit 1acce29926d9 ("iommu/dma: simplify dma_iova_destroy() and drop
>> the free_iova helper") turned dma_iova_destroy() into dma_iova_unlink()
>> followed by dma_iova_free(). Before it, the destroy path marked its
>> IOTLB gather as queued for DMA-FQ domains, skipped iommu_iotlb_sync()
>> and handed the IOVA over to the flush queue, exactly like
>> __iommu_dma_unmap(). After it:
>>
>> - dma_iova_unlink() never queues its gather and always calls
>> iommu_iotlb_sync() after iommu_unmap_fast(),
>> - dma_iova_free() passes a NULL gather to iommu_dma_free_iova(), so
>> the IOVA goes straight back to the allocator via free_iova_fast().
>>
>> DMA-FQ domains therefore get strict invalidation on this path. This
>> includes blk_rq_dma_map(), which NVMe uses for all data transfers, so
>> iommu.strict=0 has no effect on NVMe I/O. On a Qualcomm Glymur CRD
>> (SMMUv3 without RANGE_INV, 4K pages, NVMe on PCIe Gen5 x4) sequential
>> fio throughput drops from 10.6/11.9 GiB/s (write/read) to the strict
>> mode level of ~2.7 GiB/s.
>>
>> Instead of reverting, decide once in dma_iova_try_alloc() whether the
>> IOVA space is going to be released through the flush queue and record
>> it in a new DMA_IOVA_USE_FQ flag in dma_iova_state::__size, next to
>> DMA_IOVA_USE_SWIOTLB, so struct dma_iova_state does not grow.
>> dma_iova_destroy() then unmaps with a gather queued according to that
>> flag, skipping the sync for flush queue domains, and passes the same
>> gather to the IOVA free, so the IOVA space (and any page table pages
>> released by the unmap) goes through queue_iova() again. dma_iova_free()
>> honours the flag as well. The whole reservation is still freed, keeping
>> the size fix of the reverted commit.
>>
>> A gather must always be retired, either by iommu_iotlb_sync() or by
>> handing it to the flush queue together with the IOVA, and the IOVA must
>> never be returned to the allocator while a queued invalidation for it is
>> still pending. To keep that obvious, the internal unlink helper only
>> unmaps into a gather supplied by its caller, and each caller retires it
>> right away: dma_iova_destroy() syncs or queues it together with the IOVA
>> free, exactly like __iommu_dma_unmap(), while dma_iova_unlink() always
>> uses a never queued gather and syncs it, as the unlinked range remains
>> owned by the caller and may be linked again immediately.
>>
>> Fixes: 1acce29926d9 ("iommu/dma: simplify dma_iova_destroy() and drop the free_iova helper")
>> Reported-by: Sibi Sankar <sibi.sankar@oss.qualcomm.com>
>> Closes: https://lore.kernel.org/all/20261125135120.1126571-1-sibi.sankar@oss.qualcomm.com/
>> Suggested-by: Leon Romanovsky <leon@kernel.org>
>> Cc: stable@vger.kernel.org # v7.3+
>> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
>> ---
>> drivers/iommu/dma-iommu.c | 103 ++++++++++++++++++++++++++----------
>> include/linux/dma-mapping.h | 8 ++-
>> 2 files changed, 83 insertions(+), 28 deletions(-)
> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Thanks!
What about the issue pointed by sashiko.dev? My LLM said that this will fix it:
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 0e329ecd7dfa..106da975bf0f 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -1892,11 +1892,12 @@ static void __dma_iova_free(struct device *dev, struct dma_iova_state *state,
*/
void dma_iova_free(struct device *dev, struct dma_iova_state *state)
{
- struct iommu_iotlb_gather iotlb_gather;
-
- iommu_iotlb_gather_init(&iotlb_gather);
- iotlb_gather.queued = state->__size & DMA_IOVA_USE_FQ;
- __dma_iova_free(dev, state, &iotlb_gather);
+ /*
+ * Nothing is linked any more and every dma_iova_unlink() has already
+ * invalidated the IOTLB synchronously, so there is no deferred
+ * invalidation to wait for and the IOVA can be reused right away.
+ */
+ __dma_iova_free(dev, state, NULL);
}
EXPORT_SYMBOL_GPL(dma_iova_free);
@@ -2190,12 +2191,13 @@ void dma_iova_destroy(struct device *dev, struct dma_iova_state *state,
struct iommu_iotlb_gather iotlb_gather;
iommu_iotlb_gather_init(&iotlb_gather);
- iotlb_gather.queued = state->__size & DMA_IOVA_USE_FQ;
/*
* We can be here if the first call to dma_iova_link() failed and
- * there is nothing to unlink, so let's be more clear.
+ * there is nothing to unlink, so let's be more clear. Only queue the
+ * gather if there is an unmap whose invalidation can be deferred.
*/
+ iotlb_gather.queued = mapped_len && (state->__size & DMA_IOVA_USE_FQ);
if (mapped_len)
__dma_iova_unlink(dev, state, 0, mapped_len, dir, attrs,
&iotlb_gather);
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH 4/4] iommu/dma: restore flush queue use in dma_iova_destroy()
2026-11-27 14:45 ` Marek Szyprowski
@ 2026-11-27 15:17 ` Jason Gunthorpe
2026-11-27 16:29 ` Marek Szyprowski
0 siblings, 1 reply; 25+ messages in thread
From: Jason Gunthorpe @ 2026-11-27 15:17 UTC (permalink / raw)
To: Marek Szyprowski
Cc: iommu, linux-media, linux-arm-msm, kvm, linux-kernel,
Robin Murphy, Joerg Roedel, Will Deacon, Leon Romanovsky,
Sibi Sankar, Honglei Huang, prakash.gupta, Alex Williamson,
Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
Bryan O'Donoghue, Mauro Carvalho Chehab, Hans Verkuil, stable
On Fri, Nov 27, 2026 at 03:45:15PM +0100, Marek Szyprowski wrote:
> On 27.11.2026 15:37, Jason Gunthorpe wrote:
> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> index 0e329ecd7dfa..106da975bf0f 100644
> --- a/drivers/iommu/dma-iommu.c
> +++ b/drivers/iommu/dma-iommu.c
> @@ -1892,11 +1892,12 @@ static void __dma_iova_free(struct device *dev, struct dma_iova_state *state,
> */
> void dma_iova_free(struct device *dev, struct dma_iova_state *state)
> {
> - struct iommu_iotlb_gather iotlb_gather;
> -
> - iommu_iotlb_gather_init(&iotlb_gather);
> - iotlb_gather.queued = state->__size & DMA_IOVA_USE_FQ;
> - __dma_iova_free(dev, state, &iotlb_gather);
> + /*
> + * Nothing is linked any more and every dma_iova_unlink() has already
> + * invalidated the IOTLB synchronously, so there is no deferred
> + * invalidation to wait for and the IOVA can be reused right away.
> + */
> + __dma_iova_free(dev, state, NULL);
> }
> EXPORT_SYMBOL_GPL(dma_iova_free);
That makes sense, but I'm a little lost why we needed the
DMA_IOVA_USE_FQ ?
If any queued gather was ever created then the ultimate free has to
also be queued. But the comment implies that queued gathers were never
created in this case?
> @@ -2190,12 +2191,13 @@ void dma_iova_destroy(struct device *dev, struct dma_iova_state *state,
> struct iommu_iotlb_gather iotlb_gather;
>
> iommu_iotlb_gather_init(&iotlb_gather);
> - iotlb_gather.queued = state->__size & DMA_IOVA_USE_FQ;
>
> /*
> * We can be here if the first call to dma_iova_link() failed and
> - * there is nothing to unlink, so let's be more clear.
> + * there is nothing to unlink, so let's be more clear. Only queue the
> + * gather if there is an unmap whose invalidation can be deferred.
> */
Not sure what this comment means now? What invalidation cannot be deferred?
> + iotlb_gather.queued = mapped_len && (state->__size & DMA_IOVA_USE_FQ);
> if (mapped_len)
I'd probably put it inside the if..
Jason
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size
2026-11-27 14:29 ` Jason Gunthorpe
@ 2026-11-27 15:24 ` Leon Romanovsky
2026-11-27 17:21 ` Bryan O'Donoghue
1 sibling, 0 replies; 25+ messages in thread
From: Leon Romanovsky @ 2026-11-27 15:24 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Marek Szyprowski, iommu, linux-media, linux-arm-msm, kvm,
linux-kernel, Robin Murphy, Joerg Roedel, Will Deacon,
Sibi Sankar, Honglei Huang, prakash.gupta, Alex Williamson,
Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
Bryan O'Donoghue, Mauro Carvalho Chehab, Hans Verkuil, stable
On Fri, Nov 27, 2026 at 10:29:12AM -0400, Jason Gunthorpe wrote:
> On Fri, Nov 27, 2026 at 12:58:45PM +0100, Marek Szyprowski wrote:
> > The IOVA reservation code compares dma_iova_state::__size directly with
> > the requested chunk size. __size is internal to the DMA IOVA API and may
> > carry flags in its upper bits, so use the dma_iova_size() accessor
> > instead.
>
> WTF is this even doing?
>
> Fix this by reserving the 0-600MB range, below the boundary the
> non-pixel stream cannot address, using dma_iova_try_alloc() so the
> IOMMU-DMA core never hands that range out to a real DMA mapping. This
> reserves only IOVA space, it does not allocate any physical memory.
>
> That isn't what this API is for, and it isn't how it even works! It is
> pure luck that the first call to it happens to take out the lower
> address space.
>
> We even had a long discussion about this driver and this need in
> another thread and this is the hack job you guys merged?
You should also mention that NONE of the DMA/IOMMU developers or the authors
of that API were CCed when the change was merged.
https://lore.kernel.org/all/20260818-reserve_iova_in_driver-v2-2-5005a1154408@oss.qualcomm.com/
>
> And it couldn't even use the right APIs??!
And proposed for the stable@ :(
>
> Jason
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 4/4] iommu/dma: restore flush queue use in dma_iova_destroy()
2026-11-27 11:58 ` [PATCH 4/4] iommu/dma: restore flush queue use in dma_iova_destroy() Marek Szyprowski
2026-11-27 14:37 ` Jason Gunthorpe
@ 2026-11-27 15:31 ` Leon Romanovsky
1 sibling, 0 replies; 25+ messages in thread
From: Leon Romanovsky @ 2026-11-27 15:31 UTC (permalink / raw)
To: Marek Szyprowski
Cc: iommu, linux-media, linux-arm-msm, kvm, linux-kernel,
Robin Murphy, Joerg Roedel, Will Deacon, Jason Gunthorpe,
Sibi Sankar, Honglei Huang, prakash.gupta, Alex Williamson,
Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
Bryan O'Donoghue, Mauro Carvalho Chehab, Hans Verkuil, stable
On Fri, Nov 27, 2026 at 12:58:48PM +0100, Marek Szyprowski wrote:
> Commit 1acce29926d9 ("iommu/dma: simplify dma_iova_destroy() and drop
> the free_iova helper") turned dma_iova_destroy() into dma_iova_unlink()
> followed by dma_iova_free(). Before it, the destroy path marked its
> IOTLB gather as queued for DMA-FQ domains, skipped iommu_iotlb_sync()
> and handed the IOVA over to the flush queue, exactly like
> __iommu_dma_unmap(). After it:
>
> - dma_iova_unlink() never queues its gather and always calls
> iommu_iotlb_sync() after iommu_unmap_fast(),
> - dma_iova_free() passes a NULL gather to iommu_dma_free_iova(), so
> the IOVA goes straight back to the allocator via free_iova_fast().
>
> DMA-FQ domains therefore get strict invalidation on this path. This
> includes blk_rq_dma_map(), which NVMe uses for all data transfers, so
> iommu.strict=0 has no effect on NVMe I/O. On a Qualcomm Glymur CRD
> (SMMUv3 without RANGE_INV, 4K pages, NVMe on PCIe Gen5 x4) sequential
> fio throughput drops from 10.6/11.9 GiB/s (write/read) to the strict
> mode level of ~2.7 GiB/s.
>
> Instead of reverting, decide once in dma_iova_try_alloc() whether the
> IOVA space is going to be released through the flush queue and record
> it in a new DMA_IOVA_USE_FQ flag in dma_iova_state::__size, next to
> DMA_IOVA_USE_SWIOTLB, so struct dma_iova_state does not grow.
> dma_iova_destroy() then unmaps with a gather queued according to that
> flag, skipping the sync for flush queue domains, and passes the same
> gather to the IOVA free, so the IOVA space (and any page table pages
> released by the unmap) goes through queue_iova() again. dma_iova_free()
> honours the flag as well. The whole reservation is still freed, keeping
> the size fix of the reverted commit.
>
> A gather must always be retired, either by iommu_iotlb_sync() or by
> handing it to the flush queue together with the IOVA, and the IOVA must
> never be returned to the allocator while a queued invalidation for it is
> still pending. To keep that obvious, the internal unlink helper only
> unmaps into a gather supplied by its caller, and each caller retires it
> right away: dma_iova_destroy() syncs or queues it together with the IOVA
> free, exactly like __iommu_dma_unmap(), while dma_iova_unlink() always
> uses a never queued gather and syncs it, as the unlinked range remains
> owned by the caller and may be linked again immediately.
>
> Fixes: 1acce29926d9 ("iommu/dma: simplify dma_iova_destroy() and drop the free_iova helper")
> Reported-by: Sibi Sankar <sibi.sankar@oss.qualcomm.com>
> Closes: https://lore.kernel.org/all/20261125135120.1126571-1-sibi.sankar@oss.qualcomm.com/
> Suggested-by: Leon Romanovsky <leon@kernel.org>
> Cc: stable@vger.kernel.org # v7.3+
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> ---
> drivers/iommu/dma-iommu.c | 103 ++++++++++++++++++++++++++----------
> include/linux/dma-mapping.h | 8 ++-
> 2 files changed, 83 insertions(+), 28 deletions(-)
<...>
> /*
> * All flags stored in the upper bits of dma_iova_state::__size. Sizes passed
> * to dma_iova_try_alloc() must not overlap with them.
> */
> -#define DMA_IOVA_FLAGS DMA_IOVA_USE_SWIOTLB
> +#define DMA_IOVA_FLAGS (DMA_IOVA_USE_SWIOTLB | DMA_IOVA_USE_FQ)
We need to be careful here. Every bit reduces the IOVA space available to
everyone. It is only a matter of time before someone complains that __size
is too small for their use case. This extra bit is probably not an issue,
but that could change if we keep adding bits to DMA_IOVA_FLAGS.
Thanks
>
> static inline size_t dma_iova_size(struct dma_iova_state *state)
> {
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 4/4] iommu/dma: restore flush queue use in dma_iova_destroy()
2026-11-27 15:17 ` Jason Gunthorpe
@ 2026-11-27 16:29 ` Marek Szyprowski
2026-11-27 17:18 ` Marek Szyprowski
0 siblings, 1 reply; 25+ messages in thread
From: Marek Szyprowski @ 2026-11-27 16:29 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: iommu, linux-media, linux-arm-msm, kvm, linux-kernel,
Robin Murphy, Joerg Roedel, Will Deacon, Leon Romanovsky,
Sibi Sankar, Honglei Huang, prakash.gupta, Alex Williamson,
Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
Bryan O'Donoghue, Mauro Carvalho Chehab, Hans Verkuil, stable
On 27.11.2026 16:17, Jason Gunthorpe wrote:
> On Fri, Nov 27, 2026 at 03:45:15PM +0100, Marek Szyprowski wrote:
>
>> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
>> index 0e329ecd7dfa..106da975bf0f 100644
>> --- a/drivers/iommu/dma-iommu.c
>> +++ b/drivers/iommu/dma-iommu.c
>> @@ -1892,11 +1892,12 @@ static void __dma_iova_free(struct device *dev, struct dma_iova_state *state,
>> */
>> void dma_iova_free(struct device *dev, struct dma_iova_state *state)
>> {
>> - struct iommu_iotlb_gather iotlb_gather;
>> -
>> - iommu_iotlb_gather_init(&iotlb_gather);
>> - iotlb_gather.queued = state->__size & DMA_IOVA_USE_FQ;
>> - __dma_iova_free(dev, state, &iotlb_gather);
>> + /*
>> + * Nothing is linked any more and every dma_iova_unlink() has already
>> + * invalidated the IOTLB synchronously, so there is no deferred
>> + * invalidation to wait for and the IOVA can be reused right away.
>> + */
>> + __dma_iova_free(dev, state, NULL);
>> }
>> EXPORT_SYMBOL_GPL(dma_iova_free);
> That makes sense, but I'm a little lost why we needed the
> DMA_IOVA_USE_FQ ?
>
> If any queued gather was ever created then the ultimate free has to
> also be queued. But the comment implies that queued gathers were never
> created in this case?
Indeed there is no point caching domain->iova_cookie->fq_domain once the
dma_iova_free() doesn't use the gather. Now fq_domain can be directly
checked in dma_iova_destroy(). This simplifies things a lot. I will send v2
soon.
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 4/4] iommu/dma: restore flush queue use in dma_iova_destroy()
2026-11-27 16:29 ` Marek Szyprowski
@ 2026-11-27 17:18 ` Marek Szyprowski
0 siblings, 0 replies; 25+ messages in thread
From: Marek Szyprowski @ 2026-11-27 17:18 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: iommu, linux-media, linux-arm-msm, kvm, linux-kernel,
Robin Murphy, Joerg Roedel, Will Deacon, Leon Romanovsky,
Sibi Sankar, Honglei Huang, prakash.gupta, Alex Williamson,
Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
Bryan O'Donoghue, Mauro Carvalho Chehab, Hans Verkuil, stable
On 27.11.2026 17:29, Marek Szyprowski wrote:
> On 27.11.2026 16:17, Jason Gunthorpe wrote:
>> On Fri, Nov 27, 2026 at 03:45:15PM +0100, Marek Szyprowski wrote:
>>> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
>>> index 0e329ecd7dfa..106da975bf0f 100644
>>> --- a/drivers/iommu/dma-iommu.c
>>> +++ b/drivers/iommu/dma-iommu.c
>>> @@ -1892,11 +1892,12 @@ static void __dma_iova_free(struct device *dev, struct dma_iova_state *state,
>>> */
>>> void dma_iova_free(struct device *dev, struct dma_iova_state *state)
>>> {
>>> - struct iommu_iotlb_gather iotlb_gather;
>>> -
>>> - iommu_iotlb_gather_init(&iotlb_gather);
>>> - iotlb_gather.queued = state->__size & DMA_IOVA_USE_FQ;
>>> - __dma_iova_free(dev, state, &iotlb_gather);
>>> + /*
>>> + * Nothing is linked any more and every dma_iova_unlink() has already
>>> + * invalidated the IOTLB synchronously, so there is no deferred
>>> + * invalidation to wait for and the IOVA can be reused right away.
>>> + */
>>> + __dma_iova_free(dev, state, NULL);
>>> }
>>> EXPORT_SYMBOL_GPL(dma_iova_free);
>> That makes sense, but I'm a little lost why we needed the
>> DMA_IOVA_USE_FQ ?
>>
>> If any queued gather was ever created then the ultimate free has to
>> also be queued. But the comment implies that queued gathers were never
>> created in this case?
> Indeed there is no point caching domain->iova_cookie->fq_domain once the
> dma_iova_free() doesn't use the gather. Now fq_domain can be directly
> checked in dma_iova_destroy(). This simplifies things a lot. I will send v2
> soon.
v2:
https://lore.kernel.org/all/20261127171529.2917893-1-m.szyprowski@samsung.com/
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size
2026-11-27 14:29 ` Jason Gunthorpe
2026-11-27 15:24 ` Leon Romanovsky
@ 2026-11-27 17:21 ` Bryan O'Donoghue
2026-11-27 17:26 ` Jason Gunthorpe
2026-11-29 13:41 ` Bryan O'Donoghue
1 sibling, 2 replies; 25+ messages in thread
From: Bryan O'Donoghue @ 2026-11-27 17:21 UTC (permalink / raw)
To: Jason Gunthorpe, Marek Szyprowski
Cc: iommu, linux-media, linux-arm-msm, kvm, linux-kernel,
Robin Murphy, Joerg Roedel, Will Deacon, Leon Romanovsky,
Sibi Sankar, Honglei Huang, prakash.gupta, Alex Williamson,
Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
Mauro Carvalho Chehab, Hans Verkuil, stable
On 27/11/2026 14:29, Jason Gunthorpe wrote:
> On Fri, Nov 27, 2026 at 12:58:45PM +0100, Marek Szyprowski wrote:
>> The IOVA reservation code compares dma_iova_state::__size directly with
>> the requested chunk size. __size is internal to the DMA IOVA API and may
>> carry flags in its upper bits, so use the dma_iova_size() accessor
>> instead.
>
> WTF is this even doing?
>
> Fix this by reserving the 0-600MB range, below the boundary the
> non-pixel stream cannot address, using dma_iova_try_alloc() so the
> IOMMU-DMA core never hands that range out to a real DMA mapping. This
> reserves only IOVA space, it does not allocate any physical memory.
>
> That isn't what this API is for, and it isn't how it even works! It is
> pure luck that the first call to it happens to take out the lower
> address space.
>
> We even had a long discussion about this driver and this need in
> another thread and this is the hack job you guys merged?
Have to say I wasn't aware of an objection from you, I don't think I was
on that thread.
> And it couldn't even use the right APIs??!
>
> Jason
It would be possible to reserve this IOVA range in DT so given what
you've highlighted I think this and the Iris commit should be reverted
and the DT constraint implemented.
https://lore.kernel.org/lkml/20260601041336.9497-1-daniel@quora.org/
[PATCH 1/2]
https://lore.kernel.org/lkml/20260601041336.9497-2-daniel@quora.org/
[PATCH 2/2]
Already has RB from Krzysztof so I'm happy to re-up that.
https://lore.kernel.org/r/20260614145113.84243-1-daniel@quora.org
@Vikash I know that's not ideal from your perspective and may make the
iommu stuff you have proposed harder but, accepting this is a misuse of
the API and "happens to work" instead of "works by design", I don't see
much other option.
---
bod
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size
2026-11-27 17:21 ` Bryan O'Donoghue
@ 2026-11-27 17:26 ` Jason Gunthorpe
2026-11-28 8:55 ` Bryan O'Donoghue
2026-11-29 14:19 ` Vikash Garodia
2026-11-29 13:41 ` Bryan O'Donoghue
1 sibling, 2 replies; 25+ messages in thread
From: Jason Gunthorpe @ 2026-11-27 17:26 UTC (permalink / raw)
To: Bryan O'Donoghue
Cc: Marek Szyprowski, iommu, linux-media, linux-arm-msm, kvm,
linux-kernel, Robin Murphy, Joerg Roedel, Will Deacon,
Leon Romanovsky, Sibi Sankar, Honglei Huang, prakash.gupta,
Alex Williamson, Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
Mauro Carvalho Chehab, Hans Verkuil, stable
On Fri, Nov 27, 2026 at 05:21:35PM +0000, Bryan O'Donoghue wrote:
> On 27/11/2026 14:29, Jason Gunthorpe wrote:
> > On Fri, Nov 27, 2026 at 12:58:45PM +0100, Marek Szyprowski wrote:
> > > The IOVA reservation code compares dma_iova_state::__size directly with
> > > the requested chunk size. __size is internal to the DMA IOVA API and may
> > > carry flags in its upper bits, so use the dma_iova_size() accessor
> > > instead.
> >
> > WTF is this even doing?
> >
> > Fix this by reserving the 0-600MB range, below the boundary the
> > non-pixel stream cannot address, using dma_iova_try_alloc() so the
> > IOMMU-DMA core never hands that range out to a real DMA mapping. This
> > reserves only IOVA space, it does not allocate any physical memory.
> >
> > That isn't what this API is for, and it isn't how it even works! It is
> > pure luck that the first call to it happens to take out the lower
> > address space.
> >
> > We even had a long discussion about this driver and this need in
> > another thread and this is the hack job you guys merged?
>
> Have to say I wasn't aware of an objection from you, I don't think I was on
> that thread.
Nobody ever shared this insane thing with us. Seriously, this isn't
even remotely using these APIs for what they are for. Nobody thought
"hey this seems like a creative use of APIs, lets ask someone" ?
> It would be possible to reserve this IOVA range in DT so given what you've
> highlighted I think this and the Iris commit should be reverted and the DT
> constraint implemented.
That was the other thread, obviously using DT to describe a hardware
issue is the correct choice. But there was some problem where they
also wanted to split the SID space using DT and then the DT mechansim
doesn't work because the whole thing becomes too hacky :\
Jason
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size
2026-11-27 17:26 ` Jason Gunthorpe
@ 2026-11-28 8:55 ` Bryan O'Donoghue
2026-11-30 19:52 ` Jason Gunthorpe
2026-11-29 14:19 ` Vikash Garodia
1 sibling, 1 reply; 25+ messages in thread
From: Bryan O'Donoghue @ 2026-11-28 8:55 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Marek Szyprowski, iommu, linux-media, linux-arm-msm, kvm,
linux-kernel, Robin Murphy, Joerg Roedel, Will Deacon,
Leon Romanovsky, Sibi Sankar, Honglei Huang, prakash.gupta,
Alex Williamson, Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
Mauro Carvalho Chehab, Hans Verkuil, stable
On 27/11/2026 17:26, Jason Gunthorpe wrote:
>> It would be possible to reserve this IOVA range in DT so given what you've
>> highlighted I think this and the Iris commit should be reverted and the DT
>> constraint implemented.
> That was the other thread, obviously using DT to describe a hardware
> issue is the correct choice. But there was some problem where they
> also wanted to split the SID space using DT and then the DT mechansim
> doesn't work because the whole thing becomes too hacky :\
>
> Jason
Actually I've been looking for some resolution on this.
https://lore.kernel.org/linux-media/d0e76f09-a360-4c1d-bfab-c5658f2a69e0@kernel.org
There's been radio silence on the method from the iommu maintainers so I
haven't merged the DT that would come to depend on it.
If its mergable with changes then grand, if not then the approach needs
to be rolled back.
Either way several series in limbo and now this rollback.
I would like to do the right thing _once_ to resolve.
---
bod
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size
2026-11-27 17:21 ` Bryan O'Donoghue
2026-11-27 17:26 ` Jason Gunthorpe
@ 2026-11-29 13:41 ` Bryan O'Donoghue
1 sibling, 0 replies; 25+ messages in thread
From: Bryan O'Donoghue @ 2026-11-29 13:41 UTC (permalink / raw)
To: Jason Gunthorpe, Marek Szyprowski
Cc: iommu, linux-media, linux-arm-msm, kvm, linux-kernel,
Robin Murphy, Joerg Roedel, Will Deacon, Leon Romanovsky,
Sibi Sankar, Honglei Huang, prakash.gupta, Alex Williamson,
Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
Mauro Carvalho Chehab, Hans Verkuil, stable
On 27/11/2026 17:21, Bryan O'Donoghue wrote:
>
> Already has RB from Krzysztof so I'm happy to re-up that.
>
> https://lore.kernel.org/r/20260614145113.84243-1-daniel@quora.org
This won't work any more @reg is a required property => real physical
address is required, describing iova like this /reserved-memory is verboten.
---
bod
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size
2026-11-27 17:26 ` Jason Gunthorpe
2026-11-28 8:55 ` Bryan O'Donoghue
@ 2026-11-29 14:19 ` Vikash Garodia
2026-11-30 1:10 ` Bryan O'Donoghue
1 sibling, 1 reply; 25+ messages in thread
From: Vikash Garodia @ 2026-11-29 14:19 UTC (permalink / raw)
To: Jason Gunthorpe, Bryan O'Donoghue
Cc: Marek Szyprowski, iommu, linux-media, linux-arm-msm, kvm,
linux-kernel, Robin Murphy, Joerg Roedel, Will Deacon,
Leon Romanovsky, Sibi Sankar, Honglei Huang, prakash.gupta,
Alex Williamson, Dikshita Agarwal, Abhinav Kumar,
Mauro Carvalho Chehab, Hans Verkuil, stable
On 11/27/2026 10:56 PM, Jason Gunthorpe wrote:
> On Fri, Nov 27, 2026 at 05:21:35PM +0000, Bryan O'Donoghue wrote:
>> On 27/11/2026 14:29, Jason Gunthorpe wrote:
>>> On Fri, Nov 27, 2026 at 12:58:45PM +0100, Marek Szyprowski wrote:
>>>> The IOVA reservation code compares dma_iova_state::__size directly with
>>>> the requested chunk size. __size is internal to the DMA IOVA API and may
>>>> carry flags in its upper bits, so use the dma_iova_size() accessor
>>>> instead.
>>>
>>> WTF is this even doing?
>>>
>>> Fix this by reserving the 0-600MB range, below the boundary the
>>> non-pixel stream cannot address, using dma_iova_try_alloc() so the
>>> IOMMU-DMA core never hands that range out to a real DMA mapping. This
>>> reserves only IOVA space, it does not allocate any physical memory.
>>>
>>> That isn't what this API is for, and it isn't how it even works! It is
>>> pure luck that the first call to it happens to take out the lower
>>> address space.
>>>
>>> We even had a long discussion about this driver and this need in
>>> another thread and this is the hack job you guys merged?
>>
>> Have to say I wasn't aware of an objection from you, I don't think I was on
>> that thread.
>
> Nobody ever shared this insane thing with us. Seriously, this isn't
> even remotely using these APIs for what they are for. Nobody thought
> "hey this seems like a creative use of APIs, lets ask someone" ?
>
Sure, its a miss to add the maintainers of the file which defines the
api. Relying on b4 alone was not the right approach. Noted for any
future submissions.
>> It would be possible to reserve this IOVA range in DT so given what you've
>> highlighted I think this and the Iris commit should be reverted and the DT
>> constraint implemented.
>
> That was the other thread, obviously using DT to describe a hardware
> issue is the correct choice. But there was some problem where they
> also wanted to split the SID space using DT and then the DT mechansim
> doesn't work because the whole thing becomes too hacky :\
>
We discussed this earlier here[1] and concluded DT as the right place to
address this.
The DT approach is waiting for the series [2] to land, which should take
care of the reservation in a definite way.
[1]
https://lore.kernel.org/all/c7b956a9-d3e8-4e18-b780-5d08f5cd2ca1@kernel.org/
[2]
https://lore.kernel.org/all/20261120-add_iommu_ranges-v8-0-d90486973b73@oss.qualcomm.com/
Regards,
Vikash
> Jason
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size
2026-11-29 14:19 ` Vikash Garodia
@ 2026-11-30 1:10 ` Bryan O'Donoghue
2026-11-30 6:15 ` Vikash Garodia
` (2 more replies)
0 siblings, 3 replies; 25+ messages in thread
From: Bryan O'Donoghue @ 2026-11-30 1:10 UTC (permalink / raw)
To: Vikash Garodia, Jason Gunthorpe
Cc: Marek Szyprowski, iommu, linux-media, linux-arm-msm, kvm,
linux-kernel, Robin Murphy, Joerg Roedel, Will Deacon,
Leon Romanovsky, Sibi Sankar, Honglei Huang, prakash.gupta,
Alex Williamson, Dikshita Agarwal, Abhinav Kumar,
Mauro Carvalho Chehab, Hans Verkuil, stable
On 29/11/2026 14:19, Vikash Garodia wrote:
>
> On 11/27/2026 10:56 PM, Jason Gunthorpe wrote:
>> On Fri, Nov 27, 2026 at 05:21:35PM +0000, Bryan O'Donoghue wrote:
>>> On 27/11/2026 14:29, Jason Gunthorpe wrote:
>>>> On Fri, Nov 27, 2026 at 12:58:45PM +0100, Marek Szyprowski wrote:
>>>>> The IOVA reservation code compares dma_iova_state::__size directly with
>>>>> the requested chunk size. __size is internal to the DMA IOVA API and may
>>>>> carry flags in its upper bits, so use the dma_iova_size() accessor
>>>>> instead.
>>>>
>>>> WTF is this even doing?
>>>>
>>>> Fix this by reserving the 0-600MB range, below the boundary the
>>>> non-pixel stream cannot address, using dma_iova_try_alloc() so the
>>>> IOMMU-DMA core never hands that range out to a real DMA mapping. This
>>>> reserves only IOVA space, it does not allocate any physical memory.
>>>>
>>>> That isn't what this API is for, and it isn't how it even works! It is
>>>> pure luck that the first call to it happens to take out the lower
>>>> address space.
>>>>
>>>> We even had a long discussion about this driver and this need in
>>>> another thread and this is the hack job you guys merged?
>>>
>>> Have to say I wasn't aware of an objection from you, I don't think I was on
>>> that thread.
>>
>> Nobody ever shared this insane thing with us. Seriously, this isn't
>> even remotely using these APIs for what they are for. Nobody thought
>> "hey this seems like a creative use of APIs, lets ask someone" ?
>>
>
> Sure, its a miss to add the maintainers of the file which defines the
> api. Relying on b4 alone was not the right approach. Noted for any
> future submissions.
>
>>> It would be possible to reserve this IOVA range in DT so given what you've
>>> highlighted I think this and the Iris commit should be reverted and the DT
>>> constraint implemented.
>>
>> That was the other thread, obviously using DT to describe a hardware
>> issue is the correct choice. But there was some problem where they
>> also wanted to split the SID space using DT and then the DT mechansim
>> doesn't work because the whole thing becomes too hacky :\
>>
>
> We discussed this earlier here[1] and concluded DT as the right place to
> address this.
> The DT approach is waiting for the series [2] to land, which should take
> care of the reservation in a definite way.
>
> [1]
> https://lore.kernel.org/all/c7b956a9-d3e8-4e18-b780-5d08f5cd2ca1@kernel.org/
>
> [2]
> https://lore.kernel.org/all/20261120-add_iommu_ranges-v8-0-d90486973b73@oss.qualcomm.com/
The other direction is to have venus and iris register their own IOMMU
domain and then the address allocator they will provide places the floor
at 600MB for the SID.
Jason, do you think this is the right approach ?
drivers/media/platform/nvidia/tegra-vde/
vde->domain = iommu_paging_domain_alloc(dev);
if (IS_ERR(vde->domain)) {
err = PTR_ERR(vde->domain);
vde->domain = NULL;
goto put_group;
}
err = iova_cache_get();
if (err)
goto free_domain;
order = __ffs(vde->domain->pgsize_bitmap);
init_iova_domain(&vde->iova, 1UL << order, 0);
err = iommu_attach_group(vde->domain, vde->group);
if (err)
goto put_iova;
/*
* We're using some static addresses that are not accessible by VDE
* to trap invalid memory accesses.
*/
shift = iova_shift(&vde->iova);
iova = reserve_iova(&vde->iova, 0x60000000 >> shift,
0x70000000 >> shift);
if (!iova) {
err = -ENOMEM;
goto detach_group;
}
Vikash I can prototype this up it, reverting Vishnu's patch will bring
back the reset and the upstream code now relies on dodgy behaviours. If
iommu-ranges lands, we can go back to using the default IOMMU domain and
drop rolling our own allocations.
---
bod
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size
2026-11-30 1:10 ` Bryan O'Donoghue
@ 2026-11-30 6:15 ` Vikash Garodia
2026-11-30 9:09 ` Marek Szyprowski
2026-11-30 19:54 ` Jason Gunthorpe
2 siblings, 0 replies; 25+ messages in thread
From: Vikash Garodia @ 2026-11-30 6:15 UTC (permalink / raw)
To: Bryan O'Donoghue, Jason Gunthorpe
Cc: Marek Szyprowski, iommu, linux-media, linux-arm-msm, kvm,
linux-kernel, Robin Murphy, Joerg Roedel, Will Deacon,
Leon Romanovsky, Sibi Sankar, Honglei Huang, prakash.gupta,
Alex Williamson, Dikshita Agarwal, Abhinav Kumar,
Mauro Carvalho Chehab, Hans Verkuil, stable
On 11/30/2026 6:40 AM, Bryan O'Donoghue wrote:
> On 29/11/2026 14:19, Vikash Garodia wrote:
>>
>> On 11/27/2026 10:56 PM, Jason Gunthorpe wrote:
>>> On Fri, Nov 27, 2026 at 05:21:35PM +0000, Bryan O'Donoghue wrote:
>>>> On 27/11/2026 14:29, Jason Gunthorpe wrote:
>>>>> On Fri, Nov 27, 2026 at 12:58:45PM +0100, Marek Szyprowski wrote:
>>>>>> The IOVA reservation code compares dma_iova_state::__size directly
>>>>>> with
>>>>>> the requested chunk size. __size is internal to the DMA IOVA API
>>>>>> and may
>>>>>> carry flags in its upper bits, so use the dma_iova_size() accessor
>>>>>> instead.
>>>>>
>>>>> WTF is this even doing?
>>>>>
>>>>> Fix this by reserving the 0-600MB range, below the boundary the
>>>>> non-pixel stream cannot address, using dma_iova_try_alloc()
>>>>> so the
>>>>> IOMMU-DMA core never hands that range out to a real DMA
>>>>> mapping. This
>>>>> reserves only IOVA space, it does not allocate any physical
>>>>> memory.
>>>>>
>>>>> That isn't what this API is for, and it isn't how it even works! It is
>>>>> pure luck that the first call to it happens to take out the lower
>>>>> address space.
>>>>>
>>>>> We even had a long discussion about this driver and this need in
>>>>> another thread and this is the hack job you guys merged?
>>>>
>>>> Have to say I wasn't aware of an objection from you, I don't think I
>>>> was on
>>>> that thread.
>>>
>>> Nobody ever shared this insane thing with us. Seriously, this isn't
>>> even remotely using these APIs for what they are for. Nobody thought
>>> "hey this seems like a creative use of APIs, lets ask someone" ?
>>>
>>
>> Sure, its a miss to add the maintainers of the file which defines the
>> api. Relying on b4 alone was not the right approach. Noted for any
>> future submissions.
>>
>>>> It would be possible to reserve this IOVA range in DT so given what
>>>> you've
>>>> highlighted I think this and the Iris commit should be reverted and
>>>> the DT
>>>> constraint implemented.
>>>
>>> That was the other thread, obviously using DT to describe a hardware
>>> issue is the correct choice. But there was some problem where they
>>> also wanted to split the SID space using DT and then the DT mechansim
>>> doesn't work because the whole thing becomes too hacky :\
>>>
>>
>> We discussed this earlier here[1] and concluded DT as the right place to
>> address this.
>> The DT approach is waiting for the series [2] to land, which should take
>> care of the reservation in a definite way.
>>
>> [1]
>> https://lore.kernel.org/all/c7b956a9-d3e8-4e18-
>> b780-5d08f5cd2ca1@kernel.org/
>>
>> [2]
>> https://lore.kernel.org/all/20261120-add_iommu_ranges-v8-0-
>> d90486973b73@oss.qualcomm.com/
> The other direction is to have venus and iris register their own IOMMU
> domain and then the address allocator they will provide places the floor
> at 600MB for the SID.
>
> Jason, do you think this is the right approach ?
>
> drivers/media/platform/nvidia/tegra-vde/
>
> vde->domain = iommu_paging_domain_alloc(dev);
> if (IS_ERR(vde->domain)) {
> err = PTR_ERR(vde->domain);
> vde->domain = NULL;
> goto put_group;
> }
>
> err = iova_cache_get();
> if (err)
> goto free_domain;
>
> order = __ffs(vde->domain->pgsize_bitmap);
> init_iova_domain(&vde->iova, 1UL << order, 0);
>
> err = iommu_attach_group(vde->domain, vde->group);
> if (err)
> goto put_iova;
>
> /*
> * We're using some static addresses that are not accessible by
> VDE
> * to trap invalid memory accesses.
> */
> shift = iova_shift(&vde->iova);
> iova = reserve_iova(&vde->iova, 0x60000000 >> shift,
> 0x70000000 >> shift);
> if (!iova) {
> err = -ENOMEM;
> goto detach_group;
> }
>
> Vikash I can prototype this up it, reverting Vishnu's patch will bring
> back the reset and the upstream code now relies on dodgy behaviours.
> If iommu-ranges lands, we can go back to using the default IOMMU domain and
> drop rolling our own allocations.
What's holding up the iommu-ranges patches? They've been pending for a
while, and we’re waiting for maintainers to confirm whether they’re
ready to apply or have any further suggestions..
>
> ---
> bod
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size
2026-11-30 1:10 ` Bryan O'Donoghue
2026-11-30 6:15 ` Vikash Garodia
@ 2026-11-30 9:09 ` Marek Szyprowski
2026-11-30 19:54 ` Jason Gunthorpe
2 siblings, 0 replies; 25+ messages in thread
From: Marek Szyprowski @ 2026-11-30 9:09 UTC (permalink / raw)
To: Bryan O'Donoghue, Vikash Garodia, Jason Gunthorpe
Cc: iommu, linux-media, linux-arm-msm, kvm, linux-kernel,
Robin Murphy, Joerg Roedel, Will Deacon, Leon Romanovsky,
Sibi Sankar, Honglei Huang, prakash.gupta, Alex Williamson,
Dikshita Agarwal, Abhinav Kumar, Mauro Carvalho Chehab,
Hans Verkuil, stable
On 30.11.2026 02:10, Bryan O'Donoghue wrote:
> On 29/11/2026 14:19, Vikash Garodia wrote:
>>
>> On 11/27/2026 10:56 PM, Jason Gunthorpe wrote:
>>> On Fri, Nov 27, 2026 at 05:21:35PM +0000, Bryan O'Donoghue wrote:
>>>> On 27/11/2026 14:29, Jason Gunthorpe wrote:
>>>>> On Fri, Nov 27, 2026 at 12:58:45PM +0100, Marek Szyprowski wrote:
>>>>>> The IOVA reservation code compares dma_iova_state::__size directly with
>>>>>> the requested chunk size. __size is internal to the DMA IOVA API and may
>>>>>> carry flags in its upper bits, so use the dma_iova_size() accessor
>>>>>> instead.
>>>>>
>>>>> WTF is this even doing?
>>>>>
>>>>> Fix this by reserving the 0-600MB range, below the boundary the
>>>>> non-pixel stream cannot address, using dma_iova_try_alloc() so the
>>>>> IOMMU-DMA core never hands that range out to a real DMA mapping. This
>>>>> reserves only IOVA space, it does not allocate any physical memory.
>>>>>
>>>>> That isn't what this API is for, and it isn't how it even works! It is
>>>>> pure luck that the first call to it happens to take out the lower
>>>>> address space.
>>>>>
>>>>> We even had a long discussion about this driver and this need in
>>>>> another thread and this is the hack job you guys merged?
>>>>
>>>> Have to say I wasn't aware of an objection from you, I don't think I was on
>>>> that thread.
>>>
>>> Nobody ever shared this insane thing with us. Seriously, this isn't
>>> even remotely using these APIs for what they are for. Nobody thought
>>> "hey this seems like a creative use of APIs, lets ask someone" ?
>>>
>>
>> Sure, its a miss to add the maintainers of the file which defines the
>> api. Relying on b4 alone was not the right approach. Noted for any
>> future submissions.
>>
>>>> It would be possible to reserve this IOVA range in DT so given what you've
>>>> highlighted I think this and the Iris commit should be reverted and the DT
>>>> constraint implemented.
>>>
>>> That was the other thread, obviously using DT to describe a hardware
>>> issue is the correct choice. But there was some problem where they
>>> also wanted to split the SID space using DT and then the DT mechansim
>>> doesn't work because the whole thing becomes too hacky :\
>>>
>>
>> We discussed this earlier here[1] and concluded DT as the right place to
>> address this.
>> The DT approach is waiting for the series [2] to land, which should take
>> care of the reservation in a definite way.
>>
>> [1]
>> https://lore.kernel.org/all/c7b956a9-d3e8-4e18-b780-5d08f5cd2ca1@kernel.org/
>>
>> [2]
>> https://lore.kernel.org/all/20261120-add_iommu_ranges-v8-0-d90486973b73@oss.qualcomm.com/
> The other direction is to have venus and iris register their own IOMMU domain and then the address allocator they will provide places the floor at 600MB for the SID.
>
> Jason, do you think this is the right approach ?
>
> drivers/media/platform/nvidia/tegra-vde/
>
> vde->domain = iommu_paging_domain_alloc(dev);
> if (IS_ERR(vde->domain)) {
> err = PTR_ERR(vde->domain);
> vde->domain = NULL;
> goto put_group;
> }
>
> err = iova_cache_get();
> if (err)
> goto free_domain;
>
> order = __ffs(vde->domain->pgsize_bitmap);
> init_iova_domain(&vde->iova, 1UL << order, 0);
>
> err = iommu_attach_group(vde->domain, vde->group);
> if (err)
> goto put_iova;
>
> /*
> * We're using some static addresses that are not accessible by VDE
> * to trap invalid memory accesses.
> */
> shift = iova_shift(&vde->iova);
> iova = reserve_iova(&vde->iova, 0x60000000 >> shift,
> 0x70000000 >> shift);
> if (!iova) {
> err = -ENOMEM;
> goto detach_group;
> }
>
> Vikash I can prototype this up it, reverting Vishnu's patch will bring back the reset and the upstream code now relies on dodgy behaviours. If iommu-ranges lands, we can go back to using the default IOMMU domain and drop rolling our own allocations.
Well, the iris/venus driver case clearly shows that there are devices which
does some 'weird' assumptions about the IOVA values. I encountered the similar
issue long time ago when I tried to port legacy Exynos multimedia drivers to
the proposed ARM 32bit migration to generic IOMMU-DMA layer. IMHO all what
those drivers need to fully use the IOMMU-DMA glue and generic DMA-mapping
API is to let them to mark some parts of the IOVA address space as reserved.
I'm not sure if this has to be exposed in device-tree though.
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size
2026-11-28 8:55 ` Bryan O'Donoghue
@ 2026-11-30 19:52 ` Jason Gunthorpe
0 siblings, 0 replies; 25+ messages in thread
From: Jason Gunthorpe @ 2026-11-30 19:52 UTC (permalink / raw)
To: Bryan O'Donoghue
Cc: Marek Szyprowski, iommu, linux-media, linux-arm-msm, kvm,
linux-kernel, Robin Murphy, Joerg Roedel, Will Deacon,
Leon Romanovsky, Sibi Sankar, Honglei Huang, prakash.gupta,
Alex Williamson, Vikash Garodia, Dikshita Agarwal, Abhinav Kumar,
Mauro Carvalho Chehab, Hans Verkuil, stable
On Sat, Nov 28, 2026 at 08:55:20AM +0000, Bryan O'Donoghue wrote:
> On 27/11/2026 17:26, Jason Gunthorpe wrote:
> > > It would be possible to reserve this IOVA range in DT so given what you've
> > > highlighted I think this and the Iris commit should be reverted and the DT
> > > constraint implemented.
> > That was the other thread, obviously using DT to describe a hardware
> > issue is the correct choice. But there was some problem where they
> > also wanted to split the SID space using DT and then the DT mechansim
> > doesn't work because the whole thing becomes too hacky :\
> >
> > Jason
>
> Actually I've been looking for some resolution on this.
>
> https://lore.kernel.org/linux-media/d0e76f09-a360-4c1d-bfab-c5658f2a69e0@kernel.org
>
> There's been radio silence on the method from the iommu maintainers so I
> haven't merged the DT that would come to depend on it.
I don't know alot about that, it seems OK to me at first blush, but
Robin is the expert there.
Jason
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size
2026-11-30 1:10 ` Bryan O'Donoghue
2026-11-30 6:15 ` Vikash Garodia
2026-11-30 9:09 ` Marek Szyprowski
@ 2026-11-30 19:54 ` Jason Gunthorpe
2 siblings, 0 replies; 25+ messages in thread
From: Jason Gunthorpe @ 2026-11-30 19:54 UTC (permalink / raw)
To: Bryan O'Donoghue
Cc: Vikash Garodia, Marek Szyprowski, iommu, linux-media,
linux-arm-msm, kvm, linux-kernel, Robin Murphy, Joerg Roedel,
Will Deacon, Leon Romanovsky, Sibi Sankar, Honglei Huang,
prakash.gupta, Alex Williamson, Dikshita Agarwal, Abhinav Kumar,
Mauro Carvalho Chehab, Hans Verkuil, stable
On Mon, Nov 30, 2026 at 01:10:03AM +0000, Bryan O'Donoghue wrote:
> The other direction is to have venus and iris register their own IOMMU
> domain and then the address allocator they will provide places the floor at
> 600MB for the SID.
>
> Jason, do you think this is the right approach ?
There is yet another thread about this too, and you shouldn't this
because you loose the DMA API and all the cache flushing it gives.
I suggested that people who want this should follow the old design of
PASID to get a dummy struct device just for the DMA API to use with
its own private iommu domain.
However, that still leaves us with the issue here that the DMA API is
not aware of the weird HW limitation.
> drivers/media/platform/nvidia/tegra-vde/
>
> vde->domain = iommu_paging_domain_alloc(dev);
> if (IS_ERR(vde->domain)) {
> err = PTR_ERR(vde->domain);
> vde->domain = NULL;
> goto put_group;
> }
>
> err = iova_cache_get();
> if (err)
> goto free_domain;
>
> order = __ffs(vde->domain->pgsize_bitmap);
> init_iova_domain(&vde->iova, 1UL << order, 0);
>
> err = iommu_attach_group(vde->domain, vde->group);
> if (err)
> goto put_iova;
>
> /*
> * We're using some static addresses that are not accessible by VDE
> * to trap invalid memory accesses.
> */
> shift = iova_shift(&vde->iova);
> iova = reserve_iova(&vde->iova, 0x60000000 >> shift,
> 0x70000000 >> shift);
Is this HW or software that is motivating this carve out? I was never
clear on that..
Jason
^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2026-11-30 19:55 UTC | newest]
Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CGME20261127115859eucas1p1ae20b01eec39080daf19dbd71aba10e9@eucas1p1.samsung.com>
[not found] ` <20261127115849.2780625-1-m.szyprowski@samsung.com>
2026-11-27 11:58 ` [PATCH 1/4] media: venus: use dma_iova_size() to check the reserved IOVA size Marek Szyprowski
2026-11-27 12:41 ` Vikash Garodia
2026-11-27 14:29 ` Jason Gunthorpe
2026-11-27 15:24 ` Leon Romanovsky
2026-11-27 17:21 ` Bryan O'Donoghue
2026-11-27 17:26 ` Jason Gunthorpe
2026-11-28 8:55 ` Bryan O'Donoghue
2026-11-30 19:52 ` Jason Gunthorpe
2026-11-29 14:19 ` Vikash Garodia
2026-11-30 1:10 ` Bryan O'Donoghue
2026-11-30 6:15 ` Vikash Garodia
2026-11-30 9:09 ` Marek Szyprowski
2026-11-30 19:54 ` Jason Gunthorpe
2026-11-29 13:41 ` Bryan O'Donoghue
2026-11-27 11:58 ` [PATCH 2/4] media: iris: " Marek Szyprowski
2026-11-27 12:41 ` Vikash Garodia
2026-11-27 11:58 ` [PATCH 3/4] dma-mapping: add DMA_IOVA_FLAGS mask for the dma_iova_state size flags Marek Szyprowski
2026-11-27 14:37 ` Jason Gunthorpe
2026-11-27 11:58 ` [PATCH 4/4] iommu/dma: restore flush queue use in dma_iova_destroy() Marek Szyprowski
2026-11-27 14:37 ` Jason Gunthorpe
2026-11-27 14:45 ` Marek Szyprowski
2026-11-27 15:17 ` Jason Gunthorpe
2026-11-27 16:29 ` Marek Szyprowski
2026-11-27 17:18 ` Marek Szyprowski
2026-11-27 15:31 ` Leon Romanovsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox