Skip to content

Commit c94c0f2

Browse files
wusamuel6Kernel Patches Daemon
authored andcommitted
bpf: Open coded BPF for wakeup_sources
Add open coded BPF iterators for wakeup_sources, which opens up more options for BPF programs that need to traverse through wakeup_sources. Signed-off-by: Samuel Wu <[email protected]>
1 parent a080189 commit c94c0f2

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

kernel/bpf/helpers.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4518,6 +4518,9 @@ BTF_ID_FLAGS(func, bpf_iter_dmabuf_new, KF_ITER_NEW | KF_SLEEPABLE)
45184518
BTF_ID_FLAGS(func, bpf_iter_dmabuf_next, KF_ITER_NEXT | KF_RET_NULL | KF_SLEEPABLE)
45194519
BTF_ID_FLAGS(func, bpf_iter_dmabuf_destroy, KF_ITER_DESTROY | KF_SLEEPABLE)
45204520
#endif
4521+
BTF_ID_FLAGS(func, bpf_iter_wakeup_source_new, KF_ITER_NEW | KF_SLEEPABLE)
4522+
BTF_ID_FLAGS(func, bpf_iter_wakeup_source_next, KF_ITER_NEXT | KF_RET_NULL | KF_SLEEPABLE)
4523+
BTF_ID_FLAGS(func, bpf_iter_wakeup_source_destroy, KF_ITER_DESTROY | KF_SLEEPABLE)
45214524
BTF_ID_FLAGS(func, __bpf_trap)
45224525
BTF_ID_FLAGS(func, bpf_strcmp);
45234526
BTF_ID_FLAGS(func, bpf_strcasecmp);

kernel/bpf/wakeup_source_iter.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,40 @@ static struct bpf_iter_reg bpf_wakeup_source_reg_info = {
9090
.seq_info = &wakeup_source_iter_seq_info,
9191
};
9292

93+
struct bpf_iter_wakeup_source {
94+
struct wakeup_source *ws;
95+
int srcuidx;
96+
};
97+
98+
__bpf_kfunc_start_defs();
99+
100+
__bpf_kfunc int bpf_iter_wakeup_source_new(struct bpf_iter_wakeup_source *it)
101+
{
102+
it->srcuidx = wakeup_sources_read_lock();
103+
it->ws = wakeup_sources_walk_start();
104+
105+
return 0;
106+
}
107+
108+
__bpf_kfunc struct wakeup_source *bpf_iter_wakeup_source_next(struct bpf_iter_wakeup_source *it)
109+
{
110+
struct wakeup_source *prev = it->ws;
111+
112+
if (!prev)
113+
return NULL;
114+
115+
it->ws = wakeup_sources_walk_next(it->ws);
116+
117+
return prev;
118+
}
119+
120+
__bpf_kfunc void bpf_iter_wakeup_source_destroy(struct bpf_iter_wakeup_source *it)
121+
{
122+
wakeup_sources_read_unlock(it->srcuidx);
123+
}
124+
125+
__bpf_kfunc_end_defs();
126+
93127
DEFINE_BPF_ITER_FUNC(wakeup_source, struct bpf_iter_meta *meta,
94128
struct wakeup_source *wakeup_source)
95129
BTF_ID_LIST_SINGLE(bpf_wakeup_source_btf_id, struct, wakeup_source)

0 commit comments

Comments
 (0)