Skip to content

Commit

Permalink
selftests/xsk: Read current MAX_SKB_FRAGS from sysctl knob
Browse files Browse the repository at this point in the history
Currently, xskxceiver assumes that MAX_SKB_FRAGS value is always 17
which is not true - since the introduction of BIG TCP this can now take
any value between 17 to 45 via CONFIG_MAX_SKB_FRAGS.

Adjust the TOO_MANY_FRAGS test case to read the currently configured
MAX_SKB_FRAGS value by reading it from /proc/sys/net/core/max_skb_frags.
If running system does not provide that sysctl file then let us try
running the test with a default value.

Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>
Link: https://lore.kernel.org/bpf/20240910124129.289874-1-maciej.fijalkowski@intel.com
  • Loading branch information
mfijalko authored and borkmann committed Sep 11, 2024
1 parent 6b08365 commit d41905b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
43 changes: 38 additions & 5 deletions tools/testing/selftests/bpf/xskxceiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,25 @@ static bool ifobj_zc_avail(struct ifobject *ifobject)
return zc_avail;
}

#define MAX_SKB_FRAGS_PATH "/proc/sys/net/core/max_skb_frags"
static unsigned int get_max_skb_frags(void)
{
unsigned int max_skb_frags = 0;
FILE *file;

file = fopen(MAX_SKB_FRAGS_PATH, "r");
if (!file) {
ksft_print_msg("Error opening %s\n", MAX_SKB_FRAGS_PATH);
return 0;
}

if (fscanf(file, "%u", &max_skb_frags) != 1)
ksft_print_msg("Error reading %s\n", MAX_SKB_FRAGS_PATH);

fclose(file);
return max_skb_frags;
}

static struct option long_options[] = {
{"interface", required_argument, 0, 'i'},
{"busy-poll", no_argument, 0, 'b'},
Expand Down Expand Up @@ -2244,13 +2263,24 @@ static int testapp_poll_rxq_tmout(struct test_spec *test)

static int testapp_too_many_frags(struct test_spec *test)
{
struct pkt pkts[2 * XSK_DESC__MAX_SKB_FRAGS + 2] = {};
struct pkt *pkts;
u32 max_frags, i;
int ret;

if (test->mode == TEST_MODE_ZC)
if (test->mode == TEST_MODE_ZC) {
max_frags = test->ifobj_tx->xdp_zc_max_segs;
else
max_frags = XSK_DESC__MAX_SKB_FRAGS;
} else {
max_frags = get_max_skb_frags();
if (!max_frags) {
ksft_print_msg("Couldn't retrieve MAX_SKB_FRAGS from system, using default (17) value\n");
max_frags = 17;
}
max_frags += 1;
}

pkts = calloc(2 * max_frags + 2, sizeof(struct pkt));
if (!pkts)
return TEST_FAILURE;

test->mtu = MAX_ETH_JUMBO_SIZE;

Expand Down Expand Up @@ -2280,7 +2310,10 @@ static int testapp_too_many_frags(struct test_spec *test)
pkts[2 * max_frags + 1].valid = true;

pkt_stream_generate_custom(test, pkts, 2 * max_frags + 2);
return testapp_validate_traffic(test);
ret = testapp_validate_traffic(test);

free(pkts);
return ret;
}

static int xsk_load_xdp_programs(struct ifobject *ifobj)
Expand Down
1 change: 0 additions & 1 deletion tools/testing/selftests/bpf/xskxceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#define XSK_UMEM__LARGE_FRAME_SIZE (3 * 1024)
#define XSK_UMEM__MAX_FRAME_SIZE (4 * 1024)
#define XSK_DESC__INVALID_OPTION (0xffff)
#define XSK_DESC__MAX_SKB_FRAGS 18
#define HUGEPAGE_SIZE (2 * 1024 * 1024)
#define PKT_DUMP_NB_TO_PRINT 16
#define RUN_ALL_TESTS UINT_MAX
Expand Down

0 comments on commit d41905b

Please sign in to comment.