diff mbox series

[bpf-next] selftests: xsk: read current MAX_SKB_FRAGS from sysctl knob

Message ID 20240909141110.284967-1-maciej.fijalkowski@intel.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] selftests: xsk: read current MAX_SKB_FRAGS from sysctl knob | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-4 success Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-16 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-17 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-12 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-18 success Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-35 success Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-27 success Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-28 success Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-41 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-33 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-34 success Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 success Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for x86_64-gcc / veristat / veristat on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-36 success Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-32 success Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-29 success Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-40 success Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-22 success Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-31 success Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-39 success Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-30 success Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
bpf/vmtest-bpf-next-VM_Test-37 success Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-38 success Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-25 success Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 13 maintainers not CCed: jonathan.lemon@gmail.com mykolal@fb.com eddyz87@gmail.com sdf@fomichev.me haoluo@google.com shuah@kernel.org jolsa@kernel.org linux-kselftest@vger.kernel.org song@kernel.org yonghong.song@linux.dev kpsingh@kernel.org martin.lau@linux.dev john.fastabend@gmail.com
netdev/build_clang success Errors and warnings before: 7 this patch: 7
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 69 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Maciej Fijalkowski Sept. 9, 2024, 2:11 p.m. UTC
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.

Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
 tools/testing/selftests/bpf/xskxceiver.c | 41 +++++++++++++++++++++---
 tools/testing/selftests/bpf/xskxceiver.h |  1 -
 2 files changed, 36 insertions(+), 6 deletions(-)

Comments

Magnus Karlsson Sept. 10, 2024, 11:48 a.m. UTC | #1
On Mon, 9 Sept 2024 at 16:12, Maciej Fijalkowski
<maciej.fijalkowski@intel.com> wrote:
>
> 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.
>
> Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
> ---
>  tools/testing/selftests/bpf/xskxceiver.c | 41 +++++++++++++++++++++---
>  tools/testing/selftests/bpf/xskxceiver.h |  1 -
>  2 files changed, 36 insertions(+), 6 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
> index 92af633faea8..595b6da26897 100644
> --- a/tools/testing/selftests/bpf/xskxceiver.c
> +++ b/tools/testing/selftests/bpf/xskxceiver.c
> @@ -325,6 +325,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'},
> @@ -2245,13 +2264,22 @@ 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)
> +                       return TEST_FAILURE;

Thanks for this fix Maciej. However, I think failing the test here is
a little bit too drastic. How about just returning TEST_SKIP and print
out that the max number of skbs is unknown as the reason for the skip?
Or even more optimistically, print out a warning that we could not
read the max number of skb but we are guessing 17 and then run the
test? If it passes, great we guessed correctly, but if it fails we are
not worse off than the current code. Do not know how often a file
system does not contain /proc/sys/net/core/max_skb_frags though.

> +               max_frags += 1;
> +       }
> +
> +       pkts = calloc(2 * max_frags + 2, sizeof(struct pkt));
> +       if (!pkts)
> +               return TEST_FAILURE;
>
>         test->mtu = MAX_ETH_JUMBO_SIZE;
>
> @@ -2281,7 +2309,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)
> diff --git a/tools/testing/selftests/bpf/xskxceiver.h b/tools/testing/selftests/bpf/xskxceiver.h
> index 885c948c5d83..e46e823f6a1a 100644
> --- a/tools/testing/selftests/bpf/xskxceiver.h
> +++ b/tools/testing/selftests/bpf/xskxceiver.h
> @@ -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
> --
> 2.34.1
>
>
Maciej Fijalkowski Sept. 10, 2024, noon UTC | #2
On Tue, Sep 10, 2024 at 01:48:35PM +0200, Magnus Karlsson wrote:
> On Mon, 9 Sept 2024 at 16:12, Maciej Fijalkowski
> <maciej.fijalkowski@intel.com> wrote:
> >
> > 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.
> >
> > Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
> > ---
> >  tools/testing/selftests/bpf/xskxceiver.c | 41 +++++++++++++++++++++---
> >  tools/testing/selftests/bpf/xskxceiver.h |  1 -
> >  2 files changed, 36 insertions(+), 6 deletions(-)
> >
> > diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
> > index 92af633faea8..595b6da26897 100644
> > --- a/tools/testing/selftests/bpf/xskxceiver.c
> > +++ b/tools/testing/selftests/bpf/xskxceiver.c
> > @@ -325,6 +325,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'},
> > @@ -2245,13 +2264,22 @@ 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)
> > +                       return TEST_FAILURE;
> 
> Thanks for this fix Maciej. However, I think failing the test here is
> a little bit too drastic. How about just returning TEST_SKIP and print
> out that the max number of skbs is unknown as the reason for the skip?
> Or even more optimistically, print out a warning that we could not
> read the max number of skb but we are guessing 17 and then run the
> test? If it passes, great we guessed correctly, but if it fails we are
> not worse off than the current code.

makes sense to default to 17 if we couldn't read it from file. will fix in
v2.

> Do not know how often a file
> system does not contain /proc/sys/net/core/max_skb_frags though.

A mix of CONFIG_NET, CONFIG_PROC_FS and CONFIG_SYSCTL i think.

> 
> > +               max_frags += 1;
> > +       }
> > +
> > +       pkts = calloc(2 * max_frags + 2, sizeof(struct pkt));
> > +       if (!pkts)
> > +               return TEST_FAILURE;
> >
> >         test->mtu = MAX_ETH_JUMBO_SIZE;
> >
> > @@ -2281,7 +2309,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)
> > diff --git a/tools/testing/selftests/bpf/xskxceiver.h b/tools/testing/selftests/bpf/xskxceiver.h
> > index 885c948c5d83..e46e823f6a1a 100644
> > --- a/tools/testing/selftests/bpf/xskxceiver.h
> > +++ b/tools/testing/selftests/bpf/xskxceiver.h
> > @@ -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
> > --
> > 2.34.1
> >
> >
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
index 92af633faea8..595b6da26897 100644
--- a/tools/testing/selftests/bpf/xskxceiver.c
+++ b/tools/testing/selftests/bpf/xskxceiver.c
@@ -325,6 +325,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'},
@@ -2245,13 +2264,22 @@  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)
+			return TEST_FAILURE;
+		max_frags += 1;
+	}
+
+	pkts = calloc(2 * max_frags + 2, sizeof(struct pkt));
+	if (!pkts)
+		return TEST_FAILURE;
 
 	test->mtu = MAX_ETH_JUMBO_SIZE;
 
@@ -2281,7 +2309,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)
diff --git a/tools/testing/selftests/bpf/xskxceiver.h b/tools/testing/selftests/bpf/xskxceiver.h
index 885c948c5d83..e46e823f6a1a 100644
--- a/tools/testing/selftests/bpf/xskxceiver.h
+++ b/tools/testing/selftests/bpf/xskxceiver.h
@@ -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