From patchwork Tue Sep 16 20:29:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Shen Lim X-Patchwork-Id: 4920011 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 22FBCBEEA5 for ; Tue, 16 Sep 2014 20:32:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 36743201E4 for ; Tue, 16 Sep 2014 20:32:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5A6CF201DD for ; Tue, 16 Sep 2014 20:32:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XTzNv-0004gJ-8e; Tue, 16 Sep 2014 20:29:59 +0000 Received: from mail-qg0-x233.google.com ([2607:f8b0:400d:c04::233]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XTzNs-0004ci-Pk for linux-arm-kernel@lists.infradead.org; Tue, 16 Sep 2014 20:29:57 +0000 Received: by mail-qg0-f51.google.com with SMTP id e89so575938qgf.10 for ; Tue, 16 Sep 2014 13:29:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2hjUocU15+FxrSCPDx2mhjm8nycFKE8AxwOepjnChf4=; b=0ACbope6Xf1TvrI2Ii6kzEmpePjWGbQOTtXAfs6tjVq6im6PJtrimV2FMWcTijmnXW LsQ4Ywdb0ZeC73ae73xvjcIcRNi19Cu2Gcnqchca/0FVw95Bn4KqkmOQszoVFOnKhj+D TdwNsvKmwGJqDqVpVzPctKAOhiy+M+NjP6o+pfWcs2VJrARFa3unthukN66QPRYsKTfP j9UcMcFzkgC2q5LWnQdBz9meT3BaRZQwWJrbnNpnvdmeHjjE9MPSN1qJadaDiGlKzmFY sd7BmuTYMMw2UJz+ZNzxQV4MoDlzvxqVLYMcIZf2DB/ELVx+RAKz0ky72F9Wjnuf9wIz 0bkg== X-Received: by 10.236.70.105 with SMTP id o69mr45030307yhd.25.1410899375079; Tue, 16 Sep 2014 13:29:35 -0700 (PDT) Received: from gup76.ec.rr.com (cpe-174-106-244-218.ec.res.rr.com. [174.106.244.218]) by mx.google.com with ESMTPSA id o25sm6882987yhd.30.2014.09.16.13.29.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Sep 2014 13:29:34 -0700 (PDT) From: Zi Shen Lim To: Catalin Marinas , Will Deacon Subject: [PATCH] arm64: bpf: add 'load 64-bit immediate' instruction Date: Tue, 16 Sep 2014 13:29:23 -0700 Message-Id: <1410899363-27635-1-git-send-email-zlim.lnx@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1410892655-17818-1-git-send-email-zlim.lnx@gmail.com> References: <1410892655-17818-1-git-send-email-zlim.lnx@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140916_132956_900850_6C858500 X-CRM114-Status: GOOD ( 16.53 ) X-Spam-Score: -0.1 (/) Cc: Zi Shen Lim , linux-kernel@vger.kernel.org, Daniel Borkmann , "David S . Miller" , linux-arm-kernel@lists.infradead.org, Alexei Starovoitov X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Catalin, Will, Please consider applying this after -rc1 as well. [1] Let me know how you prefer to handle these patches and I can repost as necessary. Thanks, z [1] https://lkml.org/lkml/2014/9/16/418 >8------------------------------------------------------8< Commit 02ab695bb37e (net: filter: add "load 64-bit immediate" eBPF instruction) introduced a new eBPF instruction. Let's add support for this for arm64 as well. Our arm64 eBPF JIT compiler now passes the new "load 64-bit immediate" test case introduced in the same commit 02ab695bb37e. Signed-off-by: Zi Shen Lim Cc: Catalin Marinas Cc: Will Deacon Cc: David S. Miller Cc: Alexei Starovoitov --- arch/arm64/net/bpf_jit_comp.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 80cc769..618d2cd 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -205,6 +205,12 @@ static void build_epilogue(struct jit_ctx *ctx) emit(A64_RET(A64_LR), ctx); } +/* JITs an eBPF instruction. + * Returns: + * 0 - successfully JITed an 8-byte eBPF instruction. + * >0 - successfully JITed a 16-byte eBPF instruction. + * <0 - failed to JIT. + */ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx) { const u8 code = insn->code; @@ -464,6 +470,27 @@ emit_cond_jmp: emit(A64_B(jmp_offset), ctx); break; + /* dst = imm64 */ + case BPF_LD | BPF_IMM | BPF_DW: + { + const struct bpf_insn insn1 = insn[1]; + u64 imm64; + + if (insn1.code != 0 || insn1.src_reg != 0 || + insn1.dst_reg != 0 || insn1.off != 0) { + /* Note: verifier in BPF core must catch invalid + * instructions. + */ + pr_err_once("Invalid BPF_LD_IMM64 instruction\n"); + return -EINVAL; + } + + imm64 = (u64)insn1.imm << 32 | imm; + emit_a64_mov_i64(dst, imm64, ctx); + + return 1; + } + /* LDX: dst = *(size *)(src + off) */ case BPF_LDX | BPF_MEM | BPF_W: case BPF_LDX | BPF_MEM | BPF_H: @@ -615,6 +642,10 @@ static int build_body(struct jit_ctx *ctx) ctx->offset[i] = ctx->idx; ret = build_insn(insn, ctx); + if (ret > 0) { + i++; + continue; + } if (ret) return ret; }