* [PATCH] printk: Fix skipped entries after index iterator restart
@ 2026-11-16 8:56 Avi Weiss
2026-11-16 9:15 ` Andy Shevchenko
2026-11-24 10:19 ` Petr Mladek
0 siblings, 2 replies; 5+ messages in thread
From: Avi Weiss @ 2026-11-16 8:56 UTC (permalink / raw)
To: Chris Down, Petr Mladek, John Ogness
Cc: Steven Rostedt, Sergey Senozhatsky, printk, linux-kernel, Avi Weiss
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.
Fixes: 337015573718 ("printk: Userspace format indexing support")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---
kernel/printk/index.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/printk/index.c b/kernel/printk/index.c
index a6b27526baaf6..642640a36abe1 100644
--- a/kernel/printk/index.c
+++ b/kernel/printk/index.c
@@ -59,7 +59,7 @@ static void *pi_start(struct seq_file *s, loff_t *pos)
if (*pos == 0)
return SEQ_START_TOKEN;
- return pi_next(s, NULL, pos);
+ return pi_get_entry(s->file->f_inode->i_private, *pos - 1);
}
/*
base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] printk: Fix skipped entries after index iterator restart
2026-11-16 8:56 [PATCH] printk: Fix skipped entries after index iterator restart Avi Weiss
@ 2026-11-16 9:15 ` Andy Shevchenko
2026-11-24 10:28 ` Petr Mladek
2026-11-24 10:19 ` Petr Mladek
1 sibling, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2026-11-16 9:15 UTC (permalink / raw)
To: Avi Weiss
Cc: Chris Down, Petr Mladek, John Ogness, Steven Rostedt,
Sergey Senozhatsky, printk, linux-kernel
On Mon, Nov 16, 2026 at 10:56:10AM +0200, 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.
...
> - return pi_next(s, NULL, pos);
> + return pi_get_entry(s->file->f_inode->i_private, *pos - 1);
Side note (because it seems used more in the same form), we have file_inode()
helper and this should idiomatically look as
return pi_get_entry(file_inode(s->file)->i_private, *pos - 1);
But I haven't checked if the file_inode() is recommended or deprecated API.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] printk: Fix skipped entries after index iterator restart
2026-11-16 9:15 ` Andy Shevchenko
@ 2026-11-24 10:28 ` Petr Mladek
2026-11-24 10:41 ` Andy Shevchenko
0 siblings, 1 reply; 5+ messages in thread
From: Petr Mladek @ 2026-11-24 10:28 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Avi Weiss, Chris Down, John Ogness, Steven Rostedt,
Sergey Senozhatsky, printk, linux-kernel
On Mon 2026-11-16 11:15:03, Andy Shevchenko wrote:
> On Mon, Nov 16, 2026 at 10:56:10AM +0200, 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.
>
> ...
>
> > - return pi_next(s, NULL, pos);
> > + return pi_get_entry(s->file->f_inode->i_private, *pos - 1);
>
> Side note (because it seems used more in the same form), we have file_inode()
> helper and this should idiomatically look as
>
> return pi_get_entry(file_inode(s->file)->i_private, *pos - 1);
>
> But I haven't checked if the file_inode() is recommended or deprecated API.
Good to know. But honestly, the variant with file_inode(s->file) looks
less readable to me. IMHO, it is not worth it.
Best Regards,
Petr
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] printk: Fix skipped entries after index iterator restart
2026-11-24 10:28 ` Petr Mladek
@ 2026-11-24 10:41 ` Andy Shevchenko
0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2026-11-24 10:41 UTC (permalink / raw)
To: Petr Mladek
Cc: Avi Weiss, Chris Down, John Ogness, Steven Rostedt,
Sergey Senozhatsky, printk, linux-kernel
On Tue, Nov 24, 2026 at 11:28:01AM +0100, Petr Mladek wrote:
> On Mon 2026-11-16 11:15:03, Andy Shevchenko wrote:
> > On Mon, Nov 16, 2026 at 10:56:10AM +0200, Avi Weiss wrote:
...
> > > - return pi_next(s, NULL, pos);
> > > + return pi_get_entry(s->file->f_inode->i_private, *pos - 1);
> >
> > Side note (because it seems used more in the same form), we have file_inode()
> > helper and this should idiomatically look as
> >
> > return pi_get_entry(file_inode(s->file)->i_private, *pos - 1);
> >
> > But I haven't checked if the file_inode() is recommended or deprecated API.
>
> Good to know. But honestly, the variant with file_inode(s->file) looks
> less readable to me. IMHO, it is not worth it.
I agree, but I have checked treewide and that's why I put word 'idiomatically'.
All questions to VFS folks :-)
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] printk: Fix skipped entries after index iterator restart
2026-11-16 8:56 [PATCH] printk: Fix skipped entries after index iterator restart Avi Weiss
2026-11-16 9:15 ` Andy Shevchenko
@ 2026-11-24 10:19 ` Petr Mladek
1 sibling, 0 replies; 5+ messages in thread
From: Petr Mladek @ 2026-11-24 10:19 UTC (permalink / raw)
To: Avi Weiss
Cc: Chris Down, John Ogness, Steven Rostedt, Sergey Senozhatsky,
printk, linux-kernel
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@gmail.com>
Otherwise the patch looks good to me. With the updated commit
message:
Reviewed-by: Petr Mladek <pmladek@suse.com>
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-24 10:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 8:56 [PATCH] printk: Fix skipped entries after index iterator restart Avi Weiss
2026-11-16 9:15 ` Andy Shevchenko
2026-11-24 10:28 ` Petr Mladek
2026-11-24 10:41 ` Andy Shevchenko
2026-11-24 10:19 ` Petr Mladek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®