mirror of
https://github.com/torvalds/linux.git
synced 2026-06-04 20:46:48 +02:00
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>
This commit is contained in:
parent
9ddfa24e16
commit
4d99137eea
|
|
@ -42,6 +42,10 @@ int size;
|
|||
u64 fault_addr;
|
||||
void *arena_ptr;
|
||||
|
||||
#define private(name) SEC(".bss." #name) __hidden __attribute__((aligned(8)))
|
||||
|
||||
private(STREAM) struct bpf_spin_lock block;
|
||||
|
||||
SEC("syscall")
|
||||
__success __retval(0)
|
||||
int stream_exhaust(void *ctx)
|
||||
|
|
@ -255,4 +259,32 @@ int stream_print_stack_invalid_id(void *ctx)
|
|||
return bpf_stream_print_stack((enum bpf_stream_id)0xbadcafe);
|
||||
}
|
||||
|
||||
SEC("syscall")
|
||||
__arch_x86_64
|
||||
__arch_arm64
|
||||
__success __retval(0)
|
||||
__stdout(_STR)
|
||||
__stderr("CPU: {{[0-9]+}} UID: 0 PID: {{[0-9]+}} Comm: {{.*}}")
|
||||
__stderr("Call trace:\n"
|
||||
"{{([a-zA-Z_][a-zA-Z0-9_]*\\+0x[0-9a-fA-F]+/0x[0-9a-fA-F]+\n"
|
||||
"|[ \t]+[^\n]+\n)*}}")
|
||||
int stream_print_kfuncs_locked(void *ctx)
|
||||
{
|
||||
int ret;
|
||||
|
||||
bpf_spin_lock(&block);
|
||||
|
||||
ret = bpf_stream_printk(BPF_STDOUT, _STR);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
ret = bpf_stream_print_stack(BPF_STDERR);
|
||||
|
||||
out:
|
||||
bpf_spin_unlock(&block);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user