Build BPF selftests and libbpf and bpftool, that are used as part of
selftests, in debug mode (specifically, -Og). This makes it much simpler and
nicer to do development and/or bug fixing. See patch #4 for some unscientific
measurements.
This patch set fixes new maybe-unitialized warnings produced in -Og build
mode. Patch #1 fixes the blocker which was causing some XDP selftests failures
due to non-zero padding in bpf_xdp_set_link_opts, which only happened in debug
mode.
Andrii Nakryiko (4):
libbpf: add explicit padding to bpf_xdp_set_link_opts
bpftool: fix maybe-uninitialized warnings
selftests/bpf: fix maybe-uninitialized warning in xdpxceiver test
selftests/bpf: build everything in debug mode
tools/bpf/bpftool/btf.c | 3 +++
tools/bpf/bpftool/main.c | 3 +--
tools/bpf/bpftool/map.c | 2 +-
tools/lib/bpf/libbpf.h | 1 +
tools/testing/selftests/bpf/Makefile | 7 +++++--
tools/testing/selftests/bpf/xdpxceiver.c | 4 ++--
6 files changed, 13 insertions(+), 7 deletions(-)
--
2.24.1
Adding such anonymous padding fixes the issue with uninitialized portions of
bpf_xdp_set_link_opts when using LIBBPF_DECLARE_OPTS macro with inline field
initialization:
DECLARE_LIBBPF_OPTS(bpf_xdp_set_link_opts, opts, .old_fd = -1);
When such code is compiled in debug mode, compiler is generating code that
leaves padding bytes uninitialized, which triggers error inside libbpf APIs
that do strict zero initialization checks for OPTS structs.
Adding anonymous padding field fixes the issue.
Fixes: bd5ca3ef93cd ("libbpf: Add function to set link XDP fd while specifying old program")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/lib/bpf/libbpf.h | 1 +
1 file changed, 1 insertion(+)
@@ -546,6 +546,7 @@ static int do_dump(int argc, char **argv)NEXT_ARG();if(argc<1){p_err("expecting value for 'format' option\n");+err=-EINVAL;gotodone;}if(strcmp(*argv,"c")==0){
@@ -555,11 +556,13 @@ static int do_dump(int argc, char **argv)}else{p_err("unrecognized format specifier: '%s', possible values: raw, c",*argv);+err=-EINVAL;gotodone;}NEXT_ARG();}else{p_err("unrecognized option: '%s'",*argv);+err=-EINVAL;gotodone;}}
xsk_ring_prod__reserve() doesn't necessarily set idx in some conditions, so
from static analysis point of view compiler is right about the problems like:
In file included from xdpxceiver.c:92:
xdpxceiver.c: In function ‘xsk_populate_fill_ring’:
/data/users/andriin/linux/tools/testing/selftests/bpf/tools/include/bpf/xsk.h:119:20: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
return &addrs[idx & fill->mask];
~~~~^~~~~~~~~~~~
xdpxceiver.c:300:6: note: ‘idx’ was declared here
u32 idx;
^~~
xdpxceiver.c: In function ‘tx_only’:
xdpxceiver.c:596:30: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
struct xdp_desc *tx_desc = xsk_ring_prod__tx_desc(&xsk->tx, idx + i);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fix two warnings reported by compiler by pre-initializing variable.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/testing/selftests/bpf/xdpxceiver.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Build selftests, bpftool, and libbpf in debug mode with DWARF data to
facilitate easier debugging.
In terms of impact on building and running selftests. Build is actually faster
now:
BEFORE: make -j60 380.21s user 37.87s system 1466% cpu 28.503 total
AFTER: make -j60 345.47s user 37.37s system 1599% cpu 23.939 total
test_progs runtime seems to be the same:
BEFORE:
real 1m5.139s
user 0m1.600s
sys 0m43.977s
AFTER:
real 1m3.799s
user 0m1.721s
sys 0m42.420s
Huge difference is being able to debug issues throughout test_progs, bpftool,
and libbpf without constantly updating 3 Makefiles by hand (including GDB
seeing the source code without any extra incantations).
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/testing/selftests/bpf/Makefile | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
On Sat, Mar 13, 2021 at 1:09 PM Andrii Nakryiko [off-list ref] wrote:
quoted hunk
Build selftests, bpftool, and libbpf in debug mode with DWARF data to
facilitate easier debugging.
In terms of impact on building and running selftests. Build is actually faster
now:
BEFORE: make -j60 380.21s user 37.87s system 1466% cpu 28.503 total
AFTER: make -j60 345.47s user 37.37s system 1599% cpu 23.939 total
test_progs runtime seems to be the same:
BEFORE:
real 1m5.139s
user 0m1.600s
sys 0m43.977s
AFTER:
real 1m3.799s
user 0m1.721s
sys 0m42.420s
Huge difference is being able to debug issues throughout test_progs, bpftool,
and libbpf without constantly updating 3 Makefiles by hand (including GDB
seeing the source code without any extra incantations).
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/testing/selftests/bpf/Makefile | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
I was asked about '-Og' flag and the minimum GCC version that supports
it. It seems it was added in GCC 4.8 ([0]), so given the kernel's
minimum version is GCC 4.9, we shouldn't need take any extra
precautions to handle older compilers.
[0] https://gcc.gnu.org/gcc-4.8/changes.html
Build BPF selftests and libbpf and bpftool, that are used as part of
selftests, in debug mode (specifically, -Og). This makes it much simpler and
nicer to do development and/or bug fixing. See patch #4 for some unscientific
measurements.
This patch set fixes new maybe-unitialized warnings produced in -Og build
mode. Patch #1 fixes the blocker which was causing some XDP selftests failures
due to non-zero padding in bpf_xdp_set_link_opts, which only happened in debug
mode.
It was applied. gitbot doesn't seem to auto-reply anymore. hmm.
On Tue, Mar 16, 2021 at 2:02 PM Alexei Starovoitov [off-list ref] wrote:
On 3/13/21 1:09 PM, Andrii Nakryiko wrote:
quoted
Build BPF selftests and libbpf and bpftool, that are used as part of
selftests, in debug mode (specifically, -Og). This makes it much simpler and
nicer to do development and/or bug fixing. See patch #4 for some unscientific
measurements.
This patch set fixes new maybe-unitialized warnings produced in -Og build
mode. Patch #1 fixes the blocker which was causing some XDP selftests failures
due to non-zero padding in bpf_xdp_set_link_opts, which only happened in debug
mode.
It was applied. gitbot doesn't seem to auto-reply anymore. hmm.
Thanks! Yeah, it seems to be unreliable lately. I think it sent some
notifications yesterday, but not all.