From nobody Mon Feb 9 16:50:46 2026 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 D4870451044 for ; Tue, 20 Jan 2026 18:16:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768932973; cv=none; b=RiMqkfpkgf9TgtWpkU/Bk3czXIRtPOhwNgy4pjp3Hj6fB0gfynrMTF1/amS2SUpvozNOS8q7tWwYQGOHMjnkIGydiiAs2GT5zvDARIHSAE+pLENBShKl9d9LljiIwM3uuuchhjp6i4iZum2PmJCH/peZLdjiGKUXyUar9thRS8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768932973; c=relaxed/simple; bh=URguZv+z+GzFNe+cJ2zMPSHRjgwbLnOTJ/PrC+X4qs0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=r6hVzY7fjSHgBz5hrloKPDYAWSB2Zmrv8fY2wZFSpkfufER8ITpYwuGqpWctMrcCqfQjU+Fxjx6yt98dMN/HITR65ppuCEE5BKCVY1hFdCvlcfA+1RoK5VB3j2H+oR7WtVZJRkWcMRIVgFJJn6D1fTnsvJbFxFj7D9LwkbDd9JE= 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.210.181 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-pf1-f181.google.com with SMTP id d2e1a72fcca58-81f416c0473so4851455b3a.3 for ; Tue, 20 Jan 2026 10:16:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768932971; x=1769537771; 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=04o5YPIM/ynG9CDHLB19er8qSsbuftkYbcHCNFB6R4Q=; b=Lr27ljtx/7iVJo1CPMegjFsmQCEHg0M6Krker23rzeU7e35aP92xdl6dy7qAn1SqIc Ee2kOgS9REgHQ4yaGfqs2VNnySfDsHX3YVh0pWzxuid86px9ndddUc5eRR8KIcNc7a+5 0H1G9/cePTEn92AkNpJiyaLcmKzn3IsDviKpo4kYZRkkkak9K+wDlxGWEf9cxLTm3/5o +bRPN5VLaWkmr+1wcLU6IG1r60+aK6DZ7Qd767/ybIsXGmaZygyDGTELvGdbeutLiz7b Vus1B/mqQwEpKwYvk7T5iVQXeUg+eDhGBEuyBid6/ue3SppBm2PDLiXEo0FlcjkIFT5/ gggA== X-Forwarded-Encrypted: i=1; AJvYcCU2IjCg4jFX3yqQjQwAIaafVACsBGzpmpkV0A9ElVjltCJa/r/UT4N8IYSPCXGPyupsdPQ43fwZc9kETa0=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/dlGR/ZjhCh2tLaEnLesKaF9JuXjBrn3sKuVsvCiJ4WH6lXfR NVfHnHY89O1u013anqBx0z2iUuWCiYbZ8NAwhSiDlWPYADphlkrLsfrQNfbQqA== X-Gm-Gg: AZuq6aJF46+0bR1iZc24W7y3+08OjR8gwYtxydjpAJamaIw0yQN2HpVfNBWiJhqrkTM lI1G7qR7eBCWW6jLOaUuBH+C25rLWHCkTa32zXdZ439H6m0ZgpAXhfDy6WgD5VPd02cYe3eKHBK YOVuOLYSMpEwyxVam8RpzdHq3dmX6YnFU2ztYUKu/H6rKdZfUJgV6QWsoVrDrdZdFjuX3aoKgCu gocaUsIObD3ojq9oGnL6jjrNrupvd468L2a5owrzCZh52hgtCs9fIN4NX4j3faFbM4rewxjbGM2 /ffW/H3Ya/F/CZQ0Z7sG/dvOkIhKG3FJ5W9RFroJTbW/RnThuF2xPXeXBNvhlzKFwI+nXL8hFE/ Uyul+4945c4nEfl5dsuuF3GelvSlYHAUZisYCL8oqp4kFM8CW+/fmXwgqex+zkxyavTZHvruJQx STxg== X-Received: by 2002:a05:6808:bd1:b0:453:7a2a:62cd with SMTP id 5614622812f47-45e8aa74004mr810527b6e.50.1768926248216; Tue, 20 Jan 2026 08:24:08 -0800 (PST) Received: from localhost ([2a03:2880:10ff:53::]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4044bd5b00esm9168566fac.15.2026.01.20.08.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jan 2026 08:24:07 -0800 (PST) From: Breno Leitao Date: Tue, 20 Jan 2026 08:23:49 -0800 Subject: [PATCH net-next v2 3/5] netconsole: convert to NBCON console infrastructure 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: <20260120-nbcon-v2-3-b61f960587a8@debian.org> References: <20260120-nbcon-v2-0-b61f960587a8@debian.org> In-Reply-To: <20260120-nbcon-v2-0-b61f960587a8@debian.org> To: Breno Leitao , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , pmladek@suse.com, john.ogness@linutronix.de Cc: Greg Kroah-Hartman , Steven Rostedt , Sergey Senozhatsky , Andrew Morton , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, asantostc@gmail.com, efault@gmx.de, gustavold@gmail.com, calvin@wbinvd.org, jv@jvosburgh.net, mpdesouza@suse.com, kernel-team@meta.com X-Mailer: b4 0.15-dev-47773 X-Developer-Signature: v=1; a=openpgp-sha256; l=5459; i=leitao@debian.org; h=from:subject:message-id; bh=URguZv+z+GzFNe+cJ2zMPSHRjgwbLnOTJ/PrC+X4qs0=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBpb6widhBlttuzOawbHxAveWRni5+IZPIISE4jr 8QIE6VCjaCJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaW+sIgAKCRA1o5Of/Hh3 bWNTD/97j5o5CuRXZxOvUp9rq3WeHpW32Bs2KxnvW29M7PYhsa2Pw/c+NyqFAP0OxkfxHxeLwX+ BbBe5OlpBebjbryO0kzQdXnNlOpolQanFpaNExqtnqdqWpvhtO3DvtEefBESftjwQemUg+QCjPG aA3bpuILcNA6YZOTa10lBD2doTuh7wSO9OcWTc6ywxHwXkRdTYE9BoR3eCZ3ElVXw8V0MA9O65o PN/wcDm1njBNl+Y2h7Gs/fZDuM6mZPUJEVo5zIB02sPwv2Jhj6Jd7QZ4DgtIUlMm03n9gOwKSj2 wZEOS/XSDrTSaiFs8ZPypV/s0oHM5XVHcGsNSlu8k1qrxYgS5xLW8QNs+c+urFD6pm3nvIt+BbP YLA7RdiUYVuP1zWQHguMTm7GrLvGK9VDFsc97fn0y/OQIjGP4C/IY3uRM+hHaSRmnfaL+J5ndku 1B/OslgDhCOK+r+2wrIaGFIUpRLpSm4D/H1ucPT8LR3Nvb6ksGFvfg+F/nqnWZNToSH9uDlMA08 n7CIf0tfiWkFf/Ey/hbcGejXtQ090KBnScZyxPExEEnZ28WnPMEibrBi4Bo7JhOykoaGlsg3jpI Qzz2tMQnq+hcJ5zHsmJQwqcxuUkbxKcDIDL6VH+g47UBWRrZ1E3vneiHumEJ4WBU59teLt/VlCs zKTK06U/ezAuV7A== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D Convert netconsole from the legacy console API to the NBCON framework. NBCON provides threaded printing which unblocks printk()s and flushes in a thread, decoupling network TX from printk() when netconsole is in use. Since netconsole relies on the network stack which cannot safely operate from all atomic contexts, mark both consoles with CON_NBCON_ATOMIC_UNSAFE. (See discussion in [1]) CON_NBCON_ATOMIC_UNSAFE restricts write_atomic() usage to emergency scenarios (panic) where regular messages are sent in threaded mode. Implementation changes: - Unify write_ext_msg() and write_msg() into netconsole_write() - Add device_lock/device_unlock callbacks to manage target_list_lock - Use nbcon_enter_unsafe()/nbcon_exit_unsafe() around network operations. - If nbcon_enter_unsafe() fails, just return given netconsole lost the ownership of the console. - Set write_thread and write_atomic callbacks (both use same function) Link: https://lore.kernel.org/all/b2qps3uywhmjaym4mht2wpxul4yqtuuayeoq4iv4k= 3zf5wdgh3@tocu6c7mj4lt/ [1] Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 97 ++++++++++++++++++++++++++++++--------------= ---- 1 file changed, 60 insertions(+), 37 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index dc3bd7c9b0498..c5d7e97fe2a78 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1709,22 +1709,6 @@ static void send_ext_msg_udp(struct netconsole_targe= t *nt, const char *msg, sysdata_len); } =20 -static void write_ext_msg(struct console *con, const char *msg, - unsigned int len) -{ - struct netconsole_target *nt; - unsigned long flags; - - if ((oops_only && !oops_in_progress) || list_empty(&target_list)) - return; - - spin_lock_irqsave(&target_list_lock, flags); - list_for_each_entry(nt, &target_list, list) - if (nt->extended && nt->enabled && netif_running(nt->np.dev)) - send_ext_msg_udp(nt, msg, len); - spin_unlock_irqrestore(&target_list_lock, flags); -} - static void send_msg_udp(struct netconsole_target *nt, const char *msg, unsigned int len) { @@ -1739,29 +1723,62 @@ static void send_msg_udp(struct netconsole_target *= nt, const char *msg, } } =20 -static void write_msg(struct console *con, const char *msg, unsigned int l= en) +/** + * netconsole_write - Generic function to send a msg to all targets + * @wctxt: nbcon write context + * @extended: "true" for extended console mode + * + * Given an nbcon write context, send the message to the netconsole targets + */ +static void netconsole_write(struct nbcon_write_context *wctxt, bool exten= ded) { - unsigned long flags; struct netconsole_target *nt; =20 if (oops_only && !oops_in_progress) return; - /* Avoid taking lock and disabling interrupts unnecessarily */ - if (list_empty(&target_list)) - return; =20 - spin_lock_irqsave(&target_list_lock, flags); list_for_each_entry(nt, &target_list, list) { - if (!nt->extended && nt->enabled && netif_running(nt->np.dev)) { - /* - * We nest this inside the for-each-target loop above - * so that we're able to get as much logging out to - * at least one target if we die inside here, instead - * of unnecessarily keeping all targets in lock-step. - */ - send_msg_udp(nt, msg, len); - } + if (nt->extended !=3D extended || !nt->enabled || + !netif_running(nt->np.dev)) + continue; + + /* If nbcon_enter_unsafe() fails, just return given netconsole + * lost the ownership, and iterating over the targets will not + * be able to re-acquire. + */ + if (!nbcon_enter_unsafe(wctxt)) + return; + + if (extended) + send_ext_msg_udp(nt, wctxt->outbuf, wctxt->len); + else + send_msg_udp(nt, wctxt->outbuf, wctxt->len); + + nbcon_exit_unsafe(wctxt); } +} + +static void netconsole_write_ext(struct console *con __always_unused, + struct nbcon_write_context *wctxt) +{ + netconsole_write(wctxt, true); +} + +static void netconsole_write_basic(struct console *con __always_unused, + struct nbcon_write_context *wctxt) +{ + netconsole_write(wctxt, false); +} + +static void netconsole_device_lock(struct console *con __always_unused, + unsigned long *flags) +{ + spin_lock_irqsave(&target_list_lock, *flags); +} + +static void netconsole_device_unlock(struct console *con __always_unused, + unsigned long flags) +{ spin_unlock_irqrestore(&target_list_lock, flags); } =20 @@ -1924,15 +1941,21 @@ static void free_param_target(struct netconsole_tar= get *nt) } =20 static struct console netconsole_ext =3D { - .name =3D "netcon_ext", - .flags =3D CON_ENABLED | CON_EXTENDED, - .write =3D write_ext_msg, + .name =3D "netcon_ext", + .flags =3D CON_ENABLED | CON_EXTENDED | CON_NBCON | CON_NBCON_ATOMIC_UNSA= FE, + .write_thread =3D netconsole_write_ext, + .write_atomic =3D netconsole_write_ext, + .device_lock =3D netconsole_device_lock, + .device_unlock =3D netconsole_device_unlock, }; =20 static struct console netconsole =3D { - .name =3D "netcon", - .flags =3D CON_ENABLED, - .write =3D write_msg, + .name =3D "netcon", + .flags =3D CON_ENABLED | CON_NBCON | CON_NBCON_ATOMIC_UNSAFE, + .write_thread =3D netconsole_write_basic, + .write_atomic =3D netconsole_write_basic, + .device_lock =3D netconsole_device_lock, + .device_unlock =3D netconsole_device_unlock, }; =20 static int __init init_netconsole(void) --=20 2.47.3