From patchwork Tue Sep 24 15:20:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harman Kalra X-Patchwork-Id: 59683 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CE7852BEA; Tue, 24 Sep 2019 17:21:23 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 884412BCE for ; Tue, 24 Sep 2019 17:21:22 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x8OFKlpT022665; Tue, 24 Sep 2019 08:21:21 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=pfpt0818; bh=kbXmjtba48b2cSWRyYbobpzNLCAsOAl98kvcug87UDg=; b=Tpc5QK8lu1f8rl1qn3ejzeie/KEkTvf+r6G83PImierARNUZL6VEtLg/GnprZM2o3W2W 2SU/+4XbaULAqc0drz7SV+ypZvVlPQesPmInSgIdzbn2gfcPB8y+01uQBVL2T9nbDVsq t9BVRQETHgVU/OFmEvy415MdIui77OD5d3pm+DhLCn6BRoBcMyvLFASqrI6XpF26kKE2 knytCYvz6h/EMbqF917fhgZegpfbs9lIKoJ1mRAGGBaxxE9EMZT7Hi+bPoWKlAF++gdM MRzBfL6kAjAHHfZRJGHmTZZoMQzQQD3V5alujh/Hn6WY4R+vRqO4PSXzpPEwL/edbMN8 8w== Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0b-0016f401.pphosted.com with ESMTP id 2v7nq1804k-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 24 Sep 2019 08:21:21 -0700 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 24 Sep 2019 08:20:26 -0700 Received: from NAM05-BY2-obe.outbound.protection.outlook.com (104.47.50.55) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Tue, 24 Sep 2019 08:20:26 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HK78AH2op2DijjddxUxxBvx/tNPH7wEfEFnpb7VFbDkn8HcBUgETtVf/kpBBiNQE+ByNma6AWWLNYKbFv/RO6uM2W6mhhA8MhsJTSEg3dcKQk5rJ20uuHM0tzqMva5S3pKAif1Z95Cnu+jMct/Oh5feoKlfmH7v51MjFEhZQO/gOWffHs3XZArSK4ytpQA59ayNPcDYDNgX09FL3lf528kp6G/oOFTs9HRpK45YfSeS83QrLwKEN7V50knUgagTdDm/q4OzyymSPn9kx2AGy3NVt3iHMtl8R1ta4S/+ZhLd2slb3DpTLUOXyf52mIKlbbPYKQMrF6lkBZuHuCOgyWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kbXmjtba48b2cSWRyYbobpzNLCAsOAl98kvcug87UDg=; b=fefa8xEmQ/k3R/nZ+zOaelIlcufCHCRtp/t/iCMnO5uPzALv5G5CsXWj3pIYyHAH1DXLJCQSUTtGItwP0B5460cAzvdmiJSwb60ndUOxzifjgAMj5z3LALJHHxAoABcYANRnXvV2x32Q0dlGMEl+NHjdGeul35ZlDcxL5saLUqPRcpZH+/QMQYyK5wj8K2FqPjsFcT4N/Hpr2dsaqEm46qJclolJAT46u5wMFlTscp6y4CtH1GnFAg+Rx9fGp2BDrZ7rR3Tx8XZS2RZD5rPxbMwddA8Qs2lo3KAFG3rvWFLJmjHghBqV8dJ/phIEOdudzwLm9c0SMvIMDJiEd+pjGQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector2-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kbXmjtba48b2cSWRyYbobpzNLCAsOAl98kvcug87UDg=; b=aaexGY6Ss0jEBOcrNaFUAtCTD2LJyz6WBh8dmuiZn9LUMnfQxEDFWPtD4S1kxKcaw0DVjvDTBdpK9UxUcDr7ffEtPxQGqnMlf97uKP+K+Qdw06eYkzYWoK7fvAgd30DOHj1FsQflEXHAGx13MZYEaCsw9gK7kScP7XRMMqz6go8= Received: from MN2PR18MB2848.namprd18.prod.outlook.com (20.179.21.149) by MN2PR18MB2591.namprd18.prod.outlook.com (20.179.82.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2284.23; Tue, 24 Sep 2019 15:20:25 +0000 Received: from MN2PR18MB2848.namprd18.prod.outlook.com ([fe80::196f:da3c:751b:8ffa]) by MN2PR18MB2848.namprd18.prod.outlook.com ([fe80::196f:da3c:751b:8ffa%7]) with mapi id 15.20.2284.023; Tue, 24 Sep 2019 15:20:24 +0000 From: Harman Kalra To: Konstantin Ananyev CC: "dev@dpdk.org" , Harman Kalra Thread-Topic: [PATCH] test/bpf: add new test cases Thread-Index: AQHVcuuWfPAukSSWCkez/k1/g6T2dA== Date: Tue, 24 Sep 2019 15:20:24 +0000 Message-ID: <1569338383-11118-1-git-send-email-hkalra@marvell.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: BMXPR01CA0015.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:d::25) To MN2PR18MB2848.namprd18.prod.outlook.com (2603:10b6:208:3e::21) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.7.4 x-originating-ip: [115.113.156.2] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 49eba447-751c-4faa-f77b-08d74102b8f6 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600167)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR18MB2591; x-ms-traffictypediagnostic: MN2PR18MB2591: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1169; x-forefront-prvs: 0170DAF08C x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(376002)(366004)(39860400002)(136003)(346002)(396003)(189003)(199004)(81156014)(8676002)(81166006)(305945005)(7736002)(66946007)(50226002)(3846002)(6116002)(5660300002)(316002)(66066001)(64756008)(66556008)(66476007)(54906003)(478600001)(66446008)(2906002)(30864003)(14454004)(6486002)(25786009)(486006)(14444005)(256004)(52116002)(86362001)(99286004)(36756003)(6512007)(476003)(186003)(4326008)(2616005)(6436002)(55236004)(19627235002)(107886003)(71190400001)(6916009)(386003)(26005)(6506007)(71200400001)(102836004)(8936002); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR18MB2591; H:MN2PR18MB2848.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: GwUvvBpnVo81/AZXgkkEW2vfxzl83jT7yqw4GyxjxZhxB+/2cyHUfbNtFGNzD2lNx4AmYkzQHbq/DerF0ttVaJ0DSN1UiI8EhyfdPe9eWuUjeOR2/KrmVrdMivFVPmzArQXEHL7ULD/LCSltGoA0zaAV4u6F8FzEnhh75hO7DEPgj24jiUKaEet0NQXBLRqxjFpEZRSUGjcje93Gt5lHgdGTI1VOd0bftqofZkmszs9wEooo8VtzNcubSih+B4hNkNfq5poFnpRYX3xytK3HlYDKFSP4Q9k+XS5anabQDIdHvCE1fmUbt9XNgYE6JacEyj3YnR9RaADYgRlVx8FboZqydDdJ7rjR90yx0PYJaDLjRoFE/rtOkrTHmZ9NnN5OojSWbzhpAbh3AFaYiS5gvFd1nt9N+3jcb6LaYau4Krk= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 49eba447-751c-4faa-f77b-08d74102b8f6 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Sep 2019 15:20:24.7346 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: syku7ZOb/f6NKEcNyjbSixbsNd2PCvNuP601r4TY6poZF2ElCWIkrRPjsoecmuBV/q0KQIYZ7wokyq3G5rHJdg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR18MB2591 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,1.0.8 definitions=2019-09-24_06:2019-09-23,2019-09-24 signatures=0 Subject: [dpdk-dev] [PATCH] test/bpf: add new test cases X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch implements following new test cases: - test_call4: test case to verify if stack corruption occurs across with multiple function calls. - test_jump2: test case with a default packet in memory, parse the packet and check if dest ip is part of a subnet. - test_call5: test case with string data in the stack and calling string comaprision. Signed-off-by: Harman Kalra --- app/test/test_bpf.c | 644 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 644 insertions(+) diff --git a/app/test/test_bpf.c b/app/test/test_bpf.c index e8841800a..c6b9819fc 100644 --- a/app/test/test_bpf.c +++ b/app/test/test_bpf.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include "test.h" @@ -35,6 +37,12 @@ struct dummy_vect8 { struct dummy_offset out[8]; }; +struct dummy_net { + struct rte_ether_hdr eth_hdr; + struct rte_vlan_hdr vlan_hdr; + struct rte_ipv4_hdr ip_hdr; +}; + #define TEST_FILL_1 0xDEADBEEF #define TEST_MUL_1 21 @@ -54,6 +62,20 @@ struct dummy_vect8 { #define TEST_IMM_4 ((uint64_t)UINT32_MAX) #define TEST_IMM_5 ((uint64_t)UINT32_MAX + 1) +#define TEST_MEMFROB 0x2a2a2a2a + +#define STRING_GEEK 0x6B656567 +#define STRING_WEEK 0x6B656577 + +#define TEST_NETMASK 0xffffff00 +#define TEST_SUBNET 0xaca80200 + +uint8_t src_mac[] = { 0x00, 0xFF, 0xAA, 0xFF, 0xAA, 0xFF }; +uint8_t dst_mac[] = { 0x00, 0xAA, 0xFF, 0xAA, 0xFF, 0xAA }; + +uint32_t ip_src_addr = (172U << 24) | (168U << 16) | (2 << 8) | 1; +uint32_t ip_dst_addr = (172U << 24) | (168U << 16) | (2 << 8) | 2; + struct bpf_test { const char *name; size_t arg_sz; @@ -866,6 +888,181 @@ test_jump1_check(uint64_t rc, const void *arg) return cmp_res(__func__, rv, rc, &rv, &rc, sizeof(rv)); } +/* Jump test case - check ip4_dest in particular subnet */ +static const struct ebpf_insn test_jump2_prog[] = { + + [0] = { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_K), + .dst_reg = EBPF_REG_2, + .imm = 0xe, + }, + [1] = { + .code = (BPF_LDX | BPF_MEM | BPF_H), + .dst_reg = EBPF_REG_3, + .src_reg = EBPF_REG_1, + .off = 12, + }, + [2] = { + .code = (BPF_JMP | EBPF_JNE | BPF_K), + .dst_reg = EBPF_REG_3, + .off = 2, + .imm = 0x81, + }, + [3] = { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_K), + .dst_reg = EBPF_REG_2, + .imm = 0x12, + }, + [4] = { + .code = (BPF_LDX | BPF_MEM | BPF_H), + .dst_reg = EBPF_REG_3, + .src_reg = EBPF_REG_1, + .off = 16, + }, + [5] = { + .code = (EBPF_ALU64 | BPF_AND | BPF_K), + .dst_reg = EBPF_REG_3, + .imm = 0xffff, + }, + [6] = { + .code = (BPF_JMP | EBPF_JNE | BPF_K), + .dst_reg = EBPF_REG_3, + .off = 9, + .imm = 0x8, + }, + [7] = { + .code = (EBPF_ALU64 | BPF_ADD | BPF_X), + .dst_reg = EBPF_REG_1, + .src_reg = EBPF_REG_2, + }, + [8] = { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_K), + .dst_reg = EBPF_REG_0, + .imm = 0, + }, + [9] = { + .code = (BPF_LDX | BPF_MEM | BPF_W), + .dst_reg = EBPF_REG_1, + .src_reg = EBPF_REG_1, + .off = 16, + }, + [10] = { + .code = (BPF_ALU | EBPF_MOV | BPF_K), + .dst_reg = EBPF_REG_3, + .imm = TEST_NETMASK, + }, + [11] = { + .code = (BPF_ALU | EBPF_END | EBPF_TO_BE), + .dst_reg = EBPF_REG_3, + .imm = sizeof(uint32_t) * CHAR_BIT, + }, + [12] = { + .code = (BPF_ALU | BPF_AND | BPF_X), + .dst_reg = EBPF_REG_1, + .src_reg = EBPF_REG_3, + }, + [13] = { + .code = (BPF_ALU | EBPF_MOV | BPF_K), + .dst_reg = EBPF_REG_3, + .imm = TEST_SUBNET, + }, + [14] = { + .code = (BPF_ALU | EBPF_END | EBPF_TO_BE), + .dst_reg = EBPF_REG_3, + .imm = sizeof(uint32_t) * CHAR_BIT, + }, + [15] = { + .code = (BPF_JMP | BPF_JEQ | BPF_X), + .dst_reg = EBPF_REG_1, + .src_reg = EBPF_REG_3, + .off = 1, + }, + [16] = { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_K), + .dst_reg = EBPF_REG_0, + .imm = -1, + }, + [17] = { + .code = (BPF_JMP | EBPF_EXIT), + }, +}; + +/* Preparing a vlan packet */ +static void +test_jump2_prepare(void *arg) +{ + struct dummy_net *dn; + + dn = arg; + memset(dn, 0, sizeof(*dn)); + + /* + * Initialize ether header. + */ + rte_ether_addr_copy((struct rte_ether_addr *)dst_mac, + &dn->eth_hdr.d_addr); + rte_ether_addr_copy((struct rte_ether_addr *)src_mac, + &dn->eth_hdr.s_addr); + dn->eth_hdr.ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN); + + /* + * Initialize vlan header. + */ + dn->vlan_hdr.eth_proto = rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4); + dn->vlan_hdr.vlan_tci = 32; + + /* + * Initialize IP header. + */ + dn->ip_hdr.version_ihl = 0x45; /*IP_VERSION | IP_HDRLEN*/ + dn->ip_hdr.time_to_live = 64; /* IP_DEFTTL */ + dn->ip_hdr.next_proto_id = IPPROTO_TCP; + dn->ip_hdr.packet_id = rte_cpu_to_be_16(0x463c); + dn->ip_hdr.total_length = rte_cpu_to_be_16(60); + dn->ip_hdr.src_addr = rte_cpu_to_be_32(ip_src_addr); + dn->ip_hdr.dst_addr = rte_cpu_to_be_32(ip_dst_addr); +} + +static int +test_jump2_check(uint64_t rc, const void *arg) +{ + const struct rte_ether_hdr *eth_hdr = arg; + const struct rte_ipv4_hdr *ipv4_hdr; + const void *next = eth_hdr; + uint16_t eth_type; + uint64_t v = -1; + + if (eth_hdr->ether_type == htons(0x8100)) { + const struct rte_vlan_hdr *vlan_hdr = + (const void *)(eth_hdr + 1); + eth_type = vlan_hdr->eth_proto; + next = vlan_hdr + 1; + } else { + eth_type = eth_hdr->ether_type; + next = eth_hdr + 1; + } + + if (eth_type == htons(0x0800)) { + ipv4_hdr = next; + if ((ipv4_hdr->dst_addr & rte_cpu_to_be_32(TEST_NETMASK)) == + rte_cpu_to_be_32(TEST_SUBNET)) { + v = 0; + } + } + + if (v != rc) { + printf("%s@%d: invalid return value " + "expected=0x%" PRIx64 ", actual=0x%" PRIx64 "\n", + __func__, __LINE__, v, rc); + return -1; + } + + if (v) + printf("Either IP not part of subnet or wrong ethertype\n"); + + return 0; +} + /* alu (add, sub, and, or, xor, neg) test-cases */ static const struct ebpf_insn test_alu1_prog[] = { @@ -1889,6 +2086,403 @@ static const struct rte_bpf_xsym test_call3_xsym[] = { }, }; +/* Test for stack corruption in multiple function calls */ +static const struct ebpf_insn test_call4_prog[] = { + { + .code = (BPF_ST | BPF_MEM | BPF_B), + .dst_reg = EBPF_REG_10, + .off = -4, + .imm = 1, + }, + { + .code = (BPF_ST | BPF_MEM | BPF_B), + .dst_reg = EBPF_REG_10, + .off = -3, + .imm = 2, + }, + { + .code = (BPF_ST | BPF_MEM | BPF_B), + .dst_reg = EBPF_REG_10, + .off = -2, + .imm = 3, + }, + { + .code = (BPF_ST | BPF_MEM | BPF_B), + .dst_reg = EBPF_REG_10, + .off = -1, + .imm = 4, + }, + { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_X), + .dst_reg = EBPF_REG_1, + .src_reg = EBPF_REG_10, + }, + { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_K), + .dst_reg = EBPF_REG_2, + .imm = 4, + }, + { + .code = (EBPF_ALU64 | BPF_SUB | BPF_X), + .dst_reg = EBPF_REG_1, + .src_reg = EBPF_REG_2, + }, + { + .code = (BPF_JMP | EBPF_CALL), + .imm = 0, + }, + { + .code = (BPF_LDX | BPF_MEM | BPF_B), + .dst_reg = EBPF_REG_1, + .src_reg = EBPF_REG_10, + .off = -4, + }, + { + .code = (BPF_LDX | BPF_MEM | BPF_B), + .dst_reg = EBPF_REG_2, + .src_reg = EBPF_REG_10, + .off = -3, + }, + { + .code = (BPF_LDX | BPF_MEM | BPF_B), + .dst_reg = EBPF_REG_3, + .src_reg = EBPF_REG_10, + .off = -2, + }, + { + .code = (BPF_LDX | BPF_MEM | BPF_B), + .dst_reg = EBPF_REG_4, + .src_reg = EBPF_REG_10, + .off = -1, + }, + { + .code = (BPF_JMP | EBPF_CALL), + .imm = 1, + }, + { + .code = (EBPF_ALU64 | BPF_XOR | BPF_K), + .dst_reg = EBPF_REG_0, + .imm = TEST_MEMFROB, + }, + { + .code = (BPF_JMP | EBPF_EXIT), + }, +}; + +/* Gathering the bytes together */ +static uint32_t +dummy_func4_1(uint8_t a, uint8_t b, uint8_t c, uint8_t d) +{ + return (a << 24) | (b << 16) | (c << 8) | (d << 0); +} + +/* Implementation of memfrob */ +static uint32_t +dummy_func4_0(uint32_t *s, uint8_t n) +{ + char *p = (char *) s; + while (n-- > 0) + *p++ ^= 42; + return *s; +} + + +static int +test_call4_check(uint64_t rc, const void *arg) +{ + uint8_t a[4] = {1, 2, 3, 4}; + uint32_t s, v = 0; + + RTE_SET_USED(arg); + + s = dummy_func4_0((uint32_t *)a, 4); + + s = dummy_func4_1(a[0], a[1], a[2], a[3]); + + v = s ^ TEST_MEMFROB; + + if (v != rc) { + printf("%s@%d: invalid return value " + "expected=0x%" PRIx32 ", actual=0x%" PRIx64 "\n", + __func__, __LINE__, v, rc); + return -1; + } + return 0; +} + +static const struct rte_bpf_xsym test_call4_xsym[] = { + [0] = { + .name = RTE_STR(dummy_func4_0), + .type = RTE_BPF_XTYPE_FUNC, + .func = { + .val = (void *)dummy_func4_0, + .nb_args = 2, + .args = { + [0] = { + .type = RTE_BPF_ARG_PTR, + .size = 4 * sizeof(uint8_t), + }, + [1] = { + .type = RTE_BPF_ARG_RAW, + .size = sizeof(uint8_t), + }, + }, + .ret = { + .type = RTE_BPF_ARG_RAW, + .size = sizeof(uint32_t), + }, + }, + }, + [1] = { + .name = RTE_STR(dummy_func4_1), + .type = RTE_BPF_XTYPE_FUNC, + .func = { + .val = (void *)dummy_func4_1, + .nb_args = 4, + .args = { + [0] = { + .type = RTE_BPF_ARG_RAW, + .size = sizeof(uint8_t), + }, + [1] = { + .type = RTE_BPF_ARG_RAW, + .size = sizeof(uint8_t), + }, + [2] = { + .type = RTE_BPF_ARG_RAW, + .size = sizeof(uint8_t), + }, + [3] = { + .type = RTE_BPF_ARG_RAW, + .size = sizeof(uint8_t), + }, + }, + .ret = { + .type = RTE_BPF_ARG_RAW, + .size = sizeof(uint32_t), + }, + }, + }, +}; + +/* string compare test case */ +static const struct ebpf_insn test_call5_prog[] = { + + [0] = { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_K), + .dst_reg = EBPF_REG_1, + .imm = STRING_GEEK, + }, + [1] = { + .code = (BPF_STX | BPF_MEM | BPF_W), + .dst_reg = EBPF_REG_10, + .src_reg = EBPF_REG_1, + .off = -8, + }, + [2] = { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_K), + .dst_reg = EBPF_REG_6, + .imm = 0, + }, + [3] = { + .code = (BPF_STX | BPF_MEM | BPF_B), + .dst_reg = EBPF_REG_10, + .src_reg = EBPF_REG_6, + .off = -4, + }, + [4] = { + .code = (BPF_STX | BPF_MEM | BPF_W), + .dst_reg = EBPF_REG_10, + .src_reg = EBPF_REG_6, + .off = -12, + }, + [5] = { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_K), + .dst_reg = EBPF_REG_1, + .imm = STRING_WEEK, + }, + [6] = { + .code = (BPF_STX | BPF_MEM | BPF_W), + .dst_reg = EBPF_REG_10, + .src_reg = EBPF_REG_1, + .off = -16, + }, + [7] = { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_X), + .dst_reg = EBPF_REG_1, + .src_reg = EBPF_REG_10, + }, + [8] = { + .code = (EBPF_ALU64 | BPF_ADD | BPF_K), + .dst_reg = EBPF_REG_1, + .imm = -8, + }, + [9] = { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_X), + .dst_reg = EBPF_REG_2, + .src_reg = EBPF_REG_1, + }, + [10] = { + .code = (BPF_JMP | EBPF_CALL), + .imm = 0, + }, + [11] = { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_X), + .dst_reg = EBPF_REG_1, + .src_reg = EBPF_REG_0, + }, + [12] = { + .code = (BPF_ALU | EBPF_MOV | BPF_K), + .dst_reg = EBPF_REG_0, + .imm = -1, + }, + [13] = { + .code = (EBPF_ALU64 | BPF_LSH | BPF_K), + .dst_reg = EBPF_REG_1, + .imm = 0x20, + }, + [14] = { + .code = (EBPF_ALU64 | BPF_RSH | BPF_K), + .dst_reg = EBPF_REG_1, + .imm = 0x20, + }, + [15] = { + .code = (BPF_JMP | EBPF_JNE | BPF_K), + .dst_reg = EBPF_REG_1, + .off = 11, + .imm = 0, + }, + [16] = { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_X), + .dst_reg = EBPF_REG_1, + .src_reg = EBPF_REG_10, + }, + [17] = { + .code = (EBPF_ALU64 | BPF_ADD | BPF_K), + .dst_reg = EBPF_REG_1, + .imm = -8, + }, + [18] = { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_X), + .dst_reg = EBPF_REG_2, + .src_reg = EBPF_REG_10, + }, + [19] = { + .code = (EBPF_ALU64 | BPF_ADD | BPF_K), + .dst_reg = EBPF_REG_2, + .imm = -16, + }, + [20] = { + .code = (BPF_JMP | EBPF_CALL), + .imm = 0, + }, + [21] = { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_X), + .dst_reg = EBPF_REG_1, + .src_reg = EBPF_REG_0, + }, + [22] = { + .code = (EBPF_ALU64 | BPF_LSH | BPF_K), + .dst_reg = EBPF_REG_1, + .imm = 0x20, + }, + [23] = { + .code = (EBPF_ALU64 | BPF_RSH | BPF_K), + .dst_reg = EBPF_REG_1, + .imm = 0x20, + }, + [24] = { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_X), + .dst_reg = EBPF_REG_0, + .src_reg = EBPF_REG_1, + }, + [25] = { + .code = (BPF_JMP | BPF_JEQ | BPF_X), + .dst_reg = EBPF_REG_1, + .src_reg = EBPF_REG_6, + .off = 1, + }, + [26] = { + .code = (EBPF_ALU64 | EBPF_MOV | BPF_K), + .dst_reg = EBPF_REG_0, + .imm = 0, + }, + [27] = { + .code = (BPF_JMP | EBPF_EXIT), + }, +}; + +/* String comparision impelementation, return 0 if equal else difference */ +static uint32_t +dummy_func5(const char *s1, const char *s2) +{ + while (*s1 && (*s1 == *s2)) { + s1++; + s2++; + } + return *(const unsigned char *)s1 - *(const unsigned char *)s2; +} + +static int +test_call5_check(uint64_t rc, const void *arg) +{ + char a[] = "geek"; + char b[] = "week"; + uint32_t v; + + RTE_SET_USED(arg); + + v = dummy_func5(a, a); + if (v != 0) { + v = -1; + goto fail; + } + + v = dummy_func5(a, b); + if (v == 0) + goto fail; + + v = 0; + +fail: + if (v != rc) { + printf("%s@%d: invalid return value " + "expected=0x%" PRIx32 ", actual=0x%" PRIx64 "\n", + __func__, __LINE__, v, rc); + return -1; + } + + if (v) + printf("String comparision test failed\n"); + + return 0; +} + +static const struct rte_bpf_xsym test_call5_xsym[] = { + [0] = { + .name = RTE_STR(dummy_func5), + .type = RTE_BPF_XTYPE_FUNC, + .func = { + .val = (void *)dummy_func5, + .nb_args = 2, + .args = { + [0] = { + .type = RTE_BPF_ARG_PTR, + .size = sizeof(char), + }, + [1] = { + .type = RTE_BPF_ARG_PTR, + .size = sizeof(char), + }, + }, + .ret = { + .type = RTE_BPF_ARG_RAW, + .size = sizeof(uint32_t), + }, + }, + }, +}; + static const struct bpf_test tests[] = { { .name = "test_store1", @@ -1988,6 +2582,20 @@ static const struct bpf_test tests[] = { .prepare = test_jump1_prepare, .check_result = test_jump1_check, }, + { + .name = "test_jump2", + .arg_sz = sizeof(struct dummy_net), + .prm = { + .ins = test_jump2_prog, + .nb_ins = RTE_DIM(test_jump2_prog), + .prog_arg = { + .type = RTE_BPF_ARG_PTR, + .size = sizeof(struct dummy_net), + }, + }, + .prepare = test_jump2_prepare, + .check_result = test_jump2_check, + }, { .name = "test_alu1", .arg_sz = sizeof(struct dummy_vect8), @@ -2098,6 +2706,42 @@ static const struct bpf_test tests[] = { /* for now don't support function calls on 32 bit platform */ .allow_fail = (sizeof(uint64_t) != sizeof(uintptr_t)), }, + { + .name = "test_call4", + .arg_sz = sizeof(struct dummy_offset), + .prm = { + .ins = test_call4_prog, + .nb_ins = RTE_DIM(test_call4_prog), + .prog_arg = { + .type = RTE_BPF_ARG_PTR, + .size = 2 * sizeof(struct dummy_offset), + }, + .xsym = test_call4_xsym, + .nb_xsym = RTE_DIM(test_call4_xsym), + }, + .prepare = test_store1_prepare, + .check_result = test_call4_check, + /* for now don't support function calls on 32 bit platform */ + .allow_fail = (sizeof(uint64_t) != sizeof(uintptr_t)), + }, + { + .name = "test_call5", + .arg_sz = sizeof(struct dummy_offset), + .prm = { + .ins = test_call5_prog, + .nb_ins = RTE_DIM(test_call5_prog), + .prog_arg = { + .type = RTE_BPF_ARG_PTR, + .size = sizeof(struct dummy_offset), + }, + .xsym = test_call5_xsym, + .nb_xsym = RTE_DIM(test_call5_xsym), + }, + .prepare = test_store1_prepare, + .check_result = test_call5_check, + /* for now don't support function calls on 32 bit platform */ + .allow_fail = (sizeof(uint64_t) != sizeof(uintptr_t)), + }, }; static int