From patchwork Sat Feb 26 12:19:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 12761296 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 41789C4332F for ; Sat, 26 Feb 2022 12:21:58 +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=jaf1V9BdzcXpTKJuhVqHmQWlUW8jBqvBm+aAeeNvydg=; b=uTBGMvgrzmtYZR HGD6FKYo6t8kj5WKu4wVk1O6rKzVy4ho13mUwGRu2mppIDP6H3DowwjrrEpvwDkFi8lc+oHoagZ0G 6oUTkMpS/cQ1qOQsqH6humVhXYXtaOdzjYfZzsYN+93CIoby/X1fiUcZxwPJ9UljHCZsvDmPM+t0l /YuMvTPIc5vuQC5s2oxxkWsimP9cdE34e6ON02xJ9oq8mHxuiucFweHovhiHkSxedRXLy4PtfofV3 2caPFqaItryYd08s2MUmgsdQu3wGO6XIx8JWpQxQNVyZUJv64Xx8KL5zt6QGUTXXRsFkrb0NtmLif PgUVD+6akoOCF+ppb35Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNw3p-007zw4-Ey; Sat, 26 Feb 2022 12:20:29 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNw3l-007zt5-Ds for linux-arm-kernel@lists.infradead.org; Sat, 26 Feb 2022 12:20:27 +0000 Received: from dggpeml500025.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4K5Qfr5pnwzdZTW; Sat, 26 Feb 2022 20:19:00 +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; Sat, 26 Feb 2022 20:20:14 +0800 From: Hou Tao To: Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Will Deacon CC: Song Liu , John Fastabend , Yonghong Song , Andrii Nakryiko , "David S . Miller" , Jakub Kicinski , , , , Zi Shen Lim , Catalin Marinas , Ard Biesheuvel , Subject: [PATCH bpf-next v4 1/2] bpf, arm64: call build_prologue() first in first JIT pass Date: Sat, 26 Feb 2022 20:19:05 +0800 Message-ID: <20220226121906.5709-2-houtao1@huawei.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20220226121906.5709-1-houtao1@huawei.com> References: <20220226121906.5709-1-houtao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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-20220226_042025_678427_69A04532 X-CRM114-Status: UNSURE ( 9.81 ) 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 Sat Feb 26 12:19:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 12761294 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 B8D17C433F5 for ; Sat, 26 Feb 2022 12:21:57 +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=9WkY/YT2aqt+YzBgF+84cVJBxP2ZC49kWBCSVqStxzg=; b=lfnw15UWUKr2Wy QJYAps2MVVxO2HST6iEebb8SBCasP1srB5hqOs3MqzuQTkftiPusV80G25rvGlD/HiegAc6ufxpwO sW62XknNWyY8+z9nZR1Z6K+8LFHXpk2Bi1WJNA2JlAQuZ17ClWvxz66PjTsyKi05Aj/2hacXKyk1R ycxtl3H5p9+A6pdCcanT3aL8OdR2rOI1YdUS5CNvYerHRT7lU/avKwZnwh41H9v03DC3vsNI1cS4r 3qGpuBOyE1hR1O9JYnbcn2CujcqYPkdC9GjV5sZQDon6IVhkvPiL7YbS8zOylj/Vaeblnyvu04ofx kYL1bF68URMITP92ID2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNw47-007zyQ-Oj; Sat, 26 Feb 2022 12:20:47 +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 1nNw3n-007zt1-49 for linux-arm-kernel@lists.infradead.org; Sat, 26 Feb 2022 12:20:29 +0000 Received: from dggpeml500025.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4K5QcF4PDMz9sBF; Sat, 26 Feb 2022 20:16:45 +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; Sat, 26 Feb 2022 20:20:14 +0800 From: Hou Tao To: Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Will Deacon CC: Song Liu , John Fastabend , Yonghong Song , Andrii Nakryiko , "David S . Miller" , Jakub Kicinski , , , , Zi Shen Lim , Catalin Marinas , Ard Biesheuvel , Subject: [PATCH bpf-next v4 2/2] bpf, arm64: feed byte-offset into bpf line info Date: Sat, 26 Feb 2022 20:19:06 +0800 Message-ID: <20220226121906.5709-3-houtao1@huawei.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20220226121906.5709-1-houtao1@huawei.com> References: <20220226121906.5709-1-houtao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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-20220226_042027_396759_13D83F2E X-CRM114-Status: UNSURE ( 8.88 ) 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 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. bpf_prog_fill_jited_linfo() will be the last user of ctx.offset before its free, so convert the offset into byte-offset before call bpf_prog_fill_jited_linfo(). Fixes: 37ab566c178d ("bpf: arm64: Enable arm64 jit to provide bpf_line_info") Suggested-by: Daniel Borkmann Signed-off-by: Hou Tao --- arch/arm64/net/bpf_jit_comp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index 68b35c83e637..e850c69e128c 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -1274,6 +1274,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog) prog->jited_len = prog_size; if (!prog->is_func || extra_pass) { + int i; + + /* offset[prog->len] is the size of program */ + for (i = 0; i <= prog->len; i++) + ctx.offset[i] *= AARCH64_INSN_SIZE; bpf_prog_fill_jited_linfo(prog, ctx.offset + 1); out_off: kfree(ctx.offset);