Commit 44e8f13f authored by Alexei Starovoitov's avatar Alexei Starovoitov
Browse files

Merge branch 'bpf-add-_impl-suffix-for-kfuncs-with-implicit-args'



Mykyta Yatsenko says:

====================
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.

Signed-off-by: default avatarMykyta Yatsenko <yatsenko@meta.com>
Acked-by: default avatarIhor Solodrai <ihor.solodrai@linux.dev>
---
Changes in v3:
- Fix commit messages
- Link to v2: https://lore.kernel.org/r/20251104-implv2-v2-0-6dbc35f39f28@meta.com

Changes in v1:
- Split commit into 2
- Rebase on the correct branch
- Link to v1: https://lore.kernel.org/all/20251103232319.122965-1-mykyta.yatsenko5@gmail.com/
====================

Link: https://patch.msgid.link/20251104-implv2-v3-0-4772b9ae0e06@meta.com


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parents 156c75f5 137cc92f
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -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,
__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,8 +4198,9 @@ __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,
__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);
@@ -4376,9 +4380,9 @@ 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_task_work_schedule_signal, KF_TRUSTED_ARGS)
BTF_ID_FLAGS(func, bpf_task_work_schedule_resume, 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)

static const struct btf_kfunc_id_set common_kfunc_set = {
+2 −1
Original line number Diff line number Diff line
@@ -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,
+6 −6
Original line number Diff line number Diff line
@@ -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)
+1 −1
Original line number Diff line number Diff line
@@ -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.

+14 −14
Original line number Diff line number Diff line
@@ -315,7 +315,7 @@ enum libbpf_tristate {
			  ___param, sizeof(___param));		\
})

extern int bpf_stream_vprintk(int stream_id, const char *fmt__str, const void *args,
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...)					\
@@ -328,7 +328,7 @@ extern int bpf_stream_vprintk(int stream_id, const char *fmt__str, const void *a
	___bpf_fill(___param, args);							\
	_Pragma("GCC diagnostic pop")							\
											\
	bpf_stream_vprintk(stream_id, ___fmt, ___param, sizeof(___param), NULL);\
	bpf_stream_vprintk_impl(stream_id, ___fmt, ___param, sizeof(___param), NULL);	\
})

/* Use __bpf_printk when bpf_printk call has 3 or fewer fmt args
Loading