get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 40807,
    "url": "http://patches.dpdk.org/api/patches/40807/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1528447355-29411-2-git-send-email-konstantin.ananyev@intel.com/",
    "project": {
        "id": 1,
        "url": "http://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": "<1528447355-29411-2-git-send-email-konstantin.ananyev@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1528447355-29411-2-git-send-email-konstantin.ananyev@intel.com",
    "date": "2018-06-08T08:42:33",
    "name": "[dpdk-dev,1/3] bpf: add extra information for external symbol definitions",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "a62341fe7adce382f4bf1d9fd76bdf5be2a56656",
    "submitter": {
        "id": 33,
        "url": "http://patches.dpdk.org/api/people/33/?format=api",
        "name": "Ananyev, Konstantin",
        "email": "konstantin.ananyev@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/1528447355-29411-2-git-send-email-konstantin.ananyev@intel.com/mbox/",
    "series": [
        {
            "id": 43,
            "url": "http://patches.dpdk.org/api/series/43/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=43",
            "date": "2018-06-08T08:42:32",
            "name": "bpf: extend validation of input BPF programs",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/43/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/40807/comments/",
    "check": "warning",
    "checks": "http://patches.dpdk.org/api/patches/40807/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 904251B1A2;\n\tFri,  8 Jun 2018 10:42:53 +0200 (CEST)",
            "from mga01.intel.com (mga01.intel.com [192.55.52.88])\n\tby dpdk.org (Postfix) with ESMTP id C1AD11B029\n\tfor <dev@dpdk.org>; Fri,  8 Jun 2018 10:42:49 +0200 (CEST)",
            "from orsmga007.jf.intel.com ([10.7.209.58])\n\tby fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t08 Jun 2018 01:42:49 -0700",
            "from sivswdev02.ir.intel.com (HELO localhost.localdomain)\n\t([10.237.217.46])\n\tby orsmga007.jf.intel.com with ESMTP; 08 Jun 2018 01:42:48 -0700"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.49,490,1520924400\"; d=\"scan'208\";a=\"47424171\"",
        "From": "Konstantin Ananyev <konstantin.ananyev@intel.com>",
        "To": [
            "dev@dpdk.org",
            "dev@dpdk.org"
        ],
        "Cc": "Konstantin Ananyev <konstantin.ananyev@intel.com>",
        "Date": "Fri,  8 Jun 2018 09:42:33 +0100",
        "Message-Id": "<1528447355-29411-2-git-send-email-konstantin.ananyev@intel.com>",
        "X-Mailer": "git-send-email 1.7.0.7",
        "In-Reply-To": "<1528447355-29411-1-git-send-email-konstantin.ananyev@intel.com>",
        "References": "<1528447355-29411-1-git-send-email-konstantin.ananyev@intel.com>",
        "Subject": "[dpdk-dev] [PATCH 1/3] bpf: add extra information for external\n\tsymbol definitions",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Extend struct rte_bpf_xsym with new fields to provide information about:\n - for variables - type and size\n - for functions - number of arguments and type/size of each argument\n   and return value\n\nSuch information would allow validate code to perform\nmore extensive checking on input BPF program and catch\nmisbehaving BPF code.\n\nThat change would cause ABI/API breakage for librte_bpf.\n\nSigned-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>\n---\n app/test-pmd/bpf_cmd.c        | 27 ++++++++++++++++++++++--\n lib/librte_bpf/bpf_def.h      |  5 +++++\n lib/librte_bpf/bpf_exec.c     |  2 +-\n lib/librte_bpf/bpf_impl.h     | 14 +++++++++++++\n lib/librte_bpf/bpf_jit_x86.c  | 17 ++-------------\n lib/librte_bpf/bpf_load.c     | 49 ++++++++++++++++++++++++++++++++++++++++++-\n lib/librte_bpf/bpf_load_elf.c |  4 ++--\n lib/librte_bpf/rte_bpf.h      | 21 +++++++++++++++----\n test/test/test_bpf.c          | 19 ++++++++++++++++-\n 9 files changed, 132 insertions(+), 26 deletions(-)",
    "diff": "diff --git a/app/test-pmd/bpf_cmd.c b/app/test-pmd/bpf_cmd.c\nindex 584fad908..830bfc13a 100644\n--- a/app/test-pmd/bpf_cmd.c\n+++ b/app/test-pmd/bpf_cmd.c\n@@ -19,12 +19,35 @@ static const struct rte_bpf_xsym bpf_xsym[] = {\n \t{\n \t\t.name = RTE_STR(stdout),\n \t\t.type = RTE_BPF_XTYPE_VAR,\n-\t\t.var = &stdout,\n+\t\t.var = {\n+\t\t\t.val = &stdout,\n+\t\t\t.desc = {\n+\t\t\t\t.type = RTE_BPF_ARG_PTR,\n+\t\t\t\t.size = sizeof(stdout),\n+\t\t\t},\n+\t\t},\n \t},\n \t{\n \t\t.name = RTE_STR(rte_pktmbuf_dump),\n \t\t.type = RTE_BPF_XTYPE_FUNC,\n-\t\t.func = (void *)rte_pktmbuf_dump,\n+\t\t.func = {\n+\t\t\t.val = (void *)rte_pktmbuf_dump,\n+\t\t\t.nb_args = 3,\n+\t\t\t.args = {\n+\t\t\t\t[0] = {\n+\t\t\t\t\t.type = RTE_BPF_ARG_RAW,\n+\t\t\t\t\t.size = sizeof(uintptr_t),\n+\t\t\t\t},\n+\t\t\t\t[1] = {\n+\t\t\t\t\t.type = RTE_BPF_ARG_PTR_MBUF,\n+\t\t\t\t\t.size = sizeof(struct rte_mbuf),\n+\t\t\t\t},\n+\t\t\t\t[2] = {\n+\t\t\t\t\t.type = RTE_BPF_ARG_RAW,\n+\t\t\t\t\t.size = sizeof(uint32_t),\n+\t\t\t\t},\n+\t\t\t},\n+\t\t},\n \t},\n };\n \ndiff --git a/lib/librte_bpf/bpf_def.h b/lib/librte_bpf/bpf_def.h\nindex 6b69de345..c10f3aec4 100644\n--- a/lib/librte_bpf/bpf_def.h\n+++ b/lib/librte_bpf/bpf_def.h\n@@ -131,6 +131,11 @@ struct ebpf_insn {\n \tint32_t imm;\n };\n \n+/*\n+ * eBPF allows functions with R1-R5 as arguments.\n+ */\n+#define\tEBPF_FUNC_MAX_ARGS\t(EBPF_REG_6 - EBPF_REG_1)\n+\n #ifdef __cplusplus\n }\n #endif\ndiff --git a/lib/librte_bpf/bpf_exec.c b/lib/librte_bpf/bpf_exec.c\nindex e373b1f3d..6a79139c0 100644\n--- a/lib/librte_bpf/bpf_exec.c\n+++ b/lib/librte_bpf/bpf_exec.c\n@@ -402,7 +402,7 @@ bpf_exec(const struct rte_bpf *bpf, uint64_t reg[EBPF_REG_NUM])\n \t\t\tbreak;\n \t\t/* call instructions */\n \t\tcase (BPF_JMP | EBPF_CALL):\n-\t\t\treg[EBPF_REG_0] = bpf->prm.xsym[ins->imm].func(\n+\t\t\treg[EBPF_REG_0] = bpf->prm.xsym[ins->imm].func.val(\n \t\t\t\treg[EBPF_REG_1], reg[EBPF_REG_2],\n \t\t\t\treg[EBPF_REG_3], reg[EBPF_REG_4],\n \t\t\t\treg[EBPF_REG_5]);\ndiff --git a/lib/librte_bpf/bpf_impl.h b/lib/librte_bpf/bpf_impl.h\nindex 5d7e65c31..b577e2cbe 100644\n--- a/lib/librte_bpf/bpf_impl.h\n+++ b/lib/librte_bpf/bpf_impl.h\n@@ -34,6 +34,20 @@ extern int rte_bpf_logtype;\n #define\tRTE_BPF_LOG(lvl, fmt, args...) \\\n \trte_log(RTE_LOG_## lvl, rte_bpf_logtype, fmt, ##args)\n \n+static inline size_t\n+bpf_size(uint32_t bpf_op_sz)\n+{\n+\tif (bpf_op_sz == BPF_B)\n+\t\treturn sizeof(uint8_t);\n+\telse if (bpf_op_sz == BPF_H)\n+\t\treturn sizeof(uint16_t);\n+\telse if (bpf_op_sz == BPF_W)\n+\t\treturn sizeof(uint32_t);\n+\telse if (bpf_op_sz == EBPF_DW)\n+\t\treturn sizeof(uint64_t);\n+\treturn 0;\n+}\n+\n #ifdef __cplusplus\n }\n #endif\ndiff --git a/lib/librte_bpf/bpf_jit_x86.c b/lib/librte_bpf/bpf_jit_x86.c\nindex 111e028d2..68ea389f2 100644\n--- a/lib/librte_bpf/bpf_jit_x86.c\n+++ b/lib/librte_bpf/bpf_jit_x86.c\n@@ -113,20 +113,6 @@ union bpf_jit_imm {\n \tuint8_t u8[4];\n };\n \n-static size_t\n-bpf_size(uint32_t bpf_op_sz)\n-{\n-\tif (bpf_op_sz == BPF_B)\n-\t\treturn sizeof(uint8_t);\n-\telse if (bpf_op_sz == BPF_H)\n-\t\treturn sizeof(uint16_t);\n-\telse if (bpf_op_sz == BPF_W)\n-\t\treturn sizeof(uint32_t);\n-\telse if (bpf_op_sz == EBPF_DW)\n-\t\treturn sizeof(uint64_t);\n-\treturn 0;\n-}\n-\n /*\n  * In many cases for imm8 we can produce shorter code.\n  */\n@@ -1294,7 +1280,8 @@ emit(struct bpf_jit_state *st, const struct rte_bpf *bpf)\n \t\t\tbreak;\n \t\t/* call instructions */\n \t\tcase (BPF_JMP | EBPF_CALL):\n-\t\t\temit_call(st, (uintptr_t)bpf->prm.xsym[ins->imm].func);\n+\t\t\temit_call(st,\n+\t\t\t\t(uintptr_t)bpf->prm.xsym[ins->imm].func.val);\n \t\t\tbreak;\n \t\t/* return instruction */\n \t\tcase (BPF_JMP | EBPF_EXIT):\ndiff --git a/lib/librte_bpf/bpf_load.c b/lib/librte_bpf/bpf_load.c\nindex d1c9abd7f..2b84fe724 100644\n--- a/lib/librte_bpf/bpf_load.c\n+++ b/lib/librte_bpf/bpf_load.c\n@@ -51,17 +51,64 @@ bpf_load(const struct rte_bpf_prm *prm)\n \treturn bpf;\n }\n \n+/*\n+ * Check that user provided external symbol.\n+ */\n+static int\n+bpf_check_xsym(const struct rte_bpf_xsym *xsym)\n+{\n+\tuint32_t i;\n+\n+\tif (xsym->name == NULL)\n+\t\treturn -EINVAL;\n+\n+\tif (xsym->type == RTE_BPF_XTYPE_VAR) {\n+\t\tif (xsym->var.desc.type == RTE_BPF_ARG_UNDEF)\n+\t\t\treturn -EINVAL;\n+\t} else if (xsym->type == RTE_BPF_XTYPE_FUNC) {\n+\n+\t\tif (xsym->func.nb_args > EBPF_FUNC_MAX_ARGS)\n+\t\t\treturn -EINVAL;\n+\n+\t\t/* check function arguments */\n+\t\tfor (i = 0; i != xsym->func.nb_args; i++) {\n+\t\t\tif (xsym->func.args[i].type == RTE_BPF_ARG_UNDEF)\n+\t\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\t/* check return value info */\n+\t\tif (xsym->func.ret.type != RTE_BPF_ARG_UNDEF &&\n+\t\t\t\txsym->func.ret.size == 0)\n+\t\t\treturn -EINVAL;\n+\t} else\n+\t\treturn -EINVAL;\n+\n+\treturn 0;\n+}\n+\n __rte_experimental struct rte_bpf *\n rte_bpf_load(const struct rte_bpf_prm *prm)\n {\n \tstruct rte_bpf *bpf;\n \tint32_t rc;\n+\tuint32_t i;\n \n-\tif (prm == NULL || prm->ins == NULL) {\n+\tif (prm == NULL || prm->ins == NULL ||\n+\t\t\t(prm->nb_xsym != 0 && prm->xsym == NULL)) {\n \t\trte_errno = EINVAL;\n \t\treturn NULL;\n \t}\n \n+\trc = 0;\n+\tfor (i = 0; i != prm->nb_xsym && rc == 0; i++)\n+\t\trc = bpf_check_xsym(prm->xsym + i);\n+\n+\tif (rc != 0) {\n+\t\trte_errno = -rc;\n+\t\tRTE_BPF_LOG(ERR, \"%s: %d-th xsym is invalid\\n\", __func__, i);\n+\t\treturn NULL;\n+\t}\n+\n \tbpf = bpf_load(prm);\n \tif (bpf == NULL) {\n \t\trte_errno = ENOMEM;\ndiff --git a/lib/librte_bpf/bpf_load_elf.c b/lib/librte_bpf/bpf_load_elf.c\nindex 6ab03d86e..96d3630fe 100644\n--- a/lib/librte_bpf/bpf_load_elf.c\n+++ b/lib/librte_bpf/bpf_load_elf.c\n@@ -81,9 +81,9 @@ resolve_xsym(const char *sn, size_t ofs, struct ebpf_insn *ins, size_t ins_sz,\n \t\tins[idx].imm = fidx;\n \t/* for variable we need to store its absolute address */\n \telse {\n-\t\tins[idx].imm = (uintptr_t)prm->xsym[fidx].var;\n+\t\tins[idx].imm = (uintptr_t)prm->xsym[fidx].var.val;\n \t\tins[idx + 1].imm =\n-\t\t\t(uint64_t)(uintptr_t)prm->xsym[fidx].var >> 32;\n+\t\t\t(uint64_t)(uintptr_t)prm->xsym[fidx].var.val >> 32;\n \t}\n \n \treturn 0;\ndiff --git a/lib/librte_bpf/rte_bpf.h b/lib/librte_bpf/rte_bpf.h\nindex 1249a992c..ad62ef2c6 100644\n--- a/lib/librte_bpf/rte_bpf.h\n+++ b/lib/librte_bpf/rte_bpf.h\n@@ -40,7 +40,11 @@ enum rte_bpf_arg_type {\n  */\n struct rte_bpf_arg {\n \tenum rte_bpf_arg_type type;\n-\tsize_t size;     /**< for pointer types, size of data it points to */\n+\t/**\n+\t * for ptr type - max size of data buffer it points to\n+\t * for raw type - the size (in bytes) of the value\n+\t */\n+\tsize_t size;\n \tsize_t buf_size;\n \t/**< for mbuf ptr type, max size of rte_mbuf data buffer */\n };\n@@ -66,10 +70,19 @@ struct rte_bpf_xsym {\n \tconst char *name;        /**< name */\n \tenum rte_bpf_xtype type; /**< type */\n \tunion {\n-\t\tuint64_t (*func)(uint64_t, uint64_t, uint64_t,\n+\t\tstruct {\n+\t\t\tuint64_t (*val)(uint64_t, uint64_t, uint64_t,\n \t\t\t\tuint64_t, uint64_t);\n-\t\tvoid *var;\n-\t}; /**< value */\n+\t\t\tuint32_t nb_args;\n+\t\t\tstruct rte_bpf_arg args[EBPF_FUNC_MAX_ARGS];\n+\t\t\t/**< Function arguments descriptions. */\n+\t\t\tstruct rte_bpf_arg ret; /**< function return value. */\n+\t\t} func;\n+\t\tstruct {\n+\t\t\tvoid *val; /**< actual memory location */\n+\t\t\tstruct rte_bpf_arg desc; /**< type, size, etc. */\n+\t\t} var; /**< external variable */\n+\t};\n };\n \n /**\ndiff --git a/test/test/test_bpf.c b/test/test/test_bpf.c\nindex cbd6be63d..1e9caef95 100644\n--- a/test/test/test_bpf.c\n+++ b/test/test/test_bpf.c\n@@ -1530,7 +1530,24 @@ static const struct rte_bpf_xsym test_call1_xsym[] = {\n \t{\n \t\t.name = RTE_STR(dummy_func1),\n \t\t.type = RTE_BPF_XTYPE_FUNC,\n-\t\t.func = (void *)dummy_func1,\n+\t\t.func = {\n+\t\t\t.val = (void *)dummy_func1,\n+\t\t\t.nb_args = 3,\n+\t\t\t.args = {\n+\t\t\t\t[0] = {\n+\t\t\t\t\t.type = RTE_BPF_ARG_PTR,\n+\t\t\t\t\t.size = sizeof(struct dummy_offset),\n+\t\t\t\t},\n+\t\t\t\t[1] = {\n+\t\t\t\t\t.type = RTE_BPF_ARG_PTR,\n+\t\t\t\t\t.size = sizeof(uint32_t),\n+\t\t\t\t},\n+\t\t\t\t[2] = {\n+\t\t\t\t\t.type = RTE_BPF_ARG_PTR,\n+\t\t\t\t\t.size = sizeof(uint64_t),\n+\t\t\t\t},\n+\t\t\t},\n+\t\t},\n \t},\n };\n \n",
    "prefixes": [
        "dpdk-dev",
        "1/3"
    ]
}