BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next 0/2] xsk: support redirect to any socket bound to the same umem
@ 2024-02-05 12:35 Magnus Karlsson
  2024-02-05 12:35 ` [PATCH bpf-next 1/2] " Magnus Karlsson
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Magnus Karlsson @ 2024-02-05 12:35 UTC (permalink / raw)
  To: magnus.karlsson, bjorn, ast, daniel, netdev, maciej.fijalkowski,
	yuvale
  Cc: Magnus Karlsson, bpf

This patch set adds support for directing a packet to any socket bound
to the same umem. This makes it possible to use the XDP program to
select what socket the packet should be received on. The user can
populate the XSKMAP with various sockets and as long as they share the
same umem, the XDP program can pick any one of them.

The implementation is straight-forward. Instead of testing that the
incoming packet is targeting the same device and queue id as the
socket is bound to, just check that the umem the packet was received
on is the same as the socket we want it to be received on. This
guarantees that the redirect is legal as it is already in the correct
umem.

Patch #1 implements the feature and patch #2 adds documentation.

Thanks: Magnus

Magnus Karlsson (2):
  xsk: support redirect to any socket bound to the same umem
  xsk: document ability to redirect to any socket bound to the same umem

 Documentation/networking/af_xdp.rst | 33 +++++++++++++++++------------
 net/xdp/xsk.c                       |  5 ++++-
 2 files changed, 23 insertions(+), 15 deletions(-)


base-commit: 2a79690eae953daaac232f93e6c5ac47ac539f2d
--
2.42.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH bpf-next 1/2] xsk: support redirect to any socket bound to the same umem
  2024-02-05 12:35 [PATCH bpf-next 0/2] xsk: support redirect to any socket bound to the same umem Magnus Karlsson
@ 2024-02-05 12:35 ` Magnus Karlsson
  2024-02-05 14:26   ` Willem de Bruijn
  2024-02-05 12:35 ` [PATCH bpf-next 2/2] xsk: document ability to " Magnus Karlsson
  2024-02-06  4:10 ` [PATCH bpf-next 0/2] xsk: support " patchwork-bot+netdevbpf
  2 siblings, 1 reply; 5+ messages in thread
From: Magnus Karlsson @ 2024-02-05 12:35 UTC (permalink / raw)
  To: magnus.karlsson, bjorn, ast, daniel, netdev, maciej.fijalkowski,
	yuvale; +Cc: bpf

From: Magnus Karlsson <magnus.karlsson@intel.com>

Add support for directing a packet to any socket bound to the same
umem. This makes it possible to use the XDP program to select what
socket the packet should be received on. The user can populate the
XSKMAP with various sockets and as long as they share the same umem,
the XDP program can pick any one of them.

Suggested-by: Yuval El-Hanany <yuvale@radware.com>
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
---
 net/xdp/xsk.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 1eadfac03cc4..a339e9a1b557 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -313,10 +313,13 @@ static bool xsk_is_bound(struct xdp_sock *xs)
 
 static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
 {
+	struct net_device *dev = xdp->rxq->dev;
+	u32 qid = xdp->rxq->queue_index;
+
 	if (!xsk_is_bound(xs))
 		return -ENXIO;
 
-	if (xs->dev != xdp->rxq->dev || xs->queue_id != xdp->rxq->queue_index)
+	if (!dev->_rx[qid].pool || xs->umem != dev->_rx[qid].pool->umem)
 		return -EINVAL;
 
 	if (len > xsk_pool_get_rx_frame_size(xs->pool) && !xs->sg) {
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH bpf-next 2/2] xsk: document ability to redirect to any socket bound to the same umem
  2024-02-05 12:35 [PATCH bpf-next 0/2] xsk: support redirect to any socket bound to the same umem Magnus Karlsson
  2024-02-05 12:35 ` [PATCH bpf-next 1/2] " Magnus Karlsson
@ 2024-02-05 12:35 ` Magnus Karlsson
  2024-02-06  4:10 ` [PATCH bpf-next 0/2] xsk: support " patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: Magnus Karlsson @ 2024-02-05 12:35 UTC (permalink / raw)
  To: magnus.karlsson, bjorn, ast, daniel, netdev, maciej.fijalkowski,
	yuvale; +Cc: bpf

From: Magnus Karlsson <magnus.karlsson@intel.com>

Document the ability to redirect to any socket bound to the same umem.

Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
---
 Documentation/networking/af_xdp.rst | 33 +++++++++++++++++------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/Documentation/networking/af_xdp.rst b/Documentation/networking/af_xdp.rst
index dceeb0d763aa..72da7057e4cf 100644
--- a/Documentation/networking/af_xdp.rst
+++ b/Documentation/networking/af_xdp.rst
@@ -329,23 +329,24 @@ XDP_SHARED_UMEM option and provide the initial socket's fd in the
 sxdp_shared_umem_fd field as you registered the UMEM on that
 socket. These two sockets will now share one and the same UMEM.
 
-There is no need to supply an XDP program like the one in the previous
-case where sockets were bound to the same queue id and
-device. Instead, use the NIC's packet steering capabilities to steer
-the packets to the right queue. In the previous example, there is only
-one queue shared among sockets, so the NIC cannot do this steering. It
-can only steer between queues.
-
-In libbpf, you need to use the xsk_socket__create_shared() API as it
-takes a reference to a FILL ring and a COMPLETION ring that will be
-created for you and bound to the shared UMEM. You can use this
-function for all the sockets you create, or you can use it for the
-second and following ones and use xsk_socket__create() for the first
-one. Both methods yield the same result.
+In this case, it is possible to use the NIC's packet steering
+capabilities to steer the packets to the right queue. This is not
+possible in the previous example as there is only one queue shared
+among sockets, so the NIC cannot do this steering as it can only steer
+between queues.
+
+In libxdp (or libbpf prior to version 1.0), you need to use the
+xsk_socket__create_shared() API as it takes a reference to a FILL ring
+and a COMPLETION ring that will be created for you and bound to the
+shared UMEM. You can use this function for all the sockets you create,
+or you can use it for the second and following ones and use
+xsk_socket__create() for the first one. Both methods yield the same
+result.
 
 Note that a UMEM can be shared between sockets on the same queue id
 and device, as well as between queues on the same device and between
-devices at the same time.
+devices at the same time. It is also possible to redirect to any
+socket as long as it is bound to the same umem with XDP_SHARED_UMEM.
 
 XDP_USE_NEED_WAKEUP bind flag
 -----------------------------
@@ -822,6 +823,10 @@ A: The short answer is no, that is not supported at the moment. The
    switch, or other distribution mechanism, in your NIC to direct
    traffic to the correct queue id and socket.
 
+   Note that if you are using the XDP_SHARED_UMEM option, it is
+   possible to switch traffic between any socket bound to the same
+   umem.
+
 Q: My packets are sometimes corrupted. What is wrong?
 
 A: Care has to be taken not to feed the same buffer in the UMEM into
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next 1/2] xsk: support redirect to any socket bound to the same umem
  2024-02-05 12:35 ` [PATCH bpf-next 1/2] " Magnus Karlsson
@ 2024-02-05 14:26   ` Willem de Bruijn
  0 siblings, 0 replies; 5+ messages in thread
From: Willem de Bruijn @ 2024-02-05 14:26 UTC (permalink / raw)
  To: Magnus Karlsson, magnus.karlsson, bjorn, ast, daniel, netdev,
	maciej.fijalkowski, yuvale
  Cc: bpf

Magnus Karlsson wrote:
> From: Magnus Karlsson <magnus.karlsson@intel.com>
> 
> Add support for directing a packet to any socket bound to the same
> umem. This makes it possible to use the XDP program to select what
> socket the packet should be received on. The user can populate the
> XSKMAP with various sockets and as long as they share the same umem,
> the XDP program can pick any one of them.
> 
> Suggested-by: Yuval El-Hanany <yuvale@radware.com>
> Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>

Reviewed-by: Willem de Bruijn <willemb@google.com>

This will greatly simplify using AF_XDP sockets with standard RSS.

A socket can be attached to each NIC receive queue, and regardless to
which queue RSS directs a packet, the XDP program can pass it to the
AF_XDP socket that is the intended target.

In the trivial case a single AF_XDP socket receives all XDP_REDIRECT
traffic for the entire device. Similar to how a single PF_PACKET
socket can access all ingress traffic.

Though N fill queues still need to be maintained of course.

> ---
>  net/xdp/xsk.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index 1eadfac03cc4..a339e9a1b557 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
> @@ -313,10 +313,13 @@ static bool xsk_is_bound(struct xdp_sock *xs)
>  
>  static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len)
>  {
> +	struct net_device *dev = xdp->rxq->dev;
> +	u32 qid = xdp->rxq->queue_index;
> +
>  	if (!xsk_is_bound(xs))
>  		return -ENXIO;
>  
> -	if (xs->dev != xdp->rxq->dev || xs->queue_id != xdp->rxq->queue_index)
> +	if (!dev->_rx[qid].pool || xs->umem != dev->_rx[qid].pool->umem)
>  		return -EINVAL;
>  
>  	if (len > xsk_pool_get_rx_frame_size(xs->pool) && !xs->sg) {
> -- 
> 2.42.0
> 



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next 0/2] xsk: support redirect to any socket bound to the same umem
  2024-02-05 12:35 [PATCH bpf-next 0/2] xsk: support redirect to any socket bound to the same umem Magnus Karlsson
  2024-02-05 12:35 ` [PATCH bpf-next 1/2] " Magnus Karlsson
  2024-02-05 12:35 ` [PATCH bpf-next 2/2] xsk: document ability to " Magnus Karlsson
@ 2024-02-06  4:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-02-06  4:10 UTC (permalink / raw)
  To: Magnus Karlsson
  Cc: magnus.karlsson, bjorn, ast, daniel, netdev, maciej.fijalkowski,
	yuvale, bpf

Hello:

This series was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Mon,  5 Feb 2024 13:35:49 +0100 you wrote:
> This patch set adds support for directing a packet to any socket bound
> to the same umem. This makes it possible to use the XDP program to
> select what socket the packet should be received on. The user can
> populate the XSKMAP with various sockets and as long as they share the
> same umem, the XDP program can pick any one of them.
> 
> The implementation is straight-forward. Instead of testing that the
> incoming packet is targeting the same device and queue id as the
> socket is bound to, just check that the umem the packet was received
> on is the same as the socket we want it to be received on. This
> guarantees that the redirect is legal as it is already in the correct
> umem.
> 
> [...]

Here is the summary with links:
  - [bpf-next,1/2] xsk: support redirect to any socket bound to the same umem
    https://git.kernel.org/bpf/bpf-next/c/2863d665ea41
  - [bpf-next,2/2] xsk: document ability to redirect to any socket bound to the same umem
    https://git.kernel.org/bpf/bpf-next/c/968595a93669

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-02-06  4:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-05 12:35 [PATCH bpf-next 0/2] xsk: support redirect to any socket bound to the same umem Magnus Karlsson
2024-02-05 12:35 ` [PATCH bpf-next 1/2] " Magnus Karlsson
2024-02-05 14:26   ` Willem de Bruijn
2024-02-05 12:35 ` [PATCH bpf-next 2/2] xsk: document ability to " Magnus Karlsson
2024-02-06  4:10 ` [PATCH bpf-next 0/2] xsk: support " patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox