Skip to contentSkip to conversation

XDP multi buffer helpers

RFC PATCH In review [email protected] 6 participants 8 messages Jul 27, 2020 – Jul 28, 2020

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

cover XDP multi buffer helpers

From: Sameeh Jubran <[email protected]>

This series is based on the series that Lorenzo sent [0].

This series simply adds new bpf helpers for xdp mb support as well as introduces a sample program that uses them.

[0] - [RFC net-next 00/22] Introduce mb bit in xdp_buff/xdp_frame

Sameeh Jubran (2):
xdp: helpers: add multibuffer support samples/bpf: add bpf program that uses xdp mb helpers

 include/uapi/linux/bpf.h       |  13 +++
 net/core/filter.c              |  60 ++++++++++++++
 samples/bpf/Makefile           |   3 +
 samples/bpf/xdp_mb_kern.c      |  66 ++++++++++++++++
 samples/bpf/xdp_mb_user.c      | 174 +++++++++++++++++++++++++++++++++++++++++
 tools/include/uapi/linux/bpf.h |  13 +++
 6 files changed, 329 insertions(+)
 create mode 100644 samples/bpf/xdp_mb_kern.c
 create mode 100644 samples/bpf/xdp_mb_user.c
Signature · 1 line
2.16.6
#1 lore raw

RFC PATCH 1/2 xdp: helpers: add multibuffer support

From: Sameeh Jubran <[email protected]>

The implementation is based on this [0] draft by Jesper D. Brouer.

Provided two helpers:

* bpf_xdp_get_frag()
* bpf_xdp_get_frag_count()

[0] xdp mb design - https://github.com/xdp-project/xdp-project/blob/master/areas/core/xdp-multi-buffer01-design.org

---
 include/uapi/linux/bpf.h       | 13 +++++++++
 net/core/filter.c              | 60 ++++++++++++++++++++++++++++++++++++++++++
 tools/include/uapi/linux/bpf.h | 13 +++++++++
 3 files changed, 86 insertions(+)
