Check the detach return status and test traffic after XDP detach and reattach while an XSK remains bound. Clean socket and UMEM owners on second-step barrier failure. Port the registration and documentation to the current net-next selftest layout. Signed-off-by: Satish Kharat --- tools/testing/selftests/net/lib/xsk/test_xsk.c | 51 +++++++++++++++++++++++- tools/testing/selftests/net/lib/xsk/test_xsk.h | 2 + tools/testing/selftests/net/lib/xsk/xsk.c | 4 +- tools/testing/selftests/net/lib/xsk/xsk.h | 2 +- tools/testing/selftests/net/lib/xsk/xskxceiver.c | 23 ++++++----- 5 files changed, 67 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.c b/tools/testing/selftests/net/lib/xsk/test_xsk.c index ca161511f1e5..edcaca946ac5 100644 --- a/tools/testing/selftests/net/lib/xsk/test_xsk.c +++ b/tools/testing/selftests/net/lib/xsk/test_xsk.c @@ -1728,7 +1728,11 @@ static int xsk_reattach_xdp(struct ifobject *ifobj, struct bpf_program *xdp_prog { int err; - xsk_detach_xdp_program(ifobj->ifindex, mode_to_xdp_flags(ifobj->mode)); + err = xsk_detach_xdp_program(ifobj->ifindex, + mode_to_xdp_flags(ifobj->mode)); + if (err) + return err; + err = xsk_attach_xdp_program(xdp_prog, ifobj->ifindex, mode_to_xdp_flags(mode)); if (err) { ksft_print_msg("Error attaching XDP program\n"); @@ -1841,7 +1845,12 @@ static int __testapp_validate_traffic(struct test_spec *test, struct ifobject *i test->use_barrier = false; pthread_join(t0, NULL); clean_sockets(test, ifobj1); - clean_umem(test, ifobj1, NULL); + if (test->current_step > 1) { + clean_sockets(test, ifobj2); + clean_umem(test, ifobj1, ifobj2); + } else { + clean_umem(test, ifobj1, NULL); + } return TEST_FAILURE; } } @@ -1975,6 +1984,44 @@ int testapp_xdp_prog_cleanup(struct test_spec *test) return testapp_validate_traffic(test); } +int testapp_xdp_prog_detach_xsk_bound(struct test_spec *test) +{ + struct ifobject *ifobj_rx = test->ifobj_rx; + int err; + + test->total_steps = 2; + err = testapp_validate_traffic(test); + if (err) { + if (err == TEST_FAILURE) + test->fail = true; + return err; + } + + err = xsk_detach_xdp_program(ifobj_rx->ifindex, + mode_to_xdp_flags(ifobj_rx->mode)); + if (err) { + ksft_print_msg("Error detaching XDP program while XSK is bound: %s\n", + strerror(-err)); + test->fail = true; + clean_sockets(test, test->ifobj_rx); + clean_sockets(test, test->ifobj_tx); + clean_umem(test, test->ifobj_rx, test->ifobj_tx); + return TEST_FAILURE; + } + + ifobj_rx->xdp_prog = NULL; + err = testapp_validate_traffic(test); + if (err == TEST_FAILURE) + test->fail = true; + if (err && test->current_step < test->total_steps) { + clean_sockets(test, test->ifobj_rx); + clean_sockets(test, test->ifobj_tx); + clean_umem(test, test->ifobj_rx, test->ifobj_tx); + } + + return err; +} + int testapp_headroom(struct test_spec *test) { test->ifobj_rx->xsk->umem->frame_headroom = UMEM_HEADROOM_TEST_SIZE; diff --git a/tools/testing/selftests/net/lib/xsk/test_xsk.h b/tools/testing/selftests/net/lib/xsk/test_xsk.h index 2506b0dcc6bf..12b9fc7e2933 100644 --- a/tools/testing/selftests/net/lib/xsk/test_xsk.h +++ b/tools/testing/selftests/net/lib/xsk/test_xsk.h @@ -266,6 +266,7 @@ int testapp_unaligned_inv_desc_mb(struct test_spec *test); int testapp_xdp_drop(struct test_spec *test); int testapp_xdp_metadata(struct test_spec *test); int testapp_xdp_metadata_mb(struct test_spec *test); +int testapp_xdp_prog_detach_xsk_bound(struct test_spec *test); int testapp_xdp_prog_cleanup(struct test_spec *test); int testapp_xdp_shared_umem(struct test_spec *test); @@ -297,6 +298,7 @@ static const struct test_spec tests[] = { {.name = "TOO_MANY_FRAGS", .test_func = testapp_too_many_frags}, {.name = "XDP_ADJUST_TAIL_SHRINK", .test_func = testapp_adjust_tail_shrink}, {.name = "TX_QUEUE_CONSUMER", .test_func = testapp_tx_queue_consumer}, + {.name = "XDP_PROG_DETACH_XSK_BOUND", .test_func = testapp_xdp_prog_detach_xsk_bound}, /* Flaky tests */ {.name = "XDP_ADJUST_TAIL_SHRINK_MULTI_BUFF", .test_func = testapp_adjust_tail_shrink_mb}, {.name = "XDP_ADJUST_TAIL_GROW", .test_func = testapp_adjust_tail_grow}, diff --git a/tools/testing/selftests/net/lib/xsk/xsk.c b/tools/testing/selftests/net/lib/xsk/xsk.c index 4e9d14f883ac..f16a233dd83d 100644 --- a/tools/testing/selftests/net/lib/xsk/xsk.c +++ b/tools/testing/selftests/net/lib/xsk/xsk.c @@ -429,9 +429,9 @@ int xsk_attach_xdp_program(struct bpf_program *prog, int ifindex, u32 xdp_flags) return bpf_xdp_attach(ifindex, prog_fd, xdp_flags, NULL); } -void xsk_detach_xdp_program(int ifindex, u32 xdp_flags) +int xsk_detach_xdp_program(int ifindex, u32 xdp_flags) { - bpf_xdp_detach(ifindex, xdp_flags, NULL); + return bpf_xdp_detach(ifindex, xdp_flags, NULL); } void xsk_clear_xskmap(struct bpf_map *map) diff --git a/tools/testing/selftests/net/lib/xsk/xsk.h b/tools/testing/selftests/net/lib/xsk/xsk.h index 3f1fea999763..6d3f40becbdb 100644 --- a/tools/testing/selftests/net/lib/xsk/xsk.h +++ b/tools/testing/selftests/net/lib/xsk/xsk.h @@ -205,7 +205,7 @@ struct xsk_umem_config { }; int xsk_attach_xdp_program(struct bpf_program *prog, int ifindex, u32 xdp_flags); -void xsk_detach_xdp_program(int ifindex, u32 xdp_flags); +int xsk_detach_xdp_program(int ifindex, u32 xdp_flags); int xsk_update_xskmap(struct bpf_map *map, struct xsk_socket *xsk, u32 index); void xsk_clear_xskmap(struct bpf_map *map); bool xsk_is_in_mode(u32 ifindex, int mode); diff --git a/tools/testing/selftests/net/lib/xsk/xskxceiver.c b/tools/testing/selftests/net/lib/xsk/xskxceiver.c index 0a63651434a5..af096119d6b2 100644 --- a/tools/testing/selftests/net/lib/xsk/xskxceiver.c +++ b/tools/testing/selftests/net/lib/xsk/xskxceiver.c @@ -41,18 +41,21 @@ * Reduce the size of the RX ring to a fraction of the fill ring size. * iv. fill queue empty * Do not populate the fill queue and then try to receive pkts. - * f. bpf_link resource persistence - * Configure sockets at indexes 0 and 1, run a traffic on queue ids 0, - * then remove xsk sockets from queue 0 on both veth interfaces and - * finally run a traffic on queues ids 1 - * g. unaligned mode - * h. tests for invalid and corner case Tx descriptors so that the correct ones + * f. XDP program resource persistence + * Configure two sockets per interface, run traffic on the first socket, + * replace the XSKMAP entry with the second socket without reattaching the + * program, then verify traffic again. + * g. XDP program detach while an XSK is bound + * Run traffic, detach and reattach the XDP program without closing the + * socket, then verify traffic again. + * h. unaligned mode + * i. tests for invalid and corner case Tx descriptors so that the correct ones * are discarded and let through, respectively. - * i. 2K frame size tests - * j. If multi-buffer is supported, send 9k packets divided into 3 frames - * k. If multi-buffer and huge pages are supported, send 9k packets in a single frame + * j. 2K frame size tests + * k. If multi-buffer is supported, send 9k packets divided into 3 frames + * l. If multi-buffer and huge pages are supported, send 9k packets in a single frame * using unaligned mode - * l. If multi-buffer is supported, try various nasty combinations of descriptors to + * m. If multi-buffer is supported, try various nasty combinations of descriptors to * check if they pass the validation or not * * Flow: -- 2.43.0