Skip to contentSkip to conversation

i40e: fix regression that enables AF_XDP ZC unconditionally

PATCH In review Björn Töpel 2 participants 5 messages Feb 12, 2019 – Feb 16, 2019

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

cover i40e: fix regression that enables AF_XDP ZC unconditionally

This series addresses a recent AF_XDP zero-copy regression.

In commit f3fef2b6e1cc ("i40e: Remove umem from VSI") a regression was introduced; When the VSI was reset, the setup code would try to enable AF_XDP ZC unconditionally (as long as there was a umem placed in the netdev._rx struct). Here, we add a bitmap to the VSI that tracks if a certain queue pair has been "zero-copy enabled" via the ndo_bpf. The bitmap is used in i40e_xsk_umem, and enables zero-copy if and only if XDP is enabled, the corresponding qid in the bitmap is set and the umem is non-NULL.

Thanks,
Bj?rn

Bj?rn T?pel (2):
i40e: move i40e_xsk_umem function
i40e: add tracking of AF_XDP ZC state for each queue pair

 drivers/net/ethernet/intel/i40e/i40e.h      | 16 ++----------
 drivers/net/ethernet/intel/i40e/i40e_main.c | 28 +++++++++++++++++++++
 drivers/net/ethernet/intel/i40e/i40e_xsk.c  |  3 +++
 3 files changed, 33 insertions(+), 14 deletions(-)
Signature · 1 line
2.19.1
#1 lore raw

PATCH 1/2 i40e: move i40e_xsk_umem function

From: Bj?rn T?pel <[email protected]>

The i40e_xsk_umem function was explicitly inlined in i40e.h. There is no reason for that, so move it to i40e_main.c instead.

---
 drivers/net/ethernet/intel/i40e/i40e.h      | 14 --------------
 drivers/net/ethernet/intel/i40e/i40e_main.c | 20 ++++++++++++++++++++
 2 files changed, 20 insertions(+), 14 deletions(-)
drivers/net/ethernet/intel/i40e/i40e.h +0 -14
index d684998ba2b0..cc583ad5236b 100644
@@ -1096,20 +1096,6 @@ static inline bool i40e_enabled_xdp_vsi(struct i40e_vsi *vsi)
 	return !!vsi->xdp_prog;
 }
 
-static inline struct xdp_umem *i40e_xsk_umem(struct i40e_ring *ring)
-{
-	bool xdp_on = i40e_enabled_xdp_vsi(ring->vsi);
-	int qid = ring->queue_index;
-
-	if (ring_is_xdp(ring))
-		qid -= ring->vsi->alloc_queue_pairs;
-
-	if (!xdp_on)
-		return NULL;
-
-	return xdp_get_umem_from_qid(ring->vsi->netdev, qid);
-}
-
 int i40e_create_queue_channel(struct i40e_vsi *vsi, struct i40e_channel *ch);
 int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate);
 int i40e_add_del_cloud_filter(struct i40e_vsi *vsi,
drivers/net/ethernet/intel/i40e/i40e_main.c +20 -0
index 44856a84738d..ba1a84a2c8e5 100644
@@ -3063,6 +3063,26 @@ static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
 			    ring->queue_index);
 }
 
+/**
+ * i40e_xsk_umem - Retrieve the AF_XDP ZC if XDP and ZC is enabled
+ * @ring: The Tx or Rx ring
+ *
+ * Returns the UMEM or NULL.
+ **/
+static struct xdp_umem *i40e_xsk_umem(struct i40e_ring *ring)
+{
+	bool xdp_on = i40e_enabled_xdp_vsi(ring->vsi);
+	int qid = ring->queue_index;
+
+	if (ring_is_xdp(ring))
+		qid -= ring->vsi->alloc_queue_pairs;
+
+	if (!xdp_on)
+		return NULL;
+
+	return xdp_get_umem_from_qid(ring->vsi->netdev, qid);
+}
+
 /**
  * i40e_configure_tx_ring - Configure a transmit ring context and rest
  * @ring: The Tx ring to configure
Signature · 1 line
2.19.1
Tested-by on v1 1/2
#2 lore raw

RE: [PATCH 1/2] i40e: move i40e_xsk_umem function

Quoted 11 lines

From: netdev-owner at vger.kernel.org [mailto:netdev- owner at vger.kernel.org] On Behalf Of Bj?rn T?pel
Sent: Tuesday, February 12, 2019 12:52 AM
To: intel-wired-lan at lists.osuosl.org
Cc: Topel, Bjorn <[email protected]>; Karlsson, Magnus <[email protected]>; magnus.karlsson at gmail.com; netdev at vger.kernel.org; Sokolowski, Jan <[email protected]>
Subject: [PATCH 1/2] i40e: move i40e_xsk_umem function

From: Bj?rn T?pel <[email protected]>

Quoted 9 lines

The i40e_xsk_umem function was explicitly inlined in i40e.h. There is no reason for that, so move it to i40e_main.c instead.

---
 drivers/net/ethernet/intel/i40e/i40e.h      | 14 --------------
 drivers/net/ethernet/intel/i40e/i40e_main.c | 20 ++++++++++++++++++++
 2 files changed, 20 insertions(+), 14 deletions(-)
#3 lore raw

PATCH 2/2 i40e: add tracking of AF_XDP ZC state for each queue pair

In reply to Björn Töpel

From: Bj?rn T?pel <[email protected]>

In commit f3fef2b6e1cc ("i40e: Remove umem from VSI") a regression was introduced; When the VSI was reset, the setup code would try to enable AF_XDP ZC unconditionally (as long as there was a umem placed in the netdev._rx struct). Here, we add a bitmap to the VSI that tracks if a certain queue pair has been "zero-copy enabled" via the ndo_bpf. The bitmap is used in i40e_xsk_umem, and enables zero-copy if and only if XDP is enabled, the corresponding qid in the bitmap is set and the umem is non-NULL.

Fixes f3fef2b6e1cc ("i40e: Remove umem from VSI")
---
 drivers/net/ethernet/intel/i40e/i40e.h      |  2 ++
 drivers/net/ethernet/intel/i40e/i40e_main.c | 10 +++++++++-
 drivers/net/ethernet/intel/i40e/i40e_xsk.c  |  3 +++
 3 files changed, 14 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/i40e/i40e.h +2 -0
index cc583ad5236b..d3cc3427caad 100644
@@ -790,6 +790,8 @@ struct i40e_vsi {
 
 	/* VSI specific handlers */
 	irqreturn_t (*irq_handler)(int irq, void *data);
