Skip to content

Commit

Permalink
bpf: selftest: Trigger a DCE on the whole subprog
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Martin KaFai Lau authored and Alexei Starovoitov committed Nov 6, 2021
1 parent 3990ed4 commit d99341b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tools/testing/selftests/bpf/progs/for_each_array_map_elem.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ struct callback_ctx {
int output;
};

const volatile int bypass_unused = 1;

static __u64
unused_subprog(struct bpf_map *map, __u32 *key, __u64 *val,
struct callback_ctx *data)
{
data->output = 0;
return 1;
}

static __u64
check_array_elem(struct bpf_map *map, __u32 *key, __u64 *val,
struct callback_ctx *data)
Expand Down Expand Up @@ -54,6 +64,8 @@ int test_pkt_access(struct __sk_buff *skb)

data.output = 0;
bpf_for_each_map_elem(&arraymap, check_array_elem, &data, 0);
if (!bypass_unused)
bpf_for_each_map_elem(&arraymap, unused_subprog, &data, 0);
arraymap_output = data.output;

bpf_for_each_map_elem(&percpu_map, check_percpu_elem, (void *)0, 0);
Expand Down

0 comments on commit d99341b

Please sign in to comment.