Skip to contentSkip to conversation

vmxnet3: Add XDP support.

RFC PATCH Superseded William Tu 2 participants 3 messages Jan 24, 2023 – Jan 27, 2023

Subsystems (3)

v14 of 22 Superseded Latest is v22 →

lore
Share & tools
lore

William Tu

author
#0 lore raw

RFC PATCH v14 1/1 vmxnet3: Add XDP support.

The patch adds native-mode XDP support: XDP DROP, PASS, TX, and REDIRECT.

Background:
The vmxnet3 rx consists of three rings: ring0, ring1, and dataring. For r0 and r1, buffers at r0 are allocated using alloc_skb APIs and dma mapped to the ring's descriptor. If LRO is enabled and packet size larger than 3K, VMXNET3_MAX_SKB_BUF_SIZE, then r1 is used to mapped the rest of the buffer larger than VMXNET3_MAX_SKB_BUF_SIZE. Each buffer in r1 is allocated using alloc_page. So for LRO packets, the payload will be in one buffer from r0 and multiple from r1, for non-LRO packets, only one descriptor in r0 is used for packet size less than 3k.

When receiving a packet, the first descriptor will have the sop (start of packet) bit set, and the last descriptor will have the eop (end of packet) bit set. Non-LRO packets will have only one descriptor with both sop and eop set.

Other than r0 and r1, vmxnet3 dataring is specifically designed for handling packets with small size, usually 128 bytes, defined in VMXNET3_DEF_RXDATA_DESC_SIZE, by simply copying the packet from the backend driver in ESXi to the ring's memory region at front-end vmxnet3 driver, in order to avoid memory mapping/unmapping overhead. In summary, packet size:

    A. < 128B: use dataring
    B. 128B - 3K: use ring0 (VMXNET3_RX_BUF_SKB)
    C. > 3K: use ring0 and ring1 (VMXNET3_RX_BUF_SKB + VMXNET3_RX_BUF_PAGE)

As a result, the patch adds XDP support for packets using dataring and r0 (case A and B), not the large packet size when LRO is enabled.

XDP Implementation:
When user loads and XDP prog, vmxnet3 driver checks configurations, such as mtu, lro, and re-allocate the rx buffer size for reserving the extra headroom, XDP_PACKET_HEADROOM, for XDP frame. The XDP prog will then be associated with every rx queue of the device. Note that when using dataring for small packet size, vmxnet3 (front-end driver) doesn't control the buffer allocation, as a result we allocate a new page and copy packet from the dataring to XDP frame.

The receive side of XDP is implemented for case A and B, by invoking the bpf program at vmxnet3_rq_rx_complete and handle its returned action. The vmxnet3_process_xdp(), vmxnet3_process_xdp_small() function handles the ring0 and dataring case separately, and decides the next journey of the packet afterward.

For TX, vmxnet3 has split header design. Outgoing packets are parsed first and protocol headers (L2/L3/L4) are copied to the backend. The rest of the payload are dma mapped. Since XDP_TX does not parse the packet protocol, the entire XDP frame is dma mapped for transmission and transmitted in a batch. Later on, the frame is freed and recycled back to the memory pool.

Performance:
Tested using two VMs inside one ESXi vSphere 7.0 machine, using single core on each vmxnet3 device, sender using DPDK testpmd tx-mode attached to vmxnet3 device, sending 64B or 512B UDP packet.

VM1 txgen:

$ dpdk-testpmd -l 0-3 -n 1 -- -i --nb-cores=3 \
--forward-mode=txonly --eth-peer=0,<mac addr of vm2>
option: add "--txonly-multi-flow"
option: use --txpkts=512 or 64 byte

VM2 running XDP:

$ ./samples/bpf/xdp_rxq_info -d ens160 -a <options> --skb-mode
$ ./samples/bpf/xdp_rxq_info -d ens160 -a <options>
options: XDP_DROP, XDP_PASS, XDP_TX

To test REDIRECT to cpu 0, use

$ ./samples/bpf/xdp_redirect_cpu -d ens160 -c 0 -e drop

Single core performance comparison with skb-mode.
64B: skb-mode -> native-mode
XDP_DROP: 1.6Mpps -> 2.4Mpps
XDP_PASS: 338Kpps -> 367Kpps
XDP_TX: 1.1Mpps -> 2.3Mpps
REDIRECT-drop: 1.3Mpps -> 2.3Mpps

512B: skb-mode -> native-mode
XDP_DROP: 863Kpps -> 1.3Mpps
XDP_PASS: 275Kpps -> 376Kpps
XDP_TX: 554Kpps -> 1.2Mpps
REDIRECT-drop: 659Kpps -> 1.2Mpps

Demo: https://youtu.be/4lm1CSCi78Q

Future work:
- XDP frag support
- use napi_consume_skb() instead of dev_kfree_skb_any at unmap

---
v13 -> v14:
feedbacks from Alexander Lobakin
- fix several new lines, unrelated changes, unlikely, RCT style, coding style, etc.
- add NET_IP_ALIGN and create VMXNET3_XDP_HEADROOM, instead of using XDP_PACKET_HEADROOM
- remove %pp_page and use %page in rx_buf_int
- fix the %VMXNET3_XDP_MAX_MTU, mtu doesn't include eth, vlan, and fcs
- use NL_SET instead of netdev_err when detecting LRP
- remove two global function, vmxnet3{_xdp_headroom, xdp_enabled} make the vmxnet3_xdp_enabled static inline function, and remove vmxnet3_xdp_headroom.
- rename the VMXNET3_XDP_MAX_MTU to VMXNET3_XDP_MAX_FRSIZE

- add Reviewed-by: Alexander Duyck <[email protected]>
- add yifeng sun for testing on ESXi and XDP compare v13..v14
https://github.com/williamtu/net-next/compare/v13..v14

v12 -> v13:
- feedbacks from Guolin:
Instead of return -ENOTSUPP, disable the LRO in
netdev->features, and print err msg

v11 -> v12:
work on feedbacks from Alexander Duyck
- fix issues and refactor the vmxnet3_unmap_tx_buf and unmap_pkt

v10 -> v11:
work on feedbacks from Alexander Duyck
internal feedback from Guolin and Ronak
- fix the issue of xdp_return_frame_bulk, move to up level of vmxnet3_unmap_tx_buf and some refactoring
- refactor and simplify vmxnet3_tq_cleanup
- disable XDP when LRO is enabled, suggested by Ronak

---
 drivers/net/Kconfig                   |   1 +
 drivers/net/vmxnet3/Makefile          |   2 +-
 drivers/net/vmxnet3/vmxnet3_drv.c     | 219 ++++++++++++--
 drivers/net/vmxnet3/vmxnet3_ethtool.c |  14 +
 drivers/net/vmxnet3/vmxnet3_int.h     |  43 ++-
 drivers/net/vmxnet3/vmxnet3_xdp.c     | 419 ++++++++++++++++++++++++++
 drivers/net/vmxnet3/vmxnet3_xdp.h     |  46 +++
 7 files changed, 704 insertions(+), 40 deletions(-)
 create mode 100644 drivers/net/vmxnet3/vmxnet3_xdp.c
 create mode 100644 drivers/net/vmxnet3/vmxnet3_xdp.h
drivers/net/Kconfig +1 -0
index 9e63b8c43f3e..a4419d661bdd 100644
@@ -571,6 +571,7 @@ config VMXNET3
 	tristate "VMware VMXNET3 ethernet driver"
 	depends on PCI && INET
 	depends on PAGE_SIZE_LESS_THAN_64KB
+	select PAGE_POOL
 	help
 	  This driver supports VMware's vmxnet3 virtual ethernet NIC.
 	  To compile this driver as a module, choose M here: the
drivers/net/vmxnet3/Makefile +1 -1
index a666a88ac1ff..f82870c10205 100644
@@ -32,4 +32,4 @@
 
 obj-$(CONFIG_VMXNET3) += vmxnet3.o
 
-vmxnet3-objs := vmxnet3_drv.o vmxnet3_ethtool.o
+vmxnet3-objs := vmxnet3_drv.o vmxnet3_ethtool.o vmxnet3_xdp.o
drivers/net/vmxnet3/vmxnet3_drv.c +190 -29

400 lines not on this page · raw message

