Linux Serial subsystem development
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: "Gong, Sishuai" <sishuai@purdue.edu>
Cc: "jirislaby@kernel.org" <jirislaby@kernel.org>,
	"a.darwish@linutronix.de" <a.darwish@linutronix.de>,
	"aik@ozlabs.ru" <aik@ozlabs.ru>,
	"johan@kernel.org" <johan@kernel.org>,
	"linux-serial@vger.kernel.org" <linux-serial@vger.kernel.org>
Subject: Re: A data race between tty_port_open() and uart_do_autoconfig()
Date: Wed, 14 Apr 2021 08:20:07 +0200	[thread overview]
Message-ID: <YHaJl8vwvE1FsV2T@kroah.com> (raw)
In-Reply-To: <1D917C80-937C-4065-81DB-3B64E89C4E7B@purdue.edu>

On Wed, Apr 14, 2021 at 12:17:54AM +0000, Gong, Sishuai wrote:
> Hi,
> 
> We found a data race between two tty functions tty_port_open() and uart_do_autoconfig() in linux-5.12-rc3 and we are able to reproduce it under x86. In general, when tty_port_open() and uart_do_autoconfig() are running in parallel, uart_do_autoconfig() may fetch an out-of-date value of port->count and enter into a different execution path, as shown below.
> 
> Currently, we haven’t found any explicit errors due to this data race but we noticed the developer has used lock to read port->count, so we want to point out this data race in case this is unexpected.
> 
> ------------------------------------------
> Execution interleaving
> 
> Thread 1					Thread 2
> tty_port_open()			uart_do_autoconfig()
> 
> spin_lock_irq(&port->lock);
> 						if (mutex_lock_interruptible(&port->mutex))
> 						…
> 						if (tty_port_users(port) == 1) {
> 							uart_shutdown(tty, state);
> 
> ++port->count;
> spin_unlock_irq(&port->lock);
> 
> 
> 

Can you send a proposed patch for this to fix the issue as you sem to
have a reproducer for this that you can test if the change resolves the
issue or not?

thanks,

greg k-h

  reply	other threads:[~2021-04-14  6:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-14  0:17 A data race between tty_port_open() and uart_do_autoconfig() Gong, Sishuai
2021-04-14  6:20 ` Greg KH [this message]
2021-04-14 14:35   ` Gong, Sishuai
2021-04-14 15:08     ` Greg KH
2021-04-14 16:31       ` Gong, Sishuai

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=YHaJl8vwvE1FsV2T@kroah.com \
    --to=greg@kroah.com \
    --cc=a.darwish@linutronix.de \
    --cc=aik@ozlabs.ru \
    --cc=jirislaby@kernel.org \
    --cc=johan@kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=sishuai@purdue.edu \
    /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