From: Petr Mladek <pmladek@suse.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>,
linux-kernel@vger.kernel.org, "J. Avila" <elavila@google.com>
Subject: Re: [PATCH] printk: avoid prb_first_valid_seq() where possible
Date: Thu, 11 Feb 2021 12:05:51 +0100 [thread overview]
Message-ID: <YCUPj5MK9mA65ST2@alley> (raw)
In-Reply-To: <874kij4w59.fsf@jogness.linutronix.de>
On Wed 2021-02-10 19:32:10, John Ogness wrote:
> On 2021-02-09, Petr Mladek <pmladek@suse.com> wrote:
> >> @@ -1629,9 +1631,13 @@ int do_syslog(int type, char __user *buf, int len, int source)
> >> /* Number of chars in the log buffer */
> >> case SYSLOG_ACTION_SIZE_UNREAD:
> >> logbuf_lock_irq();
> >> - if (syslog_seq < prb_first_valid_seq(prb)) {
> >> - /* messages are gone, move to first one */
> >> - syslog_seq = prb_first_valid_seq(prb);
> >> + if (prb_read_valid_info(prb, syslog_seq, &info, NULL)) {
> >> + if (info.seq != syslog_seq) {
> >> + /* messages are gone, move to first one */
> >> + syslog_seq = info.seq;
> >> + syslog_partial = 0;
> >> + }
> >> + } else {
> >> syslog_partial = 0;
> >
> > I am scratching my head when prb_read_valid_info(prb,
> > syslog_seq, &info, NULL)) might fail.
>
> It can fail because the descriptor has been invalidated/recycled by
> writers and perhaps there is no valid record that has yet come after it.
I see. From some reasons I though that there should always be at
least one message in the commited state. But it is enough when
it is in reusable state. I should have double checked it.
> I recommend changing your suggestion to:
>
> > if (!prb_read_valid_info(prb, syslog_seq, &info, NULL)) {
> > /*
> > * No unread messages. No need to check/reset
> > * syslog_partial. When a reader does read a new
> > * message it will notice and appropriately update
> > * syslog_seq and reset syslog_partial.
> > */
The following comment might be enough after all.
/* No unread messages. */
My main concern was that we cleared syslog_partial and continued.
I thought that we might miss a bug this way. But it seems to
be perfectly fine. I just have to update my mental picture.
Otherwise. the fact that syslog_partial will be fixed by the next
successful call is more or less obvious if we change the code as you
propose.
Please, send an updated patch.
Best Regards,
Petr
> > logbuf_unlock_irq();
> > return 0;
> > }
> > if (info.seq != syslog_seq) {
> > /* messages are gone, move to first one */
> > syslog_seq = info.seq;
> > syslog_partial = 0;
> > }
>
> John Ogness
prev parent reply other threads:[~2021-02-11 11:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-05 14:17 [PATCH] printk: avoid prb_first_valid_seq() where possible John Ogness
2021-02-08 6:44 ` Sergey Senozhatsky
2021-02-08 9:21 ` John Ogness
2021-02-09 0:15 ` J. Avila
2021-02-10 18:00 ` John Ogness
2021-02-09 2:17 ` Sergey Senozhatsky
2021-02-09 17:47 ` Petr Mladek
2021-02-10 18:26 ` John Ogness
2021-02-11 11:05 ` Petr Mladek [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YCUPj5MK9mA65ST2@alley \
--to=pmladek@suse.com \
--cc=elavila@google.com \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=sergey.senozhatsky@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox