Re: [PATCH 12/15] tty: serial: switch from circ_buf to kfifo

From: Jiri Slaby
Date: Tue Apr 16 2024 - 03:05:09 EST


Hi,

On 16. 04. 24, 5:24, Pengfei Xu wrote:
On 2024-04-05 at 08:08:23 +0200, Jiri Slaby (SUSE) wrote:
Switch from struct circ_buf to proper kfifo. kfifo provides much better
API, esp. when wrap-around of the buffer needs to be taken into account.
Look at pl011_dma_tx_refill() or cpm_uart_tx_pump() changes for example.
..
Greeting!
I used syzkaller and Internal v6.9-rc4 kernel which include Linux next kernel,
and found deadlock in console_flush_all issue, bisected the commit is:
"
1788cf6a91d9 tty: serial: switch from circ_buf to kfifo
"
..
[ 17.841628] ======================================================
[ 17.841631] WARNING: possible circular locking dependency detected
[ 17.841632] 6.9.0-rc4-df0b4fecf9eb+ #1 Not tainted
[ 17.841636] ------------------------------------------------------
[ 17.841638] repro/726 is trying to acquire lock:
[ 17.841641] ffffffff86d6da80 (console_owner){....}-{0:0}, at: console_flush_all+0x51a/0xc40
[ 17.841665]
[ 17.841665] but task is already holding lock:
[ 17.841667] ffffffff89aa52b8 (&port_lock_key){-...}-{2:2}, at: uart_put_char+0x118/0x510
[ 17.841684]
[ 17.841684] which lock already depends on the new lock.
..
[ 17.842133] stack backtrace:
..
[ 17.842461] handle_bug+0xa2/0x130
[ 17.842469] exc_invalid_op+0x3c/0x80
[ 17.842479] asm_exc_invalid_op+0x1f/0x30
[ 17.842487] RIP: 0010:uart_put_char+0x3ac/0x510

So you hit a "WARNING" (see below). And printing pretty much anything (like the WARNING report) from this point inside uart_put_char() will lead to this deadlock.

..
[ 17.879899] WARNING: CPU: 0 PID: 726 at drivers/tty/serial/serial_core.c:561 uart_put_char+0x3ac/0x510

This is the real thing/root cause of the above.

WARN_ON_ONCE(!state->port.xmit_buf)) was hit in uart_put_char().

Let me see how kfifo changed xmit_buf handling.

Hope reproduced code and bisection is helpful.

Thanks, let me investigate.

--
js
suse labs