Skip to content

Commit 9ea0691

Browse files
author
Martin KaFai Lau
committed
Merge branch 'selftests-bpf-fix-a-few-dynptr-test-failures-with-64k-page-size'
Yonghong Song says: ==================== selftests/bpf: Fix a few dynptr test failures with 64K page size There are a few dynptr test failures with arm64 64K page size. They are fixed in this patch set and please see individual patches for details. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
2 parents 95993dc + 4a5dcb3 commit 9ea0691

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

tools/testing/selftests/bpf/prog_tests/dynptr.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ static struct {
5151
{"test_copy_from_user_task_str_dynptr", SETUP_SYSCALL_SLEEP},
5252
};
5353

54+
#define PAGE_SIZE_64K 65536
55+
5456
static void verify_success(const char *prog_name, enum test_setup_type setup_type)
5557
{
5658
char user_data[384] = {[0 ... 382] = 'a', '\0'};
@@ -146,14 +148,18 @@ static void verify_success(const char *prog_name, enum test_setup_type setup_typ
146148
}
147149
case SETUP_XDP_PROG:
148150
{
149-
char data[5000];
151+
char data[90000];
150152
int err, prog_fd;
151153
LIBBPF_OPTS(bpf_test_run_opts, opts,
152154
.data_in = &data,
153-
.data_size_in = sizeof(data),
154155
.repeat = 1,
155156
);
156157

158+
if (getpagesize() == PAGE_SIZE_64K)
159+
opts.data_size_in = sizeof(data);
160+
else
161+
opts.data_size_in = 5000;
162+
157163
prog_fd = bpf_program__fd(prog);
158164
err = bpf_prog_test_run_opts(prog_fd, &opts);
159165

tools/testing/selftests/bpf/progs/dynptr_success.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "bpf_misc.h"
1010
#include "errno.h"
1111

12+
#define PAGE_SIZE_64K 65536
13+
1214
char _license[] SEC("license") = "GPL";
1315

1416
int pid, err, val;
@@ -611,11 +613,12 @@ int test_dynptr_copy_xdp(struct xdp_md *xdp)
611613
struct bpf_dynptr ptr_buf, ptr_xdp;
612614
char data[] = "qwertyuiopasdfghjkl";
613615
char buf[32] = {'\0'};
614-
__u32 len = sizeof(data);
616+
__u32 len = sizeof(data), xdp_data_size;
615617
int i, chunks = 200;
616618

617619
/* ptr_xdp is backed by non-contiguous memory */
618620
bpf_dynptr_from_xdp(xdp, 0, &ptr_xdp);
621+
xdp_data_size = bpf_dynptr_size(&ptr_xdp);
619622
bpf_ringbuf_reserve_dynptr(&ringbuf, len * chunks, 0, &ptr_buf);
620623

621624
/* Destination dynptr is backed by non-contiguous memory */
@@ -673,7 +676,7 @@ int test_dynptr_copy_xdp(struct xdp_md *xdp)
673676
goto out;
674677
}
675678

676-
if (bpf_dynptr_copy(&ptr_xdp, 2000, &ptr_xdp, 0, len * chunks) != -E2BIG)
679+
if (bpf_dynptr_copy(&ptr_xdp, xdp_data_size - 3000, &ptr_xdp, 0, len * chunks) != -E2BIG)
677680
err = 1;
678681

679682
out:
@@ -820,8 +823,17 @@ int test_dynptr_memset_xdp_chunks(struct xdp_md *xdp)
820823
data_sz = bpf_dynptr_size(&ptr_xdp);
821824

822825
err = bpf_dynptr_memset(&ptr_xdp, 0, data_sz, DYNPTR_MEMSET_VAL);
823-
if (err)
826+
if (err) {
827+
/* bpf_dynptr_memset() eventually called bpf_xdp_pointer()
828+
* where if data_sz is greater than 0xffff, -EFAULT will be
829+
* returned. For 64K page size, data_sz is greater than
830+
* 64K, so error is expected and let us zero out error and
831+
* return success.
832+
*/
833+
if (data_sz >= PAGE_SIZE_64K)
834+
err = 0;
824835
goto out;
836+
}
825837

826838
bpf_for(i, 0, max_chunks) {
827839
offset = i * sizeof(buf);

0 commit comments

Comments
 (0)