bpf: add _impl suffix for kfuncs with implicit args
Subsystems (6)
v3 cover bpf: add _impl suffix for kfuncs with implicit args
We have established a pattern of function naming win "_impl" suffix; those functions accept verifier-provided bpf_prog_aux argument. Following uniform convention will allow for transparent backwards compatibility with the upcoming KF_IMPLICIT_ARGS feature. This patch set aims to fix current deviation from the convention to eliminate unnecessary backwards incompatibility in the future.
Three kfuncs added in 6.18 don’t follow this *_impl convention and therefore won’t participate in the new KF_IMPLICIT_ARGS mechanism:
* bpf_task_work_schedule_resume()
* bpf_task_work_schedule_signal()
* bpf_stream_vprintk()
Rename them to align with the implicit-arg flow:bpf_task_work_schedule_resume() -> bpf_task_work_schedule_resume_impl() bpf_task_work_schedule_signal() -> bpf_task_work_schedule_signal_impl() bpf_stream_vprintk() -> bpf_stream_vprintk_impl()
The KF_IMPLICIT_ARGS mechanism is not in tree yet, so callers must switch to the *_impl names for now. Once the new mechanism lands, the plain names (without _impl) will be reintroduced.
---
Changes in v3:
- Fix commit messages
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v1:
- Split commit into 2
- Rebase on the correct branch
- Link to v1: https://lore.kernel.org/all/[email protected]/
---
Mykyta Yatsenko (2):
bpf:add _impl suffix for bpf_task_work_schedule* kfuncs
bpf: add _impl suffix for bpf_stream_vprintk() kfunc
kernel/bpf/helpers.c | 26 +++++++++++--------- kernel/bpf/stream.c | 3 ++- kernel/bpf/verifier.c | 12 +++++----- tools/bpf/bpftool/Documentation/bpftool-prog.rst | 2 +- tools/lib/bpf/bpf_helpers.h | 28 +++++++++++----------- tools/testing/selftests/bpf/progs/stream_fail.c | 6 ++--- tools/testing/selftests/bpf/progs/task_work.c | 6 ++--- tools/testing/selftests/bpf/progs/task_work_fail.c | 8 +++---- .../testing/selftests/bpf/progs/task_work_stress.c | 4 ++-- 9 files changed, 50 insertions(+), 45 deletions(-)
---
base-commit: 6146a0f1dfae5d37442a9ddcba012add260bceb0
change-id: 20251104-implv2-d6c4be255026
Best regards,
Signature · 1 line
Mykyta Yatsenko <[email protected]>
PATCH v3 1/2 bpf:add _impl suffix for bpf_task_work_schedule* kfuncs
From: Mykyta Yatsenko <[email protected]>
Rename:
bpf_task_work_schedule_resume()->bpf_task_work_schedule_resume_impl() bpf_task_work_schedule_signal()->bpf_task_work_schedule_signal_impl()
This aligns task work scheduling kfuncs with the established naming scheme for kfuncs with the bpf_prog_aux argument provided by the verifier implicitly. This convention will be taken advantage of with the upcoming KF_IMPLICIT_ARGS feature to preserve backwards compatibility to BPF programs.
--- kernel/bpf/helpers.c | 24 +++++++++++++--------- kernel/bpf/verifier.c | 12 +++++------ tools/testing/selftests/bpf/progs/task_work.c | 6 +++--- tools/testing/selftests/bpf/progs/task_work_fail.c | 8 ++++---- .../testing/selftests/bpf/progs/task_work_stress.c | 4 ++-- 5 files changed, 29 insertions(+), 25 deletions(-)
kernel/bpf/helpers.c +14 -10
@@ -4169,7 +4169,8 @@ static int bpf_task_work_schedule(struct task_struct *task, struct bpf_task_work }/** -* bpf_task_work_schedule_signal - Schedule BPF callback using task_work_add with TWA_SIGNAL mode +* bpf_task_work_schedule_signal_impl - Schedule BPF callback using task_work_add with TWA_SIGNAL +* mode * @task: Task struct for which callback should be scheduled * @tw: Pointer to struct bpf_task_work in BPF map value for internal bookkeeping * @map__map: bpf_map that embeds struct bpf_task_work in the values
@@ -4178,15 +4179,17 @@ static int bpf_task_work_schedule(struct task_struct *task, struct bpf_task_work* * Return: 0 if task work has been scheduled successfully, negative error code otherwise */ -__bpf_kfunc int bpf_task_work_schedule_signal(struct task_struct *task, struct bpf_task_work *tw, -void *map__map,bpf_task_work_callback_t callback, -void *aux__prog) +__bpf_kfunc int bpf_task_work_schedule_signal_impl(struct task_struct *task, +struct bpf_task_work *tw,void *map__map, +bpf_task_work_callback_t callback, +void *aux__prog) {return bpf_task_work_schedule (task, tw, map__map, callback, aux__prog,TWA_SIGNAL ); }/** -* bpf_task_work_schedule_resume - Schedule BPF callback using task_work_add with TWA_RESUME mode +* bpf_task_work_schedule_resume_impl - Schedule BPF callback using task_work_add with TWA_RESUME +* mode * @task: Task struct for which callback should be scheduled * @tw: Pointer to struct bpf_task_work in BPF map value for internal bookkeeping * @map__map: bpf_map that embeds struct bpf_task_work in the values
@@ -4195,9 +4198,10 @@ __bpf_kfunc int bpf_task_work_schedule_signal(struct task_struct *task, struct b* * Return: 0 if task work has been scheduled successfully, negative error code otherwise */ -__bpf_kfunc int bpf_task_work_schedule_resume(struct task_struct *task, struct bpf_task_work *tw, -void *map__map,bpf_task_work_callback_t callback, -void *aux__prog) +__bpf_kfunc int bpf_task_work_schedule_resume_impl(struct task_struct *task, +struct bpf_task_work *tw,void *map__map, +bpf_task_work_callback_t callback, +void *aux__prog) {return bpf_task_work_schedule (task, tw, map__map, callback, aux__prog,TWA_RESUME ); }
@@ -4377,8 +4381,8 @@ BTF_ID_FLAGS(func, bpf_strnstr); BTF_ID_FLAGS(func, bpf_cgroup_read_xattr, KF_RCU)#endif BTF_ID_FLAGS(func, bpf_stream_vprintk, KF_TRUSTED_ARGS) -BTF_ID_FLAGS(func, bpf_task_work_schedule_signal, KF_TRUSTED_ARGS) -BTF_ID_FLAGS(func, bpf_task_work_schedule_resume, KF_TRUSTED_ARGS) +BTF_ID_FLAGS(func, bpf_task_work_schedule_signal_impl, KF_TRUSTED_ARGS) +BTF_ID_FLAGS(func, bpf_task_work_schedule_resume_impl, KF_TRUSTED_ARGS)BTF_KFUNCS_END (common_btf_ids) static const struct btf_kfunc_id_set common_kfunc_set = {
kernel/bpf/verifier.c +6 -6
@@ -12259,8 +12259,8 @@ enum special_kfunc_type { KF_bpf_res_spin_lock_irqsave, KF_bpf_res_spin_unlock_irqrestore, KF___bpf_trap, - KF_bpf_task_work_schedule_signal, - KF_bpf_task_work_schedule_resume, + KF_bpf_task_work_schedule_signal_impl, + KF_bpf_task_work_schedule_resume_impl, };BTF_ID_LIST (special_kfunc_list)
@@ -12331,13 +12331,13 @@ BTF_ID(func, bpf_res_spin_unlock) BTF_ID(func, bpf_res_spin_lock_irqsave) BTF_ID(func, bpf_res_spin_unlock_irqrestore) BTF_ID(func, __bpf_trap) -BTF_ID(func, bpf_task_work_schedule_signal) -BTF_ID(func, bpf_task_work_schedule_resume) +BTF_ID(func, bpf_task_work_schedule_signal_impl) +BTF_ID(func, bpf_task_work_schedule_resume_impl)static bool is_task_work_add_kfunc (u32 func_id) { -return func_id == special_kfunc_list[KF_bpf_task_work_schedule_signal] || - func_id == special_kfunc_list[KF_bpf_task_work_schedule_resume]; +return func_id == special_kfunc_list[KF_bpf_task_work_schedule_signal_impl] || + func_id == special_kfunc_list[KF_bpf_task_work_schedule_resume_impl]; }static bool is_kfunc_ret_null (struct bpf_kfunc_call_arg_meta *meta)
tools/testing/selftests/bpf/progs/task_work.c +3 -3
@@ -66,7 +66,7 @@ int oncpu_hash_map(struct pt_regs *args)if (!work)return 0 ; -bpf_task_work_schedule_resume (task, &work->tw, &hmap, process_work,NULL ); +bpf_task_work_schedule_resume_impl (task, &work->tw, &hmap, process_work,NULL );return 0 ; }
@@ -80,7 +80,7 @@ int oncpu_array_map(struct pt_regs *args) work =bpf_map_lookup_elem (&arrmap, &key);if (!work)return 0 ; -bpf_task_work_schedule_signal (task, &work->tw, &arrmap, process_work,NULL ); +bpf_task_work_schedule_signal_impl (task, &work->tw, &arrmap, process_work,NULL );return 0 ; }
@@ -102,6 +102,6 @@ int oncpu_lru_map(struct pt_regs *args) work =bpf_map_lookup_elem (&lrumap, &key);if (!work || work->data[0 ])return 0 ; -bpf_task_work_schedule_resume (task, &work->tw, &lrumap, process_work,NULL ); +bpf_task_work_schedule_resume_impl (task, &work->tw, &lrumap, process_work,NULL );return 0 ; }
tools/testing/selftests/bpf/progs/task_work_fail.c +4 -4
@@ -53,7 +53,7 @@ int mismatch_map(struct pt_regs *args) work =bpf_map_lookup_elem (&arrmap, &key);if (!work)return 0 ; -bpf_task_work_schedule_resume (task, &work->tw, &hmap, process_work,NULL ); +bpf_task_work_schedule_resume_impl (task, &work->tw, &hmap, process_work,NULL );return 0 ; }
@@ -65,7 +65,7 @@ int no_map_task_work(struct pt_regs *args)struct bpf_task_work tw; task =bpf_get_current_task_btf (); -bpf_task_work_schedule_resume (task, &tw, &hmap, process_work,NULL ); +bpf_task_work_schedule_resume_impl (task, &tw, &hmap, process_work,NULL );return 0 ; }
@@ -76,7 +76,7 @@ int task_work_null(struct pt_regs *args)struct task_struct *task; task =bpf_get_current_task_btf (); -bpf_task_work_schedule_resume (task,NULL , &hmap, process_work,NULL ); +bpf_task_work_schedule_resume_impl (task,NULL , &hmap, process_work,NULL );return 0 ; }
@@ -91,6 +91,6 @@ int map_null(struct pt_regs *args) work =bpf_map_lookup_elem (&arrmap, &key);if (!work)return 0 ; -bpf_task_work_schedule_resume (task, &work->tw,NULL , process_work,NULL ); +bpf_task_work_schedule_resume_impl (task, &work->tw,NULL , process_work,NULL );return 0 ; }
tools/testing/selftests/bpf/progs/task_work_stress.c +2 -2
@@ -51,8 +51,8 @@ int schedule_task_work(void *ctx)if (!work)return 0 ; } - err =bpf_task_work_schedule_signal (bpf_get_current_task_btf (), &work->tw, &hmap, - process_work,NULL ); + err =bpf_task_work_schedule_signal_impl (bpf_get_current_task_btf (), &work->tw, &hmap, + process_work,NULL );if (err)__sync_fetch_and_add (&schedule_error,1 );else
Signature · 1 line
2.51.1
PATCH v3 2/2 bpf: add _impl suffix for bpf_stream_vprintk() kfunc
In reply to Mykyta YatsenkoFrom: Mykyta Yatsenko <[email protected]>
Rename bpf_stream_vprintk() to bpf_stream_vprintk_impl().
This makes bpf_stream_vprintk() follow the already established "_impl" suffix-based naming convention for kfuncs with the bpf_prog_aux argument provided by the verifier implicitly. This convention will be taken advantage of with the upcoming KF_IMPLICIT_ARGS feature to preserve backwards compatibility to BPF programs.
--- kernel/bpf/helpers.c | 2 +- kernel/bpf/stream.c | 3 ++- tools/bpf/bpftool/Documentation/bpftool-prog.rst | 2 +- tools/lib/bpf/bpf_helpers.h | 28 ++++++++++++------------ tools/testing/selftests/bpf/progs/stream_fail.c | 6 ++--- 5 files changed, 21 insertions(+), 20 deletions(-)
kernel/bpf/helpers.c +1 -1
@@ -4380,7 +4380,7 @@ BTF_ID_FLAGS(func, bpf_strnstr);#if defined(CONFIG_BPF_LSM ) && defined(CONFIG_CGROUPS ) BTF_ID_FLAGS(func, bpf_cgroup_read_xattr, KF_RCU)#endif -BTF_ID_FLAGS(func, bpf_stream_vprintk, KF_TRUSTED_ARGS) +BTF_ID_FLAGS(func, bpf_stream_vprintk_impl, KF_TRUSTED_ARGS) BTF_ID_FLAGS(func, bpf_task_work_schedule_signal_impl, KF_TRUSTED_ARGS) BTF_ID_FLAGS(func, bpf_task_work_schedule_resume_impl, KF_TRUSTED_ARGS)BTF_KFUNCS_END (common_btf_ids)
kernel/bpf/stream.c +2 -1
@@ -355,7 +355,8 @@ __bpf_kfunc_start_defs();* Avoid using enum bpf_stream_id so that kfunc users don't have to pull in the * enum in headers. */ -__bpf_kfunc int bpf_stream_vprintk(int stream_id, const char *fmt__str, const void *args, u32 len__sz, void *aux__prog) +__bpf_kfunc int bpf_stream_vprintk_impl(int stream_id, const char *fmt__str, const void *args, +u32 len__sz,void *aux__prog) {struct bpf_bprintf_data data = { .get_bin_args = true,
tools/bpf/bpftool/Documentation/bpftool-prog.rst +1 -1
@@ -182,7 +182,7 @@ bpftool prog tracelog bpftool prog tracelog { stdout | stderr } *PROG* Dump the BPF stream of the program. BPF programs can write to these streams - at runtime with the **bpf_stream_vprintk**\ () kfunc. The kernel may write + at runtime with the **bpf_stream_vprintk_impl**\ () kfunc. The kernel may write error messages to the standard error stream. This facility should be used only for debugging purposes.
tools/lib/bpf/bpf_helpers.h +14 -14
@@ -315,20 +315,20 @@ enum libbpf_tristate { ___param, sizeof(___param)); \ }) -extern int bpf_stream_vprintk(int stream_id, const char *fmt__str, const void *args, - __u32 len__sz, void *aux__prog) __weak __ksym; - -#define bpf_stream_printk(stream_id, fmt, args...) \ -({ \ - static const char ___fmt[] = fmt; \ - unsigned long long ___param[___bpf_narg(args)]; \ - \ - _Pragma("GCC diagnostic push") \ - _Pragma("GCC diagnostic ignored \"-Wint-conversion\"") \ - ___bpf_fill(___param, args); \ - _Pragma("GCC diagnostic pop") \ - \ - bpf_stream_vprintk(stream_id, ___fmt, ___param, sizeof(___param), NULL);\ +extern int bpf_stream_vprintk_impl(int stream_id, const char *fmt__str, const void *args, + __u32 len__sz, void *aux__prog) __weak __ksym; + +#define bpf_stream_printk(stream_id, fmt, args...) \ +({ \ + static const char ___fmt[] = fmt; \ + unsigned long long ___param[___bpf_narg(args)]; \ + \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wint-conversion\"") \ + ___bpf_fill(___param, args); \ + _Pragma("GCC diagnostic pop") \ + \ + bpf_stream_vprintk_impl(stream_id, ___fmt, ___param, sizeof(___param), NULL); \ })/* Use __bpf_printk when bpf_printk call has 3 or fewer fmt args
tools/testing/selftests/bpf/progs/stream_fail.c +3 -3
@@ -10,7 +10,7 @@ SEC("syscall") __failure __msg("Possibly NULL pointer passed")int stream_vprintk_null_arg (void *ctx) { -bpf_stream_vprintk (BPF_STDOUT ,"" ,NULL ,0 ,NULL ); +bpf_stream_vprintk_impl (BPF_STDOUT ,"" ,NULL ,0 ,NULL );return 0 ; }
@@ -18,7 +18,7 @@ SEC("syscall") __failure __msg("R3 type=scalar expected=")int stream_vprintk_scalar_arg (void *ctx) { -bpf_stream_vprintk (BPF_STDOUT ,"" , (void *)46 ,0 ,NULL ); +bpf_stream_vprintk_impl (BPF_STDOUT ,"" , (void *)46 ,0 ,NULL );return 0 ; }
@@ -26,7 +26,7 @@ SEC("syscall") __failure __msg("arg#1 doesn't point to a const string")int stream_vprintk_string_arg (void *ctx) { -bpf_stream_vprintk (BPF_STDOUT , ctx,NULL ,0 ,NULL ); +bpf_stream_vprintk_impl (BPF_STDOUT , ctx,NULL ,0 ,NULL );return 0 ; }
Signature · 1 line
2.51.1
Quoted 18 lines · Mykyta Yatsenko
We have established a pattern of function naming win "
_impl" suffix; those functions accept verifier-providedbpf_prog_auxargument. Following uniform convention will allow for transparent backwards compatibility with the upcomingKF_IMPLICIT_ARGSfeature. This patch set aims to fix current deviation from the convention to eliminate unnecessary backwards incompatibility in the future.Three kfuncs added in 6.18 don’t follow this
*_implconvention and therefore won’t participate in the newKF_IMPLICIT_ARGSmechanism:
*bpf_task_work_schedule_resume()
*bpf_task_work_schedule_signal()
*bpf_stream_vprintk()Rename them to align with the implicit-arg flow:
bpf_task_work_schedule_resume()->bpf_task_work_schedule_resume_impl()bpf_task_work_schedule_signal()->bpf_task_work_schedule_signal_impl()bpf_stream_vprintk()->bpf_stream_vprintk_impl()
Quoted 5 lines
The
KF_IMPLICIT_ARGSmechanism is not in tree yet, so callers must switch to the*_implnames for now. Once the new mechanism lands, the plain names (without_impl) will be reintroduced.Signed-off-by Mykyta Yatsenko <[email protected]>
Thanks!
Quoted 30 lines
---
Changes in v3:
- Fix commit messages
- Link to v2: https://lore.kernel.org/r/[email protected]Changes in v1:
- Split commit into 2
- Rebase on the correct branch
- Link to v1: https://lore.kernel.org/all/[email protected]/---
Mykyta Yatsenko (2):
bpf:add_implsuffix for bpf_task_work_schedule* kfuncs
bpf: add_implsuffix forbpf_stream_vprintk()kfunckernel/bpf/helpers.c | 26 +++++++++++--------- kernel/bpf/stream.c | 3 ++- kernel/bpf/verifier.c | 12 +++++----- tools/bpf/bpftool/Documentation/bpftool-prog.rst | 2 +- tools/lib/bpf/bpf_helpers.h | 28 +++++++++++----------- tools/testing/selftests/bpf/progs/stream_fail.c | 6 ++--- tools/testing/selftests/bpf/progs/task_work.c | 6 ++--- tools/testing/selftests/bpf/progs/task_work_fail.c | 8 +++---- .../testing/selftests/bpf/progs/task_work_stress.c | 4 ++-- 9 files changed, 50 insertions(+), 45 deletions(-)---
base-commit:6146a0f1dfae5d37442a9ddcba012add260bceb0
change-id: 20251104-implv2-d6c4be255026Best regards,
This series was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This series was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:
Quoted 8 lines · On Tue, 04 Nov 2025 22:54:24 +0000 you wrote:
We have established a pattern of function naming win "
_impl" suffix; those functions accept verifier-providedbpf_prog_auxargument. Following uniform convention will allow for transparent backwards compatibility with the upcomingKF_IMPLICIT_ARGSfeature. This patch set aims to fix current deviation from the convention to eliminate unnecessary backwards incompatibility in the future.[...]
Here is the summary with links:
- [bpf,v3,1/2] bpf:add _impl suffix for bpf_task_work_schedule* kfuncs
https://git.kernel.org/bpf/bpf/c/ea0714d61dea - [bpf,v3,2/2] bpf: add _impl suffix for bpf_stream_vprintk() kfunc https://git.kernel.org/bpf/bpf/c/137cc92ffe2e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html