drivers/net/vmxnet3/vmxnet3_ethtool.c +14 -0
index 18cf7c723201..6f542236b26e 100644
@@ -76,6 +76,10 @@ vmxnet3_tq_driver_stats[] = {
 					 copy_skb_header) },
 	{ "  giant hdr",	offsetof(struct vmxnet3_tq_driver_stats,
 					 oversized_hdr) },
+	{ "  xdp xmit",		offsetof(struct vmxnet3_tq_driver_stats,
+					 xdp_xmit) },
+	{ "  xdp xmit err",	offsetof(struct vmxnet3_tq_driver_stats,
+					 xdp_xmit_err) },
 };
 
 /* per rq stats maintained by the device */
@@ -106,6 +110,16 @@ vmxnet3_rq_driver_stats[] = {
 					 drop_fcs) },
 	{ "  rx buf alloc fail", offsetof(struct vmxnet3_rq_driver_stats,
 					  rx_buf_alloc_failure) },
+	{ "     xdp packets", offsetof(struct vmxnet3_rq_driver_stats,
+				       xdp_packets) },
+	{ "     xdp tx", offsetof(struct vmxnet3_rq_driver_stats,
+				  xdp_tx) },
+	{ "     xdp redirects", offsetof(struct vmxnet3_rq_driver_stats,
+					 xdp_redirects) },
+	{ "     xdp drops", offsetof(struct vmxnet3_rq_driver_stats,
+				     xdp_drops) },
+	{ "     xdp aborted", offsetof(struct vmxnet3_rq_driver_stats,
+				       xdp_aborted) },
 };
 
 /* global stats maintained by the driver */
drivers/net/vmxnet3/vmxnet3_int.h +33 -10

101 lines not on this page · raw message

drivers/net/vmxnet3/vmxnet3_xdp.c new file +419 -0

419 lines not on this page · raw message

drivers/net/vmxnet3/vmxnet3_xdp.h new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.32.1 (Apple Git-133)
#1 lore raw

From: William Tu <[email protected]>
Date: Mon, 23 Jan 2023 20:45:15 -0800

Quoted 3 lines

The patch adds native-mode XDP support: XDP DROP, PASS, TX, and REDIRECT.

Background:

[...]

Quoted 24 lines
drivers/net/vmxnet3/vmxnet3_drv.c +9 -1
@@ -414,26 +427,34 @@ static void
 vmxnet3_tq_cleanup(struct vmxnet3_tx_queue *tq,
 		   struct vmxnet3_adapter *adapter)
 {
+	struct xdp_frame_bulk bq;
+	u32 map_type;
 	int i;
 
+	xdp_frame_bulk_init(&bq);
+
 	while (tq->tx_ring.next2comp != tq->tx_ring.next2fill) {
 		struct vmxnet3_tx_buf_info *tbi;
 
 		tbi = tq->buf_info + tq->tx_ring.next2comp;
+		map_type = tbi->map_type;
 
 		vmxnet3_unmap_tx_buf(tbi, adapter->pdev);
 		if (tbi->skb) {
-			dev_kfree_skb_any(tbi->skb);
+			if (map_type & VMXNET3_MAP_XDP)
+				xdp_return_frame_bulk(tbi->xdpf, &bq);
+			else
+				dev_kfree_skb_any(tbi->skb);
 			tbi->skb = NULL;

drivers/net/vmxnet3/vmxnet3_drv.c static void · line 453

Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1 -5
 		}
 		vmxnet3_cmd_ring_adv_next2comp(&tq->tx_ring);
 	}
 
-	/* sanity check, verify all buffers are indeed unmapped and freed */
-	for (i = 0; i < tq->tx_ring.size; i++) {
-		BUG_ON(tq->buf_info[i].skb != NULL ||
-		       tq->buf_info[i].map_type != VMXNET3_MAP_NONE);
-	}
+	xdp_flush_frame_bulk(&bq);

Breh, I forgot you need to lock RCU read for bulk-flushing...

xdp_frame_bulk_init();
rcu_read_lock();

...

xdp_flush_frame_bulk();
rcu_read_unlock();

In both places where you use it.

Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_drv.c +4 -0
+
+	/* sanity check, verify all buffers are indeed unmapped */
+	for (i = 0; i < tq->tx_ring.size; i++)
+		BUG_ON(tq->buf_info[i].map_type != VMXNET3_MAP_NONE);
 
 	tq->tx_ring.gen = VMXNET3_INIT_GEN;
 	tq->tx_ring.next2fill = tq->tx_ring.next2comp = 0;

[...]

Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4 -0
+static int
+vmxnet3_xdp_set(struct net_device *netdev, struct netdev_bpf *bpf,
+		struct netlink_ext_ack *extack)
+{

drivers/net/vmxnet3/vmxnet3_xdp.c line 32

Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10 -0
+	struct vmxnet3_adapter *adapter = netdev_priv(netdev);
+	struct bpf_prog *new_bpf_prog = bpf->prog;
+	struct bpf_prog *old_bpf_prog;
+	unsigned int max_mtu;
+	bool need_update;
+	bool running;
+	int err;
+
+	max_mtu = SKB_WITH_OVERHEAD(PAGE_SIZE - VMXNET3_XDP_HEADROOM) -
+				    netdev->hard_header_len;

Wrong alignment. You aligned it to the opening brace, but the last variable itself is not inside the braces.
Either align it to 'SKB' or include into the expression inside the braces, both is fine.

Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4 -0
+	if (new_bpf_prog && netdev->mtu > max_mtu) {
+		NL_SET_ERR_MSG_MOD(extack, "MTU too large for XDP");
+		return -EOPNOTSUPP;
+	}

[...]

Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4 -0
+	default:
+		bpf_warn_invalid_xdp_action(rq->adapter->netdev, prog, act);
+		fallthrough;
+	case XDP_ABORTED:

drivers/net/vmxnet3/vmxnet3_xdp.c line 290

Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10 -0
+		trace_xdp_exception(rq->adapter->netdev, prog, act);
+		rq->stats.xdp_aborted++;
+		break;
+	case XDP_DROP:
+		rq->stats.xdp_drops++;
+		break;
+	}
+
+	page_pool_recycle_direct(rq->page_pool,
+				 virt_to_head_page(xdp->data_hard_start));

Nit: you can reuse the @page variable to make this one more elegant, too :)

	page = virt_to ...
	page_pool_recycle_direct(pool, page);
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +7 -0
+
+	return act;
+}
+
+static struct sk_buff *
+vmxnet3_build_skb(struct vmxnet3_rx_queue *rq, struct page *page,
+		  const struct xdp_buff *xdp)

[...]

drivers/net/vmxnet3/vmxnet3_xdp.c line 335

Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +8 -0
+	page = page_pool_alloc_pages(rq->page_pool, GFP_ATOMIC);
+	if (unlikely(!page)) {
+		rq->stats.rx_buf_alloc_failure++;
+		return XDP_DROP;
+	}
+
+	xdp_init_buff(&xdp, PAGE_SIZE, &rq->xdp_rxq);
+	xdp_prepare_buff(&xdp, page_address(page), XDP_PACKET_HEADROOM,

Isn't page_pool->p.offset more correct here instead of just %XDP_PACKET_HEADROOM? You included %NET_IP_ALIGN there.

drivers/net/vmxnet3/vmxnet3_xdp.c line 340

Quoted 5 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +5 -0
+			 len, false);
+	xdp_buff_clear_frags_flag(&xdp);
+
+	/* Must copy the data because it's at dataring. */
+	memcpy(xdp.data, data, len);

Aren't you missing dma_sync_single_for_cpu() before this memcpy()?

Quoted 2 lines
(quoted diff) +2 -0
+
+	rcu_read_lock();

[...]

