Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754088AbdFMXty (ORCPT ); Tue, 13 Jun 2017 19:49:54 -0400 Received: from mail-dm3nam03on0070.outbound.protection.outlook.com ([104.47.41.70]:9568 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753323AbdFMXtt (ORCPT ); Tue, 13 Jun 2017 19:49:49 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=David.Daney@cavium.com; From: David Daney To: Alexei Starovoitov , Daniel Borkmann , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-mips@linux-mips.org, ralf@linux-mips.org, David Daney Subject: [PATCH 2/4] test_bpf: Add test to make conditional jump cross a large number of insns. Date: Tue, 13 Jun 2017 16:49:36 -0700 Message-Id: <20170613234938.4823-3-david.daney@cavium.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170613234938.4823-1-david.daney@cavium.com> References: <20170613234938.4823-1-david.daney@cavium.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: BY2PR07CA0024.namprd07.prod.outlook.com (10.166.107.19) To MWHPR07MB3501.namprd07.prod.outlook.com (10.164.192.28) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR07MB3501: X-MS-Office365-Filtering-Correlation-Id: c2f60fcd-bb9f-43bb-9b3c-08d4b2b6de81 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:MWHPR07MB3501; X-Microsoft-Exchange-Diagnostics: 1;MWHPR07MB3501;3:4TXUqgwDoHO8ZQNqxXx/L4osKv+1KQA8gwh0Mt+lQIv+d8uklEF8zz8+ewJQKHOaIEtDIFmE2iDNLLpIvGGvOcGHE/SLOMM/QAwPpUQho3EeBsPC96x4L3Y8oF26oMF99DvKcgJjfuQsv+idr/Noe3C5Ucg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VUy0yJRWmJFe0ScgLtPhDg4pMyazYi34eura5XdQyaqHq3HqIBde/FxiNjpmfus1J+Oyih/iGdqGPu4EoRKaTosnr4JvhH6Gv8klYxs6y4gC5ZJRgUsYMwwOI+xpXYt1mAuqsb1tzwPpdikCEZrEj2FUUS3nFYDEAr1b8bHQiJLT3Zls1CqJT2KeukYWCoOX1Yp6Ci5f+w0JvI1o6nl1u1ZwFoYT3L1y/W7xR/w0ritYzHmgSQiqUMymhoPPndv76oPnHFL11MbPwFtebenwDKCrs7lpHQY66xZOJITApulitSMikCvYx5fkEW+se69SUH8xdLqter0ii6OaWsGSxN9EEoPyFTqECI4c8TAL41c7Nu8+dlD5aK123op1eqdq8TM6NUyIz1Cx X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(3002001)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123562025)(20161123555025)(20161123558100)(20161123560025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:MWHPR07MB3501;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:MWHPR07MB3501; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;MWHPR07MB3501;4:sdon57zVFhmDY4ffwUSqdcYkL/Yfx30MmKx2SjeXbI?= =?us-ascii?Q?H8NQeIEESShW8tv3aLU55g8JS2aEyzwp3dTvxiy/VDtUE1M2gGj+IbaUOwKu?= =?us-ascii?Q?cEi1iwjhVVHieK3QCO1uZ11hs+ss0pJUB/7PN63L6lgX5NxZ6Db+PnbdnBCE?= =?us-ascii?Q?MuoKQdboCQgtgUcBScjcw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?= =?us-ascii?Q?VU9C+2s8kdiID4pjECO6uJr+4bzKAIWr8t4wlxdS4UWrz2j19YHWgxCPw3aa?= =?us-ascii?Q?YyojI+mouL9KXQHktwwQuVQRw6X8/L?= X-Forefront-PRVS: 0337AFFE9A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(6009001)(39840400002)(39450400003)(39410400002)(39400400002)(39850400002)(189002)(199003)(6512007)(105586002)(53936002)(50226002)(53416004)(2950100002)(106356001)(4326008)(189998001)(6506006)(25786009)(42186005)(6666003)(33646002)(50466002)(69596002)(5003940100001)(6486002)(48376002)(76176999)(47776003)(7736002)(305945005)(1076002)(478600001)(101416001)(2906002)(81156014)(8676002)(81166006)(72206003)(107886003)(36756003)(5660300001)(66066001)(38730400002)(3846002)(68736007)(97736004)(6116002)(86362001)(50986999);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR07MB3501;H:ddl.caveonetworks.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;MWHPR07MB3501;23:OjPBNjiP/464mkaGj4g7sevimu92mRKGhXdOKBHZh?= =?us-ascii?Q?lzrXvLU5AK8VdujTnpoyJMZ+hkCfknxOzJNFIYc+D7hd9fuZ7ZACx3LyAGw5?= =?us-ascii?Q?gBasCFKyKafX3WIG0JcNblh9CGPiiACmhd51d3tSnlpOd7yt5A27KkSMoQVZ?= =?us-ascii?Q?mEtgaFii8LCanN0s2AxZwzStsh5tRRrsuXpDCvhbrI9i0bAAo4TCOgC6i7mV?= =?us-ascii?Q?0M3PTIlTIZrIwN+NAH+A5Jy7UhloBDMZDsX9vCwraW80xbG0WhCw80QkSErK?= =?us-ascii?Q?PCjbYwB9PHXgtUT6ZuY2BNqHatQpZKxHOrgvWab4qpNptaP8d4Vqs0Bg4E3Q?= =?us-ascii?Q?pOxOjVDaCR3QhiES9k5ZO/DD/kynKjNenCWOeLmQ2H9VRz9NlZ44kts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IG1a5wE9Ti81Y7ZPDivrAvGMsf3jrL1aIhQVbvHJl729A;24:zgDv82cLUtTR/9Nw/wj176YOjGYQYSkIOV6lkFUsC33qe2VwO3PnQVoVfZWWKTQFnSrrHge5h/KCjNC42yNngWqi3C31BySjYVn407NMDQ8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;MWHPR07MB3501;7:VuxI//SHaU3WB75yCxarh/fjBRUM0tXmDhvZOKMXYojra/IB4QPJLHA9LlXBwtlZA/60KZte+wndkiNZs3H1W0pMd+EUdlGQ2yDKCy3UgPZqIAjvVsXrU7PYUNM5yeC85lXaEpHafdMu5Frz6W578oPYQPbJF70hfGJEsBrTQ7EkYDvs43DsJtRYkhGPm3i0EbgH35jqLeYAudM/Afw4442pnKxQz16hvpM75bbiPFWrpFo7xIckQzQIoh0y1X3QR6aPMY4X5ejukUT9IoGogEBxSGhNUeMBkYZfNVLzliarDm60bLVRded7unrJVY+P7N/g63GE9Os45e6jqrQSRQ== X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2017 23:49:45.0410 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR07MB3501 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1812 Lines: 66 On MIPS, conditional branches can only span 32k instructions. To exceed this limit in the JIT with the BPF maximum of 4k insns, we need to choose eBPF insns that expand to more than 8 machine instructions. Use BPF_LD_ABS as it is quite complex. This forces the JIT to invert the sense of the branch to branch around a long jump to the end. This (somewhat) verifies that the branch inversion logic and target address calculation of the long jumps are done correctly. Signed-off-by: David Daney --- lib/test_bpf.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/test_bpf.c b/lib/test_bpf.c index be88cba..9ecbf47 100644 --- a/lib/test_bpf.c +++ b/lib/test_bpf.c @@ -434,6 +434,30 @@ static int bpf_fill_ld_abs_vlan_push_pop(struct bpf_test *self) return 0; } +static int bpf_fill_jump_around_ld_abs(struct bpf_test *self) +{ + unsigned int len = BPF_MAXINSNS; + struct bpf_insn *insn; + int i = 0; + + insn = kmalloc_array(len, sizeof(*insn), GFP_KERNEL); + if (!insn) + return -ENOMEM; + + insn[i++] = BPF_MOV64_REG(R6, R1); + insn[i++] = BPF_LD_ABS(BPF_B, 0); + insn[i] = BPF_JMP_IMM(BPF_JEQ, R0, 10, len - i - 2); + i++; + while (i < len - 1) + insn[i++] = BPF_LD_ABS(BPF_B, 1); + insn[i] = BPF_EXIT_INSN(); + + self->u.ptr.insns = insn; + self->u.ptr.len = len; + + return 0; +} + static int __bpf_fill_stxdw(struct bpf_test *self, int size) { unsigned int len = BPF_MAXINSNS; @@ -5022,6 +5046,14 @@ static struct bpf_test tests[] = { { { ETH_HLEN, 0xbef } }, .fill_helper = bpf_fill_ld_abs_vlan_push_pop, }, + { + "BPF_MAXINSNS: jump around ld_abs", + { }, + INTERNAL, + { 10, 11 }, + { { 2, 10 } }, + .fill_helper = bpf_fill_jump_around_ld_abs, + }, /* * LD_IND / LD_ABS on fragmented SKBs */ -- 2.9.4