bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
	andrii@kernel.org
Cc: netdev@vger.kernel.org, magnus.karlsson@intel.com,
	bjorn@kernel.org, toke@kernel.org, kuba@kernel.org,
	horms@kernel.org, tirthendu.sarkar@intel.com
Subject: [PATCH v7 bpf-next 02/24] xsk: introduce XSK_USE_SG bind flag for xsk socket
Date: Wed, 19 Jul 2023 15:23:59 +0200	[thread overview]
Message-ID: <20230719132421.584801-3-maciej.fijalkowski@intel.com> (raw)
In-Reply-To: <20230719132421.584801-1-maciej.fijalkowski@intel.com>

From: Tirthendu Sarkar <tirthendu.sarkar@intel.com>

As of now xsk core drops any xdp_buff with data size greater than the
xsk frame_size as set by the af_xdp application. With multi-buffer
support introduced in the next patch xsk core can now split those
buffers into multiple descriptors provided the af_xdp application can
handle them. Such capability of the application needs to be independent
of the xdp_prog's frag support capability since there are cases where
even a single xdp_buffer may need to be split into multiple descriptors
owing to a smaller xsk frame size.

For e.g., with NIC rx_buffer size set to 4kB, a 3kB packet will
constitute of a single buffer and so will be sent as such to AF_XDP layer
irrespective of 'xdp.frags' capability of the XDP program. Now if the xsk
frame size is set to 2kB by the AF_XDP application, then the packet will
need to be split into 2 descriptors if AF_XDP application can handle
multi-buffer, else it needs to be dropped.

Applications can now advertise their frag handling capability to xsk core
so that xsk core can decide if it should drop or split xdp_buffs that
exceed xsk frame size. This is done using a new 'XSK_USE_SG' bind flag
for the xdp socket.

Signed-off-by: Tirthendu Sarkar <tirthendu.sarkar@intel.com>
---
 include/net/xdp_sock.h      | 1 +
 include/uapi/linux/if_xdp.h | 6 ++++++
 net/xdp/xsk.c               | 5 +++--
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h
index e96a1151ec75..36b0411a0d1b 100644
--- a/include/net/xdp_sock.h
+++ b/include/net/xdp_sock.h
@@ -52,6 +52,7 @@ struct xdp_sock {
 	struct xsk_buff_pool *pool;
 	u16 queue_id;
 	bool zc;
+	bool sg;
 	enum {
 		XSK_READY = 0,
 		XSK_BOUND,
diff --git a/include/uapi/linux/if_xdp.h b/include/uapi/linux/if_xdp.h
index 434f313dc26c..8d48863472b9 100644
--- a/include/uapi/linux/if_xdp.h
+++ b/include/uapi/linux/if_xdp.h
@@ -25,6 +25,12 @@
  * application.
  */
 #define XDP_USE_NEED_WAKEUP (1 << 3)
+/* By setting this option, userspace application indicates that it can
+ * handle multiple descriptors per packet thus enabling AF_XDP to split
+ * multi-buffer XDP frames into multiple Rx descriptors. Without this set
+ * such frames will be dropped.
+ */
+#define XDP_USE_SG	(1 << 4)
 
 /* Flags for xsk_umem_config flags */
 #define XDP_UMEM_UNALIGNED_CHUNK_FLAG (1 << 0)
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 914a80cd55d3..7b709e4e7ec4 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -897,7 +897,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
 
 	flags = sxdp->sxdp_flags;
 	if (flags & ~(XDP_SHARED_UMEM | XDP_COPY | XDP_ZEROCOPY |
-		      XDP_USE_NEED_WAKEUP))
+		      XDP_USE_NEED_WAKEUP | XDP_USE_SG))
 		return -EINVAL;
 
 	bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
@@ -929,7 +929,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
 		struct socket *sock;
 
 		if ((flags & XDP_COPY) || (flags & XDP_ZEROCOPY) ||
-		    (flags & XDP_USE_NEED_WAKEUP)) {
+		    (flags & XDP_USE_NEED_WAKEUP) || (flags & XDP_USE_SG)) {
 			/* Cannot specify flags for shared sockets. */
 			err = -EINVAL;
 			goto out_unlock;
@@ -1028,6 +1028,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
 
 	xs->dev = dev;
 	xs->zc = xs->umem->zc;
+	xs->sg = !!(flags & XDP_USE_SG);
 	xs->queue_id = qid;
 	xp_add_xsk(xs->pool, xs);
 
-- 
2.34.1


  parent reply	other threads:[~2023-07-19 13:25 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-19 13:23 [PATCH v7 bpf-next 00/24] xsk: multi-buffer support Maciej Fijalkowski
2023-07-19 13:23 ` [PATCH v7 bpf-next 01/24] xsk: prepare 'options' in xdp_desc for multi-buffer use Maciej Fijalkowski
2023-07-19 13:23 ` Maciej Fijalkowski [this message]
2023-07-19 13:24 ` [PATCH v7 bpf-next 03/24] xsk: prepare both copy and zero-copy modes to co-exist Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 04/24] xsk: move xdp_buff's data length check to xsk_rcv_check Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 05/24] xsk: add support for AF_XDP multi-buffer on Rx path Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 06/24] xsk: introduce wrappers and helpers for supporting multi-buffer in Tx path Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 07/24] xsk: allow core/drivers to test EOP bit Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 08/24] xsk: add support for AF_XDP multi-buffer on Tx path Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 09/24] xsk: discard zero length descriptors in " Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 10/24] xsk: add new netlink attribute dedicated for ZC max frags Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 11/24] xsk: support mbuf on ZC RX Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 12/24] ice: xsk: add RX multi-buffer support Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 13/24] i40e: " Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 14/24] xsk: support ZC Tx multi-buffer in batch API Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 15/24] ice: xsk: Tx multi-buffer support Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 16/24] i40e: xsk: add TX " Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 17/24] xsk: add multi-buffer documentation Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 18/24] selftests/xsk: transmit and receive multi-buffer packets Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 19/24] selftests/xsk: add basic multi-buffer test Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 20/24] selftests/xsk: add unaligned mode test for multi-buffer Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 21/24] selftests/xsk: add invalid descriptor " Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 22/24] selftests/xsk: add metadata copy test for multi-buff Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 23/24] selftests/xsk: add test for too many frags Maciej Fijalkowski
2023-07-19 13:24 ` [PATCH v7 bpf-next 24/24] selftests/xsk: reset NIC settings to default after running test suite Maciej Fijalkowski
2023-07-19 17:10 ` [PATCH v7 bpf-next 00/24] xsk: multi-buffer support patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230719132421.584801-3-maciej.fijalkowski@intel.com \
    --to=maciej.fijalkowski@intel.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=tirthendu.sarkar@intel.com \
    --cc=toke@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).