Message ID | 20221031173819.2344270-1-nathan@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2448892wru; Mon, 31 Oct 2022 10:42:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7BwzjmL7Dt36sA7p4arKx60Sqd0LQWWEvob9Dr3Ue1rn627qz2V5XZ/jQp1oMAHKw+8l1o X-Received: by 2002:a17:902:d591:b0:186:fe2d:f3b7 with SMTP id k17-20020a170902d59100b00186fe2df3b7mr15806016plh.68.1667238123373; Mon, 31 Oct 2022 10:42:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667238123; cv=none; d=google.com; s=arc-20160816; b=phLK5h8T9TxMKskw4bOCtRvjXxES9MR3UtEOSKNlCdPefrhGFH5qTFlNMAsrsCirWU jPvl6NIadA0OI5Ri7YjwVmpvN4MZaINqYBMvzE9Bp2Y3uHRBzep888FPhe4LYhn6SeFH mwlc5cp2Dz5dD6RBQP1FTs+eyBypRG5VQ1WQBE2tKmj7yeodKGAQ/xMXdT5PqYqUimim sYDhVJK/Ex5LeaalswDbyRljSmWNcbcMARJzM2Kik5Vz/AfGhZclnKKIJSlXH3ACWwOp sqE8XnqozLUsbwidKv2Pe7R1ZS1+N6c1xYjcgTkTqG/5IAu7msgQp+xJONWmx4QJG/c8 bXbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=5SaGqStUR0g4cwT6jeXlJGAlx8baRcL68elZmcm9RZI=; b=n9rb98J7lZ898K1Mi6g5DxvrL2eavsPhw6LvTnF2/TnhYdqe0sszNUGZrCsGsxR8Wc f+GsMkco9f9h/L4YYrhOOdRLB92vM08UkZKITRBWAPzT2VPi1BKLS8S2krp+4xFVf2Jh GHiTjBvCtMvKozC9VI9raufcSO5ZTs2Z4s1UeWepEeSnJFoSiyOifuwyjFQ5Z1ctPGwM SKoOvYVul5L967bNbd5qZtD8jdopBZQnO8cGaRCf8PNVLf9k5sTHq/zjkP+4Sz4HLluY uJkH5+BUSI5Zq9LrPNcJVelxNmy4KMg6vaXNNgStflPY6b+LwKAJw4No7CNA5ch39Fnx qiwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FWoSDZLA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id il5-20020a17090b164500b001fd7ced8960si12089897pjb.92.2022.10.31.10.41.38; Mon, 31 Oct 2022 10:42:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FWoSDZLA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231791AbiJaRjT (ORCPT <rfc822;kartikey406@gmail.com> + 99 others); Mon, 31 Oct 2022 13:39:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231829AbiJaRix (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 31 Oct 2022 13:38:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFDAE13D40; Mon, 31 Oct 2022 10:38:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 17017B819BA; Mon, 31 Oct 2022 17:38:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38709C43147; Mon, 31 Oct 2022 17:38:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667237917; bh=P9CiTbFkLwYXgkEJtoE1pjsCHoI48SKWU5aipbF3igg=; h=From:To:Cc:Subject:Date:From; b=FWoSDZLAWEJZUT6mSbEXa8gW75M91KXEbFRnzgmaEPaVFzfP862DtwPc35OjioWj4 vFG/stMP+8m/M+TkH6HKIlUgBQ9FYWXbSvARZmvo6To5gL70wjkOHX6orXCFjdBmhD xS/m5oOjcxexhDG0tJ+96hf9aJKgssVytSEDvVzMg410YPKKTf/58hEwcA+//8NAaI ryWnBKa99eryMwamtaxUrn3YJWkCCeFYU/JOEl99g9AZLhAraPxrxb6DOE7WZOSRb+ 9cp5p/hkjTkepOa4SW2CKlYlT5qRTftB9rkHvam03HxfVaTEAudlh4rLMtsk+F/ngt H77toNMvDffKQ== From: Nathan Chancellor <nathan@kernel.org> To: Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Andrii Nakryiko <andrii@kernel.org> Cc: Martin KaFai Lau <martin.lau@linux.dev>, Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>, John Fastabend <john.fastabend@gmail.com>, KP Singh <kpsingh@kernel.org>, Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>, Jiri Olsa <jolsa@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Tom Rix <trix@redhat.com>, x86@kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, patches@lists.linux.dev, Nathan Chancellor <nathan@kernel.org> Subject: [PATCH bpf] bpf: Mark bpf_arch_init_dispatcher_early() as __init_or_module Date: Mon, 31 Oct 2022 10:38:19 -0700 Message-Id: <20221031173819.2344270-1-nathan@kernel.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748225882220433656?= X-GMAIL-MSGID: =?utf-8?q?1748225882220433656?= |
Series |
[bpf] bpf: Mark bpf_arch_init_dispatcher_early() as __init_or_module
|
|
Commit Message
Nathan Chancellor
Oct. 31, 2022, 5:38 p.m. UTC
After commit dbe69b299884 ("bpf: Fix dispatcher patchable function entry
to 5 bytes nop"), building kernel/bpf/dispatcher.c in certain
configurations with LLVM's integrated assembler results in a known
recordmcount bug:
Cannot find symbol for section 4: .init.text.
kernel/bpf/dispatcher.o: failed
This occurs when there are only weak symbols in a particular section in
the translation unit; in this case, bpf_arch_init_dispatcher_early() is
marked '__weak __init' and it is the only symbol in the .init.text
section. recordmcount expects there to be a symbol for a particular
section but LLVM's integrated assembler (and GNU as after 2.37) do not
generated section symbols. This has been worked around in the kernel
before in commit 55d5b7dd6451 ("initramfs: fix clang build failure")
and commit 6e7b64b9dd6d ("elfcore: fix building with clang").
Fixing recordmcount has been brought up before but there is no clear
solution that does not break ftrace outright.
Unfortunately, working around this issue by removing the '__init' from
bpf_arch_init_dispatcher_early() is not an option, as the x86 version of
bpf_arch_init_dispatcher_early() calls text_poke_early(), which is
marked '__init_or_module', meaning that when CONFIG_MODULES is disabled,
bpf_arch_init_dispatcher_early() has to be marked '__init' as well to
avoid a section mismatch warning from modpost.
However, bpf_arch_init_dispatcher_early() can be marked
'__init_or_module' as well, which would resolve the recordmcount warning
for configurations that support modules (i.e., the vast majority of
them) while not introducing any new warnings for all configurations. Do
so to clear up the build failure for CONFIG_MODULES=y configurations.
Link: https://github.com/ClangBuiltLinux/linux/issues/981
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
arch/x86/net/bpf_jit_comp.c | 2 +-
include/linux/bpf.h | 2 +-
kernel/bpf/dispatcher.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
base-commit: 8bdc2acd420c6f3dd1f1c78750ec989f02a1e2b9
Comments
On Mon, Oct 31, 2022 at 10:38:19AM -0700, Nathan Chancellor wrote: > After commit dbe69b299884 ("bpf: Fix dispatcher patchable function entry > to 5 bytes nop"), building kernel/bpf/dispatcher.c in certain > configurations with LLVM's integrated assembler results in a known > recordmcount bug: > > Cannot find symbol for section 4: .init.text. > kernel/bpf/dispatcher.o: failed > > This occurs when there are only weak symbols in a particular section in > the translation unit; in this case, bpf_arch_init_dispatcher_early() is > marked '__weak __init' and it is the only symbol in the .init.text > section. recordmcount expects there to be a symbol for a particular > section but LLVM's integrated assembler (and GNU as after 2.37) do not > generated section symbols. This has been worked around in the kernel > before in commit 55d5b7dd6451 ("initramfs: fix clang build failure") > and commit 6e7b64b9dd6d ("elfcore: fix building with clang"). > > Fixing recordmcount has been brought up before but there is no clear > solution that does not break ftrace outright. > > Unfortunately, working around this issue by removing the '__init' from > bpf_arch_init_dispatcher_early() is not an option, as the x86 version of > bpf_arch_init_dispatcher_early() calls text_poke_early(), which is > marked '__init_or_module', meaning that when CONFIG_MODULES is disabled, > bpf_arch_init_dispatcher_early() has to be marked '__init' as well to > avoid a section mismatch warning from modpost. > > However, bpf_arch_init_dispatcher_early() can be marked > '__init_or_module' as well, which would resolve the recordmcount warning > for configurations that support modules (i.e., the vast majority of > them) while not introducing any new warnings for all configurations. Do > so to clear up the build failure for CONFIG_MODULES=y configurations. > > Link: https://github.com/ClangBuiltLinux/linux/issues/981 > Signed-off-by: Nathan Chancellor <nathan@kernel.org> LGTM but the whole thing might be actually going away: https://lore.kernel.org/bpf/Y2BD6xZ108lv3j7J@krava/T/#u because it won't compile on gcc 7 jirka > --- > arch/x86/net/bpf_jit_comp.c | 2 +- > include/linux/bpf.h | 2 +- > kernel/bpf/dispatcher.c | 2 +- > 3 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c > index 00127abd89ee..4145939bbb6a 100644 > --- a/arch/x86/net/bpf_jit_comp.c > +++ b/arch/x86/net/bpf_jit_comp.c > @@ -389,7 +389,7 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t, > return ret; > } > > -int __init bpf_arch_init_dispatcher_early(void *ip) > +int __init_or_module bpf_arch_init_dispatcher_early(void *ip) > { > const u8 *nop_insn = x86_nops[5]; > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > index 0566705c1d4e..4aa7bde406f5 100644 > --- a/include/linux/bpf.h > +++ b/include/linux/bpf.h > @@ -971,7 +971,7 @@ struct bpf_trampoline *bpf_trampoline_get(u64 key, > struct bpf_attach_target_info *tgt_info); > void bpf_trampoline_put(struct bpf_trampoline *tr); > int arch_prepare_bpf_dispatcher(void *image, void *buf, s64 *funcs, int num_funcs); > -int __init bpf_arch_init_dispatcher_early(void *ip); > +int __init_or_module bpf_arch_init_dispatcher_early(void *ip); > > #define BPF_DISPATCHER_INIT(_name) { \ > .mutex = __MUTEX_INITIALIZER(_name.mutex), \ > diff --git a/kernel/bpf/dispatcher.c b/kernel/bpf/dispatcher.c > index 04f0a045dcaa..e14a68e9a74f 100644 > --- a/kernel/bpf/dispatcher.c > +++ b/kernel/bpf/dispatcher.c > @@ -91,7 +91,7 @@ int __weak arch_prepare_bpf_dispatcher(void *image, void *buf, s64 *funcs, int n > return -ENOTSUPP; > } > > -int __weak __init bpf_arch_init_dispatcher_early(void *ip) > +int __weak __init_or_module bpf_arch_init_dispatcher_early(void *ip) > { > return -ENOTSUPP; > } > > base-commit: 8bdc2acd420c6f3dd1f1c78750ec989f02a1e2b9 > -- > 2.38.1 >
On Tue, Nov 01, 2022 at 08:57:11AM +0100, Jiri Olsa wrote: > On Mon, Oct 31, 2022 at 10:38:19AM -0700, Nathan Chancellor wrote: > > After commit dbe69b299884 ("bpf: Fix dispatcher patchable function entry > > to 5 bytes nop"), building kernel/bpf/dispatcher.c in certain > > configurations with LLVM's integrated assembler results in a known > > recordmcount bug: > > > > Cannot find symbol for section 4: .init.text. > > kernel/bpf/dispatcher.o: failed > > > > This occurs when there are only weak symbols in a particular section in > > the translation unit; in this case, bpf_arch_init_dispatcher_early() is > > marked '__weak __init' and it is the only symbol in the .init.text > > section. recordmcount expects there to be a symbol for a particular > > section but LLVM's integrated assembler (and GNU as after 2.37) do not > > generated section symbols. This has been worked around in the kernel > > before in commit 55d5b7dd6451 ("initramfs: fix clang build failure") > > and commit 6e7b64b9dd6d ("elfcore: fix building with clang"). > > > > Fixing recordmcount has been brought up before but there is no clear > > solution that does not break ftrace outright. > > > > Unfortunately, working around this issue by removing the '__init' from > > bpf_arch_init_dispatcher_early() is not an option, as the x86 version of > > bpf_arch_init_dispatcher_early() calls text_poke_early(), which is > > marked '__init_or_module', meaning that when CONFIG_MODULES is disabled, > > bpf_arch_init_dispatcher_early() has to be marked '__init' as well to > > avoid a section mismatch warning from modpost. > > > > However, bpf_arch_init_dispatcher_early() can be marked > > '__init_or_module' as well, which would resolve the recordmcount warning > > for configurations that support modules (i.e., the vast majority of > > them) while not introducing any new warnings for all configurations. Do > > so to clear up the build failure for CONFIG_MODULES=y configurations. > > > > Link: https://github.com/ClangBuiltLinux/linux/issues/981 > > Signed-off-by: Nathan Chancellor <nathan@kernel.org> > > LGTM but the whole thing might be actually going away: > https://lore.kernel.org/bpf/Y2BD6xZ108lv3j7J@krava/T/#u > > because it won't compile on gcc 7 Ah, if that is the case, I suppose we can just wait until it is reverted and replaced with the better fix. It seems like that will be the case based on Bjorn's testing: https://lore.kernel.org/87iljyyes6.fsf@all.your.base.are.belong.to.us/ Cheers, Nathan > > --- > > arch/x86/net/bpf_jit_comp.c | 2 +- > > include/linux/bpf.h | 2 +- > > kernel/bpf/dispatcher.c | 2 +- > > 3 files changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c > > index 00127abd89ee..4145939bbb6a 100644 > > --- a/arch/x86/net/bpf_jit_comp.c > > +++ b/arch/x86/net/bpf_jit_comp.c > > @@ -389,7 +389,7 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t, > > return ret; > > } > > > > -int __init bpf_arch_init_dispatcher_early(void *ip) > > +int __init_or_module bpf_arch_init_dispatcher_early(void *ip) > > { > > const u8 *nop_insn = x86_nops[5]; > > > > diff --git a/include/linux/bpf.h b/include/linux/bpf.h > > index 0566705c1d4e..4aa7bde406f5 100644 > > --- a/include/linux/bpf.h > > +++ b/include/linux/bpf.h > > @@ -971,7 +971,7 @@ struct bpf_trampoline *bpf_trampoline_get(u64 key, > > struct bpf_attach_target_info *tgt_info); > > void bpf_trampoline_put(struct bpf_trampoline *tr); > > int arch_prepare_bpf_dispatcher(void *image, void *buf, s64 *funcs, int num_funcs); > > -int __init bpf_arch_init_dispatcher_early(void *ip); > > +int __init_or_module bpf_arch_init_dispatcher_early(void *ip); > > > > #define BPF_DISPATCHER_INIT(_name) { \ > > .mutex = __MUTEX_INITIALIZER(_name.mutex), \ > > diff --git a/kernel/bpf/dispatcher.c b/kernel/bpf/dispatcher.c > > index 04f0a045dcaa..e14a68e9a74f 100644 > > --- a/kernel/bpf/dispatcher.c > > +++ b/kernel/bpf/dispatcher.c > > @@ -91,7 +91,7 @@ int __weak arch_prepare_bpf_dispatcher(void *image, void *buf, s64 *funcs, int n > > return -ENOTSUPP; > > } > > > > -int __weak __init bpf_arch_init_dispatcher_early(void *ip) > > +int __weak __init_or_module bpf_arch_init_dispatcher_early(void *ip) > > { > > return -ENOTSUPP; > > } > > > > base-commit: 8bdc2acd420c6f3dd1f1c78750ec989f02a1e2b9 > > -- > > 2.38.1 > >
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index 00127abd89ee..4145939bbb6a 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -389,7 +389,7 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t, return ret; } -int __init bpf_arch_init_dispatcher_early(void *ip) +int __init_or_module bpf_arch_init_dispatcher_early(void *ip) { const u8 *nop_insn = x86_nops[5]; diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 0566705c1d4e..4aa7bde406f5 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -971,7 +971,7 @@ struct bpf_trampoline *bpf_trampoline_get(u64 key, struct bpf_attach_target_info *tgt_info); void bpf_trampoline_put(struct bpf_trampoline *tr); int arch_prepare_bpf_dispatcher(void *image, void *buf, s64 *funcs, int num_funcs); -int __init bpf_arch_init_dispatcher_early(void *ip); +int __init_or_module bpf_arch_init_dispatcher_early(void *ip); #define BPF_DISPATCHER_INIT(_name) { \ .mutex = __MUTEX_INITIALIZER(_name.mutex), \ diff --git a/kernel/bpf/dispatcher.c b/kernel/bpf/dispatcher.c index 04f0a045dcaa..e14a68e9a74f 100644 --- a/kernel/bpf/dispatcher.c +++ b/kernel/bpf/dispatcher.c @@ -91,7 +91,7 @@ int __weak arch_prepare_bpf_dispatcher(void *image, void *buf, s64 *funcs, int n return -ENOTSUPP; } -int __weak __init bpf_arch_init_dispatcher_early(void *ip) +int __weak __init_or_module bpf_arch_init_dispatcher_early(void *ip) { return -ENOTSUPP; }