Re: [PATCH] printk: Fix skipped entries after index iterator restart
From: Petr Mladek
Date: Tue Nov 24 2026 - 05:19:44 EST
On Mon 2026-11-16 10:56:10, Avi Weiss wrote:
> seq_read_iter() can advance the iterator before the next record
> fits in the read buffer. When iteration resumes, pi_start() calls
> pi_next() at the saved position and advances past the pending printk
> index entry. As a result, index reads can silently omit formats.
>
> Return the entry corresponding to the saved position without
> advancing the iterator.
Great catch!
But honestly, I was a bit confused by the description. I think that
it is not easy to describe it a reasonable way. Well, I wonder
if the following is more clear:
<proposal>
seq_read_iter() calls pi_next() until it reads the last entry or until
the given read buffer gets full. The it calls pi_stop() in both
situations.
The next seq_read_iter() calls pi_start() to (re)start the session.
pi_start() is supposed to either start from the the beginning or
return the last entry which did not fit into the read buffer.
By other words, pi_start() should not call pi_next() which would return
the next entry. Instead it should return the entry which did not fit
into the buffer last time. Otherwise, the entry would get skipped.
Note that *pos is off-by-one because "0" position is used for the
title string (struct seq_operations). So that pr_start() should
return the *pos - 1 entry.
</proposal>
> Fixes: 337015573718 ("printk: Userspace format indexing support")
> Signed-off-by: Avi Weiss <thnkslprpt@xxxxxxxxx>
Otherwise the patch looks good to me. With the updated commit
message:
Reviewed-by: Petr Mladek <pmladek@xxxxxxxx>
Best Regards,
Petr
PS: I am going to wait few days for potential feedback. Then I will
commit the patch with the updated commit messages unless anyone
complains in the meantime.