serial: qcom-geni: fix receiver enable
cover serial: qcom-geni: fix receiver enable
This series is a follow-up to the console fixes that have been merged for 6.12-rc1 but that can interact badly with some pre-existing bugs.
Specifically, the receiver could end up being disabled when set_termios() races with the console code during boot.
Johan
Johan Hovold (3):
serial: qcom-geni: fix premature receiver enable
serial: qcom-geni: fix shutdown race
serial: qcom-geni: fix receiver enable
drivers/tty/serial/qcom_geni_serial.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
Signature · 1 line
2.44.2
PATCH 1/3 serial: qcom-geni: fix premature receiver enable
The receiver should no be enabled until the port is opened so drop the bogus call to start tx from the setup code which is shared with the console implementation.
This was added for some confused implementation of hibernation support, but the receiver must not be started unconditionally as the port may not have been open when hibernating the system.
--- drivers/tty/serial/qcom_geni_serial.c | 1 - 1 file changed, 1 deletion(-)
drivers/tty/serial/qcom_geni_serial.c +0 -1
@@ -1152,7 +1152,6 @@ static int qcom_geni_serial_port_setup(struct uart_port *uport) false, true, true);geni_se_init (&port->se,UART_RX_WM , port->rx_fifo_depth -2 );geni_se_select_mode (&port->se, port->dev_data->mode); -qcom_geni_serial_start_rx (uport); port->setup = true;return 0 ;
Signature · 1 line
2.44.2
PATCH 2/3 serial: qcom-geni: fix shutdown race
In reply to Johan HovoldA commit adding back the stopping of tx on port shutdown failed to add back the locking which had also been removed by commit e83766334f96 ("tty: serial: qcom_geni_serial: No need to stop tx/rx on UART shutdown").
Holding the port lock is needed to serialise against the console code, which may update the interrupt enable register and access the port state.
The call to stop rx that was added by the same commit is redundant as serial core will already have taken care of that and can thus be removed.
--- drivers/tty/serial/qcom_geni_serial.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/serial/qcom_geni_serial.c +2 -2
@@ -1096,10 +1096,10 @@ static void qcom_geni_serial_shutdown(struct uart_port *uport) {disable_irq (uport->irq); +uart_port_lock_irq (uport);qcom_geni_serial_stop_tx (uport); -qcom_geni_serial_stop_rx (uport); -qcom_geni_serial_cancel_tx_cmd (uport); +uart_port_unlock_irq (uport); }static void qcom_geni_serial_flush_buffer (struct uart_port *uport)
Signature · 1 line
2.44.2
PATCH 3/3 serial: qcom-geni: fix receiver enable
In reply to Johan HovoldThe receiver should be enabled in the startup() callback and there is no need to stop it on every termios update.
Since commit 6f3c3cafb115 ("serial: qcom-geni: disable interrupts during console writes") the calls to manipulate the secondary interrupts, which were done without holding the port lock, can lead to the receiver being left disabled when set_termios() races with the console code (e.g. when init opens the tty during boot).
--- drivers/tty/serial/qcom_geni_serial.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/tty/serial/qcom_geni_serial.c +6 -4
@@ -1167,6 +1167,11 @@ static int qcom_geni_serial_startup(struct uart_port *uport)if (ret)return ret; } + +uart_port_lock_irq (uport); +qcom_geni_serial_start_rx (uport); +uart_port_unlock_irq (uport); +enable_irq (uport->irq);return 0 ;
@@ -1252,7 +1257,6 @@ static void qcom_geni_serial_set_termios(struct uart_port *uport,unsigned int avg_bw_core;unsigned long timeout; -qcom_geni_serial_stop_rx (uport);/* baud rate */ baud =uart_get_baud_rate (uport, termios, old,300 ,4000000 );
@@ -1268,7 +1272,7 @@ static void qcom_geni_serial_set_termios(struct uart_port *uport,dev_err (port->se.dev,"Couldn't find suitable clock rate for %u\n" , baud * sampling_rate); - goto out_restart_rx; +return ; } dev_dbg(port->se.dev, "desired_rate = %u, clk_rate = %lu, clk_div = %u\n",
@@ -1359,8 +1363,6 @@ static void qcom_geni_serial_set_termios(struct uart_port *uport,writel (stop_bit_len, uport->membase +SE_UART_TX_STOP_BIT_LEN );writel (ser_clk_cfg, uport->membase +GENI_SER_M_CLK_CFG );writel (ser_clk_cfg, uport->membase +GENI_SER_S_CLK_CFG ); -out_restart_rx: -qcom_geni_serial_start_rx (uport); }#ifdef CONFIG_SERIAL_QCOM_GENI_CONSOLE
Signature · 1 line
2.44.2
Quoted 11 lines · Johan Hovold
The receiver should be enabled in the
startup()callback and there is no need to stop it on every termios update.Since commit
6f3c3cafb115("serial: qcom-geni: disable interrupts during console writes") the calls to manipulate the secondary interrupts, which were done without holding the port lock, can lead to the receiver being left disabled whenset_termios()races with the console code (e.g. when init opens the tty during boot).Fixes 6f3c3cafb115 ("serial: qcom-geni: disable interrupts during console writes")Signed-off-by Johan Hovold <[email protected]>
Turns out the DMA implementation is broken and currently depends on these bogus calls to stop and restart rx in set_termios().
I won't have time to look at this for a couple of weeks due to conferences, so please hold off on merging these until I'm back.
Johan
Re: [PATCH 2/3] serial: qcom-geni: fix shutdown race
In reply to Johan HovoldQuoted 41 lines · Johan Hovold
A commit adding back the stopping of tx on port shutdown failed to add back the locking which had also been removed by commit
e83766334f96("tty: serial:qcom_geni_serial: No need to stop tx/rx on UART shutdown").Holding the port lock is needed to serialise against the console code, which may update the interrupt enable register and access the port state.
The call to stop rx that was added by the same commit is redundant as serial core will already have taken care of that and can thus be removed.
Fixes d8aca2f96813 ("tty: serial: qcom-geni-serial: stop operations in progress at shutdown")Fixes 947cc4ecc06c ("serial: qcom-geni: fix soft lockup on sw flow control and suspend")Cc [email protected] # 6.3Cc Bartosz Golaszewski <[email protected]>Signed-off-by Johan Hovold <[email protected]>--- drivers/tty/serial/qcom_geni_serial.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/tty/serial/qcom_geni_serial.c +2
-3@@ -1096,10 +1096,10 @@ static void qcom_geni_serial_shutdown(struct uart_port *uport) {disable_irq (uport->irq); +uart_port_lock_irq (uport);qcom_geni_serial_stop_tx (uport); -qcom_geni_serial_stop_rx (uport); -qcom_geni_serial_cancel_tx_cmd (uport); +uart_port_unlock_irq (uport); }static void qcom_geni_serial_flush_buffer (struct uart_port *uport) --
Quoted 3 lines
2.44.2