Skip to contentSkip to conversation

igb: Add support for AF_XDP zero-copy

PATCH In review Sriram Yagnaraman 5 participants 12 messages Aug 4, 2023 – Jul 15, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v4 cover igb: Add support for AF_XDP zero-copy

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 (4):
igb: prepare for AF_XDP zero-copy support
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      |  35 +-
 drivers/net/ethernet/intel/igb/igb_main.c | 186 ++++++--
 drivers/net/ethernet/intel/igb/igb_xsk.c  | 522 ++++++++++++++++++++++
 4 files changed, 698 insertions(+), 47 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/igb/igb_xsk.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/4 igb: prepare for AF_XDP zero-copy support

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.

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_run_xdp
- igb_process_skb_fields

Introduce igb_xdp_is_enabled() to check if an XDP program is assigned to the device.

---
 drivers/net/ethernet/intel/igb/igb.h      | 15 ++++++++++++
 drivers/net/ethernet/intel/igb/igb_main.c | 29 +++++++++++------------
 2 files changed, 29 insertions(+), 15 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +15 -0
index 015b78144114..58e79eb69f92 100644
@@ -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,20 @@ 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 *);
+struct sk_buff *igb_run_xdp(struct igb_adapter *adapter,
+			    struct igb_ring *rx_ring,
+			    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);
@@ -797,6 +807,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 !!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 +14 -15
index 9a2561409b06..775c78df73fb 100644
@@ -117,8 +117,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 *);
@@ -2939,7 +2937,8 @@ static int igb_xdp(struct net_device *dev, struct netdev_bpf *xdp)
 	}
 }
 
-static void igb_xdp_ring_update_tail(struct igb_ring *ring)
+/* This function assumes __netif_tx_lock is held by the caller. */
+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.
@@ -2948,7 +2947,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();
 
@@ -3025,11 +3024,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;
 }
 
@@ -4897,7 +4896,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];
@@ -5016,7 +5015,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;
 
@@ -6631,7 +6630,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++) {
@@ -8600,9 +8599,9 @@ static struct sk_buff *igb_build_skb(struct igb_ring *rx_ring,
 	return skb;
 }
 
-static struct sk_buff *igb_run_xdp(struct igb_adapter *adapter,
-				   struct igb_ring *rx_ring,
-				   struct xdp_buff *xdp)
+struct sk_buff *igb_run_xdp(struct igb_adapter *adapter,
+			    struct igb_ring *rx_ring,
+			    struct xdp_buff *xdp)
 {
 	int err, result = IGB_XDP_PASS;
 	struct bpf_prog *xdp_prog;
@@ -8798,9 +8797,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.34.1
#2 lore raw

PATCH v4 2/4 igb: Introduce XSK data structures and helpers

In reply to Sriram Yagnaraman

Add the following ring flags
- IGB_RING_FLAG_TX_DISABLED (when xsk pool is being setup)
- IGB_RING_FLAG_AF_XDP_ZC (xsk pool is active)

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.

---
 drivers/net/ethernet/intel/igb/Makefile   |   2 +-
 drivers/net/ethernet/intel/igb/igb.h      |  14 +-
 drivers/net/ethernet/intel/igb/igb_main.c |   9 +
 drivers/net/ethernet/intel/igb/igb_xsk.c  | 210 ++++++++++++++++++++++
 4 files changed, 233 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/ethernet/intel/igb/igb_xsk.c
drivers/net/ethernet/intel/igb/Makefile +1 -1
index 394c1e0656b9..86d25dba507d 100644
@@ -8,4 +8,4 @@ obj-$(CONFIG_IGB) += igb.o
 
 igb-objs := 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 +13 -1
index 58e79eb69f92..1af1a0423fba 100644
@@ -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,9 @@ 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,
+	IGB_RING_FLAG_AF_XDP_ZC
 };
 
 #define ring_uses_large_buffer(ring) \
@@ -822,4 +827,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
index 775c78df73fb..2c1e1d70bcf9 100644
@@ -2929,9 +2929,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;
 	}
@@ -3058,6 +3063,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,
 };
 
 /**
@@ -4376,6 +4382,8 @@ void igb_configure_tx_ring(struct igb_adapter *adapter,
 	u64 tdba = ring->dma;
 	int reg_idx = ring->reg_idx;
 
+	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),
@@ -4771,6 +4779,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));
+	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 +210 -0

210 lines not on this page · raw message

Signature · 1 line
2.34.1
#3 lore raw

PATCH v4 3/4 igb: add AF_XDP zero-copy Rx support

In reply to Sriram Yagnaraman

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.

---
 drivers/net/ethernet/intel/igb/igb.h      |   4 +
 drivers/net/ethernet/intel/igb/igb_main.c |  92 ++++++--
 drivers/net/ethernet/intel/igb/igb_xsk.c  | 262 +++++++++++++++++++++-
 3 files changed, 336 insertions(+), 22 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +4 -0
index 1af1a0423fba..39202c40116a 100644
@@ -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];
@@ -832,6 +833,9 @@ 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, 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 +71 -21

192 lines not on this page · raw message

drivers/net/ethernet/intel/igb/igb_xsk.c +261 -1

274 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

Re: [Intel-wired-lan] [PATCH iwl-next v4 3/4] igb: add AF_XDP zero-copy Rx support

kernel test robot noticed the following build warnings:

Hi Sriram,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tnguy-next-queue/dev-queue]

url:    https://github.com/intel-lab-lkp/linux/commits/Sriram-Yagnaraman/igb-prepare-for-AF_XDP-zero-copy-support/20230804-164354
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue.git dev-queue
patch link:    https://lore.kernel.org/r/20230804084051.14194-4-sriram.yagnaraman%40est.tech
patch subject: [Intel-wired-lan] [PATCH iwl-next v4 3/4] igb: add AF_XDP zero-copy Rx support
config: i386-debian-10.3 (https://download.01.org/0day-ci/archive/20230805/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230805/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/net/ethernet/intel/igb/igb_main.c: In function 'igb_dump':

>> drivers/net/ethernet/intel/igb/igb_main.c:505:42: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     505 |                         dma_addr_t dma = (dma_addr_t)NULL;
         |                                          ^

vim +505 drivers/net/ethernet/intel/igb/igb_main.c

348
349 /* igb_dump - Print registers, Tx-rings and Rx-rings */
350 static void igb_dump(struct igb_adapter *adapter)
351 {
352 struct net_device *netdev = adapter->netdev;
353 struct e1000_hw *hw = &adapter->hw;
354 struct igb_reg_info *reginfo;
355 struct igb_ring *tx_ring;
356 union e1000_adv_tx_desc *tx_desc;
357 struct my_u0 { __le64 a; __le64 b; } *u0;
358 struct igb_ring *rx_ring;
359 union e1000_adv_rx_desc *rx_desc;
360 u32 staterr;
361 u16 i, n;
362
363 if (!netif_msg_hw(adapter))
364 return;
365
366 /* Print netdevice Info */
367 if (netdev) {
368 dev_info(&adapter->pdev->dev, "Net device Info\n");
369 pr_info("Device Name state trans_start\n");
370 pr_info("%-15s %016lX %016lX\n", netdev->name,
371 netdev->state, dev_trans_start(netdev));
372 }
373
374 /* Print Registers */
375 dev_info(&adapter->pdev->dev, "Register Dump\n");
376 pr_info(" Register Name Value\n");
377 for (reginfo = (struct igb_reg_info *)igb_reg_info_tbl;
378 reginfo->name; reginfo++) {
379 igb_regdump(hw, reginfo);
380 }
381
382 /* Print TX Ring Summary */
383 if (!netdev || !netif_running(netdev))
384 goto exit;
385
386 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
387 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
388 for (n = 0; n < adapter->num_tx_queues; n++) {
389 struct igb_tx_buffer *buffer_info;
390 tx_ring = adapter->tx_ring[n];
391 buffer_info = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
392 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
393 n, tx_ring->next_to_use, tx_ring->next_to_clean,
394 (u64)dma_unmap_addr(buffer_info, dma),
395 dma_unmap_len(buffer_info, len),
396 buffer_info->next_to_watch,
397 (u64)buffer_info->time_stamp);
398 }
399
400 /* Print TX Rings */
401 if (!netif_msg_tx_done(adapter))
402 goto rx_ring_summary;
403
404 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
405
406 /* Transmit Descriptor Formats
407 *
408 * Advanced Transmit Descriptor

   409		 *   +--------------------------------------------------------------+
   410		 * 0 |         Buffer Address [63:0]                                |
   411		 *   +--------------------------------------------------------------+
   412		 * 8 | PAYLEN  | PORTS  |CC|IDX | STA | DCMD  |DTYP|MAC|RSV| DTALEN |
   413		 *   +--------------------------------------------------------------+
   414		 *   63      46 45    40 39 38 36 35 32 31   24             15       0
   415		 */
   416	
   417		for (n = 0; n < adapter->num_tx_queues; n++) {
   418			tx_ring = adapter->tx_ring[n];
   419			pr_info("------------------------------------\n");
   420			pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
   421			pr_info("------------------------------------\n");
   422			pr_info("T [desc]     [address 63:0  ] [PlPOCIStDDM Ln] [bi->dma       ] leng  ntw timestamp        bi->skb\n");
   423	
   424			for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
   425				const char *next_desc;
   426				struct igb_tx_buffer *buffer_info;
   427				tx_desc = IGB_TX_DESC(tx_ring, i);
   428				buffer_info = &tx_ring->tx_buffer_info[i];
   429				u0 = (struct my_u0 *)tx_desc;
   430				if (i == tx_ring->next_to_use &&
   431				    i == tx_ring->next_to_clean)
   432					next_desc = " NTC/U";
   433				else if (i == tx_ring->next_to_use)
   434					next_desc = " NTU";
   435				else if (i == tx_ring->next_to_clean)
   436					next_desc = " NTC";
   437				else
   438					next_desc = "";
   439	
   440				pr_info("T [0x%03X]    %016llX %016llX %016llX %04X  %p %016llX %p%s\n",
   441					i, le64_to_cpu(u0->a),
   442					le64_to_cpu(u0->b),
   443					(u64)dma_unmap_addr(buffer_info, dma),
   444					dma_unmap_len(buffer_info, len),
   445					buffer_info->next_to_watch,
   446					(u64)buffer_info->time_stamp,
   447					buffer_info->skb, next_desc);
   448	
   449				if (netif_msg_pktdata(adapter) && buffer_info->skb)
   450					print_hex_dump(KERN_INFO, "",
   451						DUMP_PREFIX_ADDRESS,
   452						16, 1, buffer_info->skb->data,
   453						dma_unmap_len(buffer_info, len),
   454						true);
   455			}
   456		}
   457	
   458		/* Print RX Rings Summary */
   459	rx_ring_summary:
   460		dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
   461		pr_info("Queue [NTU] [NTC]\n");
   462		for (n = 0; n < adapter->num_rx_queues; n++) {
   463			rx_ring = adapter->rx_ring[n];
   464			pr_info(" %5d %5X %5X\n",
   465				n, rx_ring->next_to_use, rx_ring->next_to_clean);
   466		}
   467	
   468		/* Print RX Rings */
   469		if (!netif_msg_rx_status(adapter))
   470			goto exit;
   471	
   472		dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
   473	
   474		/* Advanced Receive Descriptor (Read) Format
   475		 *    63                                           1        0
   476		 *    +-----------------------------------------------------+
   477		 *  0 |       Packet Buffer Address [63:1]           |A0/NSE|
   478		 *    +----------------------------------------------+------+
   479		 *  8 |       Header Buffer Address [63:1]           |  DD  |
   480		 *    +-----------------------------------------------------+
   481		 *
   482		 *
   483		 * Advanced Receive Descriptor (Write-Back) Format
   484		 *
   485		 *   63       48 47    32 31  30      21 20 17 16   4 3     0
   486		 *   +------------------------------------------------------+
   487		 * 0 | Packet     IP     |SPH| HDR_LEN   | RSV|Packet|  RSS |
   488		 *   | Checksum   Ident  |   |           |    | Type | Type |
   489		 *   +------------------------------------------------------+
   490		 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
   491		 *   +------------------------------------------------------+
   492		 *   63       48 47    32 31            20 19               0
   493		 */
   494	
   495		for (n = 0; n < adapter->num_rx_queues; n++) {
   496			rx_ring = adapter->rx_ring[n];
   497			pr_info("------------------------------------\n");
   498			pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
   499			pr_info("------------------------------------\n");
   500			pr_info("R  [desc]      [ PktBuf     A0] [  HeadBuf   DD] [bi->dma       ] [bi->skb] <-- Adv Rx Read format\n");
   501			pr_info("RWB[desc]      [PcsmIpSHl PtRs] [vl er S cks ln] ---------------- [bi->skb] <-- Adv Rx Write-Back format\n");
   502	
   503			for (i = 0; i < rx_ring->count; i++) {
   504				const char *next_desc;
 > 505				dma_addr_t dma = (dma_addr_t)NULL;
   506				struct igb_rx_buffer *buffer_info = NULL;
   507				rx_desc = IGB_RX_DESC(rx_ring, i);
   508				u0 = (struct my_u0 *)rx_desc;
   509				staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
   510	
   511				if (!rx_ring->xsk_pool) {
   512					buffer_info = &rx_ring->rx_buffer_info[i];
   513					dma = buffer_info->dma;
   514				}
   515	
   516				if (i == rx_ring->next_to_use)
   517					next_desc = " NTU";
   518				else if (i == rx_ring->next_to_clean)
   519					next_desc = " NTC";
   520				else
   521					next_desc = "";
   522	
   523				if (staterr & E1000_RXD_STAT_DD) {
   524					/* Descriptor Done */
   525					pr_info("%s[0x%03X]     %016llX %016llX ---------------- %s\n",
   526						"RWB", i,
   527						le64_to_cpu(u0->a),
   528						le64_to_cpu(u0->b),
   529						next_desc);
   530				} else {
   531					pr_info("%s[0x%03X]     %016llX %016llX %016llX %s\n",
   532						"R  ", i,
   533						le64_to_cpu(u0->a),
   534						le64_to_cpu(u0->b),
   535						(u64)dma,
   536						next_desc);
   537	
   538					if (netif_msg_pktdata(adapter) &&
   539					    buffer_info && dma && buffer_info->page) {
   540						print_hex_dump(KERN_INFO, "",
   541						  DUMP_PREFIX_ADDRESS,
   542						  16, 1,
   543						  page_address(buffer_info->page) +

544 buffer_info->page_offset,
545 igb_rx_bufsz(rx_ring), true);
546 }
547 }
548 }
549 }
550
551 exit:
552 return;
553 }
554

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw

PATCH v4 4/4 igb: add AF_XDP zero-copy Tx support

In reply to Sriram Yagnaraman

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.

---
 drivers/net/ethernet/intel/igb/igb.h      |  2 +
 drivers/net/ethernet/intel/igb/igb_main.c | 56 +++++++++++++++++++----
 drivers/net/ethernet/intel/igb/igb_xsk.c  | 52 +++++++++++++++++++++
 3 files changed, 101 insertions(+), 9 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +2 -0
index 39202c40116a..f52a988fe2f0 100644
@@ -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,
@@ -836,6 +837,7 @@ int igb_xsk_pool_setup(struct igb_adapter *adapter,
 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, 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 +47 -9

128 lines not on this page · raw message

drivers/net/ethernet/intel/igb/igb_xsk.c +52 -0

58 lines not on this page · raw message

Signature · 1 line
2.34.1
#6 lore raw
In reply to Sriram Yagnaraman

Hi Sriram,

Quoted 7 lines · Sriram Yagnaraman

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.

I gave this patch series a try on a recent kernel and silicon (i210). There was one issue in igb_xmit_zc(). But other than that it worked very nicely.

It seems like it hasn't been merged yet. Do you have any plans for continuing to work on this?

Thanks,
Kurt

#7 lore raw
Quoted 7 lines · Kurt Kanzenbach

Hi Sriram,

Quoted 4 lines · Sriram Yagnaraman

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.

Quoted 7 lines
Quoted 3 lines

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.

I gave this patch series a try on a recent kernel and silicon (i210). There was one issue in igb_xmit_zc(). But other than that it worked very nicely.

Hi Kurt and Sriram,

I recently tried the patches on a 6.1 kernel. On two different devices i210 & i211 I couldn't see any packets being transmitted on the wire. Perhaps caused by the issue in igb_xmit_zc() you mentioned, Kurt? Can you share your findings, please?

RX seemed to work on first sight.

Quoted 2 lines

It seems like it hasn't been merged yet. Do you have any plans for continuing to work on this?

I can offer to do testing and debugging on real hardware if this helps.

Thanks,
Benjamin

#8 lore raw

Hi Benjamin,

Quoted 16 lines · Benjamin Steinke
Quoted 7 lines · Kurt Kanzenbach

Hi Sriram,

Quoted 4 lines · Sriram Yagnaraman

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.

Quoted 7 lines
Quoted 3 lines

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.

I gave this patch series a try on a recent kernel and silicon (i210). There was one issue in igb_xmit_zc(). But other than that it worked very nicely.

Quoted 6 lines

Hi Kurt and Sriram,

I recently tried the patches on a 6.1 kernel. On two different devices i210 & i211 I couldn't see any packets being transmitted on the wire. Perhaps caused by the issue in igb_xmit_zc() you mentioned, Kurt? Can you share your findings, please?

Yeah, that's exactly the issue.

Following igb_xmit_xdp_ring() I've added PAYLEN to the Tx descriptor instead of setting it to zero:

igb_xmit_zc()

{
        [...]

	/* put descriptor type bits */
	cmd_type = E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_DEXT |
		   E1000_ADVTXD_DCMD_IFCS;
	olinfo_status = descs[i].len << E1000_ADVTXD_PAYLEN_SHIFT;
	
	cmd_type |= descs[i].len | IGB_TXD_DCMD;
	tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
	tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);

	[...]
}

Afterwards packets are transmitted on the wire.

Quoted 3 lines

RX seemed to work on first sight.

Yes, Rx works even with PTP enabled.

Quoted 4 lines
Quoted 2 lines

It seems like it hasn't been merged yet. Do you have any plans for continuing to work on this?

I can offer to do testing and debugging on real hardware if this helps.

Great. Thanks!

#9 lore raw

Hi,

Quoted 73 lines

-----Original Message-----
From: Kurt Kanzenbach <[email protected]>
Sent: Thursday, 27 June 2024 19:19
To: Benjamin Steinke <[email protected]>; Sriram Yagnaraman <[email protected]>
Cc: [email protected]; Maciej Fijalkowski <[email protected]>; Jesper Dangaard Brouer <[email protected]>; Daniel Borkmann <[email protected]>; [email protected]; Jonathan Lemon <[email protected]>; John Fastabend <[email protected]>; Alexei Starovoitov <[email protected]>; Björn Töpel <[email protected]>; Eric Dumazet <[email protected]>; Sriram Yagnaraman <[email protected]>; Tony Nguyen <[email protected]>; Jakub Kicinski <[email protected]>; [email protected]; Paolo Abeni <[email protected]>; David S . Miller <[email protected]>; Magnus Karlsson <[email protected]>
Subject: Re: [Intel-wired-lan] [PATCH iwl-next v4 0/4] igb: Add support for AF_XDP zero-copy

Hi Benjamin,

Quoted 16 lines · Benjamin Steinke
Quoted 7 lines · Kurt Kanzenbach

Hi Sriram,

Quoted 4 lines · Sriram Yagnaraman

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.

Quoted 7 lines
Quoted 3 lines

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.

I gave this patch series a try on a recent kernel and silicon (i210). There was one issue in igb_xmit_zc(). But other than that it worked very nicely.

Quoted 7 lines

Hi Kurt and Sriram,

I recently tried the patches on a 6.1 kernel. On two different devices i210 &
i211 I couldn't see any packets being transmitted on the wire. Perhaps caused by the issue in igb_xmit_zc() you mentioned, Kurt? Can you share your findings, please?

Yeah, that's exactly the issue.

Following igb_xmit_xdp_ring() I've added PAYLEN to the Tx descriptor instead of setting it to zero:

igb_xmit_zc()

{
        [...]

	/* put descriptor type bits */
	cmd_type = E1000_ADVTXD_DTYP_DATA |
E1000_ADVTXD_DCMD_DEXT |
		   E1000_ADVTXD_DCMD_IFCS;
	olinfo_status = descs[i].len << E1000_ADVTXD_PAYLEN_SHIFT;

	cmd_type |= descs[i].len | IGB_TXD_DCMD;
	tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
	tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);

	[...]
}

