selftests/bpf: Fix bench runner SIGSEGV
authorAndrii Nakryiko <andrii@kernel.org>
Thu, 1 Feb 2024 17:20:27 +0000 (09:20 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 1 Feb 2024 21:16:12 +0000 (22:16 +0100)
commit943b043aeecce9accb6d367af47791c633e95e4d
tree97a7fbc05a135c421de0685dceeb38ee74693da4
parentb9551da8cf3ade01a50316df8a618fd945723ee0
selftests/bpf: Fix bench runner SIGSEGV

Some benchmarks don't have either "consumer" or "producer" sides. For
example, trig-tp and other BPF triggering benchmarks don't have
consumers, as they only do "producing" by calling into syscall or
predefined uproes. As such it's valid for some benchmarks to have zero
consumers or producers. So allows to specify `-c0` explicitly.

This triggers another problem. If benchmark doesn't support either
consumer or producer side, consumer_thread/producer_thread callback will
be NULL, but benchmark runner will attempt to use those NULL callback to
create threads anyways. So instead of crashing with SIGSEGV in case of
misconfigured benchmark, detect the condition and report error.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/bpf/20240201172027.604869-6-andrii@kernel.org
tools/testing/selftests/bpf/bench.c