diff mbox series

[3/3] selftests/bpf: ringbuf, mmap: bump up page size to 64K

Message ID 20210326114722.210109-3-yauheni.kaliuta@redhat.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series bpf/selftests: page size fixes | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Yauheni Kaliuta March 26, 2021, 11:47 a.m. UTC
Both ringbuf and mmap need PAGE_SIZE, but it's not available during
bpf program compile time. 4K size was hardcoded (page shift 12 bits)
which makes the tests fail on systems, configured for larger pages.

Bump it up to 64K which at the first glance look reasonable at the
moment for most of the systems.

Use define to make it clear.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
---
 tools/testing/selftests/bpf/prog_tests/ringbuf.c       |  9 +++++++--
 tools/testing/selftests/bpf/progs/map_ptr_kern.c       |  9 +++++++--
 tools/testing/selftests/bpf/progs/test_mmap.c          | 10 ++++++++--
 tools/testing/selftests/bpf/progs/test_ringbuf.c       |  8 +++++++-
 tools/testing/selftests/bpf/progs/test_ringbuf_multi.c |  7 ++++++-
 5 files changed, 35 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
index fddbc5db5d6a..9057654da957 100644
--- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c
+++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
@@ -15,6 +15,11 @@ 
 #include "test_ringbuf.skel.h"
 
 #define EDONE 7777
+#ifdef PAGE_SIZE
+#undef PAGE_SIZE
+#endif
+/* this is not actual page size, but the value used for ringbuf */
+#define PAGE_SIZE 65536
 
 static int duration = 0;
 
@@ -110,9 +115,9 @@  void test_ringbuf(void)
 	CHECK(skel->bss->avail_data != 3 * rec_sz,
 	      "err_avail_size", "exp %ld, got %ld\n",
 	      3L * rec_sz, skel->bss->avail_data);
-	CHECK(skel->bss->ring_size != 4096,
+	CHECK(skel->bss->ring_size != PAGE_SIZE,
 	      "err_ring_size", "exp %ld, got %ld\n",
-	      4096L, skel->bss->ring_size);
+	      (long)PAGE_SIZE, skel->bss->ring_size);
 	CHECK(skel->bss->cons_pos != 0,
 	      "err_cons_pos", "exp %ld, got %ld\n",
 	      0L, skel->bss->cons_pos);
diff --git a/tools/testing/selftests/bpf/progs/map_ptr_kern.c b/tools/testing/selftests/bpf/progs/map_ptr_kern.c
index d8850bc6a9f1..c1460f27af78 100644
--- a/tools/testing/selftests/bpf/progs/map_ptr_kern.c
+++ b/tools/testing/selftests/bpf/progs/map_ptr_kern.c
@@ -8,6 +8,11 @@ 
 #define MAX_ENTRIES 8
 #define HALF_ENTRIES (MAX_ENTRIES >> 1)
 
+#ifndef PAGE_SIZE
+/* use reasonable value for various configurations */
+#define PAGE_SIZE 65536
+#endif
+
 _Static_assert(MAX_ENTRIES < LOOP_BOUND, "MAX_ENTRIES must be < LOOP_BOUND");
 
 enum bpf_map_type g_map_type = BPF_MAP_TYPE_UNSPEC;
@@ -635,7 +640,7 @@  struct bpf_ringbuf_map {
 
 struct {
 	__uint(type, BPF_MAP_TYPE_RINGBUF);
-	__uint(max_entries, 1 << 12);
+	__uint(max_entries, PAGE_SIZE);
 } m_ringbuf SEC(".maps");
 
 static inline int check_ringbuf(void)
@@ -643,7 +648,7 @@  static inline int check_ringbuf(void)
 	struct bpf_ringbuf_map *ringbuf = (struct bpf_ringbuf_map *)&m_ringbuf;
 	struct bpf_map *map = (struct bpf_map *)&m_ringbuf;
 
-	VERIFY(check(&ringbuf->map, map, 0, 0, 1 << 12));
+	VERIFY(check(&ringbuf->map, map, 0, 0, PAGE_SIZE));
 
 	return 1;
 }
diff --git a/tools/testing/selftests/bpf/progs/test_mmap.c b/tools/testing/selftests/bpf/progs/test_mmap.c
index 4eb42cff5fe9..c22fcfea0767 100644
--- a/tools/testing/selftests/bpf/progs/test_mmap.c
+++ b/tools/testing/selftests/bpf/progs/test_mmap.c
@@ -5,11 +5,16 @@ 
 #include <stdint.h>
 #include <bpf/bpf_helpers.h>
 
+#ifndef PAGE_SIZE
+/* use reasonable value for various configurations */
+#define PAGE_SIZE 65536
+#endif
+
 char _license[] SEC("license") = "GPL";
 
 struct {
 	__uint(type, BPF_MAP_TYPE_ARRAY);
-	__uint(max_entries, 4096);
+	__uint(max_entries, PAGE_SIZE);
 	__uint(map_flags, BPF_F_MMAPABLE | BPF_F_RDONLY_PROG);
 	__type(key, __u32);
 	__type(value, char);
@@ -17,7 +22,8 @@  struct {
 
 struct {
 	__uint(type, BPF_MAP_TYPE_ARRAY);
-	__uint(max_entries, 512 * 4); /* at least 4 pages of data */
+	/* at least 4 pages of data */
+	__uint(max_entries, 4 * (PAGE_SIZE / sizeof (__u64)));
 	__uint(map_flags, BPF_F_MMAPABLE);
 	__type(key, __u32);
 	__type(value, __u64);
diff --git a/tools/testing/selftests/bpf/progs/test_ringbuf.c b/tools/testing/selftests/bpf/progs/test_ringbuf.c
index 8ba9959b036b..6e645babdc18 100644
--- a/tools/testing/selftests/bpf/progs/test_ringbuf.c
+++ b/tools/testing/selftests/bpf/progs/test_ringbuf.c
@@ -4,6 +4,12 @@ 
 #include <linux/bpf.h>
 #include <bpf/bpf_helpers.h>
 
+#ifndef PAGE_SIZE
+/* use reasonable value for various configurations */
+#define PAGE_SIZE 65536
+#endif
+
+
 char _license[] SEC("license") = "GPL";
 
 struct sample {
@@ -15,7 +21,7 @@  struct sample {
 
 struct {
 	__uint(type, BPF_MAP_TYPE_RINGBUF);
-	__uint(max_entries, 1 << 12);
+	__uint(max_entries, PAGE_SIZE);
 } ringbuf SEC(".maps");
 
 /* inputs */
diff --git a/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c b/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c
index edf3b6953533..13bcf095e06c 100644
--- a/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c
+++ b/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c
@@ -4,6 +4,11 @@ 
 #include <linux/bpf.h>
 #include <bpf/bpf_helpers.h>
 
+#ifndef PAGE_SIZE
+/* use reasonable value for various configurations */
+#define PAGE_SIZE 65536
+#endif
+
 char _license[] SEC("license") = "GPL";
 
 struct sample {
@@ -15,7 +20,7 @@  struct sample {
 
 struct ringbuf_map {
 	__uint(type, BPF_MAP_TYPE_RINGBUF);
-	__uint(max_entries, 1 << 12);
+	__uint(max_entries, PAGE_SIZE);
 } ringbuf1 SEC(".maps"),
   ringbuf2 SEC(".maps");