Quoted 9 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +9 -0
+int
+vmxnet3_process_xdp(struct vmxnet3_adapter *adapter,
+		    struct vmxnet3_rx_queue *rq,
+		    struct Vmxnet3_RxCompDesc *rcd,
+		    struct vmxnet3_rx_buf_info *rbi,
+		    struct Vmxnet3_RxDesc *rxd,
+		    struct sk_buff **skb_xdp_pass)
+{
+	struct bpf_prog *xdp_prog;

drivers/net/vmxnet3/vmxnet3_xdp.c line 382

Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10 -0
+	dma_addr_t new_dma_addr;
+	struct xdp_buff xdp;
+	struct page *page;
+	void *new_data;
+	int act;
+
+	page = rbi->page;
+	dma_sync_single_for_cpu(&adapter->pdev->dev,
+				page_pool_get_dma_addr(page) +
+				XDP_PACKET_HEADROOM, rcd->len,

Same.

drivers/net/vmxnet3/vmxnet3_xdp.c line 386

Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4 -0
+				page_pool_get_dma_dir(rq->page_pool));
+
+	xdp_init_buff(&xdp, rbi->len, &rq->xdp_rxq);
+	xdp_prepare_buff(&xdp, page_address(page), XDP_PACKET_HEADROOM,

Same.

drivers/net/vmxnet3/vmxnet3_xdp.c line 395

Quoted 9 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +9 -0
+			 rcd->len, false);
+	xdp_buff_clear_frags_flag(&xdp);
+
+	rcu_read_lock();
+	xdp_prog = rcu_dereference(rq->adapter->xdp_bpf_prog);
+	if (!xdp_prog) {
+		rcu_read_unlock();
+		act = XDP_PASS;
+		goto refill;

Is it correct to go to 'refill' here? You miss vmxnet3_build_skb() this way. And when you call vmxne3_process_xdp_small() later during the NAPI poll, you also don't build an skb and go to 'sop_done' directly instead. So I feel you must add a new label below and go to it instead, just like you do in process_xdp():

drivers/net/vmxnet3/vmxnet3_xdp.c line 353

Quoted 5 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +5 -0
+	}
+	act = vmxnet3_run_xdp(rq, &xdp);
+	rcu_read_unlock();
+
+	if (act == XDP_PASS) {

here:

Quoted 9 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +9 -0
+		*skb_xdp_pass = vmxnet3_build_skb(rq, page, &xdp);
+		if (!skb_xdp_pass)
+			act = XDP_DROP;
+	}
+
+refill:
+	new_data = vmxnet3_pp_get_buff(rq->page_pool, &new_dma_addr,
+				       GFP_ATOMIC);
+	if (!new_data) {

drivers/net/vmxnet3/vmxnet3_xdp.c line 419

Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10 -0
+		rq->stats.rx_buf_alloc_failure++;
+		return XDP_DROP;
+	}
+	rbi->page = virt_to_head_page(new_data);
+	rbi->dma_addr = new_dma_addr;
+	rxd->addr = cpu_to_le64(rbi->dma_addr);
+	rxd->len = rbi->len;
+
+	return act;
+}

+ a couple notes in the reply to your previous revision. I feel like one more spin and I won't have any more comments, will be good to me :)

Thanks,
Olek

author
#2 lore raw

Hi Alexander,

Thanks for finding more issues in my code!

Quoted 38 lines · Alexander Lobakin

From: William Tu <[email protected]>
Date: Mon, 23 Jan 2023 20:45:15 -0800

Quoted 3 lines

The patch adds native-mode XDP support: XDP DROP, PASS, TX, and REDIRECT.

Background:

[...]

