From: Bobby Eshleman <bobbyeshleman@gmail.com>
To: sashiko-reviews@lists.linux.dev
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH net-next v5 1/3] net: devmem: allow rx-buf-size > PAGE_SIZE per dmabuf binding
Date: Wed, 15 Jul 2026 02:28:12 -0700 [thread overview]
Message-ID: <aldSrNgB4+EJRI0X@devvm29614.prn0.facebook.com> (raw)
In-Reply-To: <20260710072712.BC57B1F000E9@smtp.kernel.org>
On Fri, Jul 10, 2026 at 07:27:12AM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] On 32-bit architectures with 64-bit DMA addresses (e.g., CONFIG_ARCH_DMA_ADDR_T_64BIT), passing `dma_addr_t` to `gen_pool` functions truncates the DMA address to 32 bits, leading to broken bit allocations, leaked chunks, and possible data corruption.
> --
>
> --- Patch [1]: [PATCH net-next v5 1/3] net: devmem: allow rx-buf-size > PAGE_SIZE per dmabuf binding ---
> commit 700c87449a5348e02d33589504f632f46bed92e7
> Author: Bobby Eshleman <bobbyeshleman@meta.com>
>
> net: devmem: allow rx-buf-size > PAGE_SIZE per dmabuf binding
>
> This commit introduces the NETDEV_A_DMABUF_RX_BUF_SIZE netlink attribute.
> It allows userspace to request an RX buffer size larger than PAGE_SIZE
> for devmem dmabuf bindings, avoiding CPU churn for large flows.
>
> > diff --git a/net/core/devmem.c b/net/core/devmem.c
> > index 957d6b96216b3..3ce3cc14bec07 100644
> > --- a/net/core/devmem.c
> > +++ b/net/core/devmem.c
> [ ... ]
> > @@ -113,12 +114,13 @@ void net_devmem_free_dmabuf(struct net_iov *niov)
> > {
> > struct net_devmem_dmabuf_binding *binding = net_devmem_iov_binding(niov);
> > unsigned long dma_addr = net_devmem_get_dma_addr(niov);
> > + size_t niov_size = 1UL << binding->niov_shift;
> >
> > if (WARN_ON(!gen_pool_has_addr(binding->chunk_pool, dma_addr,
> > - PAGE_SIZE)))
>
> [Severity: High]
> This is a pre-existing issue, but can this truncate the DMA address?
> Looking at net_devmem_free_dmabuf() in net/core/devmem.c, dma_addr is
> derived as a dma_addr_t (which can be 64-bit), but is passed to
> gen_pool_has_addr() and gen_pool_free() which expect an unsigned long.
>
> On 32-bit architectures with 64-bit DMA addresses (like
> CONFIG_ARCH_DMA_ADDR_T_64BIT), this will silently truncate the upper 32
> bits. If a chunk crosses a 4GB boundary in its lower 32 bits, the end
> address could wrap around, causing gen_pool_has_addr() to fail the bounds
> check and permanently leak memory via this WARN_ON path.
Let's defer pre-existing issues to future work?
>
> > + niov_size)))
> > return;
> >
> > - gen_pool_free(binding->chunk_pool, dma_addr, PAGE_SIZE);
> > + gen_pool_free(binding->chunk_pool, dma_addr, niov_size);
> > }
> [ ... ]
> > @@ -288,7 +295,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
> >
> > owner->area.base_virtual = virtual;
> > owner->base_dma_addr = dma_addr;
> > - owner->area.num_niovs = len / PAGE_SIZE;
> > + owner->area.num_niovs = len >> niov_shift;
> > owner->binding = binding;
> >
> > err = gen_pool_add_owner(binding->chunk_pool, dma_addr,
>
> [Severity: High]
> This is a pre-existing issue, but does this suffer from the same 64-bit to
> 32-bit truncation?
>
> In net_devmem_bind_dmabuf() in net/core/devmem.c, gen_pool_add_owner()
> takes an unsigned long for its virtual address parameter. Passing the
> 64-bit dma_addr here will truncate the upper 32 bits on 32-bit systems.
>
> If two dmabuf chunks happen to share the same lower 32 bits, this
> truncation could cause overlapping chunk registrations. This might
> eventually lead to double allocations of the same network buffers and
> silent data corruption.
Ditto?
next prev parent reply other threads:[~2026-07-16 8:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 22:55 [PATCH net-next v5 0/3] net: devmem: allow rx-buf-size > PAGE_SIZE per binding Bobby Eshleman
2026-07-08 22:55 ` [PATCH net-next v5 1/3] net: devmem: allow rx-buf-size > PAGE_SIZE per dmabuf binding Bobby Eshleman
2026-07-10 7:27 ` sashiko-bot
2026-07-15 9:28 ` Bobby Eshleman [this message]
2026-07-08 22:55 ` [PATCH net-next v5 2/3] selftests/net: ncdevmem: add -b option to set rx-buf-size on bind Bobby Eshleman
2026-07-20 21:15 ` Mina Almasry
2026-07-08 22:55 ` [PATCH net-next v5 3/3] selftests/net: devmem.py: add check_rx_large_niov Bobby Eshleman
2026-07-10 7:27 ` sashiko-bot
2026-07-15 9:33 ` Bobby Eshleman
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=aldSrNgB4+EJRI0X@devvm29614.prn0.facebook.com \
--to=bobbyeshleman@gmail.com \
--cc=dri-devel@lists.freedesktop.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox