vmxnet3: Add XDP support.
Subsystems (3)
RFC PATCH v13 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-modeXDP_DROP: 1.6Mpps -> 2.4MppsXDP_PASS: 338Kpps -> 367KppsXDP_TX: 1.1Mpps -> 2.3Mpps
REDIRECT-drop: 1.3Mpps -> 2.3Mpps
512B: skb-mode -> native-modeXDP_DROP: 863Kpps -> 1.3MppsXDP_PASS: 275Kpps -> 376KppsXDP_TX: 554Kpps -> 1.2Mpps
REDIRECT-drop: 659Kpps -> 1.2Mpps
Limitations:
a. LRO will be disabled when users load XDP program b. MTU will be checked and limit to
VMXNET3_MAX_SKB_BUF_SIZE(3K) - XDP_PACKET_HEADROOM(256) - SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
---
v12 -> v13:
- feedbacks from Guolin:
Instead of return -ENOTSUPP, disable the LRO in
netdev->features, and print err msg
- add Sankararaman Jayaraman into CC list
- v12..v13
https://github.com/williamtu/net-next/compare/v12..v13
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
v9 -> v10:
- Mark as RFC as we're waiting for internal review Feedback from Alexander Duyck
- fix dma mapping leak of ndo_xdp_xmit case
- remove unused MAP_INVALID and adjist bitfield
v8 -> v9:
new
- add rxdataring support (need extra copy but still fast)
- update performance number (much better than v8!)
https://youtu.be/4lm1CSCi78Q
- work on feedbacks from Alexander Duyck and Alexander Lobakin Alexander Lobakin
- use xdp_return_frame_bulk and see some performance improvement
- use xdp_do_flush not xdp_do_flush_map
- fix several alignment issues, formatting issues, minor code restructure, remove 2 dead functions, unrelated add/del of new lines, add braces when logical ops nearby, endianness conversion
- remove several oneliner goto label
- anonymous union of skb and xdpf
- remove xdp_enabled and use xdp prog directly to check
- use bitsfields macro --> I decide to do it later as there are many unrelated places needed to change.
Alexander Duyck
- use bitfield for tbi map type
- anonymous union of skb and xdpf
- remove use of modulus ops, cpu % tq_number
others
- fix issue reported from kernel test robot using sparse
v7 -> v8:
- work on feedbacks from Gerhard Engleder and Alexander
- change memory model to use page pool API, rewrite some of the XDP processing code
- attach bpf xdp prog to adapter, not per rx queue
- I reference some of the XDP implementation from drivers/net/ethernet/mediatek and drivers/net/ethernet/stmicro/stmmac/
- drop support for rxdataring for this version
- redo performance evaluation and demo here
https://youtu.be/T7_0yrCXCe0
- check using /sys/kernel/debug/kmemleak
v6 -> v7:
work on feedbacks from Alexander Duyck on XDP_TX and XDP_REDIRECT
- fix memleak of xdp frame when doing ndo_xdp_xmit (vmxnet3_xdp_xmit)
- at vmxnet3_xdp_xmit_frame, fix return value, -NOSPC and ENOMEM, and free skb when dma map fails
- add xdp_buff_clean_frags_flag since we don't support frag
- update experiements of XDP_TX and XDP_REDIRECT
- for XDP_REDIRECT, I assume calling xdp_do_redirect will take the buffer and free it, so I need to allocate a new buffer to refill the rx ring. However, I hit some OOM when testing using ./samples/bpf/xdp_redirect_cpu -d ens160 -c 0 -e <drop or pass>
- I couldn't find the reason so mark this patch as RFC
I tested the patch using below script:
while [ true ]; do
timeout 20 ./samples/bpf/xdp_rxq_info -d ens160 -a XDP_DROP --skb-mode timeout 20 ./samples/bpf/xdp_rxq_info -d ens160 -a XDP_DROP timeout 20 ./samples/bpf/xdp_rxq_info -d ens160 -a XDP_PASS --skb-mode timeout 20 ./samples/bpf/xdp_rxq_info -d ens160 -a XDP_PASS timeout 20 ./samples/bpf/xdp_rxq_info -d ens160 -a XDP_TX --skb-mode timeout 20 ./samples/bpf/xdp_rxq_info -d ens160 -a XDP_TX timeout 20 ./samples/bpf/xdp_redirect_cpu -d ens160 -c 0 -e drop timeout 20 ./samples/bpf/xdp_redirect_cpu -d ens160 -c 0 -e pass done
--- drivers/net/Kconfig | 1 + drivers/net/vmxnet3/Makefile | 2 +- drivers/net/vmxnet3/vmxnet3_drv.c | 225 ++++++++++++-- drivers/net/vmxnet3/vmxnet3_ethtool.c | 14 + drivers/net/vmxnet3/vmxnet3_int.h | 44 ++- drivers/net/vmxnet3/vmxnet3_xdp.c | 425 ++++++++++++++++++++++++++ drivers/net/vmxnet3/vmxnet3_xdp.h | 41 +++ 7 files changed, 708 insertions(+), 44 deletions(-) create mode 100644 drivers/net/vmxnet3/vmxnet3_xdp.c create mode 100644 drivers/net/vmxnet3/vmxnet3_xdp.h
drivers/net/Kconfig +1 -0
@@ -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
@@ -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 +192 -33
431 lines not on this page · raw message
drivers/net/vmxnet3/vmxnet3_ethtool.c +14 -0
@@ -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 +34 -10
108 lines not on this page · raw message
drivers/net/vmxnet3/vmxnet3_xdp.c new file +425 -0
425 lines not on this page · raw message
drivers/net/vmxnet3/vmxnet3_xdp.h new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 83 lines · William Tu
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 usingalloc_skbAPIs 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 thanVMXNET3_MAX_SKB_BUF_SIZE. Each buffer in r1 is allocated usingalloc_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_completeand handle its returned action. Thevmxnet3_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_TXdoes 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 byteVM2 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_TXTo test REDIRECT to cpu 0, use
$ ./samples/bpf/xdp_redirect_cpu -d ens160 -c 0 -e dropSingle core performance comparison with skb-mode.
64B: skb-mode -> native-modeXDP_DROP: 1.6Mpps -> 2.4MppsXDP_PASS: 338Kpps -> 367KppsXDP_TX: 1.1Mpps -> 2.3Mpps
REDIRECT-drop: 1.3Mpps -> 2.3Mpps512B: skb-mode -> native-mode
XDP_DROP: 863Kpps -> 1.3MppsXDP_PASS: 275Kpps -> 376KppsXDP_TX: 554Kpps -> 1.2Mpps
REDIRECT-drop: 659Kpps -> 1.2Mpps
Quoted 7 lines
Limitations:
a. LRO will be disabled when users load XDP program b. MTU will be checked and limit to
VMXNET3_MAX_SKB_BUF_SIZE(3K)-XDP_PACKET_HEADROOM(256)-SKB_DATA_ALIGN(sizeof(struct skb_shared_info))Signed-off-by William Tu <[email protected]>
I don't see anything else that jumps out at me as needing to be addressed.
From: William Tu <[email protected]>
Date: Thu, 12 Jan 2023 06:07:43 -0800
First of all, sorry for the huge delay. I have a couple ten thousand lines of code to review this week, not counting LKML submissions >_<
Quoted 1 line
The patch adds native-mode XDP support: XDP DROP, PASS, TX, and REDIRECT.
[...]
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_unmap_tx_buf(struct vmxnet3_tx_buf_info *tbi, · line 362
Quoted 13 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-5- skb = tq->buf_info[eop_idx].skb; -BUG_ON (skb ==NULL ); - tq->buf_info[eop_idx].skb =NULL ; - + tbi = &tq->buf_info[eop_idx]; +BUG_ON (tbi->skb ==NULL ); + map_type = tbi->map_type;VMXNET3_INC_RING_IDX_ONLY (eop_idx, tq->tx_ring.size);while (tq->tx_ring.next2comp != eop_idx) {vmxnet3_unmap_tx_buf (tq->buf_info + tq->tx_ring.next2comp, pdev); -
Nit: please try to avoid such unrelated changes. Moreover, I feel like it's better for readability to have a newline here, so see no reason to remove it.
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_unmap_pkt(u32 eop_idx, struct vmxnet3_tx_queue *tq, · line 377
Quoted 12 lines
drivers/net/vmxnet3/vmxnet3_drv.c +4
-1/* update next2comp w/o tx_lock. Since we are marking more, * instead of less, tx ring entries avail, the worst case is * that the tx routine incorrectly re-queues a pkt due to @@ -369,7 +371,14 @@ vmxnet3_unmap_pkt(u32 eop_idx, struct vmxnet3_tx_queue *tq, entries++; } -dev_kfree_skb_any (skb); +if (map_type &VMXNET3_MAP_XDP ) +xdp_return_frame_bulk (tbi->xdpf, bq); +else +dev_kfree_skb_any (tbi->skb);
Not really related to XDP, but maybe for some future improvements: this function is to be called inside the BH context only, so using napi_consume_skb() would give you some nice perf improvement.
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_tx_complete(struct vmxnet3_tx_queue *tq, · line 392
Quoted 13 lines
drivers/net/vmxnet3/vmxnet3_drv.c +5
-0+ +/* xdpf and skb are in an anonymous union. */ + tbi->skb =NULL ; +return entries; }@@ -379,8 +388,10 @@ vmxnet3_tq_tx_complete(struct vmxnet3_tx_queue *tq, struct vmxnet3_adapter *adapter) {int completed =0 ; +struct xdp_frame_bulk bq;union Vmxnet3_GenericDesc *gdesc;
RCT style of declarations?
Quoted 5 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1
-0+xdp_frame_bulk_init (&bq); gdesc = tq->comp_ring.base + tq->comp_ring.next2proc;while (VMXNET3_TCD_GET_GEN (&gdesc->tcd) == tq->comp_ring.gen) {/* Prevent any &gdesc->tcd field from being (speculatively)
[...]
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq, · line 1291
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +6
-0@@ -1253,6 +1283,60 @@ vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq,return NETDEV_TX_OK ; } +static int +vmxnet3_create_pp (struct vmxnet3_adapter *adapter, +struct vmxnet3_rx_queue *rq,int size) +{ +const struct page_pool_params pp_params = { + .order =0 ,
Nit: it will be zeroed implicitly, so can be omitted. OTOH if you want to explicitly say that you always use order-0 pages only, you can leave it here.
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq, · line 1296
Quoted 5 lines
drivers/net/vmxnet3/vmxnet3_drv.c +5
-0+ .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV, + .pool_size = size, + .nid = NUMA_NO_NODE, + .dev = &adapter->pdev->dev, + .offset = XDP_PACKET_HEADROOM,
Curious, on which architectures does this driver work in the real world? Is it x86 only or maybe 64-bit systems only? Because not having %NET_IP_ALIGN here will significantly slow down Rx on the systems where it's defined as 2, not 0 (those systems can't stand unaligned access).
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +10
-0+ .max_len = VMXNET3_XDP_MAX_MTU, + .dma_dir = DMA_BIDIRECTIONAL, + }; +struct page_pool *pp; +int err; + + pp =page_pool_create (&pp_params); +if (IS_ERR (pp)) +return PTR_ERR (pp); +
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq, · line 1316
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +10
-0+ err =xdp_rxq_info_reg (&rq->xdp_rxq, adapter->netdev, rq->qid, + rq->napi.napi_id); +if (err <0 ) + goto err_free_pp; + + err =xdp_rxq_info_reg_mem_model (&rq->xdp_rxq,MEM_TYPE_PAGE_POOL , pp); +if (err) + goto err_unregister_rxq; + + rq->page_pool = pp;
Nit: newline here?
Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_drv.c +8
-0+return 0 ; + +err_unregister_rxq: +xdp_rxq_info_unreg (&rq->xdp_rxq); +err_free_pp: +page_pool_destroy (pp); + +return err;
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq, · line 1334
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +10
-0+} + +void * +vmxnet3_pp_get_buff (struct page_pool *pp,dma_addr_t *dma_addr, +gfp_t gfp_mask) +{ +struct page *page; + + page =page_pool_alloc_pages (pp, gfp_mask | __GFP_NOWARN); +if (!page)
unlikely()? It's error/exception path, you will never hit this branch under normal conditions.
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq, · line 1337
Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-0+return NULL ; + + *dma_addr =page_pool_get_dma_addr (page) +XDP_PACKET_HEADROOM ;
Hmm, I'd rather say:
*dma_addr = page_pool_get_dma_addr(page) + pp->p.offset;
Then you'd need to adujst offset only once in the function where you create Page Pool if/when you need to change the Rx offset. With the current code, it's easy to forget you need to change it in two places.
Alternatively, you could define something like
#define VMXNET3_RX_OFFSET XDP_PACKET_HEADROOM
and use it here and on Page Pool creation. Then, if you need to change the Rx offset one day, you will adjust only that definition.
(also nit re newline before return?)
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq, · line 1491
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-0+return page_address (page); +}static netdev_tx_t vmxnet3_xmit_frame (struct sk_buff *skb,struct net_device *netdev)@@ -1404,6 +1488,8 @@ vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq,struct Vmxnet3_RxDesc rxCmdDesc;struct Vmxnet3_RxCompDesc rxComp;#endif +bool need_flush =0 ;
= false, it's boolean, not int.
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1
-0+vmxnet3_getRxComp (rcd, &rq->comp_ring.base[rq->comp_ring.next2proc].rcd, &rxComp);while (rcd->gen == rq->comp_ring.gen) {
[...]
Quoted 9 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1
-0@@ -1622,6 +1754,7 @@ vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq, } +sop_done: skb = ctx->skb;if (rcd->eop) {u32 mtu = adapter->netdev->mtu;
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq, · line 1867
Quoted 5 lines
drivers/net/vmxnet3/vmxnet3_drv.c +2
-0@@ -1730,6 +1863,8 @@ vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq,vmxnet3_getRxComp (rcd, &rq->comp_ring.base[rq->comp_ring.next2proc].rcd, &rxComp); } +if (need_flush) +xdp_do_flush ();
What about %XDP_TX? On each %XDP_TX we usually only place the frame to a Tx ring and hit the doorbell to kick Tx only here, before xdp_do_flush().
Quoted 27 lines
drivers/net/vmxnet3/vmxnet3_drv.c +9
-2return num_pkts; }@@ -1755,13 +1890,20 @@ vmxnet3_rq_cleanup(struct vmxnet3_rx_queue *rq, &rq->rx_ring[ring_idx].base[i].rxd, &rxDesc);if (rxd->btype ==VMXNET3_RXD_BTYPE_HEAD && - rq->buf_info[ring_idx][i].skb) { + rq->buf_info[ring_idx][i].pp_page && + rq->buf_info[ring_idx][i].buf_type == +VMXNET3_RX_BUF_XDP ) { +page_pool_recycle_direct (rq->page_pool, + rq->buf_info[ring_idx][i].pp_page); + rq->buf_info[ring_idx][i].pp_page =NULL ; + }else if (rxd->btype ==VMXNET3_RXD_BTYPE_HEAD && + rq->buf_info[ring_idx][i].skb) {dma_unmap_single (&adapter->pdev->dev, rxd->addr, rxd->len,DMA_FROM_DEVICE );dev_kfree_skb (rq->buf_info[ring_idx][i].skb); rq->buf_info[ring_idx][i].skb =NULL ; }else if (rxd->btype ==VMXNET3_RXD_BTYPE_BODY && - rq->buf_info[ring_idx][i].page) { + rq->buf_info[ring_idx][i].page) {dma_unmap_page (&adapter->pdev->dev, rxd->addr, rxd->len,DMA_FROM_DEVICE );put_page (rq->buf_info[ring_idx][i].page);
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_rq_cleanup_all(struct vmxnet3_adapter *adapter) · line 1791
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1
-1@@ -1786,9 +1928,9 @@ vmxnet3_rq_cleanup_all(struct vmxnet3_adapter *adapter)for (i =0 ; i < adapter->num_rx_queues; i++)vmxnet3_rq_cleanup (&adapter->rx_queue[i], adapter); +rcu_assign_pointer (adapter->xdp_bpf_prog,NULL ); } -
(nit: also unrelated)
drivers/net/vmxnet3/vmxnet3_drv.c static void vmxnet3_rq_destroy(struct vmxnet3_rx_queue *rq, · line 1960
Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1
-0static void vmxnet3_rq_destroy (struct vmxnet3_rx_queue *rq,struct vmxnet3_adapter *adapter) {@@ -1815,6 +1957,13 @@ static void vmxnet3_rq_destroy(struct vmxnet3_rx_queue *rq, } } +if (rq->page_pool) {
Isn't it always true? You always create a Page Pool per each RQ IIUC?
Quoted 9 lines
drivers/net/vmxnet3/vmxnet3_drv.c +6
-0+if (xdp_rxq_info_is_reg (&rq->xdp_rxq)) +xdp_rxq_info_unreg (&rq->xdp_rxq); +page_pool_destroy (rq->page_pool); + rq->page_pool =NULL ; + } +if (rq->data_ring.base) { dma_free_coherent(&adapter->pdev->dev, rq->rx_ring[0].size * rq->data_ring.desc_size,
[...]
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_setup_driver_shared(struct vmxnet3_adapter *adapter) · line 2745
Quoted 11 lines
drivers/net/vmxnet3/vmxnet3_drv.c +2
-2-static int +int vmxnet3_rq_create_all (struct vmxnet3_adapter *adapter) {int i, err =0 ;@@ -2585,7 +2742,7 @@ vmxnet3_setup_driver_shared(struct vmxnet3_adapter *adapter)if (adapter->netdev->features &NETIF_F_RXCSUM ) devRead->misc.uptFeatures |=UPT1_F_RXCSUM ; -if (adapter->netdev->features &NETIF_F_LRO ) { +if ((adapter->netdev->features &NETIF_F_LRO )) {
Unneeded change (moreover, Clang sometimes triggers on such on W=1+)
Quoted 23 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-2devRead->misc.uptFeatures |=UPT1_F_LRO ; devRead->misc.maxNumRxSG =cpu_to_le16 (1 +MAX_SKB_FRAGS ); }@@ -3026,7 +3183,7 @@ vmxnet3_free_pci_resources(struct vmxnet3_adapter *adapter) } -static void +void vmxnet3_adjust_rx_ring_size (struct vmxnet3_adapter *adapter) {size_t sz, i, ring0_size, ring1_size, comp_size;@@ -3035,7 +3192,8 @@ vmxnet3_adjust_rx_ring_size(struct vmxnet3_adapter *adapter)if (adapter->netdev->mtu <=VMXNET3_MAX_SKB_BUF_SIZE -VMXNET3_MAX_ETH_HDR_SIZE ) { adapter->skb_buf_size = adapter->netdev->mtu + -VMXNET3_MAX_ETH_HDR_SIZE ; +VMXNET3_MAX_ETH_HDR_SIZE + +vmxnet3_xdp_headroom (adapter);if (adapter->skb_buf_size <VMXNET3_MIN_T0_BUF_SIZE ) adapter->skb_buf_size =VMXNET3_MIN_T0_BUF_SIZE ;
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_reset_work(struct work_struct *data) · line 3566
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_drv.c +0
-1@@ -3563,7 +3721,6 @@ vmxnet3_reset_work(struct work_struct *data)clear_bit (VMXNET3_STATE_BIT_RESETTING , &adapter->state); } -
(unrelated)
Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_drv.c +0
-0static int vmxnet3_probe_device (struct pci_dev *pdev,const struct pci_device_id *id)
[...]
drivers/net/vmxnet3/vmxnet3_int.h struct vmxnet3_tx_queue { · line 269
Quoted 6 lines
enum
vmxnet3_rx_buf_type{drivers/net/vmxnet3/vmxnet3_int.h +2
-1VMXNET3_RX_BUF_NONE =0 ,VMXNET3_RX_BUF_SKB =1 , -VMXNET3_RX_BUF_PAGE =2 +VMXNET3_RX_BUF_PAGE =2 , +VMXNET3_RX_BUF_XDP =3
I'd always leave a ',' after the last entry. As you can see, if you don't do that, you have to introduce 2 lines of changes instead of just 1 when you add a new entry.
drivers/net/vmxnet3/vmxnet3_int.h struct vmxnet3_rx_buf_info { · line 282
Quoted 8 lines
};
#define
VMXNET3_RXD_COMP_PENDING0drivers/net/vmxnet3/vmxnet3_int.h +1
-0@@ -271,6 +279,7 @@ struct vmxnet3_rx_buf_info {union {struct sk_buff *skb;struct page *page; +struct page *pp_page;/* Page Pool for XDP frame */
Why not just use the already existing field if they're of the same type?
Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_int.h +0
-0};dma_addr_t dma_addr; };
[...]
drivers/net/vmxnet3/vmxnet3_xdp.c line 30
Quoted 12 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +12
-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; +bool need_update; +bool running; +int err =0 ; + +if (new_bpf_prog && netdev->mtu >VMXNET3_XDP_MAX_MTU ) {
Mismatch: as I said before, %VMXNET3_XDP_MAX_MTU is not MTU, rather max frame len. At the same time, netdev->mtu is real MTU, which doesn't include Eth, VLAN and FCS.
drivers/net/vmxnet3/vmxnet3_xdp.c line 31
Quoted 1 line
drivers/net/vmxnet3/vmxnet3_xdp.c new file +1
-0+NL_SET_ERR_MSG_MOD (extack,"MTU too large for XDP" );
Any plans to add XDP multi-buffer support?
drivers/net/vmxnet3/vmxnet3_xdp.c line 35
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4
-0+return -EOPNOTSUPP ; + } + +if ((adapter->netdev->features &NETIF_F_LRO )) {
(redundant braces)
drivers/net/vmxnet3/vmxnet3_xdp.c line 36
Quoted 1 line
drivers/net/vmxnet3/vmxnet3_xdp.c new file +1
-0+netdev_err (adapter->netdev,"LRO is not supported with XDP" );
Why is this error printed via netdev_err(), not NL_SET()?
Quoted 19 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +19
-0+ adapter->netdev->features &= ~NETIF_F_LRO ; + } + + old_bpf_prog =rcu_dereference (adapter->xdp_bpf_prog); +if (!new_bpf_prog && !old_bpf_prog) +return 0 ; + + running =netif_running (netdev); + need_update = !!old_bpf_prog != !!new_bpf_prog; + +if (running && need_update) +vmxnet3_quiesce_dev (adapter); + +vmxnet3_xdp_exchange_program (adapter, new_bpf_prog); +if (old_bpf_prog) +bpf_prog_put (old_bpf_prog); + +if (!running || !need_update) +return 0 ;
drivers/net/vmxnet3/vmxnet3_xdp.c line 65
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+ +vmxnet3_reset_dev (adapter); +vmxnet3_rq_destroy_all (adapter); +vmxnet3_adjust_rx_ring_size (adapter); + err =vmxnet3_rq_create_all (adapter); +if (err) { +NL_SET_ERR_MSG_MOD (extack, +"failed to re-create rx queues for XDP." ); + err = -EOPNOTSUPP ; +return err;
return -OPNOTSUPP? Why doing it in two steps?
drivers/net/vmxnet3/vmxnet3_xdp.c line 72
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +7
-0+ } + err =vmxnet3_activate_dev (adapter); +if (err) { +NL_SET_ERR_MSG_MOD (extack, +"failed to activate device for XDP." ); + err = -EOPNOTSUPP ; +return err;
(same)
Review
Quoted 2 lines
(quoted diff) +2
-0+ } + clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);
(classic newline nit)
Review
Quoted 1 line
(quoted diff) +1
-0+ return err;
@err will be 0 at this point, return it directly.
Quoted 15 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +15
-0+} + +/* This is the main xdp call used by kernel to set/unset eBPF program. */ +int +vmxnet3_xdp (struct net_device *netdev,struct netdev_bpf *bpf) +{ +switch (bpf->command) { +case XDP_SETUP_PROG : +return vmxnet3_xdp_set (netdev, bpf, bpf->extack); +default : +return -EINVAL ; + } +return 0 ; +} +
drivers/net/vmxnet3/vmxnet3_xdp.c line 100
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+bool +vmxnet3_xdp_enabled (struct vmxnet3_adapter *adapter) +{ +return !!rcu_access_pointer (adapter->xdp_bpf_prog); +} + +int +vmxnet3_xdp_headroom (struct vmxnet3_adapter *adapter) +{ +return vmxnet3_xdp_enabled (adapter) ?VMXNET3_XDP_PAD :0 ;
Uhm, the function is called '_headroom', but in fact it returns skb overhead (headroom + tailroom).
Also, I don't feel like it's incorrect to return 0 as skb overhead, as you unconditionally set PP offset to %XDP_PACKET_HEADROOM, plus skb tailroom is always SKB_DATA_ALIGN(sizeof(skb_shared_info)) regardless of XDP prog presence. So I'd rather always return _XDP_PAD (or just embed this definition into the single call site).
Quoted 1 line
+}
Making these 2 functions global are overkill and doesn't affect performance positively. They can easily be static inlines.
Quoted 14 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +14
-0+ +static int +vmxnet3_xdp_xmit_frame (struct vmxnet3_adapter *adapter, +struct xdp_frame *xdpf, +struct vmxnet3_tx_queue *tq,bool dma_map) +{ +struct vmxnet3_tx_buf_info *tbi =NULL ; +union Vmxnet3_GenericDesc *gdesc; +struct vmxnet3_tx_ctx ctx; +int tx_num_deferred; +struct page *page; +u32 buf_size; +int ret =0 ; +u32 dw2;
[...]
drivers/net/vmxnet3/vmxnet3_xdp.c line 181
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+dma_wmb (); + gdesc->dword[2 ] =cpu_to_le32 (le32_to_cpu (gdesc->dword[2 ]) ^ +VMXNET3_TXD_GEN ); + +if (tx_num_deferred >=le32_to_cpu (tq->shared->txThreshold)) { + tq->shared->txNumDeferred =0 ; +VMXNET3_WRITE_BAR0_REG (adapter, +VMXNET3_REG_TXPROD + tq->qid *8 , + tq->tx_ring.next2fill); + }
(NL))
Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +8
-0+return ret; +} + +static int +vmxnet3_xdp_xmit_back (struct vmxnet3_adapter *adapter, +struct xdp_frame *xdpf) +{ +struct vmxnet3_tx_queue *tq;
drivers/net/vmxnet3/vmxnet3_xdp.c line 199
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+struct netdev_queue *nq; +int err =0 , cpu; +int tq_number; + + tq_number = adapter->num_tx_queues; + cpu =smp_processor_id (); +if (likely (cpu < tq_number)) + tq = &adapter->tx_queue[cpu]; +else + tq = &adapter->tx_queue[reciprocal_scale (cpu, tq_number)];
Interesting solution, the first time I see such. Usually we do just smp_processor_id() % num_tx_queues. I don't say yours is worse, just a sidenote :)
Quoted 13 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +13
-0+if (tq->stopped) +return -ENETDOWN ; + + nq =netdev_get_tx_queue (adapter->netdev, tq->qid); + +__netif_tx_lock (nq, cpu); + err =vmxnet3_xdp_xmit_frame (adapter, xdpf, tq, false); +__netif_tx_unlock (nq); +return err; +} + +/* ndo_xdp_xmit */ +int
drivers/net/vmxnet3/vmxnet3_xdp.c line 222
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+vmxnet3_xdp_xmit(struct net_device *dev, + int n, struct xdp_frame **frames, u32 flags) +{ + struct vmxnet3_adapter *adapter; +struct vmxnet3_tx_queue *tq; +struct netdev_queue *nq; +int i, err, cpu; +int tq_number; + + adapter =netdev_priv (dev);
Nit: embed into the declaration?
Quoted 44 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +44
-0+ +if (unlikely (test_bit (VMXNET3_STATE_BIT_QUIESCED , &adapter->state))) +return -ENETDOWN ; +if (unlikely (test_bit (VMXNET3_STATE_BIT_RESETTING , &adapter->state))) +return -EINVAL ; + + tq_number = adapter->num_tx_queues; + cpu =smp_processor_id (); +if (likely (cpu < tq_number)) + tq = &adapter->tx_queue[cpu]; +else + tq = &adapter->tx_queue[reciprocal_scale (cpu, tq_number)]; +if (tq->stopped) +return -ENETDOWN ; + + nq =netdev_get_tx_queue (adapter->netdev, tq->qid); + +for (i =0 ; i < n; i++) { + err =vmxnet3_xdp_xmit_frame (adapter, frames[i], tq, true); +if (err) { + tq->stats.xdp_xmit_err++; +break ; + } + } + tq->stats.xdp_xmit += i; + +return i; +} + +static int +vmxnet3_run_xdp (struct vmxnet3_rx_queue *rq,struct xdp_buff *xdp) +{ +struct xdp_frame *xdpf; +struct bpf_prog *prog; +int err; +u32 act; + + prog =rcu_dereference (rq->adapter->xdp_bpf_prog); + act =bpf_prog_run_xdp (prog, xdp); + rq->stats.xdp_packets++; + +switch (act) { +case XDP_PASS : +return act;
drivers/net/vmxnet3/vmxnet3_xdp.c line 276
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+case XDP_REDIRECT : + err =xdp_do_redirect (rq->adapter->netdev, xdp, prog); +if (!err) + rq->stats.xdp_redirects++; +else + rq->stats.xdp_drops++; +return act; +case XDP_TX : + xdpf =xdp_convert_buff_to_frame (xdp); +if (!xdpf ||vmxnet3_xdp_xmit_back (rq->adapter, xdpf)) {
I think this also could be unlikely()?
drivers/net/vmxnet3/vmxnet3_xdp.c line 279
Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +3
-0+ rq->stats.xdp_drops++; +page_pool_recycle_direct (rq->page_pool, +virt_to_head_page (xdp->data_hard_start));
Uff, I don't like this line break. Maybe grab the page into a local var at first and then pass it to the function?
Quoted 46 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +46
-0+ }else { + rq->stats.xdp_tx++; + } +return act; +default : +bpf_warn_invalid_xdp_action (rq->adapter->netdev, prog, act); + fallthrough; +case XDP_ABORTED : +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)); +return act; +} + +static struct sk_buff * +vmxnet3_build_skb (struct vmxnet3_rx_queue *rq,struct page *page, +const struct xdp_buff *xdp) +{ +struct sk_buff *skb; + + skb =build_skb (page_address (page),PAGE_SIZE ); +if (unlikely (!skb)) { +page_pool_recycle_direct (rq->page_pool, page); + rq->stats.rx_buf_alloc_failure++; +return NULL ; + } + +/* bpf prog might change len and data position. */ +skb_reserve (skb, xdp->data - xdp->data_hard_start); +skb_put (skb, xdp->data_end - xdp->data); +skb_mark_for_recycle (skb); + +return skb; +} + +/* Handle packets from DataRing. */ +int +vmxnet3_process_xdp_small(struct vmxnet3_adapter *adapter, + struct vmxnet3_rx_queue *rq,
drivers/net/vmxnet3/vmxnet3_xdp.c line 335
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+ void *data, int len, + struct sk_buff **skb_xdp_pass) +{ + struct bpf_prog *xdp_prog; +struct xdp_buff xdp; +struct page *page; +int act; + + page =page_pool_alloc_pages (rq->page_pool,GFP_ATOMIC ); +if (!page) {
(unlikely nit)
drivers/net/vmxnet3/vmxnet3_xdp.c line 346
Quoted 11 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +11
-0+ 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 , + len, false); +xdp_buff_clear_frags_flag (&xdp); + +/* Must copy the data because it's at dataring. */ +memcpy (xdp.data, data, len);
Wanted to write "oh, too bad we have to copy the data" and only then noticed your explanation that dataring is used for frames < 128 bytes only :D
drivers/net/vmxnet3/vmxnet3_xdp.c line 359
Quoted 13 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +13
-0+ +rcu_read_lock (); + xdp_prog =rcu_dereference (rq->adapter->xdp_bpf_prog); +if (!xdp_prog) { +rcu_read_unlock (); +page_pool_recycle_direct (rq->page_pool, page); + act =XDP_PASS ; + goto out_skb; + } + act =vmxnet3_run_xdp (rq, &xdp); +rcu_read_unlock (); + +out_skb:
Nit: you can move this label one line below and skip always-true branch when !xdp_prog.
Quoted 5 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +5
-0+if (act ==XDP_PASS ) { + *skb_xdp_pass =vmxnet3_build_skb (rq, page, &xdp); +if (!skb_xdp_pass) +return XDP_DROP ; + }
[...]
drivers/net/vmxnet3/vmxnet3_xdp.h line 22
Quoted 5 lines
drivers/net/vmxnet3/vmxnet3_xdp.h new file +5
-0+#include "vmxnet3_int.h" + +#define VMXNET3_XDP_PAD (SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) + \ + XDP_PACKET_HEADROOM) +#define VMXNET3_XDP_MAX_MTU (PAGE_SIZE - VMXNET3_XDP_PAD)
Uhm, couldn't say it's valid to name it as "MTU", it's rather max frame size. MTU doesn't include Ethernet, VLAN headers and FCS.
Quoted 9 lines
drivers/net/vmxnet3/vmxnet3_xdp.h new file +9
-0+ +int vmxnet3_xdp (struct net_device *netdev,struct netdev_bpf *bpf); +bool vmxnet3_xdp_enabled (struct vmxnet3_adapter *adapter); +int vmxnet3_xdp_headroom (struct vmxnet3_adapter *adapter); +int vmxnet3_xdp_xmit (struct net_device *dev,int n,struct xdp_frame **frames, +u32 flags); +int vmxnet3_process_xdp(struct vmxnet3_adapter *adapter, + struct vmxnet3_rx_queue *rq, + struct Vmxnet3_RxCompDesc *rcd,
drivers/net/vmxnet3/vmxnet3_xdp.h line 41
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.h new file +10
-0+struct vmxnet3_rx_buf_info *rbi, + struct Vmxnet3_RxDesc *rxd, + struct sk_buff **skb_xdp_pass); +int vmxnet3_process_xdp_small (struct vmxnet3_adapter *adapter, +struct vmxnet3_rx_queue *rq, +void *data,int len, +struct sk_buff **skb_xdp_pass); +void *vmxnet3_pp_get_buff (struct page_pool *pp,dma_addr_t *dma_addr, +gfp_t gfp_mask); +#endif
Thanks,
Olek
Quoted 7 lines · Alexander Lobakin
From: William Tu <[email protected]>
Date: Thu, 12 Jan 2023 06:07:43 -0800First of all, sorry for the huge delay. I have a couple ten thousand lines of code to review this week, not counting LKML submissions >_<
Hi Alexander,
I totally understand, and thanks again for taking another review of this patch. Your feedback is very much appreciated.
Quoted 13 lines
Quoted 1 line
The patch adds native-mode XDP support: XDP DROP, PASS, TX, and REDIRECT.
[...]
Quoted 9 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-4- skb = tq->buf_info[eop_idx].skb; -BUG_ON (skb ==NULL ); - tq->buf_info[eop_idx].skb =NULL ; - + tbi = &tq->buf_info[eop_idx]; +BUG_ON (tbi->skb ==NULL ); + map_type = tbi->map_type;VMXNET3_INC_RING_IDX_ONLY (eop_idx, tq->tx_ring.size);
Quoted 8 lines
Quoted 4 lines
while (tq->tx_ring.next2comp != eop_idx) { vmxnet3_unmap_tx_buf(tq->buf_info + tq->tx_ring.next2comp, pdev);-
Nit: please try to avoid such unrelated changes. Moreover, I feel like it's better for readability to have a newline here, so see no reason to remove it.
Thanks! There are many mistakes like this below (either missing or need space, RCT style, adding unlikely, Unneeded change), I will fix them in next version.
Quoted 8 lines
Quoted 8 lines
/* update next2comp w/o
tx_lock. Since we are marking more,
* instead of less, tx ring entries avail, the worst case is
* that the tx routine incorrectly re-queues a pkt due todrivers/net/vmxnet3/vmxnet3_drv.c +0
-0@@ -369,7 +371,14 @@ vmxnet3_unmap_pkt(u32 eop_idx, struct vmxnet3_tx_queue *tq, entries++; }
Quoted 9 lines
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_unmap_pkt(u32 eop_idx, struct vmxnet3_tx_queue *tq, · line 377
Quoted 5 lines
drivers/net/vmxnet3/vmxnet3_drv.c +4
-1-dev_kfree_skb_any (skb); +if (map_type &VMXNET3_MAP_XDP ) +xdp_return_frame_bulk (tbi->xdpf, bq); +else +dev_kfree_skb_any (tbi->skb);Not really related to XDP, but maybe for some future improvements: this function is to be called inside the BH context only, so using
napi_consume_skb()would give you some nice perf improvement.
Sure, thanks for pointing this. I will keep this in future work list in the commit message.
Quoted 29 lines
Quoted 9 lines
drivers/net/vmxnet3/vmxnet3_drv.c +4
-0+ +/* xdpf and skb are in an anonymous union. */ + tbi->skb =NULL ; +return entries; }drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_tx_complete(struct vmxnet3_tx_queue *tq, · line 392
Quoted 5 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1
-0@@ -379,8 +388,10 @@ vmxnet3_tq_tx_complete(struct vmxnet3_tx_queue *tq, struct vmxnet3_adapter *adapter) {int completed =0 ; +struct xdp_frame_bulk bq;union Vmxnet3_GenericDesc *gdesc;RCT style of declarations?
Quoted 5 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1
-0+xdp_frame_bulk_init (&bq); gdesc = tq->comp_ring.base + tq->comp_ring.next2proc;while (VMXNET3_TCD_GET_GEN (&gdesc->tcd) == tq->comp_ring.gen) {/* Prevent any &gdesc->tcd field from being (speculatively) [...]
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_drv.c +0
-0@@ -1253,6 +1283,60 @@ vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq,return NETDEV_TX_OK ; }
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq, · line 1291
Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_drv.c +6
-0+static int +vmxnet3_create_pp (struct vmxnet3_adapter *adapter, +struct vmxnet3_rx_queue *rq,int size) +{ +const struct page_pool_params pp_params = { + .order =0 ,Nit: it will be zeroed implicitly, so can be omitted. OTOH if you want to explicitly say that you always use order-0 pages only, you can leave it here.
I will leave it here as it's more clear.
Quoted 11 lines
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq, · line 1296
Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_drv.c +5
-0+ .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV, + .pool_size = size, + .nid = NUMA_NO_NODE, + .dev = &adapter->pdev->dev, + .offset = XDP_PACKET_HEADROOM,Curious, on which architectures does this driver work in the real world? Is it x86 only or maybe 64-bit systems only? Because not having %NET_IP_ALIGN here will significantly slow down Rx on the systems where it's defined as 2, not 0 (those systems can't stand unaligned access).
Interesting, and I don't know that after I research a little. I tested only on x86 and 64bit. But in reality vmxnet3 works in other architectures.
I will define s.t like below
#define VMXNET3_XDP_HEADROOM (XDP_PACKET_HEADROOM + NET_IP_ALIGN)
Quoted 54 lines
Quoted 11 lines
drivers/net/vmxnet3/vmxnet3_drv.c +10
-0+ .max_len = VMXNET3_XDP_MAX_MTU, + .dma_dir = DMA_BIDIRECTIONAL, + }; +struct page_pool *pp; +int err; + + pp =page_pool_create (&pp_params); +if (IS_ERR (pp)) +return PTR_ERR (pp); +drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq, · line 1316
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +10
-0+ err =xdp_rxq_info_reg (&rq->xdp_rxq, adapter->netdev, rq->qid, + rq->napi.napi_id); +if (err <0 ) + goto err_free_pp; + + err =xdp_rxq_info_reg_mem_model (&rq->xdp_rxq,MEM_TYPE_PAGE_POOL , pp); +if (err) + goto err_unregister_rxq; + + rq->page_pool = pp;Nit: newline here?
Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_drv.c +8
-0+return 0 ; + +err_unregister_rxq: +xdp_rxq_info_unreg (&rq->xdp_rxq); +err_free_pp: +page_pool_destroy (pp); + +return err;drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq, · line 1334
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +10
-0+} + +void * +vmxnet3_pp_get_buff (struct page_pool *pp,dma_addr_t *dma_addr, +gfp_t gfp_mask) +{ +struct page *page; + + page =page_pool_alloc_pages (pp, gfp_mask | __GFP_NOWARN); +if (!page)
unlikely()? It's error/exception path, you will never hit this branch under normal conditions.drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq, · line 1337
Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-0+return NULL ; + + *dma_addr =page_pool_get_dma_addr (page) +XDP_PACKET_HEADROOM ;Hmm, I'd rather say:
*dma_addr = page_pool_get_dma_addr(page) + pp->p.offset;
Quoted 7 lines
Then you'd need to adujst offset only once in the function where you create Page Pool if/when you need to change the Rx offset. With the current code, it's easy to forget you need to change it in two places.
Alternatively, you could define something like#define
VMXNET3_RX_OFFSETXDP_PACKET_HEADROOM
got it, thanks.
Also consider the NET_IP_ALIGN suggestion, I will do
#define VMXNET3_RX_OFFSET (XDP_PACKET_HEADROOM + NET_IP_ALIGN)
Quoted 30 lines
and use it here and on Page Pool creation. Then, if you need to change the Rx offset one day, you will adjust only that definition.
(also nit re newline before return?)
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq, · line 1491
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-0+return page_address (page); +}static netdev_tx_t vmxnet3_xmit_frame (struct sk_buff *skb,struct net_device *netdev)@@ -1404,6 +1488,8 @@ vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq,struct Vmxnet3_RxDesc rxCmdDesc;struct Vmxnet3_RxCompDesc rxComp;#endif +bool need_flush =0 ;= false, it's boolean, not int.
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1
-0+vmxnet3_getRxComp (rcd, &rq->comp_ring.base[rq->comp_ring.next2proc].rcd, &rxComp);while (rcd->gen == rq->comp_ring.gen) {[...]
Quoted 4 lines
(quoted diff) +0
-0@@ -1622,6 +1754,7 @@ vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq, }
Quoted 13 lines
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq, · line 1867
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-0+sop_done: skb = ctx->skb;if (rcd->eop) {u32 mtu = adapter->netdev->mtu;@@ -1730,6 +1863,8 @@ vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq,vmxnet3_getRxComp (rcd, &rq->comp_ring.base[rq->comp_ring.next2proc].rcd, &rxComp); } +if (need_flush) +xdp_do_flush ();What about %XDP_TX? On each %XDP_TX we usually only place the frame to a Tx ring and hit the doorbell to kick Tx only here, before
xdp_do_flush().
I think it's ok here. For XDP_TX, we place the frame to tx ring and wait until a threshold (%tq->shared->txThreshold), then hit the doorbell.
Quoted 45 lines
Quoted 28 lines
drivers/net/vmxnet3/vmxnet3_drv.c +9
-2return num_pkts; }@@ -1755,13 +1890,20 @@ vmxnet3_rq_cleanup(struct vmxnet3_rx_queue *rq, &rq->rx_ring[ring_idx].base[i].rxd, &rxDesc);if (rxd->btype ==VMXNET3_RXD_BTYPE_HEAD && - rq->buf_info[ring_idx][i].skb) { + rq->buf_info[ring_idx][i].pp_page && + rq->buf_info[ring_idx][i].buf_type == +VMXNET3_RX_BUF_XDP ) { +page_pool_recycle_direct (rq->page_pool, + rq->buf_info[ring_idx][i].pp_page); + rq->buf_info[ring_idx][i].pp_page =NULL ; + }else if (rxd->btype ==VMXNET3_RXD_BTYPE_HEAD && + rq->buf_info[ring_idx][i].skb) {dma_unmap_single (&adapter->pdev->dev, rxd->addr, rxd->len,DMA_FROM_DEVICE );dev_kfree_skb (rq->buf_info[ring_idx][i].skb); rq->buf_info[ring_idx][i].skb =NULL ; }else if (rxd->btype ==VMXNET3_RXD_BTYPE_BODY && - rq->buf_info[ring_idx][i].page) { + rq->buf_info[ring_idx][i].page) {dma_unmap_page (&adapter->pdev->dev, rxd->addr, rxd->len,DMA_FROM_DEVICE );put_page (rq->buf_info[ring_idx][i].page);drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_rq_cleanup_all(struct vmxnet3_adapter *adapter) · line 1791
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1
-1@@ -1786,9 +1928,9 @@ vmxnet3_rq_cleanup_all(struct vmxnet3_adapter *adapter)for (i =0 ; i < adapter->num_rx_queues; i++)vmxnet3_rq_cleanup (&adapter->rx_queue[i], adapter); +rcu_assign_pointer (adapter->xdp_bpf_prog,NULL ); } -(nit: also unrelated)
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_drv.c +0
-0static void vmxnet3_rq_destroy (struct vmxnet3_rx_queue *rq,struct vmxnet3_adapter *adapter) {@@ -1815,6 +1957,13 @@ static void vmxnet3_rq_destroy(struct vmxnet3_rx_queue *rq, } }
Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_drv.c static void vmxnet3_rq_destroy(struct vmxnet3_rx_queue *rq, · line 1960
Quoted 1 line
drivers/net/vmxnet3/vmxnet3_drv.c +1
-0+if (rq->page_pool) {Isn't it always true? You always create a Page Pool per each RQ IIUC?
good catch, will remove the check.
Quoted 70 lines
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +6
-0+if (xdp_rxq_info_is_reg (&rq->xdp_rxq)) +xdp_rxq_info_unreg (&rq->xdp_rxq); +page_pool_destroy (rq->page_pool); + rq->page_pool =NULL ; + } +if (rq->data_ring.base) { dma_free_coherent(&adapter->pdev->dev, rq->rx_ring[0].size * rq->data_ring.desc_size,[...]
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_setup_driver_shared(struct vmxnet3_adapter *adapter) · line 2745
Quoted 11 lines
drivers/net/vmxnet3/vmxnet3_drv.c +2
-2-static int +int vmxnet3_rq_create_all (struct vmxnet3_adapter *adapter) {int i, err =0 ;@@ -2585,7 +2742,7 @@ vmxnet3_setup_driver_shared(struct vmxnet3_adapter *adapter)if (adapter->netdev->features &NETIF_F_RXCSUM ) devRead->misc.uptFeatures |=UPT1_F_RXCSUM ; -if (adapter->netdev->features &NETIF_F_LRO ) { +if ((adapter->netdev->features &NETIF_F_LRO )) {Unneeded change (moreover, Clang sometimes triggers on such on W=1+)
Quoted 23 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-2devRead->misc.uptFeatures |=UPT1_F_LRO ; devRead->misc.maxNumRxSG =cpu_to_le16 (1 +MAX_SKB_FRAGS ); }@@ -3026,7 +3183,7 @@ vmxnet3_free_pci_resources(struct vmxnet3_adapter *adapter) } -static void +void vmxnet3_adjust_rx_ring_size (struct vmxnet3_adapter *adapter) {size_t sz, i, ring0_size, ring1_size, comp_size;@@ -3035,7 +3192,8 @@ vmxnet3_adjust_rx_ring_size(struct vmxnet3_adapter *adapter)if (adapter->netdev->mtu <=VMXNET3_MAX_SKB_BUF_SIZE -VMXNET3_MAX_ETH_HDR_SIZE ) { adapter->skb_buf_size = adapter->netdev->mtu + -VMXNET3_MAX_ETH_HDR_SIZE ; +VMXNET3_MAX_ETH_HDR_SIZE + +vmxnet3_xdp_headroom (adapter);if (adapter->skb_buf_size <VMXNET3_MIN_T0_BUF_SIZE ) adapter->skb_buf_size =VMXNET3_MIN_T0_BUF_SIZE ;drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_reset_work(struct work_struct *data) · line 3566
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_drv.c +0
-1@@ -3563,7 +3721,6 @@ vmxnet3_reset_work(struct work_struct *data)clear_bit (VMXNET3_STATE_BIT_RESETTING , &adapter->state); } -(unrelated)
Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_drv.c +0
-0static int vmxnet3_probe_device (struct pci_dev *pdev,const struct pci_device_id *id)[...]
drivers/net/vmxnet3/vmxnet3_int.h struct vmxnet3_tx_queue { · line 269
Quoted 6 lines
enum vmxnet3_rx_buf_type { VMXNET3_RX_BUF_NONE = 0, VMXNET3_RX_BUF_SKB = 1,drivers/net/vmxnet3/vmxnet3_int.h +2
-1-VMXNET3_RX_BUF_PAGE =2 +VMXNET3_RX_BUF_PAGE =2 , +VMXNET3_RX_BUF_XDP =3
Quoted 3 lines
I'd always leave a ',' after the last entry. As you can see, if you don't do that, you have to introduce 2 lines of changes instead of just 1 when you add a new entry.
thanks, that's good point. Will do it, thanks!
Quoted 11 lines
drivers/net/vmxnet3/vmxnet3_int.h struct vmxnet3_rx_buf_info { · line 282
Quoted 9 lines
};
#define
VMXNET3_RXD_COMP_PENDING0drivers/net/vmxnet3/vmxnet3_int.h +1
-0@@ -271,6 +279,7 @@ struct vmxnet3_rx_buf_info {union {struct sk_buff *skb;struct page *page; +struct page *pp_page;/* Page Pool for XDP frame */ Why not just use the already existing field if they're of the same type?
I guess in the beginning I want to avoid mixing the two cases/rings. I will use just %page as you suggest.
Quoted 7 lines
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_int.h +0
-0};dma_addr_t dma_addr; };[...]
Quoted 16 lines
drivers/net/vmxnet3/vmxnet3_xdp.c line 30
Quoted 12 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +12
-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; +bool need_update; +bool running; +int err =0 ; + +if (new_bpf_prog && netdev->mtu >VMXNET3_XDP_MAX_MTU ) {Mismatch: as I said before, %VMXNET3_XDP_MAX_MTU is not MTU, rather max frame len. At the same time,
netdev->mtuis real MTU, which doesn't include Eth, VLAN and FCS.
Thanks!
So I should include the hardware header length, define s.t like
#define VMXNET3_RX_OFFSET (XDP_PACKET_HEADROOM + NET_IP_ALIGN)
#define VMXNET3_XDP_MAX_MTU PAGE_SIZE - VMXNET3_RX_OFFSET -dev->hard_header_len
Quoted 10 lines
Quoted 2 lines
+
NL_SET_ERR_MSG_MOD(extack, "MTU too large for XDP");Any plans to add XDP multi-buffer support?
drivers/net/vmxnet3/vmxnet3_xdp.c line 35
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4
-0+return -EOPNOTSUPP ; + } + +if ((adapter->netdev->features &NETIF_F_LRO )) {
Quoted 5 lines
(redundant braces)
Quoted 1 line
+
netdev_err(adapter->netdev, "LRO is not supported with XDP");Why is this error printed via
netdev_err(), notNL_SET()?
I want to show the error message in dmesg, which I didn't see it printed when using NL_SET
is it better to use NL_SET?
Quoted 86 lines
Quoted 20 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +19
-0+ adapter->netdev->features &= ~NETIF_F_LRO ; + } + + old_bpf_prog =rcu_dereference (adapter->xdp_bpf_prog); +if (!new_bpf_prog && !old_bpf_prog) +return 0 ; + + running =netif_running (netdev); + need_update = !!old_bpf_prog != !!new_bpf_prog; + +if (running && need_update) +vmxnet3_quiesce_dev (adapter); + +vmxnet3_xdp_exchange_program (adapter, new_bpf_prog); +if (old_bpf_prog) +bpf_prog_put (old_bpf_prog); + +if (!running || !need_update) +return 0 ;drivers/net/vmxnet3/vmxnet3_xdp.c line 65
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+ +vmxnet3_reset_dev (adapter); +vmxnet3_rq_destroy_all (adapter); +vmxnet3_adjust_rx_ring_size (adapter); + err =vmxnet3_rq_create_all (adapter); +if (err) { +NL_SET_ERR_MSG_MOD (extack, +"failed to re-create rx queues for XDP." ); + err = -EOPNOTSUPP ; +return err;return -OPNOTSUPP? Why doing it in two steps?
drivers/net/vmxnet3/vmxnet3_xdp.c line 72
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +7
-0+ } + err =vmxnet3_activate_dev (adapter); +if (err) { +NL_SET_ERR_MSG_MOD (extack, +"failed to activate device for XDP." ); + err = -EOPNOTSUPP ; +return err;(same)
Review
Quoted 2 lines
(quoted diff) +2
-0+ } + clear_bit(VMXNET3_STATE_BIT_RESETTING, &adapter->state);(classic newline nit)
Quoted 1 line
+ return err;
@err will be 0 at this point, return it directly.
Quoted 15 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +15
-0+} + +/* This is the main xdp call used by kernel to set/unset eBPF program. */ +int +vmxnet3_xdp (struct net_device *netdev,struct netdev_bpf *bpf) +{ +switch (bpf->command) { +case XDP_SETUP_PROG : +return vmxnet3_xdp_set (netdev, bpf, bpf->extack); +default : +return -EINVAL ; + } +return 0 ; +} +drivers/net/vmxnet3/vmxnet3_xdp.c line 100
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+bool +vmxnet3_xdp_enabled (struct vmxnet3_adapter *adapter) +{ +return !!rcu_access_pointer (adapter->xdp_bpf_prog); +} + +int +vmxnet3_xdp_headroom (struct vmxnet3_adapter *adapter) +{ +return vmxnet3_xdp_enabled (adapter) ?VMXNET3_XDP_PAD :0 ;Uhm, the function is called '
_headroom', but in fact it returns skb overhead (headroom + tailroom).
Also, I don't feel like it's incorrect to return 0 as skb overhead, as you unconditionally set PP offset to %XDP_PACKET_HEADROOM, plus skb tailroom is alwaysSKB_DATA_ALIGN(sizeof(skb_shared_info))regardless of XDP prog presence. So I'd rather always return_XDP_PAD(or just embed this definition into the single call site).
Quoted 4 lines
Quoted 1 line
+}
Making these 2 functions global are overkill and doesn't affect performance positively. They can easily be static inlines.
right, I realize vmxnet3_xdp_headroom is used only at one place. I will embed into the code.
and I will make the vmxnet3_xdp_enable static inline thanks!
Quoted 45 lines
Quoted 15 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +14
-0+ +static int +vmxnet3_xdp_xmit_frame (struct vmxnet3_adapter *adapter, +struct xdp_frame *xdpf, +struct vmxnet3_tx_queue *tq,bool dma_map) +{ +struct vmxnet3_tx_buf_info *tbi =NULL ; +union Vmxnet3_GenericDesc *gdesc; +struct vmxnet3_tx_ctx ctx; +int tx_num_deferred; +struct page *page; +u32 buf_size; +int ret =0 ; +u32 dw2;[...]
drivers/net/vmxnet3/vmxnet3_xdp.c line 181
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+dma_wmb (); + gdesc->dword[2 ] =cpu_to_le32 (le32_to_cpu (gdesc->dword[2 ]) ^ +VMXNET3_TXD_GEN ); + +if (tx_num_deferred >=le32_to_cpu (tq->shared->txThreshold)) { + tq->shared->txNumDeferred =0 ; +VMXNET3_WRITE_BAR0_REG (adapter, +VMXNET3_REG_TXPROD + tq->qid *8 , + tq->tx_ring.next2fill); + }(NL))
Quoted 14 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +14
-0+return ret; +} + +static int +vmxnet3_xdp_xmit_back (struct vmxnet3_adapter *adapter, +struct xdp_frame *xdpf) +{ +struct vmxnet3_tx_queue *tq; +struct netdev_queue *nq; +int err =0 , cpu; +int tq_number; + + tq_number = adapter->num_tx_queues; + cpu =smp_processor_id ();
Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_xdp.c line 199
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4
-0+if (likely (cpu < tq_number)) + tq = &adapter->tx_queue[cpu]; +else + tq = &adapter->tx_queue[reciprocal_scale (cpu, tq_number)];Interesting solution, the first time I see such. Usually we do just
smp_processor_id() % num_tx_queues. I don't say yours is worse, just a sidenote :)
ha, yes, I learned from Alexander Duyck's feedback
Quoted 84 lines
Quoted 14 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +13
-0+if (tq->stopped) +return -ENETDOWN ; + + nq =netdev_get_tx_queue (adapter->netdev, tq->qid); + +__netif_tx_lock (nq, cpu); + err =vmxnet3_xdp_xmit_frame (adapter, xdpf, tq, false); +__netif_tx_unlock (nq); +return err; +} + +/* ndo_xdp_xmit */ +int drivers/net/vmxnet3/vmxnet3_xdp.c line 222
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+vmxnet3_xdp_xmit(struct net_device *dev, + int n, struct xdp_frame **frames, u32 flags) +{ + struct vmxnet3_adapter *adapter; +struct vmxnet3_tx_queue *tq; +struct netdev_queue *nq; +int i, err, cpu; +int tq_number; + + adapter =netdev_priv (dev);Nit: embed into the declaration?
Quoted 44 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +44
-0+ +if (unlikely (test_bit (VMXNET3_STATE_BIT_QUIESCED , &adapter->state))) +return -ENETDOWN ; +if (unlikely (test_bit (VMXNET3_STATE_BIT_RESETTING , &adapter->state))) +return -EINVAL ; + + tq_number = adapter->num_tx_queues; + cpu =smp_processor_id (); +if (likely (cpu < tq_number)) + tq = &adapter->tx_queue[cpu]; +else + tq = &adapter->tx_queue[reciprocal_scale (cpu, tq_number)]; +if (tq->stopped) +return -ENETDOWN ; + + nq =netdev_get_tx_queue (adapter->netdev, tq->qid); + +for (i =0 ; i < n; i++) { + err =vmxnet3_xdp_xmit_frame (adapter, frames[i], tq, true); +if (err) { + tq->stats.xdp_xmit_err++; +break ; + } + } + tq->stats.xdp_xmit += i; + +return i; +} + +static int +vmxnet3_run_xdp (struct vmxnet3_rx_queue *rq,struct xdp_buff *xdp) +{ +struct xdp_frame *xdpf; +struct bpf_prog *prog; +int err; +u32 act; + + prog =rcu_dereference (rq->adapter->xdp_bpf_prog); + act =bpf_prog_run_xdp (prog, xdp); + rq->stats.xdp_packets++; + +switch (act) { +case XDP_PASS : +return act;drivers/net/vmxnet3/vmxnet3_xdp.c line 276
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+case XDP_REDIRECT : + err =xdp_do_redirect (rq->adapter->netdev, xdp, prog); +if (!err) + rq->stats.xdp_redirects++; +else + rq->stats.xdp_drops++; +return act; +case XDP_TX : + xdpf =xdp_convert_buff_to_frame (xdp); +if (!xdpf ||vmxnet3_xdp_xmit_back (rq->adapter, xdpf)) {I think this also could be
unlikely()?
Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_xdp.c line 279
Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +3
-0+ rq->stats.xdp_drops++; +page_pool_recycle_direct (rq->page_pool, +virt_to_head_page (xdp->data_hard_start));Uff, I don't like this line break. Maybe grab the page into a local var at first and then pass it to the function?
OK!
Quoted 60 lines
Quoted 47 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +46
-0+ }else { + rq->stats.xdp_tx++; + } +return act; +default : +bpf_warn_invalid_xdp_action (rq->adapter->netdev, prog, act); + fallthrough; +case XDP_ABORTED : +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)); +return act; +} + +static struct sk_buff * +vmxnet3_build_skb (struct vmxnet3_rx_queue *rq,struct page *page, +const struct xdp_buff *xdp) +{ +struct sk_buff *skb; + + skb =build_skb (page_address (page),PAGE_SIZE ); +if (unlikely (!skb)) { +page_pool_recycle_direct (rq->page_pool, page); + rq->stats.rx_buf_alloc_failure++; +return NULL ; + } + +/* bpf prog might change len and data position. */ +skb_reserve (skb, xdp->data - xdp->data_hard_start); +skb_put (skb, xdp->data_end - xdp->data); +skb_mark_for_recycle (skb); + +return skb; +} + +/* Handle packets from DataRing. */ +int +vmxnet3_process_xdp_small(struct vmxnet3_adapter *adapter, + struct vmxnet3_rx_queue *rq,drivers/net/vmxnet3/vmxnet3_xdp.c line 335
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+ void *data, int len, + struct sk_buff **skb_xdp_pass) +{ + struct bpf_prog *xdp_prog; +struct xdp_buff xdp; +struct page *page; +int act; + + page =page_pool_alloc_pages (rq->page_pool,GFP_ATOMIC ); +if (!page) {(unlikely nit)
Quoted 15 lines
drivers/net/vmxnet3/vmxnet3_xdp.c line 346
Quoted 11 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +11
-0+ 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 , + len, false); +xdp_buff_clear_frags_flag (&xdp); + +/* Must copy the data because it's at dataring. */ +memcpy (xdp.data, data, len);Wanted to write "oh, too bad we have to copy the data" and only then noticed your explanation that dataring is used for frames < 128 bytes only :D
:D
Quoted 26 lines
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +3
-0+ +rcu_read_lock (); + xdp_prog =rcu_dereference (rq->adapter->xdp_bpf_prog);drivers/net/vmxnet3/vmxnet3_xdp.c line 359
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+if (!xdp_prog) { +rcu_read_unlock (); +page_pool_recycle_direct (rq->page_pool, page); + act =XDP_PASS ; + goto out_skb; + } + act =vmxnet3_run_xdp (rq, &xdp); +rcu_read_unlock (); + +out_skb:Nit: you can move this label one line below and skip always-true branch when !xdp_prog.
Quoted 5 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +5
-0+if (act ==XDP_PASS ) { + *skb_xdp_pass =vmxnet3_build_skb (rq, page, &xdp); +if (!skb_xdp_pass) +return XDP_DROP ; + }[...]
Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_xdp.h line 22
Quoted 5 lines
drivers/net/vmxnet3/vmxnet3_xdp.h new file +5
-0+#include "vmxnet3_int.h" + +#define VMXNET3_XDP_PAD (SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) + \ + XDP_PACKET_HEADROOM) +#define VMXNET3_XDP_MAX_MTU (PAGE_SIZE - VMXNET3_XDP_PAD)Uhm, couldn't say it's valid to name it as "MTU", it's rather max frame size. MTU doesn't include Ethernet, VLAN headers and FCS.
Got it, will rename it.
Working on next version now...
Thanks
William
From: William Tu <[email protected]>
Date: Sat, 21 Jan 2023 10:29:28 -0800
Quoted 5 lines
Quoted 3 lines · Alexander Lobakin
From: William Tu <[email protected]>
Date: Thu, 12 Jan 2023 06:07:43 -0800
[...]
Quoted 11 lines
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq, · line 1291
Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_drv.c +6
-0+static int +vmxnet3_create_pp (struct vmxnet3_adapter *adapter, +struct vmxnet3_rx_queue *rq,int size) +{ +const struct page_pool_params pp_params = { + .order =0 ,Nit: it will be zeroed implicitly, so can be omitted. OTOH if you want to explicitly say that you always use order-0 pages only, you can leave it here.
I will leave it here as it's more clear.
+
Quoted 12 lines
Quoted 12 lines
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq, · line 1296
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_drv.c +5
-0+ .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV, + .pool_size = size, + .nid = NUMA_NO_NODE, + .dev = &adapter->pdev->dev, + .offset = XDP_PACKET_HEADROOM,Curious, on which architectures does this driver work in the real world? Is it x86 only or maybe 64-bit systems only? Because not having %NET_IP_ALIGN here will significantly slow down Rx on the systems where it's defined as 2, not 0 (those systems can't stand unaligned access).
[...]
Quoted 10 lines
Quoted 9 lines
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq, · line 1867
Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_drv.c +2
-0@@ -1730,6 +1863,8 @@ vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq,vmxnet3_getRxComp (rcd, &rq->comp_ring.base[rq->comp_ring.next2proc].rcd, &rxComp); } +if (need_flush) +xdp_do_flush ();What about %XDP_TX? On each %XDP_TX we usually only place the frame to a Tx ring and hit the doorbell to kick Tx only here, before
xdp_do_flush().
Quoted 2 lines
I think it's ok here. For
XDP_TX, we place the frame to tx ring and wait until a threshold (%tq->shared->txThreshold), then hit the doorbell.
What if it didn't reach the threshold and the NAPI poll cycle is finished? It will stay on the ring without hitting the doorbell?
Quoted 165 lines
Quoted 46 lines
Quoted 29 lines
drivers/net/vmxnet3/vmxnet3_drv.c +9
-2return num_pkts; }@@ -1755,13 +1890,20 @@ vmxnet3_rq_cleanup(struct vmxnet3_rx_queue *rq, &rq->rx_ring[ring_idx].base[i].rxd, &rxDesc);if (rxd->btype ==VMXNET3_RXD_BTYPE_HEAD && - rq->buf_info[ring_idx][i].skb) { + rq->buf_info[ring_idx][i].pp_page && + rq->buf_info[ring_idx][i].buf_type == +VMXNET3_RX_BUF_XDP ) { +page_pool_recycle_direct (rq->page_pool, + rq->buf_info[ring_idx][i].pp_page); + rq->buf_info[ring_idx][i].pp_page =NULL ; + }else if (rxd->btype ==VMXNET3_RXD_BTYPE_HEAD && + rq->buf_info[ring_idx][i].skb) {dma_unmap_single (&adapter->pdev->dev, rxd->addr, rxd->len,DMA_FROM_DEVICE );dev_kfree_skb (rq->buf_info[ring_idx][i].skb); rq->buf_info[ring_idx][i].skb =NULL ; }else if (rxd->btype ==VMXNET3_RXD_BTYPE_BODY && - rq->buf_info[ring_idx][i].page) { + rq->buf_info[ring_idx][i].page) {dma_unmap_page (&adapter->pdev->dev, rxd->addr, rxd->len,DMA_FROM_DEVICE );put_page (rq->buf_info[ring_idx][i].page);drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_rq_cleanup_all(struct vmxnet3_adapter *adapter) · line 1791
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1
-1@@ -1786,9 +1928,9 @@ vmxnet3_rq_cleanup_all(struct vmxnet3_adapter *adapter)for (i =0 ; i < adapter->num_rx_queues; i++)vmxnet3_rq_cleanup (&adapter->rx_queue[i], adapter); +rcu_assign_pointer (adapter->xdp_bpf_prog,NULL ); } -(nit: also unrelated)
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_drv.c +0
-0static void vmxnet3_rq_destroy (struct vmxnet3_rx_queue *rq,struct vmxnet3_adapter *adapter) {@@ -1815,6 +1957,13 @@ static void vmxnet3_rq_destroy(struct vmxnet3_rx_queue *rq, } }Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_drv.c static void vmxnet3_rq_destroy(struct vmxnet3_rx_queue *rq, · line 1960
Quoted 1 line
drivers/net/vmxnet3/vmxnet3_drv.c +1
-0+if (rq->page_pool) {Isn't it always true? You always create a Page Pool per each RQ IIUC?
good catch, will remove the check.
Quoted 70 lines
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +6
-0+if (xdp_rxq_info_is_reg (&rq->xdp_rxq)) +xdp_rxq_info_unreg (&rq->xdp_rxq); +page_pool_destroy (rq->page_pool); + rq->page_pool =NULL ; + } +if (rq->data_ring.base) { dma_free_coherent(&adapter->pdev->dev, rq->rx_ring[0].size * rq->data_ring.desc_size,[...]
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_setup_driver_shared(struct vmxnet3_adapter *adapter) · line 2745
Quoted 11 lines
drivers/net/vmxnet3/vmxnet3_drv.c +2
-2-static int +int vmxnet3_rq_create_all (struct vmxnet3_adapter *adapter) {int i, err =0 ;@@ -2585,7 +2742,7 @@ vmxnet3_setup_driver_shared(struct vmxnet3_adapter *adapter)if (adapter->netdev->features &NETIF_F_RXCSUM ) devRead->misc.uptFeatures |=UPT1_F_RXCSUM ; -if (adapter->netdev->features &NETIF_F_LRO ) { +if ((adapter->netdev->features &NETIF_F_LRO )) {Unneeded change (moreover, Clang sometimes triggers on such on W=1+)
Quoted 23 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-2devRead->misc.uptFeatures |=UPT1_F_LRO ; devRead->misc.maxNumRxSG =cpu_to_le16 (1 +MAX_SKB_FRAGS ); }@@ -3026,7 +3183,7 @@ vmxnet3_free_pci_resources(struct vmxnet3_adapter *adapter) } -static void +void vmxnet3_adjust_rx_ring_size (struct vmxnet3_adapter *adapter) {size_t sz, i, ring0_size, ring1_size, comp_size;@@ -3035,7 +3192,8 @@ vmxnet3_adjust_rx_ring_size(struct vmxnet3_adapter *adapter)if (adapter->netdev->mtu <=VMXNET3_MAX_SKB_BUF_SIZE -VMXNET3_MAX_ETH_HDR_SIZE ) { adapter->skb_buf_size = adapter->netdev->mtu + -VMXNET3_MAX_ETH_HDR_SIZE ; +VMXNET3_MAX_ETH_HDR_SIZE + +vmxnet3_xdp_headroom (adapter);if (adapter->skb_buf_size <VMXNET3_MIN_T0_BUF_SIZE ) adapter->skb_buf_size =VMXNET3_MIN_T0_BUF_SIZE ;drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_reset_work(struct work_struct *data) · line 3566
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_drv.c +0
-1@@ -3563,7 +3721,6 @@ vmxnet3_reset_work(struct work_struct *data)clear_bit (VMXNET3_STATE_BIT_RESETTING , &adapter->state); } -(unrelated)
Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_drv.c +0
-0static int vmxnet3_probe_device (struct pci_dev *pdev,const struct pci_device_id *id)[...]
drivers/net/vmxnet3/vmxnet3_int.h struct vmxnet3_tx_queue { · line 269
Quoted 6 lines
enum vmxnet3_rx_buf_type { VMXNET3_RX_BUF_NONE = 0, VMXNET3_RX_BUF_SKB = 1,drivers/net/vmxnet3/vmxnet3_int.h +2
-1-VMXNET3_RX_BUF_PAGE =2 +VMXNET3_RX_BUF_PAGE =2 , +VMXNET3_RX_BUF_XDP =3 Quoted 3 lines
I'd always leave a ',' after the last entry. As you can see, if you don't do that, you have to introduce 2 lines of changes instead of just 1 when you add a new entry.
thanks, that's good point. Will do it, thanks!
Quoted 11 lines
drivers/net/vmxnet3/vmxnet3_int.h struct vmxnet3_rx_buf_info { · line 282
Quoted 9 lines
};
#define
VMXNET3_RXD_COMP_PENDING0drivers/net/vmxnet3/vmxnet3_int.h +1
-0@@ -271,6 +279,7 @@ struct vmxnet3_rx_buf_info {union {struct sk_buff *skb;struct page *page; +struct page *pp_page;/* Page Pool for XDP frame */ Why not just use the already existing field if they're of the same type?
I guess in the beginning I want to avoid mixing the two cases/rings. I will use just %page as you suggest.
Quoted 7 lines
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_int.h +0
-0};dma_addr_t dma_addr; };[...]
Quoted 16 lines
drivers/net/vmxnet3/vmxnet3_xdp.c line 30
Quoted 12 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +12
-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; +bool need_update; +bool running; +int err =0 ; + +if (new_bpf_prog && netdev->mtu >VMXNET3_XDP_MAX_MTU ) {Mismatch: as I said before, %VMXNET3_XDP_MAX_MTU is not MTU, rather max frame len. At the same time,
netdev->mtuis real MTU, which doesn't include Eth, VLAN and FCS.
Quoted 5 lines
Thanks!
So I should include the hardware header length, define s.t like
#defineVMXNET3_RX_OFFSET(XDP_PACKET_HEADROOM+NET_IP_ALIGN)
#defineVMXNET3_XDP_MAX_MTUPAGE_SIZE-VMXNET3_RX_OFFSET-dev->hard_header_len
Hmm, since your netdev is always Ethernet, you can hardcode %ETH_HLEN. OTOH don't forget to include 2 VLANs, FCS and tailroom:
#define VMXNET3_RX_OFFSET (XDP_PACKET_HEADROOM + NET_IP_ALIGN)
#define VMXNET3_RX_TAILROOOM SKB_DATA_ALIGN(sizeof(skb_shared_info))
#define VMXNET3_RX_MAX_FRAME (PAGE_SIZE - VMXNET3_RX_OFFSET - \
VMXNET3_RX_TAILROOM)
#define VMXNET3_RX_MAX_MTU (VMXNET3_RX_MAX_FRAME - ETH_HLEN - \
2 * VLAN_HLEN - ETH_FCS_LEN)
Then it will be your max MTU :)dev->hard_header_len is also ok, but it's always %ETH_HLEN for Ethernet devices.
Quoted 13 lines
Quoted 13 lines
Quoted 3 lines
+
NL_SET_ERR_MSG_MOD(extack, "MTU too large for XDP");Any plans to add XDP multi-buffer support?
drivers/net/vmxnet3/vmxnet3_xdp.c line 35
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4
-0+return -EOPNOTSUPP ; + } + +if ((adapter->netdev->features &NETIF_F_LRO )) {(redundant braces)
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+
netdev_err(adapter->netdev, "LRO is not supported with XDP");Why is this error printed via
netdev_err(), notNL_SET()?I want to show the error message in dmesg, which I didn't see it printed when using
NL_SET
is it better to useNL_SET?
When &netlink_ext_ack is available, it's better to use it instead. Alternatively, you can print to both Netlink *and* the kernel log. Printing to NL allows you to pass a message directly to userspace and then the program you use to configure devices will print it. Otherwise, the user will need to open up the kernel log.
Quoted 9 lines
Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_xdp.c line 42
Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +6
-0+ adapter->netdev->features &= ~NETIF_F_LRO ; + } + + old_bpf_prog =rcu_dereference (adapter->xdp_bpf_prog); +if (!new_bpf_prog && !old_bpf_prog) +return 0 ;
Quoted 3 lines
Working on next version now...
Thanks
William
Thanks,
Olek
Hi Alexander,
Thanks for your feedback.
Quoted 51 lines · Alexander Lobakin
From: William Tu <[email protected]>
Date: Sat, 21 Jan 2023 10:29:28 -0800Quoted 5 lines
Quoted 3 lines · Alexander Lobakin
From: William Tu <[email protected]>
Date: Thu, 12 Jan 2023 06:07:43 -0800[...]
Quoted 11 lines
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq, · line 1291
Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_drv.c +6
-0+static int +vmxnet3_create_pp (struct vmxnet3_adapter *adapter, +struct vmxnet3_rx_queue *rq,int size) +{ +const struct page_pool_params pp_params = { + .order =0 ,Nit: it will be zeroed implicitly, so can be omitted. OTOH if you want to explicitly say that you always use order-0 pages only, you can leave it here.
I will leave it here as it's more clear.
+
Quoted 12 lines
Quoted 12 lines
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq, · line 1296
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_drv.c +5
-0+ .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV, + .pool_size = size, + .nid = NUMA_NO_NODE, + .dev = &adapter->pdev->dev, + .offset = XDP_PACKET_HEADROOM,Curious, on which architectures does this driver work in the real world? Is it x86 only or maybe 64-bit systems only? Because not having %NET_IP_ALIGN here will significantly slow down Rx on the systems where it's defined as 2, not 0 (those systems can't stand unaligned access).
[...]
Quoted 10 lines
Quoted 9 lines
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq, · line 1867
Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_drv.c +2
-0@@ -1730,6 +1863,8 @@ vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq,vmxnet3_getRxComp (rcd, &rq->comp_ring.base[rq->comp_ring.next2proc].rcd, &rxComp); } +if (need_flush) +xdp_do_flush ();What about %XDP_TX? On each %XDP_TX we usually only place the frame to a Tx ring and hit the doorbell to kick Tx only here, before
xdp_do_flush().
Quoted 5 lines
Quoted 2 lines
I think it's ok here. For
XDP_TX, we place the frame to tx ring and wait until a threshold (%tq->shared->txThreshold), then hit the doorbell.What if it didn't reach the threshold and the NAPI poll cycle is finished? It will stay on the ring without hitting the doorbell?
Good catch... Actually we don't need to do anything here.
The backend driver at hypervisor side will poll packets from the tx queues, transmit these packets, and reset the %tq->shared->txThreshold to zero. I should add a comment in the source code.
Quoted 178 lines
Quoted 166 lines
Quoted 47 lines
Quoted 30 lines
drivers/net/vmxnet3/vmxnet3_drv.c +9
-2return num_pkts; }@@ -1755,13 +1890,20 @@ vmxnet3_rq_cleanup(struct vmxnet3_rx_queue *rq, &rq->rx_ring[ring_idx].base[i].rxd, &rxDesc);if (rxd->btype ==VMXNET3_RXD_BTYPE_HEAD && - rq->buf_info[ring_idx][i].skb) { + rq->buf_info[ring_idx][i].pp_page && + rq->buf_info[ring_idx][i].buf_type == +VMXNET3_RX_BUF_XDP ) { +page_pool_recycle_direct (rq->page_pool, + rq->buf_info[ring_idx][i].pp_page); + rq->buf_info[ring_idx][i].pp_page =NULL ; + }else if (rxd->btype ==VMXNET3_RXD_BTYPE_HEAD && + rq->buf_info[ring_idx][i].skb) {dma_unmap_single (&adapter->pdev->dev, rxd->addr, rxd->len,DMA_FROM_DEVICE );dev_kfree_skb (rq->buf_info[ring_idx][i].skb); rq->buf_info[ring_idx][i].skb =NULL ; }else if (rxd->btype ==VMXNET3_RXD_BTYPE_BODY && - rq->buf_info[ring_idx][i].page) { + rq->buf_info[ring_idx][i].page) {dma_unmap_page (&adapter->pdev->dev, rxd->addr, rxd->len,DMA_FROM_DEVICE );put_page (rq->buf_info[ring_idx][i].page);drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_rq_cleanup_all(struct vmxnet3_adapter *adapter) · line 1791
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1
-1@@ -1786,9 +1928,9 @@ vmxnet3_rq_cleanup_all(struct vmxnet3_adapter *adapter)for (i =0 ; i < adapter->num_rx_queues; i++)vmxnet3_rq_cleanup (&adapter->rx_queue[i], adapter); +rcu_assign_pointer (adapter->xdp_bpf_prog,NULL ); } -(nit: also unrelated)
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_drv.c +0
-0static void vmxnet3_rq_destroy (struct vmxnet3_rx_queue *rq,struct vmxnet3_adapter *adapter) {@@ -1815,6 +1957,13 @@ static void vmxnet3_rq_destroy(struct vmxnet3_rx_queue *rq, } }Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_drv.c static void vmxnet3_rq_destroy(struct vmxnet3_rx_queue *rq, · line 1960
Quoted 1 line
drivers/net/vmxnet3/vmxnet3_drv.c +1
-0+if (rq->page_pool) {Isn't it always true? You always create a Page Pool per each RQ IIUC?
good catch, will remove the check.
Quoted 70 lines
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +6
-0+if (xdp_rxq_info_is_reg (&rq->xdp_rxq)) +xdp_rxq_info_unreg (&rq->xdp_rxq); +page_pool_destroy (rq->page_pool); + rq->page_pool =NULL ; + } +if (rq->data_ring.base) { dma_free_coherent(&adapter->pdev->dev, rq->rx_ring[0].size * rq->data_ring.desc_size,[...]
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_setup_driver_shared(struct vmxnet3_adapter *adapter) · line 2745
Quoted 11 lines
drivers/net/vmxnet3/vmxnet3_drv.c +2
-2-static int +int vmxnet3_rq_create_all (struct vmxnet3_adapter *adapter) {int i, err =0 ;@@ -2585,7 +2742,7 @@ vmxnet3_setup_driver_shared(struct vmxnet3_adapter *adapter)if (adapter->netdev->features &NETIF_F_RXCSUM ) devRead->misc.uptFeatures |=UPT1_F_RXCSUM ; -if (adapter->netdev->features &NETIF_F_LRO ) { +if ((adapter->netdev->features &NETIF_F_LRO )) {Unneeded change (moreover, Clang sometimes triggers on such on W=1+)
Quoted 23 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-2devRead->misc.uptFeatures |=UPT1_F_LRO ; devRead->misc.maxNumRxSG =cpu_to_le16 (1 +MAX_SKB_FRAGS ); }@@ -3026,7 +3183,7 @@ vmxnet3_free_pci_resources(struct vmxnet3_adapter *adapter) } -static void +void vmxnet3_adjust_rx_ring_size (struct vmxnet3_adapter *adapter) {size_t sz, i, ring0_size, ring1_size, comp_size;@@ -3035,7 +3192,8 @@ vmxnet3_adjust_rx_ring_size(struct vmxnet3_adapter *adapter)if (adapter->netdev->mtu <=VMXNET3_MAX_SKB_BUF_SIZE -VMXNET3_MAX_ETH_HDR_SIZE ) { adapter->skb_buf_size = adapter->netdev->mtu + -VMXNET3_MAX_ETH_HDR_SIZE ; +VMXNET3_MAX_ETH_HDR_SIZE + +vmxnet3_xdp_headroom (adapter);if (adapter->skb_buf_size <VMXNET3_MIN_T0_BUF_SIZE ) adapter->skb_buf_size =VMXNET3_MIN_T0_BUF_SIZE ;drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_reset_work(struct work_struct *data) · line 3566
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_drv.c +0
-1@@ -3563,7 +3721,6 @@ vmxnet3_reset_work(struct work_struct *data)clear_bit (VMXNET3_STATE_BIT_RESETTING , &adapter->state); } -(unrelated)
Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_drv.c +0
-0static int vmxnet3_probe_device (struct pci_dev *pdev,const struct pci_device_id *id)[...]
drivers/net/vmxnet3/vmxnet3_int.h struct vmxnet3_tx_queue { · line 269
Quoted 6 lines
enum vmxnet3_rx_buf_type { VMXNET3_RX_BUF_NONE = 0, VMXNET3_RX_BUF_SKB = 1,drivers/net/vmxnet3/vmxnet3_int.h +2
-1-VMXNET3_RX_BUF_PAGE =2 +VMXNET3_RX_BUF_PAGE =2 , +VMXNET3_RX_BUF_XDP =3 Quoted 3 lines
I'd always leave a ',' after the last entry. As you can see, if you don't do that, you have to introduce 2 lines of changes instead of just 1 when you add a new entry.
thanks, that's good point. Will do it, thanks!
Quoted 11 lines
drivers/net/vmxnet3/vmxnet3_int.h struct vmxnet3_rx_buf_info { · line 282
Quoted 9 lines
};
#define
VMXNET3_RXD_COMP_PENDING0drivers/net/vmxnet3/vmxnet3_int.h +1
-0@@ -271,6 +279,7 @@ struct vmxnet3_rx_buf_info {union {struct sk_buff *skb;struct page *page; +struct page *pp_page;/* Page Pool for XDP frame */ Why not just use the already existing field if they're of the same type?
I guess in the beginning I want to avoid mixing the two cases/rings. I will use just %page as you suggest.
Quoted 7 lines
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_int.h +0
-0};dma_addr_t dma_addr; };[...]
Quoted 16 lines
drivers/net/vmxnet3/vmxnet3_xdp.c line 30
Quoted 12 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +12
-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; +bool need_update; +bool running; +int err =0 ; + +if (new_bpf_prog && netdev->mtu >VMXNET3_XDP_MAX_MTU ) {Mismatch: as I said before, %VMXNET3_XDP_MAX_MTU is not MTU, rather max frame len. At the same time,
netdev->mtuis real MTU, which doesn't include Eth, VLAN and FCS.Quoted 5 lines
Thanks!
So I should include the hardware header length, define s.t like
#defineVMXNET3_RX_OFFSET(XDP_PACKET_HEADROOM+NET_IP_ALIGN)
#defineVMXNET3_XDP_MAX_MTUPAGE_SIZE-VMXNET3_RX_OFFSET-dev->hard_header_lenHmm, since your netdev is always Ethernet, you can hardcode %ETH_HLEN. OTOH don't forget to include 2 VLANs, FCS and tailroom:
#define VMXNET3_RX_OFFSET (XDP_PACKET_HEADROOM + NET_IP_ALIGN) #define VMXNET3_RX_TAILROOOM SKB_DATA_ALIGN(sizeof(skb_shared_info)) #define VMXNET3_RX_MAX_FRAME (PAGE_SIZE - VMXNET3_RX_OFFSET - \
Quoted 7 lines
VMXNET3_RX_TAILROOM)
#defineVMXNET3_RX_MAX_MTU(VMXNET3_RX_MAX_FRAME-ETH_HLEN- \
2 *VLAN_HLEN-ETH_FCS_LEN)Then it will be your max MTU :)
dev->hard_header_lenis also ok, but it's always %ETH_HLEN for Ethernet devices.
Thanks a lot :)
Quoted 22 lines
Quoted 14 lines
Quoted 14 lines
Quoted 4 lines
+
NL_SET_ERR_MSG_MOD(extack, "MTU too large for XDP");Any plans to add XDP multi-buffer support?
drivers/net/vmxnet3/vmxnet3_xdp.c line 35
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4
-0+return -EOPNOTSUPP ; + } + +if ((adapter->netdev->features &NETIF_F_LRO )) {(redundant braces)
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+
netdev_err(adapter->netdev, "LRO is not supported with XDP");Why is this error printed via
netdev_err(), notNL_SET()?I want to show the error message in dmesg, which I didn't see it printed when using
NL_SET
is it better to useNL_SET?
Quoted 5 lines
When
&netlink_ext_ackis available, it's better to use it instead. Alternatively, you can print to both Netlink *and* the kernel log. Printing to NL allows you to pass a message directly to userspace and then the program you use to configure devices will print it. Otherwise, the user will need to open up the kernel log.
Got it, thanks for explaining it.
Thanks
William