vmxnet3: Add XDP support.
Subsystems (3)
RFC PATCH v5 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
C. > 3K: use ring0 and ring1As 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 the XDP frame's headroom is zero.
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 new vmxnet3_run_xdp function handles the difference of using dataring or ring0, 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 using dma mapped for the transmission.
Performance:
Tested using two VMs inside one ESXi machine, using single core on each vmxnet3 device, sender using DPDK testpmd tx-mode attached to vmxnet3 device, sending 64B or 512B packet.
VM1 txgen:
$ dpdk-testpmd -l 0-3 -n 1 -- -i --nb-cores=3 \ --forward-mode=txonly --eth-peer=0,<mac addr of vm2> option: add "--txonly-multi-flow" option: use --txpkts=512 or 64 byte
VM2 running XDP:
$ ./samples/bpf/xdp_rxq_info -d ens160 -a <options> --skb-mode $ ./samples/bpf/xdp_rxq_info -d ens160 -a <options> options: XDP_DROP, XDP_PASS, XDP_TX
To test REDIRECT to cpu 0, use
$ ./samples/bpf/xdp_redirect_cpu -d ens160 -c 0 -e drop
Single core performance comparison with skb-mode.
64B: skb-mode -> native-mode (with this patch)
XDP_DROP: 960Kpps -> 2.4Mpps XDP_PASS: 240Kpps -> 499Kpps XDP_TX: 683Kpps -> 2.3Mpps REDIRECT: 389Kpps -> 449Kpps
Same performance compared to v2.
512B: skb-mode -> native-mode (with this patch)
v2 v3
XDP_DROP: 640Kpps -> 914Kpps -> 1.3Mpps XDP_PASS: 220Kpps -> 240Kpps -> 280Kpps XDP_TX: 483Kpps -> 886Kpps -> 1.3Mpps REDIRECT: 365Kpps -> 1.2Mpps(?) -> 261Kpps
Good performance improvement over v2, due to skip
skb allocation.
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))
---
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
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/vmxnet3/Makefile | 2 +- drivers/net/vmxnet3/vmxnet3_drv.c | 48 ++- drivers/net/vmxnet3/vmxnet3_ethtool.c | 14 + drivers/net/vmxnet3/vmxnet3_int.h | 20 ++ drivers/net/vmxnet3/vmxnet3_xdp.c | 454 ++++++++++++++++++++++++++ drivers/net/vmxnet3/vmxnet3_xdp.h | 39 +++ 6 files changed, 569 insertions(+), 8 deletions(-) create mode 100644 drivers/net/vmxnet3/vmxnet3_xdp.c create mode 100644 drivers/net/vmxnet3/vmxnet3_xdp.h
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 +41 -7
156 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 +20 -0
@@ -56,6 +56,8 @@#include <linux/if_arp.h> #include <linux/inetdevice.h> #include <linux/log2.h> +#include <linux/bpf.h> +#include <linux/skbuff.h> #include "vmxnet3_defs.h"
@@ -217,6 +219,9 @@ struct vmxnet3_tq_driver_stats {u64 linearized;/* # of pkts linearized */ u64 copy_skb_header;/* # of times we have to copy skb header */ u64 oversized_hdr; + +u64 xdp_xmit; +u64 xdp_xmit_err; };struct vmxnet3_tx_ctx {
@@ -285,6 +290,12 @@ struct vmxnet3_rq_driver_stats {u64 drop_err;u64 drop_fcs;u64 rx_buf_alloc_failure; + +u64 xdp_packets;/* Total packets processed by XDP. */ +u64 xdp_tx; +u64 xdp_redirects; +u64 xdp_drops; +u64 xdp_aborted; };struct vmxnet3_rx_data_ring {
@@ -307,6 +318,8 @@ struct vmxnet3_rx_queue {struct vmxnet3_rx_buf_info *buf_info[2 ];struct Vmxnet3_RxQueueCtrl *shared;struct vmxnet3_rq_driver_stats stats; +struct bpf_prog __rcu *xdp_bpf_prog; +struct xdp_rxq_info xdp_rxq; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define VMXNET3_DEVICE_MAX_TX_QUEUES 32
@@ -415,6 +428,7 @@ struct vmxnet3_adapter {u16 tx_prod_offset;u16 rx_prod_offset;u16 rx_prod2_offset; +bool xdp_enabled; };#define VMXNET3_WRITE_BAR0_REG (adapter, reg, val) \
@@ -490,6 +504,12 @@ vmxnet3_tq_destroy_all(struct vmxnet3_adapter *adapter);void vmxnet3_rq_destroy_all (struct vmxnet3_adapter *adapter); +int +vmxnet3_rq_create_all (struct vmxnet3_adapter *adapter); + +void +vmxnet3_adjust_rx_ring_size (struct vmxnet3_adapter *adapter); +netdev_features_t vmxnet3_fix_features (struct net_device *netdev,netdev_features_t features);
drivers/net/vmxnet3/vmxnet3_xdp.c new file +454 -0
454 lines not on this page · raw message
drivers/net/vmxnet3/vmxnet3_xdp.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later +* +* Linux driver for VMware's vmxnet3 ethernet NIC. +* Copyright (C) 2008-2023, VMware, Inc. All Rights Reserved. +* Maintained by: [email protected] +* +*/ + +#ifndef _VMXNET3_XDP_H +#define _VMXNET3_XDP_H + +#include <linux/filter.h> +#include <linux/bpf_trace.h> +#include <linux/netlink.h> +#include <net/xdp.h> + +#include "vmxnet3_int.h" + +#define VMXNET3_XDP_ROOM (SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) + \ + XDP_PACKET_HEADROOM) +#define VMXNET3_XDP_MAX_MTU (VMXNET3_MAX_SKB_BUF_SIZE - VMXNET3_XDP_ROOM) + +#define VMXNET3_XDP_CONTINUE 0/* Pass to the stack, ex: XDP_PASS. */ +#define VMXNET3_XDP_TAKEN 1/* Skip the stack, ex: XDP_DROP/TX/REDIRECT */ + +int vmxnet3_xdp (struct net_device *netdev,struct netdev_bpf *bpf); +void vmxnet3_unregister_xdp_rxq (struct vmxnet3_rx_queue *rq); +int vmxnet3_register_xdp_rxq (struct vmxnet3_rx_queue *rq, +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, +struct vmxnet3_rx_buf_info *rbi, +struct Vmxnet3_RxDesc *rxd, +bool *need_flush); +#endif
Signature · 1 line
2.25.1
Quoted 144 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 C. > 3K: use ring0 and ring1As 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 the XDP frame's headroom is zero.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. The newvmxnet3_run_xdpfunction handles the difference of using dataring or ring0, 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 using dma mapped for the transmission.Performance:
Tested using two VMs inside one ESXi machine, using single core on each vmxnet3 device, sender using DPDK testpmd tx-mode attached to vmxnet3 device, sending 64B or 512B 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-mode (with this patch)XDP_DROP: 960Kpps -> 2.4Mpps XDP_PASS: 240Kpps -> 499Kpps XDP_TX: 683Kpps -> 2.3Mpps REDIRECT: 389Kpps -> 449KppsSame performance compared to v2.
512B: skb-mode -> native-mode (with this patch)
v2 v3XDP_DROP: 640Kpps -> 914Kpps -> 1.3Mpps XDP_PASS: 220Kpps -> 240Kpps -> 280Kpps XDP_TX: 483Kpps -> 886Kpps -> 1.3Mpps REDIRECT: 365Kpps -> 1.2Mpps(?) -> 261KppsGood performance improvement over v2, due to skip
skb allocation.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]>---
v4 -> v5:
- move XDP code to separate file: vmxnet3_xdp.{c, h}, suggested by Guolin
- exposevmxnet3_rq_create_allandvmxnet3_adjust_rx_ring_size
- more test usingsamples/bpf/{xdp1, xdp2,xdp_adjust_tail}
- add debug print
- rebase on commit65e6af6cebev3 -> v4:
- code refactoring and improved commit message
- make dataring and non-dataring case clear
- inXDP_PASS, handle xdp.data and xdp.data_end change after bpf program executed
- now still working on internal testing
- v4 applied on net-next commit65e6af6cebefv2 -> v3:
- code refactoring: move the XDP processing to the front of thevmxnet3_rq_rx_complete, and minimize the places of changes to existing code.
- Performance improvement overBUF_SKB(512B) due to skipping skb allocation when DROP and TX.v1 -> v2:
- Avoid skb allocation for small packet size (when dataring is used)
- Usercu_read_lockunlock instead ofREAD_ONCE
- Peroformance improvement over v1
- Merge xdp drop, tx, pass, and redirect into 1 patchI tested the patch using below script:
while [ true ]; do
timeout 20./samples/bpf/xdp_rxq_info-d ens160 -aXDP_DROP--skb-mode timeout 20./samples/bpf/xdp_rxq_info-d ens160 -aXDP_DROPtimeout 20./samples/bpf/xdp_rxq_info-d ens160 -aXDP_PASS--skb-mode timeout 20./samples/bpf/xdp_rxq_info-d ens160 -aXDP_PASStimeout 20./samples/bpf/xdp_rxq_info-d ens160 -aXDP_TX--skb-mode timeout 20./samples/bpf/xdp_rxq_info-d ens160 -aXDP_TXtimeout 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/vmxnet3/Makefile | 2 +- drivers/net/vmxnet3/vmxnet3_drv.c | 48 ++- drivers/net/vmxnet3/vmxnet3_ethtool.c | 14 + drivers/net/vmxnet3/vmxnet3_int.h | 20 ++ drivers/net/vmxnet3/vmxnet3_xdp.c | 454 ++++++++++++++++++++++++++ drivers/net/vmxnet3/vmxnet3_xdp.h | 39 +++ 6 files changed, 569 insertions(+), 8 deletions(-) create mode 100644 drivers/net/vmxnet3/vmxnet3_xdp.c create mode 100644 drivers/net/vmxnet3/vmxnet3_xdp.h
<...>
Quoted 49 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +49
-0+int +vmxnet3_process_xdp (struct vmxnet3_adapter *adapter, +struct vmxnet3_rx_queue *rq, +struct Vmxnet3_RxCompDesc *rcd, +struct vmxnet3_rx_buf_info *rbi, +struct Vmxnet3_RxDesc *rxd, +bool *need_flush) +{ +struct bpf_prog *xdp_prog; +dma_addr_t new_dma_addr; +struct sk_buff *new_skb; +bool rxDataRingUsed; +int ret, act; + + ret =VMXNET3_XDP_CONTINUE ; +if (unlikely (rcd->len ==0 )) +return VMXNET3_XDP_TAKEN ; + + rxDataRingUsed =VMXNET3_RX_DATA_RING (adapter, rcd->rqID); +rcu_read_lock (); + xdp_prog =rcu_dereference (rq->xdp_bpf_prog); +if (!xdp_prog) { +rcu_read_unlock (); +return VMXNET3_XDP_CONTINUE ; + } + act =vmxnet3_run_xdp (rq, rbi, rcd, need_flush, rxDataRingUsed); +rcu_read_unlock (); + +switch (act) { +case XDP_PASS : + ret =VMXNET3_XDP_CONTINUE ; +break ; +case XDP_DROP : +case XDP_TX : +case XDP_REDIRECT : +case XDP_ABORTED : +default : +/* Reuse and remap the existing buffer. */ + ret =VMXNET3_XDP_TAKEN ; +if (rxDataRingUsed) +return ret; + + new_skb = rbi->skb; + new_dma_addr = +dma_map_single (&adapter->pdev->dev, + new_skb->data, rbi->len, +DMA_FROM_DEVICE ); +if (dma_mapping_error (&adapter->pdev->dev, + new_dma_addr)) {
drivers/net/vmxnet3/vmxnet3_xdp.c line 454
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+dev_kfree_skb (new_skb); + rq->stats.drop_total++; +return ret; + } + rbi->dma_addr = new_dma_addr; + rxd->addr =cpu_to_le64 (rbi->dma_addr); + rxd->len = rbi->len; + } +return ret; +}
FOr XDP_DROP and XDP_ABORTED this makes sense. You might want to add a trace point in the case of aborted just so you can catch such cases for debug.
However for XDP_TX and XDP_REDIRECT shouldn't both of those be calling out to seperate functions to either place the frame on a Tx ring or to hand it off to xdp_do_redirect so that the frame gets routed where it needs to go? Also don't you run a risk with overwriting frames that might be waiting on transmit?
Thanks for taking a look at this patch!
<...>
Quoted 56 lines
Quoted 56 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +55
-0+int +vmxnet3_process_xdp (struct vmxnet3_adapter *adapter, +struct vmxnet3_rx_queue *rq, +struct Vmxnet3_RxCompDesc *rcd, +struct vmxnet3_rx_buf_info *rbi, +struct Vmxnet3_RxDesc *rxd, +bool *need_flush) +{ +struct bpf_prog *xdp_prog; +dma_addr_t new_dma_addr; +struct sk_buff *new_skb; +bool rxDataRingUsed; +int ret, act; + + ret =VMXNET3_XDP_CONTINUE ; +if (unlikely (rcd->len ==0 )) +return VMXNET3_XDP_TAKEN ; + + rxDataRingUsed =VMXNET3_RX_DATA_RING (adapter, rcd->rqID); +rcu_read_lock (); + xdp_prog =rcu_dereference (rq->xdp_bpf_prog); +if (!xdp_prog) { +rcu_read_unlock (); +return VMXNET3_XDP_CONTINUE ; + } + act =vmxnet3_run_xdp (rq, rbi, rcd, need_flush, rxDataRingUsed); +rcu_read_unlock (); + +switch (act) { +case XDP_PASS : + ret =VMXNET3_XDP_CONTINUE ; +break ; +case XDP_DROP : +case XDP_TX : +case XDP_REDIRECT : +case XDP_ABORTED : +default : +/* Reuse and remap the existing buffer. */ + ret =VMXNET3_XDP_TAKEN ; +if (rxDataRingUsed) +return ret; + + new_skb = rbi->skb; + new_dma_addr = +dma_map_single (&adapter->pdev->dev, + new_skb->data, rbi->len, +DMA_FROM_DEVICE ); +if (dma_mapping_error (&adapter->pdev->dev, + new_dma_addr)) { +dev_kfree_skb (new_skb); + rq->stats.drop_total++; +return ret; + } + rbi->dma_addr = new_dma_addr; + rxd->addr =cpu_to_le64 (rbi->dma_addr);
Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_xdp.c line 454
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4
-0+ rxd->len = rbi->len; + } +return ret; +}FOr
XDP_DROPandXDP_ABORTEDthis makes sense. You might want to add a trace point in the case of aborted just so you can catch such cases for debug.
Good point, I will add the trace point.
Quoted 6 lines
However for
XDP_TXandXDP_REDIRECTshouldn't both of those be calling out to seperate functions to either place the frame on a Tx ring or to hand it off toxdp_do_redirectso that the frame gets routed where it needs to go? Also don't you run a risk with overwriting frames that might be waiting on transmit?
Yes, I have XDP_TX and XDP_REDIRECT handled in another function, the vmxnet3_run_xdp() and __vmxnet3_run_xdp().
How do I avoid overwriting frames that might be waiting on transmit? I checked my vmxnet3_xdp_xmit_back and vmxnet3_xdp_xmit_frame, I think since I called the vmxnet3_xdp_xmit_frame at the rx context, it should be ok?
Thanks
William
Quoted 67 lines · William Tu
Thanks for taking a look at this patch!
<...>
Quoted 56 lines
Quoted 56 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +55
-0+int +vmxnet3_process_xdp (struct vmxnet3_adapter *adapter, +struct vmxnet3_rx_queue *rq, +struct Vmxnet3_RxCompDesc *rcd, +struct vmxnet3_rx_buf_info *rbi, +struct Vmxnet3_RxDesc *rxd, +bool *need_flush) +{ +struct bpf_prog *xdp_prog; +dma_addr_t new_dma_addr; +struct sk_buff *new_skb; +bool rxDataRingUsed; +int ret, act; + + ret =VMXNET3_XDP_CONTINUE ; +if (unlikely (rcd->len ==0 )) +return VMXNET3_XDP_TAKEN ; + + rxDataRingUsed =VMXNET3_RX_DATA_RING (adapter, rcd->rqID); +rcu_read_lock (); + xdp_prog =rcu_dereference (rq->xdp_bpf_prog); +if (!xdp_prog) { +rcu_read_unlock (); +return VMXNET3_XDP_CONTINUE ; + } + act =vmxnet3_run_xdp (rq, rbi, rcd, need_flush, rxDataRingUsed); +rcu_read_unlock (); + +switch (act) { +case XDP_PASS : + ret =VMXNET3_XDP_CONTINUE ; +break ; +case XDP_DROP : +case XDP_TX : +case XDP_REDIRECT : +case XDP_ABORTED : +default : +/* Reuse and remap the existing buffer. */ + ret =VMXNET3_XDP_TAKEN ; +if (rxDataRingUsed) +return ret; + + new_skb = rbi->skb; + new_dma_addr = +dma_map_single (&adapter->pdev->dev, + new_skb->data, rbi->len, +DMA_FROM_DEVICE ); +if (dma_mapping_error (&adapter->pdev->dev, + new_dma_addr)) { +dev_kfree_skb (new_skb); + rq->stats.drop_total++; +return ret; + } + rbi->dma_addr = new_dma_addr; + rxd->addr =cpu_to_le64 (rbi->dma_addr);Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_xdp.c line 454
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4
-0+ rxd->len = rbi->len; + } +return ret; +}FOr
XDP_DROPandXDP_ABORTEDthis makes sense. You might want to add a trace point in the case of aborted just so you can catch such cases for debug.
Quoted 2 lines
Good point, I will add the trace point.
You will probably want to add that trace point in __vmxnet3_run_xdp.
Quoted 8 lines
Quoted 5 lines
However for
XDP_TXandXDP_REDIRECTshouldn't both of those be calling out to seperate functions to either place the frame on a Tx ring or to hand it off toxdp_do_redirectso that the frame gets routed where it needs to go? Also don't you run a risk with overwriting frames that might be waiting on transmit?Yes, I have
XDP_TXandXDP_REDIRECThandled in another function, thevmxnet3_run_xdp()and__vmxnet3_run_xdp().
Okay, for the redirect case it looks like you address it by doing a memcpy to a freshly allocated page so that saves us that trouble in that case.
Quoted 4 lines
How do I avoid overwriting frames that might be waiting on transmit? I checked my
vmxnet3_xdp_xmit_backandvmxnet3_xdp_xmit_frame, I think since I called thevmxnet3_xdp_xmit_frameat the rx context, it should be ok?
I don't think you can guarantee that. Normally for TX you would want to detach and replace the page unless you have some sort of other recycling/reuse taking care of it for you. Normally that is handled via page pool.
On the Intel parts I had gotten around that via our split buffer model so we just switched to the other half of the page while the Tx sat on the first half, and by the time we would have to check again we would either detach the page for flip back if it had already been freed by the Tx path.
drivers/net/vmxnet3/vmxnet3_xdp.c line 210
Quoted 5 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4
-0+static int +vmxnet3_xdp_xmit_back (struct vmxnet3_adapter *adapter, +struct xdp_frame *xdpf, +struct sk_buff *skb)
Also after re-reviewing this I was wondering why you have the skb argument for this function? The only caller is passing NULL and I wouldn't expect you to be passing an skb since you are working with XDP buffers anyway. Seems like you could also drop the argument from vmxnet3_xdp_xmit_frame() since you are only passing it NULL as well.
Quoted 69 lines · Alexander H Duyck
Quoted 67 lines · William Tu
Thanks for taking a look at this patch!
<...>
Quoted 64 lines
Quoted 50 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +49
-0+int +vmxnet3_process_xdp (struct vmxnet3_adapter *adapter, +struct vmxnet3_rx_queue *rq, +struct Vmxnet3_RxCompDesc *rcd, +struct vmxnet3_rx_buf_info *rbi, +struct Vmxnet3_RxDesc *rxd, +bool *need_flush) +{ +struct bpf_prog *xdp_prog; +dma_addr_t new_dma_addr; +struct sk_buff *new_skb; +bool rxDataRingUsed; +int ret, act; + + ret =VMXNET3_XDP_CONTINUE ; +if (unlikely (rcd->len ==0 )) +return VMXNET3_XDP_TAKEN ; + + rxDataRingUsed =VMXNET3_RX_DATA_RING (adapter, rcd->rqID); +rcu_read_lock (); + xdp_prog =rcu_dereference (rq->xdp_bpf_prog); +if (!xdp_prog) { +rcu_read_unlock (); +return VMXNET3_XDP_CONTINUE ; + } + act =vmxnet3_run_xdp (rq, rbi, rcd, need_flush, rxDataRingUsed); +rcu_read_unlock (); + +switch (act) { +case XDP_PASS : + ret =VMXNET3_XDP_CONTINUE ; +break ; +case XDP_DROP : +case XDP_TX : +case XDP_REDIRECT : +case XDP_ABORTED : +default : +/* Reuse and remap the existing buffer. */ + ret =VMXNET3_XDP_TAKEN ; +if (rxDataRingUsed) +return ret; + + new_skb = rbi->skb; + new_dma_addr = +dma_map_single (&adapter->pdev->dev, + new_skb->data, rbi->len, +DMA_FROM_DEVICE ); +if (dma_mapping_error (&adapter->pdev->dev, + new_dma_addr)) {drivers/net/vmxnet3/vmxnet3_xdp.c line 454
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+dev_kfree_skb (new_skb); + rq->stats.drop_total++; +return ret; + } + rbi->dma_addr = new_dma_addr; + rxd->addr =cpu_to_le64 (rbi->dma_addr); + rxd->len = rbi->len; + } +return ret; +}FOr
XDP_DROPandXDP_ABORTEDthis makes sense. You might want to add a trace point in the case of aborted just so you can catch such cases for debug.
Quoted 4 lines
Quoted 2 lines
Good point, I will add the trace point.
You will probably want to add that trace point in
__vmxnet3_run_xdp.
Yes, thanks.
Quoted 24 lines
Quoted 9 lines
Quoted 6 lines
However for
XDP_TXandXDP_REDIRECTshouldn't both of those be calling out to seperate functions to either place the frame on a Tx ring or to hand it off toxdp_do_redirectso that the frame gets routed where it needs to go? Also don't you run a risk with overwriting frames that might be waiting on transmit?Yes, I have
XDP_TXandXDP_REDIRECThandled in another function, thevmxnet3_run_xdp()and__vmxnet3_run_xdp().Okay, for the redirect case it looks like you address it by doing a memcpy to a freshly allocated page so that saves us that trouble in that case.
Quoted 4 lines
How do I avoid overwriting frames that might be waiting on transmit? I checked my
vmxnet3_xdp_xmit_backandvmxnet3_xdp_xmit_frame, I think since I called thevmxnet3_xdp_xmit_frameat the rx context, it should be ok?I don't think you can guarantee that. Normally for TX you would want to detach and replace the page unless you have some sort of other recycling/reuse taking care of it for you. Normally that is handled via page pool.
Quoted 5 lines
On the Intel parts I had gotten around that via our split buffer model so we just switched to the other half of the page while the Tx sat on the first half, and by the time we would have to check again we would either detach the page for flip back if it had already been freed by the Tx path.
I see your point. So for XDP_TX, I can also do s.t like I did in XDP_REDIRECT, memcpy to a freshly allocated page so the frame won't get overwritten. Probably the performance will suffer.
Do you suggest allocating new page or risk buffer overwritten?
Quoted 12 lines
drivers/net/vmxnet3/vmxnet3_xdp.c line 210
Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4
-0+static int +vmxnet3_xdp_xmit_back (struct vmxnet3_adapter *adapter, +struct xdp_frame *xdpf, +struct sk_buff *skb)Also after re-reviewing this I was wondering why you have the skb argument for this function? The only caller is passing NULL and I wouldn't expect you to be passing an skb since you are working with XDP buffers anyway. Seems like you could also drop the argument from
vmxnet3_xdp_xmit_frame()since you are only passing it NULL as well.
You're right! I don't need to pass skb here. I probably forgot to remove it when refactoring code. Will remove the two places.
Thanks!
Regards,
William
Quoted 24 lines · William Tu
Quoted 16 lines · Alexander H Duyck
Quoted 8 lines · William Tu
Thanks for taking a look at this patch!
<...>
How do I avoid overwriting frames that might be waiting on transmit? I checked my
vmxnet3_xdp_xmit_backandvmxnet3_xdp_xmit_frame, I think since I called thevmxnet3_xdp_xmit_frameat the rx context, it should be ok?I don't think you can guarantee that. Normally for TX you would want to detach and replace the page unless you have some sort of other recycling/reuse taking care of it for you. Normally that is handled via page pool.
Quoted 5 lines
On the Intel parts I had gotten around that via our split buffer model so we just switched to the other half of the page while the Tx sat on the first half, and by the time we would have to check again we would either detach the page for flip back if it had already been freed by the Tx path.
Quoted 4 lines
I see your point. So for
XDP_TX, I can also do s.t like I did inXDP_REDIRECT, memcpy to a freshly allocated page so the frame won't get overwritten. Probably the performance will suffer.
Do you suggest allocating new page or risk buffer overwritten?
This is one of the reasons for the page pool being used in other drivers. You may want to look at going that route if you want to avoid the memcpy. I don't think you can leave the page mapped without risking it will be overwritten.
Quoted 13 lines
Quoted 12 lines
drivers/net/vmxnet3/vmxnet3_xdp.c line 210
Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +4
-0+static int +vmxnet3_xdp_xmit_back (struct vmxnet3_adapter *adapter, +struct xdp_frame *xdpf, +struct sk_buff *skb)Also after re-reviewing this I was wondering why you have the skb argument for this function? The only caller is passing NULL and I wouldn't expect you to be passing an skb since you are working with XDP buffers anyway. Seems like you could also drop the argument from
vmxnet3_xdp_xmit_frame()since you are only passing it NULL as well.
Quoted 3 lines
You're right! I don't need to pass skb here. I probably forgot to remove it when refactoring code. Will remove the two places.
Thanks!
Sounds good. I will keep an eye out for v6.