* [PATCH 0/2] serial: fsl_lpuart: 8-bit FSL-LPUART driver improvements
@ 2026-11-15 18:01 Jonas Juffinger via B4 Relay
2026-11-15 18:01 ` [PATCH 1/2] serial: fsl_lpuart: Enable break detection in 8-bit driver Jonas Juffinger via B4 Relay
2026-11-15 18:01 ` [PATCH 2/2] serial: fsl_lpuart: Enable DMA for TX in console mode Jonas Juffinger via B4 Relay
0 siblings, 2 replies; 7+ messages in thread
From: Jonas Juffinger via B4 Relay @ 2026-11-15 18:01 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: linux-kernel, linux-serial, michael, sherry.sun, Jonas Juffinger
Add break detection that is currently only working in the 32-bit part of
the driver.
Enable DMA for TX when it is a console for the 8-bit part of the driver.
Signed-off-by: Jonas Juffinger <jonas.juffinger@liebherr.com>
---
Jonas Juffinger (2):
serial: fsl_lpuart: Enable break detection in 8-bit driver
serial: fsl_lpuart: Enable DMA for TX in console mode
drivers/tty/serial/fsl_lpuart.c | 35 ++++++++++++++++++++++++-----------
1 file changed, 24 insertions(+), 11 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261115-fsl_lpuart_8_bit_break_detection-8707d4334f30
Best regards,
--
Jonas Juffinger <jonas.juffinger@liebherr.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] serial: fsl_lpuart: Enable break detection in 8-bit driver
2026-11-15 18:01 [PATCH 0/2] serial: fsl_lpuart: 8-bit FSL-LPUART driver improvements Jonas Juffinger via B4 Relay
@ 2026-11-15 18:01 ` Jonas Juffinger via B4 Relay
2026-11-15 18:08 ` sashiko-bot
2026-11-16 8:12 ` Sherry Sun
2026-11-15 18:01 ` [PATCH 2/2] serial: fsl_lpuart: Enable DMA for TX in console mode Jonas Juffinger via B4 Relay
1 sibling, 2 replies; 7+ messages in thread
From: Jonas Juffinger via B4 Relay @ 2026-11-15 18:01 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: linux-kernel, linux-serial, michael, sherry.sun, Jonas Juffinger
From: Jonas Juffinger <jonas.juffinger@liebherr.com>
Add break detection in the code for the 8-bit LPUART.
The driver contains the code for the 8-bit and 32-bit LPUART device
but only the 32-bit part has working break detection. Add break
detection to the 8-bit LPUART driver.
Break detection in the 32-bit part was added with commit 5541a9bacfe5
("serial: fsl_lpuart: handle break and make sysrq work") and later fixed
with commit 707f816f2559 ("tty: serial: fsl_lpuart: correct the count of
break characters"). This patch is practically identical.
Signed-off-by: Jonas Juffinger <jonas.juffinger@liebherr.com>
---
drivers/tty/serial/fsl_lpuart.c | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index c8575c965203..5817c47e4db3 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -885,6 +885,7 @@ static void lpuart_rxint(struct lpuart_port *sport)
unsigned int flg, ignored = 0, overrun = 0;
struct tty_port *port = &sport->port.state->port;
u8 rx, sr;
+ bool is_break;
uart_port_lock(&sport->port);
@@ -898,14 +899,27 @@ static void lpuart_rxint(struct lpuart_port *sport)
sr = readb(sport->port.membase + UARTSR1);
rx = readb(sport->port.membase + UARTDR);
+ /*
+ * The LPUART can't distinguish between a break and a framing error,
+ * thus we assume it is a break if the received data is zero.
+ */
+ is_break = (sr & UARTSR1_FE) && !rx;
+
+ if (is_break && uart_handle_break(&sport->port))
+ continue;
+
if (uart_prepare_sysrq_char(&sport->port, rx))
continue;
if (sr & (UARTSR1_PE | UARTSR1_OR | UARTSR1_FE)) {
- if (sr & UARTSR1_PE)
+ if (sr & UARTSR1_PE) {
sport->port.icount.parity++;
- else if (sr & UARTSR1_FE)
- sport->port.icount.frame++;
+ } else if (sr & UARTSR1_FE) {
+ if (is_break)
+ sport->port.icount.brk++;
+ else
+ sport->port.icount.frame++;
+ }
if (sr & UARTSR1_OR)
overrun++;
@@ -918,15 +932,17 @@ static void lpuart_rxint(struct lpuart_port *sport)
sr &= sport->port.read_status_mask;
- if (sr & UARTSR1_PE)
+ if (sr & UARTSR1_PE) {
flg = TTY_PARITY;
- else if (sr & UARTSR1_FE)
- flg = TTY_FRAME;
+ } else if (sr & UARTSR1_FE) {
+ if (is_break)
+ flg = TTY_BREAK;
+ else
+ flg = TTY_FRAME;
+ }
if (sr & UARTSR1_OR)
flg = TTY_OVERRUN;
-
- sport->port.sysrq = 0;
}
if (tty_insert_flip_char(port, rx, flg) == 0)
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] serial: fsl_lpuart: Enable DMA for TX in console mode
2026-11-15 18:01 [PATCH 0/2] serial: fsl_lpuart: 8-bit FSL-LPUART driver improvements Jonas Juffinger via B4 Relay
2026-11-15 18:01 ` [PATCH 1/2] serial: fsl_lpuart: Enable break detection in 8-bit driver Jonas Juffinger via B4 Relay
@ 2026-11-15 18:01 ` Jonas Juffinger via B4 Relay
2026-11-15 18:21 ` sashiko-bot
2026-11-16 8:15 ` Sherry Sun
1 sibling, 2 replies; 7+ messages in thread
From: Jonas Juffinger via B4 Relay @ 2026-11-15 18:01 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: linux-kernel, linux-serial, michael, sherry.sun, Jonas Juffinger
From: Jonas Juffinger <jonas.juffinger@liebherr.com>
Remove the check that disabled TX DMA if the device is in console mode.
The reason for this check was that break detection cannot be efficiently
implemented with DMA. See commit 8cac2f6eb854 ("serial: fsl_lpuart:
disable DMA for console and fix sysrq").
However, break detection only affects the RX path, not the TX path.
The 8-bit LPUART hardware supports using DMA only for TX and not for RX.
I do not have a CPU with the 32-bit LPUART hardware to verify that this
change also work with the 32-bit LPUART. It probably does.
Signed-off-by: Jonas Juffinger <jonas.juffinger@liebherr.com>
---
drivers/tty/serial/fsl_lpuart.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 5817c47e4db3..e569e2c6ffe9 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -1765,9 +1765,6 @@ static void lpuart_tx_dma_startup(struct lpuart_port *sport)
u32 uartbaud;
int ret;
- if (uart_console(&sport->port))
- goto err;
-
if (!sport->dma_tx_chan)
goto err;
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] serial: fsl_lpuart: Enable break detection in 8-bit driver
2026-11-15 18:01 ` [PATCH 1/2] serial: fsl_lpuart: Enable break detection in 8-bit driver Jonas Juffinger via B4 Relay
@ 2026-11-15 18:08 ` sashiko-bot
2026-11-16 8:12 ` Sherry Sun
1 sibling, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-15 18:08 UTC (permalink / raw)
To: Jonas Juffinger; +Cc: linux-serial
> From: Jonas Juffinger <jonas.juffinger@liebherr.com>
>
> Add break detection in the code for the 8-bit LPUART.
>
> The driver contains the code for the 8-bit and 32-bit LPUART device
> but only the 32-bit part has working break detection. Add break
> detection to the 8-bit LPUART driver.
>
> Break detection in the 32-bit part was added with commit 5541a9bacfe5
> ("serial: fsl_lpuart: handle break and make sysrq work") and later fixed
> with commit 707f816f2559 ("tty: serial: fsl_lpuart: correct the count of
> break characters"). This patch is practically identical.
>
> Signed-off-by: Jonas Juffinger <jonas.juffinger@liebherr.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261115-fsl_lpuart_8_bit_break_detection-v1-0-b7ac2307dd55@liebherr.com?part=1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] serial: fsl_lpuart: Enable DMA for TX in console mode
2026-11-15 18:01 ` [PATCH 2/2] serial: fsl_lpuart: Enable DMA for TX in console mode Jonas Juffinger via B4 Relay
@ 2026-11-15 18:21 ` sashiko-bot
2026-11-16 8:15 ` Sherry Sun
1 sibling, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-15 18:21 UTC (permalink / raw)
To: Jonas Juffinger; +Cc: linux-serial
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] serial: fsl_lpuart: TX DMA race with lpuart32_console_write()
on 32-bit LPUART
- [High] serial: fsl_lpuart: UAF of dma_tx_chan in
lpuart_tx_dma_startup() on resume
- [Medium] serial: fsl_lpuart: console port.lock deadlock via dev_err()
in TX DMA paths
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] tty: serial: fsl_lpuart: double dma_release_channel() in
lpuart_remove() [1]
--
commit bca86d1a502b49317e75f113fc0d208cb42b275f
Author: Jonas Juffinger <jonas.juffinger@liebherr.com>
serial: fsl_lpuart: Enable DMA for TX in console mode
This commit removes the console port check in lpuart_tx_dma_startup() so
that TX DMA can be used on LPUART ports operating as a serial console.
> diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
> index 5817c47e4db3f..e569e2c6ffe9c 100644
> --- a/drivers/tty/serial/fsl_lpuart.c
> +++ b/drivers/tty/serial/fsl_lpuart.c
> @@ -1765,9 +1765,6 @@ static void lpuart_tx_dma_startup(struct lpuart_port *sport)
> u32 uartbaud;
> int ret;
>
> - if (uart_console(&sport->port))
> - goto err;
> -
> if (!sport->dma_tx_chan)
> goto err;
>
[Severity: High]
Can enabling TX DMA on a console port cause concurrent DMA and polled CPU
writes to the TX FIFO during console output?
On 32-bit LPUART, lpuart_tx_dma_startup() enables hardware TX DMA requests
by setting UARTBAUD_TDMAE in UARTBAUD. When printk() invokes
lpuart32_console_write(), it only masks interrupt bits in UARTCTRL and
never clears UARTBAUD_TDMAE:
drivers/tty/serial/fsl_lpuart.c:lpuart32_console_write() {
...
cr = old_cr = lpuart32_read(&sport->port, UARTCTRL);
cr |= UARTCTRL_TE | UARTCTRL_RE;
cr &= ~(UARTCTRL_TIE | UARTCTRL_TCIE | UARTCTRL_RIE);
lpuart32_write(&sport->port, cr, UARTCTRL);
uart_console_write(&sport->port, s, count, lpuart32_console_putchar);
...
}
If a TTY TX DMA transfer is in progress when console output runs, both the
DMA engine and lpuart32_console_putchar() respond to UARTSTAT_TDRE and
write to UARTDATA concurrently, corrupting serial output and potentially
overflowing the TX FIFO. On 8-bit LPUART, lpuart_console_write() clears
UARTCR2_TIE without waiting for in-flight DMA beats to finish, which
pauses active multi-byte DMA transfers mid-stream and interleaves console
characters into the TTY stream.
[Severity: High]
Does removing this check cause a use-after-free of sport->dma_tx_chan on
system resume when no_console_suspend is enabled?
When a TTY port is opened and then closed, lpuart_startup() /
lpuart32_startup() allocates sport->dma_tx_chan via lpuart_request_dma(),
and lpuart_shutdown() / lpuart32_shutdown() releases it in
lpuart_dma_shutdown() without clearing the pointer:
drivers/tty/serial/fsl_lpuart.c:lpuart_dma_shutdown() {
...
if (sport->dma_tx_chan)
dma_release_channel(sport->dma_tx_chan);
if (sport->dma_rx_chan)
dma_release_channel(sport->dma_rx_chan);
}
When console_suspend_enabled is false, lpuart_uport_is_active() returns
true for the console port even while the TTY port is closed. On resume,
lpuart_resume() calls lpuart_hw_setup() / lpuart32_hw_setup() ->
lpuart_tx_dma_startup() without calling lpuart_request_dma(). Without the
uart_console() guard, lpuart_tx_dma_startup() sees the non-NULL dangling
sport->dma_tx_chan pointer, passes it to lpuart_dma_tx_request() ->
dmaengine_slave_config(), and sets sport->lpuart_dma_tx_use = true on a
freed channel.
In addition, if the console port is open with an active TX DMA transfer
when lpuart_suspend() runs under no_console_suspend, uart_suspend_port()
returns early without draining TX, and lpuart_suspend() terminates
sport->dma_tx_chan and clears sport->dma_tx_in_progress without unmapping
sport->tx_sgl, leaking the DMA mapping.
[Severity: Medium]
Can calling dev_err() in the TX DMA error paths deadlock on
sport->port.lock when the port is a console?
lpuart_tx_dma_startup() -> lpuart_dma_tx_request() and lpuart_start_tx() /
lpuart32_start_tx() -> lpuart_dma_tx() all run under sport->port.lock:
lpuart_start_tx()
uart_port_lock_irqsave(&sport->port, &flags)
lpuart_dma_tx()
dev_err(dev, "DMA mapping error for TX.\n")
...
lpuart_console_write()
uart_port_lock_irqsave(&sport->port, &flags) <-- spins forever
If dmaengine_slave_config() fails in lpuart_dma_tx_request(), or if
dma_map_sg() or dmaengine_prep_slave_sg() fails in lpuart_dma_tx(),
dev_err() synchronously calls into the console write path and deadlocks on
sport->port.lock.
[Severity: Critical]
This problem wasn't introduced by this patch, but can lpuart_remove() call
dma_release_channel() a second time on sport->dma_tx_chan and
sport->dma_rx_chan [1]?
As noted above, lpuart_dma_shutdown() releases sport->dma_tx_chan and
sport->dma_rx_chan on port close without setting either pointer to NULL.
If the device is later unbound or the driver is unloaded, lpuart_remove()
checks those still non-NULL pointers and calls dma_release_channel() again
on the freed channels:
drivers/tty/serial/fsl_lpuart.c:lpuart_remove() {
...
if (sport->dma_tx_chan)
dma_release_channel(sport->dma_tx_chan);
if (sport->dma_rx_chan)
dma_release_channel(sport->dma_rx_chan);
...
}
Clearing sport->dma_tx_chan and sport->dma_rx_chan to NULL in
lpuart_dma_shutdown() would avoid both the double release in
lpuart_remove() and the dangling channel pointer across port close.
[1] https://sashiko.dev/#/bug/linux-4b237987-ed3a-4504-92ea-6f92bae6e727
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261115-fsl_lpuart_8_bit_break_detection-v1-0-b7ac2307dd55@liebherr.com?part=2
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH 1/2] serial: fsl_lpuart: Enable break detection in 8-bit driver
2026-11-15 18:01 ` [PATCH 1/2] serial: fsl_lpuart: Enable break detection in 8-bit driver Jonas Juffinger via B4 Relay
2026-11-15 18:08 ` sashiko-bot
@ 2026-11-16 8:12 ` Sherry Sun
1 sibling, 0 replies; 7+ messages in thread
From: Sherry Sun @ 2026-11-16 8:12 UTC (permalink / raw)
To: jonas.juffinger@liebherr.com, Greg Kroah-Hartman, Jiri Slaby
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
michael@walle.cc
> From: Jonas Juffinger <jonas.juffinger@liebherr.com>
>
> Add break detection in the code for the 8-bit LPUART.
>
> The driver contains the code for the 8-bit and 32-bit LPUART device but only
> the 32-bit part has working break detection. Add break detection to the 8-bit
> LPUART driver.
>
> Break detection in the 32-bit part was added with commit 5541a9bacfe5
> ("serial: fsl_lpuart: handle break and make sysrq work") and later fixed with
> commit 707f816f2559 ("tty: serial: fsl_lpuart: correct the count of break
> characters"). This patch is practically identical.
>
> Signed-off-by: Jonas Juffinger <jonas.juffinger@liebherr.com>
Reviewed-by: Sherry Sun <sherry.sun@nxp.com>
Best Regards
Sherry
> ---
> drivers/tty/serial/fsl_lpuart.c | 32 ++++++++++++++++++++++++--------
> 1 file changed, 24 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c index
> c8575c965203..5817c47e4db3 100644
> --- a/drivers/tty/serial/fsl_lpuart.c
> +++ b/drivers/tty/serial/fsl_lpuart.c
> @@ -885,6 +885,7 @@ static void lpuart_rxint(struct lpuart_port *sport)
> unsigned int flg, ignored = 0, overrun = 0;
> struct tty_port *port = &sport->port.state->port;
> u8 rx, sr;
> + bool is_break;
>
> uart_port_lock(&sport->port);
>
> @@ -898,14 +899,27 @@ static void lpuart_rxint(struct lpuart_port *sport)
> sr = readb(sport->port.membase + UARTSR1);
> rx = readb(sport->port.membase + UARTDR);
>
> + /*
> + * The LPUART can't distinguish between a break and a framing
> error,
> + * thus we assume it is a break if the received data is zero.
> + */
> + is_break = (sr & UARTSR1_FE) && !rx;
> +
> + if (is_break && uart_handle_break(&sport->port))
> + continue;
> +
> if (uart_prepare_sysrq_char(&sport->port, rx))
> continue;
>
> if (sr & (UARTSR1_PE | UARTSR1_OR | UARTSR1_FE)) {
> - if (sr & UARTSR1_PE)
> + if (sr & UARTSR1_PE) {
> sport->port.icount.parity++;
> - else if (sr & UARTSR1_FE)
> - sport->port.icount.frame++;
> + } else if (sr & UARTSR1_FE) {
> + if (is_break)
> + sport->port.icount.brk++;
> + else
> + sport->port.icount.frame++;
> + }
>
> if (sr & UARTSR1_OR)
> overrun++; @@ -918,15 +932,17 @@ static void
> lpuart_rxint(struct lpuart_port *sport)
>
> sr &= sport->port.read_status_mask;
>
> - if (sr & UARTSR1_PE)
> + if (sr & UARTSR1_PE) {
> flg = TTY_PARITY;
> - else if (sr & UARTSR1_FE)
> - flg = TTY_FRAME;
> + } else if (sr & UARTSR1_FE) {
> + if (is_break)
> + flg = TTY_BREAK;
> + else
> + flg = TTY_FRAME;
> + }
>
> if (sr & UARTSR1_OR)
> flg = TTY_OVERRUN;
> -
> - sport->port.sysrq = 0;
> }
>
> if (tty_insert_flip_char(port, rx, flg) == 0)
>
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH 2/2] serial: fsl_lpuart: Enable DMA for TX in console mode
2026-11-15 18:01 ` [PATCH 2/2] serial: fsl_lpuart: Enable DMA for TX in console mode Jonas Juffinger via B4 Relay
2026-11-15 18:21 ` sashiko-bot
@ 2026-11-16 8:15 ` Sherry Sun
1 sibling, 0 replies; 7+ messages in thread
From: Sherry Sun @ 2026-11-16 8:15 UTC (permalink / raw)
To: jonas.juffinger@liebherr.com, Greg Kroah-Hartman, Jiri Slaby
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
michael@walle.cc
> From: Jonas Juffinger <jonas.juffinger@liebherr.com>
>
> Remove the check that disabled TX DMA if the device is in console mode.
>
> The reason for this check was that break detection cannot be efficiently
> implemented with DMA. See commit 8cac2f6eb854 ("serial: fsl_lpuart:
> disable DMA for console and fix sysrq").
> However, break detection only affects the RX path, not the TX path.
>
> The 8-bit LPUART hardware supports using DMA only for TX and not for RX.
> I do not have a CPU with the 32-bit LPUART hardware to verify that this
> change also work with the 32-bit LPUART. It probably does.
No, it doesn't work for 32-bit LPUART, I've tested it and the console become a
mess with this change. :(
Best Regards
Sherry
>
> Signed-off-by: Jonas Juffinger <jonas.juffinger@liebherr.com>
> ---
> drivers/tty/serial/fsl_lpuart.c | 3 ---
> 1 file changed, 3 deletions(-)
>
> diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c index
> 5817c47e4db3..e569e2c6ffe9 100644
> --- a/drivers/tty/serial/fsl_lpuart.c
> +++ b/drivers/tty/serial/fsl_lpuart.c
> @@ -1765,9 +1765,6 @@ static void lpuart_tx_dma_startup(struct
> lpuart_port *sport)
> u32 uartbaud;
> int ret;
>
> - if (uart_console(&sport->port))
> - goto err;
> -
> if (!sport->dma_tx_chan)
> goto err;
>
>
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-16 8:15 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-15 18:01 [PATCH 0/2] serial: fsl_lpuart: 8-bit FSL-LPUART driver improvements Jonas Juffinger via B4 Relay
2026-11-15 18:01 ` [PATCH 1/2] serial: fsl_lpuart: Enable break detection in 8-bit driver Jonas Juffinger via B4 Relay
2026-11-15 18:08 ` sashiko-bot
2026-11-16 8:12 ` Sherry Sun
2026-11-15 18:01 ` [PATCH 2/2] serial: fsl_lpuart: Enable DMA for TX in console mode Jonas Juffinger via B4 Relay
2026-11-15 18:21 ` sashiko-bot
2026-11-16 8:15 ` Sherry Sun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox