๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
4 messages
4 total messages Started by Stanislav Fomichev Wed, 11 Nov 2026 22:47
[PATCH net-next v4 4/5] net: devmem: size TX net_iovs from the dmabuf sg table
#14731
Author: Stanislav Fomichev
Date: Wed, 11 Nov 2026 22:47
106 lines
14859 bytes
PAGE_SIZE TX net_iovs cap devmem skbs at MAX_SKB_FRAGS pages (~68KB),
which makes BIG TCP ineffective.

TX net_iovs only need to be DMA contiguous. Use the largest power of 2,
from PAGE_SIZE up to 2MB, which aligns every DMA segment of the dmabuf:
- 2MB hugepage-backed udmabufs get 2MB net_iovs
- no UAPI change, TX addresses are dmabuf offsets
- skbs keep their size, only the frags get larger

The net_iov size doesn't depend on the device. A frag is never larger
than its skb, and the skb is never larger than the device's
gso_max_size. TCP sizes skbs to fit, and validate_xmit_skb() segments
bigger ones. gso_max_size is 64KB unless BIG TCP is enabled. With BIG
TCP, page frags can already be 64KB or larger, for example with
MSG_ZEROCOPY from huge pages or with 64KB pages. So drivers that
enable BIG TCP already have to handle them. bnxt doesn't handle them
yet. It has a 16-bit BD length and needs a separate fix.

Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
Reviewed-by: Mina Almasry <almasrymina@google.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
---
 net/core/devmem.c      | 28 ++++++++++++++++++++++++++--
 net/core/netdev-genl.c |  2 +-
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/net/core/devmem.c b/net/core/devmem.c
index c6868f39261a..713528048897 100644
--- a/net/core/devmem.c
+++ b/net/core/devmem.c
@@ -303,6 +303,20 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
 	return err;
 }
 
+static bool net_devmem_sgt_aligned(struct sg_table *sgt, size_t size)
+{
+	struct scatterlist *sg;
+	unsigned int i;
+
+	for_each_sgtable_dma_sg(sgt, sg, i) {
+		if (!IS_ALIGNED(sg_dma_address(sg), size) ||
+		    !IS_ALIGNED(sg_dma_len(sg), size))
+			return false;
+	}
+	return true;
+}
+
+/* niov_shift == 0 picks the net_iov size from the dmabuf, TX only */
 struct net_devmem_dmabuf_binding *
 net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
 		       struct device *dma_dev,
