* [PATCH net-next] i40e: xsk: use xdp_build_skb_from_zc() for XDP_PASS
@ 2026-07-24 2:01 Chenguang Zhao
2026-07-24 15:30 ` Maciej Fijalkowski
0 siblings, 1 reply; 2+ messages in thread
From: Chenguang Zhao @ 2026-07-24 2:01 UTC (permalink / raw)
To: anthony.l.nguyen, przemyslaw.kitszel, andrew+netdev, davem,
edumazet, kuba, pabeni
Cc: intel-wired-lan, netdev, chenguang.zhao, Chenguang Zhao,
Jason Xing
From: Chenguang Zhao <zhaochenguang@kylinos.cn>
Replace the driver-local i40e_construct_skb_zc() with the common
helper xdp_build_skb_from_zc(). On failure, free the xdp buff in
the caller. Push the Ethernet header back before eth_skb_pad()/
i40e_process_skb_fields() because xdp_build_skb_from_zc() already
called eth_type_trans().
Signed-off-by: Chenguang Zhao <zhaochenguang@kylinos.cn>
Reviewed-by: Jason Xing <kerneljasonxing@gmail.com>
---
The earlier patch was discussed on the net tree.
v2:
https://lore.kernel.org/all/20260717012416.168107-1-chenguang.zhao@linux.dev/
v1:
https://lore.kernel.org/all/20260714025112.284724-1-chenguang.zhao@linux.dev/
Because older kernels do not have xdp_build_skb_from_zc(), only the bugfix goes
to net; the refactor lands on net-next.
drivers/net/ethernet/intel/i40e/i40e_xsk.c | 74 +++-------------------
1 file changed, 9 insertions(+), 65 deletions(-)
diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c
index 9f47388eaba5..13932b36142d 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c
@@ -3,6 +3,7 @@
#include <linux/bpf_trace.h>
#include <linux/unroll.h>
+#include <net/xdp.h>
#include <net/xdp_sock_drv.h>
#include "i40e_txrx_common.h"
#include "i40e_xsk.h"
@@ -277,70 +278,6 @@ bool i40e_alloc_rx_buffers_zc(struct i40e_ring *rx_ring, u16 count)
return count == nb_buffs;
}
-/**
- * i40e_construct_skb_zc - Create skbuff from zero-copy Rx buffer
- * @rx_ring: Rx ring
- * @xdp: xdp_buff
- *
- * This functions allocates a new skb from a zero-copy Rx buffer.
- *
- * Returns the skb, or NULL on failure.
- **/
-static struct sk_buff *i40e_construct_skb_zc(struct i40e_ring *rx_ring,
- struct xdp_buff *xdp)
-{
- unsigned int totalsize = xdp->data_end - xdp->data_meta;
- unsigned int metasize = xdp->data - xdp->data_meta;
- struct skb_shared_info *sinfo = NULL;
- struct sk_buff *skb;
- u32 nr_frags = 0;
-
- if (unlikely(xdp_buff_has_frags(xdp))) {
- sinfo = xdp_get_shared_info_from_buff(xdp);
- nr_frags = sinfo->nr_frags;
- }
- net_prefetch(xdp->data_meta);
-
- /* allocate a skb to store the frags */
- skb = napi_alloc_skb(&rx_ring->q_vector->napi, totalsize);
- if (unlikely(!skb))
- goto out;
-
- memcpy(__skb_put(skb, totalsize), xdp->data_meta,
- ALIGN(totalsize, sizeof(long)));
-
- if (metasize) {
- skb_metadata_set(skb, metasize);
- __skb_pull(skb, metasize);
- }
-
- if (likely(!xdp_buff_has_frags(xdp)))
- 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];
- struct page *page;
- void *addr;
-
- page = dev_alloc_page();
- if (!page) {
- dev_kfree_skb(skb);
- return NULL;
- }
- 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));
- }
-
-out:
- xsk_buff_free(xdp);
- return skb;
-}
-
static void i40e_handle_xdp_result_zc(struct i40e_ring *rx_ring,
struct xdp_buff *xdp_buff,
union i40e_rx_desc *rx_desc,
@@ -372,14 +309,21 @@ static void i40e_handle_xdp_result_zc(struct i40e_ring *rx_ring,
* BIT(I40E_RXD_QW1_ERROR_SHIFT). This is due to that
* SBP is *not* set in PRT_SBPVSI (default not set).
*/
- skb = i40e_construct_skb_zc(rx_ring, xdp_buff);
+ skb = xdp_build_skb_from_zc(xdp_buff);
if (!skb) {
+ xsk_buff_free(xdp_buff);
rx_ring->rx_stats.alloc_buff_failed++;
*rx_packets = 0;
*rx_bytes = 0;
return;
}
+ /*
+ * xdp_build_skb_from_zc() already ran eth_type_trans();
+ * restore the header for eth_skb_pad()/process_skb_fields().
+ */
+ __skb_push(skb, skb->data - skb_mac_header(skb));
+
if (eth_skb_pad(skb)) {
*rx_packets = 0;
*rx_bytes = 0;
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] i40e: xsk: use xdp_build_skb_from_zc() for XDP_PASS
2026-07-24 2:01 [PATCH net-next] i40e: xsk: use xdp_build_skb_from_zc() for XDP_PASS Chenguang Zhao
@ 2026-07-24 15:30 ` Maciej Fijalkowski
0 siblings, 0 replies; 2+ messages in thread
From: Maciej Fijalkowski @ 2026-07-24 15:30 UTC (permalink / raw)
To: Chenguang Zhao
Cc: anthony.l.nguyen, przemyslaw.kitszel, andrew+netdev, davem,
edumazet, kuba, pabeni, intel-wired-lan, netdev, Chenguang Zhao,
Jason Xing
On Fri, Jul 24, 2026 at 10:01:25AM +0800, Chenguang Zhao wrote:
> From: Chenguang Zhao <zhaochenguang@kylinos.cn>
>
> Replace the driver-local i40e_construct_skb_zc() with the common
> helper xdp_build_skb_from_zc(). On failure, free the xdp buff in
> the caller. Push the Ethernet header back before eth_skb_pad()/
> i40e_process_skb_fields() because xdp_build_skb_from_zc() already
> called eth_type_trans().
>
> Signed-off-by: Chenguang Zhao <zhaochenguang@kylinos.cn>
> Reviewed-by: Jason Xing <kerneljasonxing@gmail.com>
> ---
> The earlier patch was discussed on the net tree.
> v2:
> https://lore.kernel.org/all/20260717012416.168107-1-chenguang.zhao@linux.dev/
> v1:
> https://lore.kernel.org/all/20260714025112.284724-1-chenguang.zhao@linux.dev/
> Because older kernels do not have xdp_build_skb_from_zc(), only the bugfix goes
> to net; the refactor lands on net-next.
>
> drivers/net/ethernet/intel/i40e/i40e_xsk.c | 74 +++-------------------
> 1 file changed, 9 insertions(+), 65 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c
> index 9f47388eaba5..13932b36142d 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c
> +++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c
> @@ -3,6 +3,7 @@
>
> #include <linux/bpf_trace.h>
> #include <linux/unroll.h>
> +#include <net/xdp.h>
> #include <net/xdp_sock_drv.h>
> #include "i40e_txrx_common.h"
> #include "i40e_xsk.h"
> @@ -277,70 +278,6 @@ bool i40e_alloc_rx_buffers_zc(struct i40e_ring *rx_ring, u16 count)
> return count == nb_buffs;
> }
>
> -/**
> - * i40e_construct_skb_zc - Create skbuff from zero-copy Rx buffer
> - * @rx_ring: Rx ring
> - * @xdp: xdp_buff
> - *
> - * This functions allocates a new skb from a zero-copy Rx buffer.
> - *
> - * Returns the skb, or NULL on failure.
> - **/
> -static struct sk_buff *i40e_construct_skb_zc(struct i40e_ring *rx_ring,
> - struct xdp_buff *xdp)
> -{
> - unsigned int totalsize = xdp->data_end - xdp->data_meta;
> - unsigned int metasize = xdp->data - xdp->data_meta;
> - struct skb_shared_info *sinfo = NULL;
> - struct sk_buff *skb;
> - u32 nr_frags = 0;
> -
> - if (unlikely(xdp_buff_has_frags(xdp))) {
> - sinfo = xdp_get_shared_info_from_buff(xdp);
> - nr_frags = sinfo->nr_frags;
> - }
> - net_prefetch(xdp->data_meta);
> -
> - /* allocate a skb to store the frags */
> - skb = napi_alloc_skb(&rx_ring->q_vector->napi, totalsize);
> - if (unlikely(!skb))
> - goto out;
> -
> - memcpy(__skb_put(skb, totalsize), xdp->data_meta,
> - ALIGN(totalsize, sizeof(long)));
> -
> - if (metasize) {
> - skb_metadata_set(skb, metasize);
> - __skb_pull(skb, metasize);
> - }
> -
> - if (likely(!xdp_buff_has_frags(xdp)))
> - 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];
> - struct page *page;
> - void *addr;
> -
> - page = dev_alloc_page();
> - if (!page) {
> - dev_kfree_skb(skb);
> - return NULL;
> - }
> - 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));
> - }
> -
> -out:
> - xsk_buff_free(xdp);
> - return skb;
> -}
> -
> static void i40e_handle_xdp_result_zc(struct i40e_ring *rx_ring,
> struct xdp_buff *xdp_buff,
> union i40e_rx_desc *rx_desc,
> @@ -372,14 +309,21 @@ static void i40e_handle_xdp_result_zc(struct i40e_ring *rx_ring,
> * BIT(I40E_RXD_QW1_ERROR_SHIFT). This is due to that
> * SBP is *not* set in PRT_SBPVSI (default not set).
> */
> - skb = i40e_construct_skb_zc(rx_ring, xdp_buff);
> + skb = xdp_build_skb_from_zc(xdp_buff);
> if (!skb) {
> + xsk_buff_free(xdp_buff);
> rx_ring->rx_stats.alloc_buff_failed++;
> *rx_packets = 0;
> *rx_bytes = 0;
> return;
> }
>
> + /*
> + * xdp_build_skb_from_zc() already ran eth_type_trans();
> + * restore the header for eth_skb_pad()/process_skb_fields().
> + */
> + __skb_push(skb, skb->data - skb_mac_header(skb));
This feels a bit counter-productive. We would end up calling
skb_record_rx_queue() and eth_type_trans() twice. Maybe we should open
code the bits from i40e_process_skb_fields() excluding the two above?
Or pull it out to internal function and make i40e_process_skb_fields()
call it.
> +
> if (eth_skb_pad(skb)) {
> *rx_packets = 0;
> *rx_bytes = 0;
> --
> 2.25.1
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-24 15:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-24 2:01 [PATCH net-next] i40e: xsk: use xdp_build_skb_from_zc() for XDP_PASS Chenguang Zhao
2026-07-24 15:30 ` Maciej Fijalkowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox