Skip to contentSkip to conversation

xsk: reuseq cleanup

PATCH In review Jonathan Lemon 3 participants 16 messages Jun 27, 2019 – Jul 1, 2019

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

cover xsk: reuseq cleanup

Clean up and normalize usage of the recycle queue in order to support upcoming TX from RX queue functionality.

Jonathan Lemon (6):
Have xsk_umem_peek_addr_rq() return chunk-aligned handles. Clean up xsk reuseq API
Always check the recycle stack when using the umem fq. Simplify AF_XDP umem allocation path for Intel drivers. Remove use of umem _rq variants from Mellanox driver. Remove the umem _rq variants now that the last consumer is gone.

 drivers/net/ethernet/intel/i40e/i40e_xsk.c    | 86 +++----------------
 .../ethernet/intel/ixgbe/ixgbe_txrx_common.h  |  2 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c  | 59 ++-----------
 .../ethernet/mellanox/mlx5/core/en/xsk/rx.c   |  8 +-
 .../ethernet/mellanox/mlx5/core/en/xsk/umem.c |  7 +-
 include/net/xdp_sock.h                        | 69 ++-------------
 net/xdp/xdp_umem.c                            |  2 +-
 net/xdp/xsk.c                                 | 22 ++++-
 net/xdp/xsk_queue.c                           | 56 +++++-------
 net/xdp/xsk_queue.h                           |  2 +-
 10 files changed, 68 insertions(+), 245 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/6 Have xsk_umem_peek_addr_rq() return chunk-aligned handles.

xkq_peek_addr() returns chunk-aligned handles, so have the rq behave the same way. Clean up callsites.

---
 drivers/net/ethernet/intel/i40e/i40e_xsk.c          | 2 --
 drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c        | 2 --
 drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.c | 2 +-
 include/net/xdp_sock.h                              | 2 +-
 4 files changed, 2 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_xsk.c +0 -2
index 32bad014d76c..3b84fca1c11d 100644
@@ -289,8 +289,6 @@ static bool i40e_alloc_buffer_slow_zc(struct i40e_ring *rx_ring,
 		return false;
 	}
 
-	handle &= rx_ring->xsk_umem->chunk_mask;
-
 	hr = umem->headroom + XDP_PACKET_HEADROOM;
 
 	bi->dma = xdp_umem_get_dma(umem, handle);
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c +0 -2
index 6b609553329f..a9cab3271ac9 100644
@@ -293,8 +293,6 @@ static bool ixgbe_alloc_buffer_slow_zc(struct ixgbe_ring *rx_ring,
 		return false;
 	}
 
