Skip to content

Commit

Permalink
selftests/xsk: Add support check for bpf_xdp_adjust_tail() helper in …
Browse files Browse the repository at this point in the history
…xskxceiver

Add is_adjust_tail_supported function to check if the
bpf_xdp_adjust_tail() helper is supported when 'adjust_tail' is set in the
test. Look up a specific key in the bss section of the XDP program. If the
key is not found or its value is -EOPNOTSUPP, return false, indicating that
the helper is not supported.

Signed-off-by: Tushar Vyavahare <[email protected]>
  • Loading branch information
tvyavaha authored and Kernel Patches Daemon committed Feb 21, 2025
1 parent 90107a8 commit 6dac82b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
36 changes: 34 additions & 2 deletions tools/testing/selftests/bpf/xskxceiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,8 @@ static void __test_spec_init(struct test_spec *test, struct ifobject *ifobj_tx,
test->nb_sockets = 1;
test->fail = false;
test->set_ring = false;
test->adjust_tail = false;
test->adjust_tail_support = false;
test->mtu = MAX_ETH_PKT_SIZE;
test->xdp_prog_rx = ifobj_rx->xdp_progs->progs.xsk_def_prog;
test->xskmap_rx = ifobj_rx->xdp_progs->maps.xsk;
Expand Down Expand Up @@ -992,6 +994,31 @@ static bool is_metadata_correct(struct pkt *pkt, void *buffer, u64 addr)
return true;
}

static bool is_adjust_tail_supported(struct xsk_xdp_progs *skel_rx)
{
struct bpf_map *data_map;
int value = 0;
int key = 0;
int ret;

data_map = bpf_object__find_map_by_name(skel_rx->obj, "xsk_xdp_.bss");
if (!data_map || !bpf_map__is_internal(data_map)) {
ksft_print_msg("Error: could not find bss section of XDP program\n");
exit_with_error(errno);
}

ret = bpf_map_lookup_elem(bpf_map__fd(data_map), &key, &value);
if (ret) {
ksft_print_msg("Error: bpf_map_lookup_elem failed with error %d\n", ret);
return false;
}

/* Set the 'count' variable to -EOPNOTSUPP in the XDP program if the adjust_tail helper is
* not supported. Skip the adjust_tail test case in this scenario.
*/
return value != -EOPNOTSUPP;
}

static bool is_frag_valid(struct xsk_umem_info *umem, u64 addr, u32 len, u32 expected_pkt_nb,
u32 bytes_processed)
{
Expand Down Expand Up @@ -1768,8 +1795,13 @@ static void *worker_testapp_validate_rx(void *arg)

if (!err && ifobject->validation_func)
err = ifobject->validation_func(ifobject);
if (err)
report_failure(test);

if (err) {
if (test->adjust_tail && !is_adjust_tail_supported(ifobject->xdp_progs))
test->adjust_tail_support = false;
else
report_failure(test);
}

pthread_exit(NULL);
}
Expand Down
2 changes: 2 additions & 0 deletions tools/testing/selftests/bpf/xskxceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ struct test_spec {
u16 nb_sockets;
bool fail;
bool set_ring;
bool adjust_tail;
bool adjust_tail_support;
enum test_mode mode;
char name[MAX_TEST_NAME_SIZE];
};
Expand Down

0 comments on commit 6dac82b

Please sign in to comment.