All of lore.kernel.org
 help / color / mirror / Atom feed
* perf test LLVM & clang 6 failing
@ 2017-11-24 14:47 Arnaldo Carvalho de Melo
  2017-11-24 15:16 ` Daniel Borkmann
  0 siblings, 1 reply; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-11-24 14:47 UTC (permalink / raw)
  To: Wang Nan
  Cc: Alexei Starovoitov, Daniel Borkmann, Adrian Hunter, David Ahern,
	Jiri Olsa, Ingo Molnar, Namhyung Kim, Linux Kernel Mailing List

FYI, just noticed, recently updated clang to version 6, from its
upstream git repo.

root@jouet ~]# perf test -v LLVM
37: LLVM search and compile                               :
37.1: Basic BPF llvm compile                              :
--- start ---
test child forked, pid 5255
Kernel build dir is set to /lib/modules/4.14.0+/build
set env: KBUILD_DIR=/lib/modules/4.14.0+/build
unset env: KBUILD_OPTS
include option is set to  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h 
set env: NR_CPUS=4
set env: LINUX_VERSION_CODE=0x40e00
set env: CLANG_EXEC=/usr/local/bin/clang
set env: CLANG_OPTIONS=-xc 
set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h 
set env: WORKING_DIR=/lib/modules/4.14.0+/build
set env: CLANG_SOURCE=-
llvm compiling command template: echo '/*
 * bpf-script-example.c
 * Test basic LLVM building
 */
#ifndef LINUX_VERSION_CODE
# error Need LINUX_VERSION_CODE
# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
#endif
#define BPF_ANY 0
#define BPF_MAP_TYPE_ARRAY 2
#define BPF_FUNC_map_lookup_elem 1
#define BPF_FUNC_map_update_elem 2

static void *(*bpf_map_lookup_elem)(void *map, void *key) =
	(void *) BPF_FUNC_map_lookup_elem;
static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
	(void *) BPF_FUNC_map_update_elem;

struct bpf_map_def {
	unsigned int type;
	unsigned int key_size;
	unsigned int value_size;
	unsigned int max_entries;
};

#define SEC(NAME) __attribute__((section(NAME), used))
struct bpf_map_def SEC("maps") flip_table = {
	.type = BPF_MAP_TYPE_ARRAY,
	.key_size = sizeof(int),
	.value_size = sizeof(int),
	.max_entries = 1,
};

SEC("func=SyS_epoll_wait")
int bpf_func__SyS_epoll_wait(void *ctx)
{
	int ind =0;
	int *flag = bpf_map_lookup_elem(&flip_table, &ind);
	int new_flag;
	if (!flag)
		return 0;
	/* flip flag and store back */
	new_flag = !*flag;
	bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);
	return new_flag;
}
char _license[] SEC("license") = "GPL";
int _version SEC("version") = LINUX_VERSION_CODE;
' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
test child finished with 0
---- end ----
LLVM search and compile subtest 0: Ok
37.2: kbuild searching                                    :
--- start ---
test child forked, pid 5728
Kernel build dir is set to /lib/modules/4.14.0+/build
set env: KBUILD_DIR=/lib/modules/4.14.0+/build
unset env: KBUILD_OPTS
include option is set to  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h 
set env: NR_CPUS=4
set env: LINUX_VERSION_CODE=0x40e00
set env: CLANG_EXEC=/usr/local/bin/clang
set env: CLANG_OPTIONS=-xc 
set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h 
set env: WORKING_DIR=/lib/modules/4.14.0+/build
set env: CLANG_SOURCE=-
llvm compiling command template: echo '/*
 * bpf-script-test-kbuild.c
 * Test include from kernel header
 */
#ifndef LINUX_VERSION_CODE
# error Need LINUX_VERSION_CODE
# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
#endif
#define SEC(NAME) __attribute__((section(NAME), used))

#include <uapi/linux/fs.h>
#include <uapi/asm/ptrace.h>

SEC("func=vfs_llseek")
int bpf_func__vfs_llseek(void *ctx)
{
	return 0;
}

char _license[] SEC("license") = "GPL";
int _version SEC("version") = LINUX_VERSION_CODE;
' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
In file included from <stdin>:12:
In file included from /home/acme/git/linux/arch/x86/include/uapi/asm/ptrace.h:5:
In file included from /home/acme/git/linux/include/linux/compiler.h:237:
In file included from /home/acme/git/linux/arch/x86/include/asm/barrier.h:5:
In file included from /home/acme/git/linux/arch/x86/include/asm/alternative.h:10:
/home/acme/git/linux/arch/x86/include/asm/asm.h:145:50: error: unknown register name 'esp' in asm
register unsigned long current_stack_pointer asm(_ASM_SP);
                                                 ^
/home/acme/git/linux/arch/x86/include/asm/asm.h:44:18: note: expanded from macro '_ASM_SP'
#define _ASM_SP         __ASM_REG(sp)
                        ^
/home/acme/git/linux/arch/x86/include/asm/asm.h:27:32: note: expanded from macro '__ASM_REG'
#define __ASM_REG(reg)         __ASM_SEL_RAW(e##reg, r##reg)
                               ^
/home/acme/git/linux/arch/x86/include/asm/asm.h:18:29: note: expanded from macro '__ASM_SEL_RAW'
# define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(a)
                            ^
/home/acme/git/linux/arch/x86/include/asm/asm.h:11:32: note: expanded from macro '__ASM_FORM_RAW'
# define __ASM_FORM_RAW(x)     #x
                               ^
<scratch space>:4:1: note: expanded from here
"esp"
^
1 error generated.
ERROR:	unable to compile -
Hint:	Check error message shown above.
Hint:	You can also pre-compile it into .o using:
     		clang -target bpf -O2 -c -
     	with proper -I and -D options.
Failed to compile test case: 'kbuild searching'
test child finished with -1
---- end ----
LLVM search and compile subtest 1: FAILED!
37.3: Compile source for BPF prologue generation          :
--- force skipped ---
LLVM search and compile subtest 2: Skip
37.4: Compile source for BPF relocation                   :
--- force skipped ---
LLVM search and compile subtest 3: Skip
[root@jouet ~]# clang -v
clang version 6.0.0 (http://llvm.org/git/clang.git 56cc8f8880db2ebc433eeb6b6a707c101467a186) (http://llvm.org/git/llvm.git 3656d83960a4f3fedf6d8f19043abf52379f78c3)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/7
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/7
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
[root@jouet ~]#

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: perf test LLVM & clang 6 failing
  2017-11-24 14:47 perf test LLVM & clang 6 failing Arnaldo Carvalho de Melo
@ 2017-11-24 15:16 ` Daniel Borkmann
  2017-11-24 19:09   ` Arnaldo Carvalho de Melo
  2017-11-27 17:04   ` Arnaldo Carvalho de Melo
  0 siblings, 2 replies; 15+ messages in thread
From: Daniel Borkmann @ 2017-11-24 15:16 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Wang Nan
  Cc: Alexei Starovoitov, Adrian Hunter, David Ahern, Jiri Olsa,
	Ingo Molnar, Namhyung Kim, Linux Kernel Mailing List, yhs

[ +Yonghong ]

On 11/24/2017 03:47 PM, Arnaldo Carvalho de Melo wrote:
> FYI, just noticed, recently updated clang to version 6, from its
> upstream git repo.

Do you recall what was your LLVM version prior to this where it was
working fine? (Wild guess from below would be the BPF inline asm
support that was added recently to LLVM (2865ab6996) vs asm() used
in headers included in the stdin header causing trouble due to arch
mixup?)

> root@jouet ~]# perf test -v LLVM
> 37: LLVM search and compile                               :
> 37.1: Basic BPF llvm compile                              :
> --- start ---
> test child forked, pid 5255
> Kernel build dir is set to /lib/modules/4.14.0+/build
> set env: KBUILD_DIR=/lib/modules/4.14.0+/build
> unset env: KBUILD_OPTS
> include option is set to  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h 
> set env: NR_CPUS=4
> set env: LINUX_VERSION_CODE=0x40e00
> set env: CLANG_EXEC=/usr/local/bin/clang
> set env: CLANG_OPTIONS=-xc 
> set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h 
> set env: WORKING_DIR=/lib/modules/4.14.0+/build
> set env: CLANG_SOURCE=-
> llvm compiling command template: echo '/*
>  * bpf-script-example.c
>  * Test basic LLVM building
>  */
> #ifndef LINUX_VERSION_CODE
> # error Need LINUX_VERSION_CODE
> # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
> #endif
> #define BPF_ANY 0
> #define BPF_MAP_TYPE_ARRAY 2
> #define BPF_FUNC_map_lookup_elem 1
> #define BPF_FUNC_map_update_elem 2
> 
> static void *(*bpf_map_lookup_elem)(void *map, void *key) =
> 	(void *) BPF_FUNC_map_lookup_elem;
> static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
> 	(void *) BPF_FUNC_map_update_elem;
> 
> struct bpf_map_def {
> 	unsigned int type;
> 	unsigned int key_size;
> 	unsigned int value_size;
> 	unsigned int max_entries;
> };
> 
> #define SEC(NAME) __attribute__((section(NAME), used))
> struct bpf_map_def SEC("maps") flip_table = {
> 	.type = BPF_MAP_TYPE_ARRAY,
> 	.key_size = sizeof(int),
> 	.value_size = sizeof(int),
> 	.max_entries = 1,
> };
> 
> SEC("func=SyS_epoll_wait")
> int bpf_func__SyS_epoll_wait(void *ctx)
> {
> 	int ind =0;
> 	int *flag = bpf_map_lookup_elem(&flip_table, &ind);
> 	int new_flag;
> 	if (!flag)
> 		return 0;
> 	/* flip flag and store back */
> 	new_flag = !*flag;
> 	bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);
> 	return new_flag;
> }
> char _license[] SEC("license") = "GPL";
> int _version SEC("version") = LINUX_VERSION_CODE;
> ' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
> test child finished with 0
> ---- end ----
> LLVM search and compile subtest 0: Ok
> 37.2: kbuild searching                                    :
> --- start ---
> test child forked, pid 5728
> Kernel build dir is set to /lib/modules/4.14.0+/build
> set env: KBUILD_DIR=/lib/modules/4.14.0+/build
> unset env: KBUILD_OPTS
> include option is set to  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h 
> set env: NR_CPUS=4
> set env: LINUX_VERSION_CODE=0x40e00
> set env: CLANG_EXEC=/usr/local/bin/clang
> set env: CLANG_OPTIONS=-xc 
> set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h 
> set env: WORKING_DIR=/lib/modules/4.14.0+/build
> set env: CLANG_SOURCE=-
> llvm compiling command template: echo '/*
>  * bpf-script-test-kbuild.c
>  * Test include from kernel header
>  */
> #ifndef LINUX_VERSION_CODE
> # error Need LINUX_VERSION_CODE
> # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
> #endif
> #define SEC(NAME) __attribute__((section(NAME), used))
> 
> #include <uapi/linux/fs.h>
> #include <uapi/asm/ptrace.h>
> 
> SEC("func=vfs_llseek")
> int bpf_func__vfs_llseek(void *ctx)
> {
> 	return 0;
> }
> 
> char _license[] SEC("license") = "GPL";
> int _version SEC("version") = LINUX_VERSION_CODE;
> ' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
> In file included from <stdin>:12:
> In file included from /home/acme/git/linux/arch/x86/include/uapi/asm/ptrace.h:5:
> In file included from /home/acme/git/linux/include/linux/compiler.h:237:
> In file included from /home/acme/git/linux/arch/x86/include/asm/barrier.h:5:
> In file included from /home/acme/git/linux/arch/x86/include/asm/alternative.h:10:
> /home/acme/git/linux/arch/x86/include/asm/asm.h:145:50: error: unknown register name 'esp' in asm
> register unsigned long current_stack_pointer asm(_ASM_SP);
>                                                  ^
> /home/acme/git/linux/arch/x86/include/asm/asm.h:44:18: note: expanded from macro '_ASM_SP'
> #define _ASM_SP         __ASM_REG(sp)
>                         ^
> /home/acme/git/linux/arch/x86/include/asm/asm.h:27:32: note: expanded from macro '__ASM_REG'
> #define __ASM_REG(reg)         __ASM_SEL_RAW(e##reg, r##reg)
>                                ^
> /home/acme/git/linux/arch/x86/include/asm/asm.h:18:29: note: expanded from macro '__ASM_SEL_RAW'
> # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(a)
>                             ^
> /home/acme/git/linux/arch/x86/include/asm/asm.h:11:32: note: expanded from macro '__ASM_FORM_RAW'
> # define __ASM_FORM_RAW(x)     #x
>                                ^
> <scratch space>:4:1: note: expanded from here
> "esp"
> ^
> 1 error generated.
> ERROR:	unable to compile -
> Hint:	Check error message shown above.
> Hint:	You can also pre-compile it into .o using:
>      		clang -target bpf -O2 -c -
>      	with proper -I and -D options.
> Failed to compile test case: 'kbuild searching'
> test child finished with -1
> ---- end ----
> LLVM search and compile subtest 1: FAILED!
> 37.3: Compile source for BPF prologue generation          :
> --- force skipped ---
> LLVM search and compile subtest 2: Skip
> 37.4: Compile source for BPF relocation                   :
> --- force skipped ---
> LLVM search and compile subtest 3: Skip
> [root@jouet ~]# clang -v
> clang version 6.0.0 (http://llvm.org/git/clang.git 56cc8f8880db2ebc433eeb6b6a707c101467a186) (http://llvm.org/git/llvm.git 3656d83960a4f3fedf6d8f19043abf52379f78c3)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /usr/local/bin
> Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/7
> Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/7
> Candidate multilib: .;@m64
> Candidate multilib: 32;@m32
> Selected multilib: .;@m64
> [root@jouet ~]#
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: perf test LLVM & clang 6 failing
  2017-11-24 15:16 ` Daniel Borkmann
@ 2017-11-24 19:09   ` Arnaldo Carvalho de Melo
  2017-11-26  6:29     ` Yonghong Song
  2017-11-27 17:04   ` Arnaldo Carvalho de Melo
  1 sibling, 1 reply; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-11-24 19:09 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Wang Nan, Alexei Starovoitov, Adrian Hunter, David Ahern,
	Jiri Olsa, Ingo Molnar, Namhyung Kim, Linux Kernel Mailing List,
	yhs

Em Fri, Nov 24, 2017 at 04:16:52PM +0100, Daniel Borkmann escreveu:
> [ +Yonghong ]
> 
> On 11/24/2017 03:47 PM, Arnaldo Carvalho de Melo wrote:
> > FYI, just noticed, recently updated clang to version 6, from its
> > upstream git repo.
> 
> Do you recall what was your LLVM version prior to this where it was
> working fine? (Wild guess from below would be the BPF inline asm

IIRC it was 4.0

> support that was added recently to LLVM (2865ab6996) vs asm() used
> in headers included in the stdin header causing trouble due to arch
> mixup?)
> 
> > root@jouet ~]# perf test -v LLVM
> > 37: LLVM search and compile                               :
> > 37.1: Basic BPF llvm compile                              :
> > --- start ---
> > test child forked, pid 5255
> > Kernel build dir is set to /lib/modules/4.14.0+/build
> > set env: KBUILD_DIR=/lib/modules/4.14.0+/build
> > unset env: KBUILD_OPTS
> > include option is set to  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h 
> > set env: NR_CPUS=4
> > set env: LINUX_VERSION_CODE=0x40e00
> > set env: CLANG_EXEC=/usr/local/bin/clang
> > set env: CLANG_OPTIONS=-xc 
> > set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h 
> > set env: WORKING_DIR=/lib/modules/4.14.0+/build
> > set env: CLANG_SOURCE=-
> > llvm compiling command template: echo '/*
> >  * bpf-script-example.c
> >  * Test basic LLVM building
> >  */
> > #ifndef LINUX_VERSION_CODE
> > # error Need LINUX_VERSION_CODE
> > # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
> > #endif
> > #define BPF_ANY 0
> > #define BPF_MAP_TYPE_ARRAY 2
> > #define BPF_FUNC_map_lookup_elem 1
> > #define BPF_FUNC_map_update_elem 2
> > 
> > static void *(*bpf_map_lookup_elem)(void *map, void *key) =
> > 	(void *) BPF_FUNC_map_lookup_elem;
> > static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
> > 	(void *) BPF_FUNC_map_update_elem;
> > 
> > struct bpf_map_def {
> > 	unsigned int type;
> > 	unsigned int key_size;
> > 	unsigned int value_size;
> > 	unsigned int max_entries;
> > };
> > 
> > #define SEC(NAME) __attribute__((section(NAME), used))
> > struct bpf_map_def SEC("maps") flip_table = {
> > 	.type = BPF_MAP_TYPE_ARRAY,
> > 	.key_size = sizeof(int),
> > 	.value_size = sizeof(int),
> > 	.max_entries = 1,
> > };
> > 
> > SEC("func=SyS_epoll_wait")
> > int bpf_func__SyS_epoll_wait(void *ctx)
> > {
> > 	int ind =0;
> > 	int *flag = bpf_map_lookup_elem(&flip_table, &ind);
> > 	int new_flag;
> > 	if (!flag)
> > 		return 0;
> > 	/* flip flag and store back */
> > 	new_flag = !*flag;
> > 	bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);
> > 	return new_flag;
> > }
> > char _license[] SEC("license") = "GPL";
> > int _version SEC("version") = LINUX_VERSION_CODE;
> > ' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
> > test child finished with 0
> > ---- end ----
> > LLVM search and compile subtest 0: Ok
> > 37.2: kbuild searching                                    :
> > --- start ---
> > test child forked, pid 5728
> > Kernel build dir is set to /lib/modules/4.14.0+/build
> > set env: KBUILD_DIR=/lib/modules/4.14.0+/build
> > unset env: KBUILD_OPTS
> > include option is set to  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h 
> > set env: NR_CPUS=4
> > set env: LINUX_VERSION_CODE=0x40e00
> > set env: CLANG_EXEC=/usr/local/bin/clang
> > set env: CLANG_OPTIONS=-xc 
> > set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h 
> > set env: WORKING_DIR=/lib/modules/4.14.0+/build
> > set env: CLANG_SOURCE=-
> > llvm compiling command template: echo '/*
> >  * bpf-script-test-kbuild.c
> >  * Test include from kernel header
> >  */
> > #ifndef LINUX_VERSION_CODE
> > # error Need LINUX_VERSION_CODE
> > # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
> > #endif
> > #define SEC(NAME) __attribute__((section(NAME), used))
> > 
> > #include <uapi/linux/fs.h>
> > #include <uapi/asm/ptrace.h>
> > 
> > SEC("func=vfs_llseek")
> > int bpf_func__vfs_llseek(void *ctx)
> > {
> > 	return 0;
> > }
> > 
> > char _license[] SEC("license") = "GPL";
> > int _version SEC("version") = LINUX_VERSION_CODE;
> > ' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
> > In file included from <stdin>:12:
> > In file included from /home/acme/git/linux/arch/x86/include/uapi/asm/ptrace.h:5:
> > In file included from /home/acme/git/linux/include/linux/compiler.h:237:
> > In file included from /home/acme/git/linux/arch/x86/include/asm/barrier.h:5:
> > In file included from /home/acme/git/linux/arch/x86/include/asm/alternative.h:10:
> > /home/acme/git/linux/arch/x86/include/asm/asm.h:145:50: error: unknown register name 'esp' in asm
> > register unsigned long current_stack_pointer asm(_ASM_SP);
> >                                                  ^
> > /home/acme/git/linux/arch/x86/include/asm/asm.h:44:18: note: expanded from macro '_ASM_SP'
> > #define _ASM_SP         __ASM_REG(sp)
> >                         ^
> > /home/acme/git/linux/arch/x86/include/asm/asm.h:27:32: note: expanded from macro '__ASM_REG'
> > #define __ASM_REG(reg)         __ASM_SEL_RAW(e##reg, r##reg)
> >                                ^
> > /home/acme/git/linux/arch/x86/include/asm/asm.h:18:29: note: expanded from macro '__ASM_SEL_RAW'
> > # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(a)
> >                             ^
> > /home/acme/git/linux/arch/x86/include/asm/asm.h:11:32: note: expanded from macro '__ASM_FORM_RAW'
> > # define __ASM_FORM_RAW(x)     #x
> >                                ^
> > <scratch space>:4:1: note: expanded from here
> > "esp"
> > ^
> > 1 error generated.
> > ERROR:	unable to compile -
> > Hint:	Check error message shown above.
> > Hint:	You can also pre-compile it into .o using:
> >      		clang -target bpf -O2 -c -
> >      	with proper -I and -D options.
> > Failed to compile test case: 'kbuild searching'
> > test child finished with -1
> > ---- end ----
> > LLVM search and compile subtest 1: FAILED!
> > 37.3: Compile source for BPF prologue generation          :
> > --- force skipped ---
> > LLVM search and compile subtest 2: Skip
> > 37.4: Compile source for BPF relocation                   :
> > --- force skipped ---
> > LLVM search and compile subtest 3: Skip
> > [root@jouet ~]# clang -v
> > clang version 6.0.0 (http://llvm.org/git/clang.git 56cc8f8880db2ebc433eeb6b6a707c101467a186) (http://llvm.org/git/llvm.git 3656d83960a4f3fedf6d8f19043abf52379f78c3)
> > Target: x86_64-unknown-linux-gnu
> > Thread model: posix
> > InstalledDir: /usr/local/bin
> > Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/7
> > Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/7
> > Candidate multilib: .;@m64
> > Candidate multilib: 32;@m32
> > Selected multilib: .;@m64
> > [root@jouet ~]#
> > 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: perf test LLVM & clang 6 failing
  2017-11-24 19:09   ` Arnaldo Carvalho de Melo
@ 2017-11-26  6:29     ` Yonghong Song
  0 siblings, 0 replies; 15+ messages in thread
From: Yonghong Song @ 2017-11-26  6:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Daniel Borkmann
  Cc: Wang Nan, Alexei Starovoitov, Adrian Hunter, David Ahern,
	Jiri Olsa, Ingo Molnar, Namhyung Kim, Linux Kernel Mailing List



On 11/24/17 11:09 AM, Arnaldo Carvalho de Melo wrote:
> Em Fri, Nov 24, 2017 at 04:16:52PM +0100, Daniel Borkmann escreveu:
>> [ +Yonghong ]
>>
>> On 11/24/2017 03:47 PM, Arnaldo Carvalho de Melo wrote:
>>> FYI, just noticed, recently updated clang to version 6, from its
>>> upstream git repo.
>>
>> Do you recall what was your LLVM version prior to this where it was
>> working fine? (Wild guess from below would be the BPF inline asm
> 
> IIRC it was 4.0

I tried the following example (the almost the same one as the failed
compilation one before except a few SEC(...) marking which should not
impact the result):

$ cat bpf_prog.c
#include <uapi/linux/fs.h>
#include <uapi/asm/ptrace.h>

int bpf_func__vfs_llseek(void *ctx)
{
         return 0;
}
$ cat run.sh
KERNEL_INC_OPTIONS="-nostdinc -isystem 
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include 
-I/home/yhs/work/net-next/arch/x86/include 
-I/home/yhs/work/linux-bld/arch/x86/include 
-I/home/yhs/work/net-next/include -I/home/yhs/work/linux-bld/include 
-I/home/yhs/work/net-next/arch/x86/include/uapi 
-I/home/yhs/work/linux-bld/arch/x86/include/generated/uapi 
-I/home/yhs/work/net-next/include/uapi 
-I/home/yhs/work/linux-bld/include/generated/uapi -include 
/home/yhs/work/net-next/include/linux/kconfig.h"

clang -D__KERNEL__ -D__NR_CPUS__=4 -xc \
       $KERNEL_INC_OPTIONS \
       -Wno-unused-value -Wno-pointer-sign \
       -c bpf_prog.c -O2 -target bpf
$

You can actually get KERNEL_INC_OPTIONS by compiling kernel samples/bpf.

This program failed at both llvm 4.0 and latest trunk (6.0).

The same symptom:
In file included from bpf_prog.c:2:
In file included from 
/home/yhs/work/net-next/arch/x86/include/uapi/asm/ptrace.h:5:
In file included from /home/yhs/work/net-next/include/linux/compiler.h:237:
In file included from 
/home/yhs/work/net-next/arch/x86/include/asm/barrier.h:5:
In file included from 
/home/yhs/work/net-next/arch/x86/include/asm/alternative.h:10:
/home/yhs/work/net-next/arch/x86/include/asm/asm.h:145:50: error: 
unknown register name 'esp' in asm
register unsigned long current_stack_pointer asm(_ASM_SP);
                                                  ^
/home/yhs/work/net-next/arch/x86/include/asm/asm.h:44:18: note: expanded 
from macro '_ASM_SP'
#define _ASM_SP         __ASM_REG(sp)

I suggest that you use the same compilation process as
samples/bpf and tools/testing/selftests/bpf:

$ cat run1.sh
KERNEL_INC_OPTIONS="-nostdinc -isystem 
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include 
-I/home/yhs/work/net-next/arch/x86/include 
-I/home/yhs/work/linux-bld/arch/x86/include 
-I/home/yhs/work/net-next/include -I/home/yhs/work/linux-bld/include 
-I/home/yhs/work/net-next/arch/x86/include/uapi 
-I/home/yhs/work/linux-bld/arch/x86/include/generated/uapi 
-I/home/yhs/work/net-next/include/uapi 
-I/home/yhs/work/linux-bld/include/generated/uapi -include 
/home/yhs/work/net-next/include/linux/kconfig.h"

clang -D__KERNEL__ -D__NR_CPUS__=4 -xc \
       $KERNEL_INC_OPTIONS \
       -Wno-unused-value -Wno-pointer-sign \
       -c bpf_prog.c -O2 -emit-llvm -S
llc -filetype=obj -march=bpf bpf_prog.ll
$

This is especially true if you are doing tracing there ptrace.h may be 
included in your header files.

The "clang" compiler will be able to handle host inline asm properly and
filter out functions which uses host inline asm's. If any file-level
inline asms are still left (e.g., arm64), the llvm 6.0 should be able
to handle this but not llvm 4.0.

> 
>> support that was added recently to LLVM (2865ab6996) vs asm() used
>> in headers included in the stdin header causing trouble due to arch
>> mixup?)
>>
>>> root@jouet ~]# perf test -v LLVM
>>> 37: LLVM search and compile                               :
>>> 37.1: Basic BPF llvm compile                              :
>>> --- start ---
>>> test child forked, pid 5255
>>> Kernel build dir is set to /lib/modules/4.14.0+/build
>>> set env: KBUILD_DIR=/lib/modules/4.14.0+/build
>>> unset env: KBUILD_OPTS
>>> include option is set to  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h
>>> set env: NR_CPUS=4
>>> set env: LINUX_VERSION_CODE=0x40e00
>>> set env: CLANG_EXEC=/usr/local/bin/clang
>>> set env: CLANG_OPTIONS=-xc
>>> set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h
>>> set env: WORKING_DIR=/lib/modules/4.14.0+/build
>>> set env: CLANG_SOURCE=-
>>> llvm compiling command template: echo '/*
>>>   * bpf-script-example.c
>>>   * Test basic LLVM building
>>>   */
>>> #ifndef LINUX_VERSION_CODE
>>> # error Need LINUX_VERSION_CODE
>>> # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
>>> #endif
>>> #define BPF_ANY 0
>>> #define BPF_MAP_TYPE_ARRAY 2
>>> #define BPF_FUNC_map_lookup_elem 1
>>> #define BPF_FUNC_map_update_elem 2
>>>
>>> static void *(*bpf_map_lookup_elem)(void *map, void *key) =
>>> 	(void *) BPF_FUNC_map_lookup_elem;
>>> static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
>>> 	(void *) BPF_FUNC_map_update_elem;
>>>
>>> struct bpf_map_def {
>>> 	unsigned int type;
>>> 	unsigned int key_size;
>>> 	unsigned int value_size;
>>> 	unsigned int max_entries;
>>> };
>>>
>>> #define SEC(NAME) __attribute__((section(NAME), used))
>>> struct bpf_map_def SEC("maps") flip_table = {
>>> 	.type = BPF_MAP_TYPE_ARRAY,
>>> 	.key_size = sizeof(int),
>>> 	.value_size = sizeof(int),
>>> 	.max_entries = 1,
>>> };
>>>
>>> SEC("func=SyS_epoll_wait")
>>> int bpf_func__SyS_epoll_wait(void *ctx)
>>> {
>>> 	int ind =0;
>>> 	int *flag = bpf_map_lookup_elem(&flip_table, &ind);
>>> 	int new_flag;
>>> 	if (!flag)
>>> 		return 0;
>>> 	/* flip flag and store back */
>>> 	new_flag = !*flag;
>>> 	bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);
>>> 	return new_flag;
>>> }
>>> char _license[] SEC("license") = "GPL";
>>> int _version SEC("version") = LINUX_VERSION_CODE;
>>> ' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
>>> test child finished with 0
>>> ---- end ----
>>> LLVM search and compile subtest 0: Ok
>>> 37.2: kbuild searching                                    :
>>> --- start ---
>>> test child forked, pid 5728
>>> Kernel build dir is set to /lib/modules/4.14.0+/build
>>> set env: KBUILD_DIR=/lib/modules/4.14.0+/build
>>> unset env: KBUILD_OPTS
>>> include option is set to  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h
>>> set env: NR_CPUS=4
>>> set env: LINUX_VERSION_CODE=0x40e00
>>> set env: CLANG_EXEC=/usr/local/bin/clang
>>> set env: CLANG_OPTIONS=-xc
>>> set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h
>>> set env: WORKING_DIR=/lib/modules/4.14.0+/build
>>> set env: CLANG_SOURCE=-
>>> llvm compiling command template: echo '/*
>>>   * bpf-script-test-kbuild.c
>>>   * Test include from kernel header
>>>   */
>>> #ifndef LINUX_VERSION_CODE
>>> # error Need LINUX_VERSION_CODE
>>> # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
>>> #endif
>>> #define SEC(NAME) __attribute__((section(NAME), used))
>>>
>>> #include <uapi/linux/fs.h>
>>> #include <uapi/asm/ptrace.h>
>>>
>>> SEC("func=vfs_llseek")
>>> int bpf_func__vfs_llseek(void *ctx)
>>> {
>>> 	return 0;
>>> }
>>>
>>> char _license[] SEC("license") = "GPL";
>>> int _version SEC("version") = LINUX_VERSION_CODE;
>>> ' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
>>> In file included from <stdin>:12:
>>> In file included from /home/acme/git/linux/arch/x86/include/uapi/asm/ptrace.h:5:
>>> In file included from /home/acme/git/linux/include/linux/compiler.h:237:
>>> In file included from /home/acme/git/linux/arch/x86/include/asm/barrier.h:5:
>>> In file included from /home/acme/git/linux/arch/x86/include/asm/alternative.h:10:
>>> /home/acme/git/linux/arch/x86/include/asm/asm.h:145:50: error: unknown register name 'esp' in asm
>>> register unsigned long current_stack_pointer asm(_ASM_SP);
>>>                                                   ^
>>> /home/acme/git/linux/arch/x86/include/asm/asm.h:44:18: note: expanded from macro '_ASM_SP'
>>> #define _ASM_SP         __ASM_REG(sp)
>>>                          ^
>>> /home/acme/git/linux/arch/x86/include/asm/asm.h:27:32: note: expanded from macro '__ASM_REG'
>>> #define __ASM_REG(reg)         __ASM_SEL_RAW(e##reg, r##reg)
>>>                                 ^
>>> /home/acme/git/linux/arch/x86/include/asm/asm.h:18:29: note: expanded from macro '__ASM_SEL_RAW'
>>> # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(a)
>>>                              ^
>>> /home/acme/git/linux/arch/x86/include/asm/asm.h:11:32: note: expanded from macro '__ASM_FORM_RAW'
>>> # define __ASM_FORM_RAW(x)     #x
>>>                                 ^
>>> <scratch space>:4:1: note: expanded from here
>>> "esp"
>>> ^
>>> 1 error generated.
>>> ERROR:	unable to compile -
>>> Hint:	Check error message shown above.
>>> Hint:	You can also pre-compile it into .o using:
>>>       		clang -target bpf -O2 -c -
>>>       	with proper -I and -D options.
>>> Failed to compile test case: 'kbuild searching'
>>> test child finished with -1
>>> ---- end ----
>>> LLVM search and compile subtest 1: FAILED!
>>> 37.3: Compile source for BPF prologue generation          :
>>> --- force skipped ---
>>> LLVM search and compile subtest 2: Skip
>>> 37.4: Compile source for BPF relocation                   :
>>> --- force skipped ---
>>> LLVM search and compile subtest 3: Skip
>>> [root@jouet ~]# clang -v
>>> clang version 6.0.0 (https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_git_clang.git&d=DwIBAg&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=z5qVLSWJOX6g2fVdnv6PkJEj6w9ZeuUbyGZiXHbXR8o&s=e4qbhCUq0iI5gnbkZLhFvoo0HDFpRyIjElZsWLCJlZc&e= 56cc8f8880db2ebc433eeb6b6a707c101467a186) (https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_git_llvm.git&d=DwIBAg&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=z5qVLSWJOX6g2fVdnv6PkJEj6w9ZeuUbyGZiXHbXR8o&s=1kpNkh0Slwca73HtsdX4NxJzsEM5vRjayUu-GQldnU8&e= 3656d83960a4f3fedf6d8f19043abf52379f78c3)
>>> Target: x86_64-unknown-linux-gnu
>>> Thread model: posix
>>> InstalledDir: /usr/local/bin
>>> Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/7
>>> Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/7
>>> Candidate multilib: .;@m64
>>> Candidate multilib: 32;@m32
>>> Selected multilib: .;@m64
>>> [root@jouet ~]#
>>>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: perf test LLVM & clang 6 failing
  2017-11-24 15:16 ` Daniel Borkmann
  2017-11-24 19:09   ` Arnaldo Carvalho de Melo
