Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: selftest: Trigger a DCE on the whole subprog

This patch adds a test to trigger the DCE to remove
the whole subprog to ensure the verifier does not
depend on a stable subprog index. The DCE is done
by testing a global const.

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211106014020.651638-1-kafai@fb.com

authored by

Martin KaFai Lau and committed by
Alexei Starovoitov
d99341b3 3990ed4c

+12
+12
tools/testing/selftests/bpf/progs/for_each_array_map_elem.c
··· 23 23 int output; 24 24 }; 25 25 26 + const volatile int bypass_unused = 1; 27 + 28 + static __u64 29 + unused_subprog(struct bpf_map *map, __u32 *key, __u64 *val, 30 + struct callback_ctx *data) 31 + { 32 + data->output = 0; 33 + return 1; 34 + } 35 + 26 36 static __u64 27 37 check_array_elem(struct bpf_map *map, __u32 *key, __u64 *val, 28 38 struct callback_ctx *data) ··· 64 54 65 55 data.output = 0; 66 56 bpf_for_each_map_elem(&arraymap, check_array_elem, &data, 0); 57 + if (!bypass_unused) 58 + bpf_for_each_map_elem(&arraymap, unused_subprog, &data, 0); 67 59 arraymap_output = data.output; 68 60 69 61 bpf_for_each_map_elem(&percpu_map, check_percpu_elem, (void *)0, 0);