Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753560AbbHCPbR (ORCPT ); Mon, 3 Aug 2015 11:31:17 -0400 Received: from mail-qg0-f52.google.com ([209.85.192.52]:34358 "EHLO mail-qg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753073AbbHCPbO (ORCPT ); Mon, 3 Aug 2015 11:31:14 -0400 Message-ID: <55BF893C.1000901@hurleysoftware.com> Date: Mon, 03 Aug 2015 11:31:08 -0400 From: Peter Hurley User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: Johannes Thumshirn CC: Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Andreas Werner Subject: Re: [PATCH] tty: serial: men_z135_uart.c: Fix race between IRQ and set_termios() References: <1438610285-1441-1-git-send-email-jthumshirn@suse.de> In-Reply-To: <1438610285-1441-1-git-send-email-jthumshirn@suse.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2568 Lines: 71 Hi Johannes, On 08/03/2015 09:58 AM, Johannes Thumshirn wrote: > Fix panic caused by a race between men_z135_intr() and men_z135_set_termios(). > > men_z135_intr() and men_z135_set_termios() both hold the struct uart_port::lock > spinlock, but men_z135_intr() does a spin_lock_irqsave() and > men_z135_set_termios() does a normal spin_lock(), which can lead to a deadlock > when an interrupt is called while the lock is being helt by > men_z135_set_termios(). The irq handler can and should use normal spin_lock()/unlock(). The set_termios() method should used spin_lock_irq(); there's no need to save the interrupt state because that method will never be called from interrupt context. So the 'flags' local can be dropped from the patch. Also, the port lock is already initialized in uart_add_one_port() and should not be initialized by the probe() function. Regards, Peter Hurley > This was discovered using a insmod, hardware looppback send/receive, rmmod > stress test. > > Signed-off-by: Johannes Thumshirn > Cc: Andreas Werner > --- > drivers/tty/serial/men_z135_uart.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/tty/serial/men_z135_uart.c b/drivers/tty/serial/men_z135_uart.c > index 35c5550..d020435 100644 > --- a/drivers/tty/serial/men_z135_uart.c > +++ b/drivers/tty/serial/men_z135_uart.c > @@ -656,6 +656,7 @@ static void men_z135_set_termios(struct uart_port *port, > struct ktermios *old) > { > struct men_z135_port *uart = to_men_z135(port); > + unsigned long flags; > unsigned int baud; > u32 conf_reg; > u32 bd_reg; > @@ -717,7 +718,7 @@ static void men_z135_set_termios(struct uart_port *port, > > baud = uart_get_baud_rate(port, termios, old, 0, uart_freq / 16); > > - spin_lock(&port->lock); > + spin_lock_irqsave(&port->lock, flags); > if (tty_termios_baud_rate(termios)) > tty_termios_encode_baud_rate(termios, baud, baud); > > @@ -725,7 +726,7 @@ static void men_z135_set_termios(struct uart_port *port, > iowrite32(bd_reg, port->membase + MEN_Z135_BAUD_REG); > > uart_update_timeout(port, termios->c_cflag, baud); > - spin_unlock(&port->lock); > + spin_unlock_irqrestore(&port->lock, flags); > } > > static const char *men_z135_type(struct uart_port *port) > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/