bpf: emit map name in register state if applicable and available
authorAndrii Nakryiko <andrii@kernel.org>
Sat, 18 Nov 2023 03:46:20 +0000 (19:46 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 18 Nov 2023 19:39:59 +0000 (11:39 -0800)
commit0c95c9fdb696f35c7864785ba84cb9a50152daff
tree909fcb7acbc43862d80a67c68c62e4b41b09b16d
parent67d43dfbb42d6575304daea67733c88fbf536a1c
bpf: emit map name in register state if applicable and available

In complicated real-world applications, whenever debugging some
verification error through verifier log, it often would be very useful
to see map name for PTR_TO_MAP_VALUE register. Usually this needs to be
inferred from key/value sizes and maybe trying to guess C code location,
but it's not always clear.

Given verifier has the name, and it's never too long, let's just emit it
for ptr_to_map_key, ptr_to_map_value, and const_ptr_to_map registers. We
reshuffle the order a bit, so that map name, key size, and value size
appear before offset and immediate values, which seems like a more
logical order.

Current output:

  R1_w=map_ptr(map=array_map,ks=4,vs=8,off=0,imm=0)

But we'll get rid of useless off=0 and imm=0 parts in the next patch.

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-6-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/log.c
tools/testing/selftests/bpf/prog_tests/spin_lock.c