linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* BPF relocation 'perf test' entries failing was: Re: [GIT PULL 00/27] perf/core improvements and fixes
@ 2018-07-26 13:15 Arnaldo Carvalho de Melo
  2018-07-26 17:34 ` Sandipan Das
  0 siblings, 1 reply; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-07-26 13:15 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann
  Cc: Ingo Molnar, Martin KaFai Lau, Clark Williams, linux-perf-users,
	Adrian Hunter, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Wang Nan, linux-kernel

Em Wed, Jul 25, 2018 at 02:59:34PM -0300, Arnaldo Carvalho de Melo escreveu:
> Hi Ingo,
> 
> 	Please consider pulling, I'm now investigating why these failed:
> 
>   38: LLVM search and compile                               :
>   38.1: Basic BPF llvm compile                              : Ok
>   38.2: kbuild searching                                    : Ok
>   38.3: Compile source for BPF prologue generation          : Ok
>   38.4: Compile source for BPF relocation                   : FAILED!
>   40: BPF filter                                            :
>   40.1: Basic BPF filtering                                 : Ok
>   40.2: BPF pinning                                         : Ok
>   40.3: BPF prologue generation                             : Ok
>   40.4: BPF relocation checker                              : FAILED!
> 
> 	I think these failures are not related to changes in this patch
> kit. Details about the test environment, versions, etc.

So, here are more details:

The relevant bit seems to be:

libbpf: Program 'func=sys_write' contains non-map related relo data pointing to section 65522

So this seems to be something that was caught by the kernel verifier and
now is being caught by libbpf, /me goes to read the tools/lib/bpf
changelog...

- Arnaldo

BPF filter subtest 2: Ok
40.3: BPF prologue generation                             :
--- start ---
test child forked, pid 13336
Kernel build dir is set to /lib/modules/4.18.0-rc6-00093-g9981b4fb8684/build
set env: KBUILD_DIR=/lib/modules/4.18.0-rc6-00093-g9981b4fb8684/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=0x41200
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: PERF_BPF_INC_OPTIONS=-I/home/acme/lib/include/perf/bpf
set env: WORKING_DIR=/lib/modules/4.18.0-rc6-00093-g9981b4fb8684/build
set env: CLANG_SOURCE=-
llvm compiling command template: echo '/*
 * bpf-script-test-relocation.c
 * Test BPF loader checking relocation
 */
#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") my_table = {
	.type = BPF_MAP_TYPE_ARRAY,
	.key_size = sizeof(int),
	.value_size = sizeof(int),
	.max_entries = 1,
};

int this_is_a_global_val;

SEC("func=sys_write")
int bpf_func__sys_write(void *ctx)
{
	int key = 0;
	int value = 0;

	/*
	 * Incorrect relocation. Should not allow this program be
	 * loaded into kernel.
	 */
	bpf_map_update_elem(&this_is_a_global_val, &key, &value, 0);
	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 $PERF_BPF_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
llvm compiling command : echo '/*
 * bpf-script-test-relocation.c
 * Test BPF loader checking relocation
 */
#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) my_table = {
	.type = BPF_MAP_TYPE_ARRAY,
	.key_size = sizeof(int),
	.value_size = sizeof(int),
	.max_entries = 1,
};

int this_is_a_global_val;

SEC(func=sys_write)
int bpf_func__sys_write(void *ctx)
{
	int key = 0;
	int value = 0;

	/*
	 * Incorrect relocation. Should not allow this program be
	 * loaded into kernel.
	 */
	bpf_map_update_elem(&this_is_a_global_val, &key, &value, 0);
	return 0;
}
char _license[] SEC(license) = GPL;
int _version SEC(version) = LINUX_VERSION_CODE;
' | /usr/lib64/ccache/clang -D__KERNEL__ -D__NR_CPUS__=4 -DLINUX_VERSION_CODE=0x41200 -xc   -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  -I/home/acme/lib/include/perf/bpf -Wno-unused-value -Wno-pointer-sign -working-directory /lib/modules/4.18.0-rc6-00093-g9981b4fb8684/build -c - -target bpf -O2 -o -
libbpf: loading object '[bpf_relocation_test]' from buffer
libbpf: section(1) .strtab, size 115, link 0, flags 0, type=3
libbpf: skip section(1) .strtab
libbpf: section(2) .text, size 0, link 0, flags 6, type=1
libbpf: skip section(2) .text
libbpf: section(3) func=sys_write, size 104, link 0, flags 6, type=1
libbpf: found program func=sys_write
libbpf: section(4) .relfunc=sys_write, size 16, link 8, flags 0, type=9
libbpf: section(5) maps, size 16, link 0, flags 3, type=1
libbpf: section(6) license, size 4, link 0, flags 3, type=1
libbpf: license of [bpf_relocation_test] is GPL
libbpf: section(7) version, size 4, link 0, flags 3, type=1
libbpf: kernel version of [bpf_relocation_test] is 41200
libbpf: section(8) .symtab, size 144, link 1, flags 0, type=2
libbpf: maps in [bpf_relocation_test]: 1 maps in 16 bytes
libbpf: map 0 is "my_table"
libbpf: collecting relocating info for: 'func=sys_write'
libbpf: relo for 5 value 4 name 21
libbpf: Program 'func=sys_write' contains non-map related relo data pointing to section 65522
bpf: failed to load buffer
Compile BPF program failed.
test child finished with 0
---- end ----
BPF filter subtest 3: Ok
40.4: BPF relocation checker                              :
--- start ---
test child forked, pid 13746
test child finished with -1
---- end ----
BPF filter subtest 4: FAILED!
[root@seventh ~]#

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

* Re: BPF relocation 'perf test' entries failing was: Re: [GIT PULL 00/27] perf/core improvements and fixes
  2018-07-26 13:15 BPF relocation 'perf test' entries failing was: Re: [GIT PULL 00/27] perf/core improvements and fixes Arnaldo Carvalho de Melo
@ 2018-07-26 17:34 ` Sandipan Das
  2018-07-26 18:58   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 5+ messages in thread
