From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=193.142.43.55 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796059688; b=ZMYrq6NVThLevmQ1W5oeoUfFczgNMTODi91dKiPlgH1j9UxKa7ECaZkqg2QlnnFoUtmy 6lA+NEOJhwpMO0XjqNoegzonuoAny/7ijSm9H8wCwdKBIH2AGUzYiR2fI04cn/bww3aGk p8aTK6HU0h5g9oqMW1C1irFgSk5IraXzXudh+/eYRmZ3nbTbLcNZsiJq4iJNGWeNJKS3R hOBGy73t8IdMEutXX7OnR+KwKZ3fnezadwV5pDll30oYW75G457qumMzT57vg2sVcwmHk Cp2T2WuZMRQsq9UXWLymWNfXSdXKVtSVrdbUChuSC+sa3AnKZF73+Fhs1f6XGH4YacQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796059688; h=DMARC-Filter:From:DKIM-Signature:DKIM-Signature:To:Cc:Subject: In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type; bh=Au69ACXKJQ7n05QQS+wLMslmY4WtRmhCY3bN81B5u9k=; b=MpOtr0P/NwpSIbGBDHOUw0oKLR8AKsh1p84YnAoTnKjK5EhabxRa9ppQ6bIbtY1gVb1h A7G8QVGiQ1Gftyo89tzwf6k0MkJxzbL4r+5mRHZpBGkXEyq0sc4ScsSUL/D6u58uRp5ZX cpWrMdTGrDLfRpkoojfNrtZipjV6DlAuQWqKBk3h/xiyEWc7STpPZ0MizFXK2qhgv227O 8bk2ixiNsaRTPdwZUhq1ohRe0mkZH4UlthyJ8VpU1UTXkeuZhXwgKPHUksp22EbySjAFh wRBvQ5uJbLWyi/zwG8wcIb7naZrsduhEKxMqJ78ULS+YDWQM3ug0SqT4LwJNnO6dOvw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=3YZzB6FB; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=5su8iCLU; arc=none smtp.remote-ip=193.142.43.55 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9049C606A320; Mon, 30 Nov 2026 17:28:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9049C606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=3YZzB6FB; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=5su8iCLU From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1796059685; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Au69ACXKJQ7n05QQS+wLMslmY4WtRmhCY3bN81B5u9k=; b=3YZzB6FB0Mq64jzPs08mxLi2Yp8h18ie+j1cd3mkZq/s1rr+W2AbAqMEGTOFuef+fxc2QJ 0cVCdL1xCTZ5HbOq8dwsrxKvoASi0i5Hq1Tr1drg9Fm5TOWCc8cymNEKGBc5BtHVcFZcen S0NQLgRO8QISaggyUGlyRXGDxm0VvExxoE2AOT7MgZtaKtxH0UePr7sjy8XfCDYWZ7iDC+ TblIjTSqlLNtB2bt9VyVoutTMx0EzkVA/v5KFtee7GnRHtk0djJoqpNvcVenQXu/5s7VF6 tCgesP2BJfLaRzV2eC0hWgndvRZHjokOKNLs80gZR/BShReBOU6Yo37kp+qpzg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1796059685; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Au69ACXKJQ7n05QQS+wLMslmY4WtRmhCY3bN81B5u9k=; b=5su8iCLUf9j+NoDWzWqZEegMdWUffbO6boeCXhH6osKAyLGIsySH0EpICYTyru1t10W57B IRW3QjYjALrFcXDw== To: Eliav Farber , Greg Kroah-Hartman , Jiri Slaby Cc: Petr Mladek , Steven Rostedt , Sergey Senozhatsky , printk@lists.linux.dev, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Eliav Farber Subject: Re: [PATCH] serial: core: Don't spin for nbcon ownership with the port lock held In-Reply-To: <20261130155133.37435-1-farbere@amazon.com> References: <20261130155133.37435-1-farbere@amazon.com> Date: Mon, 30 Nov 2026 18:34:04 +0106 Message-ID: <87zeuq1b6j.fsf@jogness.linutronix.de> 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-Type: text/plain Hi Eliav, On 2026-11-30, Eliav Farber wrote: > 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. It is always refused because it is not a reacquire. Commit 571c1ea91a73 ("printk: nbcon: Allow reacquire during panic") only considered the reacquire situation. > 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(). Right, not good. > --- > > 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. Any foreign panic that occurs between the port-lock and ownership acquire can cause this. > - 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. I do not think the reacquire fix should extend to general port locking. The idea with reacquire is that the ex-owner already has the port lock and just needs to reacquire in order to finish some important task (such as re-enabling interrupts). > 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); > + } Should these instead reuse the trylock variants? For example: static inline void uart_port_lock(struct uart_port *up) { while (!uart_port_trylock(up)) cpu_relax(); } Or perhaps in order to allow non-nbcon drivers to remain minimally affected in behavior: static inline void uart_port_lock(struct uart_port *up) { if (!__uart_port_using_nbcon(up)) { spin_lock(&up->lock); return; } while (!uart_port_trylock(up)) cpu_relax(); } The same for the irq and irqsave variants. Thoughts? John Ogness