Skip to content

Commit 44e8f13

Browse files
author
Alexei Starovoitov
committed
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: Mykyta Yatsenko <[email protected]> Acked-by: Ihor Solodrai <[email protected]> --- 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]/ ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents 156c75f + 137cc92 commit 44e8f13

File tree

9 files changed

+50
-45
lines changed

9 files changed

+50
-45
lines changed

kernel/bpf/helpers.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4169,7 +4169,8 @@ static int bpf_task_work_schedule(struct task_struct *task, struct bpf_task_work
41694169
}
41704170

41714171
/**
4172-
* bpf_task_work_schedule_signal - Schedule BPF callback using task_work_add with TWA_SIGNAL mode
4172+
* bpf_task_work_schedule_signal_impl - Schedule BPF callback using task_work_add with TWA_SIGNAL
4173+
* mode
41734174
* @task: Task struct for which callback should be scheduled
41744175
* @tw: Pointer to struct bpf_task_work in BPF map value for internal bookkeeping
41754176
* @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
41784179
*
41794180
* Return: 0 if task work has been scheduled successfully, negative error code otherwise
41804181
*/
4181-
__bpf_kfunc int bpf_task_work_schedule_signal(struct task_struct *task, struct bpf_task_work *tw,
4182-
void *map__map, bpf_task_work_callback_t callback,
4183-
void *aux__prog)
4182+
__bpf_kfunc int bpf_task_work_schedule_signal_impl(struct task_struct *task,
4183+
struct bpf_task_work *tw, void *map__map,
4184+
bpf_task_work_callback_t callback,
4185+
void *aux__prog)
41844186
{
41854187
return bpf_task_work_schedule(task, tw, map__map, callback, aux__prog, TWA_SIGNAL);
41864188
}
41874189

41884190
/**
4189-
* bpf_task_work_schedule_resume - Schedule BPF callback using task_work_add with TWA_RESUME mode
4191+
* bpf_task_work_schedule_resume_impl - Schedule BPF callback using task_work_add with TWA_RESUME
4192+
* mode
41904193
* @task: Task struct for which callback should be scheduled
41914194
* @tw: Pointer to struct bpf_task_work in BPF map value for internal bookkeeping
41924195
* @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
41954198
*
41964199
* Return: 0 if task work has been scheduled successfully, negative error code otherwise
41974200
*/
4198-
__bpf_kfunc int bpf_task_work_schedule_resume(struct task_struct *task, struct bpf_task_work *tw,
4199-
void *map__map, bpf_task_work_callback_t callback,
4200-
void *aux__prog)
4201+
__bpf_kfunc int bpf_task_work_schedule_resume_impl(struct task_struct *task,
4202+
struct bpf_task_work *tw, void *map__map,
4203+
bpf_task_work_callback_t callback,
4204+
void *aux__prog)
42014205
{
42024206
return bpf_task_work_schedule(task, tw, map__map, callback, aux__prog, TWA_RESUME);
42034207
}
@@ -4376,9 +4380,9 @@ BTF_ID_FLAGS(func, bpf_strnstr);
43764380
#if defined(CONFIG_BPF_LSM) && defined(CONFIG_CGROUPS)
43774381
BTF_ID_FLAGS(func, bpf_cgroup_read_xattr, KF_RCU)
43784382
#endif
4379-
BTF_ID_FLAGS(func, bpf_stream_vprintk, KF_TRUSTED_ARGS)
4380-
BTF_ID_FLAGS(func, bpf_task_work_schedule_signal, KF_TRUSTED_ARGS)
4381-
BTF_ID_FLAGS(func, bpf_task_work_schedule_resume, KF_TRUSTED_ARGS)
4383+
BTF_ID_FLAGS(func, bpf_stream_vprintk_impl, KF_TRUSTED_ARGS)
4384+
BTF_ID_FLAGS(func, bpf_task_work_schedule_signal_impl, KF_TRUSTED_ARGS)
4385+
BTF_ID_FLAGS(func, bpf_task_work_schedule_resume_impl, KF_TRUSTED_ARGS)
43824386
BTF_KFUNCS_END(common_btf_ids)
43834387