include/uapi/linux/bpf.h +13 -0
index 5e3863899..3484e481a 100644
@@ -3320,6 +3320,17 @@ union bpf_attr {
  *		A non-negative value equal to or less than *size* on success,
  *		or a negative error in case of failure.
  *
+ * int bpf_xdp_get_frag(struct xdp_buff *xdp_md, u32 frag_index, u32 *size, u32 *offset)
+ * 	Description
+ *		Get the offset from containing page and size of a given frag.
+ * 	Return
+ * 		0 on success, or a negative error in case of failure.
+ *
+ * int bpf_xdp_get_frag_count(struct xdp_buff *xdp_md)
+ * 	Description
+ *		Get the total number of frags for a given packet.
+ * 	Return
+ * 		The number of frags
  */
 #define __BPF_FUNC_MAPPER(FN)		\
 	FN(unspec),			\
@@ -3464,6 +3475,8 @@ union bpf_attr {
 	FN(skc_to_tcp_request_sock),	\
 	FN(skc_to_udp6_sock),		\
 	FN(get_task_stack),		\
+	FN(xdp_get_frag),		\
+	FN(xdp_get_frag_count),		\
 	/* */
 
 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
net/core/filter.c +60 -0

72 lines not on this page · raw message

tools/include/uapi/linux/bpf.h +13 -0
index 5e3863899..3484e481a 100644
@@ -3320,6 +3320,17 @@ union bpf_attr {
  *		A non-negative value equal to or less than *size* on success,
  *		or a negative error in case of failure.
  *
+ * int bpf_xdp_get_frag(struct xdp_buff *xdp_md, u32 frag_index, u32 *size, u32 *offset)
+ * 	Description
+ *		Get the offset from containing page and size of a given frag.
+ * 	Return
+ * 		0 on success, or a negative error in case of failure.
+ *
+ * int bpf_xdp_get_frag_count(struct xdp_buff *xdp_md)
+ * 	Description
+ *		Get the total number of frags for a given packet.
+ * 	Return
+ * 		The number of frags
  */
 #define __BPF_FUNC_MAPPER(FN)		\
 	FN(unspec),			\
@@ -3464,6 +3475,8 @@ union bpf_attr {
 	FN(skc_to_tcp_request_sock),	\
 	FN(skc_to_udp6_sock),		\
 	FN(get_task_stack),		\
+	FN(xdp_get_frag),		\
+	FN(xdp_get_frag_count),		\
 	/* */
 
 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
Signature · 1 line
2.16.6
#2 lore raw

Re: [PATCH RFC net-next 1/2] xdp: helpers: add multibuffer support

reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux…

Hi,

[FYI, it's a private test report for your RFC patch.] [auto build test ERROR on net-next/master]

url:    https://github.com/0day-ci/linux/commits/sameehj-amazon-com/XDP-multi-buffer-helpers/20200727-210026
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git a57066b1a01977a646145f4ce8dfb4538b08368a
config: nios2-defconfig (attached as .config)
compiler: nios2-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=nios2

If you fix the issue, kindly add following tag as appropriate

All error/warnings (new ones prefixed by >>):

net/core/filter.c: In function '__bpf_xdp_has_frags':

>> net/core/filter.c:3480:12: error: 'struct xdp_buff' has no member named 'mb'
    3480 |  return xdp->mb != 0;
         |            ^~
>> net/core/filter.c:3481:1: warning: control reaches end of non-void function [-Wreturn-type]
    3481 | }
         | ^

vim +3480 net/core/filter.c

3477
3478 static inline bool __bpf_xdp_has_frags(struct xdp_buff *xdp)
3479 {

> 3480		return xdp->mb != 0;
> 3481	}

3482

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer
#3 lore raw

Re: [PATCH RFC net-next 1/2] xdp: helpers: add multibuffer support

In reply to [email protected]

From: <[email protected]>
Date: Mon, 27 Jul 2020 12:56:52 +0000

net/core/filter.c static const struct bpf_func_proto bpf_xdp_adjust_head_proto = { · line 3458

Quoted 12 lines
net/core/filter.c +4 -0
index bdd2382e6..93e790d7b 100644
@@ -3452,6 +3452,62 @@ static const struct bpf_func_proto bpf_xdp_adjust_head_proto = {
 	.arg2_type	= ARG_ANYTHING,
 };
 
+static inline bool __bpf_xdp_has_frags(struct  xdp_buff *xdp)
+{
+	return xdp->mb != 0;
+}

Please don't use the inline keyword in foo.c files, let the compiler decide.

Thank you.

#4 lore raw

RFC PATCH 2/2 samples/bpf: add bpf program that uses xdp mb helpers

In reply to [email protected]

From: Sameeh Jubran <[email protected]>

The bpf program returns XDP_PASS for every packet and calculates the total number of bytes in its linear and paged parts.

The program is executed with:
./xdp_mb [if name]

and has the following output format:
[if index]: [rx packet count] pkt/sec, [number of bytes] bytes/sec

---
 samples/bpf/Makefile      |   3 +
 samples/bpf/xdp_mb_kern.c |  66 ++++++++++++++++++
 samples/bpf/xdp_mb_user.c | 174 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 243 insertions(+)
 create mode 100644 samples/bpf/xdp_mb_kern.c
 create mode 100644 samples/bpf/xdp_mb_user.c
samples/bpf/Makefile +3 -0
index f87ee0207..fd21d99e5 100644
@@ -53,6 +53,7 @@ tprogs-y += task_fd_query
 tprogs-y += xdp_sample_pkts
 tprogs-y += ibumad
 tprogs-y += hbm
+tprogs-y += xdp_mb
 
 # Libbpf dependencies
 LIBBPF = $(TOOLS_PATH)/lib/bpf/libbpf.a
@@ -109,6 +110,7 @@ task_fd_query-objs := bpf_load.o task_fd_query_user.o $(TRACE_HELPERS)
 xdp_sample_pkts-objs := xdp_sample_pkts_user.o $(TRACE_HELPERS)
 ibumad-objs := bpf_load.o ibumad_user.o $(TRACE_HELPERS)
 hbm-objs := bpf_load.o hbm.o $(CGROUP_HELPERS)
+xdp_mb-objs := xdp_mb_user.o
 
 # Tell kbuild to always build the programs
 always-y := $(tprogs-y)
@@ -170,6 +172,7 @@ always-y += ibumad_kern.o
 always-y += hbm_out_kern.o
 always-y += hbm_edt_kern.o
 always-y += xdpsock_kern.o
+always-y += xdp_mb_kern.o
 
 ifeq ($(ARCH), arm)
 # Strip all except -D__LINUX_ARM_ARCH__ option needed to handle linux
samples/bpf/xdp_mb_kern.c new file +66 -0

66 lines not on this page · raw message

samples/bpf/xdp_mb_user.c new file +174 -0

174 lines not on this page · raw message

Signature · 1 line
2.16.6
#5 lore raw
In reply to [email protected]
Quoted 3 lines · On Mon, Jul 27, 2020 at 12:56:51PM +0000, [email protected] wrote:

From: Sameeh Jubran <[email protected]>

This series is based on the series that Lorenzo sent [0].

What is your final design for multi buffer support in XDP? Why don't you provide a single RFC that is fully functional but instead you're sending a bunch of separate RFCs?

IMHO it's a weird strategy. Not sure what others think about.

Quoted 5 lines

This series simply adds new bpf helpers for xdp mb support as well as introduces a sample program that uses them.

[0] - [RFC net-next 00/22] Introduce mb bit in xdp_buff/xdp_frame

Direct link wouldn't hurt I guess :) Please also include all the previous discussions that took place on mailing list around this topic. This will make reviewers life easier I suppose. As I asked above, I'm not sure what's your final design for this feature.

Quoted 18 lines

Sameeh Jubran (2):
xdp: helpers: add multibuffer support samples/bpf: add bpf program that uses xdp mb helpers

 include/uapi/linux/bpf.h       |  13 +++
 net/core/filter.c              |  60 ++++++++++++++
 samples/bpf/Makefile           |   3 +
 samples/bpf/xdp_mb_kern.c      |  66 ++++++++++++++++
 samples/bpf/xdp_mb_user.c      | 174 +++++++++++++++++++++++++++++++++++++++++
 tools/include/uapi/linux/bpf.h |  13 +++
 6 files changed, 329 insertions(+)
 create mode 100644 samples/bpf/xdp_mb_kern.c
 create mode 100644 samples/bpf/xdp_mb_user.c
Signature · 1 line
2.16.6
#6 lore raw
Quoted 8 lines · On Mon, Jul 27, 2020 at 12:56:51PM +0000, [email protected] wrote:
Quoted 3 lines

From: Sameeh Jubran <[email protected]>

This series is based on the series that Lorenzo sent [0].

What is your final design for multi buffer support in XDP? Why don't you provide a single RFC that is fully functional but instead you're sending a bunch of separate RFCs?

Hi Maciej,

IMO the buffer layout is defined now (we will use the trailing part of the "linear" area of the xdp_buff to store references for subsequent buffers like we already do for skb).
What is not defined yet are the metadata (e.g. number of frames, total length, ..) we want to pass to the bpf layer. This is the main reason why I sent this series
[1] as RFC, I want to collect feedbacks about this approach. For the moment (at least in my series) mb in xdp_buff is just used to indicate if this is a multi-buff xdp_buff.

Quoted 3 lines

IMHO it's a weird strategy. Not sure what others think about.

we did not coordinate, sorry for the noise.

Regards,
Lorenzo

[1] https://patchwork.ozlabs.org/project/netdev/cover/[email protected]/

Quoted 30 lines
Quoted 5 lines

This series simply adds new bpf helpers for xdp mb support as well as introduces a sample program that uses them.

[0] - [RFC net-next 00/22] Introduce mb bit in xdp_buff/xdp_frame

Direct link wouldn't hurt I guess :) Please also include all the previous discussions that took place on mailing list around this topic. This will make reviewers life easier I suppose. As I asked above, I'm not sure what's your final design for this feature.

Quoted 18 lines

Sameeh Jubran (2):
xdp: helpers: add multibuffer support samples/bpf: add bpf program that uses xdp mb helpers

 include/uapi/linux/bpf.h       |  13 +++
 net/core/filter.c              |  60 ++++++++++++++
 samples/bpf/Makefile           |   3 +
 samples/bpf/xdp_mb_kern.c      |  66 ++++++++++++++++
 samples/bpf/xdp_mb_user.c      | 174 +++++++++++++++++++++++++++++++++++++++++
 tools/include/uapi/linux/bpf.h |  13 +++
 6 files changed, 329 insertions(+)
 create mode 100644 samples/bpf/xdp_mb_kern.c
 create mode 100644 samples/bpf/xdp_mb_user.c
Signature · 1 line
2.16.6
maintainer
#7 lore raw
In reply to Maciej Fijalkowski
Quoted 8 lines · On Tue, 28 Jul 2020 14:33:27 +0200 Maciej Fijalkowski wrote:
Quoted 3 lines · On Mon, Jul 27, 2020 at 12:56:51PM +0000, [email protected] wrote:

From: Sameeh Jubran <[email protected]>

This series is based on the series that Lorenzo sent [0].

What is your final design for multi buffer support in XDP? Why don't you provide a single RFC that is fully functional but instead you're sending a bunch of separate RFCs?

+1

are we expecting a new attachment type?