Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751697AbdHSTFp (ORCPT ); Sat, 19 Aug 2017 15:05:45 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:57701 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750812AbdHSTFn (ORCPT ); Sat, 19 Aug 2017 15:05:43 -0400 Subject: Re: [PATCH net-next v3] arm: eBPF JIT compiler To: Shubham Bansal , , References: <1503134429-29063-1-git-send-email-illusionist.neo@gmail.com> CC: , , , , , From: Alexei Starovoitov Message-ID: Date: Sat, 19 Aug 2017 12:04:31 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <1503134429-29063-1-git-send-email-illusionist.neo@gmail.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [2620:10d:c090:180::1:cb] X-ClientProxiedBy: YQBPR0101CA0007.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c00::20) To BL2PR15MB0961.namprd15.prod.outlook.com (2603:10b6:201:15::23) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 862d68a7-0113-4a33-caee-08d4e73524cd X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:BL2PR15MB0961; X-Microsoft-Exchange-Diagnostics: 1;BL2PR15MB0961;3:C5m5Ax57kp2Wqd8Pnpia/C1uT7bTD4LftR42RJRo4AfIhGLFRP0jHdDE/LcmUAk2C0+eqqkkptpPznWL34/pMxtooufalEg1oihdKSoTL+bRGkONJOR9iyhWtBvKsaXP9GSDmazkQ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IO6un13joHUz7O2y9gUkqro1D6vWAXPuW1M1DLJC9aZS15vpofjNKgxIPYy7Et7xQCLXl9GS4c4nzrTD2GE33WOxV13mN2iMm2rfSxMVTH6ZwE7eRqLezU3SQ8W8d4sGaV73jPY7aR/D/pAA0kpa6IZJbhogkg1aQtYIWwMbYX/IR7s8v42jLvSpsZXlG/o5BPxZ2ATO1sDuqhCFCNOoi;4:nPJNaRNB5AaXJ4YyleWlDSSVNqS2blSapggiiKrHesvfzb+v9T28sATBqLS3/yZwo2AiKv0+wqcd1wExBH2Gl3XesucXEZvUkOE2X6x4ekKkAWHDfiwNHarCmr50QnokDdq56J96s1ETwndqtbSL70XSs0IWFG81oXcb+JsHiNDiCzrNcic1frxxvsmPTib7fQ5SxQ6g6et/F17rUQlwliof0m4uTmng2T7GP6tZZ+cDJq7PFXYM4SzHWzg+KE55 X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(100000703101)(100105400095)(3002001)(10201501046)(6041248)(20161123560025)(20161123564025)(20161123562025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:BL2PR15MB0961;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:BL2PR15MB0961; X-Forefront-PRVS: 04041A2886 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(7370300001)(4630300001)(979002)(6009001)(199003)(377454003)(24454002)(189002)(31696002)(101416001)(105586002)(6486002)(4326008)(42186005)(110136004)(6246003)(25786009)(50986999)(53936002)(76176999)(54356999)(6666003)(6116002)(2906002)(64126003)(50466002)(230700001)(31686004)(106356001)(478600001)(23746002)(1706002)(86362001)(575784001)(2950100002)(4001350100001)(229853002)(36756003)(7350300001)(33646002)(83506001)(305945005)(7736002)(68736007)(65826007)(53546010)(189998001)(81166006)(81156014)(8676002)(97736004)(65956001)(65806001)(47776003)(5660300001)(42262002)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1102;SCL:1;SRVR:BL2PR15MB0961;H:[IPv6:2620:10d:c081:1132::10dd];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;BL2PR15MB0961;23:+4KNsH6S0astSKX0RdXaNoDUVYK2W1HiAk7Co?= =?Windows-1252?Q?0JO7Bej9SBvEJcphmFa9xu/gNDuId4nF7TR6nFCIn+3+hQQO6eV74I3C?= =?Windows-1252?Q?5tKgjrLwdQjbjJ3HrJSJjHumIN5HJdkfUFgcNepqrqEj+g/DJkYB9BJW?= =?Windows-1252?Q?MySahwXWvce/nyvFzLcD2Ht02uBwjAXZjJ5xzsRYI92oQth8lwGLS8l3?= =?Windows-1252?Q?ni9lq2AhKsweleq3ZK4t6mb1UPy/X5WNANtWlsz17Rm8DO9VVyE4fqmT?= =?Windows-1252?Q?OLLei+L4emEM7lgGWyGh+ia5XBc13WIgW9qbi2oB/DPv7FuvNczcXcLC?= =?Windows-1252?Q?oXVL5dfQRaDKn0YZAMKziv4KNoi/sT4/32S1Mke9zkCIdmxFB4QiaGCI?= =?Windows-1252?Q?WsqZSO6Xph9P0j0rhm60OYWaMqDHIie1ujltBQeN0qUwEv2yehH/rERo?= =?Windows-1252?Q?TfhTJ3A7hOTNoe5798F6RiQn2SNPtYPQIFSy+GW+rfsAqx6AGtqWqwJk?= =?Windows-1252?Q?Cff1yItLguw6GSI5reN2AmCyxR2qhaQiFbKob8qFL2VjTE2mt+0Va4Aj?= =?Windows-1252?Q?153+pz8r6B2vUBkBMgWR1j8iBFysrTvDVE65W6YsRf7Q8NVM2akwMARz?= =?Windows-1252?Q?mbd2im2NshMnBmSraELw/x5rVF1tSFR7XhHAgRUI2slTZGAwhnd6UvuG?= =?Windows-1252?Q?6srJ211iA/F/mUh3E1vpQFN6iBV/uWsigdm0bwElOvt8xycn3nlkU+TU?= =?Windows-1252?Q?mWtkh2NDg0IG+UOdzWjXYi5nf5w8NwMG+rxb/Xj84a3sYzdDGDQwaG7g?= =?Windows-1252?Q?g2d8SUqEC/QPvf0s43r+euAIkBnf94cZC4wGIpO3+oyDdbwGTU++gmzj?= =?Windows-1252?Q?a5qiWLOE0wLmNDIWLrIMVERWFVP2c9Cctr3e7jTZVgGMoErDVD3H0v2m?= =?Windows-1252?Q?LqDK9Pt9379J77M+bQ2A5LOZdfnqjAf/9I71aqgODj7d5XOnkFi+ZhOw?= =?Windows-1252?Q?ZxKuc1VmTE5AUAP7t9rrNMPBnPWm/OavhFwk4idO1dJFltNPVBXpTTNi?= =?Windows-1252?Q?pJjAmzujD5CVqtMAVKXjfTodb/62kfkrk1vHEjexeQxSsDgoaaHp525s?= =?Windows-1252?Q?Fdq4uJBGnCVZQ4C27MWZ80PmNJZ+kpUDZoV9/WZDGscB5euj5pI+aVXt?= =?Windows-1252?Q?SUVVraL0J3JZ1Oltvw6G6CWNSmZ/MsnHlWEL3W9URF6YxaekBKt7CQC8?= =?Windows-1252?Q?IRd3u5ejD9Gdipd5lj69UnkrUllNci3CfOGjTRsP86CiAWI+Olwl6v0X?= =?Windows-1252?Q?yOyzJk+Q/qgj3BDxL5uzWqLMcUKAQ6HAIvTLhyFUrRXxiR1LshNbVU1L?= =?Windows-1252?Q?3SsySFsL6ADJHwbCjkUy7+q2LsfGr+WLL2V83gXUqppGhjDz9krjCBpS?= =?Windows-1252?Q?xPb8SoyInliG3XaIG6fXQ+I63WuxBxue9fWltkI0c1pyPpxiHDqSJDtc?= =?Windows-1252?Q?o6ZYfd02BRVstfbdTf8uE4IjGohihjs8p6+U0gN8eCx7jALZg=3D=3D?= X-Microsoft-Exch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0o53tP4D4EDGvYcCx0TlduiFR6sKAVvDFIp3KJtVE= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Aug 2017 19:04:38.6425 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR15MB0961 X-OriginatorOrg: fb.com X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-08-19_10:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3368 Lines: 89 On 8/19/17 2:20 AM, Shubham Bansal wrote: > The JIT compiler emits ARM 32 bit instructions. Currently, It supports > eBPF only. Classic BPF is supported because of the conversion by BPF core. > > This patch is essentially changing the current implementation of JIT compiler > of Berkeley Packet Filter from classic to internal with almost all > instructions from eBPF ISA supported except the following > BPF_ALU64 | BPF_DIV | BPF_K > BPF_ALU64 | BPF_DIV | BPF_X > BPF_ALU64 | BPF_MOD | BPF_K > BPF_ALU64 | BPF_MOD | BPF_X > BPF_STX | BPF_XADD | BPF_W > BPF_STX | BPF_XADD | BPF_DW > > Implementation is using scratch space to emulate 64 bit eBPF ISA on 32 bit > ARM because of deficiency of general purpose registers on ARM. Currently, > only LITTLE ENDIAN machines are supported in this eBPF JIT Compiler. > > This patch needs to be applied after the fix from Daniel Borkmann, that is > "[net-next,v2,1/2] bpf: make htab inlining more robust wrt assumptions" > > with message ID: > 03f4e86a029058d0f674fd9bf288e55a5ec07df3.1503104831.git.daniel@iogearbox.net > > Tested on ARMv7 with QEMU by me (Shubham Bansal). > > Testing results on ARMv7: > > 1) test_bpf: Summary: 341 PASSED, 0 FAILED, [312/333 JIT'ed] > 2) test_tag: OK (40945 tests) > 3) test_progs: Summary: 30 PASSED, 0 FAILED > 4) test_lpm: OK > 5) test_lru_map: OK > > Above tests are all done with following flags enabled discreatly. > > 1) bpf_jit_enable=1 > a) CONFIG_FRAME_POINTER enabled > b) CONFIG_FRAME_POINTER disabled > 2) bpf_jit_enable=1 and bpf_jit_harden=2 > a) CONFIG_FRAME_POINTER enabled > b) CONFIG_FRAME_POINTER disabled > > See Documentation/networking/filter.txt for more information. > > Signed-off-by: Shubham Bansal impressive work. Acked-by: Alexei Starovoitov Any performance numbers with vs without JIT ? > +static const u8 bpf2a32[][2] = { > + /* return value from in-kernel function, and exit value from eBPF */ > + [BPF_REG_0] = {ARM_R1, ARM_R0}, > + /* arguments from eBPF program to in-kernel function */ > + [BPF_REG_1] = {ARM_R3, ARM_R2}, as far as i understand arm32 calling convention the mapping makes sense to me. Hard to come up with anything better than the above. > + /* function call */ > + case BPF_JMP | BPF_CALL: > + { > + const u8 *r0 = bpf2a32[BPF_REG_0]; > + const u8 *r1 = bpf2a32[BPF_REG_1]; > + const u8 *r2 = bpf2a32[BPF_REG_2]; > + const u8 *r3 = bpf2a32[BPF_REG_3]; > + const u8 *r4 = bpf2a32[BPF_REG_4]; > + const u8 *r5 = bpf2a32[BPF_REG_5]; > + const u32 func = (u32)__bpf_call_base + (u32)imm; > + > + emit_a32_mov_r64(true, r0, r1, false, false, ctx); > + emit_a32_mov_r64(true, r1, r2, false, true, ctx); > + emit_push_r64(r5, 0, ctx); > + emit_push_r64(r4, 8, ctx); > + emit_push_r64(r3, 16, ctx); > + > + emit_a32_mov_i(tmp[1], func, false, ctx); > + emit_blx_r(tmp[1], ctx); to improve the cost of call we can teach verifier to mark the registers actually used to pass arguments, so not all pushes would be needed. But it may be drop in the bucket comparing to the cost of compound 64-bit alu ops. There was some work on llvm side to use 32-bit subregisters which should help 32-bit architectures and JITs, but it didn't go far. So if you're interested further improving bpf program speeds on arm32 you may take a look at llvm side. I can certainly provide the tips.