Quoted 28 lines
drivers/net/vmxnet3/vmxnet3_drv.c +9 -1
@@ -414,26 +427,34 @@ static void
 vmxnet3_tq_cleanup(struct vmxnet3_tx_queue *tq,
                 struct vmxnet3_adapter *adapter)
 {
+     struct xdp_frame_bulk bq;
+     u32 map_type;
      int i;
 
+     xdp_frame_bulk_init(&bq);
+
      while (tq->tx_ring.next2comp != tq->tx_ring.next2fill) {
              struct vmxnet3_tx_buf_info *tbi;
 
              tbi = tq->buf_info + tq->tx_ring.next2comp;
+             map_type = tbi->map_type;
 
              vmxnet3_unmap_tx_buf(tbi, adapter->pdev);
              if (tbi->skb) {
-                     dev_kfree_skb_any(tbi->skb);
+                     if (map_type & VMXNET3_MAP_XDP)
+                             xdp_return_frame_bulk(tbi->xdpf, &bq);
+                     else
+                             dev_kfree_skb_any(tbi->skb);
                      tbi->skb = NULL;
              }
              vmxnet3_cmd_ring_adv_next2comp(&tq->tx_ring);
      }
 
Quoted 8 lines

drivers/net/vmxnet3/vmxnet3_drv.c static void · line 453

Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1 -5
-     /* sanity check, verify all buffers are indeed unmapped and freed */
-     for (i = 0; i < tq->tx_ring.size; i++) {
-             BUG_ON(tq->buf_info[i].skb != NULL ||
-                    tq->buf_info[i].map_type != VMXNET3_MAP_NONE);
-     }
+     xdp_flush_frame_bulk(&bq);

Breh, I forgot you need to lock RCU read for bulk-flushing...

Thanks, I didn't notice that, will do it.

Quoted 32 lines

xdp_frame_bulk_init();
rcu_read_lock();

...

xdp_flush_frame_bulk();
rcu_read_unlock();

In both places where you use it.

Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_drv.c +4 -0
+
+     /* sanity check, verify all buffers are indeed unmapped */
+     for (i = 0; i < tq->tx_ring.size; i++)
+             BUG_ON(tq->buf_info[i].map_type != VMXNET3_MAP_NONE);
 
      tq->tx_ring.gen = VMXNET3_INIT_GEN;
      tq->tx_ring.next2fill = tq->tx_ring.next2comp = 0;

[...]

Quoted 11 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +11 -0
+static int
+vmxnet3_xdp_set(struct net_device *netdev, struct netdev_bpf *bpf,
+             struct netlink_ext_ack *extack)
+{
+     struct vmxnet3_adapter *adapter = netdev_priv(netdev);
+     struct bpf_prog *new_bpf_prog = bpf->prog;
+     struct bpf_prog *old_bpf_prog;
+     unsigned int max_mtu;
+     bool need_update;
+     bool running;
+     int err;
Quoted 8 lines

drivers/net/vmxnet3/vmxnet3_xdp.c line 32

Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +3 -0
+
+     max_mtu = SKB_WITH_OVERHEAD(PAGE_SIZE - VMXNET3_XDP_HEADROOM) -
+                                 netdev->hard_header_len;

Wrong alignment. You aligned it to the opening brace, but the last variable itself is not inside the braces.
Either align it to 'SKB' or include into the expression inside the braces, both is fine.

sorry, my mistake again. Will fix it.

Quoted 23 lines
Quoted 5 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4 -0
+     if (new_bpf_prog && netdev->mtu > max_mtu) {
+             NL_SET_ERR_MSG_MOD(extack, "MTU too large for XDP");
+             return -EOPNOTSUPP;
+     }

[...]

Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4 -0
+     default:
+             bpf_warn_invalid_xdp_action(rq->adapter->netdev, prog, act);
+             fallthrough;
+     case XDP_ABORTED:

drivers/net/vmxnet3/vmxnet3_xdp.c line 290

Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10 -0
+             trace_xdp_exception(rq->adapter->netdev, prog, act);
+             rq->stats.xdp_aborted++;
+             break;
+     case XDP_DROP:
+             rq->stats.xdp_drops++;
+             break;
+     }
+
+     page_pool_recycle_direct(rq->page_pool,
+                              virt_to_head_page(xdp->data_hard_start));
Quoted 1 line

Nit: you can reuse the @page variable to make this one more elegant, too :)

Will do.

Quoted 23 lines
        page = virt_to ...
        page_pool_recycle_direct(pool, page);
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +7 -0
+
+     return act;
+}
+
+static struct sk_buff *
+vmxnet3_build_skb(struct vmxnet3_rx_queue *rq, struct page *page,
+               const struct xdp_buff *xdp)

[...]

drivers/net/vmxnet3/vmxnet3_xdp.c line 335

Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +8 -0
+     page = page_pool_alloc_pages(rq->page_pool, GFP_ATOMIC);
+     if (unlikely(!page)) {
+             rq->stats.rx_buf_alloc_failure++;
+             return XDP_DROP;
+     }
+
+     xdp_init_buff(&xdp, PAGE_SIZE, &rq->xdp_rxq);
+     xdp_prepare_buff(&xdp, page_address(page), XDP_PACKET_HEADROOM,
Quoted 2 lines

Isn't page_pool->p.offset more correct here instead of just %XDP_PACKET_HEADROOM? You included %NET_IP_ALIGN there.

Yes, will fix here and others below.

Quoted 8 lines

drivers/net/vmxnet3/vmxnet3_xdp.c line 340

Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +5 -0
+                      len, false);
+     xdp_buff_clear_frags_flag(&xdp);
+
+     /* Must copy the data because it's at dataring. */
+     memcpy(xdp.data, data, len);