-	handle &= rx_ring->xsk_umem->chunk_mask;
-
 	hr = umem->headroom + XDP_PACKET_HEADROOM;
 
 	bi->dma = xdp_umem_get_dma(umem, handle);
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.c +1 -1
index 6a55573ec8f2..85440b1c1c3f 100644
@@ -44,7 +44,7 @@ int mlx5e_xsk_page_alloc_umem(struct mlx5e_rq *rq,
 
 static inline void mlx5e_xsk_recycle_frame(struct mlx5e_rq *rq, u64 handle)
 {
-	xsk_umem_fq_reuse(rq->umem, handle & rq->umem->chunk_mask);
+	xsk_umem_fq_reuse(rq->umem, handle);
 }
 
 /* XSKRQ uses pages from UMEM, they must not be released. They are returned to
include/net/xdp_sock.h +1 -1
index 057b159ff8b9..39516d960636 100644
@@ -117,7 +117,7 @@ static inline u64 *xsk_umem_peek_addr_rq(struct xdp_umem *umem, u64 *addr)
 	if (!rq->length)
 		return xsk_umem_peek_addr(umem, addr);
 
-	*addr = rq->handles[rq->length - 1];
+	*addr = rq->handles[rq->length - 1] & umem->chunk_mask;
 	return addr;
 }
 
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/6 Clean up xsk reuseq API

In reply to Jonathan Lemon

The reuseq is actually a recycle stack, only accessed from the kernel side. Also, the implementation details of the stack should belong to the umem object, and not exposed to the caller.

Clean up and rename for consistency in preparation for the next patch.

---
 drivers/net/ethernet/intel/i40e/i40e_xsk.c    |  8 +--
 drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c  |  8 +--
 .../ethernet/mellanox/mlx5/core/en/xsk/rx.c   |  2 +-
 .../ethernet/mellanox/mlx5/core/en/xsk/umem.c |  7 +--
 include/net/xdp_sock.h                        | 23 ++------
 net/xdp/xdp_umem.c                            |  2 +-
 net/xdp/xsk_queue.c                           | 56 +++++++------------
 net/xdp/xsk_queue.h                           |  2 +-
 8 files changed, 33 insertions(+), 75 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_xsk.c +2 -6
index 3b84fca1c11d..7efe5905b0af 100644
@@ -78,7 +78,6 @@ static int i40e_xsk_umem_enable(struct i40e_vsi *vsi, struct xdp_umem *umem,
 				u16 qid)
 {
 	struct net_device *netdev = vsi->netdev;
-	struct xdp_umem_fq_reuse *reuseq;
 	bool if_running;
 	int err;
 
@@ -92,12 +91,9 @@ static int i40e_xsk_umem_enable(struct i40e_vsi *vsi, struct xdp_umem *umem,
 	    qid >= netdev->real_num_tx_queues)
 		return -EINVAL;
 
-	reuseq = xsk_reuseq_prepare(vsi->rx_rings[0]->count);
-	if (!reuseq)
+	if (!xsk_umem_recycle_alloc(umem, vsi->rx_rings[0]->count))
 		return -ENOMEM;
 
-	xsk_reuseq_free(xsk_reuseq_swap(umem, reuseq));
-
 	err = i40e_xsk_umem_dma_map(vsi, umem);
 	if (err)
 		return err;
@@ -811,7 +807,7 @@ void i40e_xsk_clean_rx_ring(struct i40e_ring *rx_ring)
 		if (!rx_bi->addr)
 			continue;
 
-		xsk_umem_fq_reuse(rx_ring->xsk_umem, rx_bi->handle);
+		xsk_umem_recycle_addr(rx_ring->xsk_umem, rx_bi->handle);
 		rx_bi->addr = NULL;
 	}
 }
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c +2 -6
index a9cab3271ac9..1e09fa7ffb90 100644
@@ -67,7 +67,6 @@ static int ixgbe_xsk_umem_enable(struct ixgbe_adapter *adapter,
 				 u16 qid)
 {
 	struct net_device *netdev = adapter->netdev;
-	struct xdp_umem_fq_reuse *reuseq;
 	bool if_running;
 	int err;
 
@@ -78,12 +77,9 @@ static int ixgbe_xsk_umem_enable(struct ixgbe_adapter *adapter,
 	    qid >= netdev->real_num_tx_queues)
 		return -EINVAL;
 
-	reuseq = xsk_reuseq_prepare(adapter->rx_ring[0]->count);
-	if (!reuseq)
+	if (!xsk_umem_recycle_alloc(umem, adapter->rx_ring[0]->count))
 		return -ENOMEM;
 
-	xsk_reuseq_free(xsk_reuseq_swap(umem, reuseq));
-
 	err = ixgbe_xsk_umem_dma_map(adapter, umem);
 	if (err)
 		return err;
@@ -554,7 +550,7 @@ void ixgbe_xsk_clean_rx_ring(struct ixgbe_ring *rx_ring)
 	struct ixgbe_rx_buffer *bi = &rx_ring->rx_buffer_info[i];
 
 	while (i != rx_ring->next_to_alloc) {
-		xsk_umem_fq_reuse(rx_ring->xsk_umem, bi->handle);
+		xsk_umem_recycle_addr(rx_ring->xsk_umem, bi->handle);
 		i++;
 		bi++;
 		if (i == rx_ring->count) {
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.c +1 -1
index 85440b1c1c3f..8d24eaa660a8 100644
@@ -44,7 +44,7 @@ int mlx5e_xsk_page_alloc_umem(struct mlx5e_rq *rq,
 
 static inline void mlx5e_xsk_recycle_frame(struct mlx5e_rq *rq, u64 handle)
 {
-	xsk_umem_fq_reuse(rq->umem, handle);
+	xsk_umem_recycle_addr(rq->umem, handle);
 }
 
 /* XSKRQ uses pages from UMEM, they must not be released. They are returned to
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/umem.c +1 -6
index 4baaa5788320..6f75ac653697 100644
@@ -243,13 +243,8 @@ int mlx5e_xsk_setup_umem(struct net_device *dev, struct xdp_umem *umem, u16 qid)
 
 int mlx5e_xsk_resize_reuseq(struct xdp_umem *umem, u32 nentries)
 {
-	struct xdp_umem_fq_reuse *reuseq;
-
-	reuseq = xsk_reuseq_prepare(nentries);
-	if (unlikely(!reuseq))
+	if (!xsk_umem_recycle_alloc(umem, nentries))
 		return -ENOMEM;
-	xsk_reuseq_free(xsk_reuseq_swap(umem, reuseq));
-
 	return 0;
 }
 
include/net/xdp_sock.h +5 -18
index 39516d960636..7df7b417ac53 100644
@@ -83,10 +83,7 @@ void xsk_umem_discard_addr(struct xdp_umem *umem);
 void xsk_umem_complete_tx(struct xdp_umem *umem, u32 nb_entries);
 bool xsk_umem_consume_tx(struct xdp_umem *umem, struct xdp_desc *desc);
 void xsk_umem_consume_tx_done(struct xdp_umem *umem);
-struct xdp_umem_fq_reuse *xsk_reuseq_prepare(u32 nentries);
-struct xdp_umem_fq_reuse *xsk_reuseq_swap(struct xdp_umem *umem,
-					  struct xdp_umem_fq_reuse *newq);
-void xsk_reuseq_free(struct xdp_umem_fq_reuse *rq);
+bool xsk_umem_recycle_alloc(struct xdp_umem *umem, u32 nentries);
 struct xdp_umem *xdp_get_umem_from_qid(struct net_device *dev, u16 queue_id);
 
 static inline char *xdp_umem_get_data(struct xdp_umem *umem, u64 addr)
@@ -131,7 +128,7 @@ static inline void xsk_umem_discard_addr_rq(struct xdp_umem *umem)
 		rq->length--;
 }
 
-static inline void xsk_umem_fq_reuse(struct xdp_umem *umem, u64 addr)
+static inline void xsk_umem_recycle_addr(struct xdp_umem *umem, u64 addr)
 {
 	struct xdp_umem_fq_reuse *rq = umem->fq_reuse;
 
@@ -185,19 +182,9 @@ static inline void xsk_umem_consume_tx_done(struct xdp_umem *umem)
 {
 }
 
-static inline struct xdp_umem_fq_reuse *xsk_reuseq_prepare(u32 nentries)
-{
-	return NULL;
-}
-
-static inline struct xdp_umem_fq_reuse *xsk_reuseq_swap(
-	struct xdp_umem *umem,
-	struct xdp_umem_fq_reuse *newq)
-{
-	return NULL;
-}
-static inline void xsk_reuseq_free(struct xdp_umem_fq_reuse *rq)
+static inline bool xsk_umem_recycle_alloc(struct xdp_umem *umem, u32 nentries)
 {
+	return false;
 }
 
 static inline struct xdp_umem *xdp_get_umem_from_qid(struct net_device *dev,
@@ -230,7 +217,7 @@ static inline void xsk_umem_discard_addr_rq(struct xdp_umem *umem)
 {
 }
 
-static inline void xsk_umem_fq_reuse(struct xdp_umem *umem, u64 addr)
+static inline void xsk_umem_recycle_addr(struct xdp_umem *umem, u64 addr)
 {
 }
 
net/xdp/xdp_umem.c +1 -1
index 9c6de4f114f8..2150ba3fc744 100644
@@ -208,7 +208,7 @@ static void xdp_umem_release(struct xdp_umem *umem)
 		umem->cq = NULL;
 	}
 
-	xsk_reuseq_destroy(umem);
+	xsk_umem_recycle_destroy(umem);
 
 	xdp_umem_unpin_pages(umem);
 
net/xdp/xsk_queue.c +20 -36

75 lines not on this page · raw message

net/xdp/xsk_queue.h +1 -1
index 12b49784a6d5..c9db4e8ae80e 100644
@@ -321,6 +321,6 @@ struct xsk_queue *xskq_create(u32 nentries, bool umem_queue);
 void xskq_destroy(struct xsk_queue *q_ops);
 
 /* Executed by the core when the entire UMEM gets freed */
-void xsk_reuseq_destroy(struct xdp_umem *umem);
+void xsk_umem_recycle_destroy(struct xdp_umem *umem);
 
 #endif /* _LINUX_XSK_QUEUE_H */
Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH 2/6 bpf-next] Clean up xsk reuseq API

