From nobody Tue Dec 2 02:03:31 2025 Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) (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 BB4EB348468 for ; Fri, 21 Nov 2025 11:26:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763724399; cv=none; b=tyeHRh0NLyCsgnm3HgxbGrT8Z+d47KG7WbvpK5RNSekoZJI/+prnp7z7R0YTVt7l/Lbd4bAdBRILYjmDox2hpyc76N/faepw8gM2oLLwG5kG1JHyJmyPTIYs06MK7cEx36lR9HyyoI37zHss66lgkALgu67U8Yib0mE1k3IUYVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763724399; c=relaxed/simple; bh=Up/1xSeBkB0p2W4yVcqFz2y90IusIdqbhG7Z3DkQyOM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=S3qRvcbASLQpwsp+Bdito7Aw1f8IuU+tjed3+C3Eje5KvyHu9U6zQ19hETdO7cRHz1/g4Y1y8BT61ValfbYqlIw5redrKnGg+LnID0I32xjOUclpliYnhGX+uhQcoGZGS2jJj4B3C9cZEqmMlbkC/WoOeFLVOtMD6uR/m6XWsVc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.167.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oi1-f170.google.com with SMTP id 5614622812f47-450154aa53fso771984b6e.2 for ; Fri, 21 Nov 2025 03:26:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763724397; x=1764329197; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=HeQ3fv25z6pOuPgCHIWGZAjgHMbUF84qDxUXEpKs5xA=; b=PBFVcKbadzn8iIHokjeI+vSAghXAukIluPcFdhKQLcJfYmy5+p+UiREcrOwHrwORFj oQrKjL0rqzdso7fNhzYXd60cju4zq4QrSEHvwQ1V9FrUzA+hw27pf6Y4YRRxk+7JYMkT A6mkI9LSY4k6yQIcY9uRDp0uwc3nPAeoGETVMtkM3aJV1nXE9KzLl7WVUGJYuHeP0E21 zC7BS4LGfptTKFOsz/DgHEHjKG1J+esG6QxGTr/8g8SFNiUS1UOn9f2JksgeVBm4CpBM rBeYwcnbw3UZgiC3yQsUnpd9Pd2kvsp32rR3w3K1XoUXHJ/+5NBWqYW9V7Hd47Tacfeb CcoQ== X-Forwarded-Encrypted: i=1; AJvYcCVI9bTRapiC1POfrMUWmkyqsZr/o7yX/BE/uRSrHQ5cAfgHLiuZ4ifwNTzmZPTVyj1izwFAh06c9QTYfpM=@vger.kernel.org X-Gm-Message-State: AOJu0YxDakoLi0+bUipyVF+uM9l58P6uVh0D/No9m0fVeqAyvGFi0KMa zgrF8XVtZrhPQwgEmI2XNQ7ja9OKOuwVp/hkU1x6/tJs4Vrc+DyydMnl X-Gm-Gg: ASbGncvKosV43ndExVi8sHcea3vkWIuMc4hNvmhpmqhZGFmI9cSE1ufiObR/blBw2Zq RoLyQoSgjrI6yoJFoBeW/QphmCoUSA8EfNgxbw9rHaEFNc1F1tU9lMUrKayDQF9wO3bI2DmYE0i urN+TzXDOPSVt3IIwAxtSKIS6N//INq1/TgRMHwSvjNE1O6zesIvfauRXmlc5oTjOTXBBQRc6nu o4k362kPRSIXi2bAjKQk/OEXxPg49P8BZNqBku4OM8pnZzvwmFVBtS4VF4XSSz3+3HppwPDZYNQ bgnzBc3N74+6w+YI+Mt8twa6SRG+fsiY4xSx3tsn4pOGApiKy/uscE0pkZraw4Uo5LaHNaljCo4 Fk2J0YoxErCtwRLYcXc7YLQboF4vwvS+Hc1S6YchKWaQIduEW26iE7n0GgFSxEEZ6mDWB0Dq8en AUFbzP4INHJR9VTA== X-Google-Smtp-Source: AGHT+IFJloyur0rQ9obs1zwpoSsUNIFlCUAqnRwKRBTiMrW8I69Xl0Dp8rUnZV0AbBobB8c+GozWew== X-Received: by 2002:a05:6808:4fe5:b0:44f:6d6d:4a04 with SMTP id 5614622812f47-45112cf9e04mr777367b6e.58.1763724396661; Fri, 21 Nov 2025 03:26:36 -0800 (PST) Received: from localhost ([2a03:2880:10ff:41::]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-65782a38456sm1567810eaf.3.2025.11.21.03.26.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Nov 2025 03:26:36 -0800 (PST) From: Breno Leitao Date: Fri, 21 Nov 2025 03:26:08 -0800 Subject: [PATCH RFC net-next 2/2] netconsole: add CONFIG_NETCONSOLE_NBCON for nbcon support 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251121-nbcon-v1-2-503d17b2b4af@debian.org> References: <20251121-nbcon-v1-0-503d17b2b4af@debian.org> In-Reply-To: <20251121-nbcon-v1-0-503d17b2b4af@debian.org> To: Breno Leitao , Jakub Kicinski , horms@kernel.org, efault@gmx.de, john.ogness@linutronix.de, pmladek@suse.com Cc: Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, calvin@wbinvd.org, asml.silence@gmail.com, kernel-team@meta.com, gustavold@gmail.com, asantostc@gmail.com X-Mailer: b4 0.15-dev-a6db3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4833; i=leitao@debian.org; h=from:subject:message-id; bh=Up/1xSeBkB0p2W4yVcqFz2y90IusIdqbhG7Z3DkQyOM=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBpIExoZ2WNk6LTQhAcz9lZEqVAXeRsGFwqZGYaR 1CcayasFTKJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaSBMaAAKCRA1o5Of/Hh3 bd+ZEACGDuzNg3IOH6RiePIP06/7OidbUKYcoTtMZY/n08GFE/EFxsXgvX3iJ1/5PJwz3gpLoi2 2xs0hlsJZLeBnU92MkeJJK2GcJ2XV/GzXewvnyKS048jlA9Z/FjfGL3IzR8IGeXnpJcmEPDkkyD lKZcUwc7niTGDkuwDMOHDhnH2L2NwOadwvENYdMOPtrblpYYmTYppty+7COcvPotD0Hw/uwBq65 ibcRriGq2CNxinDXa3nRbvm8BPBAsFrMggnBhhLCAceg9i+RqPCpihIzat4eBjgPxR58rqexrAt 9F7tpL0yrU2NTMtdSHK1nuJ51soZUMV81QFhbsVxZ5cxOWko89JsAHDwzRiv6b0F9UnljiMqcfx elqhJRxJofnCS8ciStv34kwFFb9aiQBITUBeTz/vXZq4IHv7A/nPnCNCTLlHyCnZ0ZMQ56M2PlG kioZXGkLLTrKAdeN2LZKzBJfCMMxgEMb6g/mmOui7T0kP5m70eqYlexNz/JvVW7QDLD9x8Au8yy GEh0TZyUUDXS5jB9V/Un6VrOAwqPEIHHNwt8YF3Us6V1Cv0Z4s4ck4ZiGJbAqZtUeVz023BbNQY /kGuSCsVSjRG8owd/mhTH0GFMtBidGXTfNL/JGZ8HXDlbNnbDUaup4vBSCrXOdgp7p0ddSX+CS8 sbihCqt0r79hccQ== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D Add optional support for the nbcon infrastructure to netconsole via a new CONFIG_NETCONSOLE_NBCON compile-time option. The nbcon infrastructure provides a lock-free, priority-based console system that supports atomic printing from any context including NMI, with safe handover mechanisms between different priority levels. This makes it particularly suitable for crash-safe kernel logging. When disabled (default), netconsole uses the legacy console callbacks, maintaining full backward compatibility. PS: .write_atomic and .write_thread uses the same callback, given that there is no safe .write_atomic, so .write_atomic is called as the last resource. This is what CON_NBCON_ATOMIC_UNSAFE is telling nbcon. Signed-off-by: Breno Leitao --- drivers/net/Kconfig | 14 ++++++++++ drivers/net/netconsole.c | 68 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 82 insertions(+) diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index ac12eaf11755..aa8771b5b723 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -369,6 +369,20 @@ config NETCONSOLE_PREPEND_RELEASE message. See for details. =20 +config NETCONSOLE_NBCON + bool "Use nbcon infrastructure (EXPERIMENTAL)" + depends on NETCONSOLE + default n + help + Enable nbcon support for netconsole. This uses the new lock-free + console infrastructure which supports threaded and atomic printing. + Given that netconsole does not support atomic operations, the current + implementation focuses on threaded callbacks, unless the host is + crashing, then it uses an unsafe atomic callbacks. This feature is + available for both extended and non-extended consoles. + + If unsure, say N to use the legacy console infrastructure. + config NETPOLL def_bool NETCONSOLE =20 diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index f4b1706fb081..2943f00b83f6 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1724,6 +1724,57 @@ static void send_ext_msg_udp(struct netconsole_targe= t *nt, const char *msg, extradata_len); } =20 +#ifdef CONFIG_NETCONSOLE_NBCON +static void netcon_write_nbcon(struct console *con, + struct nbcon_write_context *wctxt, + bool extended) +{ + struct netconsole_target *nt; + + lockdep_assert_held(&target_list_lock); + + list_for_each_entry(nt, &target_list, list) { + if (nt->extended !=3D extended || !nt->enabled || + !netif_running(nt->np.dev)) + continue; + + if (!nbcon_enter_unsafe(wctxt)) + continue; + + if (extended) + send_ext_msg_udp(nt, wctxt->outbuf, wctxt->len); + else + write_msg_target(nt, wctxt->outbuf, wctxt->len); + + nbcon_exit_unsafe(wctxt); + } +} + +static void netcon_write_nbcon_ext(struct console *con, + struct nbcon_write_context *wctxt) +{ + netcon_write_nbcon(con, wctxt, true); +} + +static void netcon_write_nbcon_basic(struct console *con, + struct nbcon_write_context *wctxt) +{ + netcon_write_nbcon(con, wctxt, false); +} + +static void netconsole_device_lock(struct console *con, unsigned long *fla= gs) +{ + /* protects all the targets at the same time */ + spin_lock_irqsave(&target_list_lock, *flags); +} + +static void netconsole_device_unlock(struct console *con, unsigned long fl= ags) +{ + spin_unlock_irqrestore(&target_list_lock, flags); +} + +#else + static void write_ext_msg(struct console *con, const char *msg, unsigned int len) { @@ -1765,6 +1816,7 @@ static void write_msg(struct console *con, const char= *msg, unsigned int len) } spin_unlock_irqrestore(&target_list_lock, flags); } +#endif =20 static int netconsole_parser_cmdline(struct netpoll *np, char *opt) { @@ -1923,14 +1975,30 @@ static void free_param_target(struct netconsole_tar= get *nt) =20 static struct console netconsole_ext =3D { .name =3D "netcon_ext", +#ifdef CONFIG_NETCONSOLE_NBCON + .flags =3D CON_ENABLED | CON_EXTENDED | CON_NBCON | CON_NBCON_ATOMIC_UNSA= FE, + .write_thread =3D netcon_write_nbcon_ext, + .write_atomic =3D netcon_write_nbcon_ext, + .device_lock =3D netconsole_device_lock, + .device_unlock =3D netconsole_device_unlock, +#else .flags =3D CON_ENABLED | CON_EXTENDED, .write =3D write_ext_msg, +#endif }; =20 static struct console netconsole =3D { .name =3D "netcon", +#ifdef CONFIG_NETCONSOLE_NBCON + .flags =3D CON_ENABLED | CON_NBCON | CON_NBCON_ATOMIC_UNSAFE, + .write_thread =3D netcon_write_nbcon_basic, + .write_atomic =3D netcon_write_nbcon_basic, + .device_lock =3D netconsole_device_lock, + .device_unlock =3D netconsole_device_unlock, +#else .flags =3D CON_ENABLED, .write =3D write_msg, +#endif }; =20 static int __init init_netconsole(void) --=20 2.47.3