]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
xsk: Add truesize to skb_add_rx_frag().
authorSebastian Andrzej Siewior <bigeasy@linutronix.de>
Fri, 2 Feb 2024 16:32:20 +0000 (17:32 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 13 Feb 2024 22:10:29 +0000 (23:10 +0100)
xsk_build_skb() allocates a page and adds it to the skb via
skb_add_rx_frag() and specifies 0 for truesize. This leads to a warning
in skb_add_rx_frag() with CONFIG_DEBUG_NET enabled because size is
larger than truesize.

Increasing truesize requires to add the same amount to socket's
sk_wmem_alloc counter in order not to underflow the counter during
release in the destructor (sock_wfree()).

Pass the size of the allocated page as truesize to skb_add_rx_frag().
Add this mount to socket's sk_wmem_alloc counter.

Fixes: cf24f5a5feea ("xsk: add support for AF_XDP multi-buffer on Tx path")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Link: https://lore.kernel.org/bpf/20240202163221.2488589-1-bigeasy@linutronix.de
net/xdp/xsk.c

index 1eadfac03cc41d35709c001a77759a23f7dbdc39..b78c0e095e221fd775b9e1eafa4dd15485915079 100644 (file)
@@ -722,7 +722,8 @@ static struct sk_buff *xsk_build_skb(struct xdp_sock *xs,
                        memcpy(vaddr, buffer, len);
                        kunmap_local(vaddr);
 
-                       skb_add_rx_frag(skb, nr_frags, page, 0, len, 0);
+                       skb_add_rx_frag(skb, nr_frags, page, 0, len, PAGE_SIZE);
+                       refcount_add(PAGE_SIZE, &xs->sk.sk_wmem_alloc);
                }
 
                if (first_frag && desc->options & XDP_TX_METADATA) {