All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: dhu@x6u.co
Cc: dri-devel@lists.freedesktop.org, media-ci@linuxtv.org
Subject: Re: [PATCH v3] dma-buf: Split sgl by largest page-aligned chunk
Date: Thu, 23 Jul 2026 00:02:13 +0000	[thread overview]
Message-ID: <20260723000213.D6E311F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260722233806.3922093-1-dhu@x6u.co>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but in the error handling path `err_unmap_dma`, `for_each_sgtable_dma_sg` incorrectly iterates over all allocated entries and calls `dma_unmap_phys` on zero-initialized memory.
- [High] This problem wasn't introduced by this patch, but in the error handling path `err_unmap_dma`, if mapping fails on the very first iteration (`i == 0`), it skips cleaning up the IOVA state, permanently leaking the IOVA space.
--

--- Patch [1]: [PATCH v3] dma-buf: Split sgl by largest page-aligned chunk ---
commit 4626127ac68c48120c89f9454d7c72b3a29300b8
Author: David Hu <xuehaohu@google.com>

dma-buf: Split sgl by largest page-aligned chunk

This commit modifies the scatterlist splitting logic to use the largest
page-aligned chunk instead of UINT_MAX. This ensures that scatterlist
DMA lengths and addresses remain page-aligned. The change prevents
hardware DMA engine failures and addresses an edge case in
ib_umem_find_best_pgsz().

Closes: https://lore.kernel.org/all/20260609165431.778061F00893@smtp.kernel.org/
Fixes: 3aa31a8bb11e ("dma-buf: provide phys_vec to scatter-gather mapping routine")
Cc: stable@vger.kernel.org

> diff --git a/drivers/dma-buf/dma-buf-mapping.c b/drivers/dma-buf/dma-buf-mapping.c
> index 794acff2546a3..50ded9daf5fb3 100644
> --- a/drivers/dma-buf/dma-buf-mapping.c
> +++ b/drivers/dma-buf/dma-buf-mapping.c

[ ... ]

While looking at this file, I noticed a couple of pre-existing issues in
dma_buf_phys_vec_to_sgt().

> err_unmap_dma:
> 	if (!i || !dma->state) {
> 		; /* Do nothing */

[Severity: High]
This isn't a bug introduced by this patch, but if mapping fails on the very
first iteration (i == 0), will this skip cleaning up the IOVA state?

If PCI_P2PDMA_MAP_THRU_HOST_BRIDGE is used, dma_iova_try_alloc() allocates
IOVA space before the mapping loop. If the very first dma_iova_link() fails,
the error path jumps here. Since !i evaluates to true, the code skips
calling dma_iova_destroy().

Does this permanently leak the device's IOVA space?

> 	} else if (dma_use_iova(dma->state)) {
> 		dma_iova_destroy(attach->dev, dma->state, mapped_len, dir,
> 				 DMA_ATTR_MMIO);
> 	} else {
> 		for_each_sgtable_dma_sg(&dma->sgt, sgl, i)
> 			dma_unmap_phys(attach->dev, sg_dma_address(sgl),
> 				       sg_dma_len(sgl), dir, DMA_ATTR_MMIO);

[Severity: High]
This isn't a bug introduced by this patch, but does this loop over
uninitialized entries?

The for_each_sgtable_dma_sg macro shadows the outer loop variable i, which
represents the number of successfully mapped entries. Instead of bounding
the loop to the mapped entries, it resets i to 0 and unconditionally
iterates up to the total allocated entries (dma->sgt.nents).

Since sg_alloc_table zero-initializes the memory via __GFP_ZERO, the unmapped
elements will have DMA addresses and lengths of 0. Can calling dma_unmap_phys
with a 0 address and 0 length cause IOMMU translation corruption or explicit
DMA faults?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260722233806.3922093-1-dhu@x6u.co?part=1

  reply	other threads:[~2026-07-23  0:02 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-21 22:21 [PATCH] dma-buf: Split sgl by largest page-aligned chunk David Hu
2026-06-21 22:34 ` sashiko-bot
2026-06-22  8:13 ` David Laight
2026-06-22 21:26   ` David Hu
2026-06-23  8:25     ` David Laight
2026-06-23 21:03       ` David Hu
2026-06-23  1:54 ` [PATCH v2] dma-buf: Split sgl into page-aligned 2G chunks David Hu
2026-06-23  2:08   ` sashiko-bot
2026-06-23  8:44   ` David Laight
2026-06-23 20:55     ` Pranjal Shrivastava
2026-06-23 22:53       ` David Laight
2026-06-24 14:31         ` Leon Romanovsky
2026-06-30 12:42         ` Jason Gunthorpe
2026-07-02  4:56           ` David Hu
2026-07-02  8:10             ` David Laight
2026-07-03  4:11               ` David Hu
2026-06-30 12:38     ` Jason Gunthorpe
2026-07-22 23:38   ` [PATCH v3] dma-buf: Split sgl by largest page-aligned chunk dhu
2026-07-23  0:02     ` sashiko-bot [this message]
2026-07-22 23:39   ` dhu
2026-07-22 23:59     ` sashiko-bot
2026-07-23  9:46     ` Leon Romanovsky
2026-07-23 16:07       ` David Hu

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=20260723000213.D6E311F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dhu@x6u.co \
    --cc=dri-devel@lists.freedesktop.org \
    --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.