vmxnet3: Add XDP support.
Subsystems (3)
RFC PATCH v16 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
Demo: https://youtu.be/4lm1CSCi78Q
Future work:
- XDP frag support
- use napi_consume_skb() instead of dev_kfree_skb_any at unmap
- stats using u64_stats_t
- using bitfield macro BIT()
---
v15 -> v16:
feedbacks from Maciej Fijalkowski
- fix unneeded code churn
- destory pp resource at vmxnet3_rq_init error path
- handle when LRO is set again when XDP is enabled in vmxnet3_fix_features
- add a helper, vmxnet3_xdp_get_tq
- remove using rcu_read_lock,unlock around XDP invocation
https://lore.kernel.org/bpf/[email protected]/
- fix a mistake in recycle page when !xdp_prog
- pass the xdp_prog to vmxnet3_run_xdp to avoid another deref
feedbacks from Alexander Lobakin
- use virt_to_page instead of virt_to_head_page (due to always 0-order)
- shrink indent level (two places)
ps. on the second thought I decide not to do it as it is easier for vmware internal review of xdp specific code all inside the 'if' statement block.
https://github.com/williamtu/net-next/compare/v15..v16
v14 -> v15:
feedbacks from Alexander Lobakin
- add rcu_read_lock unlock around xdp_frame_bulk_init
- define correct VMXNET3_XDP_MAX_MTU
- add comment explaining tx deferred and threshold in backend driver
- minor code refactoring and style fixes
- fix one bug in process_xdp when !xdp_prog
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
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
v5 -> v6:
work on feedbacks from Alexander Duyck
- remove unused skb parameter at vmxnet3_xdp_xmit
- add trace point for XDP_ABORTED
- avoid TX packet buffer being overwritten by allocatin new skb and memcpy (TX performance drop from 2.3 to 1.8Mpps)
- update some of the performance number and a demo video
https://youtu.be/I3nx5wQDTXw
- pass VMware internal regression test using non-ENS: vmxnet3v2, vmxnet3v3, vmxnet3v4, so remove RFC tag.
v4 -> v5:
- move XDP code to separate file: vmxnet3_xdp.{c, h}, suggested by Guolin
- expose vmxnet3_rq_create_all and vmxnet3_adjust_rx_ring_size
- more test using samples/bpf/{xdp1, xdp2, xdp_adjust_tail}
- add debug print
- rebase on commit 65e6af6cebe
v3 -> v4:
- code refactoring and improved commit message
- make dataring and non-dataring case clear
- in XDP_PASS, handle xdp.data and xdp.data_end change after bpf program executed
- now still working on internal testing
- v4 applied on net-next commit 65e6af6cebef
v2 -> v3:
- code refactoring: move the XDP processing to the front of the vmxnet3_rq_rx_complete, and minimize the places of changes to existing code.
- Performance improvement over BUF_SKB (512B) due to skipping skb allocation when DROP and TX.
v1 -> v2:
- Avoid skb allocation for small packet size (when dataring is used)
- Use rcu_read_lock unlock instead of READ_ONCE
- Peroformance improvement over v1
- Merge xdp drop, tx, pass, and redirect into 1 patch
--- drivers/net/Kconfig | 1 + drivers/net/vmxnet3/Makefile | 2 +- drivers/net/vmxnet3/vmxnet3_drv.c | 224 ++++++++++++-- drivers/net/vmxnet3/vmxnet3_ethtool.c | 23 ++ drivers/net/vmxnet3/vmxnet3_int.h | 43 ++- drivers/net/vmxnet3/vmxnet3_xdp.c | 416 ++++++++++++++++++++++++++ drivers/net/vmxnet3/vmxnet3_xdp.h | 49 +++ 7 files changed, 720 insertions(+), 38 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 +197 -27
405 lines not on this page · raw message
drivers/net/vmxnet3/vmxnet3_ethtool.c +23 -0
@@ -28,6 +28,7 @@#include "vmxnet3_int.h" #include <net/vxlan.h> #include <net/geneve.h> +#include "vmxnet3_xdp.h" #define VXLAN_UDP_PORT 8472
@@ -76,6 +77,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 +111,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 */
@@ -249,10 +264,18 @@ vmxnet3_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)netdev_features_t vmxnet3_fix_features (struct net_device *netdev,netdev_features_t features) { +struct vmxnet3_adapter *adapter =netdev_priv (netdev); +/* If Rx checksum is disabled, then LRO should also be disabled */ if (!(features &NETIF_F_RXCSUM )) features &= ~NETIF_F_LRO ; +/* If XDP is enabled, then LRO should not be enabled */ +if (vmxnet3_xdp_enabled (adapter) && (features &NETIF_F_LRO )) { +netdev_err (netdev,"LRO is not supported with XDP" ); + features &= ~NETIF_F_LRO ; + } +return features; }
drivers/net/vmxnet3/vmxnet3_int.h +33 -10
101 lines not on this page · raw message
drivers/net/vmxnet3/vmxnet3_xdp.c new file +416 -0
416 lines not on this page · raw message
drivers/net/vmxnet3/vmxnet3_xdp.h new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
2.37.1 (Apple Git-137.1)
From: William Tu <[email protected]>
Date: Sun, 5 Feb 2023 07:59:04 -0800
Quoted 4 lines
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.
[...]
Quoted 4 lines
Signed-off-by William Tu <[email protected]>Tested-by Yifeng Sun <[email protected]>Reviewed-by Alexander Duyck <[email protected]>Reviewed-by Alexander Lobakin <[email protected]>
Hmmm, did I give it? Can't remember :D
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_drv.c +2
-1@@ -326,14 +327,16 @@ static void vmxnet3_unmap_tx_buf(struct vmxnet3_tx_buf_info *tbi, struct pci_dev *pdev) { -if (tbi->map_type ==VMXNET3_MAP_SINGLE ) + u32 map_type = tbi->map_type; +
drivers/net/vmxnet3/vmxnet3_drv.c static void · line 339
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-2+if (map_type &VMXNET3_MAP_SINGLE )dma_unmap_single (&pdev->dev, tbi->dma_addr, tbi->len,DMA_TO_DEVICE ); - else if (tbi->map_type == VMXNET3_MAP_PAGE) +else if (map_type &VMXNET3_MAP_PAGE )dma_unmap_page (&pdev->dev, tbi->dma_addr, tbi->len,DMA_TO_DEVICE );else - BUG_ON(tbi->map_type != VMXNET3_MAP_NONE); +BUG_ON ((map_type & ~VMXNET3_MAP_XDP ));
Excesssive braces around the condition :s
Quoted 16 lines
drivers/net/vmxnet3/vmxnet3_drv.c +4
-2tbi->map_type =VMXNET3_MAP_NONE ;/* to help debugging */ }@@ -341,19 +344,20 @@ vmxnet3_unmap_tx_buf(struct vmxnet3_tx_buf_info *tbi,static int vmxnet3_unmap_pkt (u32 eop_idx,struct vmxnet3_tx_queue *tq, -struct pci_dev *pdev,struct vmxnet3_adapter *adapter) +struct pci_dev *pdev,struct vmxnet3_adapter *adapter, +struct xdp_frame_bulk *bq) { -struct sk_buff *skb; +struct vmxnet3_tx_buf_info *tbi;int entries =0 ; +u32 map_type;
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_unmap_tx_buf(struct vmxnet3_tx_buf_info *tbi, · line 359
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +2
-4/* no out of order completion */ BUG_ON (tq->buf_info[eop_idx].sop_idx != tq->tx_ring.next2comp);BUG_ON (VMXNET3_TXDESC_GET_EOP (&(tq->tx_ring.base[eop_idx].txd)) !=1 ); - 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 );
Prefer !ptr over ptr == NULL.
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1
-0+ map_type = tbi->map_type;VMXNET3_INC_RING_IDX_ONLY (eop_idx, tq->tx_ring.size);while (tq->tx_ring.next2comp != eop_idx) {
[...]
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-0@@ -1253,6 +1290,62 @@ 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)
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq, · line 1305
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +10
-0+{ +const struct page_pool_params pp_params = { + .order =0 , + .flags =PP_FLAG_DMA_MAP |PP_FLAG_DMA_SYNC_DEV , + .pool_size = size, + .nid =NUMA_NO_NODE , + .dev = &adapter->pdev->dev, + .offset =VMXNET3_XDP_RX_OFFSET , + .max_len =VMXNET3_XDP_MAX_FRSIZE , + .dma_dir =DMA_BIDIRECTIONAL ,
Don't you want to set the direction depending on whether you have XDP enabled? Bidir sync is slower than 1-dir on certain architectures without DMA coherence engines, as you need to not only drop the page from the cache, but also do a writeback.
Quoted 28 lines
drivers/net/vmxnet3/vmxnet3_drv.c +28
-0+ }; +struct page_pool *pp; +int err; + + pp =page_pool_create (&pp_params); +if (IS_ERR (pp)) +return PTR_ERR (pp); + + 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; + +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_rq_rx_complete(struct vmxnet3_rx_queue *rq, · line 1561
Quoted 11 lines
drivers/net/vmxnet3/vmxnet3_drv.c +11
-0+if (rbi->buf_type !=VMXNET3_RX_BUF_XDP ) + goto rcd_done; + + act =vmxnet3_process_xdp (adapter, rq, rcd, rbi, rxd, + &skb_xdp_pass); +if (act ==XDP_PASS ) { + ctx->skb = skb_xdp_pass; + goto sop_done; + } + ctx->skb =NULL ; + need_flush |= (act ==XDP_REDIRECT );
Also excessive braces :D
Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_drv.c +5
-0+ + goto rcd_done; + } +skip_xdp: +if (rcd->sop) {/* first buf of the pkt */ bool rxDataRingUsed;u16 len;
[...]
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +6
-0@@ -1470,6 +1591,25 @@ vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq, rxDataRingUsed =VMXNET3_RX_DATA_RING (adapter, rcd->rqID); len = rxDataRingUsed ? rcd->len : rbi->len; + +if (rxDataRingUsed &&vmxnet3_xdp_enabled (adapter)) { +struct sk_buff *skb_xdp_pass; +size_t sz; +int act; +
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq, · line 1609
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +10
-0+ sz = rcd->rxdIdx * rq->data_ring.desc_size; + act =vmxnet3_process_xdp_small (adapter, rq, + &rq->data_ring.base[sz], + rcd->len, + &skb_xdp_pass); +if (act ==XDP_PASS ) { + ctx->skb = skb_xdp_pass; + goto sop_done; + } + need_flush |= (act ==XDP_REDIRECT );
(same)
Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-0+ + goto rcd_done; + } new_skb =netdev_alloc_skb_ip_align (adapter->netdev, len);if (new_skb ==NULL ) {
[...]
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_rq_cleanup(struct vmxnet3_rx_queue *rq, · line 1905
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +5
-1@@ -1755,13 +1898,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].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].page);
Too long line. Maybe add a struct page * variable in this block to avoid this?
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_rq_cleanup(struct vmxnet3_rx_queue *rq, · line 1917
Quoted 13 lines
drivers/net/vmxnet3/vmxnet3_drv.c +4
-1+ rq->buf_info[ring_idx][i].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);
[...]
You also need to resubmit the series to add XDP features advertisement, which Lorenzo introduced recently.
Other that those, looks fine to me, my Rev-by can stay I guess :D
Thanks,
Olek
Hi Alexander,
Thanks for taking another look!
Quoted 9 lines · Alexander Lobakin
From: William Tu <[email protected]>
Date: Sun, 5 Feb 2023 07:59:04 -0800Quoted 4 lines
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.
Quoted 8 lines
[...]
Quoted 4 lines
Signed-off-by William Tu <[email protected]>Tested-by Yifeng Sun <[email protected]>Reviewed-by Alexander Duyck <[email protected]>Reviewed-by Alexander Lobakin <[email protected]>Hmmm, did I give it? Can't remember :D
Yes :)
https://lore.kernel.org/netdev/[email protected]/
Quoted 12 lines
Quoted 12 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-2@@ -326,14 +327,16 @@ static void vmxnet3_unmap_tx_buf(struct vmxnet3_tx_buf_info *tbi, struct pci_dev *pdev) { -if (tbi->map_type ==VMXNET3_MAP_SINGLE ) + u32 map_type = tbi->map_type; + +if (map_type &VMXNET3_MAP_SINGLE )dma_unmap_single (&pdev->dev, tbi->dma_addr, tbi->len,DMA_TO_DEVICE ); -else if (tbi->map_type ==VMXNET3_MAP_PAGE )
Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_drv.c static void · line 339
Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_drv.c +2
-1+else if (map_type &VMXNET3_MAP_PAGE )dma_unmap_page (&pdev->dev, tbi->dma_addr, tbi->len,DMA_TO_DEVICE );else - BUG_ON(tbi->map_type != VMXNET3_MAP_NONE); +BUG_ON ((map_type & ~VMXNET3_MAP_XDP ));Excesssive braces around the condition :s
Will fix it, thanks!
Quoted 21 lines
Quoted 21 lines
drivers/net/vmxnet3/vmxnet3_drv.c +4
-2tbi->map_type =VMXNET3_MAP_NONE ;/* to help debugging */ }@@ -341,19 +344,20 @@ vmxnet3_unmap_tx_buf(struct vmxnet3_tx_buf_info *tbi,static int vmxnet3_unmap_pkt (u32 eop_idx,struct vmxnet3_tx_queue *tq, -struct pci_dev *pdev,struct vmxnet3_adapter *adapter) +struct pci_dev *pdev,struct vmxnet3_adapter *adapter, +struct xdp_frame_bulk *bq) { -struct sk_buff *skb; +struct vmxnet3_tx_buf_info *tbi;int entries =0 ; +u32 map_type;/* no out of order completion */ BUG_ON (tq->buf_info[eop_idx].sop_idx != tq->tx_ring.next2comp);BUG_ON (VMXNET3_TXDESC_GET_EOP (&(tq->tx_ring.base[eop_idx].txd)) !=1 );
Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_unmap_tx_buf(struct vmxnet3_tx_buf_info *tbi, · line 359
Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_drv.c +2
-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 );Prefer
!ptroverptr == NULL.
Thanks, will do it.
Quoted 22 lines
Quoted 5 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1
-0+ map_type = tbi->map_type;VMXNET3_INC_RING_IDX_ONLY (eop_idx, tq->tx_ring.size);while (tq->tx_ring.next2comp != eop_idx) {[...]
Quoted 14 lines
drivers/net/vmxnet3/vmxnet3_drv.c +10
-0@@ -1253,6 +1290,62 @@ 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 , + .flags =PP_FLAG_DMA_MAP |PP_FLAG_DMA_SYNC_DEV , + .pool_size = size, + .nid =NUMA_NO_NODE , + .dev = &adapter->pdev->dev,
Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_tq_xmit(struct sk_buff *skb, struct vmxnet3_tx_queue *tq, · line 1305
Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-0+ .offset = VMXNET3_XDP_RX_OFFSET, + .max_len = VMXNET3_XDP_MAX_FRSIZE, + .dma_dir = DMA_BIDIRECTIONAL,Don't you want to set the direction depending on whether you have XDP enabled? Bidir sync is slower than 1-dir on certain architectures without DMA coherence engines, as you need to not only drop the page from the cache, but also do a writeback.
thanks for the suggestion, I didn't know that.
I will do s.t like
pp_params.dma_dir = xdp_prog ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE;
Quoted 44 lines
Quoted 29 lines
drivers/net/vmxnet3/vmxnet3_drv.c +28
-0+ }; +struct page_pool *pp; +int err; + + pp =page_pool_create (&pp_params); +if (IS_ERR (pp)) +return PTR_ERR (pp); + + 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; + +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_rq_rx_complete(struct vmxnet3_rx_queue *rq, · line 1561
Quoted 11 lines
drivers/net/vmxnet3/vmxnet3_drv.c +11
-0+if (rbi->buf_type !=VMXNET3_RX_BUF_XDP ) + goto rcd_done; + + act =vmxnet3_process_xdp (adapter, rq, rcd, rbi, rxd, + &skb_xdp_pass); +if (act ==XDP_PASS ) { + ctx->skb = skb_xdp_pass; + goto sop_done; + } + ctx->skb =NULL ; + need_flush |= (act ==XDP_REDIRECT );
Quoted 1 line
Also excessive braces :D
ha, you're right, I feel that it looks better :)
I will fix it.
Quoted 26 lines
Quoted 9 lines
drivers/net/vmxnet3/vmxnet3_drv.c +5
-0+ + goto rcd_done; + } +skip_xdp: +if (rcd->sop) {/* first buf of the pkt */ bool rxDataRingUsed;u16 len;[...]
Quoted 14 lines
drivers/net/vmxnet3/vmxnet3_drv.c +10
-0@@ -1470,6 +1591,25 @@ vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq, rxDataRingUsed =VMXNET3_RX_DATA_RING (adapter, rcd->rqID); len = rxDataRingUsed ? rcd->len : rbi->len; + +if (rxDataRingUsed &&vmxnet3_xdp_enabled (adapter)) { +struct sk_buff *skb_xdp_pass; +size_t sz; +int act; + + sz = rcd->rxdIdx * rq->data_ring.desc_size; + act = vmxnet3_process_xdp_small(adapter, rq, + &rq->data_ring.base[sz], + rcd->len,
Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_rq_rx_complete(struct vmxnet3_rx_queue *rq, · line 1561
Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_drv.c +6
-0+ &skb_xdp_pass); +if (act ==XDP_PASS ) { + ctx->skb = skb_xdp_pass; + goto sop_done; + } + need_flush |= (act ==XDP_REDIRECT );(same)
Thanks!
Quoted 13 lines
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-0+ + goto rcd_done; + } new_skb =netdev_alloc_skb_ip_align (adapter->netdev, len);if (new_skb ==NULL ) {[...]
Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_drv.c +0
-0@@ -1755,13 +1898,20 @@ vmxnet3_rq_cleanup(struct vmxnet3_rx_queue *rq, &rq->rx_ring[ring_idx].base[i].rxd, &rxDesc);
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_rq_cleanup(struct vmxnet3_rx_queue *rq, · line 1905
Quoted 7 lines
drivers/net/vmxnet3/vmxnet3_drv.c +5
-1if (rxd->btype ==VMXNET3_RXD_BTYPE_HEAD && - rq->buf_info[ring_idx][i].skb) { + rq->buf_info[ring_idx][i].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].page);Too long line. Maybe add a
struct page *variable in this block to avoid this?
Good idea, will do.
Quoted 14 lines
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_drv.c +3
-0+ rq->buf_info[ring_idx][i].page =NULL ; + }else if (rxd->btype ==VMXNET3_RXD_BTYPE_HEAD && + rq->buf_info[ring_idx][i].skb) {drivers/net/vmxnet3/vmxnet3_drv.c vmxnet3_rq_cleanup(struct vmxnet3_rx_queue *rq, · line 1917
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_drv.c +1
-1dma_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);
Quoted 4 lines
[...]
You also need to resubmit the series to add XDP features advertisement, which Lorenzo introduced recently.
Thanks! I didn't know that. Will do it.
Quoted 1 line
Other that those, looks fine to me, my Rev-by can stay I guess :D
Regards,
William