Skip to content

Commit f12f1b5

Browse files
bastien-curutchetAlexei Starovoitov
authored andcommitted
selftests/bpf: test_xsk: Don't exit immediately when xsk_attach fails
xsk_reattach_xdp calls exit_with_error() on failures. This exits the program immediately. It prevents the following tests from being run and isn't compliant with the CI. Add a return value to the functions handling XDP attachments to handle errors more smoothly. Reviewed-by: Maciej Fijalkowski <[email protected]> Signed-off-by: Bastien Curutchet (eBPF Foundation) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent e645bcf commit f12f1b5

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

tools/testing/selftests/bpf/test_xsk.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,7 +1643,7 @@ static bool xdp_prog_changed_tx(struct test_spec *test)
16431643
return ifobj->xdp_prog != test->xdp_prog_tx || ifobj->mode != test->mode;
16441644
}
16451645

1646-
static void xsk_reattach_xdp(struct ifobject *ifobj, struct bpf_program *xdp_prog,
1646+
static int xsk_reattach_xdp(struct ifobject *ifobj, struct bpf_program *xdp_prog,
16471647
struct bpf_map *xskmap, enum test_mode mode)
16481648
{
16491649
int err;
@@ -1652,31 +1652,40 @@ static void xsk_reattach_xdp(struct ifobject *ifobj, struct bpf_program *xdp_pro
16521652
err = xsk_attach_xdp_program(xdp_prog, ifobj->ifindex, mode_to_xdp_flags(mode));
16531653
if (err) {
16541654
ksft_print_msg("Error attaching XDP program\n");
1655-
exit_with_error(-err);
1655+
return err;
16561656
}
16571657

16581658
if (ifobj->mode != mode && (mode == TEST_MODE_DRV || mode == TEST_MODE_ZC))
16591659
if (!xsk_is_in_mode(ifobj->ifindex, XDP_FLAGS_DRV_MODE)) {
16601660
ksft_print_msg("ERROR: XDP prog not in DRV mode\n");
1661-
exit_with_error(EINVAL);
1661+
return -EINVAL;
16621662
}
16631663

16641664
ifobj->xdp_prog = xdp_prog;
16651665
ifobj->xskmap = xskmap;
16661666
ifobj->mode = mode;
1667+
1668+
return 0;
16671669
}
16681670

1669-
static void xsk_attach_xdp_progs(struct test_spec *test, struct ifobject *ifobj_rx,
1671+
static int xsk_attach_xdp_progs(struct test_spec *test, struct ifobject *ifobj_rx,
16701672
struct ifobject *ifobj_tx)
16711673
{
1672-
if (xdp_prog_changed_rx(test))
1673-
xsk_reattach_xdp(ifobj_rx, test->xdp_prog_rx, test->xskmap_rx, test->mode);
1674+
int err = 0;
1675+
1676+
if (xdp_prog_changed_rx(test)) {
1677+
err = xsk_reattach_xdp(ifobj_rx, test->xdp_prog_rx, test->xskmap_rx, test->mode);
1678+
if (err)
1679+
return err;
1680+
}
16741681

16751682
if (!ifobj_tx || ifobj_tx->shared_umem)
1676-
return;
1683+
return 0;
16771684

16781685
if (xdp_prog_changed_tx(test))
1679-
xsk_reattach_xdp(ifobj_tx, test->xdp_prog_tx, test->xskmap_tx, test->mode);
1686+
err = xsk_reattach_xdp(ifobj_tx, test->xdp_prog_tx, test->xskmap_tx, test->mode);
1687+
1688+
return err;
16801689
}
16811690

16821691
static void clean_sockets(struct test_spec *test, struct ifobject *ifobj)
@@ -1789,7 +1798,8 @@ static int testapp_validate_traffic(struct test_spec *test)
17891798
}
17901799
}
17911800

1792-
xsk_attach_xdp_progs(test, ifobj_rx, ifobj_tx);
1801+
if (xsk_attach_xdp_progs(test, ifobj_rx, ifobj_tx))
1802+
return TEST_FAILURE;
17931803
return __testapp_validate_traffic(test, ifobj_rx, ifobj_tx);
17941804
}
17951805

0 commit comments

Comments
 (0)