Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/98966/?format=api
https://patches.dpdk.org/api/patches/98966/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/patch/20210916001416.39998-6-stephen@networkplumber.org/", "project": { "id": 1, "url": "https://patches.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": "<20210916001416.39998-6-stephen@networkplumber.org>", "list_archive_url": "https://inbox.dpdk.org/dev/20210916001416.39998-6-stephen@networkplumber.org", "date": "2021-09-16T00:14:09", "name": "[v9,05/12] bpf: add function to dump eBPF instructions", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "130d20766642901fd5ae07eca3dd5f75f09ebe35", "submitter": { "id": 27, "url": "https://patches.dpdk.org/api/people/27/?format=api", "name": "Stephen Hemminger", "email": "stephen@networkplumber.org" }, "delegate": { "id": 1, "url": "https://patches.dpdk.org/api/users/1/?format=api", "username": "tmonjalo", "first_name": "Thomas", "last_name": "Monjalon", "email": "thomas@monjalon.net" }, "mbox": "https://patches.dpdk.org/project/dpdk/patch/20210916001416.39998-6-stephen@networkplumber.org/mbox/", "series": [ { "id": 18954, "url": "https://patches.dpdk.org/api/series/18954/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=18954", "date": "2021-09-16T00:14:04", "name": "Packet capture framework enhancements", "version": 9, "mbox": "https://patches.dpdk.org/series/18954/mbox/" } ], "comments": "https://patches.dpdk.org/api/patches/98966/comments/", "check": "success", "checks": "https://patches.dpdk.org/api/patches/98966/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 1A4A6A0C41;\n\tThu, 16 Sep 2021 02:14:52 +0200 (CEST)", "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 4BB3840E25;\n\tThu, 16 Sep 2021 02:14:34 +0200 (CEST)", "from mail-pg1-f182.google.com (mail-pg1-f182.google.com\n [209.85.215.182])\n by mails.dpdk.org (Postfix) with ESMTP id 06213410EB\n for <dev@dpdk.org>; Thu, 16 Sep 2021 02:14:26 +0200 (CEST)", "by mail-pg1-f182.google.com with SMTP id f129so4472683pgc.1\n for <dev@dpdk.org>; Wed, 15 Sep 2021 17:14:25 -0700 (PDT)", "from hermes.local (204-195-33-123.wavecable.com. [204.195.33.123])\n by smtp.gmail.com with ESMTPSA id 26sm1082252pgx.72.2021.09.15.17.14.23\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 15 Sep 2021 17:14:23 -0700 (PDT)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=networkplumber-org.20150623.gappssmtp.com; s=20150623;\n h=from:to:cc:subject:date:message-id:in-reply-to:references\n :mime-version:content-transfer-encoding;\n bh=RiI2oQa8rTaqCkNdQlcn5v7FnNEBKwaRSlYvsVzUur4=;\n b=ixit7oU3xaA6GZbpgv0nAYQNVXTD7gn5s58ORpDflEViZKDrHqnNjVxim6r9Q7j3hW\n YyGR/HQObZYcsI5gXwr2XyxjP2c3aKzMGJh16ExDq8DFXfbBkc3YoujOP81U7QUSZTNh\n TGcFm5PAHRxqo0c46xtvq8x+QbTnRzcPdCMpjhY9tqwrGch5YG5A1DxEybEoiqEQQ0Ro\n qhsz6HYDmv7tHVe8Gu76Uqyx4JLN6VX4XhEyh33WY9F28uayJuz2GDvS/8O5wNdCq7ht\n S9tpv8G/JVDxWWyeYRWrUGgkgkleeZ7LJ+9N6ArcQc+/JtliRBLhGd6wCYu25esz4LoK\n gGtA==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20210112;\n h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n :references:mime-version:content-transfer-encoding;\n bh=RiI2oQa8rTaqCkNdQlcn5v7FnNEBKwaRSlYvsVzUur4=;\n b=MWjF1s1IEA29jk5svNf7NzqXcBEGs+S/YDtWUHTNixHx30K5SpIvLSaDYBdxNoRwRG\n q0o59tekzMQRUfzG3gnrd59tkqPt5LrVmUa6WqxTU1EIGx33Jccvx9J9U37kIzldv217\n ivBmENJ/cIf66/bLul+SZq103Dll7azSxVaflCGpD0q9RyK7WTt7FYfAYfTdCYIy+KlO\n GZGHzYgdJ1FR4Y0jo7pT+aU1QPoR274w/gjlfa+49ZRWjAGlOQ4DqUzaALKMLT2cYIwc\n kqdN2UGbkkx6nuUjTLbkqjuXB2xt99RgLR9pmLjWD6q2A8j48vRDfnan5lne+lgeV/Rq\n MwZg==", "X-Gm-Message-State": "AOAM531yuP3nNDDBxZOok4FT5AjMTU5pB2DCv9p1SMRFuXs9TObuhC0H\n df63IjYqK7n9rDcF6HssKuVnVgeAkJPK0A==", "X-Google-Smtp-Source": "\n ABdhPJxru0zBM8ruxcWHZvpOKnAIMRUw9erp8Al3yZLx+6o9a5jZcS65A7Kf1jaYqsP09lEw+hjzsA==", "X-Received": "by 2002:a63:63c7:: with SMTP id x190mr2344996pgb.70.1631751264778;\n Wed, 15 Sep 2021 17:14:24 -0700 (PDT)", "From": "Stephen Hemminger <stephen@networkplumber.org>", "To": "dev@dpdk.org", "Cc": "Stephen Hemminger <stephen@networkplumber.org>,\n Konstantin Ananyev <konstantin.ananyev@intel.com>", "Date": "Wed, 15 Sep 2021 17:14:09 -0700", "Message-Id": "<20210916001416.39998-6-stephen@networkplumber.org>", "X-Mailer": "git-send-email 2.30.2", "In-Reply-To": "<20210916001416.39998-1-stephen@networkplumber.org>", "References": "<20210903004732.109023-1-stephen@networkplumber.org>\n <20210916001416.39998-1-stephen@networkplumber.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[dpdk-dev] [PATCH v9 05/12] bpf: add function to dump eBPF\n instructions", "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", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "When debugging converted (and other) programs it is useful\nto see disassembled eBPF output.\n\nSigned-off-by: Stephen Hemminger <stephen@networkplumber.org>\nAcked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>\n---\n lib/bpf/bpf_dump.c | 118 ++++++++++++++++++++++++++++++++++++++++++++\n lib/bpf/meson.build | 1 +\n lib/bpf/rte_bpf.h | 14 ++++++\n lib/bpf/version.map | 1 +\n 4 files changed, 134 insertions(+)\n create mode 100644 lib/bpf/bpf_dump.c", "diff": "diff --git a/lib/bpf/bpf_dump.c b/lib/bpf/bpf_dump.c\nnew file mode 100644\nindex 000000000000..a6a431e64903\n--- /dev/null\n+++ b/lib/bpf/bpf_dump.c\n@@ -0,0 +1,118 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright (c) 2021 Stephen Hemminger\n+ * Based on filter2xdp\n+ * Copyright (C) 2017 Tobias Klauser\n+ */\n+\n+#include <stdio.h>\n+#include <stdint.h>\n+\n+#include \"rte_bpf.h\"\n+\n+#define BPF_OP_INDEX(x) (BPF_OP(x) >> 4)\n+#define BPF_SIZE_INDEX(x) (BPF_SIZE(x) >> 3)\n+\n+static const char *const class_tbl[] = {\n+\t[BPF_LD] = \"ld\", [BPF_LDX] = \"ldx\",\t [BPF_ST] = \"st\",\n+\t[BPF_STX] = \"stx\", [BPF_ALU] = \"alu\",\t [BPF_JMP] = \"jmp\",\n+\t[BPF_RET] = \"ret\", [BPF_MISC] = \"alu64\",\n+};\n+\n+static const char *const alu_op_tbl[16] = {\n+\t[BPF_ADD >> 4] = \"add\",\t [BPF_SUB >> 4] = \"sub\",\n+\t[BPF_MUL >> 4] = \"mul\",\t [BPF_DIV >> 4] = \"div\",\n+\t[BPF_OR >> 4] = \"or\",\t [BPF_AND >> 4] = \"and\",\n+\t[BPF_LSH >> 4] = \"lsh\",\t [BPF_RSH >> 4] = \"rsh\",\n+\t[BPF_NEG >> 4] = \"neg\",\t [BPF_MOD >> 4] = \"mod\",\n+\t[BPF_XOR >> 4] = \"xor\",\t [EBPF_MOV >> 4] = \"mov\",\n+\t[EBPF_ARSH >> 4] = \"arsh\", [EBPF_END >> 4] = \"endian\",\n+};\n+\n+static const char *const size_tbl[] = {\n+\t[BPF_W >> 3] = \"w\",\n+\t[BPF_H >> 3] = \"h\",\n+\t[BPF_B >> 3] = \"b\",\n+\t[EBPF_DW >> 3] = \"dw\",\n+};\n+\n+static const char *const jump_tbl[16] = {\n+\t[BPF_JA >> 4] = \"ja\",\t [BPF_JEQ >> 4] = \"jeq\",\n+\t[BPF_JGT >> 4] = \"jgt\",\t [BPF_JGE >> 4] = \"jge\",\n+\t[BPF_JSET >> 4] = \"jset\", [EBPF_JNE >> 4] = \"jne\",\n+\t[EBPF_JSGT >> 4] = \"jsgt\", [EBPF_JSGE >> 4] = \"jsge\",\n+\t[EBPF_CALL >> 4] = \"call\", [EBPF_EXIT >> 4] = \"exit\",\n+};\n+\n+static void ebpf_dump(FILE *f, const struct ebpf_insn insn, size_t n)\n+{\n+\tconst char *op, *postfix = \"\";\n+\tuint8_t cls = BPF_CLASS(insn.code);\n+\n+\tfprintf(f, \" L%zu:\\t\", n);\n+\n+\tswitch (cls) {\n+\tdefault:\n+\t\tfprintf(f, \"unimp 0x%x // class: %s\\n\", insn.code,\n+\t\t\tclass_tbl[cls]);\n+\t\tbreak;\n+\tcase BPF_ALU:\n+\t\tpostfix = \"32\";\n+\t\t/* fall through */\n+\tcase EBPF_ALU64:\n+\t\top = alu_op_tbl[BPF_OP_INDEX(insn.code)];\n+\t\tif (BPF_SRC(insn.code) == BPF_X)\n+\t\t\tfprintf(f, \"%s%s r%u, r%u\\n\", op, postfix, insn.dst_reg,\n+\t\t\t\tinsn.src_reg);\n+\t\telse\n+\t\t\tfprintf(f, \"%s%s r%u, #0x%x\\n\", op, postfix,\n+\t\t\t\tinsn.dst_reg, insn.imm);\n+\t\tbreak;\n+\tcase BPF_LD:\n+\t\top = \"ld\";\n+\t\tpostfix = size_tbl[BPF_SIZE_INDEX(insn.code)];\n+\t\tif (BPF_MODE(insn.code) == BPF_IMM)\n+\t\t\tfprintf(f, \"%s%s r%d, #0x%x\\n\", op, postfix,\n+\t\t\t\tinsn.dst_reg, insn.imm);\n+\t\telse if (BPF_MODE(insn.code) == BPF_ABS)\n+\t\t\tfprintf(f, \"%s%s r%d, [%d]\\n\", op, postfix,\n+\t\t\t\tinsn.dst_reg, insn.imm);\n+\t\telse if (BPF_MODE(insn.code) == BPF_IND)\n+\t\t\tfprintf(f, \"%s%s r%d, [r%u + %d]\\n\", op, postfix,\n+\t\t\t\tinsn.dst_reg, insn.src_reg, insn.imm);\n+\t\telse\n+\t\t\tfprintf(f, \"// BUG: LD opcode 0x%02x in eBPF insns\\n\",\n+\t\t\t\tinsn.code);\n+\t\tbreak;\n+\tcase BPF_LDX:\n+\t\top = \"ldx\";\n+\t\tpostfix = size_tbl[BPF_SIZE_INDEX(insn.code)];\n+\t\tfprintf(f, \"%s%s r%d, [r%u + %d]\\n\", op, postfix, insn.dst_reg,\n+\t\t\tinsn.src_reg, insn.off);\n+\t\tbreak;\n+#define L(pc, off) ((int)(pc) + 1 + (off))\n+\tcase BPF_JMP:\n+\t\top = jump_tbl[BPF_OP_INDEX(insn.code)];\n+\t\tif (op == NULL)\n+\t\t\tfprintf(f, \"invalid jump opcode: %#x\\n\", insn.code);\n+\t\telse if (BPF_OP(insn.code) == BPF_JA)\n+\t\t\tfprintf(f, \"%s L%d\\n\", op, L(n, insn.off));\n+\t\telse if (BPF_OP(insn.code) == EBPF_EXIT)\n+\t\t\tfprintf(f, \"%s\\n\", op);\n+\t\telse\n+\t\t\tfprintf(f, \"%s r%u, #0x%x, L%d\\n\", op, insn.dst_reg,\n+\t\t\t\tinsn.imm, L(n, insn.off));\n+\t\tbreak;\n+\tcase BPF_RET:\n+\t\tfprintf(f, \"// BUG: RET opcode 0x%02x in eBPF insns\\n\",\n+\t\t\tinsn.code);\n+\t\tbreak;\n+\t}\n+}\n+\n+void rte_bpf_dump(FILE *f, const struct ebpf_insn *buf, uint32_t len)\n+{\n+\tuint32_t i;\n+\n+\tfor (i = 0; i < len; ++i)\n+\t\tebpf_dump(f, buf[i], i);\n+}\ndiff --git a/lib/bpf/meson.build b/lib/bpf/meson.build\nindex 54f7610ae990..5b5585173aeb 100644\n--- a/lib/bpf/meson.build\n+++ b/lib/bpf/meson.build\n@@ -2,6 +2,7 @@\n # Copyright(c) 2018 Intel Corporation\n \n sources = files('bpf.c',\n+\t'bpf_dump.c',\n 'bpf_exec.c',\n 'bpf_load.c',\n 'bpf_pkt.c',\ndiff --git a/lib/bpf/rte_bpf.h b/lib/bpf/rte_bpf.h\nindex 2f23e272a376..0d0a84b130a0 100644\n--- a/lib/bpf/rte_bpf.h\n+++ b/lib/bpf/rte_bpf.h\n@@ -198,6 +198,20 @@ rte_bpf_exec_burst(const struct rte_bpf *bpf, void *ctx[], uint64_t rc[],\n int\n rte_bpf_get_jit(const struct rte_bpf *bpf, struct rte_bpf_jit *jit);\n \n+/**\n+ * Dump epf instructions to a file.\n+ *\n+ * @param f\n+ * A pointer to a file for output\n+ * @param buf\n+ * A pointer to BPF instructions\n+ * @param len\n+ * Number of BPF instructions to dump.\n+ */\n+__rte_experimental\n+void\n+rte_bpf_dump(FILE *f, const struct ebpf_insn *buf, uint32_t len);\n+\n #ifdef RTE_PORT_PCAP\n \n struct bpf_program;\ndiff --git a/lib/bpf/version.map b/lib/bpf/version.map\nindex 47082d5003ef..3b953f2f4592 100644\n--- a/lib/bpf/version.map\n+++ b/lib/bpf/version.map\n@@ -19,4 +19,5 @@ EXPERIMENTAL {\n \tglobal:\n \n \trte_bpf_convert;\n+\trte_bpf_dump;\n };\n", "prefixes": [ "v9", "05/12" ] }{ "id": 98966, "url": "