From: Sandipan Das @ 2018-07-26 17:34 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Alexei Starovoitov, Daniel Borkmann, Ingo Molnar,
	Martin KaFai Lau, Clark Williams, linux-perf-users,
	Adrian Hunter, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Wang Nan, linux-kernel, Naveen N. Rao

Hi Arnaldo,

I came across the same problem. Does the following patch fix it?
https://lkml.org/lkml/2018/7/26/669

- Sandipan

On Thursday 26 July 2018 06:45 PM, Arnaldo Carvalho de Melo wrote:
> Em Wed, Jul 25, 2018 at 02:59:34PM -0300, Arnaldo Carvalho de Melo escreveu:
>> Hi Ingo,
>>
>> 	Please consider pulling, I'm now investigating why these failed:
>>
>>   38: LLVM search and compile                               :
>>   38.1: Basic BPF llvm compile                              : Ok
>>   38.2: kbuild searching                                    : Ok
>>   38.3: Compile source for BPF prologue generation          : Ok
>>   38.4: Compile source for BPF relocation                   : FAILED!
>>   40: BPF filter                                            :
>>   40.1: Basic BPF filtering                                 : Ok
>>   40.2: BPF pinning                                         : Ok
>>   40.3: BPF prologue generation                             : Ok
>>   40.4: BPF relocation checker                              : FAILED!
>>
>> 	I think these failures are not related to changes in this patch
>> kit. Details about the test environment, versions, etc.
> 
> So, here are more details:
> 
> The relevant bit seems to be:
> 
> libbpf: Program 'func=sys_write' contains non-map related relo data pointing to section 65522
> 
> So this seems to be something that was caught by the kernel verifier and
> now is being caught by libbpf, /me goes to read the tools/lib/bpf
> changelog...
> 
> - Arnaldo
> 
> BPF filter subtest 2: Ok
> 40.3: BPF prologue generation                             :
> --- start ---
> test child forked, pid 13336
> Kernel build dir is set to /lib/modules/4.18.0-rc6-00093-g9981b4fb8684/build
> set env: KBUILD_DIR=/lib/modules/4.18.0-rc6-00093-g9981b4fb8684/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=0x41200
> 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: PERF_BPF_INC_OPTIONS=-I/home/acme/lib/include/perf/bpf
> set env: WORKING_DIR=/lib/modules/4.18.0-rc6-00093-g9981b4fb8684/build
> set env: CLANG_SOURCE=-
> llvm compiling command template: echo '/*
>  * bpf-script-test-relocation.c
>  * Test BPF loader checking relocation
>  */
> #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") my_table = {
> 	.type = BPF_MAP_TYPE_ARRAY,
> 	.key_size = sizeof(int),
> 	.value_size = sizeof(int),
> 	.max_entries = 1,
> };
> 
> int this_is_a_global_val;
> 
> SEC("func=sys_write")
> int bpf_func__sys_write(void *ctx)
> {
> 	int key = 0;
> 	int value = 0;
> 
> 	/*
> 	 * Incorrect relocation. Should not allow this program be
> 	 * loaded into kernel.
> 	 */
> 	bpf_map_update_elem(&this_is_a_global_val, &key, &value, 0);
> 	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 $PERF_BPF_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
> llvm compiling command : echo '/*
>  * bpf-script-test-relocation.c
>  * Test BPF loader checking relocation
>  */
> #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) my_table = {
> 	.type = BPF_MAP_TYPE_ARRAY,
> 	.key_size = sizeof(int),
> 	.value_size = sizeof(int),
> 	.max_entries = 1,
> };
> 
> int this_is_a_global_val;
> 
> SEC(func=sys_write)
> int bpf_func__sys_write(void *ctx)
> {
> 	int key = 0;
> 	int value = 0;
> 
> 	/*
> 	 * Incorrect relocation. Should not allow this program be
> 	 * loaded into kernel.
> 	 */
> 	bpf_map_update_elem(&this_is_a_global_val, &key, &value, 0);
> 	return 0;
> }
> char _license[] SEC(license) = GPL;
> int _version SEC(version) = LINUX_VERSION_CODE;
> ' | /usr/lib64/ccache/clang -D__KERNEL__ -D__NR_CPUS__=4 -DLINUX_VERSION_CODE=0x41200 -xc   -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  -I/home/acme/lib/include/perf/bpf -Wno-unused-value -Wno-pointer-sign -working-directory /lib/modules/4.18.0-rc6-00093-g9981b4fb8684/build -c - -target bpf -O2 -o -
> libbpf: loading object '[bpf_relocation_test]' from buffer
> libbpf: section(1) .strtab, size 115, link 0, flags 0, type=3
> libbpf: skip section(1) .strtab
> libbpf: section(2) .text, size 0, link 0, flags 6, type=1
> libbpf: skip section(2) .text
> libbpf: section(3) func=sys_write, size 104, link 0, flags 6, type=1
> libbpf: found program func=sys_write
> libbpf: section(4) .relfunc=sys_write, size 16, link 8, flags 0, type=9
> libbpf: section(5) maps, size 16, link 0, flags 3, type=1
> libbpf: section(6) license, size 4, link 0, flags 3, type=1
> libbpf: license of [bpf_relocation_test] is GPL
> libbpf: section(7) version, size 4, link 0, flags 3, type=1
> libbpf: kernel version of [bpf_relocation_test] is 41200
> libbpf: section(8) .symtab, size 144, link 1, flags 0, type=2
> libbpf: maps in [bpf_relocation_test]: 1 maps in 16 bytes
> libbpf: map 0 is "my_table"
> libbpf: collecting relocating info for: 'func=sys_write'
> libbpf: relo for 5 value 4 name 21
> libbpf: Program 'func=sys_write' contains non-map related relo data pointing to section 65522
> bpf: failed to load buffer
> Compile BPF program failed.
> test child finished with 0
> ---- end ----
> BPF filter subtest 3: Ok
> 40.4: BPF relocation checker                              :
> --- start ---
> test child forked, pid 13746
> test child finished with -1
> ---- end ----
> BPF filter subtest 4: FAILED!
> [root@seventh ~]#
> 
> 


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

* Re: BPF relocation 'perf test' entries failing was: Re: [GIT PULL 00/27] perf/core improvements and fixes
  2018-07-26 17:34 ` Sandipan Das
@ 2018-07-26 18:58   ` Arnaldo Carvalho de Melo
  2018-07-26 19:14     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-07-26 18:58 UTC (permalink / raw)
  To: Sandipan Das
  Cc: Alexei Starovoitov, Daniel Borkmann, Ingo Molnar,
	Martin KaFai Lau, Clark Williams, linux-perf-users,
	Adrian Hunter, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Wang Nan, linux-kernel, Naveen N. Rao

Em Thu, Jul 26, 2018 at 11:04:08PM +0530, Sandipan Das escreveu:
> Hi Arnaldo,
> 
> I came across the same problem. Does the following patch fix it?
> https://lkml.org/lkml/2018/7/26/669

Oh my, that one was subtle... Checking...

- Arnaldo
 
> - Sandipan
> 
> On Thursday 26 July 2018 06:45 PM, Arnaldo Carvalho de Melo wrote:
> > Em Wed, Jul 25, 2018 at 02:59:34PM -0300, Arnaldo Carvalho de Melo escreveu:
> >> Hi Ingo,
> >>
> >> 	Please consider pulling, I'm now investigating why these failed:
> >>
> >>   38: LLVM search and compile                               :
> >>   38.1: Basic BPF llvm compile                              : Ok
> >>   38.2: kbuild searching                                    : Ok
> >>   38.3: Compile source for BPF prologue generation          : Ok
> >>   38.4: Compile source for BPF relocation                   : FAILED!
> >>   40: BPF filter                                            :
> >>   40.1: Basic BPF filtering                                 : Ok
> >>   40.2: BPF pinning                                         : Ok
> >>   40.3: BPF prologue generation                             : Ok
> >>   40.4: BPF relocation checker                              : FAILED!
> >>
> >> 	I think these failures are not related to changes in this patch
> >> kit. Details about the test environment, versions, etc.
> > 
> > So, here are more details:
> > 
> > The relevant bit seems to be:
> > 
> > libbpf: Program 'func=sys_write' contains non-map related relo data pointing to section 65522
> > 
> > So this seems to be something that was caught by the kernel verifier and
> > now is being caught by libbpf, /me goes to read the tools/lib/bpf
> > changelog...
> > 
> > - Arnaldo
> > 
> > BPF filter subtest 2: Ok
> > 40.3: BPF prologue generation                             :
> > --- start ---
> > test child forked, pid 13336
> > Kernel build dir is set to /lib/modules/4.18.0-rc6-00093-g9981b4fb8684/build
> > set env: KBUILD_DIR=/lib/modules/4.18.0-rc6-00093-g9981b4fb8684/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=0x41200
> > 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: PERF_BPF_INC_OPTIONS=-I/home/acme/lib/include/perf/bpf
> > set env: WORKING_DIR=/lib/modules/4.18.0-rc6-00093-g9981b4fb8684/build
> > set env: CLANG_SOURCE=-
> > llvm compiling command template: echo '/*
> >  * bpf-script-test-relocation.c
> >  * Test BPF loader checking relocation
> >  */
> > #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") my_table = {
> > 	.type = BPF_MAP_TYPE_ARRAY,
> > 	.key_size = sizeof(int),
> > 	.value_size = sizeof(int),
> > 	.max_entries = 1,
> > };
> > 
> > int this_is_a_global_val;
> > 
> > SEC("func=sys_write")
> > int bpf_func__sys_write(void *ctx)
> > {
> > 	int key = 0;
> > 	int value = 0;
> > 
> > 	/*
> > 	 * Incorrect relocation. Should not allow this program be
> > 	 * loaded into kernel.
> > 	 */
> > 	bpf_map_update_elem(&this_is_a_global_val, &key, &value, 0);
> > 	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 $PERF_BPF_INC_OPTIONS -Wno-unused-value -Wno-pointer-sign -working-directory $WORKING_DIR -c "$CLANG_SOURCE" -target bpf -O2 -o -
> > llvm compiling command : echo '/*
> >  * bpf-script-test-relocation.c
> >  * Test BPF loader checking relocation
> >  */
> > #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) my_table = {
> > 	.type = BPF_MAP_TYPE_ARRAY,
> > 	.key_size = sizeof(int),
> > 	.value_size = sizeof(int),
> > 	.max_entries = 1,
> > };
> > 
> > int this_is_a_global_val;
> > 
> > SEC(func=sys_write)
> > int bpf_func__sys_write(void *ctx)
> > {
> > 	int key = 0;
> > 	int value = 0;
> > 
> > 	/*
> > 	 * Incorrect relocation. Should not allow this program be
> > 	 * loaded into kernel.
> > 	 */
> > 	bpf_map_update_elem(&this_is_a_global_val, &key, &value, 0);
> > 	return 0;
> > }
> > char _license[] SEC(license) = GPL;
> > int _version SEC(version) = LINUX_VERSION_CODE;
> > ' | /usr/lib64/ccache/clang -D__KERNEL__ -D__NR_CPUS__=4 -DLINUX_VERSION_CODE=0x41200 -xc   -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  -I/home/acme/lib/include/perf/bpf -Wno-unused-value -Wno-pointer-sign -working-directory /lib/modules/4.18.0-rc6-00093-g9981b4fb8684/build -c - -target bpf -O2 -o -
> > libbpf: loading object '[bpf_relocation_test]' from buffer
> > libbpf: section(1) .strtab, size 115, link 0, flags 0, type=3
> > libbpf: skip section(1) .strtab
> > libbpf: section(2) .text, size 0, link 0, flags 6, type=1
> > libbpf: skip section(2) .text
> > libbpf: section(3) func=sys_write, size 104, link 0, flags 6, type=1
> > libbpf: found program func=sys_write
> > libbpf: section(4) .relfunc=sys_write, size 16, link 8, flags 0, type=9
> > libbpf: section(5) maps, size 16, link 0, flags 3, type=1
> > libbpf: section(6) license, size 4, link 0, flags 3, type=1
> > libbpf: license of [bpf_relocation_test] is GPL
> > libbpf: section(7) version, size 4, link 0, flags 3, type=1
> > libbpf: kernel version of [bpf_relocation_test] is 41200
> > libbpf: section(8) .symtab, size 144, link 1, flags 0, type=2
> > libbpf: maps in [bpf_relocation_test]: 1 maps in 16 bytes
> > libbpf: map 0 is "my_table"
> > libbpf: collecting relocating info for: 'func=sys_write'
> > libbpf: relo for 5 value 4 name 21
> > libbpf: Program 'func=sys_write' contains non-map related relo data pointing to section 65522
> > bpf: failed to load buffer
> > Compile BPF program failed.
> > test child finished with 0
> > ---- end ----
> > BPF filter subtest 3: Ok
> > 40.4: BPF relocation checker                              :
> > --- start ---
> > test child forked, pid 13746
> > test child finished with -1
> > ---- end ----
> > BPF filter subtest 4: FAILED!
> > [root@seventh ~]#
> > 
> > 

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