+
+	unsigned long *af_xdp_zc_qps; /* tracks AF_XDP ZC enabled qps */
 } ____cacheline_internodealigned_in_smp;
 
 struct i40e_netdev_priv {
drivers/net/ethernet/intel/i40e/i40e_main.c +9 -1
index ba1a84a2c8e5..0dd00d58c524 100644
@@ -3077,7 +3077,7 @@ static struct xdp_umem *i40e_xsk_umem(struct i40e_ring *ring)
 	if (ring_is_xdp(ring))
 		qid -= ring->vsi->alloc_queue_pairs;
 
-	if (!xdp_on)
+	if (!xdp_on || !test_bit(qid, ring->vsi->af_xdp_zc_qps))
 		return NULL;
 
 	return xdp_get_umem_from_qid(ring->vsi->netdev, qid);
@@ -10076,6 +10076,12 @@ static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
 	hash_init(vsi->mac_filter_hash);
 	vsi->irqs_ready = false;
 
+	if (type == I40E_VSI_MAIN) {
+		vsi->af_xdp_zc_qps = bitmap_zalloc(pf->num_lan_qps, GFP_KERNEL);
+		if (!vsi->af_xdp_zc_qps)
+			goto err_rings;
+	}
+
 	ret = i40e_set_num_rings_in_vsi(vsi);
 	if (ret)
 		goto err_rings;
@@ -10094,6 +10100,7 @@ static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
 	goto unlock_pf;
 
 err_rings:
+	bitmap_free(vsi->af_xdp_zc_qps);
 	pf->next_vsi = i - 1;
 	kfree(vsi);
 unlock_pf:
@@ -10174,6 +10181,7 @@ static int i40e_vsi_clear(struct i40e_vsi *vsi)
 	i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
 	i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
 
+	bitmap_free(vsi->af_xdp_zc_qps);
 	i40e_vsi_free_arrays(vsi, true);
 	i40e_clear_rss_config_user(vsi);
 
drivers/net/ethernet/intel/i40e/i40e_xsk.c +3 -0
index 96d849460d9b..2737fee338c4 100644
@@ -102,6 +102,8 @@ static int i40e_xsk_umem_enable(struct i40e_vsi *vsi, struct xdp_umem *umem,
 	if (err)
 		return err;
 
+	set_bit(qid, vsi->af_xdp_zc_qps);
+
 	if_running = netif_running(vsi->netdev) && i40e_enabled_xdp_vsi(vsi);
 
 	if (if_running) {
@@ -143,6 +145,7 @@ static int i40e_xsk_umem_disable(struct i40e_vsi *vsi, u16 qid)
 			return err;
 	}
 
+	clear_bit(qid, vsi->af_xdp_zc_qps);
 	i40e_xsk_umem_dma_unmap(vsi, umem);
 
 	if (if_running) {
Signature · 1 line
2.19.1
Tested-by on v1 2/2
#4 lore raw

RE: [PATCH 2/2] i40e: add tracking of AF_XDP ZC state for each queue pair

Quoted 21 lines

From: netdev-owner at vger.kernel.org [mailto:netdev-
owner at vger.kernel.org] On Behalf Of Bj?rn T?pel
Sent: Tuesday, February 12, 2019 12:52 AM
To: intel-wired-lan at lists.osuosl.org
Cc: Topel, Bjorn <[email protected]>; Karlsson, Magnus <[email protected]>; magnus.karlsson at gmail.com; netdev at vger.kernel.org; Sokolowski, Jan <[email protected]>
Subject: [PATCH 2/2] i40e: add tracking of AF_XDP ZC state for each queue pair

From: Bj?rn T?pel <[email protected]>

In commit f3fef2b6e1cc ("i40e: Remove umem from VSI") a regression was introduced; When the VSI was reset, the setup code would try to enable AF_XDP ZC unconditionally (as long as there was a umem placed in the netdev._rx struct). Here, we add a bitmap to the VSI that tracks if a certain queue pair has been "zero-copy enabled" via the ndo_bpf. The bitmap is used in i40e_xsk_umem, and enables zero-copy if and only if XDP is enabled, the corresponding qid in the bitmap is set and the umem is non-NULL.

Quoted 8 lines
Fixes f3fef2b6e1cc ("i40e: Remove umem from VSI")
---
 drivers/net/ethernet/intel/i40e/i40e.h      |  2 ++
 drivers/net/ethernet/intel/i40e/i40e_main.c | 10 +++++++++-
 drivers/net/ethernet/intel/i40e/i40e_xsk.c  |  3 +++
 3 files changed, 14 insertions(+), 1 deletion(-)