From patchwork Fri Jan 5 22:28:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 135770 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1FB21432AF; Fri, 5 Jan 2024 23:29:49 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3BE21406BC; Fri, 5 Jan 2024 23:29:27 +0100 (CET) Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mails.dpdk.org (Postfix) with ESMTP id C959B402DC for ; Fri, 5 Jan 2024 23:29:23 +0100 (CET) Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6d9b050e88cso77935b3a.0 for ; Fri, 05 Jan 2024 14:29:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1704493763; x=1705098563; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iQL4L6ns3Xe6mFFN+tqfCxERNNRh960NjE05P1HTAnc=; b=fmT0Y0YQArCEhcDO/Xs8RYHh4lOlj0Z+oUmW9EKTSt7uGncAAN/GCEVK1tTJkEzBz8 3Te2yk0iFhkHQ+adLa80DmhJrWr1i/PWpByr1HJPl4+OHEMYNfIYuryTj8DxpaCm46mC 8/eTmmVRUBtokMCTZlfv/hcYpjGdALFxHRTB1GHGLNt6Ty7fDJuQFLeNIIXSJEmqHZHl xn8tXBvIb5szFpBBa57+A21tbisjWqTI9GuDS6cXiVReCFcPPJd7jebehkpjc8PY+d9t t+hFttohSEMaMwL1VqVO9nGyOVDkF5DZsuts2EHkb/v6jPFe7u+w1UgAa7HEm8j7mVai hhSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704493763; x=1705098563; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iQL4L6ns3Xe6mFFN+tqfCxERNNRh960NjE05P1HTAnc=; b=epwpDK+Rzmx8jR4YmZVpzl1cWPwbTk3hPKeASqkGxyFl+caeg8OLa0wh5IvhXuYgYU YDSRO8Bj0agjJtU8YvWeRTLOFHKqkLiynG/sR1s/eLPQX4OpYgHssk76VTdQUphQ84bo AI/a3tga+G/1fYf1tSg+1v3OBLuIuQRAQmiuDOREYH6T3zAfOaIJJpcBSgWwNA+L67Q6 HFIw+Kn0B/8RwTwULI+y1TwQuTVQOJDTL4CJ/IdM7cm68iY4yW2qgyXjjRN84fI0X5K9 FmXTos4L4jcpydr/qc067v0afmW9fdNNfQa0WQMmseMBFQPV/rzxQuoyCQ+QpsLnJDk0 y7zg== X-Gm-Message-State: AOJu0YyDEEir6r/vuWj/bXk6dE4YbeJ0/5uozCpFeW2VT4jGDGjLqiht 1AR60prOEGck3Il7Xqo9dA6NFwrvzuxfDAe5nsZsCX6GUdI= X-Google-Smtp-Source: AGHT+IF5DEaHQpJrOsqGWR18pWr+GpXrtvfuhjv4O9EdRkLvNVWbA9HTgb5yJdjLmyzoXlMc8K7wxg== X-Received: by 2002:a05:6a20:1044:b0:195:192c:e5a5 with SMTP id gt4-20020a056a20104400b00195192ce5a5mr38254pzc.56.1704493763040; Fri, 05 Jan 2024 14:29:23 -0800 (PST) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id b11-20020a170902d50b00b001d3e2578e66sm1871132plg.243.2024.01.05.14.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 14:29:22 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [RFC 5/5] tap: stop "vendoring" linux bpf header Date: Fri, 5 Jan 2024 14:28:11 -0800 Message-ID: <20240105222909.139674-6-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240105222909.139674-1-stephen@networkplumber.org> References: <20240105222909.139674-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.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. Signed-off-by: Stephen Hemminger --- drivers/net/tap/bpf/bpf_extract.py | 1 - drivers/net/tap/tap_bpf.h | 118 ----------------------------- drivers/net/tap/tap_bpf_api.c | 16 ++-- drivers/net/tap/tap_bpf_insns.h | 1 - 4 files changed, 9 insertions(+), 127 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 ", 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 aa5a733525e1..000000000000 --- a/drivers/net/tap/tap_bpf.h +++ /dev/null @@ -1,118 +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 - -/* Do not #include 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, -}; - -#endif /* __TAP_BPF_H__ */ diff --git a/drivers/net/tap/tap_bpf_api.c b/drivers/net/tap/tap_bpf_api.c index 29223b7f0ea7..54e469ebf5ff 100644 --- a/drivers/net/tap/tap_bpf_api.c +++ b/drivers/net/tap/tap_bpf_api.c @@ -2,17 +2,13 @@ * Copyright 2017 Mellanox Technologies, Ltd */ -#include -#include #include -#include +#include +#include -#include -#include #include #include -#include -#include + #include static int bpf_load(enum bpf_prog_type type, @@ -106,7 +102,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 + fprintf(stderr, "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 static struct bpf_insn cls_q_insns[] = { {0x61, 2, 1, 52, 0x00000000},