From patchwork Thu Jan 14 09:54:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Lin X-Patchwork-Id: 12019065 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7CD4C43381 for ; Thu, 14 Jan 2021 09:56:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 91518239EB for ; Thu, 14 Jan 2021 09:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728038AbhANJzv (ORCPT ); Thu, 14 Jan 2021 04:55:51 -0500 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:55373 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726661AbhANJzr (ORCPT ); Thu, 14 Jan 2021 04:55:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1610618079; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oyzYIw7NfUmuq6pxj+o4aU3g1oORfJ4VWb8hDDDtUg4=; b=HzXFhgN4jQmWNnc8gfIktHTYEQ2a6dJK5FEm/IJi+G9qiSCZpXuKbd4UotkNDgpVdT1L+9 YZy7Upte5EEIcbp1vZ/Vw5pvejThLLwHlUnG3dxK1Y8Vd4YxZxKA1k8isid+IFRXiJlVB4 /JAimTVaw0B7srUvmmsOPCwXVYplyXI= Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-ve1eur03lp2058.outbound.protection.outlook.com [104.47.9.58]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-35-1iPPBbxuMqCSaH6Z9oNzjg-1; Thu, 14 Jan 2021 10:54:35 +0100 X-MC-Unique: 1iPPBbxuMqCSaH6Z9oNzjg-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mBjRVYzbOuUSEb7QuLeknbzw7tEwf5pIo5Vv5KfR36jwRgh0edK/oVy3kXxLtOe8E2jn3fkUQukNT5O0u+jWCYX8HcwOxfuV+R/orhxrxWJt0ilT2eVm5xApjrQLQWommCbz9L0Ys7DBZnjmWErkwAAz8N711mm1XeL9hkBhXXLbdE4nXboGu9wAXXHyR7IOKf4fVfq0Uv4bUYpfgFJLR5UQjkzphecseXGNxyLIGIJnUHl/u/OJSHSbGUO0lTXcJ6c9p5QXNFLANnwhvkfEGfQScYKqovcTyU8u1Fg2gHig6aIZ3St51O62yb+v/XsNB3f0+o7hbHUadc3Jx81Wtg== 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=8TkexveZkO32PHmHYPbwsNz9YtroAOHbKCTQzOqvGgc=; b=F18kVqlqzZcfODB54OHZASOjXSJdePYkwxSgT9W2om3rrlrrqsQR7hCY3Xovd2CjcSKFta2eIr99YqW8NTJtFqNt/FufCAOVHU7EqWgPMo2Rl5oJSlbmUw4hZtZQgKyWdb51QKM/VgYryU6I8vGq52gKt0orYTZVX1VZkKG7mUqsktpvQVdP+4tM0iJTMfPMQDif8YOAr3WxBjRAk3pUkCaTLCFLyZ+ScGx/juP+9GR4UMpcQwPRgQ8mPKTolQIbT2KGl1L2KqLg0eMNnMbqLAU5+qXuiGf05KM11iU3cUuKg1/OXEOVz21wiGydL40ie+HfRwbxJ4u/uh8Y3mhNbg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from DB3PR0402MB3641.eurprd04.prod.outlook.com (2603:10a6:8:b::12) by DBBPR04MB6153.eurprd04.prod.outlook.com (2603:10a6:10:d2::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.12; Thu, 14 Jan 2021 09:54:33 +0000 Received: from DB3PR0402MB3641.eurprd04.prod.outlook.com ([fe80::80c9:1fa3:ae84:7313]) by DB3PR0402MB3641.eurprd04.prod.outlook.com ([fe80::80c9:1fa3:ae84:7313%6]) with mapi id 15.20.3763.011; Thu, 14 Jan 2021 09:54:33 +0000 From: Gary Lin To: netdev@vger.kernel.org, bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann CC: Eric Dumazet , Andrii Nakryiko , andreas.taschner@suse.com Subject: [PATCH v3 1/3] bpf,x64: pad NOPs to make images converge more easily Date: Thu, 14 Jan 2021 17:54:09 +0800 Message-ID: <20210114095411.20903-2-glin@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210114095411.20903-1-glin@suse.com> References: <20210114095411.20903-1-glin@suse.com> X-Originating-IP: [111.240.145.171] X-ClientProxiedBy: AM0PR10CA0111.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:e6::28) To DB3PR0402MB3641.eurprd04.prod.outlook.com (2603:10a6:8:b::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from GaryLaptop.prv.suse.net (111.240.145.171) by AM0PR10CA0111.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:e6::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9 via Frontend Transport; Thu, 14 Jan 2021 09:54:30 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ab824e8a-66d9-4a33-51f3-08d8b87264d1 X-MS-TrafficTypeDiagnostic: DBBPR04MB6153: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ANGDXzuJLyLAUaeZ2G1uabH/c2J15VSI6KUfNiAVXBrUVBOjTmDhOCboxofDzmcxkLa2ZZmDEy3zY97GidXwEIOGpG2w0t+D3J68AR30BgkHu6K5smM6mj3EMG2LkNBVnTudnLnKm3CbmMuG5SrOr/axSV7T8d2f7nMwq9ukE1YSkDlh9Sp6rapr+tAk+oxM3GV3baOPsOU3tYBaHFUiqrp6HM7cgwkngzXVQEWAsWbBQl0t4fGGaS+eWzRAjFC1/pfRS+U1pE0yXlP9+F63j8YrPi13JsenJkRWnsx0+xT5bjov0jCcXmpFxjQRMYhT2+13cx/vVuCjJj6sADSE7Ztq2IPrSndb+qtdVRW5I2ktNnEVL4eWNmalOLFcA33zTiXJgRWyboHY/yVqi1wTgw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB3PR0402MB3641.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(376002)(346002)(396003)(39860400002)(366004)(316002)(83380400001)(1076003)(6486002)(2906002)(478600001)(52116002)(8676002)(5660300002)(186003)(110136005)(4326008)(107886003)(36756003)(6666004)(8936002)(16526019)(6506007)(66946007)(6512007)(956004)(26005)(2616005)(66476007)(54906003)(86362001)(66556008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 7EA44FT2djXAPCcbCL4DuBWVbClHPMGe1tTf2Hm7pIQO1BREemVqTCPX/RE3CvDc98I2/IsPmargA7XHbBQbxzg/UjuGWpi3WRkXmgvcdk16AVILMs5IbjTCOz3un4Pi0RY2UpxtSeynpo0oqkQery1VF0fSeMs+CTciv67c0VubdgjT6IBKLupEljL6LeBItJsu6gZWDFyBNV2VWnGkOqjT09DhcglbUHL+0aBIUZA22J3Q4CFOCm9ydIsLsYPma1NxJxQcgacz6uM/XCQDETGFxtu/pvVEsI0q0dJx/GdG6MvXHtK6EJF3YMwvVeXHW94aP4snmV+7Tfe9f7mH2otCpxlOfgvqs10ynXvhZ5DOuEtfojkSwXSP7T5uwK8M67I2ZuIehXo/F/lj1PpTUU7crmntqnqUlmYpuf6WYa4TjiyvDaDNLe6AlSQQOk74jkxusfpLLRijJUUkUzG1L+F00uxhGsIh5RSWMZjBbaSp22kO1uJoP7nH3sR3VRxD/sD2vzKrCoWlewYB5yFPPt5PONTpv/VtccuvYbjbe8cJCR3bDQSqsiGDtwdgg9wyYspqBqkidLTugvmOFrRE1mXSM2HS4oYOnOOUMlfLD/G/K9xuZbKgQZmSNiCxNLFjlwxJacJ7+Jhkdydj9PdZuTqF0iLOWSvZs4aaesmBAPL2IErx8OUo+eef2OzeihIo/xVJdbfCHlNnm0zJ4GoiBxwHq8bumjGJJmEA+jeOIqGhaJrSw1mZ7muECBtvxtE8eqwj8pPUMBuR2klWLm48W33gluHzbTfT8G2eBT7vRYgb8rJ04mRfxvb+EIlBTrFvQiX1Prd1kbuFL9ZlEeYkm2lxtWBGGHnWn5ijMuBo0ykZMYmGeHf0UovRqRZ04z4+N/9P+Owv1K/M8LM0PVhV9gPU7/u5C1kcnDdjz1sISBaPu8GxPZ8yuXhOekfYXxSC5C6UbwWuu1+RaiodgKNjHgIgGkZV6iW1durUFmxB88TjvMiGFOkb4zqkelmlWXwa X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-AuthSource: DB3PR0402MB3641.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2021 09:54:32.9747 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-Network-Message-Id: ab824e8a-66d9-4a33-51f3-08d8b87264d1 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cfsE9/KmUSw+Y7HkHL3FAOXQN9yb46gfcSWyZdpoMS01MalaTVai+dEy/IS1EY8F X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB6153 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The x64 bpf jit expects bpf images converge within the given passes, but it could fail to do so with some corner cases. For example: l0: ja 40 l1: ja 40 [... repeated ja 40 ] l39: ja 40 l40: ret #0 This bpf program contains 40 "ja 40" instructions which are effectively NOPs and designed to be replaced with valid code dynamically. Ideally, bpf jit should optimize those "ja 40" instructions out when translating the bpf instructions into x64 machine code. However, do_jit() can only remove one "ja 40" for offset==0 on each pass, so it requires at least 40 runs to eliminate those JMPs and exceeds the current limit of passes(20). In the end, the program got rejected when BPF_JIT_ALWAYS_ON is set even though it's legit as a classic socket filter. To make bpf images more likely converge within 20 passes, this commit pads some instructions with NOPs in the last 5 passes: 1. conditional jumps A possible size variance comes from the adoption of imm8 JMP. If the offset is imm8, we calculate the size difference of this BPF instruction between the previous and the current pass and fill the gap with NOPs. To avoid the recalculation of jump offset, those NOPs are inserted before the JMP code, so we have to subtract the 2 bytes of imm8 JMP when calculating the NOP number. 2. BPF_JA There are two conditions for BPF_JA. a.) nop jumps If this instruction is not optimized out in the previous pass, instead of removing it, we insert the equivalent size of NOPs. b.) label jumps Similar to condition jumps, we prepend NOPs right before the JMP code. To make the code concise, emit_nops() is modified to use the signed len and return the number of inserted NOPs. For bpf-to-bpf, we always enable padding for the extra pass since there is only one extra run and the jump padding doesn't affected the images that converge without padding. After applying this patch, the corner case was loaded with the following jit code: flen=45 proglen=77 pass=17 image=ffffffffc03367d4 from=jump pid=10097 JIT code: 00000000: 0f 1f 44 00 00 55 48 89 e5 53 41 55 31 c0 45 31 JIT code: 00000010: ed 48 89 fb eb 30 eb 2e eb 2c eb 2a eb 28 eb 26 JIT code: 00000020: eb 24 eb 22 eb 20 eb 1e eb 1c eb 1a eb 18 eb 16 JIT code: 00000030: eb 14 eb 12 eb 10 eb 0e eb 0c eb 0a eb 08 eb 06 JIT code: 00000040: eb 04 eb 02 66 90 31 c0 41 5d 5b c9 c3 0: 0f 1f 44 00 00 nop DWORD PTR [rax+rax*1+0x0] 5: 55 push rbp 6: 48 89 e5 mov rbp,rsp 9: 53 push rbx a: 41 55 push r13 c: 31 c0 xor eax,eax e: 45 31 ed xor r13d,r13d 11: 48 89 fb mov rbx,rdi 14: eb 30 jmp 0x46 16: eb 2e jmp 0x46 ... 3e: eb 06 jmp 0x46 40: eb 04 jmp 0x46 42: eb 02 jmp 0x46 44: 66 90 xchg ax,ax 46: 31 c0 xor eax,eax 48: 41 5d pop r13 4a: 5b pop rbx 4b: c9 leave 4c: c3 ret At the 16th pass, 15 jumps were already optimized out, and one jump was replaced with NOPs at 44 and the image converged at the 17th pass. v3: - Copy the instructions of prologue separately or the size calculation of the first BPF instruction would include the prologue. - Replace WARN_ONCE() with pr_err() and EFAULT - Use MAX_PASSES in the for loop condition check - Remove the "padded" flag from x64_jit_data. For the extra pass of subprogs, padding is always enabled since it won't hurt the images that converge without padding. v2: - Simplify the sample code in the description and provide the jit code - Check the expected padding bytes with WARN_ONCE - Move the 'padded' flag to 'struct x64_jit_data' Signed-off-by: Gary Lin --- arch/x86/net/bpf_jit_comp.c | 103 ++++++++++++++++++++++++++---------- 1 file changed, 75 insertions(+), 28 deletions(-) diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index 796506dcfc42..bb36f4117e9b 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -789,8 +789,31 @@ static void detect_reg_usage(struct bpf_insn *insn, int insn_cnt, } } +static int emit_nops(u8 **pprog, int len) +{ + u8 *prog = *pprog; + int i, noplen, cnt = 0; + + while (len > 0) { + noplen = len; + + if (noplen > ASM_NOP_MAX) + noplen = ASM_NOP_MAX; + + for (i = 0; i < noplen; i++) + EMIT1(ideal_nops[noplen][i]); + len -= noplen; + } + + *pprog = prog; + + return cnt; +} + +#define INSN_SZ_DIFF (((addrs[i] - addrs[i - 1]) - (prog - temp))) + static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, - int oldproglen, struct jit_context *ctx) + int oldproglen, struct jit_context *ctx, bool jmp_padding) { bool tail_call_reachable = bpf_prog->aux->tail_call_reachable; struct bpf_insn *insn = bpf_prog->insnsi; @@ -800,7 +823,7 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, bool seen_exit = false; u8 temp[BPF_MAX_INSN_SIZE + BPF_INSN_SAFETY]; int i, cnt = 0, excnt = 0; - int proglen = 0; + int ilen, proglen = 0; u8 *prog = temp; detect_reg_usage(insn, insn_cnt, callee_regs_used, @@ -813,7 +836,13 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, bpf_prog_was_classic(bpf_prog), tail_call_reachable, bpf_prog->aux->func_idx != 0); push_callee_regs(&prog, callee_regs_used); - addrs[0] = prog - temp; + + ilen = prog - temp; + if (image) + memcpy(image + proglen, temp, ilen); + proglen += ilen; + addrs[0] = proglen; + prog = temp; for (i = 1; i <= insn_cnt; i++, insn++) { const s32 imm32 = insn->imm; @@ -822,8 +851,8 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, u8 b2 = 0, b3 = 0; s64 jmp_offset; u8 jmp_cond; - int ilen; u8 *func; + int nops; switch (insn->code) { /* ALU */ @@ -1409,6 +1438,15 @@ xadd: if (is_imm8(insn->off)) } jmp_offset = addrs[i + insn->off] - addrs[i]; if (is_imm8(jmp_offset)) { + if (jmp_padding) { + nops = INSN_SZ_DIFF - 2; + if (nops != 0 && nops != 4) { + pr_err("unexpected cond_jmp padding: %d bytes\n", + nops); + return -EFAULT; + } + cnt += emit_nops(&prog, nops); + } EMIT2(jmp_cond, jmp_offset); } else if (is_simm32(jmp_offset)) { EMIT2_off32(0x0F, jmp_cond + 0x10, jmp_offset); @@ -1431,11 +1469,33 @@ xadd: if (is_imm8(insn->off)) else jmp_offset = addrs[i + insn->off] - addrs[i]; - if (!jmp_offset) - /* Optimize out nop jumps */ + if (!jmp_offset) { + /* + * If jmp_padding is enabled, the extra nops will + * be inserted. Otherwise, optimize out nop jumps. + */ + if (jmp_padding) { + nops = INSN_SZ_DIFF; + if (nops != 0 && nops != 2 && nops != 5) { + pr_err("unexpected nop jump padding: %d bytes\n", + nops); + return -EFAULT; + } + cnt += emit_nops(&prog, nops); + } break; + } emit_jmp: if (is_imm8(jmp_offset)) { + if (jmp_padding) { + nops = INSN_SZ_DIFF - 2; + if (nops != 0 && nops != 3) { + pr_err("unexpected jump padding: %d bytes\n", + nops); + return -EFAULT; + } + cnt += emit_nops(&prog, INSN_SZ_DIFF - 2); + } EMIT2(0xEB, jmp_offset); } else if (is_simm32(jmp_offset)) { EMIT1_off32(0xE9, jmp_offset); @@ -1578,26 +1638,6 @@ static int invoke_bpf_prog(const struct btf_func_model *m, u8 **pprog, return 0; } -static void emit_nops(u8 **pprog, unsigned int len) -{ - unsigned int i, noplen; - u8 *prog = *pprog; - int cnt = 0; - - while (len > 0) { - noplen = len; - - if (noplen > ASM_NOP_MAX) - noplen = ASM_NOP_MAX; - - for (i = 0; i < noplen; i++) - EMIT1(ideal_nops[noplen][i]); - len -= noplen; - } - - *pprog = prog; -} - static void emit_align(u8 **pprog, u32 align) { u8 *target, *prog = *pprog; @@ -1972,6 +2012,9 @@ struct x64_jit_data { struct jit_context ctx; }; +#define MAX_PASSES 20 +#define PADDING_PASSES (MAX_PASSES - 5) + struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) { struct bpf_binary_header *header = NULL; @@ -1981,6 +2024,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) struct jit_context ctx = {}; bool tmp_blinded = false; bool extra_pass = false; + bool padding = false; u8 *image = NULL; int *addrs; int pass; @@ -2017,6 +2061,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) image = jit_data->image; header = jit_data->header; extra_pass = true; + padding = true; goto skip_init_addrs; } addrs = kmalloc_array(prog->len + 1, sizeof(*addrs), GFP_KERNEL); @@ -2042,8 +2087,10 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) * may converge on the last pass. In such case do one more * pass to emit the final image. */ - for (pass = 0; pass < 20 || image; pass++) { - proglen = do_jit(prog, addrs, image, oldproglen, &ctx); + for (pass = 0; pass < MAX_PASSES || image; pass++) { + if (!padding && pass >= PADDING_PASSES) + padding = true; + proglen = do_jit(prog, addrs, image, oldproglen, &ctx, padding); if (proglen <= 0) { out_image: image = NULL; From patchwork Thu Jan 14 09:54:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Lin X-Patchwork-Id: 12019063 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F352DC433E9 for ; Thu, 14 Jan 2021 09:56:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ACBC523A21 for ; Thu, 14 Jan 2021 09:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727274AbhANJzu (ORCPT ); Thu, 14 Jan 2021 04:55:50 -0500 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:22394 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728038AbhANJzr (ORCPT ); Thu, 14 Jan 2021 04:55:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1610618080; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7BKY15wF8aOwZdw6Jwti1+pccpFTzL/UrLD9CYYjYVo=; b=WWB53pLiBWVwi9Eg4BZThiNa6mpi69PtNcP/ZrIjYC8kP/8Z7kX8A7eIbC8g/7vgWYAiDI Cfgtqq7Mt8cmS5beSLC2rvdcC9PiFs2XILdx2AFwbfk6MYq+2tHUjFTSG30Yg3VfEkZgK2 2kUXTDHI6X1YYZOk7mA/lxCO3BCZmn0= Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-ve1eur03lp2058.outbound.protection.outlook.com [104.47.9.58]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-35-Ghh6-pguNtWOlCPwo3LU2Q-2; Thu, 14 Jan 2021 10:54:39 +0100 X-MC-Unique: Ghh6-pguNtWOlCPwo3LU2Q-2 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gJC+fXa/KPOMiI9PlwESLbL7thjF3oW1EW7eUj+tfl6X32yLMR0cBMlD4kGKQh4AONNv5i7P7aZp81F0uX2SwjMtSBqRPlaOOlcO9jtDSunrSw8Iz49MbqfMlY3Ev2oVaX//iL1tzFnzLLNjfNzcPCL7GPVeLrDny2LjYgK9iXTPuN0dFcs8VnhgeWQ5RU/Z7qMmR9yw9HfCsRVI+3oZye7OqUp2C8XnDyxjdkdaCJ+x5vg4oG1J3VXqjPggJYnctqfSC+J5g5clZd2EK5ns2H2iNn6aR8JFKotQhIUUD1h5NnwaXr5wAd1uiz47RELJN3oFvuJtbteT4bDxPayMSg== 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=EtGbxeFGd5wrf0vUZRAXq5W++Pi5doTWbZ4QJ2ST5mA=; b=dyZ5F8FaE00oMmrinYwmN/DDaWTQ/GXjNTAjXG4N0sKaasZRVit2W9wOg1tORwTRcJsI11miQ5+CkeXmzhGK/uDIKbVBXvjGqxgNU7XGrlGFPk9k0o8vU2gle/FufoyO7Az46kP6Pw+IQTGZ6A4PxdaYzTfdlqrsygG6zd2DIjQdkrHOmp7wASKFfCUyXH88i4UNw6BLeV9KJXbSVmiIy/klOgKQN109JKfcEydAgCrQWVHpuRK4TqMI+qL3wxTj9Tg0e5GAiQkgoqQe9SWjjXgHUod7kinGXcWBXfbET+SnaS0mUze29OFRhThD+zMHvlqYgUdXmmxwcpdwxfSN3Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from DB3PR0402MB3641.eurprd04.prod.outlook.com (2603:10a6:8:b::12) by DBBPR04MB6153.eurprd04.prod.outlook.com (2603:10a6:10:d2::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.12; Thu, 14 Jan 2021 09:54:35 +0000 Received: from DB3PR0402MB3641.eurprd04.prod.outlook.com ([fe80::80c9:1fa3:ae84:7313]) by DB3PR0402MB3641.eurprd04.prod.outlook.com ([fe80::80c9:1fa3:ae84:7313%6]) with mapi id 15.20.3763.011; Thu, 14 Jan 2021 09:54:35 +0000 From: Gary Lin To: netdev@vger.kernel.org, bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann CC: Eric Dumazet , Andrii Nakryiko , andreas.taschner@suse.com Subject: [PATCH v3 2/3] test_bpf: remove EXPECTED_FAIL flag from bpf_fill_maxinsns11 Date: Thu, 14 Jan 2021 17:54:10 +0800 Message-ID: <20210114095411.20903-3-glin@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210114095411.20903-1-glin@suse.com> References: <20210114095411.20903-1-glin@suse.com> X-Originating-IP: [111.240.145.171] X-ClientProxiedBy: AM0PR10CA0111.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:e6::28) To DB3PR0402MB3641.eurprd04.prod.outlook.com (2603:10a6:8:b::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from GaryLaptop.prv.suse.net (111.240.145.171) by AM0PR10CA0111.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:e6::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9 via Frontend Transport; Thu, 14 Jan 2021 09:54:33 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7c57fced-c0f3-4ddb-ccc5-08d8b8726681 X-MS-TrafficTypeDiagnostic: DBBPR04MB6153: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1284; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oYtwp3Oiun8806eBPcyX3Es2oPmt3TK93vw77TRxNRVHcDrI8StdbJpfyPfhuZCaSFxG1BhzFTqBLmNXD/eJgac+SlCiuMYCHNvI5Qh+1HWJNQ3e6Bjs7j9AvVI2hzO4oNQ1izXh30JHbI5g9CdwnUT0+b85zanYXLyDe6hx+g8PYAYtJFS/fEBm+/ZBNhcC0qWN3uaHf0jhNqVbgN3ReYDEpX0F7AJ3pdBkcEEJG8mR2iYcgOsVVGdoUYImOV5NlpEaXgq9FSnG1Ja0y6fIfEAY16HiXGcospUFc2OfQl621R0xn7B5Ffj8mWsGXPwW1N8SkjwGCTiHv/FsqI7BnddcktsQ66Pty8Ftm8Pa2JasLqrTWNg3S/rw7mcqLisJzhx9TjbOfcJWO15YGF5LgQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB3PR0402MB3641.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(376002)(346002)(396003)(39860400002)(366004)(316002)(83380400001)(1076003)(6486002)(2906002)(478600001)(52116002)(8676002)(5660300002)(186003)(110136005)(4326008)(107886003)(36756003)(6666004)(8936002)(16526019)(6506007)(66946007)(6512007)(956004)(26005)(2616005)(66476007)(54906003)(86362001)(66556008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: vQAu3ZZ4xImlRhUAuE/rJO7tJq3Xy4kiAUUkRGTeStRa/4arrvQ07zxIlmF1Vh+e8VLs//6fb41CjEZP30VB2tBBfr5OuTsPUZo/CVLmx5llS37a2tUwHgwLxWHI6tvg945r9zUDkMn8N9BqWlW3xSgfkDCMvOHwAuTPM218P5sZTz0YaYTxYRuVZ2mYfmpqyFqQOoExTWQM1ATrpxS21Sp85LTRrunouww2gImBppr/EVCNqwnKvVfRJ8j6mSKFhQISDcitROcHDADUuAjMfNjzqwCkVj5Lg4n3jAPAhy5s0hesZDDEhdjZHtzh0yTRVRHhwNwhCdJsIc/W296eZkpdEY8JokyevxueZ4h4oB57p46UcyipO6rOUdeO38wxEVtKsxjAdtDjxlyB2mrRk84vrbNSyQa0AplVx7c3yC+EP6d3lggDMyXBlEeiQtzzJV2DmGWaVfjyc1hJ63lV5hAV3/aOaETN21rdCiQ/0e03JtjDw4F84tgPsTdHQU1I0R6cfyE5Z3VvKTtLQScl11num3yxoZy0ntF638owUQD5n/EEVsaIFvkVY5i/HnTFZSK/ojhPejf4SJKOvx66dFslJ9ueq5DZm3JdrmlRSFGyAAcZ12qGQHOIoAk1qwyZKkFb8zl8t0c3qDGdR7zOpm2fRPw4KwtGaqMegDF0uJmnVbYG9ocwGgGpIenebEghT4eolQF8kA5HqH/ROAmCDIzWZs7lVGaigCsATdvZzbxGcmDyNh3AF5VCg6zHHO3Z2OGOMfvNXhpa97Cg8j1FWDZP4KgsMOiXamxCkYNCOdYv6kI0ppYvCGEKXaRl86X6oFnPLgR+r91RjOEHJDFfhyd3Hprcu4OUNtyrss23mJMM05tS40CTRJqEqqB/RuWyItvwpjlaWAN3Y3z8S46ZwY2WifYkNRuU36of3coEO4myHq8CC7W8fVc0+ysbVV6GjufThdr/YhvycPKM+jASe9bnG+vVpRuWJmpyIVYn4BC1hVrbhjm7M+5DRvZj6LIw X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-AuthSource: DB3PR0402MB3641.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2021 09:54:35.7281 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-Network-Message-Id: 7c57fced-c0f3-4ddb-ccc5-08d8b8726681 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: oWL6dcT6qRUIaqziicw2+CGECE9hKjbGa+uupnK0z4uI6Bm+9varsAAwlUCEgH56 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB6153 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net With NOPs padding, x64 jit now can handle the jump cases like bpf_fill_maxinsns11(). Signed-off-by: Gary Lin --- lib/test_bpf.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/test_bpf.c b/lib/test_bpf.c index ca7d635bccd9..272a9fd143ab 100644 --- a/lib/test_bpf.c +++ b/lib/test_bpf.c @@ -345,7 +345,7 @@ static int __bpf_fill_ja(struct bpf_test *self, unsigned int len, static int bpf_fill_maxinsns11(struct bpf_test *self) { - /* Hits 70 passes on x86_64, so cannot get JITed there. */ + /* Hits 70 passes on x86_64 and triggers NOPs padding. */ return __bpf_fill_ja(self, BPF_MAXINSNS, 68); } @@ -5318,15 +5318,10 @@ static struct bpf_test tests[] = { { "BPF_MAXINSNS: Jump, gap, jump, ...", { }, -#if defined(CONFIG_BPF_JIT_ALWAYS_ON) && defined(CONFIG_X86) - CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, -#else CLASSIC | FLAG_NO_DATA, -#endif { }, { { 0, 0xababcbac } }, .fill_helper = bpf_fill_maxinsns11, - .expected_errcode = -ENOTSUPP, }, { "BPF_MAXINSNS: jump over MSH", From patchwork Thu Jan 14 09:54:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Lin X-Patchwork-Id: 12019067 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E18FC433E0 for ; Thu, 14 Jan 2021 09:56:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 662CE23A21 for ; Thu, 14 Jan 2021 09:56:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728352AbhANJzw (ORCPT ); Thu, 14 Jan 2021 04:55:52 -0500 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:51259 "EHLO de-smtp-delivery-102.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726551AbhANJzu (ORCPT ); Thu, 14 Jan 2021 04:55:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1610618081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hyrYqRtTXMHSyqoUwmKQEUTSYec7i3mrrG1VEpyCw98=; b=TJdzrI29mTLdP4YgZyHOslJlGyXcZrDDe6PUOgc5bYe77Cnr1izIeYc0sTUNtpzXsdfs90 RYuE2f1IKq1LKfPTAfObBr8ToeggpDISjCYdaLKFNmUWjlwwiUXfSy1Gb9V6Qx6Qqkyz5W eiOLwCMg1Rs4g/1nw5p2rEOc2o6O26Q= Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2057.outbound.protection.outlook.com [104.47.13.57]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-1-xTsiowqBPIq9eRA1HRLM0A-1; Thu, 14 Jan 2021 10:54:40 +0100 X-MC-Unique: xTsiowqBPIq9eRA1HRLM0A-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=etjIhXPFP/+DT2R/IMsNxaEUtxbSEcit851a8O+IMID5nlR+sBE3L0+G1j7GUF0kuZwfg1E4itv1XTkAjC3OiwGXzFhHRvY5e93CE/Ik/W5BnSQu0JPfoWy6Cu2MkiMzUMgbDGFlFtltGvdwSZ+wM728KbrQLE1sdGbbGAjenogrGuhQ6qH3IK+hBjAQknLVzcBXhYEkvVDLJT7nFcMJwHyWtLrLox0x6+CMnRoYV1Vyy1l69DCxrdapXuUXRg/yhhBLDsW1UmyUhOm2vPherJFXjjv/FLeNgGV+SyKtNQY9gb0JkCXG1HIzqLjJiRwH9TRKutRwJqdk44thKFZUbA== 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=BfsH9zmb27Cp6M9alTjweF2YknHyXXP5e6uFAYUAYj8=; b=GwVToAE0nsRQzAMJfxsn3kC5awlirK9GN4wMK9zQ/cmhwJLHylgELLaRrAI66mOR57RVjr3o5We5Wu1kV2oZ68I2E5g1hV7qRvll9txnhP2yB2zhEVazaqheu1eSictEx0TVEpN2pV/1XVIFwhaZXZvm7nxSpqvI2jVxK+qnEJsYuT+0HYvNpxHhBnqqly6FXOdr23eI1miWqnpjoP0aUJ4VBkTQHV4gynzMPumoEzRJKddnkuwIM7ZVK5bCSszlRbxZx9oGEgYI/hpcV55Apmyx23yzO5u0z58U0g82vtErBbuRWS69+EyIwtKr7I6ZoQWRB5d1PsOfEce8NvF3Rw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=suse.com; Received: from DB3PR0402MB3641.eurprd04.prod.outlook.com (2603:10a6:8:b::12) by DBBPR04MB6156.eurprd04.prod.outlook.com (2603:10a6:10:cd::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9; Thu, 14 Jan 2021 09:54:38 +0000 Received: from DB3PR0402MB3641.eurprd04.prod.outlook.com ([fe80::80c9:1fa3:ae84:7313]) by DB3PR0402MB3641.eurprd04.prod.outlook.com ([fe80::80c9:1fa3:ae84:7313%6]) with mapi id 15.20.3763.011; Thu, 14 Jan 2021 09:54:38 +0000 From: Gary Lin To: netdev@vger.kernel.org, bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann CC: Eric Dumazet , Andrii Nakryiko , andreas.taschner@suse.com Subject: [PATCH v3 3/3] selftests/bpf: Add verifier test for x64 jit jump padding Date: Thu, 14 Jan 2021 17:54:11 +0800 Message-ID: <20210114095411.20903-4-glin@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210114095411.20903-1-glin@suse.com> References: <20210114095411.20903-1-glin@suse.com> X-Originating-IP: [111.240.145.171] X-ClientProxiedBy: AM0PR10CA0111.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:e6::28) To DB3PR0402MB3641.eurprd04.prod.outlook.com (2603:10a6:8:b::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from GaryLaptop.prv.suse.net (111.240.145.171) by AM0PR10CA0111.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:e6::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.9 via Frontend Transport; Thu, 14 Jan 2021 09:54:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e368f792-f7bf-4788-899e-08d8b8726826 X-MS-TrafficTypeDiagnostic: DBBPR04MB6156: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2u0f8mxeHNdOIgaXvqVx1jmfRXCwIIhFgIPrScIuMtZaxul6jQa0q4tA6vNIJZRuBewcL7W2oLAhpTAhczW6nTqz2FhA540sk3XhLo19MEv/5OOtWUgA7Atjfi9N2hZpVwH2DjjKwpMtoF4nScGkhL37GzTQE9zXm/NsZsDw2cRyryQ91r5BLWAGZ9VrDgSl+Bs6b11esF+KTE8rYuotHabazLVTVhjmvdCKYfKNXWiqZ9hfmTluDZK1YD8XWNKiC5aW8PU4hhiZ/ITkVCkonomm3fl/R1je7RgDrrRElILAGbOyznIml4hYYvPEV01TVk22S6DEaJYX8ad2pgWKau1MeFzXKi9nlA3uSmy4al1PY8/sf4lK/E9Yx4j4ZcdM X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB3PR0402MB3641.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(346002)(39860400002)(366004)(396003)(376002)(136003)(1076003)(66946007)(186003)(6506007)(5660300002)(86362001)(2906002)(4326008)(66476007)(66556008)(16526019)(2616005)(956004)(6512007)(316002)(52116002)(6486002)(478600001)(54906003)(110136005)(36756003)(8676002)(26005)(107886003)(6666004)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Ie9JPWxgqhIoacDcBfDUGtbyqmK12rZhFjaki+S6ysYAsSVJEYi729KfOXsRjNA8Tqv8yXxd7/MYIVgxtBGNFN6dba6qkxOUBja1ygxoEyzbGJYm/kW8uIacri1PsII7HUWDAnF8d17CHKfE92foiQ5Vo1Z2lbe3hYrTvOuDtlHDrPpCXbHyoBnsdrEnN7w9TPPMus7qz5j/Y5TMf+S1UnyTsZxJcS46QS79r38MHcYwojuXjKTofU6QIySxU0WWrQoESspX5QBV9evu7f2ZCksecHLN2t3Qx23W6ZWe1uNNF/FWq+isW1kXdsgzVszki2j36pe84Y8+u62ehbtf6QAyiPfF19oWpnQvtXU0HH4mi48/WO49JPy8wMeR12d8HmCjA896k6MQPf3phfmX4TJzN429zhpOsFG9uhWwVZ8mSPYkhxhFL7879u9H96ZJwCTzEExeMV7etPuDo1f8VevFooCugs9uEoghiS3PBHVGlodCTXr0/MtrTawDTBsYcFfxqYq2WBzzb/A+tqRFnwsHUxqqtGZoRIZldO6mewFydpscQJbOMfucMk8sJ8C+fc4nVEgxvRDlKMz6no2oUIPsK2VNJ03KUDAAC0R9Yk4uxvF8a88UPmdkpHyLwxM1Ak80p6DhiG2AFcTNGwRHW/x3GH7y7SxcCPhlFfrok8RXdZcGVfXJvgilY0B+XU0+K3k6XHah4rYNO95xTnvT2W2Duh9wiFsLcazI+LBzKFE8EC7zdqZY+XI1alklCBQPn7NS9RqaOkqmDAfHaD1/EAcUTSxS9YPYtNkqamfdfByxOs+cPE1I1As5K9loLAt7RvFirL8Y3oQRvo5n0qdMiT4f+1fC3Z7x/QllojGFlFlSsddws05bkh0fHCDTJhHhG6hhxhw+cW/51ZzhFaknpx97z5X1W3YI7NzGrpNqtopsS7QWPEeiCRcjr7jFQVZNK+u4o61k7JEQD67aE2mF1miLZ6ihvWijDzeOpCq96n4KoJz9Icq1/dhvhNMvZQGY X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-AuthSource: DB3PR0402MB3641.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2021 09:54:38.5234 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-Network-Message-Id: e368f792-f7bf-4788-899e-08d8b8726826 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: GDvqt3/ulJ/fNcdvAOGzJe+3bOg3YyFJPGUvHtcQwMdyrzmW14DEC6Qt5ZZ04rur X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB6156 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net There are two tests added into verifier's jit tests to trigger x64 jit jump padding. The first test can be represented as the following assembly code: 1: bpf_call bpf_get_prandom_u32 2: if r0 == 0 goto pc+128 3: if r0 == 1 goto pc+128 ... 129: if r0 == 127 goto pc+128 130: goto pc+128 131: goto pc+127 ... 256: goto pc+1 257: goto pc+0 258: r0 = 1 259: ret We first store a random number to r0 and add the corresponding conditional jumps (2~129) to make verifier believe that those jump instructions from 130 to 257 are reachable. When the program is sent to x64 jit, it starts to optimize out the NOP jumps backwards from 257. Since there are 128 such jumps, the program easily reaches 15 passes and triggers jump padding. Here is the x64 jit code of the first test: 0: 0f 1f 44 00 00 nop DWORD PTR [rax+rax*1+0x0] 5: 66 90 xchg ax,ax 7: 55 push rbp 8: 48 89 e5 mov rbp,rsp b: e8 4c 90 75 e3 call 0xffffffffe375905c 10: 48 83 f8 01 cmp rax,0x1 14: 0f 84 fe 04 00 00 je 0x518 1a: 48 83 f8 02 cmp rax,0x2 1e: 0f 84 f9 04 00 00 je 0x51d ... f6: 48 83 f8 18 cmp rax,0x18 fa: 0f 84 8b 04 00 00 je 0x58b 100: 48 83 f8 19 cmp rax,0x19 104: 0f 84 86 04 00 00 je 0x590 10a: 48 83 f8 1a cmp rax,0x1a 10e: 0f 84 81 04 00 00 je 0x595 ... 500: 0f 84 83 01 00 00 je 0x689 506: 48 81 f8 80 00 00 00 cmp rax,0x80 50d: 0f 84 76 01 00 00 je 0x689 513: e9 71 01 00 00 jmp 0x689 518: e9 6c 01 00 00 jmp 0x689 ... 5fe: e9 86 00 00 00 jmp 0x689 603: e9 81 00 00 00 jmp 0x689 608: 0f 1f 00 nop DWORD PTR [rax] 60b: eb 7c jmp 0x689 60d: eb 7a jmp 0x689 ... 683: eb 04 jmp 0x689 685: eb 02 jmp 0x689 687: 66 90 xchg ax,ax 689: b8 01 00 00 00 mov eax,0x1 68e: c9 leave 68f: c3 ret As expected, a 3 bytes NOPs is inserted at 608 due to the transition from imm32 jmp to imm8 jmp. A 2 bytes NOPs is also inserted at 687 to replace a NOP jump. The second test is to invoke the first test as a subprog to test bpf2bpf. Per the system log, there was one more jit happened with only one pass and the same jit code was produced. Signed-off-by: Gary Lin --- tools/testing/selftests/bpf/test_verifier.c | 43 +++++++++++++++++++++ tools/testing/selftests/bpf/verifier/jit.c | 16 ++++++++ 2 files changed, 59 insertions(+) diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index 9be395d9dc64..0671e88bc15d 100644 --- a/tools/testing/selftests/bpf/test_verifier.c +++ b/tools/testing/selftests/bpf/test_verifier.c @@ -296,6 +296,49 @@ static void bpf_fill_scale(struct bpf_test *self) } } +static int bpf_fill_torturous_jumps_insn(struct bpf_insn *insn) +{ + unsigned int len = 259, hlen = 128; + int i; + + insn[0] = BPF_EMIT_CALL(BPF_FUNC_get_prandom_u32); + for (i = 1; i <= hlen; i++) { + insn[i] = BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, i, hlen); + insn[i + hlen] = BPF_JMP_A(hlen - i); + } + insn[len - 2] = BPF_MOV64_IMM(BPF_REG_0, 1); + insn[len - 1] = BPF_EXIT_INSN(); + + return len; +} + +static void bpf_fill_torturous_jumps(struct bpf_test *self) +{ + struct bpf_insn *insn = self->fill_insns; + int i = 0; + + switch (self->retval) { + case 1: + self->prog_len = bpf_fill_torturous_jumps_insn(insn); + return; + case 2: + /* main */ + insn[i++] = BPF_RAW_INSN(BPF_JMP|BPF_CALL, 0, 1, 0, 3); + insn[i++] = BPF_ST_MEM(BPF_B, BPF_REG_10, -32, 0); + insn[i++] = BPF_MOV64_IMM(BPF_REG_0, 2); + insn[i++] = BPF_EXIT_INSN(); + + /* subprog */ + i += bpf_fill_torturous_jumps_insn(insn + i); + + self->prog_len = i; + return; + default: + self->prog_len = 0; + break; + } +} + /* BPF_SK_LOOKUP contains 13 instructions, if you need to fix up maps */ #define BPF_SK_LOOKUP(func) \ /* struct bpf_sock_tuple tuple = {} */ \ diff --git a/tools/testing/selftests/bpf/verifier/jit.c b/tools/testing/selftests/bpf/verifier/jit.c index c33adf344fae..b7653a334497 100644 --- a/tools/testing/selftests/bpf/verifier/jit.c +++ b/tools/testing/selftests/bpf/verifier/jit.c @@ -105,3 +105,19 @@ .result = ACCEPT, .retval = 2, }, +{ + "jit: torturous jumps", + .insns = { }, + .fill_helper = bpf_fill_torturous_jumps, + .prog_type = BPF_PROG_TYPE_SCHED_CLS, + .result = ACCEPT, + .retval = 1, +}, +{ + "jit: torturous jumps in subprog", + .insns = { }, + .fill_helper = bpf_fill_torturous_jumps, + .prog_type = BPF_PROG_TYPE_SCHED_CLS, + .result = ACCEPT, + .retval = 2, +},