From: sashiko-bot@kernel.org
To: "Marek Szyprowski" <m.szyprowski@samsung.com>, kvm@vger.kernel.org
Cc: media-ci@linuxtv.org
Subject: Re: [PATCH 4/4] iommu/dma: restore flush queue use in dma_iova_destroy()
Date: Fri, 27 Nov 2026 12:12:23 +0000 [thread overview]
Message-ID: <sashiko-outbox-237331@kernel.org> (raw)
In-Reply-To: <20261127115849.2780625-5-m.szyprowski@samsung.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] iommu/dma: unnecessary flush queue use in dma_iova_free()
--
commit 7f3e82cb1115d261e31845270a947f770830fc8e
Author: Marek Szyprowski <m.szyprowski@samsung.com>
iommu/dma: restore flush queue use in dma_iova_destroy()
This commit records whether an IOVA reservation should be released through
the IOMMU flush queue in a new DMA_IOVA_USE_FQ flag in
dma_iova_state::__size, and restores deferred IOTLB invalidation and IOVA
queuing in dma_iova_destroy() and dma_iova_free().
> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> index 99eb382a13597..0e329ecd7dfad 100644
> --- a/drivers/iommu/dma-iommu.c
> +++ b/drivers/iommu/dma-iommu.c
[ ... ]
> @@ -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);
[ ... ]
> @@ -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);
[Severity: Medium]
Does queuing the IOVA in dma_iova_free() (and in dma_iova_destroy() when
mapped_len is 0) put already-flushed or never-mapped reservations onto the
flush queue?
When dma_iova_free() is called, either no range was ever linked or all
linked ranges were already unmapped by dma_iova_unlink(), which always
runs a synchronous iommu_iotlb_sync(). Because no deferred IOTLB
invalidation or page-table freelist is pending, passing a queued gather to
__dma_iova_free() routes the IOVA through queue_iova() instead of
free_iova_fast(). Callers such as __drm_gpusvm_unmap_pages() that call
dma_iova_unlink() followed by dma_iova_free() pay for the synchronous
IOTLB sync during unlink and then still quarantine the IOVA and arm
fq_timer for a full-domain flush_iotlb_all().
Passing a NULL gather from dma_iova_free() and only setting
iotlb_gather.queued when mapped_len is non-zero in dma_iova_destroy()
would return these IOVAs straight to free_iova_fast().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127115849.2780625-1-m.szyprowski@samsung.com?part=4
next prev parent reply other threads:[~2026-11-27 12:12 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20261127115858eucas1p1ac63e4ce0f221453e8666ab9723a2ae0@eucas1p1.samsung.com>
2026-11-27 11:58 ` [PATCH 0/4] iommu/dma: restore flush queue use in dma_iova_destroy() Marek Szyprowski
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 12:12 ` sashiko-bot [this message]
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
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=sashiko-outbox-237331@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=media-ci@linuxtv.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 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.