get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/133732/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 133732,
    "url": "http://patchwork.dpdk.org/api/patches/133732/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/20231101180526.214773-2-stephen@networkplumber.org/",
    "project": {
        "id": 1,
        "url": "http://patchwork.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20231101180526.214773-2-stephen@networkplumber.org>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20231101180526.214773-2-stephen@networkplumber.org",
    "date": "2023-11-01T18:02:46",
    "name": "[v6,1/3] net/tap: support infrastructure to build the BPF filter",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "21dd7a9e8cad4709bf120e795ca8776073992b18",
    "submitter": {
        "id": 27,
        "url": "http://patchwork.dpdk.org/api/people/27/?format=api",
        "name": "Stephen Hemminger",
        "email": "stephen@networkplumber.org"
    },
    "delegate": {
        "id": 319,
        "url": "http://patchwork.dpdk.org/api/users/319/?format=api",
        "username": "fyigit",
        "first_name": "Ferruh",
        "last_name": "Yigit",
        "email": "ferruh.yigit@amd.com"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/20231101180526.214773-2-stephen@networkplumber.org/mbox/",
    "series": [
        {
            "id": 30099,
            "url": "http://patchwork.dpdk.org/api/series/30099/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=30099",
            "date": "2023-11-01T18:02:45",
            "name": "net/tap: build and fix for BPF program",
            "version": 6,
            "mbox": "http://patchwork.dpdk.org/series/30099/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/133732/comments/",
    "check": "warning",
    "checks": "http://patchwork.dpdk.org/api/patches/133732/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "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])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 4459C43263;\n\tWed,  1 Nov 2023 19:05:39 +0100 (CET)",
            "from mails.dpdk.org (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 0232D4067B;\n\tWed,  1 Nov 2023 19:05:34 +0100 (CET)",
            "from mail-pg1-f173.google.com (mail-pg1-f173.google.com\n [209.85.215.173])\n by mails.dpdk.org (Postfix) with ESMTP id 53A2E400EF\n for <dev@dpdk.org>; Wed,  1 Nov 2023 19:05:32 +0100 (CET)",
            "by mail-pg1-f173.google.com with SMTP id\n 41be03b00d2f7-565334377d0so26760a12.2\n for <dev@dpdk.org>; Wed, 01 Nov 2023 11:05:32 -0700 (PDT)",
            "from fedora.. ([38.142.2.14]) by smtp.gmail.com with ESMTPSA id\n d9-20020a056a0010c900b006be7d407a11sm1575286pfu.178.2023.11.01.11.05.29\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 01 Nov 2023 11:05:30 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1698861931;\n x=1699466731; darn=dpdk.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=9h+eESJj4gAJpfr4A8YRfsonGeQ4TrwluQZIaPVuo9I=;\n b=e3OHzyBoMAohuneAatBXXTP37FqW/D8lz+Zi6TA6sNB+to83ziMqs9CcAazj8rr70W\n QCxVEXsaCm5BeAW1TUGiXWjl1Sl1PxtjOz+rScilOdvq0DhTxSmNgT3F1PLHXKBbUXsg\n OeTq/ydeegqlKByrCeFXH5g+N/3Ij+NfFftqEQOQ/uwVq9vTok9sSXsll2vwS00oGkjD\n 8pBmH5bmHOhEpzIaU3sVRujUMMtwHPuBMXJSx8q/kRNBsgxQDhZaJD5/UjjL0+Nj/3Yt\n x0FbjPEowv3eWFDHqGXXJqagLuIodAQI+LU18893wksLoaQcyNWtZdcNLteglRkXoUnR\n 96Pw==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1698861931; x=1699466731;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n :subject:date:message-id:reply-to;\n bh=9h+eESJj4gAJpfr4A8YRfsonGeQ4TrwluQZIaPVuo9I=;\n b=sh97O1U/TePeVBVtTQ9Rn9ohjF+NrZD5HHjrMXJBq9dVToyXx9v2xaZhJwW8hmV9Ue\n 3H7gM4OuCreCZODFbuKoBpigTIQ//PXrziHqjwYxu6cESNqMtYCUKbZB+UHg1pqG8ABK\n DCeT9EJKNjCy0YpQD7OQ+BbcLwN0u+W+FtFMIByHwmhA6sviXSS6Vr4ODvOfgfbJIMYz\n JwUgRZgC5fILeEDpErfHZN3oIifMK6XZK5gVooy6db1XbUcaRTA9lsVIRTj34m7eS5nH\n Xg3PlyCuKdOA2A4dCZrQo3ewKTyMBYdevDmmoOIZ5D4UMYL+y4AjOMv+Uben8G5qYrOx\n Zjbg==",
        "X-Gm-Message-State": "AOJu0YwxPOxZSs77lpoxqg7Kwbz/aiaEW1w5qDsVL6nESgMLAJc+yi2/\n jer6MdYbTZ7kVCpNgMHDr8VZtO0XokCtzai34e2T5Hhvb/k=",
        "X-Google-Smtp-Source": "\n AGHT+IEtNKxA3zin+bvRMmF/IXR1mVTzB6mxDVXmpsZTvh6LXzRDZWh7ytnXZu/1VauQjLBj40wXog==",
        "X-Received": "by 2002:a05:6a20:7da5:b0:181:3649:2a31 with SMTP id\n v37-20020a056a207da500b0018136492a31mr3604646pzj.33.1698861930649;\n Wed, 01 Nov 2023 11:05:30 -0700 (PDT)",
        "From": "Stephen Hemminger <stephen@networkplumber.org>",
        "To": "dev@dpdk.org",
        "Cc": "Stephen Hemminger <stephen@networkplumber.org>",
        "Subject": "[PATCH v6 1/3] net/tap: support infrastructure to build the BPF\n filter",
        "Date": "Wed,  1 Nov 2023 11:02:46 -0700",
        "Message-ID": "<20231101180526.214773-2-stephen@networkplumber.org>",
        "X-Mailer": "git-send-email 2.41.0",
        "In-Reply-To": "<20231101180526.214773-1-stephen@networkplumber.org>",
        "References": "<20230716212544.5625-1-stephen@networkplumber.org>\n <20231101180526.214773-1-stephen@networkplumber.org>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org"
    },
    "content": "Move the BPF program related code into a subdirectory.\nAnd add a Makefile for building it.\n\nThe code depends on include files from iproute2.\nBut these are not public headers which iproute2 exports\nas a package API. Therefore make a local copy here.\n\nThe standalone build was also broken because by\ncommit ef5baf3486e0 (\"replace packed attributes\")\nwhich introduced __rte_packed into this code.\n\nAdd a python program to extract the resulting BPF into\na format that can be consumed by the TAP driver.\n\nUpdate the documentation.\n\nSigned-off-by: Stephen Hemminger <stephen@networkplumber.org>\n---\n doc/guides/nics/tap.rst                     |  11 +-\n drivers/net/tap/bpf/.gitignore              |   1 +\n drivers/net/tap/bpf/Makefile                |  18 ++\n drivers/net/tap/bpf/bpf_api.h               | 275 ++++++++++++++++++++\n drivers/net/tap/bpf/bpf_elf.h               |  53 ++++\n drivers/net/tap/bpf/bpf_extract.py          |  86 ++++++\n drivers/net/tap/{ => bpf}/tap_bpf_program.c |  10 +-\n drivers/net/tap/tap_rss.h                   |   2 +-\n 8 files changed, 444 insertions(+), 12 deletions(-)\n create mode 100644 drivers/net/tap/bpf/.gitignore\n create mode 100644 drivers/net/tap/bpf/Makefile\n create mode 100644 drivers/net/tap/bpf/bpf_api.h\n create mode 100644 drivers/net/tap/bpf/bpf_elf.h\n create mode 100644 drivers/net/tap/bpf/bpf_extract.py\n rename drivers/net/tap/{ => bpf}/tap_bpf_program.c (96%)",
    "diff": "diff --git a/doc/guides/nics/tap.rst b/doc/guides/nics/tap.rst\nindex 07df0d35a2..449e747994 100644\n--- a/doc/guides/nics/tap.rst\n+++ b/doc/guides/nics/tap.rst\n@@ -256,15 +256,12 @@ C functions under different ELF sections.\n \n 2. Install ``LLVM`` library and ``clang`` compiler versions 3.7 and above\n \n-3. Compile ``tap_bpf_program.c`` via ``LLVM`` into an object file::\n+3. Use make to compile  `tap_bpf_program.c`` via ``LLVM`` into an object file\n+   and extract the resulting instructions into ``tap_bpf_insn.h``.\n \n-    clang -O2 -emit-llvm -c tap_bpf_program.c -o - | llc -march=bpf \\\n-    -filetype=obj -o <tap_bpf_program.o>\n+    cd bpf; make\n \n-\n-4. Use a tool that receives two parameters: an eBPF object file and a section\n-name, and prints out the section as a C array of eBPF instructions.\n-Embed the C array in your TAP PMD tree.\n+4. Recompile the TAP PMD.\n \n The C arrays are uploaded to the kernel using BPF system calls.\n \ndiff --git a/drivers/net/tap/bpf/.gitignore b/drivers/net/tap/bpf/.gitignore\nnew file mode 100644\nindex 0000000000..30a258f1af\n--- /dev/null\n+++ b/drivers/net/tap/bpf/.gitignore\n@@ -0,0 +1 @@\n+tap_bpf_program.o\ndiff --git a/drivers/net/tap/bpf/Makefile b/drivers/net/tap/bpf/Makefile\nnew file mode 100644\nindex 0000000000..59844c616f\n--- /dev/null\n+++ b/drivers/net/tap/bpf/Makefile\n@@ -0,0 +1,18 @@\n+# SPDX-License-Identifier: BSD-3-Clause\n+# This file is not built as part of normal DPDK build.\n+# It is used to generate the eBPF code for TAP RSS.\n+CLANG=clang\n+CLANG_OPTS=-O2\n+TARGET=../tap_bpf_insns.h\n+\n+all: $(TARGET)\n+\n+clean:\n+\trm tap_bpf_program.o $(TARGET)\n+\n+tap_bpf_program.o: tap_bpf_program.c\n+\t$(CLANG) $(CLANG_OPTS) -emit-llvm -c $< -o - | \\\n+\tllc -march=bpf -filetype=obj -o $@\n+\n+$(TARGET): tap_bpf_program.o\n+\tpython3 bpf_extract.py -stap_bpf_program.c -o $@ $<\ndiff --git a/drivers/net/tap/bpf/bpf_api.h b/drivers/net/tap/bpf/bpf_api.h\nnew file mode 100644\nindex 0000000000..5887d3a851\n--- /dev/null\n+++ b/drivers/net/tap/bpf/bpf_api.h\n@@ -0,0 +1,275 @@\n+/* SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause */\n+#ifndef __BPF_API__\n+#define __BPF_API__\n+\n+/* Note:\n+ *\n+ * This file can be included into eBPF kernel programs. It contains\n+ * a couple of useful helper functions, map/section ABI (bpf_elf.h),\n+ * misc macros and some eBPF specific LLVM built-ins.\n+ */\n+\n+#include <stdint.h>\n+\n+#include <linux/pkt_cls.h>\n+#include <linux/bpf.h>\n+#include <linux/filter.h>\n+\n+#include <asm/byteorder.h>\n+\n+#include \"bpf_elf.h\"\n+\n+/** libbpf pin type. */\n+enum libbpf_pin_type {\n+\tLIBBPF_PIN_NONE,\n+\t/* PIN_BY_NAME: pin maps by name (in /sys/fs/bpf by default) */\n+\tLIBBPF_PIN_BY_NAME,\n+};\n+\n+/** Type helper macros. */\n+\n+#define __uint(name, val) int (*name)[val]\n+#define __type(name, val) typeof(val) *name\n+#define __array(name, val) typeof(val) *name[]\n+\n+/** Misc macros. */\n+\n+#ifndef __stringify\n+# define __stringify(X)\t\t#X\n+#endif\n+\n+#ifndef __maybe_unused\n+# define __maybe_unused\t\t__attribute__((__unused__))\n+#endif\n+\n+#ifndef offsetof\n+# define offsetof(TYPE, MEMBER)\t__builtin_offsetof(TYPE, MEMBER)\n+#endif\n+\n+#ifndef likely\n+# define likely(X)\t\t__builtin_expect(!!(X), 1)\n+#endif\n+\n+#ifndef unlikely\n+# define unlikely(X)\t\t__builtin_expect(!!(X), 0)\n+#endif\n+\n+#ifndef htons\n+# define htons(X)\t\t__constant_htons((X))\n+#endif\n+\n+#ifndef ntohs\n+# define ntohs(X)\t\t__constant_ntohs((X))\n+#endif\n+\n+#ifndef htonl\n+# define htonl(X)\t\t__constant_htonl((X))\n+#endif\n+\n+#ifndef ntohl\n+# define ntohl(X)\t\t__constant_ntohl((X))\n+#endif\n+\n+#ifndef __inline__\n+# define __inline__\t\t__attribute__((always_inline))\n+#endif\n+\n+/** Section helper macros. */\n+\n+#ifndef __section\n+# define __section(NAME)\t\t\t\t\t\t\\\n+\t__attribute__((section(NAME), used))\n+#endif\n+\n+#ifndef __section_tail\n+# define __section_tail(ID, KEY)\t\t\t\t\t\\\n+\t__section(__stringify(ID) \"/\" __stringify(KEY))\n+#endif\n+\n+#ifndef __section_xdp_entry\n+# define __section_xdp_entry\t\t\t\t\t\t\\\n+\t__section(ELF_SECTION_PROG)\n+#endif\n+\n+#ifndef __section_cls_entry\n+# define __section_cls_entry\t\t\t\t\t\t\\\n+\t__section(ELF_SECTION_CLASSIFIER)\n+#endif\n+\n+#ifndef __section_act_entry\n+# define __section_act_entry\t\t\t\t\t\t\\\n+\t__section(ELF_SECTION_ACTION)\n+#endif\n+\n+#ifndef __section_lwt_entry\n+# define __section_lwt_entry\t\t\t\t\t\t\\\n+\t__section(ELF_SECTION_PROG)\n+#endif\n+\n+#ifndef __section_license\n+# define __section_license\t\t\t\t\t\t\\\n+\t__section(ELF_SECTION_LICENSE)\n+#endif\n+\n+#ifndef __section_maps\n+# define __section_maps\t\t\t\t\t\t\t\\\n+\t__section(ELF_SECTION_MAPS)\n+#endif\n+\n+/** Declaration helper macros. */\n+\n+#ifndef BPF_LICENSE\n+# define BPF_LICENSE(NAME)\t\t\t\t\t\t\\\n+\tchar ____license[] __section_license = NAME\n+#endif\n+\n+/** Classifier helper */\n+\n+#ifndef BPF_H_DEFAULT\n+# define BPF_H_DEFAULT\t-1\n+#endif\n+\n+/** BPF helper functions for tc. Individual flags are in linux/bpf.h */\n+\n+#ifndef __BPF_FUNC\n+# define __BPF_FUNC(NAME, ...)\t\t\t\t\t\t\\\n+\t(* NAME)(__VA_ARGS__) __maybe_unused\n+#endif\n+\n+#ifndef BPF_FUNC\n+# define BPF_FUNC(NAME, ...)\t\t\t\t\t\t\\\n+\t__BPF_FUNC(NAME, __VA_ARGS__) = (void *) BPF_FUNC_##NAME\n+#endif\n+\n+/* Map access/manipulation */\n+static void *BPF_FUNC(map_lookup_elem, void *map, const void *key);\n+static int BPF_FUNC(map_update_elem, void *map, const void *key,\n+\t\t    const void *value, uint32_t flags);\n+static int BPF_FUNC(map_delete_elem, void *map, const void *key);\n+\n+/* Time access */\n+static uint64_t BPF_FUNC(ktime_get_ns);\n+\n+/* Debugging */\n+\n+/* FIXME: __attribute__ ((format(printf, 1, 3))) not possible unless\n+ * llvm bug https://llvm.org/bugs/show_bug.cgi?id=26243 gets resolved.\n+ * It would require ____fmt to be made const, which generates a reloc\n+ * entry (non-map).\n+ */\n+static void BPF_FUNC(trace_printk, const char *fmt, int fmt_size, ...);\n+\n+#ifndef printt\n+# define printt(fmt, ...)\t\t\t\t\t\t\\\n+\t({\t\t\t\t\t\t\t\t\\\n+\t\tchar ____fmt[] = fmt;\t\t\t\t\t\\\n+\t\ttrace_printk(____fmt, sizeof(____fmt), ##__VA_ARGS__);\t\\\n+\t})\n+#endif\n+\n+/* Random numbers */\n+static uint32_t BPF_FUNC(get_prandom_u32);\n+\n+/* Tail calls */\n+static void BPF_FUNC(tail_call, struct __sk_buff *skb, void *map,\n+\t\t     uint32_t index);\n+\n+/* System helpers */\n+static uint32_t BPF_FUNC(get_smp_processor_id);\n+static uint32_t BPF_FUNC(get_numa_node_id);\n+\n+/* Packet misc meta data */\n+static uint32_t BPF_FUNC(get_cgroup_classid, struct __sk_buff *skb);\n+static int BPF_FUNC(skb_under_cgroup, void *map, uint32_t index);\n+\n+static uint32_t BPF_FUNC(get_route_realm, struct __sk_buff *skb);\n+static uint32_t BPF_FUNC(get_hash_recalc, struct __sk_buff *skb);\n+static uint32_t BPF_FUNC(set_hash_invalid, struct __sk_buff *skb);\n+\n+/* Packet redirection */\n+static int BPF_FUNC(redirect, int ifindex, uint32_t flags);\n+static int BPF_FUNC(clone_redirect, struct __sk_buff *skb, int ifindex,\n+\t\t    uint32_t flags);\n+\n+/* Packet manipulation */\n+static int BPF_FUNC(skb_load_bytes, struct __sk_buff *skb, uint32_t off,\n+\t\t    void *to, uint32_t len);\n+static int BPF_FUNC(skb_store_bytes, struct __sk_buff *skb, uint32_t off,\n+\t\t    const void *from, uint32_t len, uint32_t flags);\n+\n+static int BPF_FUNC(l3_csum_replace, struct __sk_buff *skb, uint32_t off,\n+\t\t    uint32_t from, uint32_t to, uint32_t flags);\n+static int BPF_FUNC(l4_csum_replace, struct __sk_buff *skb, uint32_t off,\n+\t\t    uint32_t from, uint32_t to, uint32_t flags);\n+static int BPF_FUNC(csum_diff, const void *from, uint32_t from_size,\n+\t\t    const void *to, uint32_t to_size, uint32_t seed);\n+static int BPF_FUNC(csum_update, struct __sk_buff *skb, uint32_t wsum);\n+\n+static int BPF_FUNC(skb_change_type, struct __sk_buff *skb, uint32_t type);\n+static int BPF_FUNC(skb_change_proto, struct __sk_buff *skb, uint32_t proto,\n+\t\t    uint32_t flags);\n+static int BPF_FUNC(skb_change_tail, struct __sk_buff *skb, uint32_t nlen,\n+\t\t    uint32_t flags);\n+\n+static int BPF_FUNC(skb_pull_data, struct __sk_buff *skb, uint32_t len);\n+\n+/* Event notification */\n+static int __BPF_FUNC(skb_event_output, struct __sk_buff *skb, void *map,\n+\t\t      uint64_t index, const void *data, uint32_t size) =\n+\t\t      (void *) BPF_FUNC_perf_event_output;\n+\n+/* Packet vlan encap/decap */\n+static int BPF_FUNC(skb_vlan_push, struct __sk_buff *skb, uint16_t proto,\n+\t\t    uint16_t vlan_tci);\n+static int BPF_FUNC(skb_vlan_pop, struct __sk_buff *skb);\n+\n+/* Packet tunnel encap/decap */\n+static int BPF_FUNC(skb_get_tunnel_key, struct __sk_buff *skb,\n+\t\t    struct bpf_tunnel_key *to, uint32_t size, uint32_t flags);\n+static int BPF_FUNC(skb_set_tunnel_key, struct __sk_buff *skb,\n+\t\t    const struct bpf_tunnel_key *from, uint32_t size,\n+\t\t    uint32_t flags);\n+\n+static int BPF_FUNC(skb_get_tunnel_opt, struct __sk_buff *skb,\n+\t\t    void *to, uint32_t size);\n+static int BPF_FUNC(skb_set_tunnel_opt, struct __sk_buff *skb,\n+\t\t    const void *from, uint32_t size);\n+\n+/** LLVM built-ins, mem*() routines work for constant size */\n+\n+#ifndef lock_xadd\n+# define lock_xadd(ptr, val)\t((void) __sync_fetch_and_add(ptr, val))\n+#endif\n+\n+#ifndef memset\n+# define memset(s, c, n)\t__builtin_memset((s), (c), (n))\n+#endif\n+\n+#ifndef memcpy\n+# define memcpy(d, s, n)\t__builtin_memcpy((d), (s), (n))\n+#endif\n+\n+#ifndef memmove\n+# define memmove(d, s, n)\t__builtin_memmove((d), (s), (n))\n+#endif\n+\n+/* FIXME: __builtin_memcmp() is not yet fully useable unless llvm bug\n+ * https://llvm.org/bugs/show_bug.cgi?id=26218 gets resolved. Also\n+ * this one would generate a reloc entry (non-map), otherwise.\n+ */\n+#if 0\n+#ifndef memcmp\n+# define memcmp(a, b, n)\t__builtin_memcmp((a), (b), (n))\n+#endif\n+#endif\n+\n+unsigned long long load_byte(void *skb, unsigned long long off)\n+\tasm (\"llvm.bpf.load.byte\");\n+\n+unsigned long long load_half(void *skb, unsigned long long off)\n+\tasm (\"llvm.bpf.load.half\");\n+\n+unsigned long long load_word(void *skb, unsigned long long off)\n+\tasm (\"llvm.bpf.load.word\");\n+\n+#endif /* __BPF_API__ */\ndiff --git a/drivers/net/tap/bpf/bpf_elf.h b/drivers/net/tap/bpf/bpf_elf.h\nnew file mode 100644\nindex 0000000000..ea8a11c95c\n--- /dev/null\n+++ b/drivers/net/tap/bpf/bpf_elf.h\n@@ -0,0 +1,53 @@\n+/* SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause */\n+#ifndef __BPF_ELF__\n+#define __BPF_ELF__\n+\n+#include <asm/types.h>\n+\n+/* Note:\n+ *\n+ * Below ELF section names and bpf_elf_map structure definition\n+ * are not (!) kernel ABI. It's rather a \"contract\" between the\n+ * application and the BPF loader in tc. For compatibility, the\n+ * section names should stay as-is. Introduction of aliases, if\n+ * needed, are a possibility, though.\n+ */\n+\n+/* ELF section names, etc */\n+#define ELF_SECTION_LICENSE\t\"license\"\n+#define ELF_SECTION_MAPS\t\"maps\"\n+#define ELF_SECTION_PROG\t\"prog\"\n+#define ELF_SECTION_CLASSIFIER\t\"classifier\"\n+#define ELF_SECTION_ACTION\t\"action\"\n+\n+#define ELF_MAX_MAPS\t\t64\n+#define ELF_MAX_LICENSE_LEN\t128\n+\n+/* Object pinning settings */\n+#define PIN_NONE\t\t0\n+#define PIN_OBJECT_NS\t\t1\n+#define PIN_GLOBAL_NS\t\t2\n+\n+/* ELF map definition */\n+struct bpf_elf_map {\n+\t__u32 type;\n+\t__u32 size_key;\n+\t__u32 size_value;\n+\t__u32 max_elem;\n+\t__u32 flags;\n+\t__u32 id;\n+\t__u32 pinning;\n+\t__u32 inner_id;\n+\t__u32 inner_idx;\n+};\n+\n+#define BPF_ANNOTATE_KV_PAIR(name, type_key, type_val)\t\t\\\n+\tstruct ____btf_map_##name {\t\t\t\t\\\n+\t\ttype_key key;\t\t\t\t\t\\\n+\t\ttype_val value;\t\t\t\t\t\\\n+\t};\t\t\t\t\t\t\t\\\n+\tstruct ____btf_map_##name\t\t\t\t\\\n+\t    __attribute__ ((section(\".maps.\" #name), used))\t\\\n+\t    ____btf_map_##name = { }\n+\n+#endif /* __BPF_ELF__ */\ndiff --git a/drivers/net/tap/bpf/bpf_extract.py b/drivers/net/tap/bpf/bpf_extract.py\nnew file mode 100644\nindex 0000000000..b630c42b80\n--- /dev/null\n+++ b/drivers/net/tap/bpf/bpf_extract.py\n@@ -0,0 +1,86 @@\n+#!/usr/bin/env python3\n+# SPDX-License-Identifier: BSD-3-Clause\n+# Copyright (c) 2023 Stephen Hemminger <stephen@networkplumber.org>\n+\n+import argparse\n+import sys\n+import struct\n+from tempfile import TemporaryFile\n+from elftools.elf.elffile import ELFFile\n+\n+\n+def load_sections(elffile):\n+    \"\"\"Get sections of interest from ELF\"\"\"\n+    result = []\n+    parts = [(\"cls_q\", \"cls_q_insns\"), (\"l3_l4\", \"l3_l4_hash_insns\")]\n+    for name, tag in parts:\n+        section = elffile.get_section_by_name(name)\n+        if section:\n+            insns = struct.iter_unpack('<BBhL', section.data())\n+            result.append([tag, insns])\n+    return result\n+\n+\n+def dump_section(name, insns, out):\n+    \"\"\"Dump the array of BPF instructions\"\"\"\n+    print(f'\\nstatic struct bpf_insn {name}[] = {{', file=out)\n+    for bpf in insns:\n+        code = bpf[0]\n+        src = bpf[1] >> 4\n+        dst = bpf[1] & 0xf\n+        off = bpf[2]\n+        imm = bpf[3]\n+        print(f'\\t{{{code:#04x}, {dst:4d}, {src:4d}, {off:8d}, {imm:#010x}}},',\n+              file=out)\n+    print('};', file=out)\n+\n+\n+def parse_args():\n+    \"\"\"Parse command line arguments\"\"\"\n+    parser = argparse.ArgumentParser()\n+    parser.add_argument('-s',\n+                        '--source',\n+                        type=str,\n+                        help=\"original source file\")\n+    parser.add_argument('-o', '--out', type=str, help=\"output C file path\")\n+    parser.add_argument(\"file\",\n+                        nargs='+',\n+                        help=\"object file path or '-' for stdin\")\n+    return parser.parse_args()\n+\n+\n+def open_input(path):\n+    \"\"\"Open the file or stdin\"\"\"\n+    if path == \"-\":\n+        temp = TemporaryFile()\n+        temp.write(sys.stdin.buffer.read())\n+        return temp\n+    return open(path, 'rb')\n+\n+\n+def write_header(out, source):\n+    \"\"\"Write file intro header\"\"\"\n+    print(\"/* SPDX-License-Identifier: BSD-3-Clause\", file=out)\n+    if source:\n+        print(f' * Auto-generated from {source}', file=out)\n+    print(\" * This not the original source file. Do NOT edit it.\", file=out)\n+    print(\" */\\n\", file=out)\n+    print(\"#include <tap_bpf.h>\", file=out)\n+\n+\n+def main():\n+    '''program main function'''\n+    args = parse_args()\n+\n+    with open(args.out, 'w',\n+              encoding=\"utf-8\") if args.out else sys.stdout as out:\n+        write_header(out, args.source)\n+        for path in args.file:\n+            elffile = ELFFile(open_input(path))\n+            sections = load_sections(elffile)\n+            for name, insns in sections:\n+                dump_section(name, insns, out)\n+\n+\n+if __name__ == \"__main__\":\n+    main()\ndiff --git a/drivers/net/tap/tap_bpf_program.c b/drivers/net/tap/bpf/tap_bpf_program.c\nsimilarity index 96%\nrename from drivers/net/tap/tap_bpf_program.c\nrename to drivers/net/tap/bpf/tap_bpf_program.c\nindex 20c310e5e7..d65021d8a1 100644\n--- a/drivers/net/tap/tap_bpf_program.c\n+++ b/drivers/net/tap/bpf/tap_bpf_program.c\n@@ -14,9 +14,10 @@\n #include <linux/ipv6.h>\n #include <linux/if_tunnel.h>\n #include <linux/filter.h>\n-#include <linux/bpf.h>\n \n-#include \"tap_rss.h\"\n+#include \"bpf_api.h\"\n+#include \"bpf_elf.h\"\n+#include \"../tap_rss.h\"\n \n /** Create IPv4 address */\n #define IPv4(a, b, c, d) ((__u32)(((a) & 0xff) << 24) | \\\n@@ -56,6 +57,7 @@ __section(\"cls_q\") int\n match_q(struct __sk_buff *skb)\n {\n \t__u32 queue = skb->cb[1];\n+\t/* queue is set by tap_flow_bpf_cls_q() before load */\n \tvolatile __u32 q = 0xdeadbeef;\n \t__u32 match_queue = QUEUE_OFFSET + q;\n \n@@ -75,14 +77,14 @@ struct ipv4_l3_l4_tuple {\n \t__u32    dst_addr;\n \t__u16    dport;\n \t__u16    sport;\n-} __rte_packed;\n+} __attribute__((packed));\n \n struct ipv6_l3_l4_tuple {\n \t__u8        src_addr[16];\n \t__u8        dst_addr[16];\n \t__u16       dport;\n \t__u16       sport;\n-} __rte_packed;\n+} __attribute__((packed));\n \n static const __u8 def_rss_key[TAP_RSS_HASH_KEY_SIZE] = {\n \t0xd1, 0x81, 0xc6, 0x2c,\ndiff --git a/drivers/net/tap/tap_rss.h b/drivers/net/tap/tap_rss.h\nindex 48c151cf6b..dff46a012f 100644\n--- a/drivers/net/tap/tap_rss.h\n+++ b/drivers/net/tap/tap_rss.h\n@@ -35,6 +35,6 @@ struct rss_key {\n \t__u32 key_size;\n \t__u32 queues[TAP_MAX_QUEUES];\n \t__u32 nb_queues;\n-} __rte_packed;\n+} __attribute__((packed));\n \n #endif /* _TAP_RSS_H_ */\n",
    "prefixes": [
        "v6",
        "1/3"
    ]
}