From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36AAD3ABD80 for ; Thu, 23 Jul 2026 11:04:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784804672; cv=none; b=GusrFIE0t1izCECdt5Em9Ppt22WtmxwbFOcnnfJ3U/tYKMsMwGwyeWYSamzj4Va/D+jyQFM0EFlOW/rbzSNEFJayTt9UqBcBSApSl2xsmMexHL1MXsCyLqw70HuCViMdycA71CbX0tm1IAahXZDx9Pv0BIkdNTgZ3B3MdGB3S8g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784804672; c=relaxed/simple; bh=I0iDornvDemZBIdlJlUN04we46aNr0QCledKevoHYbY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CnNOCmbBO3tP3ynlQpv3eqct+hHT5xmQK9Id28IYCkuLgpdOLIWZF/ZJ31JrzKpkLARdNawcSkFFbt4EzGqRtTZNumRGr8LxH6jgXbGn4CoqLu5KkqY4dYyNy4+2jZ9ZKfyuSisB+qVTE2kxgb+48JCXJJDp9CnRsayrmaGoEmo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=IjISoDPm; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="IjISoDPm" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-47f904e80eeso421848f8f.1 for ; Thu, 23 Jul 2026 04:04:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1784804665; x=1785409465; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=7vvwztE6wT0KuKjuBo21bDNTl67qEBpJJxUw15r+TGU=; b=IjISoDPm8AFFIoIqqCmrzavLJ1lqOTxZufZyVJhnFkTznKXfabja4glxJ3n/d4DmWP vBju84IhRN2nPgz1Zhd8QddYHeNmUEgJEETSqU+REpbpCIMzAkeW5fK1Q0D/kJfTbwHC 4Iby50CY+WKX1AfM0Fj2Lgd6paWY/Dh/NEZ79OvJEzaaJ278YjzhiE3N0zRW3mUlcvsg SBF4B6zVGUzA1bJWXCyq6ydn80UG/XENbtaDdElfjv9SkK9sIEgSuMCrah+uZt/rUXMG V0159pbzHm5tWXWlRnpJgqCqEqCyHzaYSpm5d245/LGtOs61T6wym3ps7FT9RuDVxj+F 6ubg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784804665; x=1785409465; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=7vvwztE6wT0KuKjuBo21bDNTl67qEBpJJxUw15r+TGU=; b=auAc2maTyfhoY4qzKLVMXXPfwRUclwyDFGv6hggClxtwg18tS0GMcinHq9cAKznSDA Qd5K0VG1JE3LF8xBrpdemDK7ZtcVZqdOcJOBdz9es9UxCNulh0TzINFSAhehhifPovdt 346Su/TgcZnqHd93Ii9+gYopGiC1xKWVb9JPMrFSO8mklEcrIyjC2GIxDzALaOdb86pm LWDjy2EJKHpdgcYpvcQAyOSEvNiz8/0iQ8N3nDsDlPExj9vUO+MjDYfkkPa+oajTL4JW Fkxe8ocxqcxAdz6a9stWCIdcqf0LyJRacA2aC+Bis7Eqey7V4KQkh7nbdBDB2ICsx809 CGEQ== X-Forwarded-Encrypted: i=1; AHgh+RqkDmABoRXcPo0hEYzlppkGz65evzVY+tttPfTn0PC+Gg5AOs/+b7RZM7TjhN2MEL8jjR4CHqh59GxMEjI=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0o0pD79WyttbArGoNk/EBjckh0qT0E9ManFPxmx75LonijEDb owrdx4GjgGiI/7F0jc6xTvmJ/whgZGjSjZK53QDhjxiMgius46hCJitvOcu0JVBlhfw= X-Gm-Gg: AR+sD13SXJdbroKDJ6eDma0SHsYkWAAxIx1h0Ue286K9zgagNUEiNoq5FMP5ugAXzn1 AGH7sJ5OwTWPE9owYAxoRJ5lazs8NF0BzP5zrgWPHO2bxDFD47o4PeumOAtUoj/f5gk9IWwUMmf e11N8PSXbjA4pfjxYa1T6mFeIaf5ytxry7AjJ8yFw865X3moSgY5O9MykyHnSi0rW0NVwkfAOo0 ge3mPeApQfSoEYndwSNEz4PWovacxV3RV2MIUVD+RMXEDiJrADzCddsLDcj48cZdKT1LGmN8mCW 8vPPYvCqZhu5kLJEu67zH9axHHViKLUCbkcH6NqK/C7nywvo10sbRGqyuZ9XGIK+ZGUvAfNZNwT xUuoJhHA/r6nob+HV8BaU0okPeKwu0No2v+5dXmighXdlkN7xD/EYSQR3El4ZVc3jQTFjqPspzh oq99ae X-Received: by 2002:a05:6000:22c7:b0:47d:f06d:55bc with SMTP id ffacd0b85a97d-47f8d7606bdmr3306146f8f.40.1784804665030; Thu, 23 Jul 2026 04:04:25 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f85c631fdsm14173457f8f.28.2026.07.23.04.04.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 04:04:24 -0700 (PDT) Date: Thu, 23 Jul 2026 13:04:21 +0200 From: Petr Mladek To: John Ogness Cc: Greg Kroah-Hartman , Jiri Slaby , Andy Shevchenko , Sebastian Andrzej Siewior , linux-kernel@vger.kernel.org, Ilpo =?iso-8859-1?Q?J=E4rvinen?= , Andy Shevchenko , Hugo Villeneuve , Stepan Ionichev , Kees Cook , Xin Zhao , linux-serial@vger.kernel.org Subject: Re: [PATCH tty v8 1/2] serial: 8250: Switch to nbcon console, take 2 Message-ID: References: <20260722110925.74387-1-john.ogness@linutronix.de> <20260722110925.74387-2-john.ogness@linutronix.de> <87v7a7cbze.fsf@jogness.linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87v7a7cbze.fsf@jogness.linutronix.de> On Wed 2026-07-22 16:59:09, John Ogness wrote: > On 2026-07-22, Sashiko wrote: > >> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c > >> index 8c241ec7f4f29..7726cca00d364 100644 > >> --- a/drivers/tty/serial/8250/8250_port.c > >> +++ b/drivers/tty/serial/8250/8250_port.c > >> @@ -3198,11 +3218,22 @@ void serial8250_set_defaults(struct uart_8250_port *up) > >> } > >> EXPORT_SYMBOL_GPL(serial8250_set_defaults); > >> > >> -void serial8250_fifo_wait_for_lsr_thre(struct uart_8250_port *up, unsigned int count) > >> +void serial8250_fifo_wait_for_lsr_thre(struct uart_8250_port *up, > >> + struct nbcon_write_context *wctxt, > >> + unsigned int count) > >> { > >> unsigned int i; > >> > >> for (i = 0; i < count; i++) { > >> + /* > >> + * Pass the ownership as quickly as possible to a higher > >> + * priority context. Otherwise, its attempt to take over > >> + * the ownership might timeout. The new owner will wait > >> + * for UART_LSR_THRE before reusing the fifo. > >> + */ > >> + if (wctxt && !nbcon_can_proceed(wctxt)) > >> + return; > >> + > >> if (wait_for_lsr(up, UART_LSR_THRE)) > >> return; > >> } > > > > Does this leave the hardware state vulnerable to corruption during an > > emergency console takeover? > > > > The serial8250_fifo_wait_for_lsr_thre() function polls the UART_LSR > > register by calling wait_for_lsr() and modifies up->lsr_saved_flags > > non-atomically. Since reading UART_LSR clears hardware error flags > > (parity, framing, overrun, break), concurrent reads can cause one CPU > > to consume and lose the flags before the other can observe them. > > > > Because serial8250_fifo_wait_for_lsr_thre() is called outside the > > nbcon_enter_unsafe() block, the nbcon system might grant a safe > > takeover to an emergency message (e.g. sysrq, panic, or NMI printk) > > preempting this loop, as it assumes no hardware access is taking > > place. The emergency writer will then access the same hardware > > registers concurrently. > > Sashiko is correct. I did not know that the serial_lsr_in() macro (used > by wait_for_lsr()) updates @lsr_saved_flags! I looked at the other > serial_lsr_in() call sites and they are all in nbcon unsafe sections. Yeah, I missed this as well. I would not expect that a function called serial_lsr_in() would do a write. But it updates the internal structure.... > The for-loop in serial8250_fifo_wait_for_lsr_thre() should look like > this: > > for (i = 0; i < count; i++) { > /* ... */ > if (wctxt && !nbcon_enter_unsafe(wctxt)) > return; > > if (wait_for_lsr(up, UART_LSR_THRE)) > return; > > if (wctxt) > nbcon_exit_unsafe(wctxt); > } LGTM. > Note that Sashiko already reported [0] this in v7, but I did not look > deep enough at that comment, thinking Sashiko was misunderstanding nbcon > ownership. Instead it was me who was misunderstanding. :-/ I was confused as well. Best Regards, Petr