From patchwork Tue Jan 25 10:57:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 12725003 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 3DF5AC2BA4C for ; Wed, 26 Jan 2022 12:25:15 +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:References:In-Reply-To: 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: List-Owner; bh=daYcjmlPs95Wu9yd/IWChx3P8JLmv3FsH8/VI97air0=; b=Sm3KfsIf5XG6RK 8WYdnRU/bw5y9BeqrHu1XMw9Ym1gaBESh/+YKvO7a+6lFscJPNIIV9aqOqwkOBX3DsWHtuU5+LaGN WDfW7ypHzc+rPc5p6j6gtilpaq4xY45hyGQ5+ORNg7BxCc6FetjGj540j/RLktM8E13rIK25XMPg2 ENHOwSkGORWLv9bDC0gm9Xr2IFXDxKWhzdmYG75ey/yFa48UbtTpY6fTmh/x54d5DAt74/qVbDsxS dU5RbZoFjzIag6+MxDQLQO6KeABYzDBdrUwyPtnq9rz8kXNiIPqdL/lrfgrtu3Fk1uaX+Tz6m+A9l c7R+LkeAxPeUr4bMMI1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nChLN-00BgBM-JL; Wed, 26 Jan 2022 12:24:09 +0000 Received: from szxga02-in.huawei.com ([45.249.212.188]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nChKy-00Bg55-KQ for linux-arm-kernel@lists.infradead.org; Wed, 26 Jan 2022 12:23:47 +0000 Received: from dggpeml500025.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4JkNCc39MGzbkFg; Wed, 26 Jan 2022 20:22:52 +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.21; Wed, 26 Jan 2022 20:23:42 +0800 From: Hou Tao To: Alexei Starovoitov , Daniel Borkmann CC: Ard Biesheuvel , Martin KaFai Lau , Yonghong Song , Andrii Nakryiko , Zi Shen Lim , Will Deacon , Catalin Marinas , , , Subject: [PATCH bpf-next v2 2/2] bpf, arm64: calculate offset as byte-offset for bpf line info Date: Tue, 25 Jan 2022 18:57:07 +0800 Message-ID: <20220125105707.292449-3-houtao1@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220125105707.292449-1-houtao1@huawei.com> References: <20220125105707.292449-1-houtao1@huawei.com> 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-20220126_042344_864376_136706E6 X-CRM114-Status: GOOD ( 12.38 ) 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 insn_to_jit_off passed to bpf_prog_fill_jited_linfo() is calculated in instruction granularity instead of bytes granularity, but bpf line info requires byte offset, so fixing it by calculating offset as byte-offset. Signed-off-by: Hou Tao --- arch/arm64/net/bpf_jit_comp.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 6a83f3070985..7b94e0c5e134 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -152,10 +152,12 @@ 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] - AARCH64_INSN_SIZE)) / + AARCH64_INSN_SIZE; } static void jit_fill_hole(void *area, unsigned int size) @@ -946,13 +948,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 * AARCH64_INSN_SIZE; 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 * AARCH64_INSN_SIZE; continue; } if (ret) @@ -964,7 +967,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 * AARCH64_INSN_SIZE; return 0; }