History

bpf: Don't rely on GCC __attribute__((optimize)) to disable GCSE

Commit 3193c0836 ("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. This reverts commit 3193c0836, and instead, it disables the -fgcse optimization for the entire source file, but only when building for X86 using GCC with CONFIG_BPF_JIT_ALWAYS_ON disabled. Note that the original commit states that CONFIG_RETPOLINE=n triggers the issue, whereas CONFIG_RETPOLINE=y performs better without the optimization, so it is kept disabled in both cases.

Ard Biesheuvel committed 6 years ago

Commit 080b6f41 parent 0698ac64 files · +6 −8Browse files

Unified · Split

4 files
  1. include/linux/compiler-gcc.h +0 −2
  2. include/linux/compiler_types.h +0 −4
  3. kernel/bpf/Makefile +5 −1
  4. kernel/bpf/core.c +1 −1
include/linux/compiler-gcc.h+0−2
@@ -175,5 +175,3 @@ · 174 unmodified lines
175#else175#else
176#define __diag_GCC_8(s)176#define __diag_GCC_8(s)
177#endif177#endif
178
179#define __no_fgcse __attribute__((optimize("-fno-gcse")))
include/linux/compiler_types.h+0−4
@@ -247,10 +247,6 @@ struct ftrace_likely_data { · 246 unmodified lines
247#define asm_inline asm247#define asm_inline asm
248#endif248#endif
249 249
250#ifndef __no_fgcse
251# define __no_fgcse
252#endif
253
254/* Are two types/vars the same type (ignoring qualifiers)? */250/* Are two types/vars the same type (ignoring qualifiers)? */
255#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))251#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
256 252
kernel/bpf/Makefile+5−1
@@ -1,6 +1,10 @@
1# SPDX-License-Identifier: GPL-2.01# SPDX-License-Identifier: GPL-2.0
2obj-y := core.o2obj-y := core.o
3CFLAGS_core.o += $(call cc-disable-warning, override-init)3ifneq ($(CONFIG_BPF_JIT_ALWAYS_ON),y)
4# ___bpf_prog_run() needs GCSE disabled on x86; see 3193c0836f203 for details
5cflags-nogcse-$(CONFIG_X86)$(CONFIG_CC_IS_GCC) := -fno-gcse
6endif
7CFLAGS_core.o += $(call cc-disable-warning, override-init) $(cflags-nogcse-yy)
4 8
5obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o bpf_iter.o map_iter.o task_iter.o prog_iter.o9obj-$(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
6obj-$(CONFIG_BPF_SYSCALL) += hashtab.o arraymap.o percpu_freelist.o bpf_lru_list.o lpm_trie.o map_in_map.o10obj-$(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+1−1
@@ -1369,7 +1369,7 @@ u64 __weak bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr) · 1368 unmodified lines
1369 *1369 *
1370 * Decode and execute eBPF instructions.1370 * Decode and execute eBPF instructions.
1371 */1371 */
1372static u64 __no_fgcse ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, u64 *stack)1372static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, u64 *stack)
1373{1373{
1374#define BPF_INSN_2_LBL(x, y) [BPF_##x | BPF_##y] = &&x##_##y1374#define BPF_INSN_2_LBL(x, y) [BPF_##x | BPF_##y] = &&x##_##y
1375#define BPF_INSN_3_LBL(x, y, z) [BPF_##x | BPF_##y | BPF_##z] = &&x##_##y##_##z1375#define BPF_INSN_3_LBL(x, y, z) [BPF_##x | BPF_##y | BPF_##z] = &&x##_##y##_##z

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t