Skip to content

Commit 8bd44dd

Browse files
ardbiesheuvelkernel-patches-bot
authored andcommitted
bpf: don't rely on GCC __attribute__((optimize)) to disable GCSE
Commit 3193c08 ("bpf: Disable GCC -fgcse optimization for ___bpf_prog_run()") introduced a __no_fgcse macro that expands to a function scope __attribute__((optimize("-fno-gcse"))), to disable a GCC specific optimization that was causing trouble on x86 builds, and was not expected to have any positive effect in the first place. However, as the GCC manual documents, __attribute__((optimize)) is not for production use, and results in all other optimization options to be forgotten for the function in question. This can cause all kinds of trouble, but in one particular reported case, it causes -fno-asynchronous-unwind-tables to be disregarded, resulting in .eh_frame info to be emitted for the function inadvertently. This reverts commit 3193c08, and instead, it disables the -fgcse optimization for the entire source file, but only when building for X86. Cc: Nick Desaulniers <[email protected]> Cc: Arvind Sankar <[email protected]> Cc: Randy Dunlap <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Daniel Borkmann <[email protected]> Cc: Peter Zijlstra (Intel) <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Kees Cook <[email protected]> Fixes: 3193c08 ("bpf: Disable GCC -fgcse optimization for ___bpf_prog_run()") Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 1d9f23a commit 8bd44dd

File tree

4 files changed

+4
-8
lines changed

4 files changed

+4
-8
lines changed

include/linux/compiler-gcc.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,3 @@
175175
#else
176176
#define __diag_GCC_8(s)
177177
#endif
178-
179-
#define __no_fgcse __attribute__((optimize("-fno-gcse")))

include/linux/compiler_types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,6 @@ struct ftrace_likely_data {
247247
#define asm_inline asm
248248
#endif
249249

250-
#ifndef __no_fgcse
251-
# define __no_fgcse
252-
#endif
253-
254250
/* Are two types/vars the same type (ignoring qualifiers)? */
255251
#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
256252

kernel/bpf/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# SPDX-License-Identifier: GPL-2.0
22
obj-y := core.o
3-
CFLAGS_core.o += $(call cc-disable-warning, override-init)
3+
# ___bpf_prog_run() needs GCSE disabled on x86; see 3193c0836f203 for details
4+
cflags-core-$(CONFIG_X86) := -fno-gcse
5+
CFLAGS_core.o += $(call cc-disable-warning, override-init) $(cflags-core-y)
46

57
obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o bpf_iter.o map_iter.o task_iter.o prog_iter.o
68
obj-$(CONFIG_BPF_SYSCALL) += hashtab.o arraymap.o percpu_freelist.o bpf_lru_list.o lpm_trie.o map_in_map.o

kernel/bpf/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ u64 __weak bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
13691369
*
13701370
* Decode and execute eBPF instructions.
13711371
*/
1372-
static u64 __no_fgcse ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, u64 *stack)
1372+
static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, u64 *stack)
13731373
{
13741374
#define BPF_INSN_2_LBL(x, y) [BPF_##x | BPF_##y] = &&x##_##y
13751375
#define BPF_INSN_3_LBL(x, y, z) [BPF_##x | BPF_##y | BPF_##z] = &&x##_##y##_##z

0 commit comments

Comments
 (0)