Skip to content

Commit 7542925

Browse files
Geliang Tangintel-lab-lkp
authored andcommitted
Squash to "bpf: Export mptcp packet scheduler helpers"
Define .filter as Martin suggested. Signed-off-by: Geliang Tang <[email protected]>
1 parent 5a9212f commit 7542925

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

net/mptcp/bpf.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,18 +317,37 @@ BTF_ID_FLAGS(func, bpf_mptcp_subflow_queues_empty)
317317
BTF_ID_FLAGS(func, mptcp_pm_subflow_chk_stale, KF_SLEEPABLE)
318318
BTF_KFUNCS_END(bpf_mptcp_common_kfunc_ids)
319319

320+
static int bpf_mptcp_common_kfunc_filter(const struct bpf_prog *prog, u32 kfunc_id)
321+
{
322+
if (!btf_id_set8_contains(&bpf_mptcp_common_kfunc_ids, kfunc_id))
323+
return 0;
324+
325+
if (prog->type != BPF_PROG_TYPE_STRUCT_OPS)
326+
return -EACCES;
327+
328+
/* .filter is called sometimes before prog->aux->st_ops is set,
329+
* then prog->aux->st_ops is NULL. If return -EACCES in this case,
330+
* an error occur:
331+
* bug: bad parent state for iter next call
332+
*/
333+
if (prog->aux->st_ops &&
334+
prog->aux->st_ops != &bpf_mptcp_sched_ops)
335+
return -EACCES;
336+
337+
return 0;
338+
}
339+
320340
static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = {
321341
.owner = THIS_MODULE,
322342
.set = &bpf_mptcp_common_kfunc_ids,
343+
.filter = bpf_mptcp_common_kfunc_filter,
323344
};
324345

325346
static int __init bpf_mptcp_kfunc_init(void)
326347
{
327348
int ret;
328349

329350
ret = register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set);
330-
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SOCKOPT,
331-
&bpf_mptcp_common_kfunc_set);
332351
ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
333352
&bpf_mptcp_common_kfunc_set);
334353
#ifdef CONFIG_BPF_JIT

0 commit comments

Comments
 (0)