@ 2017-11-27 17:04   ` Arnaldo Carvalho de Melo
  2017-11-27 19:11     ` Yonghong Song
  1 sibling, 1 reply; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-11-27 17:04 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Josh Poimboeuf, Wang Nan, Alexei Starovoitov, Adrian Hunter,
	David Ahern, Jiri Olsa, Ingo Molnar, Namhyung Kim,
	Linux Kernel Mailing List, yhs

Em Fri, Nov 24, 2017 at 04:16:52PM +0100, Daniel Borkmann escreveu:
> [ +Yonghong ]

+ Josh
 
> On 11/24/2017 03:47 PM, Arnaldo Carvalho de Melo wrote:
> > FYI, just noticed, recently updated clang to version 6, from its
> > upstream git repo.
> 
> Do you recall what was your LLVM version prior to this where it was
> working fine? (Wild guess from below would be the BPF inline asm
> support that was added recently to LLVM (2865ab6996) vs asm() used
> in headers included in the stdin header causing trouble due to arch
> mixup?)

So, if I go to the cset just before:

commit f5caf621ee357279e759c0911daf6d55c7d36f03
Author: Josh Poimboeuf <jpoimboe@redhat.com>
Date:   Wed Sep 20 16:24:33 2017 -0500

    x86/asm: Fix inline asm call constraints for Clang
---

'perf test LLVM' works again:

[root@jouet ~]# perf test LLVM
37: LLVM search and compile                               :
37.1: Basic BPF llvm compile                              : Ok
37.2: kbuild searching                                    : Ok
37.3: Compile source for BPF prologue generation          : Ok
37.4: Compile source for BPF relocation                   : Ok
[root@jouet ~]#

I.e. 'perf test LLVM' built from what is in my acme/perf/urgent branch,
targetted to v4.15, uses kernel headers and if I go to just before
f5caf621ee, it works again, both with clang from fedora26 (4.0.1) and
with 6.0, built from sources.

'perf test BPF' breaks for another reason, needs another investigation,
maybe you guys can spot something changed recently in that area:

libbpf: failed to create map (name: 'flip_table'): Invalid argument
libbpf: failed to load object '[basic_bpf_test]'

Complete logs up to this error are below, I'll go read Yonghong message
to see if I can get the 'perf test LLVM' case fixed.

- Arnaldo

[root@jouet ~]# perf test BPF
39: BPF filter                                            :
39.1: Basic BPF filtering                                 : FAILED!
39.2: BPF pinning                                         : Skip
39.3: BPF prologue generation                             : Skip
39.4: BPF relocation checker                              : Skip
[root@jouet ~]# perf test -v BPF
39: BPF filter                                            :
39.1: Basic BPF filtering                                 :
--- start ---
test child forked, pid 3541
Kernel build dir is set to /lib/modules/4.14.0+/build
set env: KBUILD_DIR=/lib/modules/4.14.0+/build
unset env: KBUILD_OPTS
include option is set to  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h 
set env: NR_CPUS=4
set env: LINUX_VERSION_CODE=0x40e00
set env: CLANG_EXEC=/usr/lib64/ccache/clang
set env: CLANG_OPTIONS=-xc 
set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h 
set env: WORKING_DIR=/lib/modules/4.14.0+/build
set env: CLANG_SOURCE=-
llvm compiling command template: echo '/*
 * bpf-script-example.c
 * Test basic LLVM building
 */
#ifndef LINUX_VERSION_CODE
# error Need LINUX_VERSION_CODE
# error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
#endif
#define BPF_ANY 0
#define BPF_MAP_TYPE_ARRAY 2
#define BPF_FUNC_map_lookup_elem 1
#define BPF_FUNC_map_update_elem 2

static void *(*bpf_map_lookup_elem)(void *map, void *key) =
	(void *) BPF_FUNC_map_lookup_elem;
static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
	(void *) BPF_FUNC_map_update_elem;

struct bpf_map_def {
	unsigned int type;
	unsigned int key_size;
	unsigned int value_size;
	unsigned int max_entries;
};

#define SEC(NAME) __attribute__((section(NAME), used))
struct bpf_map_def SEC("maps") flip_table = {
	.type = BPF_MAP_TYPE_ARRAY,
	.key_size = sizeof(int),
	.value_size = sizeof(int),
	.max_entries = 1,
};

SEC("func=SyS_epoll_wait")
int bpf_func__SyS_epoll_wait(void *ctx)
{
	int ind =0;
	int *flag = bpf_map_lookup_elem(&flip_table, &ind);
	int new_flag;
	if (!flag)
		return 0;
	/* flip flag and store back */
	new_flag = !*flag;
	bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);
	return new_flag;
}
char _license[] SEC("license") = "GPL";
int _version SEC("version") = LINUX_VERSION_CODE;
' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
libbpf: loading object '[basic_bpf_test]' from buffer
libbpf: section .strtab, size 120, link 0, flags 0, type=3
libbpf: section .text, size 0, link 0, flags 6, type=1
libbpf: section func=SyS_epoll_wait, size 200, link 0, flags 6, type=1
libbpf: found program func=SyS_epoll_wait
libbpf: section .relfunc=SyS_epoll_wait, size 32, link 8, flags 0, type=9
libbpf: section maps, size 16, link 0, flags 3, type=1
libbpf: section license, size 4, link 0, flags 3, type=1
libbpf: license of [basic_bpf_test] is GPL
libbpf: section version, size 4, link 0, flags 3, type=1
libbpf: kernel version of [basic_bpf_test] is 40e00
libbpf: section .symtab, size 168, link 1, flags 0, type=2
libbpf: maps in [basic_bpf_test]: 1 maps in 16 bytes
libbpf: map 0 is "flip_table"
libbpf: collecting relocating info for: 'func=SyS_epoll_wait'
libbpf: relocation: insn_idx=4
libbpf: relocation: find map 0 (flip_table) for insn 4
libbpf: relocation: insn_idx=18
libbpf: relocation: find map 0 (flip_table) for insn 18
bpf: config program 'func=SyS_epoll_wait'
symbol:SyS_epoll_wait file:(null) line:0 offset:0 return:0 lazy:(null)
bpf: config 'func=SyS_epoll_wait' is ok
Looking at the vmlinux_path (8 entries long)
Using /lib/modules/4.14.0+/build/vmlinux for symbols
Open Debuginfo file: /lib/modules/4.14.0+/build/vmlinux
Try to find probe point from debuginfo.
Matched function: SyS_epoll_wait [2e5a9be]
found inline addr: 0xffffffff812af256
Probe point found: compat_SyS_epoll_pwait+150
found inline addr: 0xffffffff812af037
Probe point found: SyS_epoll_pwait+135
found inline addr: 0xffffffff812aeed0
Probe point found: SyS_epoll_wait+0
Found 3 probe_trace_events.
Opening /sys/kernel/debug/tracing//kprobe_events write=1
Writing event: p:perf_bpf_probe/func _text+2814550
Writing event: p:perf_bpf_probe/func_1 _text+2814007
Writing event: p:perf_bpf_probe/func_2 _text+2813648
libbpf: failed to create map (name: 'flip_table'): Invalid argument
libbpf: failed to load object '[basic_bpf_test]'
bpf: load objects failed
Failed to add events selected by BPF

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: perf test LLVM & clang 6 failing
  2017-11-27 17:04   ` Arnaldo Carvalho de Melo
@ 2017-11-27 19:11     ` Yonghong Song
  2017-11-27 19:34       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 15+ messages in thread
From: Yonghong Song @ 2017-11-27 19:11 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Daniel Borkmann
  Cc: Josh Poimboeuf, Wang Nan, Alexei Starovoitov, Adrian Hunter,
	David Ahern, Jiri Olsa, Ingo Molnar, Namhyung Kim,
	Linux Kernel Mailing List



On 11/27/17 9:04 AM, Arnaldo Carvalho de Melo wrote:
> Em Fri, Nov 24, 2017 at 04:16:52PM +0100, Daniel Borkmann escreveu:
>> [ +Yonghong ]
> 
> + Josh
>   
>> On 11/24/2017 03:47 PM, Arnaldo Carvalho de Melo wrote:
>>> FYI, just noticed, recently updated clang to version 6, from its
>>> upstream git repo.
>>
>> Do you recall what was your LLVM version prior to this where it was
>> working fine? (Wild guess from below would be the BPF inline asm
>> support that was added recently to LLVM (2865ab6996) vs asm() used
>> in headers included in the stdin header causing trouble due to arch
>> mixup?)
> 
> So, if I go to the cset just before:
> 
> commit f5caf621ee357279e759c0911daf6d55c7d36f03
> Author: Josh Poimboeuf <jpoimboe@redhat.com>
> Date:   Wed Sep 20 16:24:33 2017 -0500
> 
>      x86/asm: Fix inline asm call constraints for Clang
> ---
> 
> 'perf test LLVM' works again:
> 
> [root@jouet ~]# perf test LLVM
> 37: LLVM search and compile                               :
> 37.1: Basic BPF llvm compile                              : Ok
> 37.2: kbuild searching                                    : Ok
> 37.3: Compile source for BPF prologue generation          : Ok
> 37.4: Compile source for BPF relocation                   : Ok
> [root@jouet ~]#
> 
> I.e. 'perf test LLVM' built from what is in my acme/perf/urgent branch,
> targetted to v4.15, uses kernel headers and if I go to just before
> f5caf621ee, it works again, both with clang from fedora26 (4.0.1) and
> with 6.0, built from sources.

This patch introduced a module level inline assembly.

...
--- a/arch/x86/include/asm/asm.h
+++ b/arch/x86/include/asm/asm.h
@@ -132,4 +132,15 @@
  /* For C file, we already have NOKPROBE_SYMBOL macro */
  #endif

+#ifndef __ASSEMBLY__
+/*
+ * This output constraint should be used for any inline asm which has a 
"call"
+ * instruction.  Otherwise the asm may be inserted before the frame pointer
+ * gets set up by the containing function.  If you forget to do this, 
objtool
+ * may print a "call without frame pointer save/setup" warning.
+ */
+register unsigned int __asm_call_sp asm("esp");
+#define ASM_CALL_CONSTRAINT "+r" (__asm_call_sp)
+#endif
...

This will cause "clang ... -target bpf ..." failure since 4.0 does not 
have bpf inline asm support and 6.0 does not recognize the register 'esp'.

> 
> 'perf test BPF' breaks for another reason, needs another investigation,
> maybe you guys can spot something changed recently in that area:
> 
> libbpf: failed to create map (name: 'flip_table'): Invalid argument
> libbpf: failed to load object '[basic_bpf_test]'

Not sure whether this is the root cause or not, but the below section name
    SEC("func=SyS_epoll_wait")
is not a good one.
If it is used to represent the program name in the kernel, the kernel 
will reject it with invalid argument since it contains "=".

> 
> Complete logs up to this error are below, I'll go read Yonghong message
> to see if I can get the 'perf test LLVM' case fixed.
> 
> - Arnaldo
> 
> [root@jouet ~]# perf test BPF
> 39: BPF filter                                            :
> 39.1: Basic BPF filtering                                 : FAILED!
> 39.2: BPF pinning                                         : Skip
> 39.3: BPF prologue generation                             : Skip
> 39.4: BPF relocation checker                              : Skip
> [root@jouet ~]# perf test -v BPF
> 39: BPF filter                                            :
> 39.1: Basic BPF filtering                                 :
> --- start ---
> test child forked, pid 3541
> Kernel build dir is set to /lib/modules/4.14.0+/build
> set env: KBUILD_DIR=/lib/modules/4.14.0+/build
> unset env: KBUILD_OPTS
> include option is set to  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h
> set env: NR_CPUS=4
> set env: LINUX_VERSION_CODE=0x40e00
> set env: CLANG_EXEC=/usr/lib64/ccache/clang
> set env: CLANG_OPTIONS=-xc
> set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h
> set env: WORKING_DIR=/lib/modules/4.14.0+/build
> set env: CLANG_SOURCE=-
> llvm compiling command template: echo '/*
>   * bpf-script-example.c
>   * Test basic LLVM building
>   */
> #ifndef LINUX_VERSION_CODE
> # error Need LINUX_VERSION_CODE
> # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
> #endif
> #define BPF_ANY 0
> #define BPF_MAP_TYPE_ARRAY 2
> #define BPF_FUNC_map_lookup_elem 1
> #define BPF_FUNC_map_update_elem 2
> 
> static void *(*bpf_map_lookup_elem)(void *map, void *key) =
> 	(void *) BPF_FUNC_map_lookup_elem;
> static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
> 	(void *) BPF_FUNC_map_update_elem;
> 
> struct bpf_map_def {
> 	unsigned int type;
> 	unsigned int key_size;
> 	unsigned int value_size;
> 	unsigned int max_entries;
> };
> 
> #define SEC(NAME) __attribute__((section(NAME), used))
> struct bpf_map_def SEC("maps") flip_table = {
> 	.type = BPF_MAP_TYPE_ARRAY,
> 	.key_size = sizeof(int),
> 	.value_size = sizeof(int),
> 	.max_entries = 1,
> };
> 
> SEC("func=SyS_epoll_wait")
> int bpf_func__SyS_epoll_wait(void *ctx)
> {
> 	int ind =0;
> 	int *flag = bpf_map_lookup_elem(&flip_table, &ind);
> 	int new_flag;
> 	if (!flag)
> 		return 0;
> 	/* flip flag and store back */
> 	new_flag = !*flag;
> 	bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);
> 	return new_flag;
> }
> char _license[] SEC("license") = "GPL";
> int _version SEC("version") = LINUX_VERSION_CODE;
> ' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
> libbpf: loading object '[basic_bpf_test]' from buffer
> libbpf: section .strtab, size 120, link 0, flags 0, type=3
> libbpf: section .text, size 0, link 0, flags 6, type=1
> libbpf: section func=SyS_epoll_wait, size 200, link 0, flags 6, type=1
> libbpf: found program func=SyS_epoll_wait
> libbpf: section .relfunc=SyS_epoll_wait, size 32, link 8, flags 0, type=9
> libbpf: section maps, size 16, link 0, flags 3, type=1
> libbpf: section license, size 4, link 0, flags 3, type=1
> libbpf: license of [basic_bpf_test] is GPL
> libbpf: section version, size 4, link 0, flags 3, type=1
> libbpf: kernel version of [basic_bpf_test] is 40e00
> libbpf: section .symtab, size 168, link 1, flags 0, type=2
> libbpf: maps in [basic_bpf_test]: 1 maps in 16 bytes
> libbpf: map 0 is "flip_table"
> libbpf: collecting relocating info for: 'func=SyS_epoll_wait'
> libbpf: relocation: insn_idx=4
> libbpf: relocation: find map 0 (flip_table) for insn 4
> libbpf: relocation: insn_idx=18
> libbpf: relocation: find map 0 (flip_table) for insn 18
> bpf: config program 'func=SyS_epoll_wait'
> symbol:SyS_epoll_wait file:(null) line:0 offset:0 return:0 lazy:(null)
> bpf: config 'func=SyS_epoll_wait' is ok
> Looking at the vmlinux_path (8 entries long)
> Using /lib/modules/4.14.0+/build/vmlinux for symbols
> Open Debuginfo file: /lib/modules/4.14.0+/build/vmlinux
> Try to find probe point from debuginfo.
> Matched function: SyS_epoll_wait [2e5a9be]
> found inline addr: 0xffffffff812af256
> Probe point found: compat_SyS_epoll_pwait+150
> found inline addr: 0xffffffff812af037
> Probe point found: SyS_epoll_pwait+135
> found inline addr: 0xffffffff812aeed0
> Probe point found: SyS_epoll_wait+0
> Found 3 probe_trace_events.
> Opening /sys/kernel/debug/tracing//kprobe_events write=1
> Writing event: p:perf_bpf_probe/func _text+2814550
> Writing event: p:perf_bpf_probe/func_1 _text+2814007
> Writing event: p:perf_bpf_probe/func_2 _text+2813648
> libbpf: failed to create map (name: 'flip_table'): Invalid argument
> libbpf: failed to load object '[basic_bpf_test]'
> bpf: load objects failed
> Failed to add events selected by BPF
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: perf test LLVM & clang 6 failing
  2017-11-27 19:11     ` Yonghong Song
@ 2017-11-27 19:34       ` Arnaldo Carvalho de Melo
  2017-11-27 19:57         ` Josh Poimboeuf
  2017-11-27 20:05         ` perf test LLVM & clang 6 failing Arnaldo Carvalho de Melo
  0 siblings, 2 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-11-27 19:34 UTC (permalink / raw)
  To: Yonghong Song
  Cc: Daniel Borkmann, Josh Poimboeuf, Wang Nan, Alexei Starovoitov,
	Adrian Hunter, David Ahern, Jiri Olsa, Ingo Molnar, Namhyung Kim,
	Linux Kernel Mailing List

Em Mon, Nov 27, 2017 at 11:11:56AM -0800, Yonghong Song escreveu:
> On 11/27/17 9:04 AM, Arnaldo Carvalho de Melo wrote:
> > Em Fri, Nov 24, 2017 at 04:16:52PM +0100, Daniel Borkmann escreveu:
> > > [ +Yonghong ]
> > 
> > + Josh
> > > On 11/24/2017 03:47 PM, Arnaldo Carvalho de Melo wrote:
> > > > FYI, just noticed, recently updated clang to version 6, from its
> > > > upstream git repo.
> > > 
> > > Do you recall what was your LLVM version prior to this where it was
> > > working fine? (Wild guess from below would be the BPF inline asm
> > > support that was added recently to LLVM (2865ab6996) vs asm() used
> > > in headers included in the stdin header causing trouble due to arch
> > > mixup?)
> > 
> > So, if I go to the cset just before:
> > 
> > commit f5caf621ee357279e759c0911daf6d55c7d36f03
> > Author: Josh Poimboeuf <jpoimboe@redhat.com>
> > Date:   Wed Sep 20 16:24:33 2017 -0500
> > 
> >      x86/asm: Fix inline asm call constraints for Clang
> > ---
> > 
> > 'perf test LLVM' works again:
> > 
> > [root@jouet ~]# perf test LLVM
> > 37: LLVM search and compile                               :
> > 37.1: Basic BPF llvm compile                              : Ok
> > 37.2: kbuild searching                                    : Ok
> > 37.3: Compile source for BPF prologue generation          : Ok
> > 37.4: Compile source for BPF relocation                   : Ok
> > [root@jouet ~]#
> > 
> > I.e. 'perf test LLVM' built from what is in my acme/perf/urgent branch,
> > targetted to v4.15, uses kernel headers and if I go to just before
> > f5caf621ee, it works again, both with clang from fedora26 (4.0.1) and
> > with 6.0, built from sources.
> 
> This patch introduced a module level inline assembly.
> 
> ...
> --- a/arch/x86/include/asm/asm.h
> +++ b/arch/x86/include/asm/asm.h
> @@ -132,4 +132,15 @@
>  /* For C file, we already have NOKPROBE_SYMBOL macro */
>  #endif
> 
> +#ifndef __ASSEMBLY__
> +/*
> + * This output constraint should be used for any inline asm which has a
> "call"
> + * instruction.  Otherwise the asm may be inserted before the frame pointer
> + * gets set up by the containing function.  If you forget to do this,
> objtool
> + * may print a "call without frame pointer save/setup" warning.
> + */
> +register unsigned int __asm_call_sp asm("esp");
> +#define ASM_CALL_CONSTRAINT "+r" (__asm_call_sp)
> +#endif
> ...
> 
> This will cause "clang ... -target bpf ..." failure since 4.0 does not have
> bpf inline asm support and 6.0 does not recognize the register 'esp'.

Ok, explains the problem then, Josh, ideas on how to proceed here?
 
> > 'perf test BPF' breaks for another reason, needs another investigation,
> > maybe you guys can spot something changed recently in that area:
> > 
> > libbpf: failed to create map (name: 'flip_table'): Invalid argument
> > libbpf: failed to load object '[basic_bpf_test]'


So, I noticed that any maps are failing, I'll go dig, but may be some
new security tightening, even running as root, this was working
recently, was even part of our discussion on the bpf_probe_read_str()
trouble with clang's optimizer:

[root@jouet bpf]# cat open.c
#include "bpf.h"

SEC("prog=do_sys_open filename")
int prog(void *ctx, int err, char *filename_ptr)
{
	char filename[128];
	int len = bpf_probe_read_str(filename, sizeof(filename), filename_ptr); 
	if (len > 0) {
		if (len == 1)
			perf_event_output(ctx, &__bpf_stdout__, BPF_F_CURRENT_CPU, filename, len);
		else if (len < 128)
			perf_event_output(ctx, &__bpf_stdout__, BPF_F_CURRENT_CPU, filename, len);
        }
	return 1;
}
[root@jouet bpf]#
<SNIP>
Found 1 probe_trace_events.
Opening /sys/kernel/debug/tracing//kprobe_events write=1
Writing event: p:perf_bpf_probe/prog _text+2493856 filename=%si:x64
In map_prologue, ntevs=1
mapping[0]=0
libbpf: failed to create map (name: '__bpf_stdout__'): Invalid argument
libbpf: failed to load object 'open.c'
bpf: load objects failed
event syntax error: 'open.c'
                     \___ Operation not permitted
<SNIP>

Using 'perf ftrace' to trace just 'perf trace':

[root@jouet bpf]# perf ftrace -G SyS_bpf perf trace -v -e open.c,open cat /tmp/somefile 2> /dev/null
 0)               |  SyS_bpf() {
 0)               |    capable() {
 0)               |      ns_capable_common() {
 0)               |        security_capable() {
 0)   0.045 us    |          cap_capable();
 0)               |          selinux_capable() {
 0)   0.274 us    |            cred_has_capability();
 0)   0.518 us    |          }
 0)   1.464 us    |        }
 0)   1.783 us    |      }
 0)   2.130 us    |    }
 0)   0.458 us    |    check_uarg_tail_zero();
 0)               |    __check_object_size() {
 0)   0.046 us    |      __virt_addr_valid();
 0)   0.040 us    |      check_stack_object();
 0)   0.510 us    |    }
 0)   4.161 us    |  }
[root@jouet bpf]#

/me goes to look at SyS_bpf() in this kernel... (4.14.0+).

- Arnaldo

 
> Not sure whether this is the root cause or not, but the below section name
>    SEC("func=SyS_epoll_wait")
> is not a good one.
> If it is used to represent the program name in the kernel, the kernel will
> reject it with invalid argument since it contains "=".

I forgot the details about this one, but this has been working like that
for quite a while, I'll check if something new happened here...
 
