selftests/bpf: Add write to hashmap to array_map iter test
authorDave Marchevsky <davemarchevsky@fb.com>
Thu, 20 Oct 2022 16:07:21 +0000 (09:07 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 22 Oct 2022 02:23:34 +0000 (19:23 -0700)
commit8f4bc15b9ad73434643aadb19506e1547bedf7eb
tree693d1f58ea21ec39c9b60d98ee9c4087133a63ef
parent51ee71d38d8ce5a30496251200ab2f12b71e1fb6
selftests/bpf: Add write to hashmap to array_map iter test

Modify iter prog in existing bpf_iter_bpf_array_map.c, which currently
dumps arraymap key/val, to also do a write of (val, key) into a
newly-added hashmap. Confirm that the write succeeds as expected by
modifying the userspace runner program.

Before a change added in an earlier commit - considering PTR_TO_BUF reg
a valid input to helpers which expect MAP_{KEY,VAL} - the verifier
would've rejected this prog change due to type mismatch. Since using
current iter's key/val to access a separate map is a reasonable usecase,
let's add support for it.

Note that the test prog cannot directly write (val, key) into hashmap
via bpf_map_update_elem when both come from iter context because key is
marked MEM_RDONLY. This is due to bpf_map_update_elem - and other basic
map helpers - taking ARG_PTR_TO_MAP_{KEY,VALUE} w/o MEM_RDONLY type
flag. bpf_map_{lookup,update,delete}_elem don't modify their
input key/val so it should be possible to tag their args READONLY, but
due to the ubiquitous use of these helpers and verifier checks for
type == MAP_VALUE, such a change is nontrivial and seems better to
address in a followup series.

Also fixup some 'goto's in test runner's map checking loop.

Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20221020160721.4030492-4-davemarchevsky@fb.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/bpf_iter.c
tools/testing/selftests/bpf/progs/bpf_iter_bpf_array_map.c