Quoted 7 lines · Jonathan Lemon

The reuseq is actually a recycle stack, only accessed from the kernel side. Also, the implementation details of the stack should belong to the umem object, and not exposed to the caller.

Clean up and rename for consistency in preparation for the next patch.

Prepare/swap is to cater to how drivers should be written - being able to allocate resources independently of those currently used. Allowing for changing ring sizes and counts on the fly. This patch makes it harder to write drivers in the way we are encouraging people to.

IOW no, please don't do this.

#4 lore raw

Re: [PATCH 2/6 bpf-next] Clean up xsk reuseq API

Quoted 7 lines · Jakub Kicinski
Quoted 6 lines · Jonathan Lemon

The reuseq is actually a recycle stack, only accessed from the kernel side. Also, the implementation details of the stack should belong to the umem object, and not exposed to the caller.

Clean up and rename for consistency in preparation for the next patch.

Quoted 8 lines
Quoted 1 line

Prepare/swap is to cater to how drivers should be written - being able to allocate resources independently of those currently used. Allowing for changing ring sizes and counts on the fly. This patch makes it harder to write drivers in the way we are encouraging people to.

IOW no, please don't do this.

The main reason I rewrote this was to provide the same type of functionality as realloc() - no need to allocate/initialize a new array if the old one would still end up being used. This would seem to be a win for the typical case of having the interface go up/down.

Perhaps I should have named the function differently?

Signature · 1 line
Jonathan
#5 lore raw

Re: [PATCH 2/6 bpf-next] Clean up xsk reuseq API

Quoted 19 lines · Jonathan Lemon
Quoted 17 lines · Jakub Kicinski
Quoted 10 lines · Jonathan Lemon

The reuseq is actually a recycle stack, only accessed from the kernel side.
Also, the implementation details of the stack should belong to the umem
object, and not exposed to the caller.

Clean up and rename for consistency in preparation for the next patch.

Prepare/swap is to cater to how drivers should be written - being able to allocate resources independently of those currently used. Allowing for changing ring sizes and counts on the fly. This patch makes it harder to write drivers in the way we are encouraging people to.

Quoted 8 lines
Quoted 1 line

IOW no, please don't do this.

The main reason I rewrote this was to provide the same type of functionality as realloc() - no need to allocate/initialize a new array if the old one would still end up being used. This would seem to be a win for the typical case of having the interface go up/down.

Perhaps I should have named the function differently?

Perhaps add a helper which calls both parts to help poorly architected drivers?

#6 lore raw

Re: [PATCH 2/6 bpf-next] Clean up xsk reuseq API

Quoted 27 lines · Jakub Kicinski
Quoted 26 lines · Jonathan Lemon
Quoted 10 lines · Jakub Kicinski
Quoted 9 lines · Jonathan Lemon

The reuseq is actually a recycle stack, only accessed from the kernel side.
Also, the implementation details of the stack should belong to the umem
object, and not exposed to the caller.

Clean up and rename for consistency in preparation for the next patch.

Quoted 8 lines
Quoted 1 line

Prepare/swap is to cater to how drivers should be written - being able to allocate resources independently of those currently used. Allowing for changing ring sizes and counts on the fly. This patch makes it harder to write drivers in the way we are encouraging people to.

IOW no, please don't do this.

The main reason I rewrote this was to provide the same type of functionality as realloc() - no need to allocate/initialize a new array if the old one would still end up being used. This would seem to be a win for the typical case of having the interface go up/down.

Quoted 4 lines
Quoted 1 line

Perhaps I should have named the function differently?

Perhaps add a helper which calls both parts to help poorly architected drivers?

Still ends up taking more memory.

There are only 3 drivers in the tree which do AF_XDP: i40e, ixgbe, and mlx5.

All of these do the same thing:
reuseq = xsk_reuseq_prepare(n)
if (!reuseq)
error
xsk_reuseq_free(xsk_reuseq_swap(umem, reuseq));

I figured simplifying was a good thing.

But I do take your point that some future driver might want to allocate everything up front before performing a commit of the resources.

Signature · 1 line
Jonathan
#7 lore raw

Re: [PATCH 2/6 bpf-next] Clean up xsk reuseq API

Quoted 47 lines · Jonathan Lemon
Quoted 27 lines · Jakub Kicinski
Quoted 26 lines · Jonathan Lemon
Quoted 10 lines · Jakub Kicinski
Quoted 9 lines · Jonathan Lemon

The reuseq is actually a recycle stack, only accessed from the kernel side.
Also, the implementation details of the stack should belong to the umem
object, and not exposed to the caller.

Clean up and rename for consistency in preparation for the next patch.

Quoted 8 lines
Quoted 1 line

Prepare/swap is to cater to how drivers should be written - being able to allocate resources independently of those currently used. Allowing for changing ring sizes and counts on the fly. This patch makes it harder to write drivers in the way we are encouraging people to.

IOW no, please don't do this.

The main reason I rewrote this was to provide the same type of functionality as realloc() - no need to allocate/initialize a new array if the old one would still end up being used. This would seem to be a win for the typical case of having the interface go up/down.

Quoted 4 lines
Quoted 1 line

Perhaps I should have named the function differently?

Perhaps add a helper which calls both parts to help poorly architected drivers?

Still ends up taking more memory.

There are only 3 drivers in the tree which do AF_XDP: i40e, ixgbe, and mlx5.

All of these do the same thing:
reuseq = xsk_reuseq_prepare(n)
if (!reuseq)
error
xsk_reuseq_free(xsk_reuseq_swap(umem, reuseq));

Quoted 4 lines

I figured simplifying was a good thing.

But I do take your point that some future driver might want to allocate everything up front before performing a commit of the resources.