> > 
> > Complete logs up to this error are below, I'll go read Yonghong message
> > to see if I can get the 'perf test LLVM' case fixed.
> > 
> > - Arnaldo
> > 
> > [root@jouet ~]# perf test BPF
> > 39: BPF filter                                            :
> > 39.1: Basic BPF filtering                                 : FAILED!
> > 39.2: BPF pinning                                         : Skip
> > 39.3: BPF prologue generation                             : Skip
> > 39.4: BPF relocation checker                              : Skip
> > [root@jouet ~]# perf test -v BPF
> > 39: BPF filter                                            :
> > 39.1: Basic BPF filtering                                 :
> > --- start ---
> > test child forked, pid 3541
> > Kernel build dir is set to /lib/modules/4.14.0+/build
> > set env: KBUILD_DIR=/lib/modules/4.14.0+/build
> > unset env: KBUILD_OPTS
> > include option is set to  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h
> > set env: NR_CPUS=4
> > set env: LINUX_VERSION_CODE=0x40e00
> > set env: CLANG_EXEC=/usr/lib64/ccache/clang
> > set env: CLANG_OPTIONS=-xc
> > set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h
> > set env: WORKING_DIR=/lib/modules/4.14.0+/build
> > set env: CLANG_SOURCE=-
> > llvm compiling command template: echo '/*
> >   * bpf-script-example.c
> >   * Test basic LLVM building
> >   */
> > #ifndef LINUX_VERSION_CODE
> > # error Need LINUX_VERSION_CODE
> > # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
> > #endif
> > #define BPF_ANY 0
> > #define BPF_MAP_TYPE_ARRAY 2
> > #define BPF_FUNC_map_lookup_elem 1
> > #define BPF_FUNC_map_update_elem 2
> > 
> > static void *(*bpf_map_lookup_elem)(void *map, void *key) =
> > 	(void *) BPF_FUNC_map_lookup_elem;
> > static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
> > 	(void *) BPF_FUNC_map_update_elem;
> > 
> > struct bpf_map_def {
> > 	unsigned int type;
> > 	unsigned int key_size;
> > 	unsigned int value_size;
> > 	unsigned int max_entries;
> > };
> > 
> > #define SEC(NAME) __attribute__((section(NAME), used))
> > struct bpf_map_def SEC("maps") flip_table = {
> > 	.type = BPF_MAP_TYPE_ARRAY,
> > 	.key_size = sizeof(int),
> > 	.value_size = sizeof(int),
> > 	.max_entries = 1,
> > };
> > 
> > SEC("func=SyS_epoll_wait")
> > int bpf_func__SyS_epoll_wait(void *ctx)
> > {
> > 	int ind =0;
> > 	int *flag = bpf_map_lookup_elem(&flip_table, &ind);
> > 	int new_flag;
> > 	if (!flag)
> > 		return 0;
> > 	/* flip flag and store back */
> > 	new_flag = !*flag;
> > 	bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);
> > 	return new_flag;
> > }
> > char _license[] SEC("license") = "GPL";
> > int _version SEC("version") = LINUX_VERSION_CODE;
> > ' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
> > libbpf: loading object '[basic_bpf_test]' from buffer
> > libbpf: section .strtab, size 120, link 0, flags 0, type=3
> > libbpf: section .text, size 0, link 0, flags 6, type=1
> > libbpf: section func=SyS_epoll_wait, size 200, link 0, flags 6, type=1
> > libbpf: found program func=SyS_epoll_wait
> > libbpf: section .relfunc=SyS_epoll_wait, size 32, link 8, flags 0, type=9
> > libbpf: section maps, size 16, link 0, flags 3, type=1
> > libbpf: section license, size 4, link 0, flags 3, type=1
> > libbpf: license of [basic_bpf_test] is GPL
> > libbpf: section version, size 4, link 0, flags 3, type=1
> > libbpf: kernel version of [basic_bpf_test] is 40e00
> > libbpf: section .symtab, size 168, link 1, flags 0, type=2
> > libbpf: maps in [basic_bpf_test]: 1 maps in 16 bytes
> > libbpf: map 0 is "flip_table"
> > libbpf: collecting relocating info for: 'func=SyS_epoll_wait'
> > libbpf: relocation: insn_idx=4
> > libbpf: relocation: find map 0 (flip_table) for insn 4
> > libbpf: relocation: insn_idx=18
> > libbpf: relocation: find map 0 (flip_table) for insn 18
> > bpf: config program 'func=SyS_epoll_wait'
> > symbol:SyS_epoll_wait file:(null) line:0 offset:0 return:0 lazy:(null)
> > bpf: config 'func=SyS_epoll_wait' is ok
> > Looking at the vmlinux_path (8 entries long)
> > Using /lib/modules/4.14.0+/build/vmlinux for symbols
> > Open Debuginfo file: /lib/modules/4.14.0+/build/vmlinux
> > Try to find probe point from debuginfo.
> > Matched function: SyS_epoll_wait [2e5a9be]
> > found inline addr: 0xffffffff812af256
> > Probe point found: compat_SyS_epoll_pwait+150
> > found inline addr: 0xffffffff812af037
> > Probe point found: SyS_epoll_pwait+135
> > found inline addr: 0xffffffff812aeed0
> > Probe point found: SyS_epoll_wait+0
> > Found 3 probe_trace_events.
> > Opening /sys/kernel/debug/tracing//kprobe_events write=1
> > Writing event: p:perf_bpf_probe/func _text+2814550
> > Writing event: p:perf_bpf_probe/func_1 _text+2814007
> > Writing event: p:perf_bpf_probe/func_2 _text+2813648
> > libbpf: failed to create map (name: 'flip_table'): Invalid argument
> > libbpf: failed to load object '[basic_bpf_test]'
> > bpf: load objects failed
> > Failed to add events selected by BPF
> > 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: perf test LLVM & clang 6 failing
  2017-11-27 19:34       ` Arnaldo Carvalho de Melo
@ 2017-11-27 19:57         ` Josh Poimboeuf
  2017-11-27 21:45           ` Matthias Kaehlcke
  2017-11-27 20:05         ` perf test LLVM & clang 6 failing Arnaldo Carvalho de Melo
  1 sibling, 1 reply; 15+ messages in thread
From: Josh Poimboeuf @ 2017-11-27 19:57 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Yonghong Song, Daniel Borkmann, Wang Nan, Alexei Starovoitov,
	Adrian Hunter, David Ahern, Jiri Olsa, Ingo Molnar, Namhyung Kim,
	Linux Kernel Mailing List, Andrey Ryabinin, Matthias Kaehlcke

On Mon, Nov 27, 2017 at 04:34:25PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Mon, Nov 27, 2017 at 11:11:56AM -0800, Yonghong Song escreveu:
> > On 11/27/17 9:04 AM, Arnaldo Carvalho de Melo wrote:
> > > Em Fri, Nov 24, 2017 at 04:16:52PM +0100, Daniel Borkmann escreveu:
> > > > [ +Yonghong ]
> > > 
> > > + Josh
> > > > On 11/24/2017 03:47 PM, Arnaldo Carvalho de Melo wrote:
> > > > > FYI, just noticed, recently updated clang to version 6, from its
> > > > > upstream git repo.
> > > > 
> > > > Do you recall what was your LLVM version prior to this where it was
> > > > working fine? (Wild guess from below would be the BPF inline asm
> > > > support that was added recently to LLVM (2865ab6996) vs asm() used
> > > > in headers included in the stdin header causing trouble due to arch
> > > > mixup?)
> > > 
> > > So, if I go to the cset just before:
> > > 
> > > commit f5caf621ee357279e759c0911daf6d55c7d36f03
> > > Author: Josh Poimboeuf <jpoimboe@redhat.com>
> > > Date:   Wed Sep 20 16:24:33 2017 -0500
> > > 
> > >      x86/asm: Fix inline asm call constraints for Clang
> > > ---
> > > 
> > > 'perf test LLVM' works again:
> > > 
> > > [root@jouet ~]# perf test LLVM
> > > 37: LLVM search and compile                               :
> > > 37.1: Basic BPF llvm compile                              : Ok
> > > 37.2: kbuild searching                                    : Ok
> > > 37.3: Compile source for BPF prologue generation          : Ok
> > > 37.4: Compile source for BPF relocation                   : Ok
> > > [root@jouet ~]#
> > > 
> > > I.e. 'perf test LLVM' built from what is in my acme/perf/urgent branch,
> > > targetted to v4.15, uses kernel headers and if I go to just before
> > > f5caf621ee, it works again, both with clang from fedora26 (4.0.1) and
> > > with 6.0, built from sources.
> > 
> > This patch introduced a module level inline assembly.
> > 
> > ...
> > --- a/arch/x86/include/asm/asm.h
> > +++ b/arch/x86/include/asm/asm.h
> > @@ -132,4 +132,15 @@
> >  /* For C file, we already have NOKPROBE_SYMBOL macro */
> >  #endif
> > 
> > +#ifndef __ASSEMBLY__
> > +/*
> > + * This output constraint should be used for any inline asm which has a
> > "call"
> > + * instruction.  Otherwise the asm may be inserted before the frame pointer
> > + * gets set up by the containing function.  If you forget to do this,
> > objtool
> > + * may print a "call without frame pointer save/setup" warning.
> > + */
> > +register unsigned int __asm_call_sp asm("esp");
> > +#define ASM_CALL_CONSTRAINT "+r" (__asm_call_sp)
> > +#endif
> > ...
> > 
> > This will cause "clang ... -target bpf ..." failure since 4.0 does not have
> > bpf inline asm support and 6.0 does not recognize the register 'esp'.
> 
> Ok, explains the problem then, Josh, ideas on how to proceed here?

The original change to add the global inline asm:

  5caf621ee35 ("x86/asm: Fix inline asm call constraints for Clang")

was done to support clang in the first place.  Before that change, a
clang-built kernel didn't even boot.  So I'm a bit perplexed by the fact
that this change would be causing clang problems, since it was done to
fix clang in the first place.

Adding Andrey and Matthias, maybe they can help clarify things.

-- 
Josh

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: perf test LLVM & clang 6 failing
  2017-11-27 19:34       ` Arnaldo Carvalho de Melo
  2017-11-27 19:57         ` Josh Poimboeuf
@ 2017-11-27 20:05         ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-11-27 20:05 UTC (permalink / raw)
  To: Yonghong Song
  Cc: Daniel Borkmann, Josh Poimboeuf, Wang Nan, Alexei Starovoitov,
	Adrian Hunter, David Ahern, Jiri Olsa, Ingo Molnar, Namhyung Kim,
	Linux Kernel Mailing List

Em Mon, Nov 27, 2017 at 04:34:25PM -0300, Arnaldo Carvalho de Melo escreveu:
> So, I noticed that any maps are failing, I'll go dig, but may be some
> new security tightening, even running as root, this was working
> recently, was even part of our discussion on the bpf_probe_read_str()
> trouble with clang's optimizer:
> 
> [root@jouet bpf]# cat open.c
> #include "bpf.h"
> 
> SEC("prog=do_sys_open filename")
> int prog(void *ctx, int err, char *filename_ptr)
> {
> 	char filename[128];
> 	int len = bpf_probe_read_str(filename, sizeof(filename), filename_ptr); 
> 	if (len > 0) {
> 		if (len == 1)
> 			perf_event_output(ctx, &__bpf_stdout__, BPF_F_CURRENT_CPU, filename, len);
> 		else if (len < 128)
> 			perf_event_output(ctx, &__bpf_stdout__, BPF_F_CURRENT_CPU, filename, len);
>         }
> 	return 1;
> }
> [root@jouet bpf]#
> <SNIP>
> Found 1 probe_trace_events.
> Opening /sys/kernel/debug/tracing//kprobe_events write=1
> Writing event: p:perf_bpf_probe/prog _text+2493856 filename=%si:x64
> In map_prologue, ntevs=1
> mapping[0]=0
> libbpf: failed to create map (name: '__bpf_stdout__'): Invalid argument
> libbpf: failed to load object 'open.c'
> bpf: load objects failed
> event syntax error: 'open.c'
>                      \___ Operation not permitted
> <SNIP>
> 
> Using 'perf ftrace' to trace just 'perf trace':
> 
> [root@jouet bpf]# perf ftrace -G SyS_bpf perf trace -v -e open.c,open cat /tmp/somefile 2> /dev/null
>  0)               |  SyS_bpf() {
>  0)               |    capable() {
>  0)               |      ns_capable_common() {
>  0)               |        security_capable() {
>  0)   0.045 us    |          cap_capable();
>  0)               |          selinux_capable() {
>  0)   0.274 us    |            cred_has_capability();
>  0)   0.518 us    |          }
>  0)   1.464 us    |        }
>  0)   1.783 us    |      }
>  0)   2.130 us    |    }
>  0)   0.458 us    |    check_uarg_tail_zero();
>  0)               |    __check_object_size() {
>  0)   0.046 us    |      __virt_addr_valid();
>  0)   0.040 us    |      check_stack_object();
>  0)   0.510 us    |    }
>  0)   4.161 us    |  }
> [root@jouet bpf]#
> 
> /me goes to look at SyS_bpf() in this kernel... (4.14.0+).

Tracing 'perf trace' with 'perf trace' we see:

# perf trace -e bpf perf trace -e open.c,open cat /tmp/somefile
<SNIP traced 'perf trace' error messages>
  0.000 ( 0.015 ms): perf/16767 bpf(cmd: MAP_CREATE, uattr: 0x7ffc3c8c7ac0, size: 72) = -1 EINVAL Invalid argument
#

Humm,

# perf probe check_stack_object%return 'ret=$retval'
Added new event:
  probe:check_stack_object (on check_stack_object%return with ret=$retval)

You can now use it in all perf tools, such as:

	perf record -e probe:check_stack_object -aR sleep 1

#

# perf trace -e bpf,probe:check* perf trace -e open.c,open cat /tmp/somefile
<SNIP lots of check_stack_object calls returning 0x0)
  4626.779 ( 0.004 ms): perf/31498 bpf(cmd: MAP_CREATE, uattr: 0x7fff7dbbaab0, size: 72                  ) ...
  4626.784 (         ): probe:check_stack_object:(ffffffffb625ec30 <- ffffffffb625ed1f) ret=0x2)
  4626.779 ( 0.006 ms): perf/31498  ... [continued]: bpf()) = -1 EINVAL Invalid argument
<SNIP lots of check_stack_object calls returning 0x0)

check_stack_object returning 0x2 means GOOD_STACK, 0x0 means
NOT_STACK...

- Arnaldo

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: perf test LLVM & clang 6 failing
  2017-11-27 19:57         ` Josh Poimboeuf
@ 2017-11-27 21:45           ` Matthias Kaehlcke
  2017-11-28  1:19             ` Yonghong Song
  2017-11-28 17:55             ` Arnaldo Carvalho de Melo
  0 siblings, 2 replies; 15+ messages in thread
From: Matthias Kaehlcke @ 2017-11-27 21:45 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Arnaldo Carvalho de Melo, Yonghong Song, Daniel Borkmann,
	Wang Nan, Alexei Starovoitov, Adrian Hunter, David Ahern,
	Jiri Olsa, Ingo Molnar, Namhyung Kim, Linux Kernel Mailing List,
	Andrey Ryabinin

El Mon, Nov 27, 2017 at 01:57:56PM -0600 Josh Poimboeuf ha dit:

> On Mon, Nov 27, 2017 at 04:34:25PM -0300, Arnaldo Carvalho de Melo wrote:
> > Em Mon, Nov 27, 2017 at 11:11:56AM -0800, Yonghong Song escreveu:
> > > On 11/27/17 9:04 AM, Arnaldo Carvalho de Melo wrote:
> > > > Em Fri, Nov 24, 2017 at 04:16:52PM +0100, Daniel Borkmann escreveu:
> > > > > [ +Yonghong ]
> > > > 
> > > > + Josh
> > > > > On 11/24/2017 03:47 PM, Arnaldo Carvalho de Melo wrote:
> > > > > > FYI, just noticed, recently updated clang to version 6, from its
> > > > > > upstream git repo.
> > > > > 
> > > > > Do you recall what was your LLVM version prior to this where it was
> > > > > working fine? (Wild guess from below would be the BPF inline asm
> > > > > support that was added recently to LLVM (2865ab6996) vs asm() used
> > > > > in headers included in the stdin header causing trouble due to arch
> > > > > mixup?)
> > > > 
> > > > So, if I go to the cset just before:
> > > > 
> > > > commit f5caf621ee357279e759c0911daf6d55c7d36f03
> > > > Author: Josh Poimboeuf <jpoimboe@redhat.com>
> > > > Date:   Wed Sep 20 16:24:33 2017 -0500
> > > > 
> > > >      x86/asm: Fix inline asm call constraints for Clang
> > > > ---
> > > > 
> > > > 'perf test LLVM' works again:
> > > > 
> > > > [root@jouet ~]# perf test LLVM
> > > > 37: LLVM search and compile                               :
> > > > 37.1: Basic BPF llvm compile                              : Ok
> > > > 37.2: kbuild searching                                    : Ok
> > > > 37.3: Compile source for BPF prologue generation          : Ok
> > > > 37.4: Compile source for BPF relocation                   : Ok
> > > > [root@jouet ~]#
> > > > 
> > > > I.e. 'perf test LLVM' built from what is in my acme/perf/urgent branch,
> > > > targetted to v4.15, uses kernel headers and if I go to just before
> > > > f5caf621ee, it works again, both with clang from fedora26 (4.0.1) and
> > > > with 6.0, built from sources.
> > > 
> > > This patch introduced a module level inline assembly.
> > > 
> > > ...
> > > --- a/arch/x86/include/asm/asm.h
> > > +++ b/arch/x86/include/asm/asm.h
> > > @@ -132,4 +132,15 @@
> > >  /* For C file, we already have NOKPROBE_SYMBOL macro */
> > >  #endif
> > > 
> > > +#ifndef __ASSEMBLY__
> > > +/*
> > > + * This output constraint should be used for any inline asm which has a
> > > "call"
> > > + * instruction.  Otherwise the asm may be inserted before the frame pointer
> > > + * gets set up by the containing function.  If you forget to do this,
> > > objtool
> > > + * may print a "call without frame pointer save/setup" warning.
> > > + */
> > > +register unsigned int __asm_call_sp asm("esp");
> > > +#define ASM_CALL_CONSTRAINT "+r" (__asm_call_sp)
> > > +#endif
> > > ...
> > > 
> > > This will cause "clang ... -target bpf ..." failure since 4.0 does not have
> > > bpf inline asm support and 6.0 does not recognize the register 'esp'.
> > 
> > Ok, explains the problem then, Josh, ideas on how to proceed here?
> 
> The original change to add the global inline asm:
> 
>   5caf621ee35 ("x86/asm: Fix inline asm call constraints for Clang")
> 
> was done to support clang in the first place.  Before that change, a
> clang-built kernel didn't even boot.  So I'm a bit perplexed by the fact
> that this change would be causing clang problems, since it was done to
> fix clang in the first place.
> 
> Adding Andrey and Matthias, maybe they can help clarify things.

Indeed the change was needed to boot on x86.

I know next to nothing about BPF, if I understand correctly the error
is generated when compiling for the BPF "architecture" not for x86. In
this process x86 assembly headers are included, one of which contains
the declaration of the register variable, in an register that exists
on x86, but not BPS.

I guess the first questions is whether the x86 asm headers should/need
to be included when compiling for BPF. If this needed/can not be
easily avoided one option could be to put the declaration within an
ifdef __x86_64__ block.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: perf test LLVM & clang 6 failing
  2017-11-27 21:45           ` Matthias Kaehlcke
@ 2017-11-28  1:19             ` Yonghong Song
  2017-11-28 17:55             ` Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 15+ messages in thread
From: Yonghong Song @ 2017-11-28  1:19 UTC (permalink / raw)
  To: Matthias Kaehlcke, Josh Poimboeuf
  Cc: Arnaldo Carvalho de Melo, Daniel Borkmann, Wang Nan,
	Alexei Starovoitov, Adrian Hunter, David Ahern, Jiri Olsa,
	Ingo Molnar, Namhyung Kim, Linux Kernel Mailing List,
	Andrey Ryabinin



On 11/27/17 1:45 PM, Matthias Kaehlcke wrote:
> El Mon, Nov 27, 2017 at 01:57:56PM -0600 Josh Poimboeuf ha dit:
> 
>> On Mon, Nov 27, 2017 at 04:34:25PM -0300, Arnaldo Carvalho de Melo wrote:
>>> Em Mon, Nov 27, 2017 at 11:11:56AM -0800, Yonghong Song escreveu:
>>>> On 11/27/17 9:04 AM, Arnaldo Carvalho de Melo wrote:
>>>>> Em Fri, Nov 24, 2017 at 04:16:52PM +0100, Daniel Borkmann escreveu:
>>>>>> [ +Yonghong ]
>>>>>
>>>>> + Josh
>>>>>> On 11/24/2017 03:47 PM, Arnaldo Carvalho de Melo wrote:
>>>>>>> FYI, just noticed, recently updated clang to version 6, from its
>>>>>>> upstream git repo.
>>>>>>
>>>>>> Do you recall what was your LLVM version prior to this where it was
>>>>>> working fine? (Wild guess from below would be the BPF inline asm
>>>>>> support that was added recently to LLVM (2865ab6996) vs asm() used
>>>>>> in headers included in the stdin header causing trouble due to arch
>>>>>> mixup?)
>>>>>
>>>>> So, if I go to the cset just before:
>>>>>
>>>>> commit f5caf621ee357279e759c0911daf6d55c7d36f03
>>>>> Author: Josh Poimboeuf <jpoimboe@redhat.com>
>>>>> Date:   Wed Sep 20 16:24:33 2017 -0500
>>>>>
>>>>>       x86/asm: Fix inline asm call constraints for Clang
>>>>> ---
>>>>>
>>>>> 'perf test LLVM' works again:
>>>>>
>>>>> [root@jouet ~]# perf test LLVM
>>>>> 37: LLVM search and compile                               :
>>>>> 37.1: Basic BPF llvm compile                              : Ok
>>>>> 37.2: kbuild searching                                    : Ok
>>>>> 37.3: Compile source for BPF prologue generation          : Ok
>>>>> 37.4: Compile source for BPF relocation                   : Ok
>>>>> [root@jouet ~]#
>>>>>
>>>>> I.e. 'perf test LLVM' built from what is in my acme/perf/urgent branch,
>>>>> targetted to v4.15, uses kernel headers and if I go to just before
>>>>> f5caf621ee, it works again, both with clang from fedora26 (4.0.1) and
>>>>> with 6.0, built from sources.
>>>>
>>>> This patch introduced a module level inline assembly.
>>>>
>>>> ...
>>>> --- a/arch/x86/include/asm/asm.h
>>>> +++ b/arch/x86/include/asm/asm.h
>>>> @@ -132,4 +132,15 @@
>>>>   /* For C file, we already have NOKPROBE_SYMBOL macro */
>>>>   #endif
>>>>
>>>> +#ifndef __ASSEMBLY__
>>>> +/*
>>>> + * This output constraint should be used for any inline asm which has a
>>>> "call"
>>>> + * instruction.  Otherwise the asm may be inserted before the frame pointer
>>>> + * gets set up by the containing function.  If you forget to do this,
>>>> objtool
>>>> + * may print a "call without frame pointer save/setup" warning.
>>>> + */
>>>> +register unsigned int __asm_call_sp asm("esp");
>>>> +#define ASM_CALL_CONSTRAINT "+r" (__asm_call_sp)
>>>> +#endif
>>>> ...
>>>>
>>>> This will cause "clang ... -target bpf ..." failure since 4.0 does not have
>>>> bpf inline asm support and 6.0 does not recognize the register 'esp'.
>>>
>>> Ok, explains the problem then, Josh, ideas on how to proceed here?
>>
>> The original change to add the global inline asm:
>>
>>    5caf621ee35 ("x86/asm: Fix inline asm call constraints for Clang")
>>
>> was done to support clang in the first place.  Before that change, a
>> clang-built kernel didn't even boot.  So I'm a bit perplexed by the fact
>> that this change would be causing clang problems, since it was done to
>> fix clang in the first place.
>>
>> Adding Andrey and Matthias, maybe they can help clarify things.
> 
> Indeed the change was needed to boot on x86.
> 
> I know next to nothing about BPF, if I understand correctly the error
> is generated when compiling for the BPF "architecture" not for x86. In
> this process x86 assembly headers are included, one of which contains
> the declaration of the register variable, in an register that exists
> on x86, but not BPS.
> 
> I guess the first questions is whether the x86 asm headers should/need
> to be included when compiling for BPF. If this needed/can not be
> easily avoided one option could be to put the declaration within an
> ifdef __x86_64__ block.

There is a way to do this. You can use the similar mechanism to
the one in linux:samples/bpf and linux:tools/testing/selftests/bpf.

Basically, you first do:
   clang ... -O2 -emit-llvm -S prog.c <=== this uses x86_64 as the 
default target
   llc -march=bpf -filetype=obj prog.ll <=== this uses bpf target
This should work.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: perf test LLVM & clang 6 failing
  2017-11-27 21:45           ` Matthias Kaehlcke
  2017-11-28  1:19             ` Yonghong Song
@ 2017-11-28 17:55             ` Arnaldo Carvalho de Melo
  2017-11-28 17:59               ` Arnaldo Carvalho de Melo
  1 sibling, 1 reply; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-11-28 17:55 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Josh Poimboeuf, Yonghong Song, Daniel Borkmann, Wang Nan,
	Alexei Starovoitov, Adrian Hunter, David Ahern, Jiri Olsa,
	Ingo Molnar, Namhyung Kim, Linux Kernel Mailing List,
	Andrey Ryabinin

Em Mon, Nov 27, 2017 at 01:45:21PM -0800, Matthias Kaehlcke escreveu:
> El Mon, Nov 27, 2017 at 01:57:56PM -0600 Josh Poimboeuf ha dit:
> 
> > On Mon, Nov 27, 2017 at 04:34:25PM -0300, Arnaldo Carvalho de Melo wrote:
> > > Em Mon, Nov 27, 2017 at 11:11:56AM -0800, Yonghong Song escreveu:
> > > > On 11/27/17 9:04 AM, Arnaldo Carvalho de Melo wrote:
> > > > > Em Fri, Nov 24, 2017 at 04:16:52PM +0100, Daniel Borkmann escreveu:
> > > > > > [ +Yonghong ]
> > > > > 
> > > > > + Josh
> > > > > > On 11/24/2017 03:47 PM, Arnaldo Carvalho de Melo wrote:
> > > > > > > FYI, just noticed, recently updated clang to version 6, from its
> > > > > > > upstream git repo.
> > > > > > 
> > > > > > Do you recall what was your LLVM version prior to this where it was
> > > > > > working fine? (Wild guess from below would be the BPF inline asm
> > > > > > support that was added recently to LLVM (2865ab6996) vs asm() used
> > > > > > in headers included in the stdin header causing trouble due to arch
> > > > > > mixup?)
> > > > > 
> > > > > So, if I go to the cset just before:
> > > > > 
> > > > > commit f5caf621ee357279e759c0911daf6d55c7d36f03
> > > > > Author: Josh Poimboeuf <jpoimboe@redhat.com>
> > > > > Date:   Wed Sep 20 16:24:33 2017 -0500
> > > > > 
> > > > >      x86/asm: Fix inline asm call constraints for Clang
> > > > > ---
> > > > > 
> > > > > 'perf test LLVM' works again:
> > > > > 
> > > > > [root@jouet ~]# perf test LLVM
> > > > > 37: LLVM search and compile                               :
> > > > > 37.1: Basic BPF llvm compile                              : Ok
> > > > > 37.2: kbuild searching                                    : Ok
> > > > > 37.3: Compile source for BPF prologue generation          : Ok
> > > > > 37.4: Compile source for BPF relocation                   : Ok
> > > > > [root@jouet ~]#
> > > > > 
> > > > > I.e. 'perf test LLVM' built from what is in my acme/perf/urgent branch,
> > > > > targetted to v4.15, uses kernel headers and if I go to just before
> > > > > f5caf621ee, it works again, both with clang from fedora26 (4.0.1) and
> > > > > with 6.0, built from sources.
> > > > 
> > > > This patch introduced a module level inline assembly.
> > > > 
> > > > ...
> > > > --- a/arch/x86/include/asm/asm.h
> > > > +++ b/arch/x86/include/asm/asm.h
> > > > @@ -132,4 +132,15 @@
> > > >  /* For C file, we already have NOKPROBE_SYMBOL macro */
> > > >  #endif
> > > > 
> > > > +#ifndef __ASSEMBLY__
> > > > +/*
> > > > + * This output constraint should be used for any inline asm which has a
> > > > "call"
> > > > + * instruction.  Otherwise the asm may be inserted before the frame pointer
> > > > + * gets set up by the containing function.  If you forget to do this,
> > > > objtool
> > > > + * may print a "call without frame pointer save/setup" warning.
> > > > + */
> > > > +register unsigned int __asm_call_sp asm("esp");
> > > > +#define ASM_CALL_CONSTRAINT "+r" (__asm_call_sp)
> > > > +#endif
> > > > ...
> > > > 
> > > > This will cause "clang ... -target bpf ..." failure since 4.0 does not have
> > > > bpf inline asm support and 6.0 does not recognize the register 'esp'.
> > > 
> > > Ok, explains the problem then, Josh, ideas on how to proceed here?
> > 
> > The original change to add the global inline asm:
> > 
> >   5caf621ee35 ("x86/asm: Fix inline asm call constraints for Clang")
> > 
> > was done to support clang in the first place.  Before that change, a
> > clang-built kernel didn't even boot.  So I'm a bit perplexed by the fact
> > that this change would be causing clang problems, since it was done to
> > fix clang in the first place.
> > 
> > Adding Andrey and Matthias, maybe they can help clarify things.
> 
> Indeed the change was needed to boot on x86.
> 
> I know next to nothing about BPF, if I understand correctly the error
> is generated when compiling for the BPF "architecture" not for x86. In
> this process x86 assembly headers are included, one of which contains
> the declaration of the register variable, in an register that exists
> on x86, but not BPS.
> 
> I guess the first questions is whether the x86 asm headers should/need
> to be included when compiling for BPF. If this needed/can not be
> easily avoided one option could be to put the declaration within an
> ifdef __x86_64__ block.

Right, unsure if this is the way to go, but fixes the problem here:

diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
index 219faaec51df..d180d573fd38 100644
--- a/arch/x86/include/asm/asm.h
+++ b/arch/x86/include/asm/asm.h
@@ -136,6 +136,8 @@
 #endif
 
 #ifndef __ASSEMBLY__
+#if defined(__i386__) || defined(__x86_64__)
+/* bpf target builds also include these headers */
 /*
  * This output constraint should be used for any inline asm which has a "call"
  * instruction.  Otherwise the asm may be inserted before the frame pointer
@@ -145,5 +147,6 @@
 register unsigned long current_stack_pointer asm(_ASM_SP);
 #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
 #endif
+#endif
 
 #endif /* _ASM_X86_ASM_H */

[root@jouet ~]# perf test LLVM
37: LLVM search and compile                               :
37.1: Basic BPF llvm compile                              : Ok
37.2: kbuild searching                                    : Ok
37.3: Compile source for BPF prologue generation          : Ok
37.4: Compile source for BPF relocation                   : Ok
[root@jouet ~]#

Is there any define clang generates for the bpf target?

- Arnaldo

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: perf test LLVM & clang 6 failing
  2017-11-28 17:55             ` Arnaldo Carvalho de Melo
@ 2017-11-28 17:59               ` Arnaldo Carvalho de Melo
  2017-12-06 16:44                 ` [tip:perf/core] x86/asm: Allow again using asm.h when building for the 'bpf' clang target tip-bot for Arnaldo Carvalho de Melo
  2017-12-18 17:17                 ` [tip:perf/urgent] " tip-bot for Arnaldo Carvalho de Melo
  0 siblings, 2 replies; 15+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-11-28 17:59 UTC (permalink / raw)
  To: Matthias Kaehlcke
  Cc: Josh Poimboeuf, Yonghong Song, Daniel Borkmann, Wang Nan,
	Alexei Starovoitov, Adrian Hunter, David Ahern, Jiri Olsa,
	Ingo Molnar, Namhyung Kim, Linux Kernel Mailing List,
	Andrey Ryabinin

Em Tue, Nov 28, 2017 at 02:55:53PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Mon, Nov 27, 2017 at 01:45:21PM -0800, Matthias Kaehlcke escreveu:
> > El Mon, Nov 27, 2017 at 01:57:56PM -0600 Josh Poimboeuf ha dit:
> > > On Mon, Nov 27, 2017 at 04:34:25PM -0300, Arnaldo Carvalho de Melo wrote:
> > > > Em Mon, Nov 27, 2017 at 11:11:56AM -0800, Yonghong Song escreveu:
> > > > > On 11/27/17 9:04 AM, Arnaldo Carvalho de Melo wrote:
> > > > > > Em Fri, Nov 24, 2017 at 04:16:52PM +0100, Daniel Borkmann escreveu:
> > > > > > > [ +Yonghong ]

> > > > > > + Josh
> > > > > > > On 11/24/2017 03:47 PM, Arnaldo Carvalho de Melo wrote:
> > > > > > > > FYI, just noticed, recently updated clang to version 6, from its
> > > > > > > > upstream git repo.

> > > > > > > Do you recall what was your LLVM version prior to this where it was
> > > > > > > working fine? (Wild guess from below would be the BPF inline asm
> > > > > > > support that was added recently to LLVM (2865ab6996) vs asm() used
> > > > > > > in headers included in the stdin header causing trouble due to arch
> > > > > > > mixup?)

> > > > > > So, if I go to the cset just before:

> > > > > > commit f5caf621ee357279e759c0911daf6d55c7d36f03
> > > > > > Author: Josh Poimboeuf <jpoimboe@redhat.com>
> > > > > > Date:   Wed Sep 20 16:24:33 2017 -0500

> > > > > >      x86/asm: Fix inline asm call constraints for Clang
> > > > > > ---

> > > > > > 'perf test LLVM' works again:

> > > > > > [root@jouet ~]# perf test LLVM
> > > > > > 37: LLVM search and compile                               :
> > > > > > 37.1: Basic BPF llvm compile                              : Ok
> > > > > > 37.2: kbuild searching                                    : Ok
> > > > > > 37.3: Compile source for BPF prologue generation          : Ok
> > > > > > 37.4: Compile source for BPF relocation                   : Ok
> > > > > > [root@jouet ~]#

> > > > > > I.e. 'perf test LLVM' built from what is in my acme/perf/urgent branch,
> > > > > > targetted to v4.15, uses kernel headers and if I go to just before
> > > > > > f5caf621ee, it works again, both with clang from fedora26 (4.0.1) and
> > > > > > with 6.0, built from sources.

> > > > > This patch introduced a module level inline assembly.

> > > > > ...
> > > > > --- a/arch/x86/include/asm/asm.h
> > > > > +++ b/arch/x86/include/asm/asm.h
> > > > > @@ -132,4 +132,15 @@
> > > > >  /* For C file, we already have NOKPROBE_SYMBOL macro */
> > > > >  #endif

> > > > > +#ifndef __ASSEMBLY__
> > > > > +/*
> > > > > + * This output constraint should be used for any inline asm which has a
> > > > > "call"
> > > > > + * instruction.  Otherwise the asm may be inserted before the frame pointer
> > > > > + * gets set up by the containing function.  If you forget to do this,
> > > > > objtool
> > > > > + * may print a "call without frame pointer save/setup" warning.
> > > > > + */
> > > > > +register unsigned int __asm_call_sp asm("esp");
> > > > > +#define ASM_CALL_CONSTRAINT "+r" (__asm_call_sp)
> > > > > +#endif
> > > > > ...
> > > > > 
> > > > > This will cause "clang ... -target bpf ..." failure since 4.0 does not have
> > > > > bpf inline asm support and 6.0 does not recognize the register 'esp'.

> > > > Ok, explains the problem then, Josh, ideas on how to proceed here?

> > > The original change to add the global inline asm:

> > >   5caf621ee35 ("x86/asm: Fix inline asm call constraints for Clang")

> > > was done to support clang in the first place.  Before that change, a
> > > clang-built kernel didn't even boot.  So I'm a bit perplexed by the fact
> > > that this change would be causing clang problems, since it was done to
> > > fix clang in the first place.

> > > Adding Andrey and Matthias, maybe they can help clarify things.

> > Indeed the change was needed to boot on x86.

> > I know next to nothing about BPF, if I understand correctly the error
> > is generated when compiling for the BPF "architecture" not for x86. In
> > this process x86 assembly headers are included, one of which contains
> > the declaration of the register variable, in an register that exists
> > on x86, but not BPS.

> > I guess the first questions is whether the x86 asm headers should/need
> > to be included when compiling for BPF. If this needed/can not be
> > easily avoided one option could be to put the declaration within an
> > ifdef __x86_64__ block.

> Right, unsure if this is the way to go, but fixes the problem here:

> +++ b/arch/x86/include/asm/asm.h
> @@ -136,6 +136,8 @@
>  #endif
>  
>  #ifndef __ASSEMBLY__
> +#if defined(__i386__) || defined(__x86_64__)
> +/* bpf target builds also include these headers */
>  /*
>   * This output constraint should be used for any inline asm which has a "call"
>   * instruction.  Otherwise the asm may be inserted before the frame pointer
> @@ -145,5 +147,6 @@
>  register unsigned long current_stack_pointer asm(_ASM_SP);
>  #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
>  #endif
> +#endif
  
>  #endif /* _ASM_X86_ASM_H */
 
> [root@jouet ~]# perf test LLVM
> 37: LLVM search and compile                               :
> 37.1: Basic BPF llvm compile                              : Ok
> 37.2: kbuild searching                                    : Ok
> 37.3: Compile source for BPF prologue generation          : Ok
> 37.4: Compile source for BPF relocation                   : Ok
> [root@jouet ~]#
 
> Is there any define clang generates for the bpf target?

Yes, __BPF__

https://clang.llvm.org/doxygen/BPF_8cpp_source.html

So, new patch:

diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
index 219faaec51df..386a6900e206 100644
--- a/arch/x86/include/asm/asm.h
+++ b/arch/x86/include/asm/asm.h
@@ -136,6 +136,7 @@
 #endif
 
 #ifndef __ASSEMBLY__
+#ifndef __BPF__
 /*
  * This output constraint should be used for any inline asm which has a "call"
  * instruction.  Otherwise the asm may be inserted before the frame pointer
@@ -145,5 +146,6 @@
 register unsigned long current_stack_pointer asm(_ASM_SP);
 #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
 #endif
+#endif
 
 #endif /* _ASM_X86_ASM_H */

[root@jouet ~]# perf test LLVM
37: LLVM search and compile                               :
37.1: Basic BPF llvm compile                              : Ok
37.2: kbuild searching                                    : Ok
37.3: Compile source for BPF prologue generation          : Ok
37.4: Compile source for BPF relocation                   : Ok
[root@jouet ~]# 

This last one looks better, no? Alexei? Daniel?

- Arnaldo

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [tip:perf/core] x86/asm: Allow again using asm.h when building for the 'bpf' clang target
  2017-11-28 17:59               ` Arnaldo Carvalho de Melo
@ 2017-12-06 16:44                 ` tip-bot for Arnaldo Carvalho de Melo
  2017-12-18 17:17                 ` [tip:perf/urgent] " tip-bot for Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 15+ messages in thread
From: tip-bot for Arnaldo Carvalho de Melo @ 2017-12-06 16:44 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, alexei.starovoitov, namhyung, daniel, yhs,
	wangnan0, hpa, glider, mingo, jpoimboe, tglx, peterz, mka,
	adrian.hunter, arnd, miguel.bernal.marin, torvalds, luto, acme,
	dsahern, aryabinin, jolsa, dvyukov

Commit-ID:  c343bade301dfe608e86b034cbabed3c0d5a50f5
Gitweb:     https://git.kernel.org/tip/c343bade301dfe608e86b034cbabed3c0d5a50f5
Author:     Arnaldo Carvalho de Melo <acme@redhat.com>
AuthorDate: Mon, 4 Dec 2017 13:08:47 -0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 5 Dec 2017 15:43:55 -0300

x86/asm: Allow again using asm.h when building for the 'bpf' clang target

Up to f5caf621ee35 ("x86/asm: Fix inline asm call constraints for Clang")
we were able to use x86 headers to build to the 'bpf' clang target, as
done by the BPF code in tools/perf/.

