From patchwork Tue Feb 8 01:25:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 12738036 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 580A3C433EF for ; Tue, 8 Feb 2022 01:27:55 +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=bxouxDnklofUcQNXgB8uebJM9iMS1MH0rAT2QTtFoQY=; b=hloUOsme16fe/l lrR2qXTFhvBVYqUwkNhk+xB8xGEsQpoFCVEsg5ZUEAThvfiARy0uwybtGHsJ0KNRicP1C/E5Y70A8 GBLLQSo8u3qk8veJqsuGeTa21rkb3JPAOfnpnqQabBpuA1k1XJGtbNpdv91M5EDvmz8igwPFbbWQK YhMUWUX5WE2378vDnY8DnbCxGyAYrwFj4SleKf6vVM316yNzwwDgvZhyR9YlB/FyjwQibERhQPJQS JIql/e/F76skFR28bh87lE36OGMWLFb5Yduf8lpZLmvrBIqnTsCQdOBjLML1bSqbfu7swCUA2M4Cl p9AE/MTAQilIZPZZQ5Dg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHFGV-00CAM6-Ru; Tue, 08 Feb 2022 01:25:55 +0000 Received: from szxga03-in.huawei.com ([45.249.212.189]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHFGS-00CAKq-2g for linux-arm-kernel@lists.infradead.org; Tue, 08 Feb 2022 01:25:53 +0000 Received: from dggpeml500025.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Jt4xp1k1HzdZTT; Tue, 8 Feb 2022 09:22:38 +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; Tue, 8 Feb 2022 09:25:45 +0800 From: Hou Tao To: Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau CC: Ard Biesheuvel , Yonghong Song , Andrii Nakryiko , Zi Shen Lim , Will Deacon , Catalin Marinas , , , Subject: [PATCH bpf-next v3 1/2] bpf, arm64: call build_prologue() first in first JIT pass Date: Tue, 8 Feb 2022 09:25:38 +0800 Message-ID: <20220208012539.491753-2-houtao1@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220208012539.491753-1-houtao1@huawei.com> References: <20220208012539.491753-1-houtao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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-20220207_172552_359128_CADA9C68 X-CRM114-Status: UNSURE ( 9.33 ) X-CRM114-Notice: Please train this message. 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 BPF line info needs ctx->offset to be the instruction offset in the whole jited image instead of the body itself, so also call build_prologue() first in 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 | 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 2375ed3e4c8a..68b35c83e637 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -1190,15 +1190,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 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; } From patchwork Tue Feb 8 01:25:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 12738037 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 B58CAC433FE for ; Tue, 8 Feb 2022 01:27:55 +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=wT8Yuot4Vf+1G1t3roW2/+N5Zd91pETs6PP/PlqeQD4=; b=0qG6HZirydd7ha xkdei47dkNMlbroDYyse0Aog5ZUaD9GekDt83UhSmz9HsAmk1jNuCKxcxIQIqNZBj0kGL1ZUcTGTe NTCGg+hpWbx+X6JvweWtvOvovR03INcpSGxLZSgOVroKroscqAe66j8EC2eq02pa0tfF70OIVlYIi dYtlkK+6yDW4TuZ9t8tPKmI/6fgR50eaJ4a5q0bCyDMHP/QK0C3UYbOLE50joXMe8CU4vfhGGRPD3 oh+UbROZr7bH1keuOBlp/MxZiItqvwG2ejwoBarsEKKoUsJBIUX1HRCnXrCsu7gRuxKaOHwk8KQsd A/+VXkkIJDoBhQOdWqww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHFGo-00CAOe-Jt; Tue, 08 Feb 2022 01:26:14 +0000 Received: from szxga03-in.huawei.com ([45.249.212.189]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nHFGS-00CAKr-2u for linux-arm-kernel@lists.infradead.org; Tue, 08 Feb 2022 01:25:54 +0000 Received: from dggpeml500025.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Jt4xp24h2zdZTS; Tue, 8 Feb 2022 09:22:38 +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; Tue, 8 Feb 2022 09:25:46 +0800 From: Hou Tao To: Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau CC: Ard Biesheuvel , Yonghong Song , Andrii Nakryiko , Zi Shen Lim , Will Deacon , Catalin Marinas , , , Subject: [PATCH bpf-next v3 2/2] bpf, arm64: calculate offset as byte-offset for bpf line info Date: Tue, 8 Feb 2022 09:25:39 +0800 Message-ID: <20220208012539.491753-3-houtao1@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220208012539.491753-1-houtao1@huawei.com> References: <20220208012539.491753-1-houtao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) 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-20220207_172552_373147_F907E228 X-CRM114-Status: GOOD ( 12.00 ) 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 ctx->offset as byte-offset. bpf2a64_offset() needs to return relative instruction offset by using ctx->offfset, so update it accordingly. Fixes: 37ab566c178d ("bpf: arm64: Enable arm64 jit to provide bpf_line_info") Signed-off-by: Hou Tao --- arch/arm64/net/bpf_jit_comp.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 68b35c83e637..aed07cba78ec 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -164,9 +164,14 @@ static inline int bpf2a64_offset(int bpf_insn, int off, /* * Whereas arm64 branch instructions encode the offset * from the branch itself, so we must subtract 1 from the - * instruction offset. + * instruction offset. The unit of ctx->offset is byte, so + * subtract AARCH64_INSN_SIZE from it. bpf2a64_offset() + * returns instruction offset, so divide by AARCH64_INSN_SIZE + * at the end. */ - 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) @@ -1087,13 +1092,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) @@ -1105,7 +1111,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; }