* Re: BPF relocation 'perf test' entries failing was: Re: [GIT PULL 00/27] perf/core improvements and fixes
  2018-07-26 18:58   ` Arnaldo Carvalho de Melo
@ 2018-07-26 19:14     ` Arnaldo Carvalho de Melo
  2018-07-27  6:27       ` Thomas-Mich Richter
  0 siblings, 1 reply; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-07-26 19:14 UTC (permalink / raw)
  To: Sandipan Das
  Cc: Alexei Starovoitov, Daniel Borkmann, Ingo Molnar,
	Martin KaFai Lau, Clark Williams, linux-perf-users,
	Adrian Hunter, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Wang Nan, linux-kernel, Naveen N. Rao, Heiko Carstens,
	Hendrik Brueckner, Martin Schwidefsky, Ravi Bangoria,
	Thomas Richter

Em Thu, Jul 26, 2018 at 03:58:05PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Thu, Jul 26, 2018 at 11:04:08PM +0530, Sandipan Das escreveu:
> > I came across the same problem. Does the following patch fix it?

> > https://lkml.org/lkml/2018/7/26/669
 
> Oh my, that one was subtle... Checking...

Right, when it said it was running:

  40.3: BPF prologue generation

In fact it was running:

  40.4: BPF relocation checker

That error message in the 'perf test -v' output:

  libbpf: Program 'func=sys_write' contains non-map related relo data pointing to section 65522

Was the _expected_ one for "40.4: BPF relocation checker", then it
failed when it couldn't run the off by one "last" subtest, duh.

Thomas, this was a problem introduced by a patch from you, just for
reference, this one:

    Fixes: 9ef0112442bd ("perf test: Fix subtest number when showing results")

I should have caught this by running 'perf test' before/after applying
that patch, I'll now make sure this is done before sending pull reqs
upstream.

In fact I did after, and thought, hey, some BPF related regression, I
must've updated clang/llvm and something new appeared on the radar, so I
went that direction and went nowhere, well, now I have an uptodate
llvm/clang combo to play with BTF, pahole, etc 8-)

Thanks!

- Arnaldo

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

* Re: BPF relocation 'perf test' entries failing was: Re: [GIT PULL 00/27] perf/core improvements and fixes
  2018-07-26 19:14     ` Arnaldo Carvalho de Melo