@@ -313,11 +327,11 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
 		       struct netlink_ext_ack *extack)
 {
 	struct net_devmem_dmabuf_binding *binding;
-	size_t niov_size = 1UL << niov_shift;
 	static u32 id_alloc_next;
 	struct scatterlist *sg;
 	struct dma_buf *dmabuf;
 	unsigned int sg_idx;
+	size_t niov_size;
 	size_t niov_idx;
 	size_t i;
 	long err;
@@ -342,7 +356,6 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
 	binding->vdev = vdev;
 	write_pnet(&binding->net, sock_net(nl_sk));
 	binding->uid = sk_uid(nl_sk);
-	binding->niov_shift = niov_shift;
 	xa_init_flags(&binding->bound_rxqs, XA_FLAGS_ALLOC);
 
 	err = percpu_ref_init(&binding->ref,
@@ -387,6 +400,17 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
 		goto err_unmap;
 	}
 
+	if (!niov_shift) {
+		niov_size = SZ_2M;
+		while (niov_size > PAGE_SIZE &&
+		       (!IS_ALIGNED(dmabuf->size, niov_size) ||
+			!net_devmem_sgt_aligned(binding->sgt, niov_size)))
+			niov_size /= 2;
+		niov_shift = ilog2(niov_size);
+	}
+	binding->niov_shift = niov_shift;
+	niov_size = 1UL << niov_shift;
+
 	if (!IS_ALIGNED(dmabuf->size, niov_size)) {
 		err = -EINVAL;
 		NL_SET_ERR_MSG_FMT(extack,
diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c
index 9c5bf17b04e5..d2ccb1090496 100644
--- a/net/core/netdev-genl.c
+++ b/net/core/netdev-genl.c
@@ -1261,7 +1261,7 @@ int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info)
 	binding = net_devmem_bind_dmabuf(bind_dev,
 					 bind_dev != netdev ? netdev : NULL,
 					 dma_dev, DMA_TO_DEVICE, dmabuf_fd,
-					 PAGE_SHIFT, priv, NETLINK_CB(skb).sk,
+					 0, priv, NETLINK_CB(skb).sk,
 					 info->extack);
 	if (IS_ERR(binding)) {
 		err = PTR_ERR(binding);
-- 
2.53.0-Meta
Re: [PATCH net-next v4 4/5] net: devmem: size TX net_iovs from the dmabuf sg table
#15436
Author: netdev-bot+sashiko
Date: Thu, 12 Nov 2026 22:49
123 lines
12333 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] This patch makes devmem TX net_iovs up to 2MB.

--

net: devmem: size TX net_iovs from the dmabuf sg table

This commit lets TX devmem bindings choose the net_iov size from the
dmabuf sg table. It uses the largest power of two between PAGE_SIZE and
2MB that aligns every DMA segment. netdev_nl_bind_tx_doit() now passes
niov_shift 0 to request this, so hugepage-backed udmabufs get 2MB TX
net_iovs.

> diff --git a/net/core/devmem.c b/net/core/devmem.c
> index c6868f39261ad..7135280488971 100644
> --- a/net/core/devmem.c
> +++ b/net/core/devmem.c

[ ... ]

> @@ -387,6 +400,17 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
>  		goto err_unmap;
>  	}
>  
> +	if (!niov_shift) {
> +		niov_size = SZ_2M;
> +		while (niov_size > PAGE_SIZE &&
> +		       (!IS_ALIGNED(dmabuf->size, niov_size) ||
> +			!net_devmem_sgt_aligned(binding->sgt, niov_size)))
> +			niov_size /= 2;
> +		niov_shift = ilog2(niov_size);
> +	}

[Severity: Medium]
netdev_nl_bind_tx_doit() now passes 0 here. That means a 2MB aligned,
hugepage-backed dmabuf gets 2MB TX net_iovs no matter which device it is
bound to. Can this produce frags that bnxt silently truncates?

Before this patch, every devmem TX frag was capped at PAGE_SIZE. Now
zerocopy_fill_skb_from_devmem() limits a frag only by niov_size - off,
the copy length and the iov length:

net/core/datagram.c:zerocopy_fill_skb_from_devmem() {
    ...
		size = min_t(size_t, size, length);
		size = min_t(size_t, size, iter_iov_len(from));

		netmem_inc_ref(net_iov_to_netmem(niov));
		skb_add_rx_frag_netmem(skb, i, net_iov_to_netmem(niov), off,
				       size, size);
    ...
}

So with BIG TCP enabled (gso_max_size > 65536), a single frag can be 64KB
or larger.

In bnxt_init_one(), bnxt sets dev->netmem_tx = NETMEM_TX_DMA and calls
netif_set_tso_max_size(dev, GSO_MAX_SIZE). bnxt_start_xmit() then writes
the frag length into the BD without checking its size:

drivers/net/ethernet/broadcom/bnxt/bnxt.c:bnxt_start_xmit() {
    ...
		len = skb_frag_size(frag);
		mapping = skb_frag_dma_map(&pdev->dev, frag, 0, len,
					   DMA_TO_DEVICE);
    ...
		flags = len << TX_BD_LEN_SHIFT;
		txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
    ...
}

TX_BD_LEN is (0xffff << 16), so the length field is 16 bits wide. A 65536
byte frag would be written as 0, and a 70000 byte frag as 4464. The DMA
mapping and BQL still use the full length. Depending on the hardware, the
result could be a corrupted LSO payload on the wire or a TX error and
ring reset.

The "Dropped oversize" check in bnxt_start_xmit() only looks at gso_size
plus hdr_len for GSO skbs, so it does not catch this.

The commit message says:

    bnxt doesn't handle them yet. It has a 16-bit BD length and needs a
    separate fix.

That fix does not appear in this series, and it is not listed as a
prerequisite. The only bnxt change in the series is "bnxt_en: let the
stack segment GSO skbs with too many frags". It handles nr_frags >
TX_MAX_FRAGS in bnxt_features_check(), but it does not limit frag size.

NETDEV_CMD_BIND_TX does not require GENL_ADMIN_PERM. Once an admin enables
BIG TCP on a bnxt port, any local user who can create such a dmabuf (for
example a udmabuf from a hugetlb memfd) could reach this path.

MSG_ZEROCOPY from huge pages can already hit the same truncation. This
patch adds a new path to it through devmem TX, in the BIG TCP setup the
patch is meant to enable.

Should the auto-selected niov size be capped per device until bnxt is
fixed? Or could the bnxt fix land before this patch?

> +	binding->niov_shift = niov_shift;
> +	niov_size = 1UL << niov_shift;
> +
>  	if (!IS_ALIGNED(dmabuf->size, niov_size)) {
>  		err = -EINVAL;
>  		NL_SET_ERR_MSG_FMT(extack,

[ ... ]

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111224740.2744522-1-sdf%40fomichev.me
Re: [PATCH net-next v4 4/5] net: devmem: size TX net_iovs from the dmabuf sg table
#15710
Author: Breno Leitao
Date: Fri, 13 Nov 2026 12:10
25 lines
9975 bytes
On Wed, Nov 11, 2026 at 02:47:39PM -0800, Stanislav Fomichev wrote:
> PAGE_SIZE TX net_iovs cap devmem skbs at MAX_SKB_FRAGS pages (~68KB),
> which makes BIG TCP ineffective.
> 
> TX net_iovs only need to be DMA contiguous. Use the largest power of 2,
> from PAGE_SIZE up to 2MB, which aligns every DMA segment of the dmabuf:
> - 2MB hugepage-backed udmabufs get 2MB net_iovs
> - no UAPI change, TX addresses are dmabuf offsets
> - skbs keep their size, only the frags get larger
> 
> The net_iov size doesn't depend on the device. A frag is never larger
> than its skb, and the skb is never larger than the device's
> gso_max_size. TCP sizes skbs to fit, and validate_xmit_skb() segments
> bigger ones. gso_max_size is 64KB unless BIG TCP is enabled. With BIG
> TCP, page frags can already be 64KB or larger, for example with
> MSG_ZEROCOPY from huge pages or with 64KB pages. So drivers that
> enable BIG TCP already have to handle them. bnxt doesn't handle them
> yet. It has a 16-bit BD length and needs a separate fix.
> 
> Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
> Reviewed-by: Mina Almasry <almasrymina@google.com>
> Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>

Reviewed-by: Breno Leitao <leitao@debian.org>
Re: [PATCH net-next v4 4/5] net: devmem: size TX net_iovs from the dmabuf sg table
#15891
Author: Breno Leitao
Date: Fri, 13 Nov 2026 12:20
25 lines
9954 bytes
On Wed, Nov 11, 2026 at 02:47:39PM -0800, Stanislav Fomichev wrote:
> PAGE_SIZE TX net_iovs cap devmem skbs at MAX_SKB_FRAGS pages (~68KB),
> which makes BIG TCP ineffective.
> 
> TX net_iovs only need to be DMA contiguous. Use the largest power of 2,
> from PAGE_SIZE up to 2MB, which aligns every DMA segment of the dmabuf:
> - 2MB hugepage-backed udmabufs get 2MB net_iovs
> - no UAPI change, TX addresses are dmabuf offsets
> - skbs keep their size, only the frags get larger
> 
> The net_iov size doesn't depend on the device. A frag is never larger
> than its skb, and the skb is never larger than the device's
> gso_max_size. TCP sizes skbs to fit, and validate_xmit_skb() segments
> bigger ones. gso_max_size is 64KB unless BIG TCP is enabled. With BIG
> TCP, page frags can already be 64KB or larger, for example with
> MSG_ZEROCOPY from huge pages or with 64KB pages. So drivers that
> enable BIG TCP already have to handle them. bnxt doesn't handle them
> yet. It has a 16-bit BD length and needs a separate fix.
> 
> Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
> Reviewed-by: Mina Almasry <almasrymina@google.com>
> Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>

Reviewed-by: Breno Leitao <leitao@debian.org>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads