Skip to contentSkip to conversation

e1000e: add XDP support

PATCH New Matteo Croce 1 participant 6 messages Dec 4

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

v5 cover e1000e: add XDP support

This series adds XDP support to the e1000e driver, with multi-buffer frames, XDP_TX, XDP_REDIRECT and .ndo_xdp_xmit.

As suggested in the v4 review, the Rx path is reworked first: the three Rx routines, and the clean_rx and alloc_rx_buf function pointers, are replaced by a single routine using the libeth helpers, and XDP is built on top of it:

- patch 1 processes Tx completions from NAPI also in MSI-X mode (82574), as page_pool buffers can't be returned from hard interrupt context;
- patch 2 disables NAPI in e1000e_down(), as a page_pool tied to a NAPI instance can only be destroyed while the NAPI is disabled;
- patch 3 removes the packet split Rx routine;
- patch 4 replaces the two remaining Rx routines with a single one:
buffers are allocated from a libeth page_pool and assembled into an xdp_buff, which can span multiple descriptors, then converted into an skb;
- patch 5 adds XDP support, including XDP_TX and XDP_REDIRECT, for both single and multi-buffer frames;
- patch 6 adds .ndo_xdp_xmit, so that the device can be a redirect target, with or without a program attached.

The hardware only supports power of two Rx buffer sizes, so it is always programmed for 2 KB buffers, and frames bigger than that span multiple descriptors. With the standard MTU, long packet reception is disabled and frames never exceed a VLAN tagged frame, so the buffers are allocated just big enough for it, two per 4 KB page.

The device has a single Tx queue, shared with the regular transmit path, so XDP_TX and .ndo_xdp_xmit place the frames on it with the Tx queue lock held. The libeth_xdp Tx helpers assume dedicated XDP queues, e.g. a frame can be split across bulk flushes, so like ice the Tx side is handled by the driver.

Attaching or removing a program resets the device, as the Rx buffers are reallocated with the XDP headroom. Programs without frags support are rejected when the MTU allows jumbo frames, and the MTU can't be raised above 1500 while one is attached.

User visible changes: the copybreak module parameter and the rx_header_split ethtool statistic are removed, as the copy and the header split Rx paths they refer to are gone.

Tested in QEMU, with three emulated 82574L devices connected to the same hub, one of them moved into a network namespace as the remote end:
- drivers/net/xdp.py selftest: 21 of 27 tests pass, the other 6 are the qstats ones, as e1000e doesn't report queue stats; same result with MSI-X and with legacy interrupts;
- UDP frames reflected with XDP_TX, with a redirect to the same device and with a redirect to another e1000e without a program attached:
250 single buffer frames of 18 to 1472 bytes and 450 multi-buffer frames of up to 8972 bytes in each mode, none lost or corrupted;
- 60 seconds of bidirectional TCP traffic (8.95 GB) while about 180k frames were reflected onto the same Tx rings with XDP_TX and redirect, with 17 reconfigurations in the meantime (ring sizes, MTU, program, link down and up): no corrupted frame, and the device works normally afterwards;
- no page_pool left with in-flight pages after the interfaces go down;
- the same on a kernel with KASAN, lockdep, DMA API debugging, kmemleak and a strict IOMMU, without any warning or leak report.
The other driver selftests give the same results with and without this series. ping.py's native XDP tests fail, as they ping right after attaching the program, while the link is still down after the device reset; without this series one of them is skipped, the other fails.

Tested on an Intel 82574L (PCIe x1), connected at 1 Gbps through a switch to a Realtek RTL8111, which generates the traffic with pktgen. The RTL8111 can't send more than about 0.53 Mpps of 64 byte frames, below the 82574L line rate, and the 82574L handles all of them in every mode, so this is the load of the CPU handling its interrupts at that rate, with generic XDP before the series and native XDP after it:

before after

  no program           53%      51%
  XDP_DROP             19%     4.5%
  XDP_PASS             58%      54%
  XDP_TX               28%     8.5%
  XDP_REDIRECT         28%      11%

XDP_REDIRECT sends the frames back on the same device, as there is no other e1000e. TCP throughput is 941 Mbit/s in both directions, with and without the series, and with and without a program attached. The XDP_TX and redirect tests done in QEMU pass also on hardware, with MSI-X, MSI and legacy interrupts, and with the link at 100 Mbps. The device keeps working after 12 reconfigurations under 0.15 Mpps of XDP_TX and redirect traffic, without leaving page_pool pages in flight.

v4: https://lore.kernel.org/all/[email protected]/

