igb: Add support for AF_XDP zero-copy
Subsystems (4)
v6 cover igb: Add support for AF_XDP zero-copy
This is version 6 of the AF_XDP zero-copy support for igb. Since Sriram's duties changed I am sending this instead. Additionally, I've tested this on real hardware, Intel i210 [1].
Changes since v5:
- Rebase to 6.11
- Fix set-but-unused variable warnings
- Split first patches (Maciej)
- Add READ/WRITE_ONCE() for xsk_pool and xdp_prog (Maciej)
- Add synchronize_net() (Maciej)
- Remove IGB_RING_FLAG_AF_XDP_ZC (Maciej)
- Add NETDEV_XDP_ACT_XSK_ZEROCOPY to last patch (Maciej)
- Update Rx ntc handling (Maciej)
- Move stats update and xdp finalize to common functions (Maciej)
- "Likelyfy" XDP_REDIRECT case (Maciej)
- Check Tx disabled and carrier in igb_xmit_zc() (Maciej)
- RCT (Maciej)
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes since v4:
- Rebase to v6.10
- Fix issue reported by kernel test robot
- Provide napi_id for xdp_rxq_info_reg() so that busy polling works
- Set olinfo_status in igb_xmit_zc() so that frames are transmitted
Link to v4: https://lore.kernel.org/intel-wired-lan/[email protected]/
[1] - https://github.com/Linutronix/TSN-Testbench/tree/main/tests/busypolling_i210
Original cover letter:
The first couple of patches adds helper funcctions to prepare for AF_XDP zero-copy support which comes in the last couple of patches, one each for Rx and TX paths.
As mentioned in v1 patchset [0], I don't have access to an actual IGB device to provide correct performance numbers. I have used Intel 82576EB emulator in QEMU [1] to test the changes to IGB driver.
The tests use one isolated vCPU for RX/TX and one isolated vCPU for the xdp-sock application [2]. Hope these measurements provide at the least some indication on the increase in performance when using ZC, especially in the TX path. It would be awesome if someone with a real IGB NIC can test the patch.
AF_XDP performance using 64 byte packets in Kpps.
Benchmark: XDP-SKB XDP-DRV XDP-DRV(ZC)
rxdrop 220 235 350
txpush 1.000 1.000 410
l2fwd 1.000 1.000 200
AF_XDP performance using 1500 byte packets in Kpps.
Benchmark: XDP-SKB XDP-DRV XDP-DRV(ZC)
rxdrop 200 210 310
txpush 1.000 1.000 410
l2fwd 0.900 1.000 160
[0]: https://lore.kernel.org/intel-wired-lan/[email protected]/
[1]: https://www.qemu.org/docs/master/system/devices/igb.html
[2]: https://github.com/xdp-project/bpf-examples/tree/master/AF_XDP-example
v3->v4:
- NULL check buffer_info in igb_dump before dereferencing (Simon Horman)
v2->v3:
- Avoid TX unit hang when using AF_XDP zero-copy by setting time_stamp on the tx_buffer_info
- Fix uninitialized nb_buffs (Simon Horman)
v1->v2:
- Use batch XSK APIs (Maciej Fijalkowski)
- Follow reverse xmas tree convention and remove the ternary operator use (Simon Horman)
---
Sriram Yagnaraman (6):
igb: Always call igb_xdp_ring_update_tail() under Tx lock
igb: Remove static qualifiers
igb: Introduce igb_xdp_is_enabled()
igb: Introduce XSK data structures and helpers
igb: Add AF_XDP zero-copy Rx support
igb: Add AF_XDP zero-copy Tx support
drivers/net/ethernet/intel/igb/Makefile | 2 +- drivers/net/ethernet/intel/igb/igb.h | 36 +- drivers/net/ethernet/intel/igb/igb_main.c | 232 ++++++++---- drivers/net/ethernet/intel/igb/igb_xsk.c | 561 ++++++++++++++++++++++++++++++ 4 files changed, 770 insertions(+), 61 deletions(-)
---
base-commit: e7d731326ef0622f103e5ed47d3405f71cdcd7f6
change-id: 20240711-b4-igb_zero_copy-bb70a31ecb0f
Best regards,
Signature · 1 line
Kurt Kanzenbach <[email protected]>
PATCH v6 1/6 igb: Always call igb_xdp_ring_update_tail() under Tx lock
From: Sriram Yagnaraman <[email protected]>
Always call igb_xdp_ring_update_tail() under __netif_tx_lock(), add a comment to indicate that. This is needed to share the same TX ring between XDP, XSK and slow paths.
--- drivers/net/ethernet/intel/igb/igb_main.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +10 -4
@@ -2914,6 +2914,7 @@ static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp) } } +/* This function assumes __netif_tx_lock is held by the caller. */ static void igb_xdp_ring_update_tail (struct igb_ring *ring) {/* Force memory writes to complete before letting h/w know there
@@ -3000,11 +3001,11 @@ static int igb_xdp_xmit(struct net_device *dev, int n, nxmit++; } -__netif_tx_unlock (nq); -if (unlikely (flags &XDP_XMIT_FLUSH ))igb_xdp_ring_update_tail (tx_ring); +__netif_tx_unlock (nq); +return nxmit; }
@@ -8853,12 +8854,14 @@ static void igb_put_rx_buffer(struct igb_ring *rx_ring,static int igb_clean_rx_irq (struct igb_q_vector *q_vector,const int budget) { +unsigned int total_bytes =0 , total_packets =0 ;struct igb_adapter *adapter = q_vector->adapter;struct igb_ring *rx_ring = q_vector->rx.ring; -struct sk_buff *skb = rx_ring->skb; -unsigned int total_bytes =0 , total_packets =0 ;u16 cleaned_count =igb_desc_unused (rx_ring); +struct sk_buff *skb = rx_ring->skb; +int cpu =smp_processor_id ();unsigned int xdp_xmit =0 ; +struct netdev_queue *nq;struct xdp_buff xdp;u32 frame_sz =0 ;int rx_buf_pgcnt;
@@ -8986,7 +8989,10 @@ static int igb_clean_rx_irq(struct igb_q_vector *q_vector, const int budget)if (xdp_xmit &IGB_XDP_TX ) {struct igb_ring *tx_ring =igb_xdp_tx_queue_mapping (adapter); + nq =txring_txq (tx_ring); +__netif_tx_lock (nq, cpu);igb_xdp_ring_update_tail (tx_ring); +__netif_tx_unlock (nq); }u64_stats_update_begin (&rx_ring->rx_syncp);
Signature · 1 line
2.39.2
Re: [PATCH iwl-next v6 1/6] igb: Always call igb_xdp_ring_update_tail() under Tx lock
drivers/net/ethernet/intel/igb/igb_main.c static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp) · line 2920
Quoted 11 lines · Kurt Kanzenbach
index
11be39f435f3..4d5e5691c9bd100644drivers/net/ethernet/intel/igb/igb_main.c +1
-0@@ -2914,6 +2914,7 @@ static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp) } } +/* This function assumes __netif_tx_lock is held by the caller. */ static void igb_xdp_ring_update_tail (struct igb_ring *ring) {/* Force memory writes to complete before letting h/w know there
This
lockdep_assert_held(txring_txq(ring)->_xmit_lock);
would be more powerful than the comment ;)
Sebastian
Re: [PATCH iwl-next v6 1/6] igb: Always call igb_xdp_ring_update_tail() under Tx lock
Quoted 8 lines · Sebastian Andrzej Siewior
Quoted 7 lines · Kurt Kanzenbach
index
11be39f435f3..4d5e5691c9bd100644drivers/net/ethernet/intel/igb/igb_main.c +0
-0@@ -2914,6 +2914,7 @@ static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp) } }
Quoted 7 lines
drivers/net/ethernet/intel/igb/igb_main.c static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp) · line 2920
Quoted 4 lines
drivers/net/ethernet/intel/igb/igb_main.c +1
-0+/* This function assumes __netif_tx_lock is held by the caller. */ static void igb_xdp_ring_update_tail (struct igb_ring *ring) {/* Force memory writes to complete before letting h/w know there This
lockdep_assert_held(txring_txq(ring)->_xmit_lock);
would be more powerful than the comment ;)
Probably yes :-).
Thanks,
Kurt
Re: [PATCH iwl-next v6 1/6] igb: Always call igb_xdp_ring_update_tail() under Tx lock
In reply to Kurt KanzenbachQuoted 5 lines · Kurt Kanzenbach
From: Sriram Yagnaraman <[email protected]>
Always call
igb_xdp_ring_update_tail()under__netif_tx_lock(), add a comment to indicate that. This is needed to share the same TX ring between XDP, XSK and slow paths.
Sorry for being a-hole here but I think this should go to -net as a fix... I should have brought it up earlier, current igb XDP support is racy on tail updates which you're fixing here.
Do you agree...or not?:)
Quoted 66 lines
Signed-off-by Sriram Yagnaraman <[email protected]>[Kurt: Split patches]Signed-off-by Kurt Kanzenbach <[email protected]>--- drivers/net/ethernet/intel/igb/igb_main.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)drivers/net/ethernet/intel/igb/igb_main.c +10
-4@@ -2914,6 +2914,7 @@ static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp) } } +/* This function assumes __netif_tx_lock is held by the caller. */ static void igb_xdp_ring_update_tail (struct igb_ring *ring) {/* Force memory writes to complete before letting h/w know there @@ -3000,11 +3001,11 @@ static int igb_xdp_xmit(struct net_device *dev, int n, nxmit++; } -__netif_tx_unlock (nq); -if (unlikely (flags &XDP_XMIT_FLUSH ))igb_xdp_ring_update_tail (tx_ring); +__netif_tx_unlock (nq); +return nxmit; }@@ -8853,12 +8854,14 @@ static void igb_put_rx_buffer(struct igb_ring *rx_ring,static int igb_clean_rx_irq (struct igb_q_vector *q_vector,const int budget) { +unsigned int total_bytes =0 , total_packets =0 ;struct igb_adapter *adapter = q_vector->adapter;struct igb_ring *rx_ring = q_vector->rx.ring; -struct sk_buff *skb = rx_ring->skb; -unsigned int total_bytes =0 , total_packets =0 ;u16 cleaned_count =igb_desc_unused (rx_ring); +struct sk_buff *skb = rx_ring->skb; +int cpu =smp_processor_id ();unsigned int xdp_xmit =0 ; +struct netdev_queue *nq;struct xdp_buff xdp;u32 frame_sz =0 ;int rx_buf_pgcnt;@@ -8986,7 +8989,10 @@ static int igb_clean_rx_irq(struct igb_q_vector *q_vector, const int budget)if (xdp_xmit &IGB_XDP_TX ) {struct igb_ring *tx_ring =igb_xdp_tx_queue_mapping (adapter); + nq =txring_txq (tx_ring); +__netif_tx_lock (nq, cpu);igb_xdp_ring_update_tail (tx_ring); +__netif_tx_unlock (nq); }u64_stats_update_begin (&rx_ring->rx_syncp);Signature · 2 lines
-- 2.39.2
Re: [PATCH iwl-next v6 1/6] igb: Always call igb_xdp_ring_update_tail() under Tx lock
Quoted 7 lines · Maciej Fijalkowski
Quoted 5 lines · Kurt Kanzenbach
From: Sriram Yagnaraman <[email protected]>
Always call
igb_xdp_ring_update_tail()under__netif_tx_lock(), add a comment to indicate that. This is needed to share the same TX ring between XDP, XSK and slow paths.
Quoted 5 lines
Sorry for being a-hole here but I think this should go to -net as a fix... I should have brought it up earlier, current igb XDP support is racy on tail updates which you're fixing here.
Do you agree...or not?:)
Yeah, makes sense. I'll add a Fixes tag and send it to iwl-net.
Thanks,
Kurt
PATCH v6 2/6 igb: Remove static qualifiers
In reply to Kurt KanzenbachFrom: Sriram Yagnaraman <[email protected]>
Remove static qualifiers on the following functions to be able to call from XSK specific file that is added in the later patches:
- igb_xdp_tx_queue_mapping()
- igb_xdp_ring_update_tail()
- igb_clean_tx_ring()
- igb_clean_rx_ring()
- igb_xdp_xmit_back()
- igb_process_skb_fields()
--- drivers/net/ethernet/intel/igb/igb.h | 8 ++++++++ drivers/net/ethernet/intel/igb/igb_main.c | 18 ++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +8 -0
@@ -718,6 +718,8 @@ extern char igb_driver_name[];int igb_xmit_xdp_ring (struct igb_adapter *adapter,struct igb_ring *ring,struct xdp_frame *xdpf); +struct igb_ring *igb_xdp_tx_queue_mapping (struct igb_adapter *adapter); +void igb_xdp_ring_update_tail (struct igb_ring *ring);int igb_open (struct net_device *netdev);int igb_close (struct net_device *netdev);int igb_up (struct igb_adapter *);
@@ -731,12 +733,18 @@ int igb_setup_tx_resources(struct igb_ring *);int igb_setup_rx_resources (struct igb_ring *);void igb_free_tx_resources (struct igb_ring *);void igb_free_rx_resources (struct igb_ring *); +void igb_clean_tx_ring (struct igb_ring *tx_ring); +void igb_clean_rx_ring (struct igb_ring *rx_ring);void igb_configure_tx_ring (struct igb_adapter *,struct igb_ring *);void igb_configure_rx_ring (struct igb_adapter *,struct igb_ring *);void igb_setup_tctl (struct igb_adapter *);void igb_setup_rctl (struct igb_adapter *);void igb_setup_srrctl (struct igb_adapter *,struct igb_ring *);netdev_tx_t igb_xmit_frame_ring (struct sk_buff *,struct igb_ring *); +int igb_xdp_xmit_back (struct igb_adapter *adapter,struct xdp_buff *xdp); +void igb_process_skb_fields (struct igb_ring *rx_ring, +union e1000_adv_rx_desc *rx_desc, +struct sk_buff *skb);void igb_alloc_rx_buffers (struct igb_ring *,u16 );void igb_update_stats (struct igb_adapter *);bool igb_has_link (struct igb_adapter *adapter);
drivers/net/ethernet/intel/igb/igb_main.c +8 -10
@@ -115,8 +115,6 @@ static void igb_configure_tx(struct igb_adapter *);static void igb_configure_rx (struct igb_adapter *);static void igb_clean_all_tx_rings (struct igb_adapter *);static void igb_clean_all_rx_rings (struct igb_adapter *); -static void igb_clean_tx_ring (struct igb_ring *); -static void igb_clean_rx_ring (struct igb_ring *);static void igb_set_rx_mode (struct net_device *);static void igb_update_phy_info (struct timer_list *);static void igb_watchdog (struct timer_list *);
@@ -2915,7 +2913,7 @@ static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp) }/* This function assumes __netif_tx_lock is held by the caller. */ -static void igb_xdp_ring_update_tail (struct igb_ring *ring) +void igb_xdp_ring_update_tail (struct igb_ring *ring) {/* Force memory writes to complete before letting h/w know there * are new descriptors to fetch.
@@ -2924,7 +2922,7 @@ static void igb_xdp_ring_update_tail(struct igb_ring *ring)writel (ring->next_to_use, ring->tail); } -static struct igb_ring *igb_xdp_tx_queue_mapping (struct igb_adapter *adapter) +struct igb_ring *igb_xdp_tx_queue_mapping (struct igb_adapter *adapter) {unsigned int r_idx =smp_processor_id ();
@@ -2934,7 +2932,7 @@ static struct igb_ring *igb_xdp_tx_queue_mapping(struct igb_adapter *adapter)return adapter->tx_ring[r_idx]; } -static int igb_xdp_xmit_back (struct igb_adapter *adapter,struct xdp_buff *xdp) +int igb_xdp_xmit_back (struct igb_adapter *adapter,struct xdp_buff *xdp) {struct xdp_frame *xdpf =xdp_convert_buff_to_frame (xdp);int cpu =smp_processor_id ();
@@ -4880,7 +4878,7 @@ static void igb_free_all_tx_resources(struct igb_adapter *adapter)* igb_clean_tx_ring - Free Tx Buffers * @tx_ring: ring to be cleaned **/ -static void igb_clean_tx_ring (struct igb_ring *tx_ring) +void igb_clean_tx_ring (struct igb_ring *tx_ring) {u16 i = tx_ring->next_to_clean;struct igb_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
@@ -4999,7 +4997,7 @@ static void igb_free_all_rx_resources(struct igb_adapter *adapter)* igb_clean_rx_ring - Free Rx Buffers per Queue * @rx_ring: ring to free buffers from **/ -static void igb_clean_rx_ring (struct igb_ring *rx_ring) +void igb_clean_rx_ring (struct igb_ring *rx_ring) {u16 i = rx_ring->next_to_clean;
@@ -8768,9 +8766,9 @@ static bool igb_cleanup_headers(struct igb_ring *rx_ring,* order to populate the hash, checksum, VLAN, timestamp, protocol, and * other fields within the skb. **/ -static void igb_process_skb_fields (struct igb_ring *rx_ring, -union e1000_adv_rx_desc *rx_desc, -struct sk_buff *skb) +void igb_process_skb_fields (struct igb_ring *rx_ring, +union e1000_adv_rx_desc *rx_desc, +struct sk_buff *skb) {struct net_device *dev = rx_ring->netdev;
Signature · 1 line
2.39.2
Re: [PATCH iwl-next v6 2/6] igb: Remove static qualifiers
Quoted 10 lines · Kurt Kanzenbach
From: Sriram Yagnaraman <[email protected]>
Remove static qualifiers on the following functions to be able to call from XSK specific file that is added in the later patches:
-igb_xdp_tx_queue_mapping()
-igb_xdp_ring_update_tail()
-igb_clean_tx_ring()
-igb_clean_rx_ring()
-igb_xdp_xmit_back()
-igb_process_skb_fields()
How about inlining some of these that are small enough?
- igb_xdp_tx_queue_mapping()
- igb_xdp_ring_update_tail()
Quoted 116 lines
Signed-off-by Sriram Yagnaraman <[email protected]>[Kurt: Split patches]Signed-off-by Kurt Kanzenbach <[email protected]>--- drivers/net/ethernet/intel/igb/igb.h | 8 ++++++++ drivers/net/ethernet/intel/igb/igb_main.c | 18 ++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-)drivers/net/ethernet/intel/igb/igb.h +8
-0@@ -718,6 +718,8 @@ extern char igb_driver_name[];int igb_xmit_xdp_ring (struct igb_adapter *adapter,struct igb_ring *ring,struct xdp_frame *xdpf); +struct igb_ring *igb_xdp_tx_queue_mapping (struct igb_adapter *adapter); +void igb_xdp_ring_update_tail (struct igb_ring *ring);int igb_open (struct net_device *netdev);int igb_close (struct net_device *netdev);int igb_up (struct igb_adapter *);@@ -731,12 +733,18 @@ int igb_setup_tx_resources(struct igb_ring *);int igb_setup_rx_resources (struct igb_ring *);void igb_free_tx_resources (struct igb_ring *);void igb_free_rx_resources (struct igb_ring *); +void igb_clean_tx_ring (struct igb_ring *tx_ring); +void igb_clean_rx_ring (struct igb_ring *rx_ring);void igb_configure_tx_ring (struct igb_adapter *,struct igb_ring *);void igb_configure_rx_ring (struct igb_adapter *,struct igb_ring *);void igb_setup_tctl (struct igb_adapter *);void igb_setup_rctl (struct igb_adapter *);void igb_setup_srrctl (struct igb_adapter *,struct igb_ring *);netdev_tx_t igb_xmit_frame_ring (struct sk_buff *,struct igb_ring *); +int igb_xdp_xmit_back (struct igb_adapter *adapter,struct xdp_buff *xdp); +void igb_process_skb_fields (struct igb_ring *rx_ring, +union e1000_adv_rx_desc *rx_desc, +struct sk_buff *skb);void igb_alloc_rx_buffers (struct igb_ring *,u16 );void igb_update_stats (struct igb_adapter *);bool igb_has_link (struct igb_adapter *adapter);drivers/net/ethernet/intel/igb/igb_main.c +8
-10@@ -115,8 +115,6 @@ static void igb_configure_tx(struct igb_adapter *);static void igb_configure_rx (struct igb_adapter *);static void igb_clean_all_tx_rings (struct igb_adapter *);static void igb_clean_all_rx_rings (struct igb_adapter *); -static void igb_clean_tx_ring (struct igb_ring *); -static void igb_clean_rx_ring (struct igb_ring *);static void igb_set_rx_mode (struct net_device *);static void igb_update_phy_info (struct timer_list *);static void igb_watchdog (struct timer_list *);@@ -2915,7 +2913,7 @@ static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp) }/* This function assumes __netif_tx_lock is held by the caller. */ -static void igb_xdp_ring_update_tail (struct igb_ring *ring) +void igb_xdp_ring_update_tail (struct igb_ring *ring) {/* Force memory writes to complete before letting h/w know there * are new descriptors to fetch. @@ -2924,7 +2922,7 @@ static void igb_xdp_ring_update_tail(struct igb_ring *ring)writel (ring->next_to_use, ring->tail); } -static struct igb_ring *igb_xdp_tx_queue_mapping (struct igb_adapter *adapter) +struct igb_ring *igb_xdp_tx_queue_mapping (struct igb_adapter *adapter) {unsigned int r_idx =smp_processor_id ();@@ -2934,7 +2932,7 @@ static struct igb_ring *igb_xdp_tx_queue_mapping(struct igb_adapter *adapter)return adapter->tx_ring[r_idx]; } -static int igb_xdp_xmit_back (struct igb_adapter *adapter,struct xdp_buff *xdp) +int igb_xdp_xmit_back (struct igb_adapter *adapter,struct xdp_buff *xdp) {struct xdp_frame *xdpf =xdp_convert_buff_to_frame (xdp);int cpu =smp_processor_id ();@@ -4880,7 +4878,7 @@ static void igb_free_all_tx_resources(struct igb_adapter *adapter)* igb_clean_tx_ring - Free Tx Buffers * @tx_ring: ring to be cleaned **/ -static void igb_clean_tx_ring (struct igb_ring *tx_ring) +void igb_clean_tx_ring (struct igb_ring *tx_ring) {u16 i = tx_ring->next_to_clean;struct igb_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];@@ -4999,7 +4997,7 @@ static void igb_free_all_rx_resources(struct igb_adapter *adapter)* igb_clean_rx_ring - Free Rx Buffers per Queue * @rx_ring: ring to free buffers from **/ -static void igb_clean_rx_ring (struct igb_ring *rx_ring) +void igb_clean_rx_ring (struct igb_ring *rx_ring) {u16 i = rx_ring->next_to_clean;@@ -8768,9 +8766,9 @@ static bool igb_cleanup_headers(struct igb_ring *rx_ring,* order to populate the hash, checksum, VLAN, timestamp, protocol, and * other fields within the skb. **/ -static void igb_process_skb_fields (struct igb_ring *rx_ring, -union e1000_adv_rx_desc *rx_desc, -struct sk_buff *skb) +void igb_process_skb_fields (struct igb_ring *rx_ring, +union e1000_adv_rx_desc *rx_desc, +struct sk_buff *skb) {struct net_device *dev = rx_ring->netdev;Signature · 2 lines
-- 2.39.2
Re: [PATCH iwl-next v6 2/6] igb: Remove static qualifiers
Quoted 12 lines · Maciej Fijalkowski
Quoted 10 lines · Kurt Kanzenbach
From: Sriram Yagnaraman <[email protected]>
Remove static qualifiers on the following functions to be able to call from XSK specific file that is added in the later patches:
-igb_xdp_tx_queue_mapping()
-igb_xdp_ring_update_tail()
-igb_clean_tx_ring()
-igb_clean_rx_ring()
-igb_xdp_xmit_back()
-igb_process_skb_fields()
Quoted 4 lines
How about inlining some of these that are small enough?
-
igb_xdp_tx_queue_mapping()
-igb_xdp_ring_update_tail()
Will do.
Thanks,
Kurt
PATCH v6 3/6 igb: Introduce igb_xdp_is_enabled()
In reply to Kurt KanzenbachFrom: Sriram Yagnaraman <[email protected]>
Introduce igb_xdp_is_enabled() to check if an XDP program is assigned to the device. Use that wherever xdp_prog is read and evaluated.
--- drivers/net/ethernet/intel/igb/igb.h | 5 +++++ drivers/net/ethernet/intel/igb/igb_main.c | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +5 -0
@@ -805,6 +805,11 @@ static inline struct netdev_queue *txring_txq(const struct igb_ring *tx_ring)return netdev_get_tx_queue (tx_ring->netdev, tx_ring->queue_index); } +static inline bool igb_xdp_is_enabled (struct igb_adapter *adapter) +{ +return !!READ_ONCE (adapter->xdp_prog); +} +int igb_add_filter (struct igb_adapter *adapter,struct igb_nfc_filter *input); int igb_erase_filter(struct igb_adapter *adapter,
drivers/net/ethernet/intel/igb/igb_main.c +5 -3
@@ -2946,7 +2946,8 @@ int igb_xdp_xmit_back(struct igb_adapter *adapter, struct xdp_buff *xdp)/* During program transitions its possible adapter->xdp_prog is assigned * but ring has not been configured yet. In this case simply abort xmit. */ - tx_ring = adapter->xdp_prog ?igb_xdp_tx_queue_mapping (adapter) :NULL ; + tx_ring =igb_xdp_is_enabled (adapter) ? +igb_xdp_tx_queue_mapping (adapter) :NULL ;if (unlikely (!tx_ring))return IGB_XDP_CONSUMED ;
@@ -2979,7 +2980,8 @@ static int igb_xdp_xmit(struct net_device *dev, int n,/* During program transitions its possible adapter->xdp_prog is assigned * but ring has not been configured yet. In this case simply abort xmit. */ - tx_ring = adapter->xdp_prog ?igb_xdp_tx_queue_mapping (adapter) :NULL ; + tx_ring =igb_xdp_is_enabled (adapter) ? +igb_xdp_tx_queue_mapping (adapter) :NULL ;if (unlikely (!tx_ring))return -ENXIO ;
@@ -6612,7 +6614,7 @@ static int igb_change_mtu(struct net_device *netdev, int new_mtu)struct igb_adapter *adapter =netdev_priv (netdev);int max_frame = new_mtu +IGB_ETH_PKT_HDR_PAD ; -if (adapter->xdp_prog) { +if (igb_xdp_is_enabled (adapter)) {int i;for (i =0 ; i < adapter->num_rx_queues; i++) {
Signature · 1 line
2.39.2
Re: [PATCH iwl-next v6 3/6] igb: Introduce igb_xdp_is_enabled()
Quoted 8 lines · Kurt Kanzenbach
From: Sriram Yagnaraman <[email protected]>
Introduce
igb_xdp_is_enabled()to check if an XDP program is assigned to the device. Use that whereverxdp_progis read and evaluated.Signed-off-by Sriram Yagnaraman <[email protected]>[Kurt: Split patches and use READ_ONCE()]Signed-off-by Kurt Kanzenbach <[email protected]>
Quoted 58 lines
--- drivers/net/ethernet/intel/igb/igb.h | 5 +++++ drivers/net/ethernet/intel/igb/igb_main.c | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-)drivers/net/ethernet/intel/igb/igb.h +5
-0@@ -805,6 +805,11 @@ static inline struct netdev_queue *txring_txq(const struct igb_ring *tx_ring)return netdev_get_tx_queue (tx_ring->netdev, tx_ring->queue_index); } +static inline bool igb_xdp_is_enabled (struct igb_adapter *adapter) +{ +return !!READ_ONCE (adapter->xdp_prog); +} +int igb_add_filter (struct igb_adapter *adapter,struct igb_nfc_filter *input); int igb_erase_filter(struct igb_adapter *adapter,drivers/net/ethernet/intel/igb/igb_main.c +5
-3@@ -2946,7 +2946,8 @@ int igb_xdp_xmit_back(struct igb_adapter *adapter, struct xdp_buff *xdp)/* During program transitions its possible adapter->xdp_prog is assigned * but ring has not been configured yet. In this case simply abort xmit. */ - tx_ring = adapter->xdp_prog ?igb_xdp_tx_queue_mapping (adapter) :NULL ; + tx_ring =igb_xdp_is_enabled (adapter) ? +igb_xdp_tx_queue_mapping (adapter) :NULL ;if (unlikely (!tx_ring))return IGB_XDP_CONSUMED ;@@ -2979,7 +2980,8 @@ static int igb_xdp_xmit(struct net_device *dev, int n,/* During program transitions its possible adapter->xdp_prog is assigned * but ring has not been configured yet. In this case simply abort xmit. */ - tx_ring = adapter->xdp_prog ?igb_xdp_tx_queue_mapping (adapter) :NULL ; + tx_ring =igb_xdp_is_enabled (adapter) ? +igb_xdp_tx_queue_mapping (adapter) :NULL ;if (unlikely (!tx_ring))return -ENXIO ;@@ -6612,7 +6614,7 @@ static int igb_change_mtu(struct net_device *netdev, int new_mtu)struct igb_adapter *adapter =netdev_priv (netdev);int max_frame = new_mtu +IGB_ETH_PKT_HDR_PAD ; -if (adapter->xdp_prog) { +if (igb_xdp_is_enabled (adapter)) {int i;for (i =0 ; i < adapter->num_rx_queues; i++) {Signature · 2 lines
-- 2.39.2
PATCH v6 4/6 igb: Introduce XSK data structures and helpers
In reply to Kurt KanzenbachFrom: Sriram Yagnaraman <[email protected]>
Add the following ring flag:
- IGB_RING_FLAG_TX_DISABLED (when xsk pool is being setup)
Add a xdp_buff array for use with XSK receive batch API, and a pointer to xsk_pool in igb_adapter.
Add enable/disable functions for TX and RX rings.
Add enable/disable functions for XSK pool.
Add xsk wakeup function.
None of the above functionality will be active until NETDEV_XDP_ACT_XSK_ZEROCOPY is advertised in netdev->xdp_features.
[Kurt: Add READ/WRITE_ONCE(), synchronize_net(),
remove IGB_RING_FLAG_AF_XDP_ZC]
--- drivers/net/ethernet/intel/igb/Makefile | 2 +- drivers/net/ethernet/intel/igb/igb.h | 13 +- drivers/net/ethernet/intel/igb/igb_main.c | 9 ++ drivers/net/ethernet/intel/igb/igb_xsk.c | 207 ++++++++++++++++++++++++++++++ 4 files changed, 229 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/igb/Makefile +1 -1
@@ -8,4 +8,4 @@ obj-$(CONFIG_IGB) += igb.o igb-y := igb_main.o igb_ethtool.o e1000_82575.o \ e1000_mac.o e1000_nvm.o e1000_phy.o e1000_mbx.o \ - e1000_i210.o igb_ptp.o igb_hwmon.o + e1000_i210.o igb_ptp.o igb_hwmon.o igb_xsk.o
drivers/net/ethernet/intel/igb/igb.h +12 -1
@@ -20,6 +20,7 @@#include <linux/mdio.h> #include <net/xdp.h> +#include <net/xdp_sock_drv.h> struct igb_adapter ;
@@ -320,6 +321,7 @@ struct igb_ring {union {/* array of buffer info structs */ struct igb_tx_buffer *tx_buffer_info;struct igb_rx_buffer *rx_buffer_info; +struct xdp_buff **rx_buffer_info_zc; };void *desc;/* descriptor ring memory */ unsigned long flags;/* ring specific flags */
@@ -357,6 +359,7 @@ struct igb_ring { }; };struct xdp_rxq_info xdp_rxq; +struct xsk_buff_pool *xsk_pool; }____cacheline_internodealigned_in_smp ;struct igb_q_vector {
@@ -384,7 +387,8 @@ enum e1000_ring_flags_t {IGB_RING_FLAG_RX_SCTP_CSUM ,IGB_RING_FLAG_RX_LB_VLAN_BSWAP ,IGB_RING_FLAG_TX_CTX_IDX , - IGB_RING_FLAG_TX_DETECT_HANG +IGB_RING_FLAG_TX_DETECT_HANG , + IGB_RING_FLAG_TX_DISABLED };#define ring_uses_large_buffer (ring) \
@@ -820,4 +824,11 @@ int igb_add_mac_steering_filter(struct igb_adapter *adapter,int igb_del_mac_steering_filter (struct igb_adapter *adapter,const u8 *addr,u8 queue,u8 flags); +struct xsk_buff_pool *igb_xsk_pool (struct igb_adapter *adapter, +struct igb_ring *ring); +int igb_xsk_pool_setup (struct igb_adapter *adapter, +struct xsk_buff_pool *pool, +u16 qid); +int igb_xsk_wakeup (struct net_device *dev,u32 qid,u32 flags); +#endif /* _IGB_H_ */
drivers/net/ethernet/intel/igb/igb_main.c +9 -0
@@ -2904,9 +2904,14 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf)static int igb_xdp (struct net_device *dev,struct netdev_bpf *xdp) { +struct igb_adapter *adapter =netdev_priv (dev); +switch (xdp->command) {case XDP_SETUP_PROG :return igb_xdp_setup (dev, xdp); +case XDP_SETUP_XSK_POOL : +return igb_xsk_pool_setup (adapter, xdp->xsk.pool, + xdp->xsk.queue_id);default :return -EINVAL ; }
@@ -3035,6 +3040,7 @@ static const struct net_device_ops igb_netdev_ops = { .ndo_setup_tc = igb_setup_tc, .ndo_bpf = igb_xdp, .ndo_xdp_xmit = igb_xdp_xmit, + .ndo_xsk_wakeup = igb_xsk_wakeup, };/**
@@ -4357,6 +4363,8 @@ void igb_configure_tx_ring(struct igb_adapter *adapter,u64 tdba = ring->dma;int reg_idx = ring->reg_idx; +WRITE_ONCE (ring->xsk_pool,igb_xsk_pool (adapter, ring)); +wr32 (E1000_TDLEN (reg_idx), ring->count *sizeof (union e1000_adv_tx_desc )); wr32(E1000_TDBAL(reg_idx),
@@ -4752,6 +4760,7 @@ void igb_configure_rx_ring(struct igb_adapter *adapter,xdp_rxq_info_unreg_mem_model (&ring->xdp_rxq);WARN_ON (xdp_rxq_info_reg_mem_model (&ring->xdp_rxq,MEM_TYPE_PAGE_SHARED ,NULL )); +WRITE_ONCE (ring->xsk_pool,igb_xsk_pool (adapter, ring));/* disable the queue */ wr32 (E1000_RXDCTL (reg_idx),0 );
drivers/net/ethernet/intel/igb/igb_xsk.c new file +207 -0
207 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH iwl-next v6 4/6] igb: Introduce XSK data structures and helpers
Quoted 8 lines · Kurt Kanzenbach
From: Sriram Yagnaraman <[email protected]>
Add the following ring flag:
-IGB_RING_FLAG_TX_DISABLED(when xsk pool is being setup)Add a
xdp_buffarray for use with XSK receive batch API, and a pointer toxsk_poolinigb_adapter.
Quoted 8 lines
Add enable/disable functions for TX and RX rings.
Add enable/disable functions for XSK pool.
Add xsk wakeup function.None of the above functionality will be active until
NETDEV_XDP_ACT_XSK_ZEROCOPYis advertised innetdev->xdp_features.Signed-off-by Sriram Yagnaraman <[email protected]>
Sriram's mail bounces unfortunately, is it possible to grab his current address?
You could also update the copyright date in igb_xsk.c. Besides:
Quoted 331 lines
[Kurt: Add READ/WRITE_ONCE(),
synchronize_net(),
removeIGB_RING_FLAG_AF_XDP_ZC]Signed-off-by Kurt Kanzenbach <[email protected]>--- drivers/net/ethernet/intel/igb/Makefile | 2 +- drivers/net/ethernet/intel/igb/igb.h | 13 +- drivers/net/ethernet/intel/igb/igb_main.c | 9 ++ drivers/net/ethernet/intel/igb/igb_xsk.c | 207 ++++++++++++++++++++++++++++++ 4 files changed, 229 insertions(+), 2 deletions(-)drivers/net/ethernet/intel/igb/Makefile +1
-1@@ -8,4 +8,4 @@ obj-$(CONFIG_IGB) += igb.o igb-y := igb_main.o igb_ethtool.o e1000_82575.o \ e1000_mac.o e1000_nvm.o e1000_phy.o e1000_mbx.o \ - e1000_i210.o igb_ptp.o igb_hwmon.o + e1000_i210.o igb_ptp.o igb_hwmon.o igb_xsk.odrivers/net/ethernet/intel/igb/igb.h +12
-1@@ -20,6 +20,7 @@#include <linux/mdio.h> #include <net/xdp.h> +#include <net/xdp_sock_drv.h> struct igb_adapter ;@@ -320,6 +321,7 @@ struct igb_ring {union {/* array of buffer info structs */ struct igb_tx_buffer *tx_buffer_info;struct igb_rx_buffer *rx_buffer_info; +struct xdp_buff **rx_buffer_info_zc; };void *desc;/* descriptor ring memory */ unsigned long flags;/* ring specific flags */ @@ -357,6 +359,7 @@ struct igb_ring { }; };struct xdp_rxq_info xdp_rxq; +struct xsk_buff_pool *xsk_pool; }____cacheline_internodealigned_in_smp ;struct igb_q_vector {@@ -384,7 +387,8 @@ enum e1000_ring_flags_t {IGB_RING_FLAG_RX_SCTP_CSUM ,IGB_RING_FLAG_RX_LB_VLAN_BSWAP ,IGB_RING_FLAG_TX_CTX_IDX , - IGB_RING_FLAG_TX_DETECT_HANG +IGB_RING_FLAG_TX_DETECT_HANG , + IGB_RING_FLAG_TX_DISABLED };#define ring_uses_large_buffer (ring) \@@ -820,4 +824,11 @@ int igb_add_mac_steering_filter(struct igb_adapter *adapter,int igb_del_mac_steering_filter (struct igb_adapter *adapter,const u8 *addr,u8 queue,u8 flags); +struct xsk_buff_pool *igb_xsk_pool (struct igb_adapter *adapter, +struct igb_ring *ring); +int igb_xsk_pool_setup (struct igb_adapter *adapter, +struct xsk_buff_pool *pool, +u16 qid); +int igb_xsk_wakeup (struct net_device *dev,u32 qid,u32 flags); +#endif /* _IGB_H_ */ drivers/net/ethernet/intel/igb/igb_main.c +9
-0@@ -2904,9 +2904,14 @@ static int igb_xdp_setup(struct net_device *dev, struct netdev_bpf *bpf)static int igb_xdp (struct net_device *dev,struct netdev_bpf *xdp) { +struct igb_adapter *adapter =netdev_priv (dev); +switch (xdp->command) {case XDP_SETUP_PROG :return igb_xdp_setup (dev, xdp); +case XDP_SETUP_XSK_POOL : +return igb_xsk_pool_setup (adapter, xdp->xsk.pool, + xdp->xsk.queue_id);default :return -EINVAL ; }@@ -3035,6 +3040,7 @@ static const struct net_device_ops igb_netdev_ops = { .ndo_setup_tc = igb_setup_tc, .ndo_bpf = igb_xdp, .ndo_xdp_xmit = igb_xdp_xmit, + .ndo_xsk_wakeup = igb_xsk_wakeup, };/** @@ -4357,6 +4363,8 @@ void igb_configure_tx_ring(struct igb_adapter *adapter,u64 tdba = ring->dma;int reg_idx = ring->reg_idx; +WRITE_ONCE (ring->xsk_pool,igb_xsk_pool (adapter, ring)); +wr32 (E1000_TDLEN (reg_idx), ring->count *sizeof (union e1000_adv_tx_desc )); wr32(E1000_TDBAL(reg_idx),@@ -4752,6 +4760,7 @@ void igb_configure_rx_ring(struct igb_adapter *adapter,xdp_rxq_info_unreg_mem_model (&ring->xdp_rxq);WARN_ON (xdp_rxq_info_reg_mem_model (&ring->xdp_rxq,MEM_TYPE_PAGE_SHARED ,NULL )); +WRITE_ONCE (ring->xsk_pool,igb_xsk_pool (adapter, ring));/* disable the queue */ wr32 (E1000_RXDCTL (reg_idx),0 );drivers/net/ethernet/intel/igb/igb_xsk.c new file +207
-0@@ -0,0 +1,207 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2018 Intel Corporation. */ + +#include <linux/bpf_trace.h> +#include <net/xdp_sock_drv.h> +#include <net/xdp.h> + +#include "e1000_hw.h" +#include "igb.h" + +static int igb_realloc_rx_buffer_info (struct igb_ring *ring,bool pool_present) +{ +int size = pool_present ? +sizeof (*ring->rx_buffer_info_zc) * ring->count : +sizeof (*ring->rx_buffer_info) * ring->count; +void *buff_info =vmalloc (size); + +if (!buff_info) +return -ENOMEM ; + +if (pool_present) { +vfree (ring->rx_buffer_info); + ring->rx_buffer_info =NULL ; + ring->rx_buffer_info_zc = buff_info; + }else { +vfree (ring->rx_buffer_info_zc); + ring->rx_buffer_info_zc =NULL ; + ring->rx_buffer_info = buff_info; + } + +return 0 ; +} + +static void igb_txrx_ring_disable (struct igb_adapter *adapter,u16 qid) +{ +struct igb_ring *tx_ring = adapter->tx_ring[qid]; +struct igb_ring *rx_ring = adapter->rx_ring[qid]; +struct e1000_hw *hw = &adapter->hw; + +set_bit (IGB_RING_FLAG_TX_DISABLED , &tx_ring->flags); + +wr32 (E1000_TXDCTL (tx_ring->reg_idx),0 ); +wr32 (E1000_RXDCTL (rx_ring->reg_idx),0 ); + +synchronize_net (); + +/* Rx/Tx share the same napi context. */ +napi_disable (&rx_ring->q_vector->napi); + +igb_clean_tx_ring (tx_ring); +igb_clean_rx_ring (rx_ring); + +memset (&rx_ring->rx_stats,0 ,sizeof (rx_ring->rx_stats)); +memset (&tx_ring->tx_stats,0 ,sizeof (tx_ring->tx_stats)); +} + +static void igb_txrx_ring_enable (struct igb_adapter *adapter,u16 qid) +{ +struct igb_ring *tx_ring = adapter->tx_ring[qid]; +struct igb_ring *rx_ring = adapter->rx_ring[qid]; + +igb_configure_tx_ring (adapter, tx_ring); +igb_configure_rx_ring (adapter, rx_ring); + +synchronize_net (); + +clear_bit (IGB_RING_FLAG_TX_DISABLED , &tx_ring->flags); + +/* call igb_desc_unused which always leaves +* at least 1 descriptor unused to make sure +* next_to_use != next_to_clean +*/ +igb_alloc_rx_buffers (rx_ring,igb_desc_unused (rx_ring)); + +/* Rx/Tx share the same napi context. */ +napi_enable (&rx_ring->q_vector->napi); +} + +struct xsk_buff_pool *igb_xsk_pool (struct igb_adapter *adapter, +struct igb_ring *ring) +{ +int qid = ring->queue_index; +struct xsk_buff_pool *pool; + + pool =xsk_get_pool_from_qid (adapter->netdev, qid); + +if (!igb_xdp_is_enabled (adapter)) +return NULL ; + +return (pool && pool->dev) ? pool :NULL ; +} + +static int igb_xsk_pool_enable (struct igb_adapter *adapter, +struct xsk_buff_pool *pool, +u16 qid) +{ +struct net_device *netdev = adapter->netdev; +struct igb_ring *rx_ring; +bool if_running; +int err; + +if (qid >= adapter->num_rx_queues) +return -EINVAL ; + +if (qid >= netdev->real_num_rx_queues || + qid >= netdev->real_num_tx_queues) +return -EINVAL ; + + err =xsk_pool_dma_map (pool, &adapter->pdev->dev,IGB_RX_DMA_ATTR ); +if (err) +return err; + + rx_ring = adapter->rx_ring[qid]; + if_running =netif_running (adapter->netdev) &&igb_xdp_is_enabled (adapter); +if (if_running) +igb_txrx_ring_disable (adapter, qid); + +if (if_running) { + err =igb_realloc_rx_buffer_info (rx_ring, true); +if (!err) { +igb_txrx_ring_enable (adapter, qid); +/* Kick start the NAPI context so that receiving will start */ + err =igb_xsk_wakeup (adapter->netdev, qid,XDP_WAKEUP_RX ); + } + +if (err) { +xsk_pool_dma_unmap (pool,IGB_RX_DMA_ATTR ); +return err; + } + } + +return 0 ; +} + +static int igb_xsk_pool_disable (struct igb_adapter *adapter,u16 qid) +{ +struct xsk_buff_pool *pool; +struct igb_ring *rx_ring; +bool if_running; +int err; + + pool =xsk_get_pool_from_qid (adapter->netdev, qid); +if (!pool) +return -EINVAL ; + + rx_ring = adapter->rx_ring[qid]; + if_running =netif_running (adapter->netdev) &&igb_xdp_is_enabled (adapter); +if (if_running) +igb_txrx_ring_disable (adapter, qid); + +xsk_pool_dma_unmap (pool,IGB_RX_DMA_ATTR ); + +if (if_running) { + err =igb_realloc_rx_buffer_info (rx_ring, false); +if (err) +return err; + +igb_txrx_ring_enable (adapter, qid); + } + +return 0 ; +} + +int igb_xsk_pool_setup (struct igb_adapter *adapter, +struct xsk_buff_pool *pool, +u16 qid) +{ +return pool ?igb_xsk_pool_enable (adapter, pool, qid) : +igb_xsk_pool_disable (adapter, qid); +} + +int igb_xsk_wakeup (struct net_device *dev,u32 qid,u32 flags) +{ +struct igb_adapter *adapter =netdev_priv (dev); +struct e1000_hw *hw = &adapter->hw; +struct igb_ring *ring; +u32 eics =0 ; + +if (test_bit (__IGB_DOWN, &adapter->state)) +return -ENETDOWN ; + +if (!igb_xdp_is_enabled (adapter)) +return -EINVAL ; + +if (qid >= adapter->num_tx_queues) +return -EINVAL ; + + ring = adapter->tx_ring[qid]; + +if (test_bit (IGB_RING_FLAG_TX_DISABLED , &ring->flags)) +return -ENETDOWN ; + +if (!READ_ONCE (ring->xsk_pool)) +return -EINVAL ; + +if (!napi_if_scheduled_mark_missed (&ring->q_vector->napi)) { +/* Cause software interrupt */ +if (adapter->flags &IGB_FLAG_HAS_MSIX ) { + eics |= ring->q_vector->eims_value; +wr32 (E1000_EICS , eics); + }else { +wr32 (E1000_ICS ,E1000_ICS_RXDMT0 ); + } + } + +return 0 ; +}Signature · 2 lines
-- 2.39.2
Re: [PATCH iwl-next v6 4/6] igb: Introduce XSK data structures and helpers
Quoted 13 lines · Maciej Fijalkowski
Quoted 12 lines · Kurt Kanzenbach
From: Sriram Yagnaraman <[email protected]>
Add the following ring flag:
-IGB_RING_FLAG_TX_DISABLED(when xsk pool is being setup)Add a
xdp_buffarray for use with XSK receive batch API, and a pointer toxsk_poolinigb_adapter.Add enable/disable functions for TX and RX rings.
Add enable/disable functions for XSK pool.
Add xsk wakeup function.
Quoted 7 lines
Quoted 4 lines
None of the above functionality will be active until
NETDEV_XDP_ACT_XSK_ZEROCOPYis advertised innetdev->xdp_features.Signed-off-by Sriram Yagnaraman <[email protected]>Sriram's mail bounces unfortunately, is it possible to grab his current address?
His current email address is in the Cc list. However, i wasn't sure if it's okay to update the From and SoB of these patches?
Quoted 2 lines
You could also update the copyright date in
igb_xsk.c.
Ditto for the copyright. It probably has to be something like Copyright(c) 2023 Ericsson?
Thanks,
Kurt
Re: [PATCH iwl-next v6 4/6] igb: Introduce XSK data structures and helpers
Quoted 17 lines · Kurt Kanzenbach
Quoted 16 lines · Maciej Fijalkowski
Quoted 15 lines · Kurt Kanzenbach
From: Sriram Yagnaraman <[email protected]>
Add the following ring flag:
-IGB_RING_FLAG_TX_DISABLED(when xsk pool is being setup)Add a
xdp_buffarray for use with XSK receive batch API, and a pointer toxsk_poolinigb_adapter.Add enable/disable functions for TX and RX rings.
Add enable/disable functions for XSK pool.
Add xsk wakeup function.None of the above functionality will be active until
NETDEV_XDP_ACT_XSK_ZEROCOPYis advertised innetdev->xdp_features.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Sriram Yagnaraman <[email protected]>Sriram's mail bounces unfortunately, is it possible to grab his current address?
His current email address is in the Cc list. However, i wasn't sure if it's okay to update the From and SoB of these patches?
Okay. Then I believe Sriram should provide a mailmap entry to map his old mail to a new one.
Quoted 6 lines
Quoted 3 lines
You could also update the copyright date in
igb_xsk.c.Ditto for the copyright. It probably has to be something like Copyright(c) 2023 Ericsson?
It says 2018 Intel. I don't think Sriram was working under E/// employment as he said he was forbidden to work on this further and that's why you picked it up, right?
My intent was not stir up the copyright pot, though. It can be left as-is or have something of a Linutronix/Sriram Yagnamaran mix :P
Quoted 3 lines
Thanks,
Kurt
Re: [PATCH iwl-next v6 4/6] igb: Introduce XSK data structures and helpers
Quoted 36 lines · Maciej Fijalkowski
Quoted 17 lines · Kurt Kanzenbach
Quoted 16 lines · Maciej Fijalkowski
Quoted 15 lines · Kurt Kanzenbach
From: Sriram Yagnaraman <[email protected]>
Add the following ring flag:
-IGB_RING_FLAG_TX_DISABLED(when xsk pool is being setup)Add a
xdp_buffarray for use with XSK receive batch API, and a pointer toxsk_poolinigb_adapter.Add enable/disable functions for TX and RX rings.
Add enable/disable functions for XSK pool.
Add xsk wakeup function.None of the above functionality will be active until
NETDEV_XDP_ACT_XSK_ZEROCOPYis advertised innetdev->xdp_features.Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Sriram Yagnaraman <[email protected]>Sriram's mail bounces unfortunately, is it possible to grab his current address?
His current email address is in the Cc list. However, i wasn't sure if it's okay to update the From and SoB of these patches?
Okay. Then I believe Sriram should provide a mailmap entry to map his old mail to a new one.
Quoted 6 lines
Quoted 3 lines
You could also update the copyright date in
igb_xsk.c.Ditto for the copyright. It probably has to be something like Copyright(c) 2023 Ericsson?
Quoted 6 lines
It says 2018 Intel. I don't think Sriram was working under E/// employment as he said he was forbidden to work on this further and that's why you picked it up, right?
My intent was not stir up the copyright pot, though. It can be left as-is or have something of a Linutronix/Sriram Yagnamaran mix :P
Let's see if Sriram has something to say about the copyright. If not i'll just leave this as-is.
Thanks,
Kurt
RE: [PATCH iwl-next v6 4/6] igb: Introduce XSK data structures and helpers
In reply to Maciej FijalkowskiQuoted 42 lines
-----Original Message-----
From: Maciej Fijalkowski <[email protected]>
Sent: Monday, 19 August 2024 16:11
To: Kurt Kanzenbach <[email protected]>
Cc: Tony Nguyen <[email protected]>; Przemek Kitszel <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Alexei Starovoitov <[email protected]>; Daniel Borkmann <[email protected]>; Jesper Dangaard Brouer <[email protected]>; John Fastabend <[email protected]>; Richard Cochran <[email protected]>; Sriram Yagnaraman <[email protected]>; Benjamin Steinke <[email protected]>; Sebastian Andrzej Siewior <[email protected]>; [email protected]; [email protected]; [email protected]; Sriram Yagnaraman <[email protected]>
Subject: Re: [PATCH iwl-next v6 4/6] igb: Introduce XSK data structures and helpersQuoted 20 lines · Kurt Kanzenbach
Quoted 9 lines · Maciej Fijalkowski
Quoted 8 lines · Kurt Kanzenbach
From: Sriram Yagnaraman <[email protected]>
Add the following ring flag:
-IGB_RING_FLAG_TX_DISABLED(when xsk pool is being setup)Add a
xdp_buffarray for use with XSK receive batch API, and a pointer toxsk_poolinigb_adapter.Quoted 6 lines
Quoted 6 lines
Add enable/disable functions for TX and RX rings.
Add enable/disable functions for XSK pool.
Add xsk wakeup function.None of the above functionality will be active until
NETDEV_XDP_ACT_XSK_ZEROCOPYis advertised in netdev-
xdp_features.Quoted 3 lines
Quoted 2 lines
Signed-off-by Sriram Yagnaraman <[email protected]>
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Sriram's mail bounces unfortunately, is it possible to grab his current address?
His current email address is in the Cc list. However, i wasn't sure if it's okay to update the From and SoB of these patches?
Okay. Then I believe Sriram should provide a mailmap entry to map his old mail to a new one.
Please feel free to remove my "est.tech" address from From: and Signed-of-By:
I am just glad that my work has not gone to waste. Thank you for that.
I will check with my company's *lawyers* to see if I can provide a mailmap to my current address :(
Quoted 19 lines
Quoted 7 lines
Quoted 4 lines
You could also update the copyright date in
igb_xsk.c.Ditto for the copyright. It probably has to be something like Copyright(c) 2023 Ericsson?
It says 2018 Intel. I don't think Sriram was working under E/// employment as he said he was forbidden to work on this further and that's why you picked it up, right?
My intent was not stir up the copyright pot, though. It can be left as-is or have something of a Linutronix/Sriram Yagnamaran mix :P
Quoted 3 lines
Thanks,
Kurt
RE: [PATCH iwl-next v6 4/6] igb: Introduce XSK data structures and helpers
Hi Sriram,
Quoted 43 lines · Sriram Yagnaraman
Quoted 43 lines
-----Original Message-----
From: Maciej Fijalkowski <[email protected]>
Sent: Monday, 19 August 2024 16:11
To: Kurt Kanzenbach <[email protected]>
Cc: Tony Nguyen <[email protected]>; Przemek Kitszel <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Alexei Starovoitov <[email protected]>; Daniel Borkmann <[email protected]>; Jesper Dangaard Brouer <[email protected]>; John Fastabend <[email protected]>; Richard Cochran <[email protected]>; Sriram Yagnaraman <[email protected]>; Benjamin Steinke <[email protected]>; Sebastian Andrzej Siewior <[email protected]>; [email protected]; [email protected]; [email protected]; Sriram Yagnaraman <[email protected]>
Subject: Re: [PATCH iwl-next v6 4/6] igb: Introduce XSK data structures and helpersQuoted 23 lines · Kurt Kanzenbach
Quoted 9 lines · Maciej Fijalkowski
Quoted 8 lines · Kurt Kanzenbach
From: Sriram Yagnaraman <[email protected]>
Add the following ring flag:
-IGB_RING_FLAG_TX_DISABLED(when xsk pool is being setup)Add a
xdp_buffarray for use with XSK receive batch API, and a pointer toxsk_poolinigb_adapter.Quoted 6 lines
Quoted 6 lines
Add enable/disable functions for TX and RX rings.
Add enable/disable functions for XSK pool.
Add xsk wakeup function.None of the above functionality will be active until
NETDEV_XDP_ACT_XSK_ZEROCOPYis advertised in netdev-
xdp_features.Quoted 5 lines
Quoted 2 lines
Signed-off-by Sriram Yagnaraman <[email protected]>Sriram's mail bounces unfortunately, is it possible to grab his current address?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
His current email address is in the Cc list. However, i wasn't sure if it's okay to update the From and SoB of these patches?
Okay. Then I believe Sriram should provide a mailmap entry to map his old mail to a new one.
Please feel free to remove my "est.tech" address from From: and Signed-of-By:
Ok, I'll replace your est.tech email address with your ericsson one in all patches. Or do you have a personal address (like gmail), which you prefer?
What about the copyright in igb_xsk.c? Does it belong to you, or Intel or to your previous employer?
Quoted 1 line
I am just glad that my work has not gone to waste. Thank you for that.
You're welcome.
Quoted 2 lines
I will check with my company's *lawyers* to see if I can provide a mailmap to my current address :(
Good luck with that :-).
Thanks,
Kurt
RE: [PATCH iwl-next v6 4/6] igb: Introduce XSK data structures and helpers
Quoted 52 lines
Hi Sriram,
Quoted 49 lines · Sriram Yagnaraman
Quoted 48 lines
-----Original Message-----
From: Maciej Fijalkowski <[email protected]>
Sent: Monday, 19 August 2024 16:11
To: Kurt Kanzenbach <[email protected]>
Cc: Tony Nguyen <[email protected]>; Przemek Kitszel <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Alexei Starovoitov <[email protected]>; Daniel Borkmann <[email protected]>; Jesper Dangaard Brouer <[email protected]>; John Fastabend <[email protected]>; Richard Cochran <[email protected]>; Sriram Yagnaraman <[email protected]>; Benjamin Steinke <[email protected]>; Sebastian Andrzej Siewior <[email protected]>; [email protected]; [email protected]; [email protected]; Sriram Yagnaraman <[email protected]>
Subject: Re: [PATCH iwl-next v6 4/6] igb: Introduce XSK data structures and helpersQuoted 18 lines · Kurt Kanzenbach
Quoted 9 lines · Maciej Fijalkowski
Quoted 8 lines · Kurt Kanzenbach
From: Sriram Yagnaraman <[email protected]>
Add the following ring flag:
-IGB_RING_FLAG_TX_DISABLED(when xsk pool is being setup)Add a
xdp_buffarray for use with XSK receive batch API, and a pointer toxsk_poolinigb_adapter.Quoted 6 lines
Quoted 6 lines
Add enable/disable functions for TX and RX rings.
Add enable/disable functions for XSK pool.
Add xsk wakeup function.None of the above functionality will be active until
NETDEV_XDP_ACT_XSK_ZEROCOPYis advertised in netdev-
xdp_features.Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Sriram Yagnaraman <[email protected]>Sriram's mail bounces unfortunately, is it possible to grab his current address?
His current email address is in the Cc list. However, i wasn't sure if it's okay to update the From and SoB of these patches?
Okay. Then I believe Sriram should provide a mailmap entry to map his old mail to a new one.
Quoted 6 lines
Quoted 2 lines
Please feel free to remove my "est.tech" address from From: and Signed-of-By:
Ok, I'll replace your est.tech email address with your ericsson one in all patches. Or do you have a personal address (like gmail), which you prefer?
Personal mail is probably best choice.
Quoted 15 lines
What about the copyright in
igb_xsk.c? Does it belong to you, or Intel or to your previous employer?Quoted 1 line
I am just glad that my work has not gone to waste. Thank you for that.
You're welcome.
Quoted 2 lines
I will check with my company's *lawyers* to see if I can provide a mailmap to my current address :(
Good luck with that :-).
Thanks,
Kurt
PATCH v6 5/6 igb: Add AF_XDP zero-copy Rx support
In reply to Kurt KanzenbachFrom: Sriram Yagnaraman <[email protected]>
Add support for AF_XDP zero-copy receive path.
When AF_XDP zero-copy is enabled, the rx buffers are allocated from the xsk buff pool using igb_alloc_rx_buffers_zc().
Use xsk_pool_get_rx_frame_size() to set SRRCTL rx buf size when zero-copy is enabled.
[Kurt: Port to v6.10 and provide napi_id for xdp_rxq_info_reg(),
RCT, remove NETDEV_XDP_ACT_XSK_ZEROCOPY, update NTC handling, move stats update and xdp finalize to common functions, READ_ONCE() xsk_pool, likelyfy for XDP_REDIRECT case]
--- drivers/net/ethernet/intel/igb/igb.h | 8 + drivers/net/ethernet/intel/igb/igb_main.c | 132 +++++++++---- drivers/net/ethernet/intel/igb/igb_xsk.c | 297 +++++++++++++++++++++++++++++- 3 files changed, 399 insertions(+), 38 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +8 -0
@@ -87,6 +87,7 @@ struct igb_adapter;#define IGB_XDP_CONSUMED BIT(0)#define IGB_XDP_TX BIT(1)#define IGB_XDP_REDIR BIT(2) +#define IGB_XDP_EXIT BIT(3)struct vf_data_storage {unsigned char vf_mac_addresses[ETH_ALEN ];
@@ -741,6 +742,9 @@ void igb_clean_tx_ring(struct igb_ring *tx_ring);void igb_clean_rx_ring (struct igb_ring *rx_ring);void igb_configure_tx_ring (struct igb_adapter *,struct igb_ring *);void igb_configure_rx_ring (struct igb_adapter *,struct igb_ring *); +void igb_finalize_xdp (struct igb_adapter *adapter,unsigned int status); +void igb_update_rx_stats (struct igb_q_vector *q_vector,unsigned int packets, +unsigned int bytes);void igb_setup_tctl (struct igb_adapter *);void igb_setup_rctl (struct igb_adapter *);void igb_setup_srrctl (struct igb_adapter *,struct igb_ring *);
@@ -829,6 +833,10 @@ struct xsk_buff_pool *igb_xsk_pool(struct igb_adapter *adapter,int igb_xsk_pool_setup (struct igb_adapter *adapter,struct xsk_buff_pool *pool,u16 qid); +bool igb_alloc_rx_buffers_zc (struct igb_ring *rx_ring,u16 count); +void igb_clean_rx_ring_zc (struct igb_ring *rx_ring); +int igb_clean_rx_irq_zc (struct igb_q_vector *q_vector, +struct xsk_buff_pool *xsk_pool,const int budget);int igb_xsk_wakeup (struct net_device *dev,u32 qid,u32 flags);#endif /* _IGB_H_ */
drivers/net/ethernet/intel/igb/igb_main.c +95 -37
234 lines not on this page · raw message
drivers/net/ethernet/intel/igb/igb_xsk.c +296 -1
309 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH iwl-next v6 5/6] igb: Add AF_XDP zero-copy Rx support
Quoted 449 lines · Kurt Kanzenbach
From: Sriram Yagnaraman <[email protected]>
Add support for
AF_XDPzero-copy receive path.When
AF_XDPzero-copy is enabled, the rx buffers are allocated from the xsk buff pool usingigb_alloc_rx_buffers_zc().Use
xsk_pool_get_rx_frame_size()to set SRRCTL rx buf size when zero-copy is enabled.Signed-off-by Sriram Yagnaraman <[email protected]>[Kurt: Port to v6.10 and provide
napi_idforxdp_rxq_info_reg(),
RCT, removeNETDEV_XDP_ACT_XSK_ZEROCOPY, update NTC handling, move stats update and xdp finalize to common functions,READ_ONCE()xsk_pool, likelyfy forXDP_REDIRECTcase]Signed-off-by Kurt Kanzenbach <[email protected]>--- drivers/net/ethernet/intel/igb/igb.h | 8 + drivers/net/ethernet/intel/igb/igb_main.c | 132 +++++++++---- drivers/net/ethernet/intel/igb/igb_xsk.c | 297 +++++++++++++++++++++++++++++- 3 files changed, 399 insertions(+), 38 deletions(-)drivers/net/ethernet/intel/igb/igb.h +8
-0@@ -87,6 +87,7 @@ struct igb_adapter;#define IGB_XDP_CONSUMED BIT(0)#define IGB_XDP_TX BIT(1)#define IGB_XDP_REDIR BIT(2) +#define IGB_XDP_EXIT BIT(3)struct vf_data_storage {unsigned char vf_mac_addresses[ETH_ALEN ];@@ -741,6 +742,9 @@ void igb_clean_tx_ring(struct igb_ring *tx_ring);void igb_clean_rx_ring (struct igb_ring *rx_ring);void igb_configure_tx_ring (struct igb_adapter *,struct igb_ring *);void igb_configure_rx_ring (struct igb_adapter *,struct igb_ring *); +void igb_finalize_xdp (struct igb_adapter *adapter,unsigned int status); +void igb_update_rx_stats (struct igb_q_vector *q_vector,unsigned int packets, +unsigned int bytes);void igb_setup_tctl (struct igb_adapter *);void igb_setup_rctl (struct igb_adapter *);void igb_setup_srrctl (struct igb_adapter *,struct igb_ring *);@@ -829,6 +833,10 @@ struct xsk_buff_pool *igb_xsk_pool(struct igb_adapter *adapter,int igb_xsk_pool_setup (struct igb_adapter *adapter,struct xsk_buff_pool *pool,u16 qid); +bool igb_alloc_rx_buffers_zc (struct igb_ring *rx_ring,u16 count); +void igb_clean_rx_ring_zc (struct igb_ring *rx_ring); +int igb_clean_rx_irq_zc (struct igb_q_vector *q_vector, +struct xsk_buff_pool *xsk_pool,const int budget);int igb_xsk_wakeup (struct net_device *dev,u32 qid,u32 flags);#endif /* _IGB_H_ */ drivers/net/ethernet/intel/igb/igb_main.c +95
-37@@ -472,12 +472,17 @@ static void igb_dump(struct igb_adapter *adapter)for (i =0 ; i < rx_ring->count; i++) {const char *next_desc; -struct igb_rx_buffer *buffer_info; - buffer_info = &rx_ring->rx_buffer_info[i]; +dma_addr_t dma = (dma_addr_t )0 ; +struct igb_rx_buffer *buffer_info =NULL ; rx_desc =IGB_RX_DESC (rx_ring, i); u0 = (struct my_u0 *)rx_desc; staterr =le32_to_cpu (rx_desc->wb.upper.status_error); +if (!rx_ring->xsk_pool) { + buffer_info = &rx_ring->rx_buffer_info[i]; + dma = buffer_info->dma; + } +if (i == rx_ring->next_to_use) next_desc =" NTU" ;else if (i == rx_ring->next_to_clean)@@ -497,11 +502,11 @@ static void igb_dump(struct igb_adapter *adapter)"R " , i,le64_to_cpu (u0->a),le64_to_cpu (u0->b), - (u64 )buffer_info->dma, + (u64 )dma, next_desc);if (netif_msg_pktdata (adapter) && - buffer_info->dma && buffer_info->page) { + buffer_info && dma && buffer_info->page) { print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 16, 1,@@ -1983,7 +1988,10 @@ static void igb_configure(struct igb_adapter *adapter)*/ for (i =0 ; i < adapter->num_rx_queues; i++) {struct igb_ring *ring = adapter->rx_ring[i]; -igb_alloc_rx_buffers (ring,igb_desc_unused (ring)); +if (ring->xsk_pool) +igb_alloc_rx_buffers_zc (ring,igb_desc_unused (ring)); +else +igb_alloc_rx_buffers (ring,igb_desc_unused (ring)); } }@@ -4425,7 +4433,8 @@ int igb_setup_rx_resources(struct igb_ring *rx_ring)if (xdp_rxq_info_is_reg (&rx_ring->xdp_rxq))xdp_rxq_info_unreg (&rx_ring->xdp_rxq); res =xdp_rxq_info_reg (&rx_ring->xdp_rxq, rx_ring->netdev, - rx_ring->queue_index,0 ); + rx_ring->queue_index, + rx_ring->q_vector->napi.napi_id);if (res <0 ) {dev_err (dev,"Failed to register xdp_rxq index %u\n" , rx_ring->queue_index);@@ -4721,12 +4730,17 @@ void igb_setup_srrctl(struct igb_adapter *adapter, struct igb_ring *ring)struct e1000_hw *hw = &adapter->hw;int reg_idx = ring->reg_idx;u32 srrctl =0 ; +u32 buf_size; - srrctl =IGB_RX_HDR_LEN <<E1000_SRRCTL_BSIZEHDRSIZE_SHIFT ; -if (ring_uses_large_buffer (ring)) - srrctl |=IGB_RXBUFFER_3072 >>E1000_SRRCTL_BSIZEPKT_SHIFT ; +if (ring->xsk_pool) + buf_size =xsk_pool_get_rx_frame_size (ring->xsk_pool); +else if (ring_uses_large_buffer (ring)) + buf_size =IGB_RXBUFFER_3072 ;else - srrctl |=IGB_RXBUFFER_2048 >>E1000_SRRCTL_BSIZEPKT_SHIFT ; + buf_size =IGB_RXBUFFER_2048 ; + + srrctl =IGB_RX_HDR_LEN <<E1000_SRRCTL_BSIZEHDRSIZE_SHIFT ; + srrctl |= buf_size >>E1000_SRRCTL_BSIZEPKT_SHIFT ; srrctl |=E1000_SRRCTL_DESCTYPE_ADV_ONEBUF ;if (hw->mac.type >= e1000_82580) srrctl |=E1000_SRRCTL_TIMESTAMP ;@@ -4758,9 +4772,17 @@ void igb_configure_rx_ring(struct igb_adapter *adapter,u32 rxdctl =0 ;xdp_rxq_info_unreg_mem_model (&ring->xdp_rxq); -WARN_ON (xdp_rxq_info_reg_mem_model (&ring->xdp_rxq, -MEM_TYPE_PAGE_SHARED ,NULL ));WRITE_ONCE (ring->xsk_pool,igb_xsk_pool (adapter, ring)); +if (ring->xsk_pool) { +WARN_ON (xdp_rxq_info_reg_mem_model (&ring->xdp_rxq, +MEM_TYPE_XSK_BUFF_POOL , +NULL )); +xsk_pool_set_rxq_info (ring->xsk_pool, &ring->xdp_rxq); + }else { +WARN_ON (xdp_rxq_info_reg_mem_model (&ring->xdp_rxq, +MEM_TYPE_PAGE_SHARED , +NULL )); + }/* disable the queue */ wr32 (E1000_RXDCTL (reg_idx),0 );@@ -4787,9 +4809,12 @@ void igb_configure_rx_ring(struct igb_adapter *adapter, rxdctl |=IGB_RX_HTHRESH <<8 ; rxdctl |=IGB_RX_WTHRESH <<16 ; -/* initialize rx_buffer_info */ -memset (ring->rx_buffer_info,0 , -sizeof (struct igb_rx_buffer ) * ring->count); +if (ring->xsk_pool) +memset (ring->rx_buffer_info_zc,0 , +sizeof (*ring->rx_buffer_info_zc) * ring->count); +else +memset (ring->rx_buffer_info,0 , +sizeof (*ring->rx_buffer_info) * ring->count);/* initialize Rx descriptor 0 */ rx_desc =IGB_RX_DESC (ring,0 );@@ -4976,8 +5001,13 @@ void igb_free_rx_resources(struct igb_ring *rx_ring) rx_ring->xdp_prog =NULL ;xdp_rxq_info_unreg (&rx_ring->xdp_rxq); -vfree (rx_ring->rx_buffer_info); - rx_ring->rx_buffer_info =NULL ; +if (rx_ring->xsk_pool) { +vfree (rx_ring->rx_buffer_info_zc); + rx_ring->rx_buffer_info_zc =NULL ; + }else { +vfree (rx_ring->rx_buffer_info); + rx_ring->rx_buffer_info =NULL ; + }/* if not set, then don't free */ if (!rx_ring->desc)@@ -5015,6 +5045,11 @@ void igb_clean_rx_ring(struct igb_ring *rx_ring)dev_kfree_skb (rx_ring->skb); rx_ring->skb =NULL ; +if (rx_ring->xsk_pool) { +igb_clean_rx_ring_zc (rx_ring); + goto skip_for_xsk; + } +/* Free all the Rx ring sk_buffs */ while (i != rx_ring->next_to_alloc) {struct igb_rx_buffer *buffer_info = &rx_ring->rx_buffer_info[i];@@ -5042,6 +5077,7 @@ void igb_clean_rx_ring(struct igb_ring *rx_ring) i =0 ; } +skip_for_xsk: rx_ring->next_to_alloc =0 ; rx_ring->next_to_clean =0 ; rx_ring->next_to_use =0 ;@@ -8186,6 +8222,7 @@ static int igb_poll(struct napi_struct *napi, int budget)struct igb_q_vector *q_vector =container_of (napi, struct igb_q_vector, napi); +struct xsk_buff_pool *xsk_pool;bool clean_complete = true;int work_done =0 ;@@ -8197,7 +8234,12 @@ static int igb_poll(struct napi_struct *napi, int budget) clean_complete =igb_clean_tx_irq (q_vector, budget);if (q_vector->rx.ring) { -int cleaned =igb_clean_rx_irq (q_vector, budget); +int cleaned; + + xsk_pool =READ_ONCE (q_vector->rx.ring->xsk_pool); + cleaned = xsk_pool ? +igb_clean_rx_irq_zc (q_vector, xsk_pool, budget) : +igb_clean_rx_irq (q_vector, budget); work_done += cleaned;if (cleaned >= budget)@@ -8861,6 +8903,38 @@ static void igb_put_rx_buffer(struct igb_ring *rx_ring, rx_buffer->page =NULL ; } +void igb_finalize_xdp (struct igb_adapter *adapter,unsigned int status) +{ +int cpu =smp_processor_id (); +struct netdev_queue *nq; + +if (status &IGB_XDP_REDIR ) +xdp_do_flush (); + +if (status &IGB_XDP_TX ) { +struct igb_ring *tx_ring =igb_xdp_tx_queue_mapping (adapter); + + nq =txring_txq (tx_ring); +__netif_tx_lock (nq, cpu); +igb_xdp_ring_update_tail (tx_ring); +__netif_tx_unlock (nq); + } +} + +void igb_update_rx_stats (struct igb_q_vector *q_vector,unsigned int packets, +unsigned int bytes) +{ +struct igb_ring *ring = q_vector->rx.ring; + +u64_stats_update_begin (&ring->rx_syncp); + ring->rx_stats.packets += packets; + ring->rx_stats.bytes += bytes; +u64_stats_update_end (&ring->rx_syncp); + + q_vector->rx.total_packets += packets; + q_vector->rx.total_bytes += bytes; +} +static int igb_clean_rx_irq (struct igb_q_vector *q_vector,const int budget) {unsigned int total_bytes =0 , total_packets =0 ;@@ -8868,9 +8942,7 @@ static int igb_clean_rx_irq(struct igb_q_vector *q_vector, const int budget)struct igb_ring *rx_ring = q_vector->rx.ring;u16 cleaned_count =igb_desc_unused (rx_ring);struct sk_buff *skb = rx_ring->skb; -int cpu =smp_processor_id ();unsigned int xdp_xmit =0 ; -struct netdev_queue *nq;struct xdp_buff xdp;u32 frame_sz =0 ;int rx_buf_pgcnt;@@ -8992,24 +9064,10 @@ static int igb_clean_rx_irq(struct igb_q_vector *q_vector, const int budget)/* place incomplete frames back on ring for completion */ rx_ring->skb = skb; -if (xdp_xmit &IGB_XDP_REDIR ) -xdp_do_flush (); - -if (xdp_xmit &IGB_XDP_TX ) { -struct igb_ring *tx_ring =igb_xdp_tx_queue_mapping (adapter); - - nq =txring_txq (tx_ring); -__netif_tx_lock (nq, cpu); -igb_xdp_ring_update_tail (tx_ring); -__netif_tx_unlock (nq); - } +if (xdp_xmit) +igb_finalize_xdp (adapter, xdp_xmit); -u64_stats_update_begin (&rx_ring->rx_syncp); - rx_ring->rx_stats.packets += total_packets; - rx_ring->rx_stats.bytes += total_bytes; -u64_stats_update_end (&rx_ring->rx_syncp); - q_vector->rx.total_packets += total_packets; - q_vector->rx.total_bytes += total_bytes; +igb_update_rx_stats (q_vector, total_packets, total_bytes);if (cleaned_count)igb_alloc_rx_buffers (rx_ring, cleaned_count);drivers/net/ethernet/intel/igb/igb_xsk.c +125
-1@@ -70,7 +70,10 @@ static void igb_txrx_ring_enable(struct igb_adapter *adapter, u16 qid)* at least 1 descriptor unused to make sure * next_to_use != next_to_clean */ -igb_alloc_rx_buffers (rx_ring,igb_desc_unused (rx_ring)); +if (rx_ring->xsk_pool) +igb_alloc_rx_buffers_zc (rx_ring,igb_desc_unused (rx_ring)); +else +igb_alloc_rx_buffers (rx_ring,igb_desc_unused (rx_ring));/* Rx/Tx share the same napi context. */ napi_enable (&rx_ring->q_vector->napi);@@ -169,6 +172,298 @@ int igb_xsk_pool_setup(struct igb_adapter *adapter,igb_xsk_pool_disable (adapter, qid); } +static u16 igb_fill_rx_descs (struct xsk_buff_pool *pool,struct xdp_buff **xdp, +union e1000_adv_rx_desc *rx_desc,u16 count) +{ +dma_addr_t dma; +u16 buffs; +int i; + +/* nothing to do */ +if (!count) +return 0 ; + + buffs =xsk_buff_alloc_batch (pool, xdp, count); +for (i =0 ; i < buffs; i++) { + dma =xsk_buff_xdp_get_dma (*xdp); + rx_desc->read.pkt_addr =cpu_to_le64 (dma); + rx_desc->wb.upper.length =0 ; + + rx_desc++; + xdp++; + } + +return buffs; +} + +bool igb_alloc_rx_buffers_zc (struct igb_ring *rx_ring,u16 count) +{ +u32 nb_buffs_extra =0 , nb_buffs =0 ; +union e1000_adv_rx_desc *rx_desc; +u16 ntu = rx_ring->next_to_use; +u16 total_count = count; +struct xdp_buff **xdp; + + rx_desc =IGB_RX_DESC (rx_ring, ntu); + xdp = &rx_ring->rx_buffer_info_zc[ntu]; + +if (ntu + count >= rx_ring->count) { + nb_buffs_extra =igb_fill_rx_descs (rx_ring->xsk_pool, xdp, + rx_desc, + rx_ring->count - ntu); +if (nb_buffs_extra != rx_ring->count - ntu) { + ntu += nb_buffs_extra; + goto exit; + } + rx_desc =IGB_RX_DESC (rx_ring,0 ); + xdp = rx_ring->rx_buffer_info_zc; + ntu =0 ; + count -= nb_buffs_extra; + } + + nb_buffs =igb_fill_rx_descs (rx_ring->xsk_pool, xdp, rx_desc, count); + ntu += nb_buffs; +if (ntu == rx_ring->count) + ntu =0 ; + +/* clear the length for the next_to_use descriptor */ + rx_desc =IGB_RX_DESC (rx_ring, ntu); + rx_desc->wb.upper.length =0 ; + +exit: +if (rx_ring->next_to_use != ntu) { + rx_ring->next_to_use = ntu; + +/* Force memory writes to complete before letting h/w +* know there are new descriptors to fetch. (Only +* applicable for weak-ordered memory model archs, +* such as IA-64). +*/ +wmb (); +writel (ntu, rx_ring->tail); + } + +return total_count == (nb_buffs + nb_buffs_extra); +} + +void igb_clean_rx_ring_zc (struct igb_ring *rx_ring) +{ +u16 ntc = rx_ring->next_to_clean; +u16 ntu = rx_ring->next_to_use; + +while (ntc != ntu) { +struct xdp_buff *xdp = rx_ring->rx_buffer_info_zc[ntc]; + +xsk_buff_free (xdp); + ntc++; +if (ntc >= rx_ring->count) + ntc =0 ; + } +} + +static struct sk_buff *igb_construct_skb_zc (struct igb_ring *rx_ring, +struct xdp_buff *xdp, +ktime_t timestamp) +{ +unsigned int totalsize = xdp->data_end - xdp->data_meta; +unsigned int metasize = xdp->data - xdp->data_meta; +struct sk_buff *skb; + +net_prefetch (xdp->data_meta); + +/* allocate a skb to store the frags */ + skb =napi_alloc_skb (&rx_ring->q_vector->napi, totalsize); +if (unlikely (!skb)) +return NULL ; + +if (timestamp) +skb_hwtstamps (skb)->hwtstamp = timestamp; + +memcpy (__skb_put (skb, totalsize), xdp->data_meta, +ALIGN (totalsize,sizeof (long ))); + +if (metasize) { +skb_metadata_set (skb, metasize); +__skb_pull (skb, metasize); + } + +return skb; +} + +static struct sk_buff *igb_run_xdp_zc(struct igb_adapter *adapter, + struct igb_ring *rx_ring, + struct xdp_buff *xdp,
drivers/net/ethernet/intel/igb/igb_xsk.c int igb_xsk_pool_setup(struct igb_adapter *adapter, · line 305
Quoted 10 lines
drivers/net/ethernet/intel/igb/igb_xsk.c +10
-0+ struct xsk_buff_pool *xsk_pool) +{ +int err, result =IGB_XDP_PASS ; +struct bpf_prog *xdp_prog; +u32 act; + + xdp_prog =READ_ONCE (rx_ring->xdp_prog); + +if (!xdp_prog) + goto xdp_out;
Reading prog per packet is inefficient plus pool pointer is only valid (non-null) when prog is also non-null. This means null prog for ZC path will not happen as you trigger it for non-null pool pointer state.
Therefore please read prog one time at the beginning of rx zc clean routine and use it for current napi instance.
Quoted 40 lines
drivers/net/ethernet/intel/igb/igb_xsk.c +40
-0+ +prefetchw (xdp->data_hard_start);/* xdp_frame write */ + + act =bpf_prog_run_xdp (xdp_prog, xdp); + +if (likely (act ==XDP_REDIRECT )) { + err =xdp_do_redirect (adapter->netdev, xdp, xdp_prog); +if (!err) { + result =IGB_XDP_REDIR ; + goto xdp_out; + } + +if (xsk_uses_need_wakeup (xsk_pool) && + err == -ENOBUFS ) + result =IGB_XDP_EXIT ; +else + result =IGB_XDP_CONSUMED ; + goto out_failure; + } + +switch (act) { +case XDP_PASS : +break ; +case XDP_TX : + result =igb_xdp_xmit_back (adapter, xdp); +if (result ==IGB_XDP_CONSUMED ) + goto out_failure; +break ; +default : +bpf_warn_invalid_xdp_action (adapter->netdev, xdp_prog, act); + fallthrough; +case XDP_ABORTED : +out_failure: +trace_xdp_exception (rx_ring->netdev, xdp_prog, act); + fallthrough; +case XDP_DROP : + result =IGB_XDP_CONSUMED ; +break ; + } +xdp_out:
drivers/net/ethernet/intel/igb/igb_xsk.c int igb_xsk_pool_setup(struct igb_adapter *adapter, · line 355
Quoted 10 lines
drivers/net/ethernet/intel/igb/igb_xsk.c +10
-0+return ERR_PTR (-result); +} + +int igb_clean_rx_irq_zc (struct igb_q_vector *q_vector, +struct xsk_buff_pool *xsk_pool,const int budget) +{ +struct igb_adapter *adapter = q_vector->adapter; +unsigned int total_bytes =0 , total_packets =0 ; +struct igb_ring *rx_ring = q_vector->rx.ring; +u16 ntc = rx_ring->next_to_clean;
I believe that at some point we said to avoid stack-based variables smaller than 4 bytes as it requires the compiler to produce more (unnecessary) insns. please just use u32 here.
Quoted 118 lines
drivers/net/ethernet/intel/igb/igb_xsk.c +111
-0+unsigned int xdp_xmit =0 ; +bool failure = false; +u16 entries_to_alloc; +struct sk_buff *skb; + +while (likely (total_packets < budget)) { +union e1000_adv_rx_desc *rx_desc; +ktime_t timestamp =0 ; +struct xdp_buff *xdp; +unsigned int size; + + rx_desc =IGB_RX_DESC (rx_ring, ntc); + size =le16_to_cpu (rx_desc->wb.upper.length); +if (!size) +break ; + +/* This memory barrier is needed to keep us from reading +* any other fields out of the rx_desc until we know the +* descriptor has been written back +*/ +dma_rmb (); + + xdp = rx_ring->rx_buffer_info_zc[ntc]; +xsk_buff_set_size (xdp, size); +xsk_buff_dma_sync_for_cpu (xdp); + +/* pull rx packet timestamp if available and valid */ +if (igb_test_staterr (rx_desc,E1000_RXDADV_STAT_TSIP )) { +int ts_hdr_len; + + ts_hdr_len =igb_ptp_rx_pktstamp (rx_ring->q_vector, + xdp->data, + ×tamp); + + xdp->data += ts_hdr_len; + xdp->data_meta += ts_hdr_len; + size -= ts_hdr_len; + } + + skb =igb_run_xdp_zc (adapter, rx_ring, xdp, xsk_pool); + +if (IS_ERR (skb)) { +unsigned int xdp_res = -PTR_ERR (skb); + +if (likely (xdp_res & (IGB_XDP_TX |IGB_XDP_REDIR ))) { + xdp_xmit |= xdp_res; + }else if (xdp_res ==IGB_XDP_EXIT ) { + failure = true; +break ; + }else if (xdp_res ==IGB_XDP_CONSUMED ) { +xsk_buff_free (xdp); + } + + total_packets++; + total_bytes += size; + ntc++; +if (ntc == rx_ring->count) + ntc =0 ; +continue ; + } + + skb =igb_construct_skb_zc (rx_ring, xdp, timestamp); + +/* exit if we failed to retrieve a buffer */ +if (!skb) { + rx_ring->rx_stats.alloc_failed++; +break ; + } + +xsk_buff_free (xdp); + ntc++; +if (ntc == rx_ring->count) + ntc =0 ; + +if (eth_skb_pad (skb)) +continue ; + +/* probably a little skewed due to removing CRC */ + total_bytes += skb->len; + +/* populate checksum, timestamp, VLAN, and protocol */ +igb_process_skb_fields (rx_ring, rx_desc, skb); + +napi_gro_receive (&q_vector->napi, skb); + +/* update budget accounting */ + total_packets++; + } + + rx_ring->next_to_clean = ntc; + +if (xdp_xmit) +igb_finalize_xdp (adapter, xdp_xmit); + +igb_update_rx_stats (q_vector, total_packets, total_bytes); + + entries_to_alloc =igb_desc_unused (rx_ring); +if (entries_to_alloc >=IGB_RX_BUFFER_WRITE ) + failure |= !igb_alloc_rx_buffers_zc (rx_ring, entries_to_alloc); + +if (xsk_uses_need_wakeup (xsk_pool)) { +if (failure || rx_ring->next_to_clean == rx_ring->next_to_use) +xsk_set_rx_need_wakeup (xsk_pool); +else +xsk_clear_rx_need_wakeup (xsk_pool); + +return (int )total_packets; + } +return failure ? budget : (int )total_packets; +} +int igb_xsk_wakeup (struct net_device *dev,u32 qid,u32 flags) {struct igb_adapter *adapter =netdev_priv (dev);Signature · 2 lines
-- 2.39.2
PATCH v6 6/6 igb: Add AF_XDP zero-copy Tx support
In reply to Kurt KanzenbachFrom: Sriram Yagnaraman <[email protected]>
Add support for AF_XDP zero-copy transmit path.
A new TX buffer type IGB_TYPE_XSK is introduced to indicate that the Tx frame was allocated from the xsk buff pool, so igb_clean_tx_ring() and igb_clean_tx_irq() can clean the buffers correctly based on type.
igb_xmit_zc() performs the actual packet transmit when AF_XDP zero-copy is enabled. We share the TX ring between slow path, XDP and AF_XDP zero-copy, so we use the netdev queue lock to ensure mutual exclusion.
[Kurt: Set olinfo_status in igb_xmit_zc() so that frames are transmitted,
Use READ_ONCE() for xsk_pool and check Tx disabled and carrier in igb_xmit_zc()]
--- drivers/net/ethernet/intel/igb/igb.h | 2 + drivers/net/ethernet/intel/igb/igb_main.c | 61 ++++++++++++++++++++++++++----- drivers/net/ethernet/intel/igb/igb_xsk.c | 59 ++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 10 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +2 -0
@@ -257,6 +257,7 @@ enum igb_tx_flags {enum igb_tx_buf_type {IGB_TYPE_SKB =0 ,IGB_TYPE_XDP , +IGB_TYPE_XSK };/* wrapper around a pointer to a socket buffer,
@@ -837,6 +838,7 @@ bool igb_alloc_rx_buffers_zc(struct igb_ring *rx_ring, u16 count);void igb_clean_rx_ring_zc (struct igb_ring *rx_ring);int igb_clean_rx_irq_zc (struct igb_q_vector *q_vector,struct xsk_buff_pool *xsk_pool,const int budget); +bool igb_xmit_zc (struct igb_ring *tx_ring);int igb_xsk_wakeup (struct net_device *dev,u32 qid,u32 flags);#endif /* _IGB_H_ */
drivers/net/ethernet/intel/igb/igb_main.c +51 -10
139 lines not on this page · raw message
drivers/net/ethernet/intel/igb/igb_xsk.c +59 -0
65 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH iwl-next v6 6/6] igb: Add AF_XDP zero-copy Tx support
Quoted 16 lines · Kurt Kanzenbach
From: Sriram Yagnaraman <[email protected]>
Add support for
AF_XDPzero-copy transmit path.A new TX buffer type
IGB_TYPE_XSKis introduced to indicate that the Tx frame was allocated from the xsk buff pool, soigb_clean_tx_ring()andigb_clean_tx_irq()can clean the buffers correctly based on type.
igb_xmit_zc()performs the actual packet transmit whenAF_XDPzero-copy is enabled. We share the TX ring between slow path, XDP andAF_XDPzero-copy, so we use the netdev queue lock to ensure mutual exclusion.Signed-off-by Sriram Yagnaraman <[email protected]>[Kurt: Set
olinfo_statusinigb_xmit_zc()so that frames are transmitted,
UseREAD_ONCE()forxsk_pooland check Tx disabled and carrier inigb_xmit_zc()]
Quoted 7 lines
Signed-off-by Kurt Kanzenbach <[email protected]>--- drivers/net/ethernet/intel/igb/igb.h | 2 + drivers/net/ethernet/intel/igb/igb_main.c | 61 ++++++++++++++++++++++++++----- drivers/net/ethernet/intel/igb/igb_xsk.c | 59 ++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 10 deletions(-)
Quoted 6 lines · Kurt Kanzenbach
This is version 6 of the
AF_XDPzero-copy support for igb. Since Sriram's duties changed I am sending this instead. Additionally, I've tested this on real hardware, Intel i210 [1].Changes since v5:
Quoted 13 lines
- Rebase to 6.11
- Fix set-but-unused variable warnings
- Split first patches (Maciej)
- Add READ/WRITE_ONCE() forxsk_poolandxdp_prog(Maciej)
- Addsynchronize_net()(Maciej)
- RemoveIGB_RING_FLAG_AF_XDP_ZC(Maciej)
- AddNETDEV_XDP_ACT_XSK_ZEROCOPYto last patch (Maciej)
- Update Rx ntc handling (Maciej)
- Move stats update and xdp finalize to common functions (Maciej)
- "Likelyfy"XDP_REDIRECTcase (Maciej)
- Check Tx disabled and carrier inigb_xmit_zc()(Maciej)
- RCT (Maciej)
- Link to v5: https://lore.kernel.org/r/[email protected]
I'll go through the set on monday.
Thanks!
Quoted 80 lines
Changes since v4:
- Rebase to v6.10
- Fix issue reported by kernel test robot
- Providenapi_idforxdp_rxq_info_reg()so that busy polling works
- Setolinfo_statusinigb_xmit_zc()so that frames are transmittedLink to v4: https://lore.kernel.org/intel-wired-lan/[email protected]/
[1] - https://github.com/Linutronix/TSN-Testbench/tree/main/tests/busypolling_i210
Original cover letter:
The first couple of patches adds helper funcctions to prepare for
AF_XDPzero-copy support which comes in the last couple of patches, one each for Rx and TX paths.As mentioned in v1 patchset [0], I don't have access to an actual IGB device to provide correct performance numbers. I have used Intel 82576EB emulator in QEMU [1] to test the changes to IGB driver.
The tests use one isolated vCPU for RX/TX and one isolated vCPU for the xdp-sock application [2]. Hope these measurements provide at the least some indication on the increase in performance when using ZC, especially in the TX path. It would be awesome if someone with a real IGB NIC can test the patch.
AF_XDPperformance using 64 byte packets in Kpps.
Benchmark: XDP-SKB XDP-DRV XDP-DRV(ZC)
rxdrop 220 235 350
txpush 1.000 1.000 410
l2fwd 1.000 1.000 200
AF_XDPperformance using 1500 byte packets in Kpps.
Benchmark: XDP-SKB XDP-DRV XDP-DRV(ZC)
rxdrop 200 210 310
txpush 1.000 1.000 410
l2fwd 0.900 1.000 160[0]: https://lore.kernel.org/intel-wired-lan/[email protected]/
[1]: https://www.qemu.org/docs/master/system/devices/igb.html
[2]: https://github.com/xdp-project/bpf-examples/tree/master/AF_XDP-example
v3->v4:
- NULL checkbuffer_infoinigb_dumpbefore dereferencing (Simon Horman)
v2->v3:
- Avoid TX unit hang when usingAF_XDPzero-copy by settingtime_stampon thetx_buffer_info
- Fix uninitializednb_buffs(Simon Horman)
v1->v2:
- Use batch XSK APIs (Maciej Fijalkowski)
- Follow reverse xmas tree convention and remove the ternary operator use (Simon Horman)---
Sriram Yagnaraman (6):
igb: Always calligb_xdp_ring_update_tail()under Tx lock
igb: Remove static qualifiers
igb: Introduceigb_xdp_is_enabled()
igb: Introduce XSK data structures and helpers
igb: AddAF_XDPzero-copy Rx support
igb: AddAF_XDPzero-copy Tx supportdrivers/net/ethernet/intel/igb/Makefile | 2 +- drivers/net/ethernet/intel/igb/igb.h | 36 +- drivers/net/ethernet/intel/igb/igb_main.c | 232 ++++++++---- drivers/net/ethernet/intel/igb/igb_xsk.c | 561 ++++++++++++++++++++++++++++++ 4 files changed, 770 insertions(+), 61 deletions(-)---
base-commit:e7d731326ef0622f103e5ed47d3405f71cdcd7f6
change-id: 20240711-b4-igb_zero_copy-bb70a31ecb0fBest regards,
Signature · 1 line
Kurt Kanzenbach <[email protected]>