43844388
static const struct btf_kfunc_id_set common_kfunc_set = {

kernel/bpf/stream.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ __bpf_kfunc_start_defs();
355355
* Avoid using enum bpf_stream_id so that kfunc users don't have to pull in the
356356
* enum in headers.
357357
*/
358-
__bpf_kfunc int bpf_stream_vprintk(int stream_id, const char *fmt__str, const void *args, u32 len__sz, void *aux__prog)
358+
__bpf_kfunc int bpf_stream_vprintk_impl(int stream_id, const char *fmt__str, const void *args,
359+
u32 len__sz, void *aux__prog)
359360
{
360361
struct bpf_bprintf_data data = {
361362
.get_bin_args = true,

kernel/bpf/verifier.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12259,8 +12259,8 @@ enum special_kfunc_type {
1225912259
KF_bpf_res_spin_lock_irqsave,
1226012260
KF_bpf_res_spin_unlock_irqrestore,
1226112261
KF___bpf_trap,
12262-
KF_bpf_task_work_schedule_signal,
12263-
KF_bpf_task_work_schedule_resume,
12262+
KF_bpf_task_work_schedule_signal_impl,
12263+
KF_bpf_task_work_schedule_resume_impl,
1226412264
};
1226512265

1226612266
BTF_ID_LIST(special_kfunc_list)
@@ -12331,13 +12331,13 @@ BTF_ID(func, bpf_res_spin_unlock)
1233112331
BTF_ID(func, bpf_res_spin_lock_irqsave)
1233212332
BTF_ID(func, bpf_res_spin_unlock_irqrestore)
1233312333
BTF_ID(func, __bpf_trap)
12334-
BTF_ID(func, bpf_task_work_schedule_signal)
12335-
BTF_ID(func, bpf_task_work_schedule_resume)
12334+
BTF_ID(func, bpf_task_work_schedule_signal_impl)
12335+
BTF_ID(func, bpf_task_work_schedule_resume_impl)
1233612336

1233712337
static bool is_task_work_add_kfunc(u32 func_id)
1233812338
{
12339-
return func_id == special_kfunc_list[KF_bpf_task_work_schedule_signal] ||
12340-
func_id == special_kfunc_list[KF_bpf_task_work_schedule_resume];
12339+
return func_id == special_kfunc_list[KF_bpf_task_work_schedule_signal_impl] ||
12340+
func_id == special_kfunc_list[KF_bpf_task_work_schedule_resume_impl];
1234112341
}
1234212342

1234312343
static bool is_kfunc_ret_null(struct bpf_kfunc_call_arg_meta *meta)

tools/bpf/bpftool/Documentation/bpftool-prog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ bpftool prog tracelog
182182

183183
bpftool prog tracelog { stdout | stderr } *PROG*
184184
Dump the BPF stream of the program. BPF programs can write to these streams
185-
at runtime with the **bpf_stream_vprintk**\ () kfunc. The kernel may write
185+
at runtime with the **bpf_stream_vprintk_impl**\ () kfunc. The kernel may write
186186
error messages to the standard error stream. This facility should be used
187187
only for debugging purposes.
188188

tools/lib/bpf/bpf_helpers.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -315,20 +315,20 @@ enum libbpf_tristate {
315315
___param, sizeof(___param)); \
316316
})
317317

318-
extern int bpf_stream_vprintk(int stream_id, const char *fmt__str, const void *args,
319-
__u32 len__sz, void *aux__prog) __weak __ksym;
320-
321-
#define bpf_stream_printk(stream_id, fmt, args...) \
322-
({ \
323-
static const char ___fmt[] = fmt; \
324-
unsigned long long ___param[___bpf_narg(args)]; \
325-
\
326-
_Pragma("GCC diagnostic push") \
327-
_Pragma("GCC diagnostic ignored \"-Wint-conversion\"") \
328-
___bpf_fill(___param, args); \
329-
_Pragma("GCC diagnostic pop") \
330-
\
331-
bpf_stream_vprintk(stream_id, ___fmt, ___param, sizeof(___param), NULL);\
318+
extern int bpf_stream_vprintk_impl(int stream_id, const char *fmt__str, const void *args,
319+
__u32 len__sz, void *aux__prog) __weak __ksym;
320+
321+
#define bpf_stream_printk(stream_id, fmt, args...) \
322+
({ \
323+
static const char ___fmt[] = fmt; \
324+
unsigned long long ___param[___bpf_narg(args)]; \
325+
\
326+
_Pragma("GCC diagnostic push") \
327+
_Pragma("GCC diagnostic ignored \"-Wint-conversion\"") \
328+
___bpf_fill(___param, args); \
329+
_Pragma("GCC diagnostic pop") \
330+
\
331+
bpf_stream_vprintk_impl(stream_id, ___fmt, ___param, sizeof(___param), NULL); \
332332
})
333333

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ SEC("syscall")
1010
__failure __msg("Possibly NULL pointer passed")
1111
int stream_vprintk_null_arg(void *ctx)
1212
{
13-
bpf_stream_vprintk(BPF_STDOUT, "", NULL, 0, NULL);
13+
bpf_stream_vprintk_impl(BPF_STDOUT, "", NULL, 0, NULL);
1414
return 0;
1515
}
1616

1717
SEC("syscall")
1818
__failure __msg("R3 type=scalar expected=")
1919
int stream_vprintk_scalar_arg(void *ctx)
2020
{
21-
bpf_stream_vprintk(BPF_STDOUT, "", (void *)46, 0, NULL);
21+
bpf_stream_vprintk_impl(BPF_STDOUT, "", (void *)46, 0, NULL);
2222
return 0;
2323
}
2424

2525
SEC("syscall")
2626
__failure __msg("arg#1 doesn't point to a const string")
2727
int stream_vprintk_string_arg(void *ctx)
2828
{
29-
bpf_stream_vprintk(BPF_STDOUT, ctx, NULL, 0, NULL);
29+
bpf_stream_vprintk_impl(BPF_STDOUT, ctx, NULL, 0, NULL);
3030
return 0;
3131
}
3232

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int oncpu_hash_map(struct pt_regs *args)
6666
if (!work)
6767
return 0;
6868

69-
bpf_task_work_schedule_resume(task, &work->tw, &hmap, process_work, NULL);
69+
bpf_task_work_schedule_resume_impl(task, &work->tw, &hmap, process_work, NULL);
7070
return 0;
7171
}
7272

@@ -80,7 +80,7 @@ int oncpu_array_map(struct pt_regs *args)
8080
work = bpf_map_lookup_elem(&arrmap, &key);
8181
if (!work)
8282
return 0;
83-
bpf_task_work_schedule_signal(task, &work->tw, &arrmap, process_work, NULL);
83+
bpf_task_work_schedule_signal_impl(task, &work->tw, &arrmap, process_work, NULL);
8484
return 0;
8585
}
8686

@@ -102,6 +102,6 @@ int oncpu_lru_map(struct pt_regs *args)
102102
work = bpf_map_lookup_elem(&lrumap, &key);
103103
if (!work || work->data[0])
104104
return 0;
105-
bpf_task_work_schedule_resume(task, &work->tw, &lrumap, process_work, NULL);
105+
bpf_task_work_schedule_resume_impl(task, &work->tw, &lrumap, process_work, NULL);
106106
return 0;
107107
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int mismatch_map(struct pt_regs *args)
5353
work = bpf_map_lookup_elem(&arrmap, &key);
5454
if (!work)
5555
return 0;
56-
bpf_task_work_schedule_resume(task, &work->tw, &hmap, process_work, NULL);
56+
bpf_task_work_schedule_resume_impl(task, &work->tw, &hmap, process_work, NULL);
5757
return 0;
5858
}
5959

