Skip to content

Commit

Permalink
bpf: use consistent log size
Browse files Browse the repository at this point in the history
Currently the log size for bpf_prog01 + bpf_prog02 is set to BUFSIZ
which is defined by the libc in stdio.h. In glibc, this is set to the
constant 8192. In other libc's this may be different, e.g. in Musl this
is set to 1024. For bpf_prog02, a log size of 1024 is not large enough
to store the verifier log resulting in the following test breakage:

[...] bpf_common.c:123: TBROK: Failed verification: ENOSPC (28)

This error is returned from kernel/bpf/verifier.c when the verifier log
exceeds the user supplied buffer.

Align bpf_prog01 + bpf_prog02 with other bpf tests and set the buffer
size explicitly to 8192 in bpf_common.h. Since all tests use this value,
use a common definition instead of redefining it in each test.

Signed-off-by: Zachary Leaf <zachary.leaf@arm.com>
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
  • Loading branch information
zdleaf authored and metan-ucw committed Jul 17, 2023
1 parent 85dcfa5 commit 4e229cc
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 10 deletions.
1 change: 1 addition & 0 deletions testcases/kernel/syscalls/bpf/bpf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "lapi/socket.h"

#define BPF_MEMLOCK_ADD (2*1024*1024)
#define BUFSIZE 8192

/* map[array_indx] = reg_to_save
*
Expand Down
2 changes: 1 addition & 1 deletion testcases/kernel/syscalls/bpf/bpf_prog01.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int load_prog(int fd)
BPF_EXIT_INSN(), /* return r0 */
};

bpf_init_prog_attr(attr, PROG, sizeof(PROG), log, BUFSIZ);
bpf_init_prog_attr(attr, PROG, sizeof(PROG), log, BUFSIZE);
return bpf_load_prog(attr, log);
}

Expand Down
4 changes: 2 additions & 2 deletions testcases/kernel/syscalls/bpf/bpf_prog02.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static int load_prog(int fd)
BPF_EXIT_INSN(), /* 26: return r0 */
};

bpf_init_prog_attr(attr, insn, sizeof(insn), log, BUFSIZ);
bpf_init_prog_attr(attr, insn, sizeof(insn), log, BUFSIZE);
return bpf_load_prog(attr, log);
}

Expand Down Expand Up @@ -117,7 +117,7 @@ static struct tst_test test = {
.bufs = (struct tst_buffers []) {
{&key, .size = sizeof(*key)},
{&val, .size = sizeof(*val)},
{&log, .size = BUFSIZ},
{&log, .size = BUFSIZE},
{&attr, .size = sizeof(*attr)},
{&msg, .size = sizeof(MSG)},
{},
Expand Down
1 change: 0 additions & 1 deletion testcases/kernel/syscalls/bpf/bpf_prog04.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "tst_capability.h"
#include "bpf_common.h"

#define BUFSIZE 8192
#define CHECK_BPF_RET(x) ((x) >= 0 || ((x) == -1 && errno != EACCES))

static const char MSG[] = "Ahoj!";
Expand Down
2 changes: 0 additions & 2 deletions testcases/kernel/syscalls/bpf/bpf_prog05.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
#include "tst_capability.h"
#include "bpf_common.h"

#define BUFSIZE 8192

static const char MSG[] = "Ahoj!";
static char *msg;

Expand Down
2 changes: 0 additions & 2 deletions testcases/kernel/syscalls/bpf/bpf_prog06.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
#include "lapi/bpf.h"
#include "bpf_common.h"

#define BUFSIZE 8192

static const char MSG[] = "Ahoj!";
static char *msg;

Expand Down
2 changes: 0 additions & 2 deletions testcases/kernel/syscalls/bpf/bpf_prog07.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
#include "lapi/bpf.h"
#include "bpf_common.h"

#define BUFSIZE 8192

static const char MSG[] = "Ahoj!";
static char *msg;

Expand Down

0 comments on commit 4e229cc

Please sign in to comment.