From patchwork Mon Nov 14 11:43:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13042172 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F8CCC4332F for ; Mon, 14 Nov 2022 11:46:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236612AbiKNLqD (ORCPT ); Mon, 14 Nov 2022 06:46:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236672AbiKNLp2 (ORCPT ); Mon, 14 Nov 2022 06:45:28 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C1D1222BF; Mon, 14 Nov 2022 03:44:47 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id BDD5C61045; Mon, 14 Nov 2022 11:44:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F566C433D6; Mon, 14 Nov 2022 11:44:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668426286; bh=l68sB4NnR3/f4L7VL19WvqH6Dh8yt/aVZ1uJVefQMtI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XtUJF22t1vMETfxkDkDoQaLgCdasT1mX3SAV8kKRXx4VF8SppR8kmCPcKMKny+Dbh +R5/4ermD/vAqhbI6Jfl2IqEnpgRKohqOPuvB4Lr0fp79bgVEMQTN7nYEURG2V56sP uAL+oq9za5RvSqWqnegWHtzmApX55dYD+0jXvOKiYAaATRPll3qAZUolXRKuXdwIp3 tZijCM3cQmnJskEoxRP80Y42UARhTetm5DtR4MNQJ6vgwf4jlfGRFsTa01Fyg8IIcV 8YhXFJHgBjabJP8rmmWYRTzNu549Kt7BxT7QTjZNordAq51h+KaB/RMfFHwsvewfck BMu5d6NEToxzA== From: "Jiri Slaby (SUSE)" To: linux-kernel@vger.kernel.org Cc: Jiri Slaby , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, Martin Liska Subject: [PATCH 21/46] btf, lto: pass scope as strings Date: Mon, 14 Nov 2022 12:43:19 +0100 Message-Id: <20221114114344.18650-22-jirislaby@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114114344.18650-1-jirislaby@kernel.org> References: <20221114114344.18650-1-jirislaby@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org From: Jiri Slaby gcc LTO can put assembler top level statements into other assembler files. The BTF IDs assumed that they are in the same file. We need to make all BTF IDs global to work around this. This is a preparation for that, as we will pass __global_on_lto as scope. That is macro that expands either to "globl" or "local" depending whether LTO is enabled. That wouldn't work without this patch as we stringify scope at the moment. Cc: Alexei Starovoitov Cc: Daniel Borkmann Cc: Andrii Nakryiko Cc: Martin KaFai Lau Cc: Song Liu Cc: Yonghong Song Cc: John Fastabend Cc: KP Singh Cc: Stanislav Fomichev Cc: Hao Luo Cc: Jiri Olsa Cc: bpf@vger.kernel.org Cc: Martin Liska Signed-off-by: Jiri Slaby --- include/linux/btf_ids.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h index 2aea877d644f..3011757a48ef 100644 --- a/include/linux/btf_ids.h +++ b/include/linux/btf_ids.h @@ -83,16 +83,16 @@ word \ #define __BTF_ID_LIST(name, scope) \ asm( \ ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ -"." #scope " " #name "; \n" \ +"." scope " " #name "; \n" \ #name ":; \n" \ ".popsection; \n"); #define BTF_ID_LIST(name) \ -__BTF_ID_LIST(name, local) \ +__BTF_ID_LIST(name, "local") \ extern u32 name[]; #define BTF_ID_LIST_GLOBAL(name, n) \ -__BTF_ID_LIST(name, globl) +__BTF_ID_LIST(name, "globl") /* The BTF_ID_LIST_SINGLE macro defines a BTF_ID_LIST with * a single entry. @@ -142,18 +142,18 @@ asm( \ #define __BTF_SET_START(name, scope) \ asm( \ ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ -"." #scope " __BTF_ID__set__" #name "; \n" \ +"." scope " __BTF_ID__set__" #name "; \n" \ "__BTF_ID__set__" #name ":; \n" \ ".zero 4 \n" \ ".popsection; \n"); #define BTF_SET_START(name) \ -__BTF_ID_LIST(name, local) \ -__BTF_SET_START(name, local) +__BTF_ID_LIST(name, "local") \ +__BTF_SET_START(name, "local") #define BTF_SET_START_GLOBAL(name) \ -__BTF_ID_LIST(name, globl) \ -__BTF_SET_START(name, globl) +__BTF_ID_LIST(name, "globl") \ +__BTF_SET_START(name, "globl") #define BTF_SET_END(name) \ asm( \ @@ -186,14 +186,14 @@ extern struct btf_id_set name; #define __BTF_SET8_START(name, scope) \ asm( \ ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ -"." #scope " __BTF_ID__set8__" #name "; \n" \ +"." scope " __BTF_ID__set8__" #name "; \n" \ "__BTF_ID__set8__" #name ":; \n" \ ".zero 8 \n" \ ".popsection; \n"); #define BTF_SET8_START(name) \ -__BTF_ID_LIST(name, local) \ -__BTF_SET8_START(name, local) +__BTF_ID_LIST(name, "local") \ +__BTF_SET8_START(name, "local") #define BTF_SET8_END(name) \ asm( \ From patchwork Mon Nov 14 11:43:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13042173 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FDC7C43219 for ; Mon, 14 Nov 2022 11:46:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236624AbiKNLqG (ORCPT ); Mon, 14 Nov 2022 06:46:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236632AbiKNLpa (ORCPT ); Mon, 14 Nov 2022 06:45:30 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E944B22BF5; Mon, 14 Nov 2022 03:44:50 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 845D061029; Mon, 14 Nov 2022 11:44:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7258C433D7; Mon, 14 Nov 2022 11:44:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668426289; bh=dM14MOihj97NYzJwhWL5SRRwVL0+QAgx8foCL3a4QiM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D4l3yS3yBfgD2zeune7JyBhi9yZvfRVo03Vw2CsrpN2qXewu6FVFqX+CycSXiYnE6 YAn/HPAzO2Cv02XdSbbNATOUQXGwpbKZ5GPnCeKpDeTb9ovq7zHgnCYAAEYUBoWZYH PAka5pjed2VwRUgOVwmgAyMDfMAkb6rrVgvHwMeArFlKbhYJroYU6GSwxmzwHMiCXS l6yIxL6P9bKUMzd50lLwvLNgExDTPPDnJ1e/XhAiNZQLil/BH4VFMfm123x4vTyhvY OBs3lehnT+iFHQts+mAjkgNtImz3iicmMM0yJkIo8/AT96ZT+bWqChaGXVh+iH+Ssr PxwwM9K7eJw8w== From: "Jiri Slaby (SUSE)" To: linux-kernel@vger.kernel.org Cc: Andi Kleen , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, Martin Liska , Jiri Slaby Subject: [PATCH 22/46] btf, lto: Make all BTF IDs global on LTO Date: Mon, 14 Nov 2022 12:43:20 +0100 Message-Id: <20221114114344.18650-23-jirislaby@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114114344.18650-1-jirislaby@kernel.org> References: <20221114114344.18650-1-jirislaby@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org From: Andi Kleen gcc LTO can put assembler top level statements into other assembler files. The BTF IDs assumed that they are in the same file. So if we are building with gcc LTO, make all BTF IDs global to work around this. This is done by new __global_on_lto macro. [js] do that for 8B BTF set too (commit ab21d6063c01) [js] do global only in LTO case Cc: Alexei Starovoitov Cc: Daniel Borkmann Cc: Andrii Nakryiko Cc: Martin KaFai Lau Cc: Song Liu Cc: Yonghong Song Cc: John Fastabend Cc: KP Singh Cc: Stanislav Fomichev Cc: Hao Luo Cc: Jiri Olsa Cc: bpf@vger.kernel.org Signed-off-by: Andi Kleen Signed-off-by: Martin Liska Signed-off-by: Jiri Slaby --- include/linux/btf_ids.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h index 3011757a48ef..a2bef302e42c 100644 --- a/include/linux/btf_ids.h +++ b/include/linux/btf_ids.h @@ -37,7 +37,7 @@ struct btf_id_set8 { #define ____BTF_ID(symbol, word) \ asm( \ ".pushsection " BTF_IDS_SECTION ",\"a\"; \n" \ -".local " #symbol " ; \n" \ +"." __global_on_lto " " #symbol " ; \n" \ ".type " #symbol ", STT_OBJECT; \n" \ ".size " #symbol ", 4; \n" \ #symbol ": \n" \ @@ -88,7 +88,7 @@ asm( \ ".popsection; \n"); #define BTF_ID_LIST(name) \ -__BTF_ID_LIST(name, "local") \ +__BTF_ID_LIST(name, __global_on_lto) \ extern u32 name[]; #define BTF_ID_LIST_GLOBAL(name, n) \ @@ -148,8 +148,8 @@ asm( \ ".popsection; \n"); #define BTF_SET_START(name) \ -__BTF_ID_LIST(name, "local") \ -__BTF_SET_START(name, "local") +__BTF_ID_LIST(name, __global_on_lto) \ +__BTF_SET_START(name, __global_on_lto) #define BTF_SET_START_GLOBAL(name) \ __BTF_ID_LIST(name, "globl") \ @@ -192,8 +192,8 @@ asm( \ ".popsection; \n"); #define BTF_SET8_START(name) \ -__BTF_ID_LIST(name, "local") \ -__BTF_SET8_START(name, "local") +__BTF_ID_LIST(name, __global_on_lto) \ +__BTF_SET8_START(name, __global_on_lto) #define BTF_SET8_END(name) \ asm( \ From patchwork Mon Nov 14 11:43:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13042174 X-Patchwork-Delegate: bpf@iogearbox.net 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B393DC4332F for ; Mon, 14 Nov 2022 11:46:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236716AbiKNLq3 (ORCPT ); Mon, 14 Nov 2022 06:46:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236722AbiKNLpp (ORCPT ); Mon, 14 Nov 2022 06:45:45 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 793FF22B3A; Mon, 14 Nov 2022 03:44:56 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id C5ACC6106E; Mon, 14 Nov 2022 11:44:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9126C433D7; Mon, 14 Nov 2022 11:44:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668426295; bh=OSbGEYnUhjKa2m71ScF7KvfTEC1ATHNDn1CpUx6Hw/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DJ8z/7CedpLvc+/MF3CZmnF65KarkQtOfm1yX5IFr/LmkkXS8OyiGK5D6LzuK4Mwa XoMpS5SsUhiHN8EntCQVS0aMN3JXNLtGIGn9JmXD9vi5XxwcfKeGIiS4xH7MxNI8t6 vH7kjHjE20tVD8aibkNSy3K52KyjWCH1iFbLzFn+bajePCfLOF8m0ZCazRzy7geM3l IVhKr+7koeeO6NdvAEFD6DO/3P47xTvTqcxey6Tldepdy+3IUwRzfAoFgp+p+ZpuSn FXWWZL6zaWeuMoxWy0bf01evM34QctoIH3I0saRBNn4hX3uT+AVmaq7no+BRMbr/1H tJh/RQSG7pzBA== From: "Jiri Slaby (SUSE)" To: linux-kernel@vger.kernel.org Cc: Andi Kleen , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, Martin Liska , Jiri Slaby Subject: [PATCH 24/46] bpf, lto: mark interpreter jump table as __noreorder Date: Mon, 14 Nov 2022 12:43:22 +0100 Message-Id: <20221114114344.18650-25-jirislaby@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221114114344.18650-1-jirislaby@kernel.org> References: <20221114114344.18650-1-jirislaby@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Andi Kleen gcc LTO has a problem that can cause static variables containing && labels to be put into a different LTO partition and then fail the build. This can happen with the jump table in the BPF interprer. Mark the interpreter function and the jump table as __noreorder, this guarantees they both end up in the first partition. Cc: Alexei Starovoitov Cc: Daniel Borkmann Cc: John Fastabend Cc: Andrii Nakryiko Cc: Martin KaFai Lau Cc: Song Liu Cc: Yonghong Song Cc: KP Singh Cc: Stanislav Fomichev Cc: Hao Luo Cc: Jiri Olsa Cc: bpf@vger.kernel.org Signed-off-by: Andi Kleen Signed-off-by: Martin Liska Signed-off-by: Jiri Slaby --- kernel/bpf/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 25a54e04560e..d40ce00622f6 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -1640,7 +1640,7 @@ u64 __weak bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr) * * Return: whatever value is in %BPF_R0 at program exit */ -static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn) +static u64 __noreorder ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn) { #define BPF_INSN_2_LBL(x, y) [BPF_##x | BPF_##y] = &&x##_##y #define BPF_INSN_3_LBL(x, y, z) [BPF_##x | BPF_##y | BPF_##z] = &&x##_##y##_##z