bpf: smarter verifier log number printing logic
authorAndrii Nakryiko <andrii@kernel.org>
Sat, 18 Nov 2023 03:46:22 +0000 (19:46 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 18 Nov 2023 19:39:59 +0000 (11:39 -0800)
commit0f8dbdbc641b45a5fa31d497f9fc83ffe1174fa3
tree61c1b84c3d0a9bf8c43a17438d126b24d53cbd8c
parent1db747d75b1dbe17bf4283ed87bd3b7a92010f34
bpf: smarter verifier log number printing logic

Instead of always printing numbers as either decimals (and in some
cases, like for "imm=%llx", in hexadecimals), decide the form based on
actual values. For numbers in a reasonably small range (currently,
[0, U16_MAX] for unsigned values, and [S16_MIN, S16_MAX] for signed ones),
emit them as decimals. In all other cases, even for signed values,
emit them in hexadecimals.

For large values hex form is often times way more useful: it's easier to
see an exact difference between 0xffffffff80000000 and 0xffffffff7fffffff,
than between 18446744071562067966 and 18446744071562067967, as one
particular example.

Small values representing small pointer offsets or application
constants, on the other hand, are way more useful to be represented in
decimal notation.

Adjust reg_bounds register state parsing logic to take into account this
change.

Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Acked-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20231118034623.3320920-8-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/log.c
tools/testing/selftests/bpf/prog_tests/reg_bounds.c
tools/testing/selftests/bpf/progs/exceptions_assert.c