@@ -65,7 +65,7 @@ int no_map_task_work(struct pt_regs *args)
6565
struct bpf_task_work tw;
6666

6767
task = bpf_get_current_task_btf();
68-
bpf_task_work_schedule_resume(task, &tw, &hmap, process_work, NULL);
68+
bpf_task_work_schedule_resume_impl(task, &tw, &hmap, process_work, NULL);
6969
return 0;
7070
}
7171

@@ -76,7 +76,7 @@ int task_work_null(struct pt_regs *args)
7676
struct task_struct *task;
7777

7878
task = bpf_get_current_task_btf();
79-
bpf_task_work_schedule_resume(task, NULL, &hmap, process_work, NULL);
79+
bpf_task_work_schedule_resume_impl(task, NULL, &hmap, process_work, NULL);
8080
return 0;
8181
}
8282

@@ -91,6 +91,6 @@ int map_null(struct pt_regs *args)
9191
work = bpf_map_lookup_elem(&arrmap, &key);
9292
if (!work)
9393
return 0;
94-
bpf_task_work_schedule_resume(task, &work->tw, NULL, process_work, NULL);
94+
bpf_task_work_schedule_resume_impl(task, &work->tw, NULL, process_work, NULL);
9595
return 0;
9696
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ int schedule_task_work(void *ctx)
5151
if (!work)
5252
return 0;
5353
}
54-
err = bpf_task_work_schedule_signal(bpf_get_current_task_btf(), &work->tw, &hmap,
55-
process_work, NULL);
54+
err = bpf_task_work_schedule_signal_impl(bpf_get_current_task_btf(), &work->tw, &hmap,
55+
process_work, NULL);
5656
if (err)
5757
__sync_fetch_and_add(&schedule_error, 1);
5858
else

0 commit comments

Comments
 (0)