From: sashiko-bot@kernel.org
To: "Krzysztof Karas" <krzysztof.karas@intel.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/3] drivers/iommu: Unroll unsuccessful mapping
Date: Thu, 25 Jun 2026 13:57:10 +0000 [thread overview]
Message-ID: <20260625135710.C69871F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260625134342.1102921-2-krzysztof.karas@intel.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] iommu_map_sg() fails to map accumulated scatterlist segments if they are followed by a physically contiguous bus address segment, leading to silent partial mapping drops. The patch mitigates the resulting resource leak in iommu_dma_map_sg() but leaves this root cause unaddressed.
--
commit 28ae7323f36f7853e142160b68651789c5fed2b2
Author: Krzysztof Karas <krzysztof.karas@intel.com>
drivers/iommu: Unroll unsuccessful mapping
This commit addresses an issue where partially successful IOMMU mappings
could leave untouched bytes unmapped, potentially leading to memory leaks.
It updates iommu_dma_map_sg() to unmap any partially mapped bytes before
freeing the IOVA and returning an error.
> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> index e8d4c2dac4da8..78a12c12b5eae 100644
> --- a/drivers/iommu/dma-iommu.c
> +++ b/drivers/iommu/dma-iommu.c
> @@ -1515,8 +1515,14 @@ int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
> * implementation - it knows better than we do.
> */
> ret = iommu_map_sg(domain, iova, sg, nents, prot, GFP_ATOMIC);
> - if (ret < 0 || ret < iova_len)
> + if (ret < 0 || ret < iova_len) {
> + if (ret > 0) {
> + /* Unmap partially mapped bytes before freeing IOVA */
> + if (iommu_unmap(domain, iova, ret) != ret)
> + ret = -EIO;
> + }
> goto out_free_iova;
> + }
[Severity: High]
This isn't a bug introduced by this patch, but while this mitigates the
resulting resource leak in iommu_dma_map_sg() when a short map occurs, does
the underlying cause of the short map still exist in iommu_map_sg()?
Looking at iommu_map_sg() in drivers/iommu/iommu.c:
while (i <= nents) {
phys_addr_t s_phys = sg_phys(sg);
if (len && s_phys != start + len) {
ret = iommu_map_nosync(domain, iova + mapped, start,
len, prot, gfp);
if (ret)
goto out_err;
mapped += len;
len = 0;
}
if (sg_dma_is_bus_address(sg))
goto next;
If a normal scatterlist segment is followed by a P2PDMA bus address segment
that happens to be physically contiguous with it (s_phys == start + len),
the flush condition is bypassed. The bus segment is then skipped via goto next,
leaving the accumulated len of the normal segment trapped.
If this happens at the end of the list, the normal segment is never flushed
and silently dropped, leading to a short map where mapped < total_len.
Could this lead to valid DMA mapping requests failing or devices performing
DMA into unmapped IOVA space if callers don't strictly validate the mapped
length?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260625134342.1102921-1-krzysztof.karas@intel.com?part=1
next prev parent reply other threads:[~2026-06-25 13:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-25 13:43 [PATCH 0/3] drivers: Improve memory management for large object allocations when i915/shmem is used with iommu Krzysztof Karas
2026-06-25 13:43 ` [PATCH 1/3] drivers/iommu: Unroll unsuccessful mapping Krzysztof Karas
2026-06-25 13:57 ` sashiko-bot [this message]
2026-06-25 14:29 ` Robin Murphy
2026-06-25 15:48 ` Michał Grzelak
2026-06-25 13:43 ` [PATCH 2/3] drm/i915/gem: split shared memory allocation table logic Krzysztof Karas
2026-06-25 13:54 ` sashiko-bot
2026-06-25 13:43 ` [PATCH 3/3] drm/i915/shmem: Count mapped pages in a folio Krzysztof Karas
2026-06-25 16:43 ` ✓ i915.CI.BAT: success for drivers: Improve memory management for large object allocations when i915/shmem is used with iommu Patchwork
2026-06-25 23:16 ` ✗ i915.CI.Full: failure " Patchwork
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=20260625135710.C69871F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=krzysztof.karas@intel.com \
--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.