On Fri, Jan 23, 2026 at 5:50 PM <[email protected]> wrote:
>
> > diff --git a/kernel/bpf/wakeup_source_iter.c 
> > b/kernel/bpf/wakeup_source_iter.c
> > new file mode 100644
> > index 000000000000..ab83d212a1f9
> > --- /dev/null
> > +++ b/kernel/bpf/wakeup_source_iter.c
>
> [ ... ]
>
> > +static void wakeup_source_iter_seq_stop(struct seq_file *seq, void *v)
> > +{
> > +     int *srcuidx = seq->private;
> > +
> > +     if (*srcuidx >= 0)
> > +             wakeup_sources_read_unlock(*srcuidx);
> > +     *srcuidx = -1;
> > +}
>
> Should this function call __wakeup_source_seq_show(seq, v, true) when v is
> NULL to notify the BPF program that iteration has completed?

My understanding is that above code is invoked as a N+1 case after
iterating through a list of size N. If desired behavior is to do
additional cleanup not already covered by _seq_stop() (e.g. printing
closing footers), then v == NULL should be handled. However, there is
no such need for wakeup_source_iter at the moment.

>
> Looking at other BPF iterators like map_iter, prog_iter, link_iter,
> task_iter, and kmem_cache_iter, they all invoke the BPF program with
> in_stop=true when the stop callback receives a NULL pointer. For example,
> map_iter does:
>
>     static void bpf_map_seq_stop(struct seq_file *seq, void *v)
>     {
>         if (!v)
>             (void)__bpf_map_seq_show(seq, v, true);
>         ...
>     }
>
> The bpf_seq_read() function in kernel/bpf/bpf_iter.c has this comment at
> the stop label: "/* bpf program called if !p */", which suggests this
> callback is expected.
>
> The __wakeup_source_seq_show() function already accepts an in_stop
> parameter but is never called with true. Without this callback, BPF
> programs using this iterator cannot detect when iteration has finished.
>

If I understand correctly, this is not mandatory. For a
straightforward iterator like this one, I'd like to keep it simple and
not unnecessarily handle this case.

>
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
>
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/21306880863

Reply via email to