From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=44.246.68.102 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796053902; b=setuqoW/vcGXlVWnggKMMlEKV6fErZrXvDoolskIJVcbxk15ebTKBkv/37aeJtrekpuG 66JyuNREijP7+z8W157u1V1EIq7sWhaq2uHCGjKCQdFRmeOSrcu6C7GZuMdt0/o0KioD3 uhxvE9ISDGLMqaQJlZT8Ky/muqgAT0mT4FtSlqSn/86+bMhAVas+uGOAuwkwgeExfwGRJ +csmk+NxjctQw2NX1qgLzPrAxrrpVqxzj3XVFH0RBvp6bAJMrHlWOE1/4jANTsY7C4m8k TbsM6ByF2sTyIV4h2W0iH6dczl/b9fUvPkLsIMH1t2SRzyIOP2inLh8Mwk8VLtryObg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796053902; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:Received:Received:X-Farcaster-Flow-ID:Received:Received: From:To:CC:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy; bh=SeDs2m9haJ7E7OUeh6l90FIX8IXf4He3wQm+lvA2iMw=; b=Ej0tF3/llXW4RzM04RfYV0mZJ+SeamZYEqGkmIt4j3lVG0UiAb91qDuI19EpbPPjjQGn C2Kr6F6gnuPOXtFb1CO+/wdD0FtDCUaYTVtwXz0TCAA3hNKKaHpis4FSXJqQ1dvj0GZ4u AvugIk9pdxcqCCf68EkrG8ia7UB62QjsoMyJMOnYavWDBsrwCNupJR91T6GICdxCCaW5a tcbShqHq3G3Q2oHgrDH/bMibaQf6qH3mKyq6BXzKwRggR0s65p8mBld2TxyNkObLOh7+o EeL6Q4D1Cweq2putIhXL5GoeM+c+1W/Sjy2lcbYgDoz20ydChALapLoAi2wfBA91oiw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass header.d=amazon.com header.i=@amazon.com header.a=rsa-sha256 header.s=amazoncorp2 header.b=JCWub8Ib; arc=none smtp.remote-ip=44.246.68.102 Received: from pdx-out-003.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-003.esa.us-west-2.outbound.mail-perimeter.amazon.com [44.246.68.102]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73D0E606A325; Mon, 30 Nov 2026 15:51:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 73D0E606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=amazon.com header.i=@amazon.com header.a=rsa-sha256 header.s=amazoncorp2 header.b=JCWub8Ib DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1796053902; x=1827589902; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=SeDs2m9haJ7E7OUeh6l90FIX8IXf4He3wQm+lvA2iMw=; b=JCWub8Ibme+WoH1kTmOs8bJ3DOgwWorO6sxU791qI20X4ndlkpnu08zC 4IFrOC6qZWSj7Ju5Wfam/VJJ3VYuUkrQp36gt9+vh0dfHD6294RcQdehA apVzbGYCtsTAzMFEx5PqUvSxp87Rgm2Tgj85aOIFoYHZcGLVsKx3RhsEI 9j2p3j1JnXGEtB0UZLSNuIghPTWk94p8ccFuwI/YF3OqD9geHniJRShyz 6yx15f3/vzAy3wiedUYZ9sLfw5OMOYtBslCjh2T3h2oaKKe9oFuFUeN3G +E36sG5hEM7n4kgt8wjOFbUQydFf6qtxbH9zwfMBIA51hTKbKiwaZylpy w==; X-CSE-ConnectionGUID: dYj464SjRx+5pIVK98w5Kg== X-CSE-MsgGUID: Dc/wIMJRTP2+b19pdbW/EQ== X-IronPort-AV: E=Sophos;i="6.27,243,1787011200"; d="scan'208";a="35404759" Received: from ip-10-5-0-115.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.0.115]) by internal-pdx-out-003.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 15:51:40 +0000 Received: from EX19MTAUWB001.ant.amazon.com [205.251.233.104:1147] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.48.218:2525] with esmtp (Farcaster) id b2b7f45f-1a2b-4ed5-9545-11d7149d2589; Mon, 30 Nov 2026 15:51:39 +0000 (UTC) X-Farcaster-Flow-ID: b2b7f45f-1a2b-4ed5-9545-11d7149d2589 Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWB001.ant.amazon.com (10.250.64.248) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.57; Mon, 30 Nov 2026 15:51:39 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.57; Mon, 30 Nov 2026 15:51:37 +0000 From: Eliav Farber To: Greg Kroah-Hartman , Jiri Slaby CC: John Ogness , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , , , , Eliav Farber Subject: [PATCH] serial: core: Don't spin for nbcon ownership with the port lock held Date: Mon, 30 Nov 2026 15:51:33 +0000 Message-ID: <20261130155133.37435-1-farbere@amazon.com> X-Mailer: git-send-email 2.47.3 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D031UWC002.ant.amazon.com (10.13.139.212) To EX19D001UWA001.ant.amazon.com (10.13.138.214) uart_port_lock() and its variants take the port lock and then spin until they own the nbcon console context, which synchronizes port->lock users against the write_atomic() callback. The context is requested at NBCON_PRIO_NORMAL, and while another CPU is in panic that request is always refused, so the spin never ends. The CPU is left holding the port lock, and in the _irq and _irqsave cases it is left with interrupts disabled, so it stops answering the stop IPI from panic(). Triggering a panic from a shell on the serial console reproduces this: a CPU enters the wrapper while the tty is transmitting and never leaves it. On an 8250 console the panic output slows to tens of milliseconds per character and never reaches the reboot. Fix this by retrying with the port lock released and interrupts restored. __uart_port_using_nbcon() is re-tested on each attempt because the console can be unregistered while the lock is dropped. A caller that already has interrupts disabled still spins, but no longer holds the port lock. This message and change were written with the help of an AI coding assistant. I reviewed everything, corrected a few things, and tested the result on arm64 hardware with an 8250 console. Fixes: 4126f149c48b ("serial: core: Acquire nbcon context in port->lock wrapper") Cc: stable@vger.kernel.org Signed-off-by: Eliav Farber --- Not for the commit log: - The spin is in the shared wrapper, so every nbcon console with a write_atomic() callback is exposed, not only 8250. Tested on 8250. My pl011 boards panic normally, and I have no hardware for the other four drivers. - The IRQs-off caller named in the commit log is not hypothetical: serial8250_handle_irq() takes the port lock through guard(uart_port_lock_check_sysrq_irqsave), in hardirq context. - This may belong in printk instead. Letting a NORMAL requester give up, or allowing direct acquires during panic, was discussed at https://lore.kernel.org/all/84frgdcgug.fsf@jogness.linutronix.de/ Happy to drop this if you prefer that route. - Tested on arm64 with a 16550A console at 115200. The panic was triggered by sysrq from a shell running on that console, so the tty was transmitting as the panic started. Before, one record took 11.8 s and the board never rebooted. After, 1.5 s from crash to "Rebooting in". A WARN that used to kill the board now prints 1172 characters in 104 ms. include/linux/serial_core.h | 38 +++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 4eeb8253752a..24d1e693d836 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -665,7 +665,15 @@ static inline bool __uart_port_using_nbcon(struct uart_port *up) return true; } -/* Only for internal port lock wrapper usage. */ +/* + * Only for internal port lock wrapper usage. + * + * The wrappers must not spin for ownership while holding the port lock. A + * request at NBCON_PRIO_NORMAL is refused for as long as another CPU is in + * panic, so the wait is unbounded. The wrappers drop the lock between + * attempts, so re-test __uart_port_using_nbcon() each time. The console can + * be unregistered while the lock is not held. + */ static inline bool __uart_port_nbcon_try_acquire(struct uart_port *up) { if (!__uart_port_using_nbcon(up)) @@ -674,16 +682,6 @@ static inline bool __uart_port_nbcon_try_acquire(struct uart_port *up) return nbcon_device_try_acquire(up->cons); } -/* Only for internal port lock wrapper usage. */ -static inline void __uart_port_nbcon_acquire(struct uart_port *up) -{ - if (!__uart_port_using_nbcon(up)) - return; - - while (!nbcon_device_try_acquire(up->cons)) - cpu_relax(); -} - /* Only for internal port lock wrapper usage. */ static inline void __uart_port_nbcon_release(struct uart_port *up) { @@ -700,7 +698,11 @@ static inline void __uart_port_nbcon_release(struct uart_port *up) static inline void uart_port_lock(struct uart_port *up) { spin_lock(&up->lock); - __uart_port_nbcon_acquire(up); + while (!__uart_port_nbcon_try_acquire(up)) { + spin_unlock(&up->lock); + cpu_relax(); + spin_lock(&up->lock); + } } /** @@ -710,7 +712,11 @@ static inline void uart_port_lock(struct uart_port *up) static inline void uart_port_lock_irq(struct uart_port *up) { spin_lock_irq(&up->lock); - __uart_port_nbcon_acquire(up); + while (!__uart_port_nbcon_try_acquire(up)) { + spin_unlock_irq(&up->lock); + cpu_relax(); + spin_lock_irq(&up->lock); + } } /** @@ -721,7 +727,11 @@ static inline void uart_port_lock_irq(struct uart_port *up) static inline void uart_port_lock_irqsave(struct uart_port *up, unsigned long *flags) { spin_lock_irqsave(&up->lock, *flags); - __uart_port_nbcon_acquire(up); + while (!__uart_port_nbcon_try_acquire(up)) { + spin_unlock_irqrestore(&up->lock, *flags); + cpu_relax(); + spin_lock_irqsave(&up->lock, *flags); + } } /** base-commit: ca20d5a011d35fc25e328fe31ac47f7aae557c5a -- 2.47.3