[tty,v1,2/8] serial: core: lock port for stop_rx() in uart_suspend_port()

Message ID 20230525093159.223817-3-john.ogness@linutronix.de
State New
Headers
Series synchronize UART_IER access against console write |

Commit Message

John Ogness May 25, 2023, 9:31 a.m. UTC
  The uarts_ops stop_rx() callback expects that the port->lock is
taken and interrupts are disabled.

Fixes: c9d2325cdb92 ("serial: core: Do stop_rx in suspend path for console if console_suspend is disabled")
Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
 drivers/tty/serial/serial_core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Vijaya Krishna Nivarthi May 25, 2023, 5:47 p.m. UTC | #1
++Doug

Hi,


> -----Original Message-----
> From: John Ogness <john.ogness@linutronix.de>
> Sent: Thursday, May 25, 2023 3:02 PM
> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Petr Mladek <pmladek@suse.com>; Thomas Gleixner
> <tglx@linutronix.de>; linux-kernel@vger.kernel.org; Jiri Slaby
> <jirislaby@kernel.org>; Vijaya Krishna Nivarthi (Temp) (QUIC)
> <quic_vnivarth@quicinc.com>; linux-serial@vger.kernel.org
> Subject: [PATCH tty v1 2/8] serial: core: lock port for stop_rx() in
> uart_suspend_port()
> 
> WARNING: This email originated from outside of Qualcomm. Please be wary
> of any links or attachments, and do not enable macros.
> 
> The uarts_ops stop_rx() callback expects that the port->lock is taken and
> interrupts are disabled.
> 
> Fixes: c9d2325cdb92 ("serial: core: Do stop_rx in suspend path for console if
> console_suspend is disabled")
> Signed-off-by: John Ogness <john.ogness@linutronix.de>
> ---
>  drivers/tty/serial/serial_core.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 4b98d13555c0..37ad53616372 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -2333,8 +2333,11 @@ int uart_suspend_port(struct uart_driver *drv,
> struct uart_port *uport)
>          * able to Re-start_rx later.
>          */
>         if (!console_suspend_enabled && uart_console(uport)) {
> -               if (uport->ops->start_rx)
> +               if (uport->ops->start_rx) {
> +                       spin_lock_irq(&uport->lock);
>                         uport->ops->stop_rx(uport);
> +                       spin_unlock_irq(&uport->lock);
> +               }


Looks correct to me.
Thank you for the fix.

-Vijay/


>                 goto unlock;
>         }
> 
> --
> 2.30.2
  
Doug Anderson May 25, 2023, 8:37 p.m. UTC | #2
Hi,

On Thu, May 25, 2023 at 2:35 AM John Ogness <john.ogness@linutronix.de> wrote:
>
> The uarts_ops stop_rx() callback expects that the port->lock is
> taken and interrupts are disabled.
>
> Fixes: c9d2325cdb92 ("serial: core: Do stop_rx in suspend path for console if console_suspend is disabled")
> Signed-off-by: John Ogness <john.ogness@linutronix.de>
> ---
>  drivers/tty/serial/serial_core.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)

Reviewed-by: Douglas Anderson <dianders@chromium.org>
  

Patch

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 4b98d13555c0..37ad53616372 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -2333,8 +2333,11 @@  int uart_suspend_port(struct uart_driver *drv, struct uart_port *uport)
 	 * able to Re-start_rx later.
 	 */
 	if (!console_suspend_enabled && uart_console(uport)) {
-		if (uport->ops->start_rx)
+		if (uport->ops->start_rx) {
+			spin_lock_irq(&uport->lock);
 			uport->ops->stop_rx(uport);
+			spin_unlock_irq(&uport->lock);
+		}
 		goto unlock;
 	}