[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <8d793502-f7c9-d007-86bc-7cc7be7044da@iogearbox.net>
Date: Tue, 15 Jan 2019 21:02:02 +0100
From: Daniel Borkmann <daniel@...earbox.net>
To: Yonghong Song <yhs@...com>, ast@...com, netdev@...r.kernel.org
Cc: kernel-team@...com
Subject: Re: [PATCH bpf] samples/bpf: workaround clang asm goto compilation
errors
On 01/13/2019 12:04 AM, Yonghong Song wrote:
> 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: Alexei Starovoitov <ast@...nel.org>
> Signed-off-by: Yonghong Song <yhs@...com>
Applied, thanks!
Powered by blists - more mailing lists