samples/bpf: fix sockex2 example
Subsystems (3)
PATCH 1/2 samples/bpf: fix sockex2 example
since llvm commit "Do not expand UNDEF SDNode during insn selection lowering" llvm will generate code that uses uninitialized registers for cases where C code is actually uses uninitialized data.
So this sockex2 example is technically broken.
Fix it by initializing on the stack variable fully.
Also increase verifier buffer limit, since verifier output
may not fit in 64k for this sockex2 code depending on llvm version.
--- samples/bpf/libbpf.h | 2 +- samples/bpf/sockex2_kern.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
samples/bpf/libbpf.h +1 -1
@@ -18,7 +18,7 @@ int bpf_prog_load(enum bpf_prog_type prog_type,int bpf_obj_pin (int fd,const char *pathname);int bpf_obj_get (const char *pathname); -#define LOG_BUF_SIZE 65536 +#define LOG_BUF_SIZE (256 * 1024)extern char bpf_log_buf[LOG_BUF_SIZE ];/* ALU ops on registers, bpf_add|sub|...: dst_reg += src_reg */
samples/bpf/sockex2_kern.c +1 -1
@@ -198,7 +198,7 @@ struct bpf_map_def SEC("maps") hash_map = { SEC("socket2")int bpf_prog2 (struct __sk_buff *skb) { -struct bpf_flow_keys flow; +struct bpf_flow_keys flow = {};struct pair *value;u32 key;
Signature · 1 line
2.8.0
PATCH 2/2 samples/bpf: fix bpf loader
llvm can emit relocations into sections other than program code (like debug info sections). Ignore them during parsing of elf file
--- samples/bpf/bpf_load.c | 4 ++++ 1 file changed, 4 insertions(+)
samples/bpf/bpf_load.c +4 -0
@@ -317,6 +317,10 @@ int load_bpf_file(char *path) &shdr_prog, &data_prog))continue ; +if (shdr_prog.sh_type !=SHT_PROGBITS || + !(shdr_prog.sh_flags &SHF_EXECINSTR )) +continue ; + insns = (struct bpf_insn *) data_prog->d_buf; processed_sec[shdr.sh_info] = true;
Signature · 1 line
2.8.0
Re: [PATCH net-next 2/2] samples/bpf: fix bpf loader
Quoted 4 lines · Alexei Starovoitov
llvm can emit relocations into sections other than program code (like debug info sections). Ignore them during parsing of elf file
Signed-off-by Alexei Starovoitov <[email protected]>
Re: [PATCH net-next 2/2] samples/bpf: fix bpf loader
In reply to Alexei StarovoitovFrom: Alexei Starovoitov <[email protected]>
Date: Tue, 22 Nov 2016 16:52:09 -0800
Quoted 4 lines
llvm can emit relocations into sections other than program code (like debug info sections). Ignore them during parsing of elf file
Signed-off-by Alexei Starovoitov <[email protected]>
Applied.
Quoted 9 lines · Alexei Starovoitov
since llvm commit "Do not expand UNDEF SDNode during insn selection lowering" llvm will generate code that uses uninitialized registers for cases where C code is actually uses uninitialized data.
So this sockex2 example is technically broken.
Fix it by initializing on the stack variable fully.
Also increase verifier buffer limit, since verifier output
may not fit in 64k for this sockex2 code depending on llvm version.Signed-off-by Alexei Starovoitov <[email protected]>
From: Alexei Starovoitov <[email protected]>
Date: Tue, 22 Nov 2016 16:52:08 -0800
Quoted 9 lines
since llvm commit "Do not expand UNDEF SDNode during insn selection lowering" llvm will generate code that uses uninitialized registers for cases where C code is actually uses uninitialized data.
So this sockex2 example is technically broken.
Fix it by initializing on the stack variable fully.
Also increase verifier buffer limit, since verifier output
may not fit in 64k for this sockex2 code depending on llvm version.Signed-off-by Alexei Starovoitov <[email protected]>
Applied.