@ 2018-07-27  6:27       ` Thomas-Mich Richter
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas-Mich Richter @ 2018-07-27  6:27 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Sandipan Das
  Cc: Alexei Starovoitov, Daniel Borkmann, Ingo Molnar,
	Martin KaFai Lau, Clark Williams, linux-perf-users,
	Adrian Hunter, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Wang Nan, linux-kernel, Naveen N. Rao, Heiko Carstens,
	Hendrik Brueckner, Martin Schwidefsky, Ravi Bangoria

On 07/26/2018 09:14 PM, Arnaldo Carvalho de Melo wrote:
> Em Thu, Jul 26, 2018 at 03:58:05PM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Thu, Jul 26, 2018 at 11:04:08PM +0530, Sandipan Das escreveu:
>>> I came across the same problem. Does the following patch fix it?
> 
>>> https://lkml.org/lkml/2018/7/26/669
>  
>> Oh my, that one was subtle... Checking...
> 
> Right, when it said it was running:
> 
>   40.3: BPF prologue generation
> 
> In fact it was running:
> 
>   40.4: BPF relocation checker
> 
> That error message in the 'perf test -v' output:
> 
>   libbpf: Program 'func=sys_write' contains non-map related relo data pointing to section 65522
> 
> Was the _expected_ one for "40.4: BPF relocation checker", then it
> failed when it couldn't run the off by one "last" subtest, duh.
> 
> Thomas, this was a problem introduced by a patch from you, just for
> reference, this one:
> 
>     Fixes: 9ef0112442bd ("perf test: Fix subtest number when showing results")
> 
> I should have caught this by running 'perf test' before/after applying
> that patch, I'll now make sure this is done before sending pull reqs
> upstream.
> 
> In fact I did after, and thought, hey, some BPF related regression, I
> must've updated clang/llvm and something new appeared on the radar, so I
> went that direction and went nowhere, well, now I have an uptodate
> llvm/clang combo to play with BTF, pahole, etc 8-)
> 
> Thanks!
> 
> - Arnaldo



Sandipan,
thanks for fixing what I have messed up.

Arnaldo,
sorry for the hickup, I should have caught this too. In fact I ran
perf test before and after, but redirected the output and just 
looked at the grep'ed lines on the screen....
I should be looked more carefully...

Apologies for the mess and thanks again for fixing this.

-- 
Thomas Richter, Dept 3303, IBM s390 Linux Development, Boeblingen, Germany
--
Vorsitzende des Aufsichtsrats: Martina Koederitz 
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294


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

end of thread, other threads:[~2018-07-27  6:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-26 13:15 BPF relocation 'perf test' entries failing was: Re: [GIT PULL 00/27] perf/core improvements and fixes Arnaldo Carvalho de Melo
2018-07-26 17:34 ` Sandipan Das
2018-07-26 18:58   ` Arnaldo Carvalho de Melo
2018-07-26 19:14     ` Arnaldo Carvalho de Melo
2018-07-27  6:27       ` Thomas-Mich Richter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).