DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [RFC 1/2] tap: stop "vendoring" linux bpf headers
Date: Mon, 29 Jan 2024 19:46:51 -0800	[thread overview]
Message-ID: <20240130034925.44869-2-stephen@networkplumber.org> (raw)
In-Reply-To: <20240130034925.44869-1-stephen@networkplumber.org>

The proper place for finding bpf structures and functions is
in linux/bpf.h. The original version was trying to workaround the
case where the build environment was running on old pre BPF
version of Glibc, but the target environment had BPF. This is not
a supportable build method, and not how rest of DPDK works.

Having own private (and divergent) version headers leads to future
problems when BPF definitions evolve.

Since DPDK officially supports only LTS or later kernel
there is no need for the #ifdef workarounds in the TAP flow
code. Cloning headers leads to problems and no longer needed.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/tap/bpf/bpf_extract.py |   1 -
 drivers/net/tap/tap_bpf.h          | 121 -----------------------------
 drivers/net/tap/tap_bpf_api.c      |  20 +++--
 drivers/net/tap/tap_bpf_insns.h    |   1 -
 drivers/net/tap/tap_flow.c         |  89 ---------------------
 5 files changed, 13 insertions(+), 219 deletions(-)
 delete mode 100644 drivers/net/tap/tap_bpf.h

diff --git a/drivers/net/tap/bpf/bpf_extract.py b/drivers/net/tap/bpf/bpf_extract.py
index b630c42b809f..73c4dafe4eca 100644
--- a/drivers/net/tap/bpf/bpf_extract.py
+++ b/drivers/net/tap/bpf/bpf_extract.py
@@ -65,7 +65,6 @@ def write_header(out, source):
         print(f' * Auto-generated from {source}', file=out)
     print(" * This not the original source file. Do NOT edit it.", file=out)
     print(" */\n", file=out)
-    print("#include <tap_bpf.h>", file=out)
 
 
 def main():
diff --git a/drivers/net/tap/tap_bpf.h b/drivers/net/tap/tap_bpf.h
deleted file mode 100644
index 0d38bc111fe0..000000000000
--- a/drivers/net/tap/tap_bpf.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
- * Copyright 2017 Mellanox Technologies, Ltd
- */
-
-#ifndef __TAP_BPF_H__
-#define __TAP_BPF_H__
-
-#include <tap_autoconf.h>
-
-/* Do not #include <linux/bpf.h> since eBPF must compile on different
- * distros which may include partial definitions for eBPF (while the
- * kernel itself may support eBPF). Instead define here all that is needed
- */
-
-/* BPF_MAP_UPDATE_ELEM command flags */
-#define	BPF_ANY	0 /* create a new element or update an existing */
-
-/* BPF architecture instruction struct */
-struct bpf_insn {
-	__u8	code;
-	__u8	dst_reg:4;
-	__u8	src_reg:4;
-	__s16	off;
-	__s32	imm; /* immediate value */
-};
-
-/* BPF program types */
-enum bpf_prog_type {
-	BPF_PROG_TYPE_UNSPEC,
-	BPF_PROG_TYPE_SOCKET_FILTER,
-	BPF_PROG_TYPE_KPROBE,
-	BPF_PROG_TYPE_SCHED_CLS,
-	BPF_PROG_TYPE_SCHED_ACT,
-};
-
-/* BPF commands types */
-enum bpf_cmd {
-	BPF_MAP_CREATE,
-	BPF_MAP_LOOKUP_ELEM,
-	BPF_MAP_UPDATE_ELEM,
-	BPF_MAP_DELETE_ELEM,
-	BPF_MAP_GET_NEXT_KEY,
-	BPF_PROG_LOAD,
-};
-
-/* BPF maps types */
-enum bpf_map_type {
-	BPF_MAP_TYPE_UNSPEC,
-	BPF_MAP_TYPE_HASH,
-};
-
-/* union of anonymous structs used with TAP BPF commands */
-union bpf_attr {
-	/* BPF_MAP_CREATE command */
-	struct {
-		__u32	map_type;
-		__u32	key_size;
-		__u32	value_size;
-		__u32	max_entries;
-		__u32	map_flags;
-		__u32	inner_map_fd;
-	};
-
-	/* BPF_MAP_UPDATE_ELEM, BPF_MAP_DELETE_ELEM commands */
-	struct {
-		__u32		map_fd;
-		__aligned_u64	key;
-		union {
-			__aligned_u64 value;
-			__aligned_u64 next_key;
-		};
-		__u64		flags;
-	};
-
-	/* BPF_PROG_LOAD command */
-	struct {
-		__u32		prog_type;
-		__u32		insn_cnt;
-		__aligned_u64	insns;
-		__aligned_u64	license;
-		__u32		log_level;
-		__u32		log_size;
-		__aligned_u64	log_buf;
-		__u32		kern_version;
-		__u32		prog_flags;
-	};
-} __rte_aligned(8);
-
-#ifndef __NR_bpf
-# if defined(__i386__)
-#  define __NR_bpf 357
-# elif defined(__x86_64__)
-#  define __NR_bpf 321
-# elif defined(__arm__)
-#  define __NR_bpf 386
-# elif defined(__aarch64__)
-#  define __NR_bpf 280
-# elif defined(__sparc__)
-#  define __NR_bpf 349
-# elif defined(__s390__)
-#  define __NR_bpf 351
-# elif defined(__powerpc__)
-#  define __NR_bpf 361
-# elif defined(__riscv)
-#  define __NR_bpf 280
-# elif defined(__loongarch__)
-#  define __NR_bpf 280
-# else
-#  error __NR_bpf not defined
-# endif
-#endif
-
-enum {
-	BPF_MAP_ID_KEY,
-	BPF_MAP_ID_SIMPLE,
-};
-
-static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns,
-		size_t insns_cnt, const char *license);
-
-#endif /* __TAP_BPF_H__ */
diff --git a/drivers/net/tap/tap_bpf_api.c b/drivers/net/tap/tap_bpf_api.c
index 15283f8917ed..9e05e2ddf19b 100644
--- a/drivers/net/tap/tap_bpf_api.c
+++ b/drivers/net/tap/tap_bpf_api.c
@@ -2,19 +2,19 @@
  * Copyright 2017 Mellanox Technologies, Ltd
  */
 
-#include <errno.h>
-#include <string.h>
 #include <unistd.h>
-#include <sys/queue.h>
+#include <syscall.h>
+#include <linux/bpf.h>
 
-#include <rte_malloc.h>
-#include <rte_eth_tap.h>
 #include <tap_flow.h>
 #include <tap_autoconf.h>
-#include <tap_tcmsgs.h>
-#include <tap_bpf.h>
+
 #include <tap_bpf_insns.h>
 
+
+static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns,
+		size_t insns_cnt, const char *license);
+
 /**
  * Load BPF program (section cls_q) into the kernel and return a bpf fd
  *
@@ -89,7 +89,13 @@ static inline __u64 ptr_to_u64(const void *ptr)
 static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
 			unsigned int size)
 {
+#ifdef __NR_bpf
 	return syscall(__NR_bpf, cmd, attr, size);
+#else
+	TAP_LOG(ERR, "No bpf syscall, kernel headers too old?\n");
+	errno = ENOSYS;
+	return -1;
+#endif
 }
 
 /**
diff --git a/drivers/net/tap/tap_bpf_insns.h b/drivers/net/tap/tap_bpf_insns.h
index 53fa76c4e6b0..88aec6885a06 100644
--- a/drivers/net/tap/tap_bpf_insns.h
+++ b/drivers/net/tap/tap_bpf_insns.h
@@ -3,7 +3,6 @@
  * This not the original source file. Do NOT edit it.
  */
 
-#include <tap_bpf.h>
 
 static struct bpf_insn cls_q_insns[] = {
 	{0x61,    2,    1,       52, 0x00000000},
diff --git a/drivers/net/tap/tap_flow.c b/drivers/net/tap/tap_flow.c
index ed4d42f92f9f..a5d38ee7c46c 100644
--- a/drivers/net/tap/tap_flow.c
+++ b/drivers/net/tap/tap_flow.c
@@ -18,95 +18,6 @@
 #include <tap_tcmsgs.h>
 #include <tap_rss.h>
 
-#ifndef HAVE_TC_FLOWER
-/*
- * For kernels < 4.2, this enum is not defined. Runtime checks will be made to
- * avoid sending TC messages the kernel cannot understand.
- */
-enum {
-	TCA_FLOWER_UNSPEC,
-	TCA_FLOWER_CLASSID,
-	TCA_FLOWER_INDEV,
-	TCA_FLOWER_ACT,
-	TCA_FLOWER_KEY_ETH_DST,         /* ETH_ALEN */
-	TCA_FLOWER_KEY_ETH_DST_MASK,    /* ETH_ALEN */
-	TCA_FLOWER_KEY_ETH_SRC,         /* ETH_ALEN */
-	TCA_FLOWER_KEY_ETH_SRC_MASK,    /* ETH_ALEN */
-	TCA_FLOWER_KEY_ETH_TYPE,        /* be16 */
-	TCA_FLOWER_KEY_IP_PROTO,        /* u8 */
-	TCA_FLOWER_KEY_IPV4_SRC,        /* be32 */
-	TCA_FLOWER_KEY_IPV4_SRC_MASK,   /* be32 */
-	TCA_FLOWER_KEY_IPV4_DST,        /* be32 */
-	TCA_FLOWER_KEY_IPV4_DST_MASK,   /* be32 */
-	TCA_FLOWER_KEY_IPV6_SRC,        /* struct in6_addr */
-	TCA_FLOWER_KEY_IPV6_SRC_MASK,   /* struct in6_addr */
-	TCA_FLOWER_KEY_IPV6_DST,        /* struct in6_addr */
-	TCA_FLOWER_KEY_IPV6_DST_MASK,   /* struct in6_addr */
-	TCA_FLOWER_KEY_TCP_SRC,         /* be16 */
-	TCA_FLOWER_KEY_TCP_DST,         /* be16 */
-	TCA_FLOWER_KEY_UDP_SRC,         /* be16 */
-	TCA_FLOWER_KEY_UDP_DST,         /* be16 */
-};
-#endif
-#ifndef HAVE_TC_VLAN_ID
-enum {
-	/* TCA_FLOWER_FLAGS, */
-	TCA_FLOWER_KEY_VLAN_ID = TCA_FLOWER_KEY_UDP_DST + 2, /* be16 */
-	TCA_FLOWER_KEY_VLAN_PRIO,       /* u8   */
-	TCA_FLOWER_KEY_VLAN_ETH_TYPE,   /* be16 */
-};
-#endif
-/*
- * For kernels < 4.2 BPF related enums may not be defined.
- * Runtime checks will be carried out to gracefully report on TC messages that
- * are rejected by the kernel. Rejection reasons may be due to:
- * 1. enum is not defined
- * 2. enum is defined but kernel is not configured to support BPF system calls,
- *    BPF classifications or BPF actions.
- */
-#ifndef HAVE_TC_BPF
-enum {
-	TCA_BPF_UNSPEC,
-	TCA_BPF_ACT,
-	TCA_BPF_POLICE,
-	TCA_BPF_CLASSID,
-	TCA_BPF_OPS_LEN,
-	TCA_BPF_OPS,
-};
-#endif
-#ifndef HAVE_TC_BPF_FD
-enum {
-	TCA_BPF_FD = TCA_BPF_OPS + 1,
-	TCA_BPF_NAME,
-};
-#endif
-#ifndef HAVE_TC_ACT_BPF
-#define tc_gen \
-	__u32                 index; \
-	__u32                 capab; \
-	int                   action; \
-	int                   refcnt; \
-	int                   bindcnt
-
-struct tc_act_bpf {
-	tc_gen;
-};
-
-enum {
-	TCA_ACT_BPF_UNSPEC,
-	TCA_ACT_BPF_TM,
-	TCA_ACT_BPF_PARMS,
-	TCA_ACT_BPF_OPS_LEN,
-	TCA_ACT_BPF_OPS,
-};
-
-#endif
-#ifndef HAVE_TC_ACT_BPF_FD
-enum {
-	TCA_ACT_BPF_FD = TCA_ACT_BPF_OPS + 1,
-	TCA_ACT_BPF_NAME,
-};
-#endif
 
 /* RSS key management */
 enum bpf_rss_key_e {
-- 
2.43.0


  reply	other threads:[~2024-01-30  3:49 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-30  3:46 [RFC 0/2] net/tap RSS BPF rewrite Stephen Hemminger
2024-01-30  3:46 ` Stephen Hemminger [this message]
2024-01-30  3:46 ` [RFC 2/2] tap: rework BPF handling Stephen Hemminger
2024-02-07 22:11 ` [PATCH v2 0/7] net/tap: RSS using BPF overhaul Stephen Hemminger
2024-02-07 22:11   ` [PATCH v2 1/7] net/tap: remove unused RSS hash types Stephen Hemminger
2024-02-07 22:11   ` [PATCH v2 2/7] net/tap: validate and setup parameters for BPF RSS Stephen Hemminger
2024-02-07 22:11   ` [PATCH v2 3/7] net/tap: stop "vendoring" linux bpf headers Stephen Hemminger
2024-02-07 22:11   ` [PATCH v2 4/7] net/tap: rewrite the RSS BPF program Stephen Hemminger
2024-02-07 22:11   ` [PATCH v2 5/7] net/tap: use libbpf to load new " Stephen Hemminger
2024-02-07 22:11   ` [PATCH v2 6/7] net/tap: remove no longer used files Stephen Hemminger
2024-02-07 22:11   ` [PATCH v2 7/7] MAINTAINERS: add maintainer for TAP device Stephen Hemminger
2024-02-08  7:01     ` Morten Brørup
2024-02-08 17:41 ` [PATCH v3 0/7] net/tap: RSS using BPF overhaul Stephen Hemminger
2024-02-08 17:41   ` [PATCH v3 1/7] net/tap: remove unused RSS hash types Stephen Hemminger
2024-02-08 17:41   ` [PATCH v3 2/7] net/tap: validate and setup parameters for BPF RSS Stephen Hemminger
2024-02-08 17:41   ` [PATCH v3 3/7] tap: stop "vendoring" linux bpf headers Stephen Hemminger
2024-02-08 17:41   ` [PATCH v3 4/7] net/tap: rewrite the RSS BPF program Stephen Hemminger
2024-02-08 17:41   ` [PATCH v3 5/7] net/tap: use libbpf to load new " Stephen Hemminger
2024-02-08 18:02     ` Stephen Hemminger
2024-02-08 17:41   ` [PATCH v3 6/7] net/tap: remove no longer used files Stephen Hemminger
2024-02-08 17:41   ` [PATCH v3 7/7] MAINTAINERS: add maintainer for TAP device Stephen Hemminger
2024-02-08 19:05 ` [PATCH v4 0/7] net/tap: queue flow action RSS using BPF redo Stephen Hemminger
2024-02-08 19:05   ` [PATCH v4 1/7] net/tap: remove unused RSS hash types Stephen Hemminger
2024-02-08 19:05   ` [PATCH v4 2/7] net/tap: validate and setup parameters for BPF RSS Stephen Hemminger
2024-02-08 19:05   ` [PATCH v4 3/7] tap: stop "vendoring" linux bpf headers Stephen Hemminger
2024-02-08 19:05   ` [PATCH v4 4/7] net/tap: rewrite the RSS BPF program Stephen Hemminger
2024-02-10  0:54     ` Ferruh Yigit
2024-02-10  2:09       ` Stephen Hemminger
2024-02-28 17:27         ` Ferruh Yigit
2024-02-29 23:39           ` Stephen Hemminger
2024-02-08 19:05   ` [PATCH v4 5/7] net/tap: use libbpf to load new " Stephen Hemminger
2024-02-08 20:39     ` Stephen Hemminger
2024-02-08 19:05   ` [PATCH v4 6/7] net/tap: remove no longer used files Stephen Hemminger
2024-02-08 19:05   ` [PATCH v4 7/7] MAINTAINERS: add maintainer for TAP device Stephen Hemminger
2024-02-12 16:47   ` [PATCH v4 0/7] net/tap: queue flow action RSS using BPF redo Stephen Hemminger
2024-04-02 17:12 ` [PATCH v5 0/8] net/tap: cleanups and fix BPF flow Stephen Hemminger
2024-04-02 17:12   ` [PATCH v5 1/8] net/tap: do not duplicate fd's Stephen Hemminger
2024-04-02 17:12   ` [PATCH v5 2/8] doc: fix the requirements and building of TAP flow Stephen Hemminger
2024-04-02 17:12   ` [PATCH v5 3/8] net/tap: remove unused RSS hash types Stephen Hemminger
2024-04-02 17:12   ` [PATCH v5 4/8] net/tap: validate and setup parameters for BPF RSS Stephen Hemminger
2024-04-02 17:12   ` [PATCH v5 5/8] net/tap: stop "vendoring" linux bpf headers Stephen Hemminger
2024-04-02 17:12   ` [PATCH v5 6/8] net/tap: rewrite the RSS BPF program Stephen Hemminger
2024-04-02 17:12   ` [PATCH v5 7/8] net/tap: use libbpf to load new " Stephen Hemminger
2024-04-03 11:50     ` Luca Boccassi
2024-04-03 14:53       ` Stephen Hemminger
2024-04-03 15:55       ` Stephen Hemminger
2024-04-03 21:19         ` Luca Boccassi
2024-04-03 23:41           ` Stephen Hemminger
2024-04-04  0:49             ` Luca Boccassi
2024-04-04 15:51               ` Stephen Hemminger
2024-04-04 16:12                 ` Luca Boccassi
2024-04-04 15:30           ` Stephen Hemminger
2024-04-04 16:11             ` Luca Boccassi
2024-04-02 17:12   ` [PATCH v5 8/8] net/tap: remove no longer used files Stephen Hemminger
2024-04-02 20:43     ` Stephen Hemminger
2024-04-05 21:14 ` [PATCH v6 0/8] net/tap: cleanup and fix BPF flow support Stephen Hemminger
2024-04-05 21:14   ` [PATCH v6 1/8] net/tap: do not duplicate fd's Stephen Hemminger
2024-04-05 21:14   ` [PATCH v6 2/8] doc: fix the requirements and building of TAP flow Stephen Hemminger
2024-04-05 21:14   ` [PATCH v6 3/8] net/tap: remove unused fields Stephen Hemminger
2024-04-05 21:14   ` [PATCH v6 4/8] net/tap: validate and setup parameters for BPF RSS Stephen Hemminger
2024-04-05 21:14   ` [PATCH v6 5/8] net/tap: stop "vendoring" linux bpf headers Stephen Hemminger
2024-04-05 21:14   ` [PATCH v6 6/8] net/tap: rewrite the RSS BPF program Stephen Hemminger
2024-04-05 21:14   ` [PATCH v6 7/8] net/tap: use libbpf to load new " Stephen Hemminger
2024-04-05 21:15   ` [PATCH v6 8/8] net/tap: remove no longer used files Stephen Hemminger
2024-04-08 21:18 ` [PATCH v7 0/8] net/tap: cleanups and fix BPF support Stephen Hemminger
2024-04-08 21:18   ` [PATCH v7 1/8] net/tap: do not duplicate fd's Stephen Hemminger
2024-04-08 21:18   ` [PATCH v7 2/8] net/tap: remove unused fields Stephen Hemminger
2024-04-08 21:18   ` [PATCH v7 3/8] net/tap: validate and setup parameters for BPF RSS Stephen Hemminger
2024-04-08 21:18   ` [PATCH v7 4/8] net/tap: do not build flow support if header is out of date Stephen Hemminger
2024-04-08 21:18   ` [PATCH v7 5/8] net/tap: rewrite the RSS BPF program Stephen Hemminger
2024-04-08 21:18   ` [PATCH v7 6/8] net/tap: use libbpf to load new " Stephen Hemminger
2024-04-08 21:18   ` [PATCH v7 7/8] net/tap: remove no longer used files Stephen Hemminger
2024-04-08 21:18   ` [PATCH v7 8/8] doc: update documentation of TAP PMD Stephen Hemminger
2024-04-09  3:40 ` [PATCH v8 0/8] net/tap: cleanups and fix BPF support Stephen Hemminger
2024-04-09  3:40   ` [PATCH v8 1/8] net/tap: do not duplicate fd's Stephen Hemminger
2024-04-09  3:40   ` [PATCH v8 2/8] net/tap: remove unused fields Stephen Hemminger
2024-04-09  3:40   ` [PATCH v8 3/8] net/tap: validate and setup parameters for BPF RSS Stephen Hemminger
2024-04-09  3:40   ` [PATCH v8 4/8] net/tap: do not build flow support if header is out of date Stephen Hemminger
2024-04-09  3:40   ` [PATCH v8 5/8] net/tap: rewrite the RSS BPF program Stephen Hemminger
2024-04-09  3:40   ` [PATCH v8 6/8] net/tap: use libbpf to load new " Stephen Hemminger
2024-04-09  3:40   ` [PATCH v8 7/8] net/tap: remove no longer used files Stephen Hemminger
2024-04-09  3:40   ` [PATCH v8 8/8] doc: update documentation of TAP PMD Stephen Hemminger

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=20240130034925.44869-2-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.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).