i40e: xsk: fix multi-buffer XDP_PASS skb construction
Subsystems (3)
PATCH v3 1/1 i40e: xsk: fix multi-buffer XDP_PASS skb construction
From: Chenguang Zhao <[email protected]>
When AF_XDP ZC receives a multi-buffer frame and the XDP program returns XDP_PASS, i40e_construct_skb_zc() copies frags into a new skb. The copy used skb_frag_page() as the memcpy source (page metadata instead of packet data) and passed a virtual address to __skb_fill_page_desc_noacc(), which expects a struct page *.
Use skb_frag_address() for the copy, attach frags with skb_add_rx_frag() so len/data_len/truesize are updated, and on dev_alloc_page() failure free the skb via the shared out path so xsk_buff_free() still runs and previously attached pages are released by kfree_skb.
---
v3:
- To ensure backport compatibility for stable branches, this patch solely addresses bug fixes. The refactored version that replaces i40e_construct_skb_zc() with xdp_build_skb_from_zc() will be submitted to the -next tree.
v2:
- https://lore.kernel.org/all/[email protected]/
v1:
- https://lore.kernel.org/all/[email protected]/
drivers/net/ethernet/intel/i40e/i40e_xsk.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_xsk.c +5 -8
@@ -318,22 +318,19 @@ static struct sk_buff *i40e_construct_skb_zc(struct i40e_ring *rx_ring, goto out;for (int i =0 ; i < nr_frags; i++) { -struct skb_shared_info *skinfo =skb_shinfo (skb);skb_frag_t *frag = &sinfo->frags[i]; +unsigned int frag_size =skb_frag_size (frag);struct page *page; -void *addr; page =dev_alloc_page ();if (!page) {dev_kfree_skb (skb); -return NULL ; + skb =NULL ; + goto out; } - addr =page_to_virt (page); -memcpy (addr,skb_frag_page (frag),skb_frag_size (frag)); - -__skb_fill_page_desc_noacc (skinfo, skinfo->nr_frags++, - addr,0 ,skb_frag_size (frag)); +memcpy (page_to_virt (page),skb_frag_address (frag), frag_size); +skb_add_rx_frag (skb, i, page,0 , frag_size,PAGE_SIZE ); } out:
Signature · 1 line
2.25.1
Quoted 14 lines
From: Chenguang Zhao <[email protected]>
When
AF_XDPZC receives a multi-buffer frame and the XDP program returnsXDP_PASS,i40e_construct_skb_zc()copies frags into a new skb. The copy usedskb_frag_page()as the memcpy source (page metadata instead of packet data) and passed a virtual address to__skb_fill_page_desc_noacc(), which expects a struct page *.Use
skb_frag_address()for the copy, attach frags withskb_add_rx_frag()so len/data_len/truesize are updated, and ondev_alloc_page()failure free the skb via the shared out path soxsk_buff_free()still runs and previously attached pages are released bykfree_skb.
Quoted 4 lines
Fixes 1c9ba9c14658 ("i40e: xsk: add RX multi-buffer support")Signed-off-by Chenguang Zhao <[email protected]>Reviewed-by Aleksandr Loktionov <[email protected]>Reviewed-by Jason Xing <[email protected]>
Holda, Patryk
Tested-byQuoted 30 lines
-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Fijalkowski, Maciej
Sent: Friday, July 24, 2026 5:25 PM
To: Chenguang Zhao <[email protected]>; Nguyen, Anthony L <[email protected]>; Kitszel, Przemyslaw <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Chenguang Zhao <[email protected]>; Loktionov, Aleksandr <[email protected]>; Jason Xing <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH net v3] i40e: xsk: fix multi-bufferXDP_PASSskb construction
Importance: HighQuoted 14 lines
From: Chenguang Zhao <[email protected]>
When
AF_XDPZC receives a multi-buffer frame and the XDP program returnsXDP_PASS,i40e_construct_skb_zc()copies frags into a new skb. The copy usedskb_frag_page()as the memcpy source (page metadata instead of packet data) and passed a virtual address to__skb_fill_page_desc_noacc(), which expects a struct page *.Use
skb_frag_address()for the copy, attach frags withskb_add_rx_frag()so len/data_len/truesize are updated, and ondev_alloc_page()failure free the skb via the shared out path soxsk_buff_free()still runs and previously attached pages are released bykfree_skb.
Quoted 6 lines
Quoted 4 lines
Fixes 1c9ba9c14658 ("i40e: xsk: add RX multi-buffer support")Signed-off-by Chenguang Zhao <[email protected]>Reviewed-by Aleksandr Loktionov <[email protected]>Reviewed-by Jason Xing <[email protected]>