With that commit, we ended up with following failure for 'perf test LLVM', this
is because "clang ... -target bpf ..." fails since 4.0 does not have bpf inline
asm support and 6.0 does not recognize the register 'esp', fix it by guarding
that part with an #ifndef __BPF__, that is defined by clang when building to
the "bpf" target.

  # perf test -v LLVM
  37: LLVM search and compile                               :
  37.1: Basic BPF llvm compile                              :
  --- start ---
  test child forked, pid 25526
  Kernel build dir is set to /lib/modules/4.14.0+/build
  set env: KBUILD_DIR=/lib/modules/4.14.0+/build
  unset env: KBUILD_OPTS
  include option is set to  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h
  set env: NR_CPUS=4
  set env: LINUX_VERSION_CODE=0x40e00
  set env: CLANG_EXEC=/usr/local/bin/clang
  set env: CLANG_OPTIONS=-xc
  set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h
  set env: WORKING_DIR=/lib/modules/4.14.0+/build
  set env: CLANG_SOURCE=-
  llvm compiling command template: echo '/*
   * bpf-script-example.c
   * Test basic LLVM building
   */
  #ifndef LINUX_VERSION_CODE
  # error Need LINUX_VERSION_CODE
  # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
  #endif
  #define BPF_ANY 0
  #define BPF_MAP_TYPE_ARRAY 2
  #define BPF_FUNC_map_lookup_elem 1
  #define BPF_FUNC_map_update_elem 2

  static void *(*bpf_map_lookup_elem)(void *map, void *key) =
	  (void *) BPF_FUNC_map_lookup_elem;
  static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
	  (void *) BPF_FUNC_map_update_elem;

  struct bpf_map_def {
	  unsigned int type;
	  unsigned int key_size;
	  unsigned int value_size;
	  unsigned int max_entries;
  };

  #define SEC(NAME) __attribute__((section(NAME), used))
  struct bpf_map_def SEC("maps") flip_table = {
	  .type = BPF_MAP_TYPE_ARRAY,
	  .key_size = sizeof(int),
	  .value_size = sizeof(int),
	  .max_entries = 1,
  };

  SEC("func=SyS_epoll_wait")
  int bpf_func__SyS_epoll_wait(void *ctx)
  {
	  int ind =0;
	  int *flag = bpf_map_lookup_elem(&flip_table, &ind);
	  int new_flag;
	  if (!flag)
		  return 0;
	  /* flip flag and store back */
	  new_flag = !*flag;
	  bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);
	  return new_flag;
  }
  char _license[] SEC("license") = "GPL";
  int _version SEC("version") = LINUX_VERSION_CODE;
  ' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
  test child finished with 0
  ---- end ----
  LLVM search and compile subtest 0: Ok
  37.2: kbuild searching                                    :
  --- start ---
  test child forked, pid 25950
  Kernel build dir is set to /lib/modules/4.14.0+/build
  set env: KBUILD_DIR=/lib/modules/4.14.0+/build
  unset env: KBUILD_OPTS
  include option is set to  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h
  set env: NR_CPUS=4
  set env: LINUX_VERSION_CODE=0x40e00
  set env: CLANG_EXEC=/usr/local/bin/clang
  set env: CLANG_OPTIONS=-xc
  set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h
  set env: WORKING_DIR=/lib/modules/4.14.0+/build
  set env: CLANG_SOURCE=-
  llvm compiling command template: echo '/*
   * bpf-script-test-kbuild.c
   * Test include from kernel header
   */
  #ifndef LINUX_VERSION_CODE
  # error Need LINUX_VERSION_CODE
  # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
  #endif
  #define SEC(NAME) __attribute__((section(NAME), used))

  #include <uapi/linux/fs.h>
  #include <uapi/asm/ptrace.h>

  SEC("func=vfs_llseek")
  int bpf_func__vfs_llseek(void *ctx)
  {
	  return 0;
  }

  char _license[] SEC("license") = "GPL";
  int _version SEC("version") = LINUX_VERSION_CODE;
  ' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
  In file included from <stdin>:12:
  In file included from /home/acme/git/linux/arch/x86/include/uapi/asm/ptrace.h:5:
  In file included from /home/acme/git/linux/include/linux/compiler.h:242:
  In file included from /home/acme/git/linux/arch/x86/include/asm/barrier.h:5:
  In file included from /home/acme/git/linux/arch/x86/include/asm/alternative.h:10:
  /home/acme/git/linux/arch/x86/include/asm/asm.h:145:50: error: unknown register name 'esp' in asm
  register unsigned long current_stack_pointer asm(_ASM_SP);
                                                   ^
  /home/acme/git/linux/arch/x86/include/asm/asm.h:44:18: note: expanded from macro '_ASM_SP'
  #define _ASM_SP         __ASM_REG(sp)
                          ^
  /home/acme/git/linux/arch/x86/include/asm/asm.h:27:32: note: expanded from macro '__ASM_REG'
  #define __ASM_REG(reg)         __ASM_SEL_RAW(e##reg, r##reg)
                                 ^
  /home/acme/git/linux/arch/x86/include/asm/asm.h:18:29: note: expanded from macro '__ASM_SEL_RAW'
  # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(a)
                              ^
  /home/acme/git/linux/arch/x86/include/asm/asm.h:11:32: note: expanded from macro '__ASM_FORM_RAW'
  # define __ASM_FORM_RAW(x)     #x
                                 ^
  <scratch space>:4:1: note: expanded from here
  "esp"
  ^
  1 error generated.
  ERROR:	unable to compile -
  Hint:	Check error message shown above.
  Hint:	You can also pre-compile it into .o using:
     		  clang -target bpf -O2 -c -
     	  with proper -I and -D options.
  Failed to compile test case: 'kbuild searching'
  test child finished with -1
  ---- end ----
  LLVM search and compile subtest 1: FAILED!

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matthias Kaehlcke <mka@chromium.org>
Cc: Miguel Bernal Marin <miguel.bernal.marin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: Yonghong Song <yhs@fb.com>
Link: https://lkml.kernel.org/r/20171128175948.GL3298@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 arch/x86/include/asm/asm.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
index 219faae..386a690 100644
--- a/arch/x86/include/asm/asm.h
+++ b/arch/x86/include/asm/asm.h
@@ -136,6 +136,7 @@
 #endif
 
 #ifndef __ASSEMBLY__
+#ifndef __BPF__
 /*
  * This output constraint should be used for any inline asm which has a "call"
  * instruction.  Otherwise the asm may be inserted before the frame pointer
@@ -145,5 +146,6 @@
 register unsigned long current_stack_pointer asm(_ASM_SP);
 #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
 #endif
+#endif
 
 #endif /* _ASM_X86_ASM_H */

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [tip:perf/urgent] x86/asm: Allow again using asm.h when building for the 'bpf' clang target
  2017-11-28 17:59               ` Arnaldo Carvalho de Melo
  2017-12-06 16:44                 ` [tip:perf/core] x86/asm: Allow again using asm.h when building for the 'bpf' clang target tip-bot for Arnaldo Carvalho de Melo
@ 2017-12-18 17:17                 ` tip-bot for Arnaldo Carvalho de Melo
  1 sibling, 0 replies; 15+ messages in thread
From: tip-bot for Arnaldo Carvalho de Melo @ 2017-12-18 17:17 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, linux-kernel, wangnan0, arnd, yhs, peterz, hpa, torvalds,
	luto, adrian.hunter, aryabinin, dsahern, mka, dvyukov, daniel,
	jolsa, namhyung, acme, glider, alexei.starovoitov, mingo,
	jpoimboe, miguel.bernal.marin

Commit-ID:  ca26cffa4e4aaeb09bb9e308f95c7835cb149248
Gitweb:     https://git.kernel.org/tip/ca26cffa4e4aaeb09bb9e308f95c7835cb149248
Author:     Arnaldo Carvalho de Melo <acme@redhat.com>
AuthorDate: Mon, 4 Dec 2017 13:08:47 -0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 18 Dec 2017 11:56:22 -0300

x86/asm: Allow again using asm.h when building for the 'bpf' clang target

Up to f5caf621ee35 ("x86/asm: Fix inline asm call constraints for Clang")
we were able to use x86 headers to build to the 'bpf' clang target, as
done by the BPF code in tools/perf/.

With that commit, we ended up with following failure for 'perf test LLVM', this
is because "clang ... -target bpf ..." fails since 4.0 does not have bpf inline
asm support and 6.0 does not recognize the register 'esp', fix it by guarding
that part with an #ifndef __BPF__, that is defined by clang when building to
the "bpf" target.

  # perf test -v LLVM
  37: LLVM search and compile                               :
  37.1: Basic BPF llvm compile                              :
  --- start ---
  test child forked, pid 25526
  Kernel build dir is set to /lib/modules/4.14.0+/build
  set env: KBUILD_DIR=/lib/modules/4.14.0+/build
  unset env: KBUILD_OPTS
  include option is set to  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h
  set env: NR_CPUS=4
  set env: LINUX_VERSION_CODE=0x40e00
  set env: CLANG_EXEC=/usr/local/bin/clang
  set env: CLANG_OPTIONS=-xc
  set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h
  set env: WORKING_DIR=/lib/modules/4.14.0+/build
  set env: CLANG_SOURCE=-
  llvm compiling command template: echo '/*
   * bpf-script-example.c
   * Test basic LLVM building
   */
  #ifndef LINUX_VERSION_CODE
  # error Need LINUX_VERSION_CODE
  # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
  #endif
  #define BPF_ANY 0
  #define BPF_MAP_TYPE_ARRAY 2
  #define BPF_FUNC_map_lookup_elem 1
  #define BPF_FUNC_map_update_elem 2

  static void *(*bpf_map_lookup_elem)(void *map, void *key) =
	  (void *) BPF_FUNC_map_lookup_elem;
  static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =
	  (void *) BPF_FUNC_map_update_elem;

  struct bpf_map_def {
	  unsigned int type;
	  unsigned int key_size;
	  unsigned int value_size;
	  unsigned int max_entries;
  };

  #define SEC(NAME) __attribute__((section(NAME), used))
  struct bpf_map_def SEC("maps") flip_table = {
	  .type = BPF_MAP_TYPE_ARRAY,
	  .key_size = sizeof(int),
	  .value_size = sizeof(int),
	  .max_entries = 1,
  };

  SEC("func=SyS_epoll_wait")
  int bpf_func__SyS_epoll_wait(void *ctx)
  {
	  int ind =0;
	  int *flag = bpf_map_lookup_elem(&flip_table, &ind);
	  int new_flag;
	  if (!flag)
		  return 0;
	  /* flip flag and store back */
	  new_flag = !*flag;
	  bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);
	  return new_flag;
  }
  char _license[] SEC("license") = "GPL";
  int _version SEC("version") = LINUX_VERSION_CODE;
  ' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
  test child finished with 0
  ---- end ----
  LLVM search and compile subtest 0: Ok
  37.2: kbuild searching                                    :
  --- start ---
  test child forked, pid 25950
  Kernel build dir is set to /lib/modules/4.14.0+/build
  set env: KBUILD_DIR=/lib/modules/4.14.0+/build
  unset env: KBUILD_OPTS
  include option is set to  -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h
  set env: NR_CPUS=4
  set env: LINUX_VERSION_CODE=0x40e00
  set env: CLANG_EXEC=/usr/local/bin/clang
  set env: CLANG_OPTIONS=-xc
  set env: KERNEL_INC_OPTIONS= -nostdinc -isystem /usr/lib/gcc/x86_64-redhat-linux/7/include -I/home/acme/git/linux/arch/x86/include -I./arch/x86/include/generated  -I/home/acme/git/linux/include -I./include -I/home/acme/git/linux/arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I/home/acme/git/linux/include/uapi -I./include/generated/uapi -include /home/acme/git/linux/include/linux/kconfig.h
  set env: WORKING_DIR=/lib/modules/4.14.0+/build
  set env: CLANG_SOURCE=-
  llvm compiling command template: echo '/*
   * bpf-script-test-kbuild.c
   * Test include from kernel header
   */
  #ifndef LINUX_VERSION_CODE
  # error Need LINUX_VERSION_CODE
  # error Example: for 4.2 kernel, put 'clang-opt="-DLINUX_VERSION_CODE=0x40200" into llvm section of ~/.perfconfig'
  #endif
  #define SEC(NAME) __attribute__((section(NAME), used))

  #include <uapi/linux/fs.h>
  #include <uapi/asm/ptrace.h>

  SEC("func=vfs_llseek")
  int bpf_func__vfs_llseek(void *ctx)
  {
	  return 0;
  }

  char _license[] SEC("license") = "GPL";
  int _version SEC("version") = LINUX_VERSION_CODE;
  ' | $CLANG_EXEC -D__KERNEL__ -D__NR_CPUS__=$NR_CPUS -DLINUX_VERSION_CODE=$LINUX_VERSION_CODE $CLANG_OPTIONS $KERNEL_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
  In file included from <stdin>:12:
  In file included from /home/acme/git/linux/arch/x86/include/uapi/asm/ptrace.h:5:
  In file included from /home/acme/git/linux/include/linux/compiler.h:242:
  In file included from /home/acme/git/linux/arch/x86/include/asm/barrier.h:5:
  In file included from /home/acme/git/linux/arch/x86/include/asm/alternative.h:10:
  /home/acme/git/linux/arch/x86/include/asm/asm.h:145:50: error: unknown register name 'esp' in asm
  register unsigned long current_stack_pointer asm(_ASM_SP);
                                                   ^
  /home/acme/git/linux/arch/x86/include/asm/asm.h:44:18: note: expanded from macro '_ASM_SP'
  #define _ASM_SP         __ASM_REG(sp)
                          ^
  /home/acme/git/linux/arch/x86/include/asm/asm.h:27:32: note: expanded from macro '__ASM_REG'
  #define __ASM_REG(reg)         __ASM_SEL_RAW(e##reg, r##reg)
                                 ^
  /home/acme/git/linux/arch/x86/include/asm/asm.h:18:29: note: expanded from macro '__ASM_SEL_RAW'
  # define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(a)
                              ^
  /home/acme/git/linux/arch/x86/include/asm/asm.h:11:32: note: expanded from macro '__ASM_FORM_RAW'
  # define __ASM_FORM_RAW(x)     #x
                                 ^
  <scratch space>:4:1: note: expanded from here
  "esp"
  ^
  1 error generated.
  ERROR:	unable to compile -
  Hint:	Check error message shown above.
  Hint:	You can also pre-compile it into .o using:
     		  clang -target bpf -O2 -c -
     	  with proper -I and -D options.
  Failed to compile test case: 'kbuild searching'
  test child finished with -1
  ---- end ----
  LLVM search and compile subtest 1: FAILED!

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matthias Kaehlcke <mka@chromium.org>
Cc: Miguel Bernal Marin <miguel.bernal.marin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: Yonghong Song <yhs@fb.com>
Link: https://lkml.kernel.org/r/20171128175948.GL3298@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 arch/x86/include/asm/asm.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
index 219faae..386a690 100644
--- a/arch/x86/include/asm/asm.h
+++ b/arch/x86/include/asm/asm.h
@@ -136,6 +136,7 @@
 #endif
 
 #ifndef __ASSEMBLY__
+#ifndef __BPF__
 /*
  * This output constraint should be used for any inline asm which has a "call"
  * instruction.  Otherwise the asm may be inserted before the frame pointer
@@ -145,5 +146,6 @@
 register unsigned long current_stack_pointer asm(_ASM_SP);
 #define ASM_CALL_CONSTRAINT "+r" (current_stack_pointer)
 #endif
+#endif
 
 #endif /* _ASM_X86_ASM_H */

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2017-12-18 17:26 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-24 14:47 perf test LLVM & clang 6 failing Arnaldo Carvalho de Melo
2017-11-24 15:16 ` Daniel Borkmann
2017-11-24 19:09   ` Arnaldo Carvalho de Melo
2017-11-26  6:29     ` Yonghong Song
2017-11-27 17:04   ` Arnaldo Carvalho de Melo
2017-11-27 19:11     ` Yonghong Song
2017-11-27 19:34       ` Arnaldo Carvalho de Melo
2017-11-27 19:57         ` Josh Poimboeuf
2017-11-27 21:45           ` Matthias Kaehlcke
2017-11-28  1:19             ` Yonghong Song
2017-11-28 17:55             ` Arnaldo Carvalho de Melo
2017-11-28 17:59               ` Arnaldo Carvalho de Melo
2017-12-06 16:44                 ` [tip:perf/core] x86/asm: Allow again using asm.h when building for the 'bpf' clang target tip-bot for Arnaldo Carvalho de Melo
2017-12-18 17:17                 ` [tip:perf/urgent] " tip-bot for Arnaldo Carvalho de Melo
2017-11-27 20:05         ` perf test LLVM & clang 6 failing Arnaldo Carvalho de Melo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.