Skip to content

Commit d124d98

Browse files
TropicaoMartin KaFai Lau
authored andcommitted
selftests/bpf: check program redirect in xdp_cpumap_attach
xdp_cpumap_attach, in its current form, only checks that an xdp cpumap program can be executed, but not that it performs correctly the cpu redirect as configured by userspace (bpf_prog_test_run_opts will return success even if the redirect program returns an error) Add a check to ensure that the program performs the configured redirect as well. The check is based on a global variable incremented by a chained program executed only if the redirect program properly executes. Signed-off-by: Alexis Lothoré (eBPF Foundation) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
1 parent d5fbcf4 commit d124d98

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

tools/testing/selftests/bpf/prog_tests/xdp_cpumap_attach.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ static void test_xdp_with_cpumap_helpers(void)
6262
err = bpf_prog_test_run_opts(prog_redir_fd, &opts);
6363
ASSERT_OK(err, "XDP test run");
6464

65-
/* wait for the packets to be flushed */
65+
/* wait for the packets to be flushed, then check that redirect has been
66+
* performed
67+
*/
6668
kern_sync_rcu();
69+
ASSERT_NEQ(skel->bss->redirect_count, 0, "redirected packets");
6770

6871
err = bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_SKB_MODE, NULL);
6972
ASSERT_OK(err, "XDP program detach");

tools/testing/selftests/bpf/progs/test_xdp_with_cpumap_helpers.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ struct {
1212
__uint(max_entries, 4);
1313
} cpu_map SEC(".maps");
1414

15+
__u32 redirect_count = 0;
16+
1517
SEC("xdp")
1618
int xdp_redir_prog(struct xdp_md *ctx)
1719
{
@@ -27,6 +29,9 @@ int xdp_dummy_prog(struct xdp_md *ctx)
2729
SEC("xdp/cpumap")
2830
int xdp_dummy_cm(struct xdp_md *ctx)
2931
{
32+
if (bpf_get_smp_processor_id() == 0)
33+
redirect_count++;
34+
3035
if (ctx->ingress_ifindex == IFINDEX_LO)
3136
return XDP_DROP;
3237

0 commit comments

Comments
 (0)