From: Jason Gunthorpe <jgg@ziepe.ca>
To: "Christian König" <christian.koenig@amd.com>
Cc: Leon Romanovsky <leon@kernel.org>,
Sumit Semwal <sumit.semwal@linaro.org>,
Kevin Tian <kevin.tian@intel.com>,
Nicolin Chen <nicolinc@nvidia.com>,
Ankit Agrawal <ankita@nvidia.com>,
Alex Williamson <alex@shazbot.org>,
linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dma-buf: Restore the scatterlist entry count before freeing
Date: Wed, 21 Oct 2026 12:01:04 -0300 [thread overview]
Message-ID: <20261021150104.GT14213@ziepe.ca> (raw)
In-Reply-To: <dc91d903-139d-4253-83f7-51a78dd4530b@amd.com>
On Tue, Oct 20, 2026 at 08:42:18AM +0200, Christian König wrote:
> On 10/19/26 20:31, Leon Romanovsky wrote:
> > On Tue, Oct 13, 2026 at 02:46:24PM +0300, Leon Romanovsky wrote:
> >> From: Leon Romanovsky <leonro@nvidia.com>
> >>
> >> dma_buf_phys_vec_to_sgt() clears orig_nents to mark the returned table
> >> as DMA-only. Since sg_free_table() uses orig_nents to walk and free the
> >> scatterlist, dma_buf_free_sgt() leaks the allocation on every successful
> >> map/unmap cycle.
> >>
> >> Restore orig_nents from nents before freeing the table. The helper
> >> allocates the DMA list directly, so nents retains the allocation count,
> >> including for chained scatterlists.
> >>
> >>
> >> The reported kmemleak output was:
> >>
> >> KMEMLEAK LEAK: 2 driver-related leak(s)
> >> KMEMLEAK LEAK: unreferenced object 0xff11000125ceff00 (size 32):
> >> KMEMLEAK LEAK: comm dtr, pid 4432, jiffies 4295031027
> >> KMEMLEAK LEAK: hex dump (first 32 bytes):
> >> KMEMLEAK LEAK: 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
> >> KMEMLEAK LEAK: 00 00 01 00 28 38 00 00 00 10 00 00 00 00 00 00 ....(8..........
> >> KMEMLEAK LEAK: backtrace (crc 4e8077f2):
> >> KMEMLEAK LEAK: __kmalloc_noprof+0x451/0x8b0
> >> KMEMLEAK LEAK: __sg_alloc_table+0x2a0/0x4d0
> >> KMEMLEAK LEAK: sg_alloc_table+0x24/0x170
> >> KMEMLEAK LEAK: dma_buf_phys_vec_to_sgt+0x84f/0xed0
> >> KMEMLEAK LEAK: 0xffffffffa1ad21a8
> >> KMEMLEAK LEAK: dma_buf_map_attachment+0x138/0x690
> >> KMEMLEAK LEAK: ib_umem_dmabuf_map_pages+0x249/0xc90 [ib_core]
> >> KMEMLEAK LEAK: 0xffffffffa138f8d2
> >> KMEMLEAK LEAK: 0xffffffffa1396abe
> >> KMEMLEAK LEAK: 0xffffffffa1331a5f
> >> KMEMLEAK LEAK: 0xffffffffa13320dd
> >> KMEMLEAK LEAK: 0xffffffffa1ad696d
> >> KMEMLEAK LEAK: 0xffffffffa1acecc7
> >> KMEMLEAK LEAK: 0xffffffffa1acfd17
> >> KMEMLEAK LEAK: __x64_sys_ioctl+0x72c/0x11f0
> >> KMEMLEAK LEAK: do_syscall_64+0xa1/0x4f0
> >> KMEMLEAK LEAK: unreferenced object 0xff1100016dbf3a80 (size 32):
> >> KMEMLEAK LEAK: comm dtr, pid 4432, jiffies 4295034705
> >> KMEMLEAK LEAK: hex dump (first 32 bytes):
> >> KMEMLEAK LEAK: 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
> >> KMEMLEAK LEAK: 00 20 10 00 28 38 00 00 00 10 00 00 00 00 00 00 . ..(8..........
> >>
> >> Fixes: 3aa31a8bb11e ("dma-buf: provide phys_vec to scatter-gather mapping routine")
> >> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
> >> ---
> >> drivers/dma-buf/dma-buf-mapping.c | 2 ++
> >> 1 file changed, 2 insertions(+)
> >
> > Reminder, thanks
>
> I'm waiting for anybody familiar with the code to review this.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Jason
prev parent reply other threads:[~2026-10-21 15:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 11:46 Leon Romanovsky
2026-10-19 18:31 ` Leon Romanovsky
2026-10-20 6:42 ` Christian König
2026-10-21 15:01 ` Jason Gunthorpe [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261021150104.GT14213@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=alex@shazbot.org \
--cc=ankita@nvidia.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=kevin.tian@intel.com \
--cc=leon@kernel.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=nicolinc@nvidia.com \
--cc=sumit.semwal@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®