Afterwards packets are transmitted on the wire.

Quoted 3 lines

RX seemed to work on first sight.

Quoted 8 lines

Yes, Rx works even with PTP enabled.

Quoted 4 lines
Quoted 2 lines

It seems like it hasn't been merged yet. Do you have any plans for continuing to work on this?

I can offer to do testing and debugging on real hardware if this helps.

Great. Thanks!

I have since changed my position at my company, and my new position doesn't allow me to contribute upstream to kernel unfortunately. It would be great if one of you can take over this and get it delivered if possible.

Glad that others find this patch useful as well.

#10 lore raw
Quoted 11 lines · Sriram Yagnaraman
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

It seems like it hasn't been merged yet. Do you have any plans for continuing to work on this?

I can offer to do testing and debugging on real hardware if this helps.

Great. Thanks!

I have since changed my position at my company, and my new position doesn't allow me to contribute upstream to kernel unfortunately. It would be great if one of you can take over this and get it delivered if possible.

Ok, I'll take it over.

Quoted 2 lines

Glad that others find this patch useful as well.

Yeah, it's very useful :).

Thanks,
Kurt

#11 lore raw
In reply to Kurt Kanzenbach
Quoted 49 lines · Kurt Kanzenbach

Hi Benjamin,

Quoted 18 lines · Benjamin Steinke
Quoted 8 lines · Kurt Kanzenbach

Hi Sriram,

Quoted 5 lines · Sriram Yagnaraman

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.

Quoted 8 lines
Quoted 4 lines

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.

I gave this patch series a try on a recent kernel and silicon (i210). There was one issue in igb_xmit_zc(). But other than that it worked very nicely.

Quoted 6 lines

Hi Kurt and Sriram,

I recently tried the patches on a 6.1 kernel. On two different devices i210 & i211 I couldn't see any packets being transmitted on the wire. Perhaps caused by the issue in igb_xmit_zc() you mentioned, Kurt? Can you share your findings, please?

Yeah, that's exactly the issue.

Following igb_xmit_xdp_ring() I've added PAYLEN to the Tx descriptor instead of setting it to zero:

igb_xmit_zc()

{
        [...]

	/* put descriptor type bits */
	cmd_type = E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_DEXT |
		   E1000_ADVTXD_DCMD_IFCS;
	olinfo_status = descs[i].len << E1000_ADVTXD_PAYLEN_SHIFT;

	cmd_type |= descs[i].len | IGB_TXD_DCMD;
	tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
	tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);

	[...]
}
Quoted 1 line

Afterwards packets are transmitted on the wire.

Hi Kurt,

I can confirm this makes the transmitter work.
Thank you for taking over this patch series and continue to bring this upstream. I will continue testing on this.

Quoted 3 lines
Quoted 1 line

RX seemed to work on first sight.

Yes, Rx works even with PTP enabled.

I can confirm this as well.

Best regards,
Benjamin