Skip to content

Commit 6070cfb

Browse files
Geliang Tangintel-lab-lkp
authored andcommitted
Squash to "bpf: Add mptcp_subflow bpf_iter"
Define .filter as Martin suggested. Signed-off-by: Geliang Tang <[email protected]>
1 parent 4db100e commit 6070cfb

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

net/mptcp/bpf.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,6 @@ __bpf_kfunc_end_defs();
305305
BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids)
306306
BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx, KF_RET_NULL)
307307
BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock, KF_RET_NULL)
308-
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new, KF_ITER_NEW | KF_TRUSTED_ARGS)
309-
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next, KF_ITER_NEXT | KF_RET_NULL)
310-
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_destroy, KF_ITER_DESTROY)
311308
BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled)
312309
BTF_ID_FLAGS(func, mptcp_subflow_active)
313310
BTF_ID_FLAGS(func, mptcp_set_timeout)
@@ -338,13 +335,40 @@ static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = {
338335
.filter = bpf_mptcp_common_kfunc_filter,
339336
};
340337

338+
/* .filter is called sometimes before prog->aux->st_ops is set,
339+
* then prog->aux->st_ops is NULL. If return -EACCES in this case,
340+
* an error occur:
341+
* bug: bad parent state for iter next call
342+
*/
343+
BTF_KFUNCS_START(bpf_mptcp_iter_kfunc_ids)
344+
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new, KF_ITER_NEW | KF_TRUSTED_ARGS)
345+
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next, KF_ITER_NEXT | KF_RET_NULL)
346+
BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_destroy, KF_ITER_DESTROY)
347+
BTF_KFUNCS_END(bpf_mptcp_iter_kfunc_ids)
348+
349+
static int bpf_mptcp_iter_kfunc_filter(const struct bpf_prog *prog, u32 kfunc_id)
350+
{
351+
if (btf_id_set8_contains(&bpf_mptcp_iter_kfunc_ids, kfunc_id) &&
352+
prog->type != BPF_PROG_TYPE_STRUCT_OPS)
353+
return -EACCES;
354+
return 0;
355+
}
356+
357+
static const struct btf_kfunc_id_set bpf_mptcp_iter_kfunc_set = {
358+
.owner = THIS_MODULE,
359+
.set = &bpf_mptcp_iter_kfunc_ids,
360+
.filter = bpf_mptcp_iter_kfunc_filter,
361+
};
362+
341363
static int __init bpf_mptcp_kfunc_init(void)
342364
{
343365
int ret;
344366

345367
ret = register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set);
346368
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
347369
&bpf_mptcp_common_kfunc_set);
370+
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
371+
&bpf_mptcp_iter_kfunc_set);
348372
#ifdef CONFIG_BPF_JIT
349373
ret = ret ?: register_bpf_struct_ops(&bpf_mptcp_sched_ops, mptcp_sched_ops);
350374
#endif

0 commit comments

Comments
 (0)