Jonathan, can you come up with a solution that satisfies both these
goals: providing a lower level API that Jakub can and would like to use for his driver and a higher level helper that can be used by today's driver to make the AF_XDP part smaller and easier to implement? I like the fact that you are simplifying the AF_XDP enabled drivers that are out there today, but at the same time I do not want to hinder Jakub from, hopefully, in the future upstreaming his support.

Thanks: Magnus

Quoted 2 lines

--
Jonathan

#8 lore raw

PATCH 3/6 Always check the recycle stack when using the umem fq.

In reply to Jonathan Lemon

The specific _rq variants are deprecated, and will be removed next.

---
 include/net/xdp_sock.h | 22 +++-------------------
 net/xdp/xsk.c          | 22 +++++++++++++++++++---
 2 files changed, 22 insertions(+), 22 deletions(-)
include/net/xdp_sock.h +3 -19
index 7df7b417ac53..55f5f27ef22a 100644
@@ -99,33 +99,17 @@ static inline dma_addr_t xdp_umem_get_dma(struct xdp_umem *umem, u64 addr)
 /* Reuse-queue aware version of FILL queue helpers */
 static inline bool xsk_umem_has_addrs_rq(struct xdp_umem *umem, u32 cnt)
 {
-	struct xdp_umem_fq_reuse *rq = umem->fq_reuse;
-
-	if (rq->length >= cnt)
-		return true;
-
-	return xsk_umem_has_addrs(umem, cnt - rq->length);
+	return xsk_umem_has_addrs(umem, cnt);
 }
 
 static inline u64 *xsk_umem_peek_addr_rq(struct xdp_umem *umem, u64 *addr)
 {
-	struct xdp_umem_fq_reuse *rq = umem->fq_reuse;
-
-	if (!rq->length)
-		return xsk_umem_peek_addr(umem, addr);
-
-	*addr = rq->handles[rq->length - 1] & umem->chunk_mask;
-	return addr;
+	return xsk_umem_peek_addr(umem, addr);
 }
 
 static inline void xsk_umem_discard_addr_rq(struct xdp_umem *umem)
 {
-	struct xdp_umem_fq_reuse *rq = umem->fq_reuse;
-
-	if (!rq->length)
-		xsk_umem_discard_addr(umem);
-	else
-		rq->length--;
+	return xsk_umem_discard_addr(umem);
 }
 
 static inline void xsk_umem_recycle_addr(struct xdp_umem *umem, u64 addr)
net/xdp/xsk.c +19 -3
index 74417a851ed5..fc33070b1821 100644
@@ -39,19 +39,35 @@ bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs)
 
 bool xsk_umem_has_addrs(struct xdp_umem *umem, u32 cnt)
 {
-	return xskq_has_addrs(umem->fq, cnt);
+	struct xdp_umem_fq_reuse *rq = umem->fq_reuse;
+
+        if (rq->length >= cnt)
+                return true;
+
+	return xskq_has_addrs(umem->fq, cnt - rq->length);
 }
 EXPORT_SYMBOL(xsk_umem_has_addrs);
 
 u64 *xsk_umem_peek_addr(struct xdp_umem *umem, u64 *addr)
 {
-	return xskq_peek_addr(umem->fq, addr);
+	struct xdp_umem_fq_reuse *rq = umem->fq_reuse;
+
+	if (!rq->length)
+		return xskq_peek_addr(umem->fq, addr);
+
+	*addr = rq->handles[rq->length - 1] & umem->chunk_mask;
+	return addr;
 }
 EXPORT_SYMBOL(xsk_umem_peek_addr);
 
 void xsk_umem_discard_addr(struct xdp_umem *umem)
 {
-	xskq_discard_addr(umem->fq);
+	struct xdp_umem_fq_reuse *rq = umem->fq_reuse;
+
+	if (!rq->length)
+		xskq_discard_addr(umem->fq);
+	else
+		rq->length--;
 }
 EXPORT_SYMBOL(xsk_umem_discard_addr);
 
Signature · 1 line
2.17.1
#9 lore raw

PATCH 4/6 Simplify AF_XDP umem allocation path for Intel drivers.

In reply to Jonathan Lemon

Now that the recycle stack is always used for the driver umem path, the driver code path can be simplified.

---
 drivers/net/ethernet/intel/i40e/i40e_xsk.c    | 76 ++-----------------
 .../ethernet/intel/ixgbe/ixgbe_txrx_common.h  |  2 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c  | 49 +-----------
 3 files changed, 13 insertions(+), 114 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_xsk.c +8 -68
