Skip to content

Commit e7321c7

Browse files
theihorKernel Patches Daemon
authored andcommitted
bpf: Re-define bpf_task_work_schedule_* kfuncs as magic
* void *aux__prog => struct bpf_prog_aux *aux__magic * Set KF_MAGIC_ARGS flag * Add relevant symbols to magic_kfuncs list * Update selftests to use the new signature Signed-off-by: Ihor Solodrai <[email protected]>
1 parent 6557de6 commit e7321c7

File tree

7 files changed

+30
-20
lines changed

7 files changed

+30
-20
lines changed

kernel/bpf/helpers.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4278,15 +4278,15 @@ static int bpf_task_work_schedule(struct task_struct *task, struct bpf_task_work
42784278
* @tw: Pointer to struct bpf_task_work in BPF map value for internal bookkeeping
42794279
* @map__map: bpf_map that embeds struct bpf_task_work in the values
42804280
* @callback: pointer to BPF subprogram to call
4281-
* @aux__prog: user should pass NULL
4281+
* @aux__magic: pointer to bpf_prog_aux of the caller BPF program, set by the verifier
42824282
*
42834283
* Return: 0 if task work has been scheduled successfully, negative error code otherwise
42844284
*/
42854285
__bpf_kfunc int bpf_task_work_schedule_signal(struct task_struct *task, struct bpf_task_work *tw,
42864286
void *map__map, bpf_task_work_callback_t callback,
4287-
void *aux__prog)
4287+
struct bpf_prog_aux *aux__magic)
42884288
{
4289-
return bpf_task_work_schedule(task, tw, map__map, callback, aux__prog, TWA_SIGNAL);
4289+
return bpf_task_work_schedule(task, tw, map__map, callback, aux__magic, TWA_SIGNAL);
42904290
}
42914291

42924292
/**
@@ -4295,15 +4295,15 @@ __bpf_kfunc int bpf_task_work_schedule_signal(struct task_struct *task, struct b
42954295
* @tw: Pointer to struct bpf_task_work in BPF map value for internal bookkeeping
42964296
* @map__map: bpf_map that embeds struct bpf_task_work in the values
42974297
* @callback: pointer to BPF subprogram to call
4298-
* @aux__prog: user should pass NULL
4298+
* @aux__magic: pointer to bpf_prog_aux of the caller BPF program, set by the verifier
42994299
*
43004300
* Return: 0 if task work has been scheduled successfully, negative error code otherwise
43014301
*/
43024302
__bpf_kfunc int bpf_task_work_schedule_resume(struct task_struct *task, struct bpf_task_work *tw,
43034303
void *map__map, bpf_task_work_callback_t callback,
4304-
void *aux__prog)
4304+
struct bpf_prog_aux *aux__magic)
43054305
{
4306-
return bpf_task_work_schedule(task, tw, map__map, callback, aux__prog, TWA_RESUME);
4306+
return bpf_task_work_schedule(task, tw, map__map, callback, aux__magic, TWA_RESUME);
43074307
}
43084308

43094309
static int make_file_dynptr(struct file *file, u32 flags, bool may_sleep,
@@ -4529,8 +4529,8 @@ BTF_ID_FLAGS(func, bpf_strncasestr);
45294529
BTF_ID_FLAGS(func, bpf_cgroup_read_xattr, KF_RCU)
45304530
#endif
45314531
BTF_ID_FLAGS(func, bpf_stream_vprintk, KF_TRUSTED_ARGS)
4532-
BTF_ID_FLAGS(func, bpf_task_work_schedule_signal, KF_TRUSTED_ARGS)
4533-
BTF_ID_FLAGS(func, bpf_task_work_schedule_resume, KF_TRUSTED_ARGS)
4532+
BTF_ID_FLAGS(func, bpf_task_work_schedule_signal, KF_MAGIC_ARGS | KF_TRUSTED_ARGS)
4533+
BTF_ID_FLAGS(func, bpf_task_work_schedule_resume, KF_MAGIC_ARGS | KF_TRUSTED_ARGS)
45344534
BTF_ID_FLAGS(func, bpf_dynptr_from_file, KF_TRUSTED_ARGS)
45354535
BTF_ID_FLAGS(func, bpf_dynptr_file_discard)
45364536
BTF_KFUNCS_END(common_btf_ids)

kernel/bpf/verifier.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3269,6 +3269,10 @@ static struct btf *find_kfunc_desc_btf(struct bpf_verifier_env *env, s16 offset)
32693269
BTF_ID_LIST(magic_kfuncs)
32703270
BTF_ID(func, bpf_wq_set_callback)
32713271
BTF_ID(func, bpf_wq_set_callback_impl)
3272+
BTF_ID(func, bpf_task_work_schedule_signal)
3273+
BTF_ID(func, bpf_task_work_schedule_signal_impl)
3274+
BTF_ID(func, bpf_task_work_schedule_resume)
3275+
BTF_ID(func, bpf_task_work_schedule_resume_impl)
32723276
BTF_ID_LIST_END(magic_kfuncs)
32733277

32743278
static s32 magic_kfunc_by_impl(s32 impl_func_id)
@@ -12387,6 +12391,8 @@ enum special_kfunc_type {
1238712391
KF_bpf_task_work_schedule_signal,
1238812392
KF_bpf_task_work_schedule_resume,
1238912393
KF_bpf_wq_set_callback,
12394+
KF_bpf_task_work_schedule_signal_impl,
12395+
KF_bpf_task_work_schedule_resume_impl,
1239012396
};
1239112397

1239212398
BTF_ID_LIST(special_kfunc_list)
@@ -12462,11 +12468,15 @@ BTF_ID(func, __bpf_trap)
1246212468
BTF_ID(func, bpf_task_work_schedule_signal)
1246312469
BTF_ID(func, bpf_task_work_schedule_resume)
1246412470
BTF_ID(func, bpf_wq_set_callback)
12471+
BTF_ID(func, bpf_task_work_schedule_signal_impl)
12472+
BTF_ID(func, bpf_task_work_schedule_resume_impl)
1246512473

1246612474
static bool is_task_work_add_kfunc(u32 func_id)
1246712475
{
1246812476
return func_id == special_kfunc_list[KF_bpf_task_work_schedule_signal] ||
12469-
func_id == special_kfunc_list[KF_bpf_task_work_schedule_resume];
12477+
func_id == special_kfunc_list[KF_bpf_task_work_schedule_signal_impl] ||
12478+
func_id == special_kfunc_list[KF_bpf_task_work_schedule_resume] ||
12479+
func_id == special_kfunc_list[KF_bpf_task_work_schedule_resume_impl];
1247012480
}
1247112481

1247212482
static bool is_kfunc_ret_null(struct bpf_kfunc_call_arg_meta *meta)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int on_open_validate_file_read(void *c)
7777
err = 1;
7878
return 0;
7979
}
80-
bpf_task_work_schedule_signal(task, &work->tw, &arrmap, task_work_callback, NULL);
80+
bpf_task_work_schedule_signal(task, &work->tw, &arrmap, task_work_callback);
8181
return 0;
8282
}
8383

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(task, &work->tw, &hmap, process_work);
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(task, &work->tw, &arrmap, process_work);
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(task, &work->tw, &lrumap, process_work);
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(task, &work->tw, &hmap, process_work);
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(task, &tw, &hmap, process_work);
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(task, NULL, &hmap, process_work);
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(task, &work->tw, NULL, process_work);
9595
return 0;
9696
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int schedule_task_work(void *ctx)
5252
return 0;
5353
}
5454
err = bpf_task_work_schedule_signal(bpf_get_current_task_btf(), &work->tw, &hmap,
55-
process_work, NULL);
55+
process_work);
5656
if (err)
5757
__sync_fetch_and_add(&schedule_error, 1);
5858
else

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ int task_work_non_sleepable_prog(void *ctx)
156156
if (!task)
157157
return 0;
158158

159-
bpf_task_work_schedule_resume(task, &val->tw, &task_work_map, task_work_cb, NULL);
159+
bpf_task_work_schedule_resume(task, &val->tw, &task_work_map, task_work_cb);
160160
return 0;
161161
}
162162

@@ -176,6 +176,6 @@ int task_work_sleepable_prog(void *ctx)
176176
if (!task)
177177
return 0;
178178

179-
bpf_task_work_schedule_resume(task, &val->tw, &task_work_map, task_work_cb, NULL);
179+
bpf_task_work_schedule_resume(task, &val->tw, &task_work_map, task_work_cb);
180180
return 0;
181181
}

0 commit comments

Comments
 (0)