All of lore.kernel.org
 help / color / mirror / Atom feed
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>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH printk v2 4/5] printk: convert @syslog_lock to mutex
Date: Thu, 1 Apr 2021 17:13:46 +0200	[thread overview]
Message-ID: <YGXjKqCgXdTmtTxy@alley> (raw)
In-Reply-To: <20210330153512.1182-5-john.ogness@linutronix.de>

On Tue 2021-03-30 17:35:11, John Ogness wrote:
> @syslog_lock was a raw_spin_lock to simplify the transition of
> removing @logbuf_lock and the safe buffers. With that transition
> complete, and since all uses of @syslog_lock are within sleepable
> contexts, @syslog_lock can become a mutex.

It makes perfect sense.

> ---
>  Note: The removal of read_syslog_seq_irq() is technically a small
>        step backwards. But the follow-up patch moves forward again
>        and closes a window that existed with read_syslog_seq_irq()
>        and @syslog_lock as a spin_lock.

This change would deserve a comment in the commit message. Well, I do
not think that is a step backward, see below.

>  kernel/printk/printk.c | 49 +++++++++++++++++-------------------------
>  1 file changed, 20 insertions(+), 29 deletions(-)
> 
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index f090d6a1b39e..b771aae46445 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -1603,21 +1603,9 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
>  
>  static void syslog_clear(void)
>  {
> -	raw_spin_lock_irq(&syslog_lock);
> +	mutex_lock(&syslog_lock);
>  	latched_seq_write(&clear_seq, prb_next_seq(prb));
> -	raw_spin_unlock_irq(&syslog_lock);
> -}
> -
> -/* Return a consistent copy of @syslog_seq. */
> -static u64 read_syslog_seq_irq(void)
> -{
> -	u64 seq;
> -
> -	raw_spin_lock_irq(&syslog_lock);
> -	seq = syslog_seq;
> -	raw_spin_unlock_irq(&syslog_lock);
> -
> -	return seq;
> +	mutex_unlock(&syslog_lock);
>  }
>  
>  int do_syslog(int type, char __user *buf, int len, int source)
> @@ -1644,8 +1633,12 @@ int do_syslog(int type, char __user *buf, int len, int source)
>  		if (!access_ok(buf, len))
>  			return -EFAULT;
>  
> -		error = wait_event_interruptible(log_wait,
> -				prb_read_valid(prb, read_syslog_seq_irq(), NULL));
> +		/* Get a consistent copy of @syslog_seq. */
> +		mutex_lock(&syslog_lock);
> +		seq = syslog_seq;
> +		mutex_unlock(&syslog_lock);
> +
> +		error = wait_event_interruptible(log_wait, prb_read_valid(prb, seq, NULL));

Honestly, I am not sure how the syslog interface should work when there
are two readers in the system. They both share the same "syslog_seq".

This either fixes a historic bug. The caller of SYSLOG_ACTION_READ
might miss the new message when another reader did read it in the
meantime.

Or it might introduce a regression when two readers would read the
same message.

Or it does not matter because the behavior is racy by definition.

Best Regards,
Petr

PS: I am going to look at this more with a fresh head after Easter
 holidays.  The answer is important also for the next patch that
 basically restores the original behavior.
 

  reply	other threads:[~2021-04-01 17:56 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-30 15:35 [PATCH printk v2 0/5] printk: remove safe buffers John Ogness
2021-03-30 15:35 ` John Ogness
2021-03-30 15:35 ` John Ogness
2021-03-30 15:35 ` John Ogness
2021-03-30 15:35 ` [PATCH printk v2 1/5] printk: track/limit recursion John Ogness
2021-04-01 10:00   ` Petr Mladek
2021-04-02  2:03     ` Sergey Senozhatsky
2021-03-30 15:35 ` [PATCH printk v2 2/5] printk: remove safe buffers John Ogness
2021-03-30 15:35   ` John Ogness
2021-03-30 15:35   ` John Ogness
2021-03-31  7:59   ` John Ogness
2021-03-31  7:59     ` John Ogness
2021-03-31  7:59     ` John Ogness
2021-04-01 12:21   ` Petr Mladek
2021-04-01 12:21     ` Petr Mladek
2021-04-01 12:21     ` Petr Mladek
2021-04-01 13:19     ` John Ogness
2021-04-01 13:19       ` John Ogness
2021-04-01 13:19       ` John Ogness
2021-04-01 14:17       ` Petr Mladek
2021-04-01 14:17         ` Petr Mladek
2021-04-01 14:17         ` Petr Mladek
2021-04-02  2:14         ` Sergey Senozhatsky
2021-04-02  2:14           ` Sergey Senozhatsky
2021-04-02  2:14           ` Sergey Senozhatsky
2021-04-06 11:17           ` Petr Mladek
2021-04-06 11:17             ` Petr Mladek
2021-04-06 11:17             ` Petr Mladek
2021-04-06 11:01         ` John Ogness
2021-04-06 11:01           ` John Ogness
2021-04-06 11:01           ` John Ogness
2021-03-30 15:35 ` [PATCH printk v2 3/5] printk: remove NMI tracking John Ogness
2021-03-30 15:35   ` John Ogness
2021-03-30 15:35   ` John Ogness
2021-04-01 14:37   ` Petr Mladek
2021-04-01 14:37     ` Petr Mladek
2021-04-01 14:37     ` Petr Mladek
2021-03-30 15:35 ` [PATCH printk v2 4/5] printk: convert @syslog_lock to mutex John Ogness
2021-04-01 15:13   ` Petr Mladek [this message]
2021-03-30 15:35 ` [PATCH printk v2 5/5] printk: syslog: close window between wait and read John Ogness

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=YGXjKqCgXdTmtTxy@alley \
    --to=pmladek@suse.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 \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.