🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #17301

Re: [RFC] netconsole: plan for a safe atomic write

#17301
From: John Ogness
Date: Mon, 16 Nov 2026 15:52
74 lines
11859 bytes
Hi Breno,

On 2026-11-13, Breno Leitao <leitao@debian.org> wrote:
> netconsole is CON_NBCON_ATOMIC_UNSAFE, so write_atomic() only runs at
> the very end of panic. There is a desired to have called safe atomic
> printing[1].
>
> This is the plan I would like to agree on before posting patches:
>
> 1. Now that we have one console per target, use one lock per
>    console/target.
>    - printk holds the target's device_lock around write_thread(),
>      write_atomic() runs under the console ownership, and stopping
>      a target takes both. target_list_lock and the cleanup list go away:
>      the list changes under dynamic_netconsole_mutex and RTNL, and is
>      walked under either.

This synchronizes the console against itself and the user interface
(netconsole configuration). IIUC it does not provide any synchronization
against non-netconsole usage of the port.

> 2. A per-target field to track atomic writes.
>    - In that mode, skbs come only from a pool popped without a lock and
>      refilled through irq_work.

IIUC the risk here is that the garbage collector is deferred and there
may not be skbs available. In that case, what do you expect to happen?
The printk record is dropped? Or the console disables itself from printk
flushing until some (hopefully) later time when skbs are ready and it
can enable itself, thus resuming the flush?

> 3. A try-once netpoll transmit, as Jakub outlined [2]:
>    - One HARD_TX_TRYLOCK, then busy, with no polling, freeing or
>      wakeups, which can deadlock under rq->lock[3].
>    - It refuses when this CPU owns the queue (netif_tx_owned()), is in
>      the device's NAPI poll (netpoll_owner_active()), or is in NMI on
>      PREEMPT_RT.

Same question. What happens when the trylock fails or it refuses?

As I have mentioned before [4], UART atomic printing uses the console
ownership to synchronize against _all_ port activity. What if the
_xmit_lock had console ownership underneath it (only for txq's shared
with a netconsole)? Then it would be enough to acquire console
ownership.

See, for example, include/linux/serial_core.h:uart_port_trylock().

> This does not make ndo_start_xmit() safe, so the flag stays until
> drivers can opt in to atomic transmit.

IIUC it makes it safe, but not reliable. It is more reliable than
kthreads, which can still be considered a win.

> It is still unclear to me whether write_atomic() should depend on the
> context (regular NMI/panic): 
>  * For regular NMI use the try lock as best effort

HARD_TX_TRYLOCK() is not NMI-safe.

>  * Ignore the locks only in the final panic flush. (unclear if this is
>    an option)

As a final unsafe flush before an infinite loop, this is always an
option.

John

> [1] https://lore.kernel.org/all/874ie4y5mw.fsf@jogness.linutronix.de/
> [2] https://lore.kernel.org/all/20260617132127.645534d1@kernel.org/
> [3] https://lore.kernel.org/all/20260610183621.3915271-1-vlad.wing@gmail.com/

[4] https://lore.kernel.org/all/87tsr1m6y5.fsf@jogness.linutronix.de/
Technical Details
Message-ID: <87h5hgyds5.fsf@jogness.linutronix.de>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364520-linux-kernel-netdev=dewy.ru
References: <avcI9gVR7brRHQSQ@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364520-linux-kernel-netdev=dewy.ru
From: john.ogness@linutronix.de (John Ogness)
Newsgroups: linux.kernel.netdev
Subject: Re: [RFC] netconsole: plan for a safe atomic write
Date: Mon, 16 Nov 2026 16:58:26 +0106
Organization: Usenet Network
Message-ID: <87h5hgyds5.fsf@jogness.linutronix.de>
References: <avcI9gVR7brRHQSQ@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: usenet.network;
	logging-data="2103850"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:a0G6SSLf6DE2H+OIiCzqwThYshs= sha256:E6/VAGlR61OSCmR4y5XYKB/Mn5ChjunnXm9vRGjtyCg=
	sha1:MxFGXVAn8B8i2ytZptjfgLtcmsM= sha256:m8Qts/ioznxG5zegFmA1iYO0U9Y+M80mJ/b2pN2ynIo=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id C6CFA114CBF; Mon, 16 Nov 2026 18:53:18 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.518
X-Spam-Status: No, score=-2.518 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, INVALID_DATE_TZ_ABSURD=0.632,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=linutronix.de header.b=xxGaSkpO; dkim=neutral
	reason="invalid (unsupported algorithm ed25519-sha256)"
	header.d=linutronix.de header.b=bqJxEwMP
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id VTQ3AQE89Hpk;
	Mon, 16 Nov 2026 18:53:07 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-364520-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linutronix.de
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id B1B43114CB8; Mon, 16 Nov 2026 18:52:53 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 65BA7356EB; Mon, 16 Nov 2026 15:52:36 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794844350;
	b=5UIq12eS2GEODnyUXeq9FdTxbcfu7OPWiOo5mLDjU7w0sMtQVHLn/Ub4V2S9VUCGVdrD
	 DmUwnD2nzaPx9Dpoiwrc0/hMlv4do/97h7oMT6G/xj/2DhdEmRD8b7uUq8r1h4CzQHmOv
	 3A/YVy0NIVRSpaWdVMsAAWa564UVvhx/GJpSzxlwZ/psmBP3rYEMAN9i9ZdmwTPTD0hQf
	 YXDTzy+yfZ4wIknBFrbnaczB2VWM9oMGcvlbyc5l6E3Gw6h5PD2HiWY3hD2uKcl4UZ4lx
	 +ziX2Q8jFnp3fOLMIlBVvKBWG5tkmswwawxoynNETPwFOD70REL/z1PTwOWBC0CNKuA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794844350;
	h=X-Original-To:Received:DMARC-Filter:From:DKIM-Signature:
	 DKIM-Signature:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type;
	bh=WPIgPkplQXYcdgIP2HZXNUASrSQ30h2/EQrrK2TSh2g=;
	b=xJOgilw2bVaKU6ZyCg0on84ITDp4BoLjuwQQUWI6YuJNcn9HnjkV8d6zpwanwGIacOea
	 oxqEmf3QGikmQHspv7Xa1MPnYZnDtxp7rQMqvOTzFtenkYpg2HzrR4lqYOkdaGzDf7a/Z
	 yYOT2qnxaA+9f0B5Bf+iqCOodSnfTkQyDFfO1uc/IZEy3OwwiHs/5NOmdL7m/GauUzgtj
	 i9lL5bkF1k7veG4Zoz4G5uWdj3QSFn3ZwGLEy0fUi6BbVKooOhuGMHtX2Jelfnfp5Yh2e
	 HQ5njq7GKHd9upxd9FBXs9cgvEEHkKlBmkVvquc9wt/qe727ixhgwnUhJyE1SvojrZQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=xxGaSkpO;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=bqJxEwMP;
	dmarc=pass header.from=linutronix.de;
	spf=pass smtp.mailfrom=linutronix.de;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A04A606A891;
	Mon, 16 Nov 2026 15:52:30 +0000 (UTC)
X-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=xxGaSkpO;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=bqJxEwMP
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=193.142.43.55
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794844349;
	b=IrUC/Vpf2OEeIyospG46adQ4vAsdV1611fVDI2WnHBtT4DZwAKR36qg9PMtRHyAIpzIw
	 GLm8Tg21qFBlDsRI7rAXRTLVFaiZmW4CXV7ps79Ss7UyFoIHZLe66olOovR9bitSw5PFq
	 xj5yoQt1d6ogVQ3dmW3h8JWQsVojkYsJWDCknkFpgoVDDsHUzywz7FUBkTbi4q7uYrLz1
	 LnDX+JH2KZejVSadsrke8H8Q2OcG2JvaAiEdtdwuBReQO8BSl9HbkAkluc5etyEBfTkEk
	 t4XIIMOHvm2ywWKtMYd5FlskOgKhMF5+mUivIGAV3DOtGtJFEUheOmvrobNGjUZDDSA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794844349;
	h=DMARC-Filter:From:DKIM-Signature:DKIM-Signature:To:Cc:Subject:
	 In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type;
	bh=WPIgPkplQXYcdgIP2HZXNUASrSQ30h2/EQrrK2TSh2g=;
	b=ND1cdTkpqm3uwq/glFgLFs6SsoapjFhaMVNsuZtUKAT84gjm9qdIQ8gcLndh+nbOqdQK
	 2hk2ISWPo+LrtTQcGYcsq2nnm3jGRjpdHtCpWxxt8bYGZ9OZuuwxZPgihjlryomKENaqP
	 Qhx+kihiwLQ+a/C18E5eVaUVkcXpETtrWc2KfedhYQ1leNNYK0jgddjSK2AZHBKMXji/3
	 55Dh0ZH73A2gHxLhAruNs4tFluq22N4Img03i3BfExaaXbEKPYz35CV3IMMK6NNHoq39s
	 le0UsAP+NmEqR8PWtskkBsH8GFdXXelDotG8fSlfYbcZ271k3HfGYwoRrCLy4FM2A9A==
X-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=xxGaSkpO;
	dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=bqJxEwMP;
	arc=none smtp.remote-ip=193.142.43.55
X-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 2CAB3606A323;
	Mon, 16 Nov 2026 15:52:29 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2CAB3606A323
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de;
	s=2020; t=1794844347;
	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=WPIgPkplQXYcdgIP2HZXNUASrSQ30h2/EQrrK2TSh2g=;
	b=xxGaSkpOIXcLNPTFf6AkudcAhEr78jeua8vlh/m7m1mxCzy5+2QevqqUFGNwx2hkLUG8D7
	TEM5gRnnLL7STjx78ypyEgHSv1/ax2kOR1fCtMZO1dMQbgjAuAYkavj6Sy7Rhb1ouJYLe2
	tW3NR94LXsr3jmRZRUWXsWTLaDKOO5vOr/u+52EODWHl0q0ZGxxrHDPESeh7B3DDRc6Se0
	t8b5M4Ki8QbLlikW8ZmnA/oI7qUHDxc9ujiks0qXnuX+buv9kX0RKnRJn7oAK5zd2Sf3Cl
	UMPAoLtJMYY0zjt11Oea0ORMysOzGTKfGOMDZXLcgtKW0domVcJ++vWDfaC0dw==
X-DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de;
	s=2020e; t=1794844347;
	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=WPIgPkplQXYcdgIP2HZXNUASrSQ30h2/EQrrK2TSh2g=;
	b=bqJxEwMPxKYdmx2Eo+k88h/knBfiFt4y1s/FS+gZ/VQINVWcad+mfRbyLysUGRy5CiPr1A
	l3QNcb1iXzwkpIBw==
X-Cc: linux-kernel@vger.kernel.org, printk@lists.linux.dev,
 netdev@vger.kernel.org
X-In-Reply-To: <avcI9gVR7brRHQSQ@gmail.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list