index 7efe5905b0af..ce8650d06962 100644
@@ -265,44 +265,16 @@ static bool i40e_alloc_buffer_zc(struct i40e_ring *rx_ring,
 }
 
 /**
- * i40e_alloc_buffer_slow_zc - Allocates an i40e_rx_buffer
+ * i40e_alloc_rx_buffers_zc - Allocates a number of Rx buffers
  * @rx_ring: Rx ring
- * @bi: Rx buffer to populate
+ * @count: The number of buffers to allocate
  *
- * This function allocates an Rx buffer. The buffer can come from fill
- * queue, or via the reuse queue.
+ * This function allocates a number of Rx buffers from the fill ring
+ * or the internal recycle mechanism and places them on the Rx ring.
  *
  * Returns true for a successful allocation, false otherwise
  **/
-static bool i40e_alloc_buffer_slow_zc(struct i40e_ring *rx_ring,
-				      struct i40e_rx_buffer *bi)
-{
-	struct xdp_umem *umem = rx_ring->xsk_umem;
-	u64 handle, hr;
-
-	if (!xsk_umem_peek_addr_rq(umem, &handle)) {
-		rx_ring->rx_stats.alloc_page_failed++;
-		return false;
-	}
-
-	hr = umem->headroom + XDP_PACKET_HEADROOM;
-
-	bi->dma = xdp_umem_get_dma(umem, handle);
-	bi->dma += hr;
-
-	bi->addr = xdp_umem_get_data(umem, handle);
-	bi->addr += hr;
-
-	bi->handle = handle + umem->headroom;
-
-	xsk_umem_discard_addr_rq(umem);
-	return true;
-}
-
-static __always_inline bool
-__i40e_alloc_rx_buffers_zc(struct i40e_ring *rx_ring, u16 count,
-			   bool alloc(struct i40e_ring *rx_ring,
-				      struct i40e_rx_buffer *bi))
+bool i40e_alloc_rx_buffers_zc(struct i40e_ring *rx_ring, u16 count)
 {
 	u16 ntu = rx_ring->next_to_use;
 	union i40e_rx_desc *rx_desc;
@@ -312,7 +284,7 @@ __i40e_alloc_rx_buffers_zc(struct i40e_ring *rx_ring, u16 count,
 	rx_desc = I40E_RX_DESC(rx_ring, ntu);
 	bi = &rx_ring->rx_bi[ntu];
 	do {
-		if (!alloc(rx_ring, bi)) {
+		if (!i40e_alloc_buffer_zc(rx_ring, bi)) {
 			ok = false;
 			goto no_buffers;
 		}
@@ -344,38 +316,6 @@ __i40e_alloc_rx_buffers_zc(struct i40e_ring *rx_ring, u16 count,
 	return ok;
 }
 
-/**
- * i40e_alloc_rx_buffers_zc - Allocates a number of Rx buffers
- * @rx_ring: Rx ring
- * @count: The number of buffers to allocate
- *
- * This function allocates a number of Rx buffers from the reuse queue
- * or fill ring and places them on the Rx ring.
- *
- * Returns true for a successful allocation, false otherwise
- **/
-bool i40e_alloc_rx_buffers_zc(struct i40e_ring *rx_ring, u16 count)
-{
-	return __i40e_alloc_rx_buffers_zc(rx_ring, count,
-					  i40e_alloc_buffer_slow_zc);
-}
-
-/**
- * i40e_alloc_rx_buffers_fast_zc - Allocates a number of Rx buffers
- * @rx_ring: Rx ring
- * @count: The number of buffers to allocate
- *
- * This function allocates a number of Rx buffers from the fill ring
- * or the internal recycle mechanism and places them on the Rx ring.
- *
- * Returns true for a successful allocation, false otherwise
- **/
-static bool i40e_alloc_rx_buffers_fast_zc(struct i40e_ring *rx_ring, u16 count)
-{
-	return __i40e_alloc_rx_buffers_zc(rx_ring, count,
-					  i40e_alloc_buffer_zc);
-}
-
 /**
  * i40e_get_rx_buffer_zc - Return the current Rx buffer
  * @rx_ring: Rx ring
@@ -541,8 +481,8 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget)
 
 		if (cleaned_count >= I40E_RX_BUFFER_WRITE) {
 			failure = failure ||
-				  !i40e_alloc_rx_buffers_fast_zc(rx_ring,
-								 cleaned_count);
+				  !i40e_alloc_rx_buffers_zc(rx_ring,
+							    cleaned_count);
 			cleaned_count = 0;
 		}
 
drivers/net/ethernet/intel/ixgbe/ixgbe_txrx_common.h +1 -1
index d93a690aff74..7408fbc2e1e1 100644
@@ -35,7 +35,7 @@ int ixgbe_xsk_umem_setup(struct ixgbe_adapter *adapter, struct xdp_umem *umem,
 
 void ixgbe_zca_free(struct zero_copy_allocator *alloc, unsigned long handle);
 
-void ixgbe_alloc_rx_buffers_zc(struct ixgbe_ring *rx_ring, u16 cleaned_count);
+bool ixgbe_alloc_rx_buffers_zc(struct ixgbe_ring *rx_ring, u16 cleaned_count);
 int ixgbe_clean_rx_irq_zc(struct ixgbe_q_vector *q_vector,
 			  struct ixgbe_ring *rx_ring,
 			  const int budget);
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c +4 -45

73 lines not on this page · raw message

Signature · 1 line
2.17.1
#10 lore raw

Re: [PATCH 4/6 bfp-next] Simplify AF_XDP umem allocation path for Intel drivers.

Quoted 4 lines · Jonathan Lemon

Now that the recycle stack is always used for the driver umem path, the driver code path can be simplified.

I guess it's a question to Bjorn and Magnus whether they want Intel drivers to always go through the reuse queue..

Could you be more explicit on the motivation? I'd call this patch set "make all drivers use reuse queue" rather than "clean up".

Also when you're changing code please make sure you CC the author.

#11 lore raw

Re: [PATCH 4/6 bfp-next] Simplify AF_XDP umem allocation path for Intel drivers.

Quoted 8 lines · Jakub Kicinski
Quoted 4 lines · Jonathan Lemon

Now that the recycle stack is always used for the driver umem path, the driver code path can be simplified.

I guess it's a question to Bjorn and Magnus whether they want Intel drivers to always go through the reuse queue..

I did pass this by them earlier.

Quoted 2 lines

Could you be more explicit on the motivation? I'd call this patch set "make all drivers use reuse queue" rather than "clean up".

The motivation is to have packets which were received on a zero-copy AF_XDP socket, and which returned a TX verdict from the bpf program, queued directly on the TX ring (if they're in the same napi context).

When these TX packets are completed, they are placed back onto the reuse queue, as there isn't really any other place to handle them.

It also addresses Maxim's concern about having buffers end up sitting on the rq after a ring resize.

I was going to send the TX change out as part of this patch, but figured it would be better split unto its own series.

Quoted 1 line

Also when you're changing code please make sure you CC the author.

Who did I miss?

Signature · 1 line
Jonathan
Tested-by Andrew Bowers
#12 lore raw

Re: [PATCH 4/6 bfp-next] Simplify AF_XDP umem allocation path for Intel drivers.

Quoted 8 lines · Jonathan Lemon
Quoted 2 lines · Jakub Kicinski

Could you be more explicit on the motivation? I'd call this patch set "make all drivers use reuse queue" rather than "clean up".

The motivation is to have packets which were received on a zero-copy AF_XDP socket, and which returned a TX verdict from the bpf program, queued directly on the TX ring (if they're in the same napi context).

Quoted 8 lines

When these TX packets are completed, they are placed back onto the reuse queue, as there isn't really any other place to handle them.

It also addresses Maxim's concern about having buffers end up sitting on the rq after a ring resize.

I was going to send the TX change out as part of this patch, but figured it would be better split unto its own series.

Makes sense, please put that info in the cover letter. (in other nit picks please prefix the patches which the name of the subsystem they are touching - net: xsk: ?, and make sure all changes have a commit message).

Looking at this yesterday I think I've seen you didn't change the RQ sizing - for the TX side to work the rq size must be RX ring size
+ XDP TX ring size (IIRC that was the worst case number of packets which we may need to park during reconfiguration).

Maybe you did do that and I missed it.

Quoted 3 lines
Quoted 1 line

Also when you're changing code please make sure you CC the author.

Who did I miss?

commit f5bd91388e26557f64ca999e0006038c7a919308

Author: Jakub Kicinski <[email protected]>
Date:   Fri Sep 7 10:18:46 2018 +0200

net: xsk: add a simple buffer reuse queue

XSK UMEM is strongly single producer single consumer so reuse of frames is challenging. Add a simple "stash" of FILL packets to reuse for drivers to optionally make use of. This is useful when driver has to free (ndo_stop) or resize a ring with an active AF_XDP ZC socket.

Sorry to get upset, I missed a bpf patch recently and had to do a revert..

#13 lore raw

Re: [PATCH 4/6 bfp-next] Simplify AF_XDP umem allocation path for Intel drivers.

Quoted 23 lines · Jakub Kicinski
Quoted 8 lines · Jonathan Lemon
Quoted 2 lines · Jakub Kicinski

Could you be more explicit on the motivation? I'd call this patch set "make all drivers use reuse queue" rather than "clean up".

The motivation is to have packets which were received on a zero-copy AF_XDP socket, and which returned a TX verdict from the bpf program, queued directly on the TX ring (if they're in the same napi context).

Quoted 8 lines

When these TX packets are completed, they are placed back onto the reuse queue, as there isn't really any other place to handle them.

It also addresses Maxim's concern about having buffers end up sitting on the rq after a ring resize.

I was going to send the TX change out as part of this patch, but figured it would be better split unto its own series.

Makes sense, please put that info in the cover letter. (in other nit picks please prefix the patches which the name of the subsystem they are touching - net: xsk: ?, and make sure all changes have a commit message).

Quoted 6 lines

Looking at this yesterday I think I've seen you didn't change the RQ sizing - for the TX side to work the rq size must be RX ring size
+ XDP TX ring size (IIRC that was the worst case number of packets which we may need to park during reconfiguration).

Maybe you did do that and I missed it.

Not yet - that's in the TX section of the patches, I'll post the Intel versions shortly.

Quoted 16 lines
Quoted 3 lines
Quoted 1 line

Also when you're changing code please make sure you CC the author.

Who did I miss?

commit f5bd91388e26557f64ca999e0006038c7a919308

Author: Jakub Kicinski <[email protected]>
Date:   Fri Sep 7 10:18:46 2018 +0200

net: xsk: add a simple buffer reuse queue

XSK UMEM is strongly single producer single consumer so reuse of frames is challenging. Add a simple "stash" of FILL packets to reuse for drivers to optionally make use of. This is useful when driver has to free (ndo_stop) or resize a ring with an active AF_XDP ZC socket.

Quoted 7 lines

Sorry to get upset, I missed a bpf patch recently and had to do a revert..

Ack.

#14 lore raw

PATCH 5/6 Remove use of umem _rq variants from Mellanox driver.

In reply to Jonathan Lemon
---
 drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/rx.c +3 -3
index 8d24eaa660a8..e116b1fde797 100644
@@ -12,7 +12,7 @@ bool mlx5e_xsk_pages_enough_umem(struct mlx5e_rq *rq, int count)
 	/* Check in advance that we have enough frames, instead of allocating
 	 * one-by-one, failing and moving frames to the Reuse Ring.
 	 */
-	return xsk_umem_has_addrs_rq(rq->umem, count);
+	return xsk_umem_has_addrs(rq->umem, count);
 }
 
 int mlx5e_xsk_page_alloc_umem(struct mlx5e_rq *rq,
@@ -21,7 +21,7 @@ int mlx5e_xsk_page_alloc_umem(struct mlx5e_rq *rq,
 	struct xdp_umem *umem = rq->umem;
 	u64 handle;
 
-	if (!xsk_umem_peek_addr_rq(umem, &handle))
+	if (!xsk_umem_peek_addr(umem, &handle))
 		return -ENOMEM;
 
 	dma_info->xsk.handle = handle + rq->buff.umem_headroom;
@@ -34,7 +34,7 @@ int mlx5e_xsk_page_alloc_umem(struct mlx5e_rq *rq,
 	 */
 	dma_info->addr = xdp_umem_get_dma(umem, handle);
 
-	xsk_umem_discard_addr_rq(umem);
+	xsk_umem_discard_addr(umem);
 
 	dma_sync_single_for_device(rq->pdev, dma_info->addr, PAGE_SIZE,
 				   DMA_BIDIRECTIONAL);
Signature · 1 line
2.17.1
#15 lore raw
In reply to Jonathan Lemon
Quoted 11 lines · Jonathan Lemon

Clean up and normalize usage of the recycle queue in order to support upcoming TX from RX queue functionality.

Jonathan Lemon (6):
Have xsk_umem_peek_addr_rq() return chunk-aligned handles. Clean up xsk reuseq API
Always check the recycle stack when using the umem fq. Simplify AF_XDP umem allocation path for Intel drivers. Remove use of umem _rq variants from Mellanox driver. Remove the umem _rq variants now that the last consumer is gone.

Maybe it is just me, but I cannot find patch 6/6. Not in my gmail account and not in my Intel account. Am I just going insane :-)?

/Magnus

Quoted 15 lines
 drivers/net/ethernet/intel/i40e/i40e_xsk.c    | 86 +++----------------
 .../ethernet/intel/ixgbe/ixgbe_txrx_common.h  |  2 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c  | 59 ++-----------
 .../ethernet/mellanox/mlx5/core/en/xsk/rx.c   |  8 +-
 .../ethernet/mellanox/mlx5/core/en/xsk/umem.c |  7 +-
 include/net/xdp_sock.h                        | 69 ++-------------
 net/xdp/xdp_umem.c                            |  2 +-
 net/xdp/xsk.c                                 | 22 ++++-
 net/xdp/xsk_queue.c                           | 56 +++++-------
 net/xdp/xsk_queue.h                           |  2 +-
 10 files changed, 68 insertions(+), 245 deletions(-)

--
2.17.1