Skip to content

Commit d41905b

Browse files
mfijalkoborkmann
authored andcommitted
selftests/xsk: Read current MAX_SKB_FRAGS from sysctl knob
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 <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Magnus Karlsson <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 6b08365 commit d41905b

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

tools/testing/selftests/bpf/xskxceiver.c

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,25 @@ static bool ifobj_zc_avail(struct ifobject *ifobject)
324324
return zc_avail;
325325
}
326326

327+
#define MAX_SKB_FRAGS_PATH "/proc/sys/net/core/max_skb_frags"
328+
static unsigned int get_max_skb_frags(void)
329+
{
330+
unsigned int max_skb_frags = 0;
331+
FILE *file;
332+
333+
file = fopen(MAX_SKB_FRAGS_PATH, "r");
334+
if (!file) {
335+
ksft_print_msg("Error opening %s\n", MAX_SKB_FRAGS_PATH);
336+
return 0;
337+
}
338+
339+
if (fscanf(file, "%u", &max_skb_frags) != 1)
340+
ksft_print_msg("Error reading %s\n", MAX_SKB_FRAGS_PATH);
341+
342+
fclose(file);
343+
return max_skb_frags;
344+
}
345+
327346
static struct option long_options[] = {
328347
{"interface", required_argument, 0, 'i'},
329348
{"busy-poll", no_argument, 0, 'b'},
@@ -2244,13 +2263,24 @@ static int testapp_poll_rxq_tmout(struct test_spec *test)
22442263

22452264
static int testapp_too_many_frags(struct test_spec *test)
22462265
{
2247-
struct pkt pkts[2 * XSK_DESC__MAX_SKB_FRAGS + 2] = {};
2266+
struct pkt *pkts;
22482267
u32 max_frags, i;
2268+
int ret;
22492269

2250-
if (test->mode == TEST_MODE_ZC)
2270+
if (test->mode == TEST_MODE_ZC) {
22512271
max_frags = test->ifobj_tx->xdp_zc_max_segs;
2252-
else
2253-
max_frags = XSK_DESC__MAX_SKB_FRAGS;
2272+
} else {
2273+
max_frags = get_max_skb_frags();
2274+
if (!max_frags) {
2275+
ksft_print_msg("Couldn't retrieve MAX_SKB_FRAGS from system, using default (17) value\n");
2276+
max_frags = 17;
2277+
}
2278+
max_frags += 1;
2279+
}
2280+
2281+
pkts = calloc(2 * max_frags + 2, sizeof(struct pkt));
2282+
if (!pkts)
2283+
return TEST_FAILURE;
22542284

22552285
test->mtu = MAX_ETH_JUMBO_SIZE;
22562286

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

22822312
pkt_stream_generate_custom(test, pkts, 2 * max_frags + 2);
2283-
return testapp_validate_traffic(test);
2313+
ret = testapp_validate_traffic(test);
2314+
2315+
free(pkts);
2316+
return ret;
22842317
}
22852318

22862319
static int xsk_load_xdp_programs(struct ifobject *ifobj)

tools/testing/selftests/bpf/xskxceiver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
#define XSK_UMEM__LARGE_FRAME_SIZE (3 * 1024)
5656
#define XSK_UMEM__MAX_FRAME_SIZE (4 * 1024)
5757
#define XSK_DESC__INVALID_OPTION (0xffff)
58-
#define XSK_DESC__MAX_SKB_FRAGS 18
5958
#define HUGEPAGE_SIZE (2 * 1024 * 1024)
6059
#define PKT_DUMP_NB_TO_PRINT 16
6160
#define RUN_ALL_TESTS UINT_MAX

0 commit comments

Comments
 (0)