Skip to content

Commit e04ae97

Browse files
Philo LuKernel Patches Daemon
authored andcommitted
selftests/bpf: Add test for __nullable suffix in tp_btf
Add a tracepoint with __nullable suffix in bpf_testmod, and add cases for it: $ ./test_progs -t "tp_btf_nullable" #406/1 tp_btf_nullable/handle_tp_btf_nullable_bare1:OK #406/2 tp_btf_nullable/handle_tp_btf_nullable_bare2:OK #406 tp_btf_nullable:OK Summary: 1/2 PASSED, 0 SKIPPED, 0 FAILED Signed-off-by: Philo Lu <[email protected]>
1 parent c839a50 commit e04ae97

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ DECLARE_TRACE(bpf_testmod_test_write_bare,
3434
TP_ARGS(task, ctx)
3535
);
3636

37+
/* Used in bpf_testmod_test_read() to test __nullable suffix */
38+
DECLARE_TRACE(bpf_testmod_test_nullable_bare,
39+
TP_PROTO(struct bpf_testmod_test_read_ctx *ctx__nullable),
40+
TP_ARGS(ctx__nullable)
41+
);
42+
3743
#undef BPF_TESTMOD_DECLARE_TRACE
3844
#ifdef DECLARE_TRACE_WRITABLE
3945
#define BPF_TESTMOD_DECLARE_TRACE(call, proto, args, size) \

tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,
394394
if (bpf_testmod_loop_test(101) > 100)
395395
trace_bpf_testmod_test_read(current, &ctx);
396396

397+
trace_bpf_testmod_test_nullable_bare(NULL);
398+
397399
/* Magic number to enable writable tp */
398400
if (len == 64) {
399401
struct bpf_testmod_test_writable_ctx writable = {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <test_progs.h>
4+
#include "test_tp_btf_nullable.skel.h"
5+
6+
void test_tp_btf_nullable(void)
7+
{
8+
if (!env.has_testmod) {
9+
test__skip();
10+
return;
11+
}
12+
13+
RUN_TESTS(test_tp_btf_nullable);
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include "vmlinux.h"
4+
#include <bpf/bpf_helpers.h>
5+
#include <bpf/bpf_tracing.h>
6+
#include "../bpf_testmod/bpf_testmod.h"
7+
#include "bpf_misc.h"
8+
9+
SEC("tp_btf/bpf_testmod_test_nullable_bare")
10+
__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
11+
int BPF_PROG(handle_tp_btf_nullable_bare1, struct bpf_testmod_test_read_ctx *nullable_ctx)
12+
{
13+
return nullable_ctx->len;
14+
}
15+
16+
SEC("tp_btf/bpf_testmod_test_nullable_bare")
17+
int BPF_PROG(handle_tp_btf_nullable_bare2, struct bpf_testmod_test_read_ctx *nullable_ctx)
18+
{
19+
if (nullable_ctx)
20+
return nullable_ctx->len;
21+
return 0;
22+
}
23+
24+
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)