From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 19E283B6C14 for ; Thu, 30 Jul 2026 08:27:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785400047; cv=none; b=ZvJwMgYI4Jc2LHomjk7aUcGt3aXpzlB2LbyBEm4L5cVdZIFkdK3n/09un8wqfCIhfJwcVdOzqIPfiVV5zo2B1CLVU/wWYWeBmrY/3+D8iLf0SrlxDZvaVlD3jBSqiS32dEd8vtKq5+r5Y2KeYr5O65Lc+fiQTM6SbY4Rv71aRCw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785400047; c=relaxed/simple; bh=pwW/HHeZcEkraoLdRbDlR2cnbN4a866QfwOfBHCrZG4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=shG9NPHNVmgGw4UT7pckplGOx5AFC0RJsIRwVFHTVX2DRaqaTCYXdIAO3M1bNOYqVL9iiaahltmsPMicF5YX88s9e9ENjIj6NJ9sBwIKZkRwpV+O7BVE+SnQ2eCBgZ+ukgK8YigvBegyGjEa37OJaatonAGdyE/h1nG4COK7Pw4= 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=QvWi4+fe; arc=none smtp.client-ip=209.85.221.43 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="QvWi4+fe" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-47362928f65so1576465f8f.2 for ; Thu, 30 Jul 2026 01:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1785400040; x=1786004840; 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=KmzU97//bt/RgXYEt4zQpFpox6tHLxvze+7qfkerEFg=; b=QvWi4+feV5TZFSt8zvTeqUgShdK/CIhQ2RnvwtlS4snWwpwrJKBtkNLEBg/7pb1+Yn RcpbfraqhLQPZBj9rUGphx8GI/qCuLsiw6v0Trdb0+byXzRu8bHnX06Xw2wTNXsZN2PI Vdqusmcp+n7nmuCrdemybwhxgZuP72jDxi90/fVZDF57mkJpdOQjx/TInoua4DlobmuC 30fftAHycEFucMJqm/nbWRfrIWV9FXqkXesvlbddBDJdw/H1OfWKBvJkgkmCe8T6lRJI jvNYX1s3/V9U6vpaOC4RE3fLXA1kATCH2gLzDCLzSXQbHDbw/Yi352cvboec43qGYa5d kg0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785400040; x=1786004840; 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=KmzU97//bt/RgXYEt4zQpFpox6tHLxvze+7qfkerEFg=; b=dnTi0pKzO0TAQiVv3QyzkbdLTsRozUrXkfD1njGK3f2g1RcKJ3v4wOZIGDofKcoGA2 4DME+I77ra3rgkNqcJDH2i+4N8WG+HiI6PK81jvPCOj6/q1owg5V9SARAd1UHclW1XAm owgPPh9HtaHeU2eC+qVBV2PLIsmCQwv1+AerMe4BRHkowyE+9ZgVC2+4m5N1jTQVVksk 9cB4j7cshHyJsPmbyi0R/0oEW2Sy7vjF20UOnUmr5TjgbzR2EE+9SimVztKP1MHkyz9s WT8m0cqeOLMsaFqQ21r0fwIvfMawlVDJdFzXrsJLSTEYbdJCYeXE7exuKcxsEdUrgk8U BIZw== X-Forwarded-Encrypted: i=1; AHgh+RpAWHstQfZC3JVwnsX04n+4iqwKDjZOaOhmMyeMs7hXFvJ7fQ7hzX34cw+W75L5QFnByA3EVahGoFrtjy0=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0ktmhsh4PWP62voeCb5gBbp7ed58Y0hi3na/422lls3PBDte7 JLFP/c7xxtDYEx6tSTyNQPF80wJ/Y0AYIc+QZLMUtSxasvMeO9Guiqnmxcn7dxDIhzU= X-Gm-Gg: AR+sD11n+MO7XRLyfIRxXPC9EFLyixX6xvctzcx/B2h7KAaNLI75k97jkgbYiu+U3dN 1e8obpnv+8VVy4dz9ShjPuSr7Beq51hh8jkSW9IOMfq5vavHmCLxy2scu9dCO+C7H829ui6M9ow ocrLFHmopVpUD/gW/DY2jRb8zp3cib2E7d6dYqMd1Ty/Ci0+qO2evE++8HSui5Zh7WnCCIMkJX7 BPCj4xAfttnSsEqeBX+Io9DV9FSAZxgrHgUOiBnBrhO9AivarxcERHGCltN/L34yg736p1oAd01 SRg7g64Q0vtlcWCbW/MbGZxFIeymURh2fgDf4/QkvM582Y3qtump1XG8FmKNmsCQtJkBxbEEjdY 116AlvL06CezaRvWik6edds98C4hcARpV1MK+tPsKZ06gtz87pw6i2/Kq0D4jw9I2N8TVfx5V3c CeOynW1ew62mStk+fY1yaF0SxiIXphb7FFLGpe3qTQyd5OMLueDs6jD6wo4KhF9s8= X-Received: by 2002:a05:6000:22ca:b0:47f:921f:3a37 with SMTP id ffacd0b85a97d-47fc81f5222mr2189848f8f.35.1785400040403; Thu, 30 Jul 2026 01:27:20 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47fc88e3c73sm4426665f8f.10.2026.07.30.01.27.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2026 01:27:19 -0700 (PDT) Date: Thu, 30 Jul 2026 10:27:17 +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 , Fushuai Wang , Kees Cook , Stepan Ionichev , linux-serial@vger.kernel.org Subject: Re: [PATCH tty v9 1/2] serial: 8250: Switch to nbcon console, take 2 Message-ID: References: <20260724103654.133654-1-john.ogness@linutronix.de> <20260724103654.133654-2-john.ogness@linutronix.de> <87o6fwms02.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: <87o6fwms02.fsf@jogness.linutronix.de> On Fri 2026-07-24 15:39:49, John Ogness wrote: > On 2026-07-24, Sashiko wrote: > >> diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c > >> index 8c241ec7f4f29..855a7aa48c2d2 100644 > >> --- a/drivers/tty/serial/8250/8250_port.c > >> +++ b/drivers/tty/serial/8250/8250_port.c > >> @@ -3198,13 +3218,28 @@ 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 console writing, enter/exit an unsafe section for each byte > >> + * in order to pass the ownership as quickly as possible if a higher > >> + * priority context wants ownership. Otherwise, an attempt to take > >> + * over the ownership might timeout. The new owner will wait for > >> + * UART_LSR_THRE before reusing the fifo. > >> + */ > >> for (i = 0; i < count; i++) { > >> + if (wctxt && !nbcon_enter_unsafe(wctxt)) > >> + return; > >> + > >> if (wait_for_lsr(up, UART_LSR_THRE)) > >> return; > > > > Does this early return on success bypass the cleanup of the unsafe > > section? > > > > If wait_for_lsr() returns true, wouldn't > > serial8250_fifo_wait_for_lsr_thre() return immediately without calling > > nbcon_exit_unsafe(wctxt)? > > > > Could this resource leak of the nbcon unsafe state prevent other > > contexts from taking over ownership? > > It simply has the effect of joining this unsafe section with the next > one. In this case it really wouldn't matter. But still, it was not my > intention. I will fix this for v10. > > How I plan for it to look for v10: > > for (i = 0; i < count; i++) { > bool tx_ready; > > if (wctxt && !nbcon_enter_unsafe(wctxt)) > return; > > tx_ready = wait_for_lsr(up, UART_LSR_THRE); > > if (wctxt) > nbcon_exit_unsafe(wctxt); > > if (tx_ready) > break; > } > > I am wondering if we should add a WARN_ON_ONCE() to nbcon_enter_unsafe() > if the context is already unsafe. It is a simple one-liner. That would > at least catch these kinds of mistakes during runtime. (I would do that > in a separate printk patch, not in this series.) Yup, makes sense. Best Regards, Petr