On Tue, May 12, 2020 at 8:54 AM Yonghong Song <yhs@xxxxxx> wrote: > > In seq_read() implementation, a positive integer return value > of seq_ops->show() indicates that the current object seq_file > buffer is discarded and next object should be checked. > bpf_seq_read() implemented in a similar way if show() > returns a positive integer value. > > But for bpf_seq_read(), show() didn't return positive integer for > all currently supported targets. Let us add a WARN_ONCE for > such cases so we can get an alert when things are changed. > > Suggested-by: Alexei Starovoitov <ast@xxxxxxxxxx> > Signed-off-by: Yonghong Song <yhs@xxxxxx> > --- > kernel/bpf/bpf_iter.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c > index 0a45a6cdfabd..b0c8b3bdf3b0 100644 > --- a/kernel/bpf/bpf_iter.c > +++ b/kernel/bpf/bpf_iter.c > @@ -120,6 +120,7 @@ static ssize_t bpf_seq_read(struct file *file, char __user *buf, size_t size, > > err = seq->op->show(seq, p); > if (err > 0) { > + WARN_ONCE(1, "seq_ops->show() returns %d\n", err); This makes it look like it's a bug or non-safe, honestly. I'd drop the warning altogether, but if not, probably leaving a comment explaining why we added WARN_ONCE here and that it's ok to remove it would be good. > /* object is skipped, decrease seq_num, so next > * valid object can reuse the same seq_num. > */ > @@ -156,6 +157,7 @@ static ssize_t bpf_seq_read(struct file *file, char __user *buf, size_t size, > > err = seq->op->show(seq, p); > if (err > 0) { > + WARN_ONCE(1, "seq_ops->show() returns %d\n", err); > bpf_iter_dec_seq_num(seq); > seq->count = offs; > } else if (err < 0 || seq_has_overflowed(seq)) { > -- > 2.24.1 >