Introduce AF_XDP buffer allocation API
Subsystems (11)
PATCH v3 6/15 i40e: refactor rx_bi accesses
In reply to Björn TöpelFrom: Bj?rn T?pel <[email protected]>
As a first step to migrate i40e to the new MEM_TYPE_XSK_BUFF_POOL APIs, code that accesses the rx_bi (SW/shadow ring) is refactored to use an accessor function.
--- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 17 +++++++++++------ drivers/net/ethernet/intel/i40e/i40e_xsk.c | 18 ++++++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_txrx.c +11 -6
@@ -1195,6 +1195,11 @@ static void i40e_update_itr(struct i40e_q_vector *q_vector, rc->total_packets =0 ; } +static struct i40e_rx_buffer *i40e_rx_bi (struct i40e_ring *rx_ring,u32 idx) +{ +return &rx_ring->rx_bi[idx]; +} +/** * i40e_reuse_rx_page - page flip buffer and store it back on the ring * @rx_ring: rx descriptor ring to store buffers on
@@ -1208,7 +1213,7 @@ static void i40e_reuse_rx_page(struct i40e_ring *rx_ring,struct i40e_rx_buffer *new_buff;u16 nta = rx_ring->next_to_alloc; - new_buff = &rx_ring->rx_bi[nta]; + new_buff =i40e_rx_bi (rx_ring, nta);/* update, and store next to alloc */ nta++;
@@ -1272,7 +1277,7 @@ struct i40e_rx_buffer *i40e_clean_programming_status( ntc = rx_ring->next_to_clean;/* fetch, update, and store next to clean */ - rx_buffer = &rx_ring->rx_bi[ntc++]; + rx_buffer =i40e_rx_bi (rx_ring, ntc++); ntc = (ntc < rx_ring->count) ? ntc :0 ; rx_ring->next_to_clean = ntc;
@@ -1361,7 +1366,7 @@ void i40e_clean_rx_ring(struct i40e_ring *rx_ring)/* Free all the Rx ring sk_buffs */ for (i =0 ; i < rx_ring->count; i++) { -struct i40e_rx_buffer *rx_bi = &rx_ring->rx_bi[i]; +struct i40e_rx_buffer *rx_bi =i40e_rx_bi (rx_ring, i);if (!rx_bi->page)continue ;
@@ -1592,7 +1597,7 @@ bool i40e_alloc_rx_buffers(struct i40e_ring *rx_ring, u16 cleaned_count)return false; rx_desc =I40E_RX_DESC (rx_ring, ntu); - bi = &rx_ring->rx_bi[ntu]; + bi =i40e_rx_bi (rx_ring, ntu); do { if (!i40e_alloc_mapped_page(rx_ring, bi))
@@ -1614,7 +1619,7 @@ bool i40e_alloc_rx_buffers(struct i40e_ring *rx_ring, u16 cleaned_count) ntu++;if (unlikely (ntu == rx_ring->count)) { rx_desc =I40E_RX_DESC (rx_ring,0 ); - bi = rx_ring->rx_bi; + bi =i40e_rx_bi (rx_ring,0 ); ntu =0 ; }
@@ -1981,7 +1986,7 @@ static struct i40e_rx_buffer *i40e_get_rx_buffer(struct i40e_ring *rx_ring, {struct i40e_rx_buffer *rx_buffer; - rx_buffer = &rx_ring->rx_bi[rx_ring->next_to_clean]; + rx_buffer =i40e_rx_bi (rx_ring, rx_ring->next_to_clean);prefetchw (rx_buffer->page);/* we are reusing so sync this buffer for CPU use */
drivers/net/ethernet/intel/i40e/i40e_xsk.c +12 -6
@@ -9,6 +9,11 @@#include "i40e_txrx_common.h" #include "i40e_xsk.h" +static struct i40e_rx_buffer *i40e_rx_bi (struct i40e_ring *rx_ring,u32 idx) +{ +return &rx_ring->rx_bi[idx]; +} +/** * i40e_xsk_umem_dma_map - DMA maps all UMEM memory for the netdev * @vsi: Current VSI
@@ -321,7 +326,7 @@ __i40e_alloc_rx_buffers_zc(struct i40e_ring *rx_ring, u16 count,bool ok = true; rx_desc =I40E_RX_DESC (rx_ring, ntu); - bi = &rx_ring->rx_bi[ntu]; + bi =i40e_rx_bi (rx_ring, ntu); do { if (!alloc(rx_ring, bi)) { ok = false;
@@ -340,7 +345,7 @@ __i40e_alloc_rx_buffers_zc(struct i40e_ring *rx_ring, u16 count,if (unlikely (ntu == rx_ring->count)) { rx_desc =I40E_RX_DESC (rx_ring,0 ); - bi = rx_ring->rx_bi; + bi =i40e_rx_bi (rx_ring,0 ); ntu =0 ; }
@@ -402,7 +407,7 @@ static struct i40e_rx_buffer *i40e_get_rx_buffer_zc(struct i40e_ring *rx_ring, {struct i40e_rx_buffer *bi; - bi = &rx_ring->rx_bi[rx_ring->next_to_clean]; + bi =i40e_rx_bi (rx_ring, rx_ring->next_to_clean);/* we are reusing so sync this buffer for CPU use */ dma_sync_single_range_for_cpu(rx_ring->dev,
@@ -424,7 +429,8 @@ static struct i40e_rx_buffer *i40e_get_rx_buffer_zc(struct i40e_ring *rx_ring,static void i40e_reuse_rx_buffer_zc (struct i40e_ring *rx_ring,struct i40e_rx_buffer *old_bi) { -struct i40e_rx_buffer *new_bi = &rx_ring->rx_bi[rx_ring->next_to_alloc]; +struct i40e_rx_buffer *new_bi =i40e_rx_bi (rx_ring, + rx_ring->next_to_alloc);u16 nta = rx_ring->next_to_alloc;/* update, and store next to alloc */
@@ -456,7 +462,7 @@ void i40e_zca_free(struct zero_copy_allocator *alloc, unsigned long handle) mask = rx_ring->xsk_umem->chunk_mask; nta = rx_ring->next_to_alloc; - bi = &rx_ring->rx_bi[nta]; + bi =i40e_rx_bi (rx_ring, nta); nta++; rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta :0 ;
@@ -826,7 +832,7 @@ void i40e_xsk_clean_rx_ring(struct i40e_ring *rx_ring)u16 i;for (i =0 ; i < rx_ring->count; i++) { -struct i40e_rx_buffer *rx_bi = &rx_ring->rx_bi[i]; +struct i40e_rx_buffer *rx_bi =i40e_rx_bi (rx_ring, i);if (!rx_bi->addr)continue ;
Signature · 1 line
2.25.1
PATCH v3 7/15 i40e: separate kernel allocated rx_bi rings from AF_XDP rings
In reply to Björn TöpelFrom: Bj?rn T?pel <[email protected]>
Continuing the path to support MEM_TYPE_XSK_BUFF_POOL, the AF_XDP zero-copy/sk_buff rx_bi rings are now separate. Functions to properly allocate the different rings are added as well.
--- drivers/net/ethernet/intel/i40e/i40e_main.c | 7 ++ drivers/net/ethernet/intel/i40e/i40e_txrx.c | 119 +++++++----------- drivers/net/ethernet/intel/i40e/i40e_txrx.h | 22 ++-- .../ethernet/intel/i40e/i40e_txrx_common.h | 40 +++++- drivers/net/ethernet/intel/i40e/i40e_type.h | 5 +- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 74 ++++++----- drivers/net/ethernet/intel/i40e/i40e_xsk.h | 2 + 7 files changed, 142 insertions(+), 127 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +7 -0
@@ -3260,8 +3260,12 @@ static int i40e_configure_rx_ring(struct i40e_ring *ring)if (ring->vsi->type ==I40E_VSI_MAIN )xdp_rxq_info_unreg_mem_model (&ring->xdp_rxq); +kfree (ring->rx_bi); ring->xsk_umem =i40e_xsk_umem (ring);if (ring->xsk_umem) { + ret =i40e_alloc_rx_bi_zc (ring); +if (ret) +return ret; ring->rx_buf_len = ring->xsk_umem->chunk_size_nohr -XDP_PACKET_HEADROOM ;/* For AF_XDP ZC, we disallow packets to span on
@@ -3280,6 +3284,9 @@ static int i40e_configure_rx_ring(struct i40e_ring *ring) ring->queue_index); }else { + ret =i40e_alloc_rx_bi (ring); +if (ret) +return ret; ring->rx_buf_len = vsi->rx_buf_len;if (ring->vsi->type ==I40E_VSI_MAIN ) { ret = xdp_rxq_info_reg_mem_model(&ring->xdp_rxq,
drivers/net/ethernet/intel/i40e/i40e_txrx.c +44 -75
217 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/i40e_txrx.h +11 -11
@@ -296,17 +296,15 @@ struct i40e_tx_buffer {struct i40e_rx_buffer {dma_addr_t dma; -union { -struct { -struct page *page; -__u32 page_offset; -__u16 pagecnt_bias; - }; -struct { -void *addr; -u64 handle; - }; - }; +struct page *page; +__u32 page_offset; +__u16 pagecnt_bias; +}; + +struct i40e_rx_buffer_zc { +dma_addr_t dma; +void *addr; +u64 handle; };struct i40e_queue_stats {
@@ -358,6 +356,7 @@ struct i40e_ring {union {struct i40e_tx_buffer *tx_bi;struct i40e_rx_buffer *rx_bi; +struct i40e_rx_buffer_zc *rx_bi_zc; };DECLARE_BITMAP (state, __I40E_RING_STATE_NBITS);u16 queue_index;/* Queue number of ring */
@@ -495,6 +494,7 @@ int __i40e_maybe_stop_tx(struct i40e_ring *tx_ring, int size);bool __i40e_chk_linearize (struct sk_buff *skb);int i40e_xdp_xmit (struct net_device *dev,int n,struct xdp_frame **frames,u32 flags); +int i40e_alloc_rx_bi (struct i40e_ring *rx_ring);/** * i40e_get_head - Retrieve head from head writeback
drivers/net/ethernet/intel/i40e/i40e_txrx_common.h +34 -6
@@ -4,13 +4,9 @@#ifndef I40E_TXRX_COMMON_ #define I40E_TXRX_COMMON_ -void i40e_fd_handle_status (struct i40e_ring *rx_ring, -union i40e_rx_desc *rx_desc,u8 prog_id);int i40e_xmit_xdp_tx_ring (struct xdp_buff *xdp,struct i40e_ring *xdp_ring); -struct i40e_rx_buffer *i40e_clean_programming_status ( -struct i40e_ring *rx_ring, -union i40e_rx_desc *rx_desc, -u64 qw); +void i40e_clean_programming_status (struct i40e_ring *rx_ring,u64 qword0_raw, +u64 qword1);void i40e_process_skb_fields (struct i40e_ring *rx_ring,union i40e_rx_desc *rx_desc,struct sk_buff *skb);void i40e_xdp_ring_update_tail (struct i40e_ring *xdp_ring);
@@ -84,6 +80,38 @@ static inline void i40e_arm_wb(struct i40e_ring *tx_ring, } } +/** +* i40e_rx_is_programming_status - check for programming status descriptor +* @qword1: qword1 representing status_error_len in CPU ordering +* +* The value of in the descriptor length field indicate if this +* is a programming status descriptor for flow director or FCoE +* by the value of I40E_RX_PROG_STATUS_DESC_LENGTH, otherwise +* it is a packet descriptor. +**/ +static inline bool i40e_rx_is_programming_status (u64 qword1) +{ +/* The Rx filter programming status and SPH bit occupy the same +* spot in the descriptor. Since we don't support packet split we +* can just reuse the bit as an indication that this is a +* programming status descriptor. +*/ +return qword1 &I40E_RXD_QW1_LENGTH_SPH_MASK ; +} + +/** +* i40e_inc_ntc: Advance the next_to_clean index +* @rx_ring: Rx ring +**/ +static inline void i40e_inc_ntc (struct i40e_ring *rx_ring) +{ +u32 ntc = rx_ring->next_to_clean +1 ; + + ntc = (ntc < rx_ring->count) ? ntc :0 ; + rx_ring->next_to_clean = ntc; +prefetch (I40E_RX_DESC (rx_ring, ntc)); +} +void i40e_xsk_clean_rx_ring (struct i40e_ring *rx_ring);void i40e_xsk_clean_tx_ring (struct i40e_ring *tx_ring);bool i40e_xsk_any_rx_ring_enabled (struct i40e_vsi *vsi);
drivers/net/ethernet/intel/i40e/i40e_type.h +4 -1
@@ -689,7 +689,7 @@ union i40e_32byte_rx_desc {__le64 rsvd2; } read; struct { - struct { + struct i40e_32b_rx_wb_qw0 { struct { union { __le16 mirroring_status;
@@ -727,6 +727,9 @@ union i40e_32byte_rx_desc { } hi_dword; } qword3; } wb;/* writeback */ +struct { +u64 qword[4 ]; + } raw; };enum i40e_rx_desc_status_bits {
drivers/net/ethernet/intel/i40e/i40e_xsk.c +40 -34
169 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/i40e_xsk.h +2 -0
@@ -19,5 +19,7 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget);bool i40e_clean_xdp_tx_irq (struct i40e_vsi *vsi,struct i40e_ring *tx_ring,int napi_budget);int i40e_xsk_wakeup (struct net_device *dev,u32 queue_id,u32 flags); +int i40e_alloc_rx_bi_zc (struct i40e_ring *rx_ring); +void i40e_clear_rx_bi_zc (struct i40e_ring *rx_ring);#endif /* _I40E_XSK_H_ */
Signature · 1 line
2.25.1
PATCH v3 8/15 i40e, xsk: migrate to new MEM_TYPE_XSK_BUFF_POOL
In reply to Björn TöpelFrom: Bj?rn T?pel <[email protected]>
Remove MEM_TYPE_ZERO_COPY in favor of the new MEM_TYPE_XSK_BUFF_POOL APIs. The AF_XDP zero-copy rx_bi ring is now simply a struct xdp_buff pointer.
--- drivers/net/ethernet/intel/i40e/i40e_main.c | 19 +- drivers/net/ethernet/intel/i40e/i40e_txrx.h | 9 +- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 352 ++------------------ drivers/net/ethernet/intel/i40e/i40e_xsk.h | 1 - 4 files changed, 47 insertions(+), 334 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +10 -9
@@ -3266,21 +3266,19 @@ static int i40e_configure_rx_ring(struct i40e_ring *ring) ret =i40e_alloc_rx_bi_zc (ring);if (ret)return ret; - ring->rx_buf_len = ring->xsk_umem->chunk_size_nohr - -XDP_PACKET_HEADROOM ; + ring->rx_buf_len =xsk_umem_get_rx_frame_size (ring->xsk_umem);/* For AF_XDP ZC, we disallow packets to span on * multiple buffers, thus letting us skip that * handling in the fast-path. */ chain_len =1 ; - ring->zca.free = i40e_zca_free; ret =xdp_rxq_info_reg_mem_model (&ring->xdp_rxq, -MEM_TYPE_ZERO_COPY , - &ring->zca); +MEM_TYPE_XSK_BUFF_POOL , +NULL );if (ret)return ret;dev_info (&vsi->back->pdev->dev, -"Registered XDP mem model MEM_TYPE_ZERO_COPY on Rx ring %d\n" , +"Registered XDP mem model MEM_TYPE_XSK_BUFF_POOL on Rx ring %d\n" , ring->queue_index); }else {
@@ -3351,9 +3349,12 @@ static int i40e_configure_rx_ring(struct i40e_ring *ring) ring->tail = hw->hw_addr +I40E_QRX_TAIL (pf_q);writel (0 , ring->tail); - ok = ring->xsk_umem ? -i40e_alloc_rx_buffers_zc (ring,I40E_DESC_UNUSED (ring)) : - !i40e_alloc_rx_buffers (ring,I40E_DESC_UNUSED (ring)); +if (ring->xsk_umem) { +xsk_buff_set_rxq_info (ring->xsk_umem, &ring->xdp_rxq); + ok =i40e_alloc_rx_buffers_zc (ring,I40E_DESC_UNUSED (ring)); + }else { + ok = !i40e_alloc_rx_buffers (ring,I40E_DESC_UNUSED (ring)); + }if (!ok) {/* Log this in case the user has forgotten to give the kernel * any buffers, even later in the application.
drivers/net/ethernet/intel/i40e/i40e_txrx.h +1 -8
@@ -301,12 +301,6 @@ struct i40e_rx_buffer {__u16 pagecnt_bias; }; -struct i40e_rx_buffer_zc { -dma_addr_t dma; -void *addr; -u64 handle; -}; -struct i40e_queue_stats {u64 packets;u64 bytes;
@@ -356,7 +350,7 @@ struct i40e_ring {union {struct i40e_tx_buffer *tx_bi;struct i40e_rx_buffer *rx_bi; -struct i40e_rx_buffer_zc *rx_bi_zc; +struct xdp_buff **rx_bi_zc; };DECLARE_BITMAP (state, __I40E_RING_STATE_NBITS);u16 queue_index;/* Queue number of ring */
@@ -418,7 +412,6 @@ struct i40e_ring {struct i40e_channel *ch;struct xdp_rxq_info xdp_rxq;struct xdp_umem *xsk_umem; -struct zero_copy_allocator zca;/* ZC allocator anchor */ }____cacheline_internodealigned_in_smp ;static inline bool ring_uses_build_skb (struct i40e_ring *ring)
drivers/net/ethernet/intel/i40e/i40e_xsk.c +36 -316
491 lines not on this page · raw message
drivers/net/ethernet/intel/i40e/i40e_xsk.h +0 -1
@@ -12,7 +12,6 @@ int i40e_queue_pair_disable(struct i40e_vsi *vsi, int queue_pair);int i40e_queue_pair_enable (struct i40e_vsi *vsi,int queue_pair);int i40e_xsk_umem_setup (struct i40e_vsi *vsi,struct xdp_umem *umem,u16 qid); -void i40e_zca_free (struct zero_copy_allocator *alloc,unsigned long handle);bool i40e_alloc_rx_buffers_zc (struct i40e_ring *rx_ring,u16 cleaned_count);int i40e_clean_rx_irq_zc (struct i40e_ring *rx_ring,int budget);
Signature · 1 line
2.25.1
PATCH v3 9/15 ice, xsk: migrate to new MEM_TYPE_XSK_BUFF_POOL
In reply to Björn TöpelFrom: Bj?rn T?pel <[email protected]>
Remove MEM_TYPE_ZERO_COPY in favor of the new MEM_TYPE_XSK_BUFF_POOL APIs.
--- drivers/net/ethernet/intel/ice/ice_base.c | 16 +- drivers/net/ethernet/intel/ice/ice_txrx.h | 8 +- drivers/net/ethernet/intel/ice/ice_xsk.c | 374 +++------------------- drivers/net/ethernet/intel/ice/ice_xsk.h | 13 +- 4 files changed, 54 insertions(+), 357 deletions(-)
drivers/net/ethernet/intel/ice/ice_base.c +8 -8
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2019, Intel Corporation. */ +#include <net/xdp_sock_drv.h> #include "ice_base.h" #include "ice_dcb_lib.h"
@@ -308,24 +309,23 @@ int ice_setup_rx_ctx(struct ice_ring *ring)if (ring->xsk_umem) {xdp_rxq_info_unreg_mem_model (&ring->xdp_rxq); - ring->rx_buf_len = ring->xsk_umem->chunk_size_nohr - -XDP_PACKET_HEADROOM ; + ring->rx_buf_len = +xsk_umem_get_rx_frame_size (ring->xsk_umem);/* For AF_XDP ZC, we disallow packets to span on * multiple buffers, thus letting us skip that * handling in the fast-path. */ chain_len =1 ; - ring->zca.free = ice_zca_free; err =xdp_rxq_info_reg_mem_model (&ring->xdp_rxq, -MEM_TYPE_ZERO_COPY , - &ring->zca); +MEM_TYPE_XSK_BUFF_POOL , +NULL );if (err)return err; +xsk_buff_set_rxq_info (ring->xsk_umem, &ring->xdp_rxq); -dev_info (ice_pf_to_dev (vsi->back),"Registered XDP mem model MEM_TYPE_ZERO_COPY on Rx ring %d\n" , +dev_info (ice_pf_to_dev (vsi->back),"Registered XDP mem model MEM_TYPE_XSK_BUFF_POOL on Rx ring %d\n" , ring->q_index); }else { - ring->zca.free =NULL ;if (!xdp_rxq_info_is_reg (&ring->xdp_rxq))/* coverity[check_return] */ xdp_rxq_info_reg(&ring->xdp_rxq,
@@ -426,7 +426,7 @@ int ice_setup_rx_ctx(struct ice_ring *ring)writel (0 , ring->tail); err = ring->xsk_umem ? -ice_alloc_rx_bufs_slow_zc (ring,ICE_DESC_UNUSED (ring)) : +ice_alloc_rx_bufs_zc (ring,ICE_DESC_UNUSED (ring)) :ice_alloc_rx_bufs (ring,ICE_DESC_UNUSED (ring));if (err) dev_info(ice_pf_to_dev(vsi->back), "Failed allocate some buffers on %sRx ring %d (pf_q %d)\n",
drivers/net/ethernet/intel/ice/ice_txrx.h +3 -5
@@ -155,17 +155,16 @@ struct ice_tx_offload_params { };struct ice_rx_buf { -struct sk_buff *skb; -dma_addr_t dma;union {struct { +struct sk_buff *skb; +dma_addr_t dma;struct page *page;unsigned int page_offset;u16 pagecnt_bias; };struct { -void *addr; -u64 handle; +struct xdp_buff *xdp; }; }; };
@@ -289,7 +288,6 @@ struct ice_ring {struct rcu_head rcu;/* to avoid race on free */ struct bpf_prog *xdp_prog;struct xdp_umem *xsk_umem; -struct zero_copy_allocator zca;/* CL3 - 3rd cacheline starts here */ struct xdp_rxq_info xdp_rxq;/* CLX - the below items are only accessed infrequently and should be
drivers/net/ethernet/intel/ice/ice_xsk.c +40 -334
514 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_xsk.h +3 -10
@@ -10,11 +10,10 @@ struct ice_vsi;#ifdef CONFIG_XDP_SOCKETS int ice_xsk_umem_setup (struct ice_vsi *vsi,struct xdp_umem *umem,u16 qid); -void ice_zca_free (struct zero_copy_allocator *zca,unsigned long handle);int ice_clean_rx_irq_zc (struct ice_ring *rx_ring,int budget);bool ice_clean_tx_irq_zc (struct ice_ring *xdp_ring,int budget);int ice_xsk_wakeup (struct net_device *netdev,u32 queue_id,u32 flags); -bool ice_alloc_rx_bufs_slow_zc (struct ice_ring *rx_ring,u16 count); +bool ice_alloc_rx_bufs_zc (struct ice_ring *rx_ring,u16 count);bool ice_xsk_any_rx_ring_ena (struct ice_vsi *vsi);void ice_xsk_clean_rx_ring (struct ice_ring *rx_ring);void ice_xsk_clean_xdp_ring (struct ice_ring *xdp_ring);
@@ -27,12 +26,6 @@ ice_xsk_umem_setup(struct ice_vsi __always_unused *vsi,return -EOPNOTSUPP ; } -static inline void -ice_zca_free (struct zero_copy_allocator __always_unused *zca, -unsigned long __always_unused handle) -{ -} -static inline int ice_clean_rx_irq_zc (struct ice_ring __always_unused *rx_ring,int __always_unused budget)
@@ -48,8 +41,8 @@ ice_clean_tx_irq_zc(struct ice_ring __always_unused *xdp_ring, }static inline bool -ice_alloc_rx_bufs_slow_zc (struct ice_ring __always_unused *rx_ring, -u16 __always_unused count) +ice_alloc_rx_bufs_zc (struct ice_ring __always_unused *rx_ring, +u16 __always_unused count) {return false; }
Signature · 1 line
2.25.1
PATCH v3 10/15 ixgbe, xsk: migrate to new MEM_TYPE_XSK_BUFF_POOL
In reply to Björn TöpelFrom: Bj?rn T?pel <[email protected]>
Remove MEM_TYPE_ZERO_COPY in favor of the new MEM_TYPE_XSK_BUFF_POOL APIs.
v1->v2: Fixed xdp_buff data_end update. (Bj?rn)
--- drivers/net/ethernet/intel/ixgbe/ixgbe.h | 9 +- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 15 +- .../ethernet/intel/ixgbe/ixgbe_txrx_common.h | 2 +- drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 307 +++--------------- 4 files changed, 62 insertions(+), 271 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe.h +4 -5
@@ -224,17 +224,17 @@ struct ixgbe_tx_buffer { };struct ixgbe_rx_buffer { -struct sk_buff *skb; -dma_addr_t dma;union {struct { +struct sk_buff *skb; +dma_addr_t dma;struct page *page;__u32 page_offset;__u16 pagecnt_bias; };struct { -void *addr; -u64 handle; +bool discard; +struct xdp_buff *xdp; }; }; };
@@ -351,7 +351,6 @@ struct ixgbe_ring { };struct xdp_rxq_info xdp_rxq;struct xdp_umem *xsk_umem; -struct zero_copy_allocator zca;/* ZC allocator anchor */ u16 ring_idx;/* {rx,tx,xdp}_ring back reference idx */ u16 rx_buf_len; }____cacheline_internodealigned_in_smp ;
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +6 -9
@@ -35,7 +35,7 @@#include <net/tc_act/tc_mirred.h> #include <net/vxlan.h> #include <net/mpls.h> -#include <net/xdp_sock.h> +#include <net/xdp_sock_drv.h> #include <net/xfrm.h> #include "ixgbe.h"
@@ -3745,8 +3745,7 @@ static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,/* configure the packet buffer length */ if (rx_ring->xsk_umem) { -u32 xsk_buf_len = rx_ring->xsk_umem->chunk_size_nohr - -XDP_PACKET_HEADROOM ; +u32 xsk_buf_len =xsk_umem_get_rx_frame_size (rx_ring->xsk_umem);/* If the MAC support setting RXDCTL.RLPML, the * SRRCTL[n].BSIZEPKT is set to PAGE_SIZE and
@@ -4093,11 +4092,10 @@ void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,xdp_rxq_info_unreg_mem_model (&ring->xdp_rxq); ring->xsk_umem =ixgbe_xsk_umem (adapter, ring);if (ring->xsk_umem) { - ring->zca.free = ixgbe_zca_free;WARN_ON (xdp_rxq_info_reg_mem_model (&ring->xdp_rxq, -MEM_TYPE_ZERO_COPY , - &ring->zca)); - +MEM_TYPE_XSK_BUFF_POOL , +NULL )); +xsk_buff_set_rxq_info (ring->xsk_umem, &ring->xdp_rxq); }else {WARN_ON (xdp_rxq_info_reg_mem_model (&ring->xdp_rxq,MEM_TYPE_PAGE_SHARED ,NULL ));
@@ -4153,8 +4151,7 @@ void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, }if (ring->xsk_umem && hw->mac.type != ixgbe_mac_82599EB) { -u32 xsk_buf_len = ring->xsk_umem->chunk_size_nohr - -XDP_PACKET_HEADROOM ; +u32 xsk_buf_len =xsk_umem_get_rx_frame_size (ring->xsk_umem); rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK |IXGBE_RXDCTL_RLPML_EN );
drivers/net/ethernet/intel/ixgbe/ixgbe_txrx_common.h +1 -1
@@ -35,7 +35,7 @@ int ixgbe_xsk_umem_setup(struct ixgbe_adapter *adapter, struct xdp_umem *umem,void ixgbe_zca_free (struct zero_copy_allocator *alloc,unsigned long handle); -void ixgbe_alloc_rx_buffers_zc (struct ixgbe_ring *rx_ring,u16 cleaned_count); +bool ixgbe_alloc_rx_buffers_zc (struct ixgbe_ring *rx_ring,u16 cleaned_count);int ixgbe_clean_rx_irq_zc (struct ixgbe_q_vector *q_vector,struct ixgbe_ring *rx_ring,const int budget);
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c +51 -256
460 lines not on this page · raw message
Signature · 1 line
2.25.1
v3 cover Introduce AF_XDP buffer allocation API
Overview
========
Driver adoption for AF_XDP has been slow. The amount of code required to proper support AF_XDP is substantial and the driver/core APIs are vague or even non-existing. Drivers have to manually adjust data offsets, updating AF_XDP handles differently for different modes (aligned/unaligned).
This series attempts to improve the situation by introducing an AF_XDP buffer allocation API. The implementation is based on a single core (single producer/consumer) buffer pool for the AF_XDP UMEM.
A buffer is allocated using the xsk_buff_alloc() function, and returned using xsk_buff_free(). If a buffer is disassociated with the pool, e.g. when a buffer is passed to an AF_XDP socket, a buffer is said to be released. Currently, the release function is only used by the AF_XDP internals and not visible to the driver.
Drivers using this API should register the XDP memory model with the new MEM_TYPE_XSK_BUFF_POOL type, which will supersede the MEM_TYPE_ZERO_COPY type.
The buffer type is struct xdp_buff, and follows the lifetime of regular xdp_buffs, i.e. the lifetime of an xdp_buff is restricted to a NAPI context. In other words, the API is not replacing xdp_frames.
DMA mapping/synching is folded into the buffer handling as well.
@JeffK The Intel drivers changes should go through the bpf-next tree,
and not your regular Intel tree, since multiple (non-Intel) drivers are affected.
The outline of the series is as following:
Patch 1 is a fix for xsk_umem_xdp_frame_sz().
Patch 2 to 4 are restructures/clean ups. The XSKMAP implementation is moved to net/xdp/. Functions/defines/enums that are only used by the AF_XDP internals are moved from the global include/net/xdp_sock.h to net/xdp/xsk.h. We are also introducing a new "driver include file", include/net/xdp_sock_drv.h, which is the only file NIC driver developers adding AF_XDP zero-copy support should care about.
Patch 5 adds the new API, and migrates the "copy-mode"/skb-mode AF_XDP path to the new API.
Patch 6 to 11 migrates the existing zero-copy drivers to the new API.
Patch 12 removes the MEM_TYPE_ZERO_COPY memory type, and the "handle" member of struct xdp_buff.
Patch 13 simplifies the xdp_return_{frame,frame_rx_napi,buff} functions.
Patch 14 is a performance patch, where some functions are inlined.
Finally, patch 15 updates the MAINTAINERS file to correctly mirror the new file layout.
Note that this series removes the "handle" member from struct xdp_buff, which reduces the xdp_buff size.
After this series, the diff stat of drivers/net/ is:
27 files changed, 390 insertions(+), 1270 deletions(-)
This series is a first step of simplifying the driver side of AF_XDP. I think more of the AF_XDP logic can be moved from the drivers to the AF_XDP core, e.g. the "need wakeup" set/clear functionality.
Statistics when allocation fails can now be added to the socket statistics via the XDP_STATISTICS getsockopt(). This will be added in a follow up series.
Performance
===========
As a nice side effect, performance is up a bit as well.
* i40e: 3% higher pps for rxdrop, zero-copy, aligned and unaligned
(40 GbE, 64B packets).
* mlx5: RX +0.8 Mpps, TX +0.4 Mpps
Changelog
=========
v2->v3:
* Added xsk_umem_xdp_frame_sz() fix to the series. (Björn)
* Initialize struct xdp_buff member frame_sz. (Björn)
* Add API to query the DMA address of a frame. (Maxim)
* Do DMA sync for CPU till the end of the frame to handle possible growth (frame_sz). (Maxim)
* mlx5: Handle frame_sz, use xsk_buff_xdp_get_frame_dma, use xsk_buff API for DMA sync on TX, add performance numbers. (Maxim)
v1->v2:
* mlx5: Fix DMA address handling, set XDP metadata to invalid. (Maxim)
* ixgbe: Fixed xdp_buff data_end update. (Björn)
* Swapped SoBs in patch 4. (Maxim)
rfc->v1:
* Fixed build errors/warnings for m68k and riscv. (kbuild test robot)
* Added headroom/chunk size getter. (Maxim/Björn)
* mlx5: Put back the sanity check for XSK params, use XSK API to get the total headroom size. (Maxim)
* Fixed spelling in commit message. (Björn)
* Make sure xp_validate_desc() is inlined for Tx perf. (Maxim)
* Sorted file entries. (Joe)
* Added xdp_return_{frame,frame_rx_napi,buff} simplification (Björn)
Thanks for all the comments/input/help!
Cheers,
Björn
Björn Töpel (14):
xsk: fix xsk_umem_xdp_frame_sz()
xsk: move xskmap.c to net/xdp/
xsk: move defines only used by AF_XDP internals to xsk.h
xsk: introduce AF_XDP buffer allocation API
i40e: refactor rx_bi accesses
i40e: separate kernel allocated rx_bi rings from AF_XDP rings i40e, xsk: migrate to new MEM_TYPE_XSK_BUFF_POOL ice, xsk: migrate to new MEM_TYPE_XSK_BUFF_POOL ixgbe, xsk: migrate to new MEM_TYPE_XSK_BUFF_POOL mlx5, xsk: migrate to new MEM_TYPE_XSK_BUFF_POOL
xsk: remove MEM_TYPE_ZERO_COPY and corresponding code
xdp: simplify xdp_return_{frame,frame_rx_napi,buff}
xsk: explicitly inline functions and move definitions MAINTAINERS, xsk: update AF_XDP section after moves/adds
Magnus Karlsson (1):
xsk: move driver interface to xdp_sock_drv.h
MAINTAINERS | 6 +-
drivers/net/ethernet/intel/i40e/i40e_main.c | 28 +-
drivers/net/ethernet/intel/i40e/i40e_txrx.c | 134 +++----
drivers/net/ethernet/intel/i40e/i40e_txrx.h | 17 +-
.../ethernet/intel/i40e/i40e_txrx_common.h | 40 +-
drivers/net/ethernet/intel/i40e/i40e_type.h | 5 +-
drivers/net/ethernet/intel/i40e/i40e_xsk.c | 378 +++---------------
drivers/net/ethernet/intel/i40e/i40e_xsk.h | 3 +-
drivers/net/ethernet/intel/ice/ice_base.c | 16 +-
drivers/net/ethernet/intel/ice/ice_txrx.h | 8 +-
drivers/net/ethernet/intel/ice/ice_xsk.c | 376 ++---------------
drivers/net/ethernet/intel/ice/ice_xsk.h | 13 +-
drivers/net/ethernet/intel/ixgbe/ixgbe.h | 9 +-
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 15 +-
.../ethernet/intel/ixgbe/ixgbe_txrx_common.h | 2 +-
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 309 +++-----------
drivers/net/ethernet/mellanox/mlx5/core/en.h | 7 +-
.../ethernet/mellanox/mlx5/core/en/params.c | 13 +-
.../net/ethernet/mellanox/mlx5/core/en/xdp.c | 33 +-
.../net/ethernet/mellanox/mlx5/core/en/xdp.h | 2 +-
.../ethernet/mellanox/mlx5/core/en/xsk/rx.c | 113 +-----
.../ethernet/mellanox/mlx5/core/en/xsk/rx.h | 25 +-
.../ethernet/mellanox/mlx5/core/en/xsk/tx.c | 9 +-
.../ethernet/mellanox/mlx5/core/en/xsk/tx.h | 2 +-
.../ethernet/mellanox/mlx5/core/en/xsk/umem.c | 51 +--
.../net/ethernet/mellanox/mlx5/core/en_main.c | 17 +-
.../net/ethernet/mellanox/mlx5/core/en_rx.c | 34 +-
drivers/net/hyperv/netvsc_bpf.c | 1 -
include/net/xdp.h | 9 +-
include/net/xdp_sock.h | 287 +------------
include/net/xdp_sock_drv.h | 232 +++++++++++
include/net/xsk_buff_pool.h | 140 +++++++
include/trace/events/xdp.h | 2 +-
kernel/bpf/Makefile | 3 -
net/core/xdp.c | 51 +--
net/ethtool/channels.c | 2 +-
net/ethtool/ioctl.c | 2 +-
net/xdp/Makefile | 3 +-
net/xdp/xdp_umem.c | 55 +--
net/xdp/xdp_umem.h | 2 +-
net/xdp/xsk.c | 204 ++++------
net/xdp/xsk.h | 30 ++
net/xdp/xsk_buff_pool.c | 336 ++++++++++++++++
net/xdp/xsk_diag.c | 2 +-
net/xdp/xsk_queue.c | 62 ---
net/xdp/xsk_queue.h | 117 ++----
{kernel/bpf => net/xdp}/xskmap.c | 2 +
47 files changed, 1278 insertions(+), 1929 deletions(-)
create mode 100644 include/net/xdp_sock_drv.h
create mode 100644 include/net/xsk_buff_pool.h
create mode 100644 net/xdp/xsk_buff_pool.c
rename {kernel/bpf => net/xdp}/xskmap.c (99%)Signature · 1 line
2.25.1
PATCH v3 1/15 xsk: fix xsk_umem_xdp_frame_sz()
From: Björn Töpel <[email protected]>
Calculating the "data_hard_end" for an XDP buffer coming from AF_XDP zero-copy mode, the return value of xsk_umem_xdp_frame_sz() is added to "data_hard_start".
Currently, the chunk size of the UMEM is returned by xsk_umem_xdp_frame_sz(). This is not correct, if the fixed UMEM headroom is non-zero. Fix this by returning the chunk_size without the UMEM headroom.
--- include/net/xdp_sock.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/xdp_sock.h +1 -1
@@ -239,7 +239,7 @@ static inline u64 xsk_umem_adjust_offset(struct xdp_umem *umem, u64 address,static inline u32 xsk_umem_xdp_frame_sz (struct xdp_umem *umem) { -return umem->chunk_size_nohr + umem->headroom; +return umem->chunk_size_nohr; }#else
Signature · 1 line
2.25.1
PATCH v3 2/15 xsk: move xskmap.c to net/xdp/
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
The XSKMAP is partly implemented by net/xdp/xsk.c. Move xskmap.c from kernel/bpf/ to net/xdp/, which is the logical place for AF_XDP related code. Also, move AF_XDP struct definitions, and function declarations only used by AF_XDP internals into net/xdp/xsk.h.
---
include/net/xdp_sock.h | 20 --------------------
kernel/bpf/Makefile | 3 ---
net/xdp/Makefile | 2 +-
net/xdp/xsk.h | 16 ++++++++++++++++
{kernel/bpf => net/xdp}/xskmap.c | 2 ++
5 files changed, 19 insertions(+), 24 deletions(-)
rename {kernel/bpf => net/xdp}/xskmap.c (99%)include/net/xdp_sock.h +0 -20
@@ -65,22 +65,12 @@ struct xdp_umem {struct list_head xsk_tx_list; }; -/* Nodes are linked in the struct xdp_sock map_list field, and used to -* track which maps a certain socket reside in. -*/ -struct xsk_map {struct bpf_map map;spinlock_t lock;/* Synchronize map updates */ struct xdp_sock *xsk_map[]; }; -struct xsk_map_node { -struct list_head node; -struct xsk_map *map; -struct xdp_sock **map_entry; -}; -struct xdp_sock {/* struct sock must be the first member of struct xdp_sock */ struct sock sk;
@@ -114,7 +104,6 @@ struct xdp_sock {struct xdp_buff ;#ifdef CONFIG_XDP_SOCKETS int xsk_generic_rcv (struct xdp_sock *xs,struct xdp_buff *xdp); -bool xsk_is_setup_for_bpf_map (struct xdp_sock *xs);/* Used from netdev driver */ bool xsk_umem_has_addrs (struct xdp_umem *umem,u32 cnt);bool xsk_umem_peek_addr (struct xdp_umem *umem,u64 *addr);
@@ -133,10 +122,6 @@ void xsk_clear_rx_need_wakeup(struct xdp_umem *umem);void xsk_clear_tx_need_wakeup (struct xdp_umem *umem);bool xsk_umem_uses_need_wakeup (struct xdp_umem *umem); -void xsk_map_try_sock_delete (struct xsk_map *map,struct xdp_sock *xs, -struct xdp_sock **map_entry); -int xsk_map_inc (struct xsk_map *map); -void xsk_map_put (struct xsk_map *map);int __xsk_map_redirect (struct xdp_sock *xs,struct xdp_buff *xdp);void __xsk_map_flush (void );
@@ -248,11 +233,6 @@ static inline int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)return -ENOTSUPP ; } -static inline bool xsk_is_setup_for_bpf_map (struct xdp_sock *xs) -{ -return false; -} -static inline bool xsk_umem_has_addrs (struct xdp_umem *umem,u32 cnt) {return false;
kernel/bpf/Makefile +0 -3
@@ -12,9 +12,6 @@ obj-$(CONFIG_BPF_JIT) += dispatcher.o ifeq ($(CONFIG_NET),y) obj-$(CONFIG_BPF_SYSCALL) += devmap.o obj-$(CONFIG_BPF_SYSCALL) += cpumap.o -ifeq ($(CONFIG_XDP_SOCKETS),y) -obj-$(CONFIG_BPF_SYSCALL) += xskmap.o -endif obj-$(CONFIG_BPF_SYSCALL) += offload.o endif ifeq ($(CONFIG_PERF_EVENTS),y)
net/xdp/Makefile +1 -1
@@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-$(CONFIG_XDP_SOCKETS) += xsk.o xdp_umem.o xsk_queue.o +obj-$(CONFIG_XDP_SOCKETS) += xsk.o xdp_umem.o xsk_queue.o xskmap.o obj-$(CONFIG_XDP_SOCKETS_DIAG) += xsk_diag.o
net/xdp/xsk.h +16 -0
@@ -17,9 +17,25 @@ struct xdp_mmap_offsets_v1 { struct xdp_ring_offset_v1 cr; }; +/* Nodes are linked in the struct xdp_sock map_list field, and used to +* track which maps a certain socket reside in. +*/ + +struct xsk_map_node { +struct list_head node; +struct xsk_map *map; +struct xdp_sock **map_entry; +}; +static inline struct xdp_sock *xdp_sk (struct sock *sk) {return (struct xdp_sock *)sk; } +bool xsk_is_setup_for_bpf_map (struct xdp_sock *xs); +void xsk_map_try_sock_delete (struct xsk_map *map,struct xdp_sock *xs, +struct xdp_sock **map_entry); +int xsk_map_inc (struct xsk_map *map); +void xsk_map_put (struct xsk_map *map); +#endif /* XSK_H_ */
net/xdp/xskmap.c renamed from kernel/bpf/xskmap.c +2 -0
@@ -9,6 +9,8 @@#include <linux/slab.h> #include <linux/sched.h> +#include "xsk.h" +int xsk_map_inc (struct xsk_map *map) {bpf_map_inc (&map->map);
Signature · 1 line
2.25.1
PATCH v3 3/15 xsk: move driver interface to xdp_sock_drv.h
In reply to Björn TöpelFrom: Magnus Karlsson <[email protected]>
Move the AF_XDP zero-copy driver interface to its own include file called xdp_sock_drv.h. This, hopefully, will make it more clear for NIC driver implementors to know what functions to use for zero-copy support.
--- drivers/net/ethernet/intel/i40e/i40e_main.c | 2 +- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 2 +- drivers/net/ethernet/intel/ice/ice_xsk.c | 2 +- drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 2 +- .../net/ethernet/mellanox/mlx5/core/en/xdp.c | 2 +- .../ethernet/mellanox/mlx5/core/en/xsk/rx.h | 2 +- .../ethernet/mellanox/mlx5/core/en/xsk/tx.h | 2 +- .../ethernet/mellanox/mlx5/core/en/xsk/umem.c | 2 +- include/net/xdp_sock.h | 214 +---------------- include/net/xdp_sock_drv.h | 217 ++++++++++++++++++ net/ethtool/channels.c | 2 +- net/ethtool/ioctl.c | 2 +- net/xdp/xdp_umem.h | 2 +- net/xdp/xsk.c | 2 +- 14 files changed, 237 insertions(+), 218 deletions(-) create mode 100644 include/net/xdp_sock_drv.h
drivers/net/ethernet/intel/i40e/i40e_main.c +1 -1
@@ -11,7 +11,7 @@#include "i40e_diag.h" #include "i40e_xsk.h" #include <net/udp_tunnel.h> -#include <net/xdp_sock.h> +#include <net/xdp_sock_drv.h> /* All i40e tracepoints are defined by the include below, which * must be included exactly once across the whole kernel with * CREATE_TRACE_POINTS defined
drivers/net/ethernet/intel/i40e/i40e_xsk.c +1 -1
@@ -2,7 +2,7 @@/* Copyright(c) 2018 Intel Corporation. */ #include <linux/bpf_trace.h> -#include <net/xdp_sock.h> +#include <net/xdp_sock_drv.h> #include <net/xdp.h> #include "i40e.h"
drivers/net/ethernet/intel/ice/ice_xsk.c +1 -1
@@ -2,7 +2,7 @@/* Copyright (c) 2019, Intel Corporation. */ #include <linux/bpf_trace.h> -#include <net/xdp_sock.h> +#include <net/xdp_sock_drv.h> #include <net/xdp.h> #include "ice.h" #include "ice_base.h"
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c +1 -1
@@ -2,7 +2,7 @@/* Copyright(c) 2018 Intel Corporation. */ #include <linux/bpf_trace.h> -#include <net/xdp_sock.h> +#include <net/xdp_sock_drv.h> #include <net/xdp.h> #include "ixgbe.h"
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c +1 -1
@@ -31,7 +31,7 @@*/ #include <linux/bpf_trace.h> -#include <net/xdp_sock.h> +#include <net/xdp_sock_drv.h> #include "en/xdp.h" #include "en/params.h"
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.h +1 -1
@@ -5,7 +5,7 @@#define __MLX5_EN_XSK_RX_H__#include "en.h" -#include <net/xdp_sock.h> +#include <net/xdp_sock_drv.h> /* RX data path */
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/tx.h +1 -1
@@ -5,7 +5,7 @@#define __MLX5_EN_XSK_TX_H__#include "en.h" -#include <net/xdp_sock.h> +#include <net/xdp_sock_drv.h> /* TX data path */
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/umem.c +1 -1
@@ -1,7 +1,7 @@// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB /* Copyright (c) 2019 Mellanox Technologies. */ -#include <net/xdp_sock.h> +#include <net/xdp_sock_drv.h> #include "umem.h" #include "setup.h" #include "en/params.h"
include/net/xdp_sock.h +8 -206
252 lines not on this page · raw message
include/net/xdp_sock_drv.h new file +217 -0
217 lines not on this page · raw message
net/ethtool/channels.c +1 -1
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0-only -#include <net/xdp_sock.h> +#include <net/xdp_sock_drv.h> #include "netlink.h" #include "common.h"
net/ethtool/ioctl.c +1 -1
@@ -24,7 +24,7 @@#include <linux/sched/signal.h> #include <linux/net.h> #include <net/devlink.h> -#include <net/xdp_sock.h> +#include <net/xdp_sock_drv.h> #include <net/flow_offload.h> #include <linux/ethtool_netlink.h> #include <generated/utsrelease.h>
net/xdp/xdp_umem.h +1 -1
@@ -6,7 +6,7 @@#ifndef XDP_UMEM_H_ #define XDP_UMEM_H_ -#include <net/xdp_sock.h> +#include <net/xdp_sock_drv.h> int xdp_umem_assign_dev (struct xdp_umem *umem,struct net_device *dev,u16 queue_id,u16 flags);
net/xdp/xsk.c +1 -1
@@ -22,7 +22,7 @@#include <linux/net.h> #include <linux/netdevice.h> #include <linux/rculist.h> -#include <net/xdp_sock.h> +#include <net/xdp_sock_drv.h> #include <net/xdp.h> #include "xsk_queue.h"
Signature · 1 line
2.25.1
PATCH v3 4/15 xsk: move defines only used by AF_XDP internals to xsk.h
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
Move the XSK_NEXT_PG_CONTIG_{MASK,SHIFT}, and XDP_UMEM_USES_NEED_WAKEUP defines from xdp_sock.h to the AF_XDP internal xsk.h file. Also, start using the BIT{,_ULL} macro instead of explicit shifts.
--- include/net/xdp_sock.h | 14 -------------- net/xdp/xsk.h | 14 ++++++++++++++ net/xdp/xsk_queue.h | 2 ++ 3 files changed, 16 insertions(+), 14 deletions(-)
include/net/xdp_sock.h +0 -14
@@ -17,13 +17,6 @@ struct net_device;struct xsk_queue ;struct xdp_buff ; -/* Masks for xdp_umem_page flags. -* The low 12-bits of the addr will be 0 since this is the page address, so we -* can use them for flags. -*/ -#define XSK_NEXT_PG_CONTIG_SHIFT 0 -#define XSK_NEXT_PG_CONTIG_MASK (1ULL << XSK_NEXT_PG_CONTIG_SHIFT) -struct xdp_umem_page {void *addr;dma_addr_t dma;
@@ -35,13 +28,6 @@ struct xdp_umem_fq_reuse {u64 handles[]; }; -/* Flags for the umem flags field. -* -* The NEED_WAKEUP flag is 1 due to the reuse of the flags field for public -* flags. See inlude/uapi/include/linux/if_xdp.h. -*/ -#define XDP_UMEM_USES_NEED_WAKEUP (1 << 1) -struct xdp_umem {struct xsk_queue *fq;struct xsk_queue *cq;
net/xdp/xsk.h +14 -0
@@ -4,6 +4,20 @@ #ifndef XSK_H_ #define XSK_H_ +/* Masks for xdp_umem_page flags. + * The low 12-bits of the addr will be 0 since this is the page address, so we + * can use them for flags. + */ +#define XSK_NEXT_PG_CONTIG_SHIFT 0 +#define XSK_NEXT_PG_CONTIG_MASK BIT_ULL(XSK_NEXT_PG_CONTIG_SHIFT) + +/* Flags for the umem flags field. + * + * The NEED_WAKEUP flag is 1 due to the reuse of the flags field for public + * flags. See inlude/uapi/include/linux/if_xdp.h. + */ +#define XDP_UMEM_USES_NEED_WAKEUP BIT(1) + struct xdp_ring_offset_v1 { __u64 producer; __u64 consumer;
net/xdp/xsk_queue.h +2 -0
@@ -10,6 +10,8 @@#include <linux/if_xdp.h> #include <net/xdp_sock.h> +#include "xsk.h" +struct xdp_ring {u32 producer____cacheline_aligned_in_smp ;u32 consumer____cacheline_aligned_in_smp ;
Signature · 1 line
2.25.1
PATCH v3 5/15 xsk: introduce AF_XDP buffer allocation API
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
In order to simplify AF_XDP zero-copy enablement for NIC driver developers, a new AF_XDP buffer allocation API is added. The implementation is based on a single core (single producer/consumer) buffer pool for the AF_XDP UMEM.
A buffer is allocated using the xsk_buff_alloc() function, and returned using xsk_buff_free(). If a buffer is disassociated with the pool, e.g. when a buffer is passed to an AF_XDP socket, a buffer is said to be released. Currently, the release function is only used by the AF_XDP internals and not visible to the driver.
Drivers using this API should register the XDP memory model with the new MEM_TYPE_XSK_BUFF_POOL type.
The API is defined in net/xdp_sock_drv.h.
The buffer type is struct xdp_buff, and follows the lifetime of regular xdp_buffs, i.e. the lifetime of an xdp_buff is restricted to a NAPI context. In other words, the API is not replacing xdp_frames.
In addition to introducing the API and implementations, the AF_XDP core is migrated to use the new APIs.
rfc->v1: Fixed build errors/warnings for m68k and riscv. (kbuild test
robot)
Added headroom/chunk size getter. (Maxim/Björn)
v1->v2: Swapped SoBs. (Maxim)
v2->v3: Initialize struct xdp_buff member frame_sz. (Björn)
Add API to query the DMA address of a frame. (Maxim) Do DMA sync for CPU till the end of the frame to handle possible growth (frame_sz). (Maxim)
--- include/net/xdp.h | 4 +- include/net/xdp_sock.h | 2 + include/net/xdp_sock_drv.h | 164 +++++++++++++ include/net/xsk_buff_pool.h | 56 +++++ include/trace/events/xdp.h | 3 +- net/core/xdp.c | 14 +- net/xdp/Makefile | 1 + net/xdp/xdp_umem.c | 19 +- net/xdp/xsk.c | 147 +++++------- net/xdp/xsk_buff_pool.c | 467 ++++++++++++++++++++++++++++++++++++ net/xdp/xsk_diag.c | 2 +- net/xdp/xsk_queue.h | 59 +++-- 12 files changed, 819 insertions(+), 119 deletions(-) create mode 100644 include/net/xsk_buff_pool.h create mode 100644 net/xdp/xsk_buff_pool.c
include/net/xdp.h +3 -1
@@ -40,6 +40,7 @@ enum xdp_mem_type {MEM_TYPE_PAGE_ORDER0 ,/* Orig XDP full page model */ MEM_TYPE_PAGE_POOL ,MEM_TYPE_ZERO_COPY , +MEM_TYPE_XSK_BUFF_POOL , MEM_TYPE_MAX, };
@@ -119,7 +120,8 @@ struct xdp_frame *convert_to_xdp_frame(struct xdp_buff *xdp)int metasize;int headroom; -if (xdp->rxq->mem.type ==MEM_TYPE_ZERO_COPY ) +if (xdp->rxq->mem.type ==MEM_TYPE_ZERO_COPY || + xdp->rxq->mem.type ==MEM_TYPE_XSK_BUFF_POOL )return xdp_convert_zc_to_xdp_frame (xdp);/* Assure headroom is available for storing info */
include/net/xdp_sock.h +2 -0
@@ -31,11 +31,13 @@ struct xdp_umem_fq_reuse {struct xdp_umem {struct xsk_queue *fq;struct xsk_queue *cq; +struct xsk_buff_pool *pool;struct xdp_umem_page *pages;u64 chunk_mask;u64 size;u32 headroom;u32 chunk_size_nohr; +u32 chunk_size;struct user_struct *user;refcount_t users;struct work_struct work;
include/net/xdp_sock_drv.h +164 -0
182 lines not on this page · raw message
include/net/xsk_buff_pool.h new file +56 -0
56 lines not on this page · raw message
include/trace/events/xdp.h +2 -1
@@ -287,7 +287,8 @@ TRACE_EVENT(xdp_devmap_xmit, FN(PAGE_SHARED) \ FN(PAGE_ORDER0) \ FN(PAGE_POOL) \ - FN(ZERO_COPY) + FN(ZERO_COPY) \ + FN(XSK_BUFF_POOL) #define __MEM_TYPE_TP_FN(x) \ TRACE_DEFINE_ENUM(MEM_TYPE_##x);
net/core/xdp.c +10 -4
@@ -17,6 +17,7 @@#include <net/xdp.h> #include <net/xdp_priv.h> /* struct xdp_mem_allocator */ #include <trace/events/xdp.h> +#include <net/xdp_sock_drv.h> #define REG_STATE_NEW 0x0#define REG_STATE_REGISTERED 0x1
@@ -361,7 +362,7 @@ EXPORT_SYMBOL_GPL(xdp_rxq_info_reg_mem_model);* of xdp_frames/pages in those cases. */ static void __xdp_return (void *data,struct xdp_mem_info *mem,bool napi_direct, -unsigned long handle) +unsigned long handle,struct xdp_buff *xdp) {struct xdp_mem_allocator *xa;struct page *page;
@@ -390,6 +391,11 @@ static void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct, xa =rhashtable_lookup (mem_id_ht, &mem->id, mem_id_rht_params); xa->zc_alloc->free (xa->zc_alloc, handle);rcu_read_unlock (); +break ; +case MEM_TYPE_XSK_BUFF_POOL : +/* NB! Only valid from an xdp_buff! */ +xsk_buff_free (xdp); +break ;default :/* Not possible, checked in xdp_rxq_info_reg_mem_model() */ break ;
@@ -398,19 +404,19 @@ static void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct,void xdp_return_frame (struct xdp_frame *xdpf) { -__xdp_return (xdpf->data, &xdpf->mem, false,0 ); +__xdp_return (xdpf->data, &xdpf->mem, false,0 ,NULL ); }EXPORT_SYMBOL_GPL (xdp_return_frame);void xdp_return_frame_rx_napi (struct xdp_frame *xdpf) { -__xdp_return (xdpf->data, &xdpf->mem, true,0 ); +__xdp_return (xdpf->data, &xdpf->mem, true,0 ,NULL ); }EXPORT_SYMBOL_GPL (xdp_return_frame_rx_napi);void xdp_return_buff (struct xdp_buff *xdp) { -__xdp_return (xdp->data, &xdp->rxq->mem, true, xdp->handle); +__xdp_return (xdp->data, &xdp->rxq->mem, true, xdp->handle, xdp); }EXPORT_SYMBOL_GPL (xdp_return_buff);
net/xdp/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_XDP_SOCKETS) += xsk.o xdp_umem.o xsk_queue.o xskmap.o +obj-$(CONFIG_XDP_SOCKETS) += xsk_buff_pool.o obj-$(CONFIG_XDP_SOCKETS_DIAG) += xsk_diag.o
net/xdp/xdp_umem.c +15 -4
@@ -245,7 +245,7 @@ static void xdp_umem_release(struct xdp_umem *umem) }xsk_reuseq_destroy (umem); - +xp_destroy (umem->pool);xdp_umem_unmap_pages (umem);xdp_umem_unpin_pages (umem);
@@ -390,6 +390,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) umem->size = size; umem->headroom = headroom; umem->chunk_size_nohr = chunk_size - headroom; + umem->chunk_size = chunk_size; umem->npgs = size /PAGE_SIZE ; umem->pgs =NULL ; umem->user =NULL ;
@@ -415,11 +416,21 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) } err =xdp_umem_map_pages (umem); -if (!err) -return 0 ; +if (err) + goto out_pages; -kvfree (umem->pages); + umem->pool =xp_create (umem->pgs, umem->npgs, chunks, chunk_size, + headroom, size, unaligned_chunks); +if (!umem->pool) { + err = -ENOMEM ; + goto out_unmap; + } +return 0 ; +out_unmap: +xdp_umem_unmap_pages (umem); +out_pages: +kvfree (umem->pages); out_pin:xdp_umem_unpin_pages (umem); out_account:
net/xdp/xsk.c +54 -93
211 lines not on this page · raw message
net/xdp/xsk_buff_pool.c new file +467 -0
467 lines not on this page · raw message
net/xdp/xsk_diag.c +1 -1
@@ -56,7 +56,7 @@ static int xsk_diag_put_umem(const struct xdp_sock *xs, struct sk_buff *nlskb) du.id = umem->id; du.size = umem->size; du.num_pages = umem->npgs; - du.chunk_size = umem->chunk_size_nohr + umem->headroom; + du.chunk_size = umem->chunk_size; du.headroom = umem->headroom; du.ifindex = umem->dev ? umem->dev->ifindex :0 ; du.queue_id = umem->queue_id;
net/xdp/xsk_queue.h +44 -15
87 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 11/15 mlx5, xsk: migrate to new MEM_TYPE_XSK_BUFF_POOL
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
Use the new MEM_TYPE_XSK_BUFF_POOL API in lieu of MEM_TYPE_ZERO_COPY in mlx5e. It allows to drop a lot of code from the driver (which is now common in AF_XDP core and was related to XSK RX frame allocation, DMA mapping, etc.) and slightly improve performance (RX +0.8 Mpps, TX +0.4 Mpps).
rfc->v1: Put back the sanity check for XSK params, use XSK API to get
the total headroom size. (Maxim)
v1->v2: Fix DMA address handling, set XDP metadata to invalid. (Maxim)
v2->v3: Handle frame_sz, use xsk_buff_xdp_get_frame_dma, use xsk_buff
API for DMA sync on TX, add performance numbers. (Maxim)
--- drivers/net/ethernet/mellanox/mlx5/core/en.h | 7 +- .../ethernet/mellanox/mlx5/core/en/params.c | 13 +- .../net/ethernet/mellanox/mlx5/core/en/xdp.c | 31 ++--- .../net/ethernet/mellanox/mlx5/core/en/xdp.h | 2 +- .../ethernet/mellanox/mlx5/core/en/xsk/rx.c | 113 ++++-------------- .../ethernet/mellanox/mlx5/core/en/xsk/rx.h | 23 +++- .../ethernet/mellanox/mlx5/core/en/xsk/tx.c | 9 +- .../ethernet/mellanox/mlx5/core/en/xsk/umem.c | 49 +------- .../net/ethernet/mellanox/mlx5/core/en_main.c | 17 +-- .../net/ethernet/mellanox/mlx5/core/en_rx.c | 34 +++++- 10 files changed, 96 insertions(+), 202 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +1 -6
@@ -407,10 +407,7 @@ struct mlx5e_dma_info {dma_addr_t addr;union {struct page *page; -struct { -u64 handle; -void *data; - } xsk; +struct xdp_buff *xsk; }; };
@@ -623,7 +620,6 @@ struct mlx5e_rq { } mpwqe; };struct { -u16 umem_headroom;u16 headroom;u32 frame0_sz;u8 map_dir;/* dma map direction */
@@ -656,7 +652,6 @@ struct mlx5e_rq {struct page_pool *page_pool;/* AF_XDP zero-copy */ -struct zero_copy_allocator zca;struct xdp_umem *umem;struct work_struct recover_work;
drivers/net/ethernet/mellanox/mlx5/core/en/params.c +7 -6
@@ -12,15 +12,16 @@ static inline bool mlx5e_rx_is_xdp(struct mlx5e_params *params,u16 mlx5e_get_linear_rq_headroom (struct mlx5e_params *params,struct mlx5e_xsk_param *xsk) { -u16 headroom =NET_IP_ALIGN ; +u16 headroom; -if (mlx5e_rx_is_xdp (params, xsk)) { +if (xsk) +return xsk->headroom; + + headroom =NET_IP_ALIGN ; +if (mlx5e_rx_is_xdp (params, xsk)) headroom +=XDP_PACKET_HEADROOM ; -if (xsk) - headroom += xsk->headroom; - }else { +else headroom +=MLX5_RX_HEADROOM ; - }return headroom; }
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c +7 -24
@@ -71,7 +71,7 @@ mlx5e_xmit_xdp_buff(struct mlx5e_xdpsq *sq, struct mlx5e_rq *rq, xdptxd.data = xdpf->data; xdptxd.len = xdpf->len; -if (xdp->rxq->mem.type ==MEM_TYPE_ZERO_COPY ) { +if (xdp->rxq->mem.type ==MEM_TYPE_XSK_BUFF_POOL ) {/* The xdp_buff was in the UMEM and was copied into a newly * allocated page. The UMEM page was returned via the ZCA, and * this new page has to be mapped at this point and has to be
@@ -119,50 +119,33 @@ mlx5e_xmit_xdp_buff(struct mlx5e_xdpsq *sq, struct mlx5e_rq *rq,/* returns true if packet was consumed by xdp */ bool mlx5e_xdp_handle (struct mlx5e_rq *rq,struct mlx5e_dma_info *di, -void *va,u16 *rx_headroom,u32 *len,bool xsk) +u32 *len,struct xdp_buff *xdp) {struct bpf_prog *prog =READ_ONCE (rq->xdp_prog); -struct xdp_umem *umem = rq->umem; -struct xdp_buff xdp;u32 act;int err;if (!prog)return false; - xdp.data = va + *rx_headroom; -xdp_set_data_meta_invalid (&xdp); - xdp.data_end = xdp.data + *len; - xdp.data_hard_start = va; -if (xsk) - xdp.handle = di->xsk.handle; - xdp.rxq = &rq->xdp_rxq; - xdp.frame_sz = rq->buff.frame0_sz; - - act =bpf_prog_run_xdp (prog, &xdp); -if (xsk) { -u64 off = xdp.data - xdp.data_hard_start; - - xdp.handle =xsk_umem_adjust_offset (umem, xdp.handle, off); - } + act =bpf_prog_run_xdp (prog, xdp);switch (act) {case XDP_PASS : - *rx_headroom = xdp.data - xdp.data_hard_start; - *len = xdp.data_end - xdp.data; + *len = xdp->data_end - xdp->data;return false;case XDP_TX : -if (unlikely (!mlx5e_xmit_xdp_buff (rq->xdpsq, rq, di, &xdp))) +if (unlikely (!mlx5e_xmit_xdp_buff (rq->xdpsq, rq, di, xdp))) goto xdp_abort;__set_bit (MLX5E_RQ_FLAG_XDP_XMIT , rq->flags);/* non-atomic */ return true;case XDP_REDIRECT :/* When XDP enabled then page-refcnt==1 here */ - err =xdp_do_redirect (rq->netdev, &xdp, prog); + err =xdp_do_redirect (rq->netdev, xdp, prog);if (unlikely (err)) goto xdp_abort;__set_bit (MLX5E_RQ_FLAG_XDP_XMIT , rq->flags);__set_bit (MLX5E_RQ_FLAG_XDP_REDIRECT , rq->flags); -if (!xsk) +if (xdp->rxq->mem.type !=MEM_TYPE_XSK_BUFF_POOL )mlx5e_page_dma_unmap (rq, di); rq->stats->xdp_redirect++;return true;
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.h +1 -1
@@ -63,7 +63,7 @@struct mlx5e_xsk_param ;int mlx5e_xdp_max_mtu (struct mlx5e_params *params,struct mlx5e_xsk_param *xsk);bool mlx5e_xdp_handle (struct mlx5e_rq *rq,struct mlx5e_dma_info *di, -void *va,u16 *rx_headroom,u32 *len,bool xsk); +u32 *len,struct xdp_buff *xdp);void mlx5e_xdp_mpwqe_complete (struct mlx5e_xdpsq *sq);bool mlx5e_poll_xdpsq_cq (struct mlx5e_cq *cq);void mlx5e_free_xdpsq_descs (struct mlx5e_xdpsq *sq);
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.c +21 -92
169 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.h +17 -6
@@ -9,12 +9,6 @@/* RX data path */ -bool mlx5e_xsk_pages_enough_umem (struct mlx5e_rq *rq,int count); -int mlx5e_xsk_page_alloc_umem (struct mlx5e_rq *rq, -struct mlx5e_dma_info *dma_info); -void mlx5e_xsk_page_release (struct mlx5e_rq *rq, -struct mlx5e_dma_info *dma_info); -void mlx5e_xsk_zca_free (struct zero_copy_allocator *zca,unsigned long handle); struct sk_buff *mlx5e_xsk_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi, u16 cqe_bcnt,
@@ -25,6 +19,23 @@ struct sk_buff *mlx5e_xsk_skb_from_cqe_linear(struct mlx5e_rq *rq,struct mlx5e_wqe_frag_info *wi, u32 cqe_bcnt); +static inline int mlx5e_xsk_page_alloc_umem (struct mlx5e_rq *rq, +struct mlx5e_dma_info *dma_info) +{ + dma_info->xsk =xsk_buff_alloc (rq->umem); +if (!dma_info->xsk) +return -ENOMEM ; + +/* Store the DMA address without headroom. In striding RQ case, we just +* provide pages for UMR, and headroom is counted at the setup stage +* when creating a WQE. In non-striding RQ case, headroom is accounted +* in mlx5e_alloc_rx_wqe. +*/ + dma_info->addr =xsk_buff_xdp_get_frame_dma (dma_info->xsk); + +return 0 ; +} +static inline bool mlx5e_xsk_update_rx_wakeup (struct mlx5e_rq *rq,bool alloc_err) {if (!xsk_umem_uses_need_wakeup (rq->umem))
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/tx.c +4 -5
@@ -5,7 +5,7 @@#include "umem.h" #include "en/xdp.h" #include "en/params.h" -#include <net/xdp_sock.h> +#include <net/xdp_sock_drv.h> int mlx5e_xsk_wakeup (struct net_device *dev,u32 qid,u32 flags) {
@@ -92,12 +92,11 @@ bool mlx5e_xsk_tx(struct mlx5e_xdpsq *sq, unsigned int budget)break ; } - xdptxd.dma_addr =xdp_umem_get_dma (umem, desc.addr); - xdptxd.data =xdp_umem_get_data (umem, desc.addr); + xdptxd.dma_addr =xsk_buff_raw_get_dma (umem, desc.addr); + xdptxd.data =xsk_buff_raw_get_data (umem, desc.addr); xdptxd.len = desc.len; -dma_sync_single_for_device (sq->pdev, xdptxd.dma_addr, - xdptxd.len,DMA_BIDIRECTIONAL ); +xsk_buff_raw_dma_sync_for_device (umem, xdptxd.dma_addr, xdptxd.len);if (unlikely (!sq->xmit_xdp_frame (sq, &xdptxd, &xdpi, check_result))) {if (sq->mpwqe.wqe)
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/umem.c +6 -43
77 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +3 -14
@@ -38,7 +38,7 @@#include <linux/bpf.h> #include <linux/if_bridge.h> #include <net/page_pool.h> -#include <net/xdp_sock.h> +#include <net/xdp_sock_drv.h> #include "eswitch.h" #include "en.h" #include "en/txrx.h"
@@ -414,7 +414,6 @@ static int mlx5e_alloc_rq(struct mlx5e_channel *c, rq->buff.map_dir = rq->xdp_prog ?DMA_BIDIRECTIONAL :DMA_FROM_DEVICE ; rq->buff.headroom =mlx5e_get_rq_headroom (mdev, params, xsk); - rq->buff.umem_headroom = xsk ? xsk->headroom :0 ; pool_size =1 << params->log_rq_mtu_frames;switch (rq->wq_type) {
@@ -526,19 +525,9 @@ static int mlx5e_alloc_rq(struct mlx5e_channel *c, }if (xsk) { - rq->buff.frame0_sz =xsk_umem_xdp_frame_sz (umem); - - err =mlx5e_xsk_resize_reuseq (umem, num_xsk_frames); -if (unlikely (err)) { -mlx5_core_err (mdev,"Unable to allocate the Reuse Ring for %u frames\n" , - num_xsk_frames); - goto err_free; - } - - rq->zca.free = mlx5e_xsk_zca_free; err =xdp_rxq_info_reg_mem_model (&rq->xdp_rxq, -MEM_TYPE_ZERO_COPY , - &rq->zca); +MEM_TYPE_XSK_BUFF_POOL ,NULL ); +xsk_buff_set_rxq_info (rq->umem, &rq->xdp_rxq); }else {/* Create a page_pool and register it with rxq */ pp_params.order =0 ;
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +29 -5
@@ -300,7 +300,7 @@ static inline void mlx5e_page_release(struct mlx5e_rq *rq,* put into the Reuse Ring, because there is no way to return * the page to the userspace when the interface goes down. */ -mlx5e_xsk_page_release (rq, dma_info); +xsk_buff_free (dma_info->xsk); elsemlx5e_page_release_dynamic (rq ,dma_info ,recycle ); }
@@ -385,7 +385,11 @@ static int mlx5e_alloc_rx_wqes(struct mlx5e_rq *rq, u16 ix, u8 wqe_bulk)if (rq->umem) {int pages_desired = wqe_bulk << rq->wqe.info.log_num_frags; -if (unlikely (!mlx5e_xsk_pages_enough_umem (rq, pages_desired))) +/* Check in advance that we have enough frames, instead of +* allocating one-by-one, failing and moving frames to the +* Reuse Ring. +*/ +if (unlikely (!xsk_buff_can_alloc (rq->umem, pages_desired)))return -ENOMEM ; }
@@ -480,8 +484,11 @@ static int mlx5e_alloc_rx_mpwqe(struct mlx5e_rq *rq, u16 ix)int err;int i; +/* Check in advance that we have enough frames, instead of allocating +* one-by-one, failing and moving frames to the Reuse Ring. +*/ if (rq->umem && -unlikely (!mlx5e_xsk_pages_enough_umem (rq,MLX5_MPWRQ_PAGES_PER_WQE ))) { +unlikely (!xsk_buff_can_alloc (rq->umem,MLX5_MPWRQ_PAGES_PER_WQE ))) { err = -ENOMEM ; goto err; }
@@ -1044,12 +1051,24 @@ struct sk_buff *mlx5e_build_linear_skb(struct mlx5e_rq *rq, void *va,return skb; } +static void mlx5e_fill_xdp_buff (struct mlx5e_rq *rq,void *va,u16 headroom, +u32 len,struct xdp_buff *xdp) +{ + xdp->data_hard_start = va; +xdp_set_data_meta_invalid (xdp); + xdp->data = va + headroom; + xdp->data_end = xdp->data + len; + xdp->rxq = &rq->xdp_rxq; + xdp->frame_sz = rq->buff.frame0_sz; +} +struct sk_buff *mlx5e_skb_from_cqe_linear (struct mlx5e_rq *rq,struct mlx5_cqe64 *cqe,struct mlx5e_wqe_frag_info *wi,u32 cqe_bcnt) {struct mlx5e_dma_info *di = wi->di;u16 rx_headroom = rq->buff.headroom; +struct xdp_buff xdp;struct sk_buff *skb;void *va, *data;bool consumed;
@@ -1065,11 +1084,13 @@ mlx5e_skb_from_cqe_linear(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe,prefetch (data);rcu_read_lock (); - consumed =mlx5e_xdp_handle (rq, di, va, &rx_headroom, &cqe_bcnt, false); +mlx5e_fill_xdp_buff (rq, va, rx_headroom, cqe_bcnt, &xdp); + consumed =mlx5e_xdp_handle (rq, di, &cqe_bcnt, &xdp);rcu_read_unlock ();if (consumed)return NULL ;/* page/packet was consumed by XDP */ + rx_headroom = xdp.data - xdp.data_hard_start; frag_size =MLX5_SKB_FRAG_SZ (rx_headroom + cqe_bcnt); skb =mlx5e_build_linear_skb (rq, va, frag_size, rx_headroom, cqe_bcnt);if (unlikely (!skb))
@@ -1343,6 +1364,7 @@ mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi,struct mlx5e_dma_info *di = &wi->umr.dma_info[page_idx];u16 rx_headroom = rq->buff.headroom;u32 cqe_bcnt32 = cqe_bcnt; +struct xdp_buff xdp;struct sk_buff *skb;void *va, *data;u32 frag_size;
@@ -1364,7 +1386,8 @@ mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi,prefetch (data);rcu_read_lock (); - consumed =mlx5e_xdp_handle (rq, di, va, &rx_headroom, &cqe_bcnt32, false); +mlx5e_fill_xdp_buff (rq, va, rx_headroom, cqe_bcnt32, &xdp); + consumed =mlx5e_xdp_handle (rq, di, &cqe_bcnt32, &xdp);rcu_read_unlock ();if (consumed) {if (__test_and_clear_bit (MLX5E_RQ_FLAG_XDP_XMIT , rq->flags))
@@ -1372,6 +1395,7 @@ mlx5e_skb_from_cqe_mpwrq_linear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi,return NULL ;/* page/packet was consumed by XDP */ } + rx_headroom = xdp.data - xdp.data_hard_start; frag_size =MLX5_SKB_FRAG_SZ (rx_headroom + cqe_bcnt32); skb =mlx5e_build_linear_skb (rq, va, frag_size, rx_headroom, cqe_bcnt32);if (unlikely (!skb))
Signature · 1 line
2.25.1
PATCH v3 12/15 xsk: remove MEM_TYPE_ZERO_COPY and corresponding code
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
There are no users of MEM_TYPE_ZERO_COPY. Remove all corresponding code, including the "handle" member of struct xdp_buff.
rfc->v1: Fixed spelling in commit message. (Björn)
--- drivers/net/hyperv/netvsc_bpf.c | 1 - include/net/xdp.h | 9 +- include/net/xdp_sock.h | 45 ---------- include/net/xdp_sock_drv.h | 149 -------------------------------- include/trace/events/xdp.h | 1 - net/core/xdp.c | 42 ++------- net/xdp/xdp_umem.c | 56 +----------- net/xdp/xsk.c | 48 +--------- net/xdp/xsk_buff_pool.c | 7 ++ net/xdp/xsk_queue.c | 62 ------------- net/xdp/xsk_queue.h | 105 ---------------------- 11 files changed, 15 insertions(+), 510 deletions(-)
drivers/net/hyperv/netvsc_bpf.c +0 -1
@@ -50,7 +50,6 @@ u32 netvsc_run_xdp(struct net_device *ndev, struct netvsc_channel *nvchan, xdp->data_end = xdp->data + len; xdp->rxq = &nvchan->xdp_rxq; xdp->frame_sz =PAGE_SIZE ; - xdp->handle =0 ;memcpy (xdp->data, data, len);
include/net/xdp.h +1 -8
@@ -39,7 +39,6 @@ enum xdp_mem_type {MEM_TYPE_PAGE_SHARED =0 ,/* Split-page refcnt based model */ MEM_TYPE_PAGE_ORDER0 ,/* Orig XDP full page model */ MEM_TYPE_PAGE_POOL , -MEM_TYPE_ZERO_COPY ,MEM_TYPE_XSK_BUFF_POOL , MEM_TYPE_MAX, };
@@ -55,10 +54,6 @@ struct xdp_mem_info {struct page_pool ; -struct zero_copy_allocator { -void (*free)(struct zero_copy_allocator *zca,unsigned long handle); -}; -struct xdp_rxq_info {struct net_device *dev;u32 queue_index;
@@ -71,7 +66,6 @@ struct xdp_buff {void *data_end;void *data_meta;void *data_hard_start; -unsigned long handle;struct xdp_rxq_info *rxq;u32 frame_sz;/* frame size to deduce data_hard_end/reserved tailroom*/ };
@@ -120,8 +114,7 @@ struct xdp_frame *convert_to_xdp_frame(struct xdp_buff *xdp)int metasize;int headroom; -if (xdp->rxq->mem.type ==MEM_TYPE_ZERO_COPY || - xdp->rxq->mem.type ==MEM_TYPE_XSK_BUFF_POOL ) +if (xdp->rxq->mem.type ==MEM_TYPE_XSK_BUFF_POOL )return xdp_convert_zc_to_xdp_frame (xdp);/* Assure headroom is available for storing info */
include/net/xdp_sock.h +0 -45
75 lines not on this page · raw message
include/net/xdp_sock_drv.h +0 -149
188 lines not on this page · raw message
include/trace/events/xdp.h +0 -1
@@ -287,7 +287,6 @@ TRACE_EVENT(xdp_devmap_xmit, FN(PAGE_SHARED) \ FN(PAGE_ORDER0) \ FN(PAGE_POOL) \ - FN(ZERO_COPY) \ FN(XSK_BUFF_POOL)#define __MEM_TYPE_TP_FN (x) \
net/core/xdp.c +5 -37
88 lines not on this page · raw message
net/xdp/xdp_umem.c +1 -55
92 lines not on this page · raw message
net/xdp/xsk.c +1 -47
80 lines not on this page · raw message
net/xdp/xsk_buff_pool.c +7 -0
@@ -8,6 +8,13 @@#include "xsk_queue.h" +/* Masks for xdp_umem_page flags. +* The low 12-bits of the addr will be 0 since this is the page address, so we +* can use them for flags. +*/ +#define XSK_NEXT_PG_CONTIG_SHIFT 0 +#define XSK_NEXT_PG_CONTIG_MASK BIT_ULL(XSK_NEXT_PG_CONTIG_SHIFT) +struct xsk_buff_pool {struct xsk_queue *fq;struct list_head free_list;
net/xdp/xsk_queue.c +0 -62
71 lines not on this page · raw message
net/xdp/xsk_queue.h +0 -105
130 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 13/15 xdp: simplify xdp_return_{frame,frame_rx_napi,buff}
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
The xdp_return_{frame,frame_rx_napi,buff} function are never used, except in xdp_convert_zc_to_xdp_frame(), by the MEM_TYPE_XSK_BUFF_POOL memory type.
To simplify and reduce code, change so that xdp_convert_zc_to_xdp_frame() calls xsk_buff_free() directly since the type is know, and remove MEM_TYPE_XSK_BUFF_POOL from the switch statement in __xdp_return() function.
--- net/core/xdp.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
net/core/xdp.c +9 -12
@@ -335,10 +335,11 @@ EXPORT_SYMBOL_GPL(xdp_rxq_info_reg_mem_model);* scenarios (e.g. queue full), it is possible to return the xdp_frame * while still leveraging this protection. The @napi_direct boolean * is used for those calls sites. Thus, allowing for faster recycling -* of xdp_frames/pages in those cases. +* of xdp_frames/pages in those cases. This path is never used by the +* MEM_TYPE_XSK_BUFF_POOL memory type, so it's explicitly not part of +* the switch-statement. */ -static void __xdp_return (void *data,struct xdp_mem_info *mem,bool napi_direct, -struct xdp_buff *xdp) +static void __xdp_return (void *data,struct xdp_mem_info *mem,bool napi_direct) {struct xdp_mem_allocator *xa;struct page *page;
@@ -360,33 +361,29 @@ static void __xdp_return(void *data, struct xdp_mem_info *mem, bool napi_direct, page =virt_to_page (data);/* Assumes order0 page*/ put_page (page);break ; -case MEM_TYPE_XSK_BUFF_POOL : -/* NB! Only valid from an xdp_buff! */ -xsk_buff_free (xdp); -break ;default :/* Not possible, checked in xdp_rxq_info_reg_mem_model() */ +WARN (1 ,"Incorrect XDP memory type (%d) usage" , mem->type);break ; } }void xdp_return_frame (struct xdp_frame *xdpf) { -__xdp_return (xdpf->data, &xdpf->mem, false,NULL ); +__xdp_return (xdpf->data, &xdpf->mem, false); }EXPORT_SYMBOL_GPL (xdp_return_frame);void xdp_return_frame_rx_napi (struct xdp_frame *xdpf) { -__xdp_return (xdpf->data, &xdpf->mem, true,NULL ); +__xdp_return (xdpf->data, &xdpf->mem, true); }EXPORT_SYMBOL_GPL (xdp_return_frame_rx_napi);void xdp_return_buff (struct xdp_buff *xdp) { -__xdp_return (xdp->data, &xdp->rxq->mem, true, xdp); +__xdp_return (xdp->data, &xdp->rxq->mem, true); } -EXPORT_SYMBOL_GPL (xdp_return_buff);/* Only called for MEM_TYPE_PAGE_POOL see xdp.h */ void __xdp_release_frame (void *data,struct xdp_mem_info *mem)
@@ -467,7 +464,7 @@ struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp) xdpf->metasize = metasize; xdpf->mem.type =MEM_TYPE_PAGE_ORDER0 ; -xdp_return_buff (xdp); +xsk_buff_free (xdp);return xdpf; }EXPORT_SYMBOL_GPL (xdp_convert_zc_to_xdp_frame);
Signature · 1 line
2.25.1
PATCH v3 14/15 xsk: explicitly inline functions and move definitions
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
In order to reduce the number of function calls, the struct xsk_buff_pool definition is moved to xsk_buff_pool.h. The functions xp_get_dma(), xp_dma_sync_for_cpu(), xp_dma_sync_for_device(), xp_validate_desc() and various helper functions are explicitly inlined.
Further, move xp_get_handle() and xp_release() to xsk.c, to allow for the compiler to perform inlining.
rfc->v1: Make sure xp_validate_desc() is inlined for Tx perf. (Maxim)
--- include/net/xsk_buff_pool.h | 98 ++++++++++++++++++++++-- net/xdp/xsk.c | 15 ++++ net/xdp/xsk_buff_pool.c | 148 ++---------------------------------- net/xdp/xsk_queue.h | 45 +++++++++++ 4 files changed, 156 insertions(+), 150 deletions(-)
include/net/xsk_buff_pool.h +91 -7
@@ -4,6 +4,7 @@#ifndef XSK_BUFF_POOL_H_ #define XSK_BUFF_POOL_H_ +#include <linux/if_xdp.h> #include <linux/types.h> #include <linux/dma-mapping.h> #include <net/xdp.h>
@@ -25,6 +26,27 @@ struct xdp_buff_xsk {struct list_head free_list_node; }; +struct xsk_buff_pool { +struct xsk_queue *fq; +struct list_head free_list; +dma_addr_t *dma_pages; +struct xdp_buff_xsk *heads; +u64 chunk_mask; +u64 addrs_cnt; +u32 free_list_cnt; +u32 dma_pages_cnt; +u32 heads_cnt; +u32 free_heads_cnt; +u32 headroom; +u32 chunk_size; +u32 frame_len; +bool cheap_dma; +bool unaligned; +void *addrs; +struct device *dev; +struct xdp_buff_xsk *free_heads[]; +}; +/* AF_XDP core. */ struct xsk_buff_pool *xp_create(struct page **pages, u32 nr_pages, u32 chunks, u32 chunk_size, u32 headroom, u64 size,
@@ -32,8 +54,6 @@ struct xsk_buff_pool *xp_create(struct page **pages, u32 nr_pages, u32 chunks,void xp_set_fq (struct xsk_buff_pool *pool,struct xsk_queue *fq);void xp_destroy (struct xsk_buff_pool *pool);void xp_release (struct xdp_buff_xsk *xskb); -u64 xp_get_handle (struct xdp_buff_xsk *xskb); -bool xp_validate_desc (struct xsk_buff_pool *pool,struct xdp_desc *desc);/* AF_XDP, and XDP core. */ void xp_free (struct xdp_buff_xsk *xskb);
@@ -47,10 +67,74 @@ struct xdp_buff *xp_alloc(struct xsk_buff_pool *pool);bool xp_can_alloc (struct xsk_buff_pool *pool,u32 count);void *xp_raw_get_data (struct xsk_buff_pool *pool,u64 addr);dma_addr_t xp_raw_get_dma (struct xsk_buff_pool *pool,u64 addr); -dma_addr_t xp_get_dma (struct xdp_buff_xsk *xskb); -dma_addr_t xp_get_frame_dma (struct xdp_buff_xsk *xskb); -void xp_dma_sync_for_cpu (struct xdp_buff_xsk *xskb); -void xp_dma_sync_for_device (struct xsk_buff_pool *pool,dma_addr_t dma, -size_t size); +static inline dma_addr_t xp_get_dma (struct xdp_buff_xsk *xskb) +{ +return xskb->dma; +} + +static inline dma_addr_t xp_get_frame_dma (struct xdp_buff_xsk *xskb) +{ +return xskb->frame_dma; +} + +void xp_dma_sync_for_cpu_slow (struct xdp_buff_xsk *xskb); +static inline void xp_dma_sync_for_cpu (struct xdp_buff_xsk *xskb) +{ +if (xskb->pool->cheap_dma) +return ; + +xp_dma_sync_for_cpu_slow (xskb); +} + +void xp_dma_sync_for_device_slow (struct xsk_buff_pool *pool,dma_addr_t dma, +size_t size); +static inline void xp_dma_sync_for_device (struct xsk_buff_pool *pool, +dma_addr_t dma,size_t size) +{ +if (pool->cheap_dma) +return ; + +xp_dma_sync_for_device_slow (pool, dma, size); +} + +/* Masks for xdp_umem_page flags. +* The low 12-bits of the addr will be 0 since this is the page address, so we +* can use them for flags. +*/ +#define XSK_NEXT_PG_CONTIG_SHIFT 0 +#define XSK_NEXT_PG_CONTIG_MASK BIT_ULL(XSK_NEXT_PG_CONTIG_SHIFT) + +static inline bool xp_desc_crosses_non_contig_pg (struct xsk_buff_pool *pool, +u64 addr,u32 len) +{ +bool cross_pg = (addr & (PAGE_SIZE -1 )) + len >PAGE_SIZE ; + +if (pool->dma_pages_cnt && cross_pg) { +return !(pool->dma_pages[addr >>PAGE_SHIFT ] & +XSK_NEXT_PG_CONTIG_MASK ); + } +return false; +} + +static inline u64 xp_aligned_extract_addr (struct xsk_buff_pool *pool,u64 addr) +{ +return addr & pool->chunk_mask; +} + +static inline u64 xp_unaligned_extract_addr (u64 addr) +{ +return addr &XSK_UNALIGNED_BUF_ADDR_MASK ; +} + +static inline u64 xp_unaligned_extract_offset (u64 addr) +{ +return addr >>XSK_UNALIGNED_BUF_OFFSET_SHIFT ; +} + +static inline u64 xp_unaligned_add_offset_to_addr (u64 addr) +{ +return xp_unaligned_extract_addr (addr) + +xp_unaligned_extract_offset (addr); +}#endif /* XSK_BUFF_POOL_H_ */
net/xdp/xsk.c +15 -0
@@ -99,6 +99,21 @@ bool xsk_umem_uses_need_wakeup(struct xdp_umem *umem) }EXPORT_SYMBOL (xsk_umem_uses_need_wakeup); +void xp_release (struct xdp_buff_xsk *xskb) +{ + xskb->pool->free_heads[xskb->pool->free_heads_cnt++] = xskb; +} + +static u64 xp_get_handle (struct xdp_buff_xsk *xskb) +{ +u64 offset = xskb->xdp.data - xskb->xdp.data_hard_start; + + offset += xskb->pool->headroom; +if (!xskb->pool->unaligned) +return xskb->orig_addr + offset; +return xskb->orig_addr + (offset <<XSK_UNALIGNED_BUF_OFFSET_SHIFT ); +} +static int __xsk_rcv_zc (struct xdp_sock *xs,struct xdp_buff *xdp,u32 len) { struct xdp_buff_xsk *xskb = container_of(xdp, struct xdp_buff_xsk, xdp);
net/xdp/xsk_buff_pool.c +5 -143
184 lines not on this page · raw message
net/xdp/xsk_queue.h +45 -0
51 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 15/15 MAINTAINERS, xsk: update AF_XDP section after moves/adds
In reply to Björn TöpelFrom: Björn Töpel <[email protected]>
Update MAINTAINERS to correctly mirror the current AF_XDP socket file layout. Also, add the AF_XDP files of libbpf.
rfc->v1: Sorted file entries. (Joe)
--- MAINTAINERS | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
MAINTAINERS +5 -1
@@ -18443,8 +18443,12 @@ R: Jonathan Lemon <[email protected]> L: [email protected] L: [email protected] S: Maintained -F: kernel/bpf/xskmap.c +F: include/net/xdp_sock* +F: include/net/xsk_buffer_pool.h +F: include/uapi/linux/if_xdp.h F: net/xdp/ +F: samples/bpf/xdpsock* +F: tools/lib/bpf/xsk* XEN BLOCK SUBSYSTEM M: Konrad Rzeszutek Wilk <[email protected]>
Signature · 1 line
2.25.1
kbuild test robot
build botRe: [PATCH bpf-next v3 07/15] i40e: separate kernel allocated rx_bi rings from AF_XDP rings
In reply to Björn TöpelI love your patch! Perhaps something to improve:
Hi "Bj?rn,
I love your patch! Perhaps something to improve:
[auto build test WARNING on bpf-next/master]
[also build test WARNING on jkirsher-next-queue/dev-queue next-20200518] [cannot apply to bpf/master linus/master v5.7-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Bj-rn-T-pel/Introduce-AF_XDP-buffer-allocation-API/20200519-203122 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master config: riscv-allyesconfig (attached as .config) compiler: riscv64-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=riscv
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>, old ones prefixed by <<):
>> drivers/net/ethernet/intel/i40e/i40e_txrx.c:531:6: warning: no previous prototype for 'i40e_fd_handle_status' [-Wmissing-prototypes]
531 | void i40e_fd_handle_status(struct i40e_ring *rx_ring, u64 qword0_raw,
| ^~~~~~~~~~~~~~~~~~~~~
vim +/i40e_fd_handle_status +531 drivers/net/ethernet/intel/i40e/i40e_txrx.c
520
521 /**
522 * i40e_fd_handle_status - check the Programming Status for FD
523 * @rx_ring: the Rx ring for this descriptor
524 * @qword0_raw: qword0
525 * @qword1: qword1 after le_to_cpu
526 * @prog_id: the id originally used for programming
527 *
528 * This is used to verify if the FD programming or invalidation
529 * requested by SW to the HW is successful or not and take actions accordingly.
530 **/
> 531 void i40e_fd_handle_status(struct i40e_ring *rx_ring, u64 qword0_raw,
532 u64 qword1, u8 prog_id)
533 {
534 struct i40e_pf *pf = rx_ring->vsi->back;
535 struct pci_dev *pdev = pf->pdev;
536 struct i40e_32b_rx_wb_qw0 *qw0;
537 u32 fcnt_prog, fcnt_avail;
538 u32 error;
539
540 qw0 = (struct i40e_32b_rx_wb_qw0 *)&qword0_raw;
541 error = (qword1 & I40E_RX_PROG_STATUS_DESC_QW1_ERROR_MASK) >>
542 I40E_RX_PROG_STATUS_DESC_QW1_ERROR_SHIFT;
543
544 if (error == BIT(I40E_RX_PROG_STATUS_DESC_FD_TBL_FULL_SHIFT)) {
545 pf->fd_inv = le32_to_cpu(qw0->hi_dword.fd_id);
546 if (qw0->hi_dword.fd_id != 0 ||
547 (I40E_DEBUG_FD & pf->hw.debug_mask))
548 dev_warn(&pdev->dev, "ntuple filter loc = %d, could not be added\n",
549 pf->fd_inv);
550
551 /* Check if the programming error is for ATR.
552 * If so, auto disable ATR and set a state for
553 * flush in progress. Next time we come here if flush is in
554 * progress do nothing, once flush is complete the state will
555 * be cleared.
556 */
557 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
558 return;
559
560 pf->fd_add_err++;
561 /* store the current atr filter count */
562 pf->fd_atr_cnt = i40e_get_current_atr_cnt(pf);
563
564 if (qw0->hi_dword.fd_id == 0 &&
565 test_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state)) {
566 /* These set_bit() calls aren't atomic with the
567 * test_bit() here, but worse case we potentially
568 * disable ATR and queue a flush right after SB
569 * support is re-enabled. That shouldn't cause an
570 * issue in practice
571 */
572 set_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
573 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
574 }
575
576 /* filter programming failed most likely due to table full */
577 fcnt_prog = i40e_get_global_fd_count(pf);
578 fcnt_avail = pf->fdir_pf_filter_count;
579 /* If ATR is running fcnt_prog can quickly change,
580 * if we are very close to full, it makes sense to disable
581 * FD ATR/SB and then re-enable it when there is room.
582 */
583 if (fcnt_prog >= (fcnt_avail - I40E_FDIR_BUFFER_FULL_MARGIN)) {
584 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
585 !test_and_set_bit(__I40E_FD_SB_AUTO_DISABLED,
586 pf->state))
587 if (I40E_DEBUG_FD & pf->hw.debug_mask)
588 dev_warn(&pdev->dev, "FD filter space full, new ntuple rules will not be added\n");
589 }
590 } else if (error == BIT(I40E_RX_PROG_STATUS_DESC_NO_FD_ENTRY_SHIFT)) {
591 if (I40E_DEBUG_FD & pf->hw.debug_mask)
592 dev_info(&pdev->dev, "ntuple filter fd_id = %d, could not be removed\n",
593 qw0->hi_dword.fd_id);
594 }
595 }
596
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all at lists.01.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/gzip
Size: 63439 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20200519/3d0ec82b/attachment-0001.bin>
Re: [PATCH bpf-next v3 07/15] i40e: separate kernel allocated rx_bi rings from AF_XDP rings
Quoted 21 lines · kbuild test robot
Hi "Bj?rn,
I love your patch! Perhaps something to improve:
[auto build test WARNING on bpf-next/master]
[also build test WARNING on jkirsher-next-queue/dev-queue next-20200518] [cannot apply to bpf/master linus/master v5.7-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]url: https://github.com/0day-ci/linux/commits/Bj-rn-T-pel/Introduce-AF_XDP-buffer-allocation-API/20200519-203122 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master config: riscv-allyesconfig (attached as .config) compiler: riscv64-linux-gcc (GCC) 9.3.0reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=riscv
Quoted 9 lines
If you fix the issue, kindly add following tag as appropriate
Reported-by kbuild test robot <[email protected]>All warnings (new ones prefixed by >>, old ones prefixed by <<):
Quoted 1 line
Quoted 1 line
drivers/net/ethernet/intel/i40e/i40e_txrx.c:531:6: warning: no previous prototype for 'i40e_fd_handle_status' [-Wmissing-prototypes]531 | void i40e_fd_handle_status(struct
i40e_ring*rx_ring, u64qword0_raw,
| ^~~~~~~~~~~~~~~~~~~~~
Yes, this could indeed be made static. Hmm, I wonder why I didn't get that warning on my x86-64 build!? I'll spin a v4 (or do a follow-up?).
Bj?rn
Jakub Kicinski
maintainerRe: [PATCH bpf-next v3 07/15] i40e: separate kernel allocated rx_bi rings from AF_XDP rings
Quoted 32 lines · On Tue, 19 May 2020 18:20:09 +0200 Bj?rn T?pel wrote:
Quoted 21 lines · kbuild test robot
Hi "Bj?rn,
I love your patch! Perhaps something to improve:
[auto build test WARNING on bpf-next/master]
[also build test WARNING on jkirsher-next-queue/dev-queue next-20200518] [cannot apply to bpf/master linus/master v5.7-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]url: https://github.com/0day-ci/linux/commits/Bj-rn-T-pel/Introduce-AF_XDP-buffer-allocation-API/20200519-203122 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master config: riscv-allyesconfig (attached as .config) compiler: riscv64-linux-gcc (GCC) 9.3.0reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=riscvQuoted 9 lines
If you fix the issue, kindly add following tag as appropriate
Reported-by kbuild test robot <[email protected]>All warnings (new ones prefixed by >>, old ones prefixed by <<):
Quoted 1 line
Quoted 1 line
drivers/net/ethernet/intel/i40e/i40e_txrx.c:531:6: warning: no previous prototype for 'i40e_fd_handle_status' [-Wmissing-prototypes]531 | void i40e_fd_handle_status(struct
i40e_ring*rx_ring, u64qword0_raw,
| ^~~~~~~~~~~~~~~~~~~~~
Quoted 5 lines
Yes, this could indeed be made static. Hmm, I wonder why I didn't get that warning on my x86-64 build!? I'll spin a v4 (or do a follow-up?).
Bj?rn
While at it I also get this on patch 11 (gcc-10, W=1):
drivers/net/ethernet/mellanox/mlx5/core/en_main.c: In function mlx5e_alloc_rq:drivers/net/ethernet/mellanox/mlx5/core/en_main.c:376:6: warning: variable num_xsk_frames set but not used [-Wunused-but-set-variable]
376 | u32 num_xsk_frames = 0;
| ^~~~~~~~~~~~~~kbuild test robot
build botRe: [PATCH bpf-next v3 07/15] i40e: separate kernel allocated rx_bi rings from AF_XDP rings
In reply to Björn TöpelI love your patch! Perhaps something to improve:
Hi "Bj?rn,
I love your patch! Perhaps something to improve:
[auto build test WARNING on bpf-next/master]
[also build test WARNING on jkirsher-next-queue/dev-queue next-20200518] [cannot apply to bpf/master linus/master v5.7-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Bj-rn-T-pel/Introduce-AF_XDP-buffer-allocation-API/20200519-203122 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master config: x86_64-allyesconfig (attached as .config) compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 135b877874fae96b4372c8a3fbfaa8ff44ff86e3)
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>, old ones prefixed by <<):
>> drivers/net/ethernet/intel/i40e/i40e_txrx.c:531:6: warning: no previous prototype for function 'i40e_fd_handle_status' [-Wmissing-prototypes]
void i40e_fd_handle_status(struct i40e_ring *rx_ring, u64 qword0_raw,
^drivers/net/ethernet/intel/i40e/i40e_txrx.c:531:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void i40e_fd_handle_status(struct i40e_ring *rx_ring, u64 qword0_raw,
^
static
1 warning generated.
vim +/i40e_fd_handle_status +531 drivers/net/ethernet/intel/i40e/i40e_txrx.c
520
521 /**
522 * i40e_fd_handle_status - check the Programming Status for FD
523 * @rx_ring: the Rx ring for this descriptor
524 * @qword0_raw: qword0
525 * @qword1: qword1 after le_to_cpu
526 * @prog_id: the id originally used for programming
527 *
528 * This is used to verify if the FD programming or invalidation
529 * requested by SW to the HW is successful or not and take actions accordingly.
530 **/
> 531 void i40e_fd_handle_status(struct i40e_ring *rx_ring, u64 qword0_raw,
532 u64 qword1, u8 prog_id)
533 {
534 struct i40e_pf *pf = rx_ring->vsi->back;
535 struct pci_dev *pdev = pf->pdev;
536 struct i40e_32b_rx_wb_qw0 *qw0;
537 u32 fcnt_prog, fcnt_avail;
538 u32 error;
539
540 qw0 = (struct i40e_32b_rx_wb_qw0 *)&qword0_raw;
541 error = (qword1 & I40E_RX_PROG_STATUS_DESC_QW1_ERROR_MASK) >>
542 I40E_RX_PROG_STATUS_DESC_QW1_ERROR_SHIFT;
543
544 if (error == BIT(I40E_RX_PROG_STATUS_DESC_FD_TBL_FULL_SHIFT)) {
545 pf->fd_inv = le32_to_cpu(qw0->hi_dword.fd_id);
546 if (qw0->hi_dword.fd_id != 0 ||
547 (I40E_DEBUG_FD & pf->hw.debug_mask))
548 dev_warn(&pdev->dev, "ntuple filter loc = %d, could not be added\n",
549 pf->fd_inv);
550
551 /* Check if the programming error is for ATR.
552 * If so, auto disable ATR and set a state for
553 * flush in progress. Next time we come here if flush is in
554 * progress do nothing, once flush is complete the state will
555 * be cleared.
556 */
557 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
558 return;
559
560 pf->fd_add_err++;
561 /* store the current atr filter count */
562 pf->fd_atr_cnt = i40e_get_current_atr_cnt(pf);
563
564 if (qw0->hi_dword.fd_id == 0 &&
565 test_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state)) {
566 /* These set_bit() calls aren't atomic with the
567 * test_bit() here, but worse case we potentially
568 * disable ATR and queue a flush right after SB
569 * support is re-enabled. That shouldn't cause an
570 * issue in practice
571 */
572 set_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
573 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
574 }
575
576 /* filter programming failed most likely due to table full */
577 fcnt_prog = i40e_get_global_fd_count(pf);
578 fcnt_avail = pf->fdir_pf_filter_count;
579 /* If ATR is running fcnt_prog can quickly change,
580 * if we are very close to full, it makes sense to disable
581 * FD ATR/SB and then re-enable it when there is room.
582 */
583 if (fcnt_prog >= (fcnt_avail - I40E_FDIR_BUFFER_FULL_MARGIN)) {
584 if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
585 !test_and_set_bit(__I40E_FD_SB_AUTO_DISABLED,
586 pf->state))
587 if (I40E_DEBUG_FD & pf->hw.debug_mask)
588 dev_warn(&pdev->dev, "FD filter space full, new ntuple rules will not be added\n");
589 }
590 } else if (error == BIT(I40E_RX_PROG_STATUS_DESC_NO_FD_ENTRY_SHIFT)) {
591 if (I40E_DEBUG_FD & pf->hw.debug_mask)
592 dev_info(&pdev->dev, "ntuple filter fd_id = %d, could not be removed\n",
593 qw0->hi_dword.fd_id);
594 }
595 }
596
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all at lists.01.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/gzip
Size: 73478 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/intel-wired-lan/attachments/20200520/796d30e9/attachment-0001.bin>
Re: [PATCH bpf-next v3 07/15] i40e: separate kernel allocated rx_bi rings from AF_XDP rings
In reply to Jakub KicinskiQuoted 1 line · Jakub Kicinski
[...]
Quoted 7 lines
While at it I also get this on patch 11 (gcc-10, W=1):
drivers/net/ethernet/mellanox/mlx5/core/en_main.c: In functionmlx5e_alloc_rq:drivers/net/ethernet/mellanox/mlx5/core/en_main.c:376:6: warning: variablenum_xsk_framesset but not used [-Wunused-but-set-variable]376 | u32 num_xsk_frames = 0; | ^~~~~~~~~~~~~~
Ah, yes. Thanks!
I'll wait until tomorrow for more input, and then do a respin.
Bj?rn