All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: Duoming Zhou <duoming@zju.edu.cn>, linux-kernel@vger.kernel.org
Cc: chris@zankel.net, jcmvbkbc@gmail.com, mustafa.ismail@intel.com,
	shiraz.saleem@intel.com, jgg@ziepe.ca, wg@grandegger.com,
	mkl@pengutronix.de, davem@davemloft.net, kuba@kernel.org,
	pabeni@redhat.com, jes@trained-monkey.org,
	gregkh@linuxfoundation.org, alexander.deucher@amd.com,
	linux-xtensa@linux-xtensa.org, linux-rdma@vger.kernel.org,
	linux-can@vger.kernel.org, netdev@vger.kernel.org,
	linux-hippi@sunsite.dk, linux-staging@lists.linux.dev,
	linux-serial@vger.kernel.org, linux-usb@vger.kernel.org,
	Russell King - ARM Linux <linux@armlinux.org.uk>
Subject: Re: [PATCH 01/11] drivers: tty: serial: Fix deadlock in sa1100_set_termios()
Date: Thu, 7 Apr 2022 09:02:05 +0200	[thread overview]
Message-ID: <656ffd1d-e7cf-d2c0-e0e6-c10215ba422b@kernel.org> (raw)
In-Reply-To: <e82ff9358d4ef90a7e9f624534d6d54fc193467f.1649310812.git.duoming@zju.edu.cn>

On 07. 04. 22, 8:33, Duoming Zhou wrote:
> There is a deadlock in sa1100_set_termios(), which is shown
> below:
> 
>     (Thread 1)              |      (Thread 2)
>                             | sa1100_enable_ms()
> sa1100_set_termios()       |  mod_timer()
>   spin_lock_irqsave() //(1) |  (wait a time)
>   ...                       | sa1100_timeout()
>   del_timer_sync()          |  spin_lock_irqsave() //(2)
>   (wait timer to stop)      |  ...
> 
> We hold sport->port.lock in position (1) of thread 1 and
> use del_timer_sync() to wait timer to stop, but timer handler
> also need sport->port.lock in position (2) of thread 2. As a result,
> sa1100_set_termios() will block forever.
> 
> This patch extracts del_timer_sync() from the protection of
> spin_lock_irqsave(), which could let timer handler to obtain
> the needed lock.
> 
> Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
> ---
>   drivers/tty/serial/sa1100.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/tty/serial/sa1100.c b/drivers/tty/serial/sa1100.c
> index 5fe6cccfc1a..3a5f12ced0b 100644
> --- a/drivers/tty/serial/sa1100.c
> +++ b/drivers/tty/serial/sa1100.c
> @@ -476,7 +476,9 @@ sa1100_set_termios(struct uart_port *port, struct ktermios *termios,
>   				UTSR1_TO_SM(UTSR1_ROR);
>   	}
>   
> +	spin_unlock_irqrestore(&sport->port.lock, flags);

Unlocking the lock at this point doesn't look safe at all. Maybe moving 
the timer deletion before the lock? There is no current maintainer to 
ask. Most of the driver originates from rmk. Ccing him just in case.

FWIW the lock was moved by this commit around linux 2.5.55 (from 
full-history-linux [1])
commit f38aef3e62c26a33ea360a86fde9b27e183a3748
Author: Russell King <rmk@flint.arm.linux.org.uk>
Date:   Fri Jan 3 15:42:09 2003 +0000

     [SERIAL] Convert change_speed() to settermios()

[1] 
https://archive.org/download/git-history-of-linux/full-history-linux.git.tar

>   	del_timer_sync(&sport->timer);
> +	spin_lock_irqsave(&sport->port.lock, flags);
>   
>   	/*
>   	 * Update the per-port timeout.

thanks,
-- 
js
suse labs

  reply	other threads:[~2022-04-07  7:02 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-07  6:33 [PATCH 00/11] Fix deadlocks caused by del_timer_sync() Duoming Zhou
2022-04-07  6:33 ` [PATCH 01/11] drivers: tty: serial: Fix deadlock in sa1100_set_termios() Duoming Zhou
2022-04-07  7:02   ` Jiri Slaby [this message]
2022-04-07 14:03     ` duoming
2022-04-07  6:33 ` [PATCH 02/11] drivers: usb: host: Fix deadlock in oxu_bus_suspend() Duoming Zhou
2022-04-07  8:01   ` Oliver Neukum
2022-04-07 12:02     ` duoming
2022-04-07  6:33 ` [PATCH 03/11] drivers: staging: rtl8192u: Fix deadlock in ieee80211_beacons_stop() Duoming Zhou
2022-04-07  6:33 ` [PATCH 04/11] drivers: staging: rtl8723bs: Fix deadlock in rtw_surveydone_event_callback() Duoming Zhou
2022-04-07  6:36 ` [PATCH 05/11] drivers: staging: rtl8192e: Fix deadlock in rtllib_beacons_stop() Duoming Zhou
2022-04-07  6:36 ` [PATCH 06/11] drivers: staging: rtl8192e: Fix deadlock in rtw_joinbss_event_prehandle() Duoming Zhou
2022-04-07  6:36 ` [PATCH 07/11] drivers: net: hippi: Fix deadlock in rr_close() Duoming Zhou
2022-04-07  6:37 ` [PATCH 08/11] drivers: net: can: Fix deadlock in grcan_close() Duoming Zhou
2022-04-07  6:37 ` [PATCH 09/11] drivers: infiniband: hw: Fix deadlock in irdma_cleanup_cm_core() Duoming Zhou
2022-04-07 11:24   ` Dan Carpenter
2022-04-07 12:54     ` duoming
2022-04-07 14:23       ` Jason Gunthorpe
2022-04-07 14:38         ` duoming
2022-04-07 17:35           ` Saleem, Shiraz
2022-04-07 15:24       ` Dan Carpenter
2022-04-07 17:36         ` Saleem, Shiraz
2022-04-08  0:35           ` duoming
2022-04-08  2:21             ` Saleem, Shiraz
2022-04-08  2:52               ` duoming
2022-04-07  6:37 ` [PATCH 10/11] arch: xtensa: platforms: Fix deadlock in iss_net_close() Duoming Zhou
2022-04-07  6:37 ` [PATCH 11/11] arch: xtensa: platforms: Fix deadlock in rs_close() Duoming Zhou
2022-04-07  7:21   ` Max Filippov
2022-04-07 11:05     ` duoming
2022-04-07  9:42   ` Sergey Shtylyov
2022-04-07 11:12     ` duoming

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=656ffd1d-e7cf-d2c0-e0e6-c10215ba422b@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=alexander.deucher@amd.com \
    --cc=chris@zankel.net \
    --cc=davem@davemloft.net \
    --cc=duoming@zju.edu.cn \
    --cc=gregkh@linuxfoundation.org \
    --cc=jcmvbkbc@gmail.com \
    --cc=jes@trained-monkey.org \
    --cc=jgg@ziepe.ca \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-hippi@sunsite.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=linux-usb@vger.kernel.org \
    --cc=linux-xtensa@linux-xtensa.org \
    --cc=linux@armlinux.org.uk \
    --cc=mkl@pengutronix.de \
    --cc=mustafa.ismail@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shiraz.saleem@intel.com \
    --cc=wg@grandegger.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 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.