v5:
- rework the Rx path to use libeth with a single Rx routine, and add multi-buffer support (Maciej)
- take the Tx queue lock for XDP_TX, as the ring is shared with the regular transmit path (Aleksandr)
- don't put the program reference on ndo_bpf failure, it's done by the core (Aleksandr), the interface is now reset with down/up which can't fail
- .ndo_xdp_xmit still stops at the first frame which doesn't fit: the caller frees the remaining ones and reports them as dropped with the xdp_devmap_xmit tracepoint, so they are not lost silently (Aleksandr)
- clean the Tx ring from NAPI also in MSI-X mode, freeing XDP buffers from the hard interrupt handler was not allowed
- fix the cover letter, this series is not about AF_XDP (Maciej)
v4: bugfixes
v3: removed a leftover file.
v2: added a missing 'select PAGE_POOL' which triggered a build failure with some configurations.

Matteo Croce (6):
e1000e: clean the Tx ring from NAPI in MSI-X mode
e1000e: disable NAPI when bringing the interface down
e1000e: remove packet split Rx
e1000e: use libeth for Rx buffer management
e1000e: add XDP support
e1000e: add .ndo_xdp_xmit support

 .../device_drivers/ethernet/intel/e1000e.rst  |   15 -
 drivers/net/ethernet/intel/Kconfig            |    1 +
 drivers/net/ethernet/intel/e1000e/e1000.h     |   66 +-
 drivers/net/ethernet/intel/e1000e/ethtool.c   |    1 -
 drivers/net/ethernet/intel/e1000e/netdev.c    | 1853 +++++++----------
 drivers/net/ethernet/intel/e1000e/param.c     |    6 -
 6 files changed, 792 insertions(+), 1150 deletions(-)

base-commit: d5cf954cebe4f175dfd834e1dc471a3aa203ec7d

Signature · 1 line
2.56.1
#1 lore raw

PATCH v5 1/6 e1000e: clean the Tx ring from NAPI in MSI-X mode

In MSI-X mode, which is only used by 82574, Tx completions are processed directly in the Tx hard interrupt handler, while in MSI and legacy interrupt modes they are processed by the NAPI poll routine.

Freeing buffers coming from a page_pool, as it will happen with XDP_TX, is not allowed from hard interrupt context.

Make the MSI-X Tx interrupt schedule NAPI as the Rx one does, always clean the Tx ring from the poll routine, and re-enable both the Rx and Tx interrupt causes when polling is complete.

---
 drivers/net/ethernet/intel/e1000e/netdev.c | 32 +++++++++++-----------
 1 file changed, 16 insertions(+), 16 deletions(-)
drivers/net/ethernet/intel/e1000e/netdev.c +16 -16
index 6f85dab5c55c..996bd6f5fa83 100644
@@ -1934,18 +1934,17 @@ static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
 {
 	struct net_device *netdev = data;
 	struct e1000_adapter *adapter = netdev_priv(netdev);
-	struct e1000_hw *hw = &adapter->hw;
-	struct e1000_ring *tx_ring = adapter->tx_ring;
-
-	adapter->total_tx_bytes = 0;
-	adapter->total_tx_packets = 0;
-
-	if (!e1000_clean_tx_irq(tx_ring))
-		/* Ring was not completely cleaned, so fire another interrupt */
-		ew32(ICS, tx_ring->ims_val);
 
-	if (!test_bit(__E1000_DOWN, &adapter->state))
-		ew32(IMS, adapter->tx_ring->ims_val);
+	/* Tx completions are processed in NAPI context, the Tx interrupt is
+	 * re-enabled when polling is done.
+	 */
+	if (napi_schedule_prep(&adapter->napi)) {
+		adapter->total_tx_bytes = 0;
+		adapter->total_tx_packets = 0;
+		adapter->total_rx_bytes = 0;
+		adapter->total_rx_packets = 0;
+		__napi_schedule_irqoff(&adapter->napi);
+	}
 
 	return IRQ_HANDLED;
 }
@@ -1968,6 +1967,8 @@ static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
 	}
 
 	if (napi_schedule_prep(&adapter->napi)) {
+		adapter->total_tx_bytes = 0;
+		adapter->total_tx_packets = 0;
 		adapter->total_rx_bytes = 0;
 		adapter->total_rx_packets = 0;
 		__napi_schedule_irqoff(&adapter->napi);
@@ -2683,13 +2684,11 @@ static int e1000e_poll(struct napi_struct *napi, int budget)
 						     napi);
 	struct e1000_hw *hw = &adapter->hw;
 	struct net_device *poll_dev = adapter->netdev;
-	int tx_cleaned = 1, work_done = 0;
+	int tx_cleaned, work_done = 0;
 
 	adapter = netdev_priv(poll_dev);
 
-	if (!adapter->msix_entries ||
-	    (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
-		tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
+	tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
 
 	adapter->clean_rx(adapter->rx_ring, &work_done, budget);
 
@@ -2704,7 +2703,8 @@ static int e1000e_poll(struct napi_struct *napi, int budget)
 			e1000_set_itr(adapter);
 		if (!test_bit(__E1000_DOWN, &adapter->state)) {
 			if (adapter->msix_entries)
-				ew32(IMS, adapter->rx_ring->ims_val);
+				ew32(IMS, adapter->rx_ring->ims_val |
+					  adapter->tx_ring->ims_val);
 			else
 				e1000_irq_enable(adapter);
 		}
Signature · 1 line
2.56.1
#2 lore raw

PATCH v5 2/6 e1000e: disable NAPI when bringing the interface down

In reply to Matteo Croce

e1000e_down() only synchronizes with a running NAPI poll, leaving NAPI enabled, and NAPI is only disabled in e1000e_close().

A page_pool tied to a NAPI instance can only be destroyed when the NAPI is disabled, as there must be no concurrent users of the pool's direct recycling cache. This is needed to allocate the Rx buffers from a page_pool which is created and destroyed when the interface is brought up and down, e.g. on MTU changes.

Disable NAPI in e1000e_down() and enable it in e1000e_up(), as most drivers do. e1000e_close() no longer needs to disable it, as when the device is present it calls e1000e_down(), and when it is not present it was already brought down when it was detached.

---
 drivers/net/ethernet/intel/e1000e/netdev.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/e1000e/netdev.c +6 -2
index 996bd6f5fa83..4badd502f3ce 100644
@@ -4257,6 +4257,8 @@ void e1000e_up(struct e1000_adapter *adapter)
 
 	clear_bit(__E1000_DOWN, &adapter->state);
 
+	napi_enable(&adapter->napi);
+
 	if (adapter->msix_entries)
 		e1000_configure_msix(adapter);
 	e1000_irq_enable(adapter);
@@ -4329,7 +4331,7 @@ void e1000e_down(struct e1000_adapter *adapter, bool reset)
 
 	e1000_irq_disable(adapter);
 
-	napi_synchronize(&adapter->napi);
+	napi_disable(&adapter->napi);
 
 	timer_delete_sync(&adapter->watchdog_timer);
 	timer_delete_sync(&adapter->phy_info_timer);
@@ -4774,6 +4776,9 @@ int e1000e_close(struct net_device *netdev)
 
 	pm_runtime_get_sync(&pdev->dev);
 
+	/* A device which is not present was already brought down, and its
+	 * NAPI disabled, when it was detached.
+	 */
 	if (netif_device_present(netdev)) {
 		e1000e_down(adapter, true);
 		e1000_free_irq(adapter);
@@ -4784,7 +4789,6 @@ int e1000e_close(struct net_device *netdev)
 
 	netif_queue_set_napi(netdev, 0, NETDEV_QUEUE_TYPE_RX, NULL);
 	netif_queue_set_napi(netdev, 0, NETDEV_QUEUE_TYPE_TX, NULL);
-	napi_disable(&adapter->napi);
 
 	e1000e_free_tx_resources(adapter->tx_ring);
 	e1000e_free_rx_resources(adapter->rx_ring);
Signature · 1 line
2.56.1
#3 lore raw

PATCH v5 3/6 e1000e: remove packet split Rx

In reply to Matteo Croce

The driver has three Rx routines: one which receives into linear skbs for the standard MTU, one which receives jumbo frames into pages, and one using packet split descriptors, which places the protocol headers into an skb and the payload into pages, used for jumbo frames when the MTU fits in up to three pages and PAGE_SIZE is at most 16 KB.

Remove the packet split routine, jumbo frames are always received with the page based routine, which is already used on systems with bigger pages or with an MTU not fitting into three pages.

This is a preparation to unify the Rx paths into a single page_pool based routine. As packet split is gone, also remove the rx_header_split ethtool statistic.

---
 drivers/net/ethernet/intel/e1000e/e1000.h   |  16 +-
 drivers/net/ethernet/intel/e1000e/ethtool.c |   1 -
 drivers/net/ethernet/intel/e1000e/netdev.c  | 603 +++-----------------
 3 files changed, 67 insertions(+), 553 deletions(-)
drivers/net/ethernet/intel/e1000e/e1000.h +1 -15
index 63ebe00376f5..533d1981eb5e 100644
@@ -121,11 +121,6 @@ enum e1000_boards {
 	board_pch_ptp
 };
 
-struct e1000_ps_page {
-	struct page *page;
-	u64 dma; /* must be u64 - written to hw */
-};
-
 /* wrappers around a pointer to a socket buffer,
  * so a DMA handle can be stored along with the buffer
  */
@@ -143,11 +138,7 @@ struct e1000_buffer {
 			u16 mapped_as_page;
 		};
 		/* Rx */
-		struct {
-			/* arrays of page information for packet split */
-			struct e1000_ps_page *ps_pages;
-			struct page *page;
-		};
+		struct page *page;
 	};
 };
 
@@ -265,15 +256,12 @@ struct e1000_adapter {
 	/* Rx stats */
 	u64 hw_csum_err;
 	u64 hw_csum_good;
-	u64 rx_hdr_split;
 	u32 gorc;
 	u64 gorc_old;
 	u32 alloc_rx_buff_failed;
 	u32 rx_dma_failed;
 	u32 rx_hwtstamp_cleared;
 
-	unsigned int rx_ps_pages;
-	u16 rx_ps_bsize0;
 	u32 max_frame_size;
 	u32 min_frame_size;
 
@@ -464,8 +452,6 @@ s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca);
 #define FLAG2_ENABLE_S0IX_FLOWS           BIT(15)
 #define FLAG2_DISABLE_K1		   BIT(16)
 
-#define E1000_RX_DESC_PS(R, i)	    \
-	(&(((union e1000_rx_desc_packet_split *)((R).desc))[i]))
 #define E1000_RX_DESC_EXT(R, i)	    \
 	(&(((union e1000_rx_desc_extended *)((R).desc))[i]))
 #define E1000_GET_DESC(R, i, type)	(&(((struct type *)((R).desc))[i]))
drivers/net/ethernet/intel/e1000e/ethtool.c +0 -1
index 6f45a37b17d4..fe0b394ce276 100644
@@ -85,7 +85,6 @@ static const struct e1000_stats e1000_gstrings_stats[] = {
 	E1000_STAT("tx_flow_control_xoff", stats.xofftxc),
 	E1000_STAT("rx_csum_offload_good", hw_csum_good),
 	E1000_STAT("rx_csum_offload_errors", hw_csum_err),
-	E1000_STAT("rx_header_split", rx_hdr_split),
 	E1000_STAT("alloc_rx_buff_failed", alloc_rx_buff_failed),
 	E1000_STAT("tx_smbus", stats.mgptc),
 	E1000_STAT("rx_smbus", stats.mgprc),
drivers/net/ethernet/intel/e1000e/netdev.c +66 -537

721 lines not on this page · raw message

Signature · 1 line
2.56.1
#4 lore raw

PATCH v5 4/6 e1000e: use libeth for Rx buffer management

In reply to Matteo Croce

The driver has two Rx routines, selected at configuration time via function pointers: one for the standard MTU, which receives into linear skbs and drops frames spanning more than one descriptor, and one for jumbo frames, which receives into pages and chains them into skb frags.

Replace both with a single Rx routine, using the libeth helpers to manage the buffers:
- the Rx buffers are allocated from a page_pool created by libeth when the interface is brought up, and destroyed when it goes down;
- the received buffers are assembled into an xdp_buff, which can span multiple descriptors and NAPI polls, and then converted into an skb;
- the hardware is always programmed for 2 KB buffers, as it only supports buffer sizes which are powers of two, and frames which don't fit in a single buffer span multiple descriptors. When long packet reception is disabled, frames are never bigger than a VLAN tagged frame, so the buffers are allocated just big enough to fit them, allowing two buffers per 4 KB page.

The adapter->clean_rx and adapter->alloc_rx_buf function pointers are removed, together with rx_buffer_len, as the buffer size no longer depends on the MTU.

As the buffers are recycled by the page_pool, copying small frames into a new skb is no longer useful, so remove the copybreak module parameter.

---
 .../device_drivers/ethernet/intel/e1000e.rst  |  15 -
 drivers/net/ethernet/intel/Kconfig            |   1 +
 drivers/net/ethernet/intel/e1000e/e1000.h     |  46 +-
 drivers/net/ethernet/intel/e1000e/netdev.c    | 789 ++++++------------
 drivers/net/ethernet/intel/e1000e/param.c     |   6 -
 5 files changed, 261 insertions(+), 596 deletions(-)
Documentation/networking/device_drivers/ethernet/intel/e1000e.rst +0 -15
index d8f810afdd49..fab6ebc0cf95 100644
@@ -163,21 +163,6 @@ It ensures that an interrupt is generated after the initial Packet is sent on
 the wire within the set amount of time. Proper tuning, along with TxIntDelay,
 may improve traffic throughput in specific network conditions.
 
-copybreak
----------
-:Valid Range: 0-xxxxxxx (0=off)
-:Default Value: 256
-
-The driver copies all packets below or equaling this size to a fresh receive
-buffer before handing it up the stack.
-This parameter differs from other parameters because it is a single (not 1,1,1
-etc.) parameter applied to all driver instances and it is also available
-during runtime at /sys/module/e1000e/parameters/copybreak.
-
-To use copybreak, type::
-
-    modprobe e1000e.ko copybreak=128
-
 SmartPowerDownEnable
 --------------------
 :Valid Range: 0,1
drivers/net/ethernet/intel/Kconfig +1 -0
index 780f113986ea..786237a093c7 100644
@@ -63,6 +63,7 @@ config E1000E
 	depends on PCI && (!SPARC32 || BROKEN)
 	depends on PTP_1588_CLOCK_OPTIONAL
 	select CRC32
+	select LIBETH_XDP
 	help
 	  This driver supports the PCI-Express Intel(R) PRO/1000 gigabit
 	  ethernet family of adapters. For PCI or PCI-X e1000 adapters,
drivers/net/ethernet/intel/e1000e/e1000.h +21 -25

101 lines not on this page · raw message

drivers/net/ethernet/intel/e1000e/netdev.c +239 -550

1,023 lines not on this page · raw message

drivers/net/ethernet/intel/e1000e/param.c +0 -6
index c6f400e6cdea..548e34b9ecfd 100644
@@ -17,12 +17,6 @@
 #define OPTION_DISABLED 0
 #define OPTION_ENABLED  1
 
-#define COPYBREAK_DEFAULT 256
-unsigned int copybreak = COPYBREAK_DEFAULT;
-module_param(copybreak, uint, 0644);
-MODULE_PARM_DESC(copybreak,
-		 "Maximum size of packet that is copied to a new buffer on receive");
-
 /* All parameters are treated the same, as an integer array of values.
  * This macro just reduces the need to repeat the same declaration code
  * over and over (plus this helps to avoid typo bugs).
Signature · 1 line
2.56.1
#5 lore raw

PATCH v5 6/6 e1000e: add .ndo_xdp_xmit support

In reply to Matteo Croce

Allow the device to be the target of XDP_REDIRECT, by implementing .ndo_xdp_xmit, including frames spanning multiple buffers.

The redirected frames are placed on the Tx ring with the Tx queue lock held, as it is shared with the regular transmit path, and are returned on Tx completion. As the Tx ring is always available when the interface is up, the feature doesn't depend on an XDP program being attached.

To make sure the Tx ring is not cleaned while frames are being placed on it, e1000e_down() now takes the Tx queue lock when stopping the queue, after flagging the device as down.

---
 drivers/net/ethernet/intel/e1000e/e1000.h  |   9 +-
 drivers/net/ethernet/intel/e1000e/netdev.c | 158 +++++++++++++++++++--
 2 files changed, 156 insertions(+), 11 deletions(-)
drivers/net/ethernet/intel/e1000e/e1000.h +7 -2
index b11b0bb38d5e..fd33ed337248 100644
@@ -129,6 +129,7 @@ enum e1000_boards {
 enum e1000_tx_buf_type {
 	E1000_TX_BUF_SKB = 0,
 	E1000_TX_BUF_XDP_TX,
+	E1000_TX_BUF_XDP_XMIT,
 };
 
 /* wrappers around a pointer to a socket buffer,
@@ -137,8 +138,12 @@ enum e1000_tx_buf_type {
 struct e1000_buffer {
 	dma_addr_t dma;
 	struct sk_buff *skb;
-	/* XDP_TX buffer, returned to its page_pool on completion */
-	netmem_ref netmem;
+	union {
+		/* XDP_TX buffer, returned to its page_pool on completion */
+		netmem_ref netmem;
+		/* frame from .ndo_xdp_xmit(), set on its first buffer */
+		struct xdp_frame *xdpf;
+	};
 	unsigned long time_stamp;
 	u16 length;
 	u16 next_to_watch;
drivers/net/ethernet/intel/e1000e/netdev.c +149 -9

190 lines not on this page · raw message

Signature · 1 line
2.56.1