• Yonghong Song's avatar
    samples/bpf: workaround clang asm goto compilation errors · 217dd7c4
    Yonghong Song authored
    [ Upstream commit 6bf3bbe1 ]
    
    x86 compilation has required asm goto support since 4.17.
    Since clang does not support asm goto, at 4.17,
    Commit b1ae32db ("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: e769742d ("Revert "x86/jump-labels: Macrofy inline assembly code to work around GCC inlining bugs"")
    Fixes: 18fe5822 ("x86, asm: change the GEN_*_RMWcc() macros to not quote the condition")
    Acked-by: 's avatarAlexei Starovoitov <ast@kernel.org>
    Signed-off-by: 's avatarYonghong Song <yhs@fb.com>
    Signed-off-by: 's avatarDaniel Borkmann <daniel@iogearbox.net>
    Signed-off-by: 's avatarSasha Levin <sashal@kernel.org>
    217dd7c4
Name
Last commit
Last update
..
.gitignore Loading commit data...
Makefile Loading commit data...
README.rst Loading commit data...
asm_goto_workaround.h Loading commit data...
bpf_insn.h Loading commit data...
bpf_load.c Loading commit data...
bpf_load.h Loading commit data...
cookie_uid_helper_example.c Loading commit data...
cpustat_kern.c Loading commit data...
cpustat_user.c Loading commit data...
fds_example.c Loading commit data...
hash_func01.h Loading commit data...
lathist_kern.c Loading commit data...
lathist_user.c Loading commit data...
load_sock_ops.c Loading commit data...
lwt_len_hist.sh Loading commit data...
lwt_len_hist_kern.c Loading commit data...
lwt_len_hist_user.c Loading commit data...
map_perf_test_kern.c Loading commit data...
map_perf_test_user.c Loading commit data...
offwaketime_kern.c Loading commit data...
offwaketime_user.c Loading commit data...
parse_ldabs.c Loading commit data...
parse_simple.c Loading commit data...
parse_varlen.c Loading commit data...
run_cookie_uid_helper_example.sh Loading commit data...
sampleip_kern.c Loading commit data...
sampleip_user.c Loading commit data...
sock_example.c Loading commit data...
sock_example.h Loading commit data...
sock_flags_kern.c Loading commit data...
sockex1_kern.c Loading commit data...
sockex1_user.c Loading commit data...
sockex2_kern.c Loading commit data...
sockex2_user.c Loading commit data...
sockex3_kern.c Loading commit data...
sockex3_user.c Loading commit data...
spintest_kern.c Loading commit data...
spintest_user.c Loading commit data...
syscall_nrs.c Loading commit data...
syscall_tp_kern.c Loading commit data...
syscall_tp_user.c Loading commit data...
task_fd_query_kern.c Loading commit data...
task_fd_query_user.c Loading commit data...
tc_l2_redirect.sh Loading commit data...
tc_l2_redirect_kern.c Loading commit data...
tc_l2_redirect_user.c Loading commit data...
tcbpf1_kern.c Loading commit data...
tcp_basertt_kern.c Loading commit data...
tcp_bpf.readme Loading commit data...
tcp_bufs_kern.c Loading commit data...
tcp_clamp_kern.c Loading commit data...
tcp_cong_kern.c Loading commit data...
tcp_iw_kern.c Loading commit data...
tcp_rwnd_kern.c Loading commit data...
tcp_synrto_kern.c Loading commit data...
tcp_tos_reflect_kern.c Loading commit data...
test_cgrp2_array_pin.c Loading commit data...
test_cgrp2_attach.c Loading commit data...
test_cgrp2_attach2.c Loading commit data...
test_cgrp2_sock.c Loading commit data...
test_cgrp2_sock.sh Loading commit data...
test_cgrp2_sock2.c Loading commit data...
test_cgrp2_sock2.sh Loading commit data...
test_cgrp2_tc.sh Loading commit data...
test_cgrp2_tc_kern.c Loading commit data...
test_cls_bpf.sh Loading commit data...
test_current_task_under_cgroup_kern.c Loading commit data...
test_current_task_under_cgroup_user.c Loading commit data...
test_ipip.sh Loading commit data...
test_lru_dist.c Loading commit data...
test_lwt_bpf.c Loading commit data...
test_lwt_bpf.sh Loading commit data...
test_map_in_map_kern.c Loading commit data...
test_map_in_map_user.c Loading commit data...
test_overhead_kprobe_kern.c Loading commit data...
test_overhead_raw_tp_kern.c Loading commit data...
test_overhead_tp_kern.c Loading commit data...
test_overhead_user.c Loading commit data...
test_override_return.sh Loading commit data...
test_probe_write_user_kern.c Loading commit data...
test_probe_write_user_user.c Loading commit data...
trace_event_kern.c Loading commit data...
trace_event_user.c Loading commit data...
trace_output_kern.c Loading commit data...
trace_output_user.c Loading commit data...
tracex1_kern.c Loading commit data...
tracex1_user.c Loading commit data...
tracex2_kern.c Loading commit data...
tracex2_user.c Loading commit data...
tracex3_kern.c Loading commit data...
tracex3_user.c Loading commit data...
tracex4_kern.c Loading commit data...
tracex4_user.c Loading commit data...
tracex5_kern.c Loading commit data...
tracex5_user.c Loading commit data...
tracex6_kern.c Loading commit data...
tracex6_user.c Loading commit data...
tracex7_kern.c Loading commit data...
tracex7_user.c Loading commit data...
xdp1_kern.c Loading commit data...
xdp1_user.c Loading commit data...
xdp2_kern.c Loading commit data...
xdp2skb_meta.sh Loading commit data...
xdp2skb_meta_kern.c Loading commit data...
xdp_adjust_tail_kern.c Loading commit data...
xdp_adjust_tail_user.c Loading commit data...
xdp_fwd_kern.c Loading commit data...
xdp_fwd_user.c Loading commit data...
xdp_monitor_kern.c Loading commit data...
xdp_monitor_user.c Loading commit data...
xdp_redirect_cpu_kern.c Loading commit data...
xdp_redirect_cpu_user.c Loading commit data...
xdp_redirect_kern.c Loading commit data...
xdp_redirect_map_kern.c Loading commit data...
xdp_redirect_map_user.c Loading commit data...
xdp_redirect_user.c Loading commit data...
xdp_router_ipv4_kern.c Loading commit data...
xdp_router_ipv4_user.c Loading commit data...
xdp_rxq_info_kern.c Loading commit data...
xdp_rxq_info_user.c Loading commit data...
xdp_sample_pkts_kern.c Loading commit data...
xdp_sample_pkts_user.c Loading commit data...
xdp_tx_iptunnel_common.h Loading commit data...
xdp_tx_iptunnel_kern.c Loading commit data...
xdp_tx_iptunnel_user.c Loading commit data...
xdpsock.h Loading commit data...
xdpsock_kern.c Loading commit data...
xdpsock_user.c Loading commit data...