Aren't you missing dma_sync_single_for_cpu() before this memcpy()?

We don't need to dma_sync_single_for_cpu here because the xdp.data is part of the rx ring (%rq->data_ring.base) and using dma_alloc_coherent.

Quoted 45 lines
Quoted 3 lines
(quoted diff) +2 -0
+
+     rcu_read_lock();

[...]

Quoted 9 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +9 -0
+int
+vmxnet3_process_xdp(struct vmxnet3_adapter *adapter,
+                 struct vmxnet3_rx_queue *rq,
+                 struct Vmxnet3_RxCompDesc *rcd,
+                 struct vmxnet3_rx_buf_info *rbi,
+                 struct Vmxnet3_RxDesc *rxd,
+                 struct sk_buff **skb_xdp_pass)
+{
+     struct bpf_prog *xdp_prog;

drivers/net/vmxnet3/vmxnet3_xdp.c line 382

Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10 -0
+     dma_addr_t new_dma_addr;
+     struct xdp_buff xdp;
+     struct page *page;
+     void *new_data;
+     int act;
+
+     page = rbi->page;
+     dma_sync_single_for_cpu(&adapter->pdev->dev,
+                             page_pool_get_dma_addr(page) +
+                             XDP_PACKET_HEADROOM, rcd->len,

Same.

drivers/net/vmxnet3/vmxnet3_xdp.c line 386

Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4 -0
+                             page_pool_get_dma_dir(rq->page_pool));
+
+     xdp_init_buff(&xdp, rbi->len, &rq->xdp_rxq);
+     xdp_prepare_buff(&xdp, page_address(page), XDP_PACKET_HEADROOM,

Same.

drivers/net/vmxnet3/vmxnet3_xdp.c line 395

Quoted 9 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +9 -0
+                      rcd->len, false);
+     xdp_buff_clear_frags_flag(&xdp);
+
+     rcu_read_lock();
+     xdp_prog = rcu_dereference(rq->adapter->xdp_bpf_prog);
+     if (!xdp_prog) {
+             rcu_read_unlock();
+             act = XDP_PASS;
+             goto refill;
Quoted 5 lines

Is it correct to go to 'refill' here? You miss vmxnet3_build_skb() this way. And when you call vmxne3_process_xdp_small() later during the NAPI poll, you also don't build an skb and go to 'sop_done' directly instead. So I feel you must add a new label below and go to it instead, just like you do in process_xdp():

good catch and you're right, will add another label below.

Quoted 22 lines

drivers/net/vmxnet3/vmxnet3_xdp.c line 353

Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +5 -0
+     }
+     act = vmxnet3_run_xdp(rq, &xdp);
+     rcu_read_unlock();
+
+     if (act == XDP_PASS) {

here:

Quoted 13 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +13 -0
+             *skb_xdp_pass = vmxnet3_build_skb(rq, page, &xdp);
+             if (!skb_xdp_pass)
+                     act = XDP_DROP;
+     }
+
+refill:
+     new_data = vmxnet3_pp_get_buff(rq->page_pool, &new_dma_addr,
+                                    GFP_ATOMIC);
+     if (!new_data) {
+             rq->stats.rx_buf_alloc_failure++;
+             return XDP_DROP;
+     }
+     rbi->page = virt_to_head_page(new_data);
Quoted 8 lines

drivers/net/vmxnet3/vmxnet3_xdp.c line 419

Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +6 -0
+     rbi->dma_addr = new_dma_addr;
+     rxd->addr = cpu_to_le64(rbi->dma_addr);
+     rxd->len = rbi->len;
+
+     return act;
+}

+ a couple notes in the reply to your previous revision. I feel like one more spin and I won't have any more comments, will be good to me :)

Will start working on next version, thanks again!
William