Skip to content

Commit 9ddfa24

Browse files
etsalAlexei Starovoitov
authored andcommitted
bpf: Allow BPF stream kfuncs while holding a lock
The BPF stream kfuncs bpf_stream_vprintk and bpf_stream_print_stack do not sleep and so are safe to call while holding a lock. Amend the verifier to allow that. Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com> Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/r/20260203180424.14057-4-emil@etsalapatis.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 954fa97 commit 9ddfa24

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

kernel/bpf/verifier.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12455,6 +12455,8 @@ enum special_kfunc_type {
1245512455
KF_bpf_arena_free_pages,
1245612456
KF_bpf_arena_reserve_pages,
1245712457
KF_bpf_session_is_return,
12458+
KF_bpf_stream_vprintk,
12459+
KF_bpf_stream_print_stack,
1245812460
};
1245912461

1246012462
BTF_ID_LIST(special_kfunc_list)
@@ -12533,6 +12535,8 @@ BTF_ID(func, bpf_arena_alloc_pages)
1253312535
BTF_ID(func, bpf_arena_free_pages)
1253412536
BTF_ID(func, bpf_arena_reserve_pages)
1253512537
BTF_ID(func, bpf_session_is_return)
12538+
BTF_ID(func, bpf_stream_vprintk)
12539+
BTF_ID(func, bpf_stream_print_stack)
1253612540

1253712541
static bool is_task_work_add_kfunc(u32 func_id)
1253812542
{
@@ -12977,10 +12981,17 @@ static bool is_bpf_arena_kfunc(u32 btf_id)
1297712981
btf_id == special_kfunc_list[KF_bpf_arena_reserve_pages];
1297812982
}
1297912983

12984+
static bool is_bpf_stream_kfunc(u32 btf_id)
12985+
{
12986+
return btf_id == special_kfunc_list[KF_bpf_stream_vprintk] ||
12987+
btf_id == special_kfunc_list[KF_bpf_stream_print_stack];
12988+
}
12989+
1298012990
static bool kfunc_spin_allowed(u32 btf_id)
1298112991
{
1298212992
return is_bpf_graph_api_kfunc(btf_id) || is_bpf_iter_num_api_kfunc(btf_id) ||
12983-
is_bpf_res_spin_lock_kfunc(btf_id) || is_bpf_arena_kfunc(btf_id);
12993+
is_bpf_res_spin_lock_kfunc(btf_id) || is_bpf_arena_kfunc(btf_id) ||
12994+
is_bpf_stream_kfunc(btf_id);
1298412995
}
1298512996

1298612997
static bool is_sync_callback_calling_kfunc(u32 btf_id)

0 commit comments

Comments
 (0)