• Yonghong Song's avatar
    samples/bpf: workaround clang asm goto compilation errors · 217dd7c4
    Yonghong Song authored
    [ Upstream commit 6bf3bbe1f4d4cf405e3c2bf07bbdff56d3223ec8 ]
    
    x86 compilation has required asm goto support since 4.17.
    Since clang does not support asm goto, at 4.17,
    Commit b1ae32dbab50 ("x86/cpufeature: Guard asm_volatile_goto usage
    for BPF compilation") worked around the issue by permitting an
    alternative implementation without asm goto for clang.
    
    At 5.0, more asm goto usages appeared.
      [yhs@148 x86]$ egrep -r asm_volatile_goto
      include/asm/cpufeature.h:     asm_volatile_goto("1: jmp 6f\n"
      include/asm/jump_label.h:     asm_volatile_goto("1:"
      include/asm/jump_label.h:     asm_volatile_goto("1:"
      include/asm/rmwcc.h:  asm_volatile_goto (fullop "; j" #cc " %l[cc_label]"     \
      include/asm/uaccess.h:        asm_volatile_goto("\n"                          \
      include/asm/uaccess.h:        asm_volatile_goto("\n"                          \
      [yhs@148 x86]$
    
    Compiling samples/bpf directories, most bpf programs failed
    compilation with error messages like:
      In file included from /home/yhs/work/bpf-next/samples/bpf/xdp_sample_pkts_kern.c:2:
      In file included from /home/yhs/work/bpf-next/include/linux/ptrace.h:6:
      In file included from /home/yhs/work/bpf-next/include/linux/sched.h:15:
      In file included from /home/yhs/work/bpf-next/include/linux/sem.h:5:
      In file included from /home/yhs/work/bpf-next/include/uapi/linux/sem.h:5:
      In file included from /home/yhs/work/bpf-next/include/linux/ipc.h:9:
      In file included from /home/yhs/work/bpf-next/include/linux/refcount.h:72:
      /home/yhs/work/bpf-next/arch/x86/include/asm/refcount.h:70:9: error: 'asm goto' constructs are not supported yet
            return GEN_BINARY_SUFFIXED_RMWcc(LOCK_PREFIX "subl",
                   ^
      /home/yhs/work/bpf-next/arch/x86/include/asm/rmwcc.h:67:2: note: expanded from macro 'GEN_BINARY_SUFFIXED_RMWcc'
            __GEN_RMWcc(op " %[val], %[var]\n\t" suffix, var, cc,           \
            ^
      /home/yhs/work/bpf-next/arch/x86/include/asm/rmwcc.h:21:2: note: expanded from macro '__GEN_RMWcc'
            asm_volatile_goto (fullop "; j" #cc " %l[cc_label]"             \
            ^
      /home/yhs/work/bpf-next/include/linux/compiler_types.h:188:37: note: expanded from macro 'asm_volatile_goto'
      #define asm_volatile_goto(x...) asm goto(x)
    
    Most implementation does not even provide an alternative
    implementation. And it is also not practical to make changes
    for each call site.
    
    This patch workarounded the asm goto issue by redefining the macro like below:
      #define asm_volatile_goto(x...) asm volatile("invalid use of asm_volatile_goto")
    
    If asm_volatile_goto is not used by bpf programs, which is typically the case, nothing bad
    will happen. If asm_volatile_goto is used by bpf programs, which is incorrect, the compiler
    will issue an error since "invalid use of asm_volatile_goto" is not valid assembly codes.
    
    With this patch, all bpf programs under samples/bpf can pass compilation.
    
    Note that bpf programs under tools/testing/selftests/bpf/ compiled fine as
    they do not access kernel internal headers.
    
    Fixes: e769742d3584 ("Revert "x86/jump-labels: Macrofy inline assembly code to work around GCC inlining bugs"")
    Fixes: 18fe58229d80 ("x86, asm: change the GEN_*_RMWcc() macros to not quote the condition")
    Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Signed-off-by: default avatarYonghong Song <yhs@fb.com>
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
    217dd7c4
Name
Last commit
Last update
..
auxdisplay Loading commit data...
bpf Loading commit data...
configfs Loading commit data...
connector Loading commit data...
hidraw Loading commit data...
hw_breakpoint Loading commit data...
kdb Loading commit data...
kfifo Loading commit data...
kobject Loading commit data...
kprobes Loading commit data...
livepatch Loading commit data...
mei Loading commit data...
mic/mpssd Loading commit data...
pktgen Loading commit data...
qmi Loading commit data...
rpmsg Loading commit data...
seccomp Loading commit data...
statx Loading commit data...
timers Loading commit data...
trace_events Loading commit data...
trace_printk Loading commit data...
uhid Loading commit data...
v4l Loading commit data...
vfio-mdev Loading commit data...
watchdog Loading commit data...
Kconfig Loading commit data...
Makefile Loading commit data...