[tty,v1,4/8] serial: core: lock port for start_rx() in uart_resume_port()

Message ID 20230525093159.223817-5-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 only user of the start_rx() callback (qcom_geni) directly calls
its own stop_rx() callback. Since stop_rx() requires that the
port->lock is taken and interrupts are disabled, the start_rx()
callback has the same requirement.

Fixes: cfab87c2c271 ("serial: core: Introduce callback for start_rx and do stop_rx in suspend only if this callback implementation is present.")
Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
 drivers/tty/serial/serial_core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Doug Anderson May 25, 2023, 4:07 p.m. UTC | #1
Hi,

On Thu, May 25, 2023 at 2:34 AM John Ogness <john.ogness@linutronix.de> wrote:
>
> The only user of the start_rx() callback (qcom_geni) directly calls
> its own stop_rx() callback. Since stop_rx() requires that the
> port->lock is taken and interrupts are disabled, the start_rx()
> callback has the same requirement.
>
> Fixes: cfab87c2c271 ("serial: core: Introduce callback for start_rx and do stop_rx in suspend only if this callback implementation is present.")
> 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 37ad53616372..f856c7fae2fd 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -2430,8 +2430,11 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
>                 if (console_suspend_enabled)
>                         uart_change_pm(state, UART_PM_STATE_ON);
>                 uport->ops->set_termios(uport, &termios, NULL);
> -               if (!console_suspend_enabled && uport->ops->start_rx)
> +               if (!console_suspend_enabled && uport->ops->start_rx) {
> +                       spin_lock_irq(&uport->lock);
>                         uport->ops->start_rx(uport);
> +                       spin_unlock_irq(&uport->lock);
> +               }

Seems right, but shouldn't you also fix the call to stop_rx() that the
same commit cfab87c2c271 ("serial: core: Introduce callback for
start_rx and do stop_rx in suspend only if this callback
implementation is present.") added? That one is also missing the lock,
right?

-Doug
  
Doug Anderson May 25, 2023, 8:38 p.m. UTC | #2
Hi,

On Thu, May 25, 2023 at 9:07 AM Doug Anderson <dianders@chromium.org> wrote:
>
> Hi,
>
> On Thu, May 25, 2023 at 2:34 AM John Ogness <john.ogness@linutronix.de> wrote:
> >
> > The only user of the start_rx() callback (qcom_geni) directly calls
> > its own stop_rx() callback. Since stop_rx() requires that the
> > port->lock is taken and interrupts are disabled, the start_rx()
> > callback has the same requirement.
> >
> > Fixes: cfab87c2c271 ("serial: core: Introduce callback for start_rx and do stop_rx in suspend only if this callback implementation is present.")
> > 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 37ad53616372..f856c7fae2fd 100644
> > --- a/drivers/tty/serial/serial_core.c
> > +++ b/drivers/tty/serial/serial_core.c
> > @@ -2430,8 +2430,11 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
> >                 if (console_suspend_enabled)
> >                         uart_change_pm(state, UART_PM_STATE_ON);
> >                 uport->ops->set_termios(uport, &termios, NULL);
> > -               if (!console_suspend_enabled && uport->ops->start_rx)
> > +               if (!console_suspend_enabled && uport->ops->start_rx) {
> > +                       spin_lock_irq(&uport->lock);
> >                         uport->ops->start_rx(uport);
> > +                       spin_unlock_irq(&uport->lock);
> > +               }
>
> Seems right, but shouldn't you also fix the call to stop_rx() that the
> same commit cfab87c2c271 ("serial: core: Introduce callback for
> start_rx and do stop_rx in suspend only if this callback
> implementation is present.") added? That one is also missing the lock,
> right?

Ah, I see. You did that in a separate patch and I wasn't CCed. I guess
I would have just put the two in one patch, but I don't feel that
strongly.

Reviewed-by: Douglas Anderson <dianders@chromium.org>
  
John Ogness May 26, 2023, 8:09 a.m. UTC | #3
On 2023-05-25, Doug Anderson <dianders@chromium.org> wrote:
>> Seems right, but shouldn't you also fix the call to stop_rx() that
>> the same commit cfab87c2c271 ("serial: core: Introduce callback for
>> start_rx and do stop_rx in suspend only if this callback
>> implementation is present.") added? That one is also missing the
>> lock, right?
>
> Ah, I see. You did that in a separate patch and I wasn't CCed. I guess
> I would have just put the two in one patch, but I don't feel that
> strongly.

Actually stop_rx() was introduced in a different commit. The commit you
reference just changed it a bit. My other patch uses a different Fixes
tag.

Also, I was concerned about packing too much new spin locking in a
single commit in the hopes it will help with any bisecting issues.

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

Thanks!

John
  

Patch

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 37ad53616372..f856c7fae2fd 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -2430,8 +2430,11 @@  int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
 		if (console_suspend_enabled)
 			uart_change_pm(state, UART_PM_STATE_ON);
 		uport->ops->set_termios(uport, &termios, NULL);
-		if (!console_suspend_enabled && uport->ops->start_rx)
+		if (!console_suspend_enabled && uport->ops->start_rx) {
+			spin_lock_irq(&uport->lock);
 			uport->ops->start_rx(uport);
+			spin_unlock_irq(&uport->lock);
+		}
 		if (console_suspend_enabled)
 			console_start(uport->cons);
 	}