vmxnet3: Add XDP support.
Subsystems (3)
RFC PATCH v18 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()
- optimization for DMA synchronization using actual frame length, instead of always max_len
---
v17 -> v18:
- rebase df28e8690e71 ("Merge branch 'net-better-const'") feedbacks from Alexander Lobakin
- use NL_SET_ERR_MSG_FMT_MOD for printing MTU in error msg
- I decided to skip the optimization for DMA synchronization, to keep this version simpler, leave it for future work.
https://github.com/williamtu/net-next/compare/v17..v18
v16 -> v17:
feedbacks from Alexander Lobakin
- code refectoring and cleanup and remove excessive braces around condition
- page pool creation: create 1-dir instead of bi-direction. 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.
- add XDP feature advertisement
- rebase to net-next 01bb11ad828b32074976
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 | 236 ++++++++++++-- drivers/net/vmxnet3/vmxnet3_ethtool.c | 23 ++ drivers/net/vmxnet3/vmxnet3_int.h | 43 ++- drivers/net/vmxnet3/vmxnet3_xdp.c | 422 ++++++++++++++++++++++++++ drivers/net/vmxnet3/vmxnet3_xdp.h | 49 +++ 7 files changed, 734 insertions(+), 42 deletions(-) create mode 100644 drivers/net/vmxnet3/vmxnet3_xdp.c create mode 100644 drivers/net/vmxnet3/vmxnet3_xdp.h
drivers/net/Kconfig +1 -0
@@ -570,6 +570,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 +205 -31
430 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 +422 -0
422 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)
The 03/18/2023 14:49, William Tu wrote:
Hi William,
...
drivers/net/vmxnet3/vmxnet3_xdp.c line 125
Quoted 13 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +13
-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 ;
This doesn't seem to be used anywhere, so it can be removed.
Quoted 17 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +17
-0+u32 dw2; + + dw2 = (tq->tx_ring.gen ^0x1 ) <<VMXNET3_TXD_GEN_SHIFT ; + dw2 |= xdpf->len; + ctx.sop_txd = tq->tx_ring.base + tq->tx_ring.next2fill; + gdesc = ctx.sop_txd; + + buf_size = xdpf->len; + tbi = tq->buf_info + tq->tx_ring.next2fill; + +if (vmxnet3_cmd_ring_desc_avail (&tq->tx_ring) ==0 ) { + tq->stats.tx_ring_full++; +return -ENOSPC ; + } + + tbi->map_type =VMXNET3_MAP_XDP ; +if (dma_map) {/* ndo_xdp_xmit */
drivers/net/vmxnet3/vmxnet3_xdp.c line 152
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+ tbi->dma_addr =dma_map_single (&adapter->pdev->dev, + xdpf->data, buf_size, +DMA_TO_DEVICE ); +if (dma_mapping_error (&adapter->pdev->dev, tbi->dma_addr)) +return -EFAULT ; + tbi->map_type |=VMXNET3_MAP_SINGLE ; + }else {/* XDP buffer from page pool */ + page =virt_to_page (xdpf->data); + tbi->dma_addr =page_pool_get_dma_addr (page) + +XDP_PACKET_HEADROOM ;
Shouldn't this be VMXNET3_XDP_HEADROOM?
drivers/net/vmxnet3/vmxnet3_xdp.c line 155
Quoted 3 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +3
-0+dma_sync_single_for_device (&adapter->pdev->dev, + tbi->dma_addr, buf_size, +DMA_BIDIRECTIONAL );
Shouldn't this be DMA_TO_DEVICE instead of DMA_BIDERECTIONAL?
Quoted 44 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +44
-0+ } + tbi->xdpf = xdpf; + tbi->len = buf_size; + + gdesc = tq->tx_ring.base + tq->tx_ring.next2fill; +WARN_ON_ONCE (gdesc->txd.gen == tq->tx_ring.gen); + + gdesc->txd.addr =cpu_to_le64 (tbi->dma_addr); + gdesc->dword[2 ] =cpu_to_le32 (dw2); + +/* Setup the EOP desc */ + gdesc->dword[3 ] =cpu_to_le32 (VMXNET3_TXD_CQ |VMXNET3_TXD_EOP ); + + gdesc->txd.om =0 ; + gdesc->txd.msscof =0 ; + gdesc->txd.hlen =0 ; + gdesc->txd.ti =0 ; + + tx_num_deferred =le32_to_cpu (tq->shared->txNumDeferred); +le32_add_cpu (&tq->shared->txNumDeferred,1 ); + tx_num_deferred++; + +vmxnet3_cmd_ring_adv_next2fill (&tq->tx_ring); + +/* set the last buf_info for the pkt */ + tbi->sop_idx = ctx.sop_txd - tq->tx_ring.base; + +dma_wmb (); + gdesc->dword[2 ] =cpu_to_le32 (le32_to_cpu (gdesc->dword[2 ]) ^ +VMXNET3_TXD_GEN ); + +/* No need to handle the case when tx_num_deferred doesn't reach +* threshold. Backend driver at hypervisor side will poll and reset +* tq->shared->txNumDeferred to 0. +*/ +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); + } + +return ret; +}
...
Quoted 15 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +15
-0+static int +vmxnet3_run_xdp (struct vmxnet3_rx_queue *rq,struct xdp_buff *xdp, +struct bpf_prog *prog) +{ +struct xdp_frame *xdpf; +struct page *page; +int err; +u32 act; + + act =bpf_prog_run_xdp (prog, xdp); + rq->stats.xdp_packets++; + page =virt_to_page (xdp->data_hard_start); + +switch (act) { +case XDP_PASS :
drivers/net/vmxnet3/vmxnet3_xdp.c line 278
Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +10
-0+return act; +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 you want, I think you can drop xdp_convert_buff_to_frame() and pass directly the page. And then inside vmxnet3_unmap_pkt() you can use page_pool_recycle_direct().
Of course this requires few other changes (I think you need a new map_type) but in the end you might save some CPU usage.
Quoted 25 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +25
-0+if (unlikely (!xdpf || +vmxnet3_xdp_xmit_back (rq->adapter, xdpf))) { + rq->stats.xdp_drops++; +page_pool_recycle_direct (rq->page_pool, page); + }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, page); + +return act; +} +
Signature · 1 line
/Horatiu
Hi Horatiu,
Thanks for your review and finding more issues!
Quoted 7 lines · Horatiu Vultur
The 03/18/2023 14:49, William Tu wrote:
Hi William,
...
Quoted 15 lines
drivers/net/vmxnet3/vmxnet3_xdp.c line 125
Quoted 13 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +13
-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 ;This doesn't seem to be used anywhere, so it can be removed.
yes, I will just return 0 at the end.
Quoted 22 lines
Quoted 22 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +21
-0+u32 dw2; + + dw2 = (tq->tx_ring.gen ^0x1 ) <<VMXNET3_TXD_GEN_SHIFT ; + dw2 |= xdpf->len; + ctx.sop_txd = tq->tx_ring.base + tq->tx_ring.next2fill; + gdesc = ctx.sop_txd; + + buf_size = xdpf->len; + tbi = tq->buf_info + tq->tx_ring.next2fill; + +if (vmxnet3_cmd_ring_desc_avail (&tq->tx_ring) ==0 ) { + tq->stats.tx_ring_full++; +return -ENOSPC ; + } + + tbi->map_type =VMXNET3_MAP_XDP ; +if (dma_map) {/* ndo_xdp_xmit */ + tbi->dma_addr =dma_map_single (&adapter->pdev->dev, + xdpf->data, buf_size, +DMA_TO_DEVICE ); +if (dma_mapping_error (&adapter->pdev->dev, tbi->dma_addr))
Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_xdp.c line 152
Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +6
-0+return -EFAULT ; + tbi->map_type |=VMXNET3_MAP_SINGLE ; + }else {/* XDP buffer from page pool */ + page =virt_to_page (xdpf->data); + tbi->dma_addr =page_pool_get_dma_addr (page) + +XDP_PACKET_HEADROOM ;Shouldn't this be
VMXNET3_XDP_HEADROOM?
yes, will fix it.
Quoted 6 lines
drivers/net/vmxnet3/vmxnet3_xdp.c line 155
Quoted 4 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +3
-0+dma_sync_single_for_device (&adapter->pdev->dev, + tbi->dma_addr, buf_size, +DMA_BIDIRECTIONAL );Shouldn't this be
DMA_TO_DEVICEinstead ofDMA_BIDERECTIONAL?
sure, will fix it.
Originally I looked at stmmac_main.c and I thought it's an optimization since in the beginning of page pool creation we set it DMA_BIDRIECTIONAL. I guess it's not applicable here.
Quoted 71 lines
Quoted 45 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +44
-0+ } + tbi->xdpf = xdpf; + tbi->len = buf_size; + + gdesc = tq->tx_ring.base + tq->tx_ring.next2fill; +WARN_ON_ONCE (gdesc->txd.gen == tq->tx_ring.gen); + + gdesc->txd.addr =cpu_to_le64 (tbi->dma_addr); + gdesc->dword[2 ] =cpu_to_le32 (dw2); + +/* Setup the EOP desc */ + gdesc->dword[3 ] =cpu_to_le32 (VMXNET3_TXD_CQ |VMXNET3_TXD_EOP ); + + gdesc->txd.om =0 ; + gdesc->txd.msscof =0 ; + gdesc->txd.hlen =0 ; + gdesc->txd.ti =0 ; + + tx_num_deferred =le32_to_cpu (tq->shared->txNumDeferred); +le32_add_cpu (&tq->shared->txNumDeferred,1 ); + tx_num_deferred++; + +vmxnet3_cmd_ring_adv_next2fill (&tq->tx_ring); + +/* set the last buf_info for the pkt */ + tbi->sop_idx = ctx.sop_txd - tq->tx_ring.base; + +dma_wmb (); + gdesc->dword[2 ] =cpu_to_le32 (le32_to_cpu (gdesc->dword[2 ]) ^ +VMXNET3_TXD_GEN ); + +/* No need to handle the case when tx_num_deferred doesn't reach +* threshold. Backend driver at hypervisor side will poll and reset +* tq->shared->txNumDeferred to 0. +*/ +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); + } + +return ret; +}...
Quoted 23 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +23
-0+static int +vmxnet3_run_xdp (struct vmxnet3_rx_queue *rq,struct xdp_buff *xdp, +struct bpf_prog *prog) +{ +struct xdp_frame *xdpf; +struct page *page; +int err; +u32 act; + + act =bpf_prog_run_xdp (prog, xdp); + rq->stats.xdp_packets++; + page =virt_to_page (xdp->data_hard_start); + +switch (act) { +case XDP_PASS : +return act; +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;
Quoted 8 lines
drivers/net/vmxnet3/vmxnet3_xdp.c line 278
Quoted 2 lines
drivers/net/vmxnet3/vmxnet3_xdp.c new file +2
-0+case XDP_TX : + xdpf =xdp_convert_buff_to_frame (xdp);If you want, I think you can drop
xdp_convert_buff_to_frame()and pass directly the page. And then insidevmxnet3_unmap_pkt()you can usepage_pool_recycle_direct().
Of course this requires few other changes (I think you need a newmap_type) but in the end you might save some CPU usage.
Thanks for the suggestion.
Will leave this for future work.
Thanks!
William
Hi William,
url: https://github.com/intel-lab-lkp/linux/commits/William-Tu/vmxnet3-Add-XDP-support/20230319-055034 patch link: https://lore.kernel.org/r/20230318214953.36834-1-u9012063%40gmail.com patch subject: [PATCH RFC v18 net-next] vmxnet3: Add XDP support. config: s390-randconfig-m031-20230321 (https://download.01.org/0day-ci/archive/20230323/[email protected]/config) compiler: s390-linux-gcc (GCC) 12.1.0
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Link: https://lore.kernel.org/r/[email protected]/
smatch warnings:drivers/net/vmxnet3/vmxnet3_xdp.c:362 vmxnet3_process_xdp_small() warn: variable dereferenced before check 'skb_xdp_pass' (see line 361) drivers/net/vmxnet3/vmxnet3_xdp.c:406 vmxnet3_process_xdp() warn: variable dereferenced before check 'skb_xdp_pass' (see line 405)
vim +/skb_xdp_pass +362 drivers/net/vmxnet3/vmxnet3_xdp.c
089db7a8620943 William Tu 2023-03-18 351 rcu_read_lock();
089db7a8620943 William Tu 2023-03-18 352 xdp_prog = rcu_dereference(rq->adapter->xdp_bpf_prog);
089db7a8620943 William Tu 2023-03-18 353 if (!xdp_prog) {
089db7a8620943 William Tu 2023-03-18 354 act = XDP_PASS;
089db7a8620943 William Tu 2023-03-18 355 goto out_skb;
089db7a8620943 William Tu 2023-03-18 356 }
089db7a8620943 William Tu 2023-03-18 357 act = vmxnet3_run_xdp(rq, &xdp, xdp_prog);
089db7a8620943 William Tu 2023-03-18 358
089db7a8620943 William Tu 2023-03-18 359 if (act == XDP_PASS) {
089db7a8620943 William Tu 2023-03-18 360 out_skb:089db7a8620943 William Tu 2023-03-18 @361 *skb_xdp_pass = vmxnet3_build_skb(rq, page, &xdp);089db7a8620943 William Tu 2023-03-18 @362 if (!skb_xdp_pass)
This should be testing if (!*skb_xdp_pass)
089db7a8620943 William Tu 2023-03-18 363 return XDP_DROP;
089db7a8620943 William Tu 2023-03-18 364 }
089db7a8620943 William Tu 2023-03-18 365
089db7a8620943 William Tu 2023-03-18 366 /* No need to refill. */
089db7a8620943 William Tu 2023-03-18 367 return act;
089db7a8620943 William Tu 2023-03-18 368 }
089db7a8620943 William Tu 2023-03-18 369
089db7a8620943 William Tu 2023-03-18 370 int
089db7a8620943 William Tu 2023-03-18 371 vmxnet3_process_xdp(struct vmxnet3_adapter *adapter,
089db7a8620943 William Tu 2023-03-18 372 struct vmxnet3_rx_queue *rq,
089db7a8620943 William Tu 2023-03-18 373 struct Vmxnet3_RxCompDesc *rcd,
089db7a8620943 William Tu 2023-03-18 374 struct vmxnet3_rx_buf_info *rbi,
089db7a8620943 William Tu 2023-03-18 375 struct Vmxnet3_RxDesc *rxd,
089db7a8620943 William Tu 2023-03-18 376 struct sk_buff **skb_xdp_pass)
089db7a8620943 William Tu 2023-03-18 377 {
089db7a8620943 William Tu 2023-03-18 378 struct bpf_prog *xdp_prog;
089db7a8620943 William Tu 2023-03-18 379 dma_addr_t new_dma_addr;
089db7a8620943 William Tu 2023-03-18 380 struct xdp_buff xdp;
089db7a8620943 William Tu 2023-03-18 381 struct page *page;
089db7a8620943 William Tu 2023-03-18 382 void *new_data;
089db7a8620943 William Tu 2023-03-18 383 int act;
089db7a8620943 William Tu 2023-03-18 384
089db7a8620943 William Tu 2023-03-18 385 page = rbi->page;
089db7a8620943 William Tu 2023-03-18 386 dma_sync_single_for_cpu(&adapter->pdev->dev,
089db7a8620943 William Tu 2023-03-18 387 page_pool_get_dma_addr(page) +
089db7a8620943 William Tu 2023-03-18 388 rq->page_pool->p.offset, rcd->len,
089db7a8620943 William Tu 2023-03-18 389 page_pool_get_dma_dir(rq->page_pool));
089db7a8620943 William Tu 2023-03-18 390
089db7a8620943 William Tu 2023-03-18 391 xdp_init_buff(&xdp, rbi->len, &rq->xdp_rxq);
089db7a8620943 William Tu 2023-03-18 392 xdp_prepare_buff(&xdp, page_address(page), rq->page_pool->p.offset,
089db7a8620943 William Tu 2023-03-18 393 rcd->len, false);
089db7a8620943 William Tu 2023-03-18 394 xdp_buff_clear_frags_flag(&xdp);
089db7a8620943 William Tu 2023-03-18 395
089db7a8620943 William Tu 2023-03-18 396 xdp_prog = rcu_dereference(rq->adapter->xdp_bpf_prog);
089db7a8620943 William Tu 2023-03-18 397 if (!xdp_prog) {
089db7a8620943 William Tu 2023-03-18 398 act = XDP_PASS;
089db7a8620943 William Tu 2023-03-18 399 goto out_skb;
089db7a8620943 William Tu 2023-03-18 400 }
089db7a8620943 William Tu 2023-03-18 401 act = vmxnet3_run_xdp(rq, &xdp, xdp_prog);
089db7a8620943 William Tu 2023-03-18 402
089db7a8620943 William Tu 2023-03-18 403 if (act == XDP_PASS) {
089db7a8620943 William Tu 2023-03-18 404 out_skb:
089db7a8620943 William Tu 2023-03-18 @405 *skb_xdp_pass = vmxnet3_build_skb(rq, page, &xdp);
089db7a8620943 William Tu 2023-03-18 @406 if (!skb_xdp_pass)
^^^^^^^^^^^^^Same.
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Quoted 80 lines · Dan Carpenter
Hi William,
url: https://github.com/intel-lab-lkp/linux/commits/William-Tu/vmxnet3-Add-XDP-support/20230319-055034 patch link: https://lore.kernel.org/r/20230318214953.36834-1-u9012063%40gmail.com patch subject: [PATCH RFC v18 net-next] vmxnet3: Add XDP support. config: s390-randconfig-m031-20230321 (https://download.01.org/0day-ci/archive/20230323/[email protected]/config) compiler: s390-linux-gcc (GCC) 12.1.0If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Link: https://lore.kernel.org/r/[email protected]/smatch warnings:
drivers/net/vmxnet3/vmxnet3_xdp.c:362vmxnet3_process_xdp_small()warn: variable dereferenced before check 'skb_xdp_pass' (see line 361)drivers/net/vmxnet3/vmxnet3_xdp.c:406vmxnet3_process_xdp()warn: variable dereferenced before check 'skb_xdp_pass' (see line 405)vim +/skb_xdp_pass +362
drivers/net/vmxnet3/vmxnet3_xdp.c089db7a8620943 William Tu 2023-03-18 351 rcu_read_lock(); 089db7a8620943 William Tu 2023-03-18 352 xdp_prog = rcu_dereference(rq->adapter->xdp_bpf_prog); 089db7a8620943 William Tu 2023-03-18 353 if (!xdp_prog) { 089db7a8620943 William Tu 2023-03-18 354 act = XDP_PASS; 089db7a8620943 William Tu 2023-03-18 355 goto out_skb; 089db7a8620943 William Tu 2023-03-18 356 } 089db7a8620943 William Tu 2023-03-18 357 act = vmxnet3_run_xdp(rq, &xdp, xdp_prog); 089db7a8620943 William Tu 2023-03-18 358 089db7a8620943 William Tu 2023-03-18 359 if (act == XDP_PASS) { 089db7a8620943 William Tu 2023-03-18 360 out_skb:
089db7a8620943William Tu 2023-03-18 @361*skb_xdp_pass=vmxnet3_build_skb(rq, page, &xdp);089db7a8620943William Tu 2023-03-18 @362 if (!skb_xdp_pass)This should be testing if (!*skb_xdp_pass)
089db7a8620943 William Tu 2023-03-18 363 return XDP_DROP; 089db7a8620943 William Tu 2023-03-18 364 } 089db7a8620943 William Tu 2023-03-18 365 089db7a8620943 William Tu 2023-03-18 366 /* No need to refill. */ 089db7a8620943 William Tu 2023-03-18 367 return act; 089db7a8620943 William Tu 2023-03-18 368 } 089db7a8620943 William Tu 2023-03-18 369 089db7a8620943 William Tu 2023-03-18 370 int 089db7a8620943 William Tu 2023-03-18 371 vmxnet3_process_xdp(struct vmxnet3_adapter *adapter, 089db7a8620943 William Tu 2023-03-18 372 struct vmxnet3_rx_queue *rq, 089db7a8620943 William Tu 2023-03-18 373 struct Vmxnet3_RxCompDesc *rcd, 089db7a8620943 William Tu 2023-03-18 374 struct vmxnet3_rx_buf_info *rbi, 089db7a8620943 William Tu 2023-03-18 375 struct Vmxnet3_RxDesc *rxd, 089db7a8620943 William Tu 2023-03-18 376 struct sk_buff **skb_xdp_pass) 089db7a8620943 William Tu 2023-03-18 377 { 089db7a8620943 William Tu 2023-03-18 378 struct bpf_prog *xdp_prog; 089db7a8620943 William Tu 2023-03-18 379 dma_addr_t new_dma_addr; 089db7a8620943 William Tu 2023-03-18 380 struct xdp_buff xdp; 089db7a8620943 William Tu 2023-03-18 381 struct page *page; 089db7a8620943 William Tu 2023-03-18 382 void *new_data; 089db7a8620943 William Tu 2023-03-18 383 int act; 089db7a8620943 William Tu 2023-03-18 384 089db7a8620943 William Tu 2023-03-18 385 page = rbi->page; 089db7a8620943 William Tu 2023-03-18 386 dma_sync_single_for_cpu(&adapter->pdev->dev, 089db7a8620943 William Tu 2023-03-18 387 page_pool_get_dma_addr(page) + 089db7a8620943 William Tu 2023-03-18 388 rq->page_pool->p.offset, rcd->len, 089db7a8620943 William Tu 2023-03-18 389 page_pool_get_dma_dir(rq->page_pool)); 089db7a8620943 William Tu 2023-03-18 390 089db7a8620943 William Tu 2023-03-18 391 xdp_init_buff(&xdp, rbi->len, &rq->xdp_rxq); 089db7a8620943 William Tu 2023-03-18 392 xdp_prepare_buff(&xdp, page_address(page), rq->page_pool->p.offset, 089db7a8620943 William Tu 2023-03-18 393 rcd->len, false); 089db7a8620943 William Tu 2023-03-18 394 xdp_buff_clear_frags_flag(&xdp); 089db7a8620943 William Tu 2023-03-18 395 089db7a8620943 William Tu 2023-03-18 396 xdp_prog = rcu_dereference(rq->adapter->xdp_bpf_prog); 089db7a8620943 William Tu 2023-03-18 397 if (!xdp_prog) { 089db7a8620943 William Tu 2023-03-18 398 act = XDP_PASS; 089db7a8620943 William Tu 2023-03-18 399 goto out_skb; 089db7a8620943 William Tu 2023-03-18 400 } 089db7a8620943 William Tu 2023-03-18 401 act = vmxnet3_run_xdp(rq, &xdp, xdp_prog); 089db7a8620943 William Tu 2023-03-18 402 089db7a8620943 William Tu 2023-03-18 403 if (act == XDP_PASS) { 089db7a8620943 William Tu 2023-03-18 404 out_skb: 089db7a8620943 William Tu 2023-03-18 @405 *skb_xdp_pass = vmxnet3_build_skb(rq, page, &xdp); 089db7a8620943 William Tu 2023-03-18 @406 if (!skb_xdp_pass) ^^^^^^^^^^^^^
Quoted 7 lines
Same.
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests
Hi Dan,
Thanks for picking up this patch and testing it!
I will fix the two places and resend.
William