Skip to content

Commit 4d99137

Browse files
etsalAlexei Starovoitov
authored andcommitted
selftests/bpf: Add selftests for stream functions under lock
Add a selftest to ensure BPF stream functions can now be called while holding a lock. Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com> Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/r/20260203180424.14057-5-emil@etsalapatis.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 9ddfa24 commit 4d99137

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

  • tools/testing/selftests/bpf/progs

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ int size;
4242
u64 fault_addr;
4343
void *arena_ptr;
4444

45+
#define private(name) SEC(".bss." #name) __hidden __attribute__((aligned(8)))
46+
47+
private(STREAM) struct bpf_spin_lock block;
48+
4549
SEC("syscall")
4650
__success __retval(0)
4751
int stream_exhaust(void *ctx)
@@ -255,4 +259,32 @@ int stream_print_stack_invalid_id(void *ctx)
255259
return bpf_stream_print_stack((enum bpf_stream_id)0xbadcafe);
256260
}
257261

262+
SEC("syscall")
263+
__arch_x86_64
264+
__arch_arm64
265+
__success __retval(0)
266+
__stdout(_STR)
267+
__stderr("CPU: {{[0-9]+}} UID: 0 PID: {{[0-9]+}} Comm: {{.*}}")
268+
__stderr("Call trace:\n"
269+
"{{([a-zA-Z_][a-zA-Z0-9_]*\\+0x[0-9a-fA-F]+/0x[0-9a-fA-F]+\n"
270+
"|[ \t]+[^\n]+\n)*}}")
271+
int stream_print_kfuncs_locked(void *ctx)
272+
{
273+
int ret;
274+
275+
bpf_spin_lock(&block);
276+
277+
ret = bpf_stream_printk(BPF_STDOUT, _STR);
278+
if (ret)
279+
goto out;
280+
281+
ret = bpf_stream_print_stack(BPF_STDERR);
282+
283+
out:
284+
bpf_spin_unlock(&block);
285+
286+
return ret;
287+
}
288+
289+
258290
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)