From patchwork Tue Jan 4 01:42:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 12702893 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0C0B8C433F5 for ; Tue, 4 Jan 2022 01:29:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=T/R9ug98tu9SYY1N7i6zlZFyhN2cEdVzAh5Udb5SqF0=; b=fwa54zRr/jYy++ uMg2UEsu8DYgBnUvC9iy62zl0551/W00eBBm/1/puEovzIs8pOWxD4sUhltGi9ntd+jQCseDbtqlQ M6HxLVJa+w+/j2cqntXNtWqAIhrEfxfLXZBZqU8j1BwdQ7HQrMfuSHCv/uognV7JSql4o6CfxM1v6 emAVxQY+GMmAJXZbFZp0872cZ2NnAOWe3N0622WjYR8QBMeB1KBiLWAV//J05hQYy0icwTuGHDpLQ NBK3VLzhoCUreavtd6qfW5mffiloILoTVwUME25+2W0rLWgSSie89r/YXfb0I/mj6kFW+y+jR2yjF t9uRCsUfJPT3jk1ZWomg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4Yc2-00ABfn-2k; Tue, 04 Jan 2022 01:27:42 +0000 Received: from szxga08-in.huawei.com ([45.249.212.255]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n4Ybx-00ABea-K7 for linux-arm-kernel@lists.infradead.org; Tue, 04 Jan 2022 01:27:40 +0000 Received: from dggpeml500025.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4JSZdS28Xsz1DKM0; Tue, 4 Jan 2022 09:23:56 +0800 (CST) Received: from huawei.com (10.175.124.27) by dggpeml500025.china.huawei.com (7.185.36.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Tue, 4 Jan 2022 09:27:20 +0800 From: Hou Tao To: Alexei Starovoitov CC: Martin KaFai Lau , Yonghong Song , Daniel Borkmann , Andrii Nakryiko , "David S . Miller" , Jakub Kicinski , , , , Zi Shen Lim , Catalin Marinas , Will Deacon , Subject: [PATCH bpf] bpf, arm64: calculate offset as byte-offset for bpf line info Date: Tue, 4 Jan 2022 09:42:36 +0800 Message-ID: <20220104014236.1512639-1-houtao1@huawei.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500025.china.huawei.com (7.185.36.35) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220103_172738_043567_A9FF8FF5 X-CRM114-Status: GOOD ( 14.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The bpf line info for arm64 is broken due to two reasons: (1) insn_to_jit_off passed to bpf_prog_fill_jited_linfo() is calculated in instruction granularity instead of bytes granularity. (2) insn_to_jit_off only considers the body itself and ignores prologue before the body. So fix it by calculating offset as byte-offset and do build_prologue() first in the first JIT pass. Fixes: 37ab566c178d ("bpf: arm64: Enable arm64 jit to provide bpf_line_info") Signed-off-by: Hou Tao --- arch/arm64/net/bpf_jit_comp.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 148ca51325bb..d7a6d4b523c9 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -24,6 +24,8 @@ #include "bpf_jit.h" +#define INSN_SZ (sizeof(u32)) + #define TMP_REG_1 (MAX_BPF_JIT_REG + 0) #define TMP_REG_2 (MAX_BPF_JIT_REG + 1) #define TCALL_CNT (MAX_BPF_JIT_REG + 2) @@ -154,10 +156,11 @@ static inline int bpf2a64_offset(int bpf_insn, int off, bpf_insn++; /* * Whereas arm64 branch instructions encode the offset - * from the branch itself, so we must subtract 1 from the + * from the branch itself, so we must subtract 4 from the * instruction offset. */ - return ctx->offset[bpf_insn + off] - (ctx->offset[bpf_insn] - 1); + return (ctx->offset[bpf_insn + off] - + (ctx->offset[bpf_insn] - INSN_SZ)) / INSN_SZ; } static void jit_fill_hole(void *area, unsigned int size) @@ -955,13 +958,14 @@ static int build_body(struct jit_ctx *ctx, bool extra_pass) const struct bpf_insn *insn = &prog->insnsi[i]; int ret; + /* BPF line info needs byte-offset instead of insn-offset */ if (ctx->image == NULL) - ctx->offset[i] = ctx->idx; + ctx->offset[i] = ctx->idx * INSN_SZ; ret = build_insn(insn, ctx, extra_pass); if (ret > 0) { i++; if (ctx->image == NULL) - ctx->offset[i] = ctx->idx; + ctx->offset[i] = ctx->idx * INSN_SZ; continue; } if (ret) @@ -973,7 +977,7 @@ static int build_body(struct jit_ctx *ctx, bool extra_pass) * instruction (end of program) */ if (ctx->image == NULL) - ctx->offset[i] = ctx->idx; + ctx->offset[i] = ctx->idx * INSN_SZ; return 0; } @@ -1058,15 +1062,18 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) goto out_off; } - /* 1. Initial fake pass to compute ctx->idx. */ - - /* Fake pass to fill in ctx->offset. */ - if (build_body(&ctx, extra_pass)) { + /* + * 1. Initial fake pass to compute ctx->idx and ctx->offset. + * + * BPF line info needs ctx->offset[i] to be the byte offset + * of instruction[i] in jited image, so build prologue first. + */ + if (build_prologue(&ctx, was_classic)) { prog = orig_prog; goto out_off; } - if (build_prologue(&ctx, was_classic)) { + if (build_body(&ctx, extra_pass)) { prog = orig_prog; goto out_off; }