From nobody Sun Feb 8 19:39:47 2026 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.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 2B82334C13B for ; Mon, 12 Jan 2026 09:41:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768210882; cv=none; b=iyTFh9+W0YxiTOWmsVwOoDPbi9Sp85G8OURpWlJkPZGI68rUKJR3BYC9NHqQtGAbGGYfc5rkJRFcE9LeNK9fsfND8Oa4k+flqbhy8W532cALriCrms7auhF13PxSXS0yt04jkSHNEklvIrIOaFJM7gOQx7aKKbB0DAHVa8F3F+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768210882; c=relaxed/simple; bh=r1PE8fDi2fMuVloDtOFpaMYOvsXBjkenyxTGboQyEIM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gDwz9afPY4RSG2P5hVv63SqIy68F6IF/sVDWDPaU4mxH56tcAnvHLp3qSv7YgqvUFz8Iqe5a4YzBZpVrUOn6LB0lgp7v7n/a17U4VweFnZYltXQLeLYRnvRy7na/8s//SvztM+NFgh5IcmbcYXVmr0A4Xa1EtfyNpSGnDPWS3h8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MdIela76; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MdIela76" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-b872f1c31f1so13899766b.0 for ; Mon, 12 Jan 2026 01:41:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768210872; x=1768815672; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=qpQJfNEVMidDJUe69qz1mLAVV7hXmHzYrjKAzwHkdw4=; b=MdIela76AAT2CYlBY7Do6dqoG1sGrlbHvVwKqjsGpEEFWWL2ec/guT9pvBZLlHmFvW HqREKgrZpCuJA0lpfRyBJFA3kW7w2dS97I1QHHSaq2xeD0xEcQj3hcGvsqUNLPIUANhs OH2TomNRQapWIKHehocVcqazrRwyanuqquVAEpRxXCyX15NnwtjrpR/A2wv2XbXyPc2t o9kD9b8OtOV9uQFQhJxvd0Xmg8D2N4N3VvP7tK0ng/XHp3WxgQ+ubRUudO+7feb9GpDA JKT5NRcqtCqUGGSFOfYSR4dLOJCL7eUPXT1L+6Lm2VCz9kyW4spGP6dM45T7vuXMU6Da hI/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768210872; x=1768815672; 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=qpQJfNEVMidDJUe69qz1mLAVV7hXmHzYrjKAzwHkdw4=; b=m0zHzh7/cr9vX2N00X5gmZJ52bChLi3BZwmpScLN3yDsttqpj/tbgNEwjTk6fIQx24 Q34LoUXMpZooPdN6XnLxyWo2V1Ji4qetfz3XhIZ3JK97gD00QDA5JCGUceg2dxWZUkid VnYC2ddBNBoIflcHqUlh5+XrI0UJwsS+pc4d9YAYRO4OE+vdYitTsicVLScujLxIjqm4 trS5IVq1UbReVE0b1UerHtVsoBxG3Pd174L7kU6pCsCWwj+Tkq4VXt6Be8fl68D2LYNy +/ptt57CboYvpOa+kZeu5+irEkJ7BxQ30jJ/M1exDg1dSRm0w7jgCTXVFb1yEN76YiNR C4Ow== X-Forwarded-Encrypted: i=1; AJvYcCWvSP6B0Fno1payjShRuBCoULrWfPVSiOs8RVZBAVMyvT7PFGBF19Ff21qlN/eHi6fX6nIVugeD8eMxxV8=@vger.kernel.org X-Gm-Message-State: AOJu0YzX3PVYFzfJAfniDR5Me83nWvamTu91u/SXgJbd/N5MXDXPyQh0 oD+uXVMnQKGGcKn70PzqvVs7R7BmokHqFXhdznSh38OaVIPkyjaxgvX6 X-Gm-Gg: AY/fxX45OM+SjwfwFbpXaBN6xnQQt463OYGoZrC2k+vFzF51hsTlvZm21xFZUACdEQ7 KsjP5aET1OknovaXgJIAd4pH4A0Y3pk4jy7fzGip2GM+/HqCr6Qgw45UlMMy0FBYTUJbayUrHPI jwtpfkbptCWMa4MxnJv0xgmvxHajUF6ma6VR3rhQHyNi+o1ZxvyugkoltDInNpO4cV7F8JVSDs/ iiUgDIfg0F89Kg8nYeiKqMPD5fcHxwOhROnPBzFn9L70NhlH3aa4B/AK7o8HBfO6eCVXNT2bBQf 78r5IOJZXQ5Oq7OaDXdrXgSc/7+ZwxOzyAjeZXwipm6tA0Hrd59tP8aVd3AFknG6aQm1KvjgKuh L6elwxjRw4BETpX8hCmSddbVMuR+zv1lkp3QFg6Pykn4OzAJnywUWsqQ0GF7MCA6jIbfqyiPVkm EGfbmU84fw6wEOkw== X-Google-Smtp-Source: AGHT+IElBQj5xgjZNMo/SofYr/1zC1dX3E6h9qPiSNrkW8u9b+CtK0Wwh85R4DKfzUJZlEY4evhbpA== X-Received: by 2002:a17:907:7296:b0:b87:19af:3e4d with SMTP id a640c23a62f3a-b8719af3f43mr222160266b.22.1768210872003; Mon, 12 Jan 2026 01:41:12 -0800 (PST) Received: from [192.168.1.243] ([143.58.192.3]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b870bcd342bsm410828766b.56.2026.01.12.01.41.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jan 2026 01:41:11 -0800 (PST) From: Andre Carvalho Date: Mon, 12 Jan 2026 09:40:57 +0000 Subject: [PATCH net-next v10 6/7] netconsole: resume previously deactivated target 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: <20260112-netcons-retrigger-v10-6-d82ebfc2503e@gmail.com> References: <20260112-netcons-retrigger-v10-0-d82ebfc2503e@gmail.com> In-Reply-To: <20260112-netcons-retrigger-v10-0-d82ebfc2503e@gmail.com> To: Breno Leitao , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan , Simon Horman Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Andre Carvalho X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1768210863; l=9836; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=r1PE8fDi2fMuVloDtOFpaMYOvsXBjkenyxTGboQyEIM=; b=tykV62ht+/NiUPNuK/wlUckVAa0RQviGHV/WkPVe4u48D/s+YWg1B9nXIYN2GmqgkfDVaS32h Y2P853khVqeA/P1AgbM6gR77O8MH5vX45ikblNlYA393q3X5EDq9Ewx X-Developer-Key: i=asantostc@gmail.com; a=ed25519; pk=eWre+RwFHCxkiaQrZLsjC67mZ/pZnzSM/f7/+yFXY4Q= Attempt to resume a previously deactivated target when the associated interface comes back (NETDEV_REGISTER) or when it changes name (NETDEV_CHANGENAME) by calling netpoll_setup on the device. Depending on how the target was setup (by mac or interface name), the corresponding field is compared with the device being brought up. Targets that match the incoming device, are scheduled for resume on a workqueue. Resuming happens on a workqueue as we can't execute netpoll_setup in the context of the netdev event. A standalone workqueue (as opposed to the global one) is used to allow for proper cleanup process during netconsole module cleanup as we need to be able to flush all pending work before traversing the target list given that targets are temporarily removed from the list during resume_target. Target transitions to STATE_DISABLED in case of failures resuming it to avoid retrying the same target indefinitely. Signed-off-by: Andre Carvalho --- drivers/net/netconsole.c | 127 +++++++++++++++++++++++++++++++++++++++++++= +--- 1 file changed, 120 insertions(+), 7 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 46d990f3d904..82c232f9ede2 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -39,6 +39,7 @@ #include #include #include +#include =20 MODULE_AUTHOR("Matt Mackall "); MODULE_DESCRIPTION("Console driver for network interfaces"); @@ -85,6 +86,8 @@ static DEFINE_SPINLOCK(target_list_lock); /* This needs to be a mutex because netpoll_cleanup might sleep */ static DEFINE_MUTEX(target_cleanup_list_lock); =20 +static struct workqueue_struct *netconsole_wq; + /* * Console driver for netconsoles. Register only consoles that have * an associated target of the same type. @@ -138,10 +141,14 @@ enum target_state { * @stats: Packet send stats for the target. Used for debugging. * @state: State of the target. * Visible from userspace (read-write). - * We maintain a strict 1:1 correspondence between this and - * whether the corresponding netpoll is active or inactive. + * From a userspace perspective, the target is either enabled or + * disabled. Internally, although both STATE_DISABLED and + * STATE_DEACTIVATED correspond to inactive targets, the latter is + * due to automatic interface state changes and will try + * recover automatically, if the interface comes back + * online. * Also, other parameters of a target may be modified at - * runtime only when it is disabled (state =3D=3D STATE_DISABLED). + * runtime only when it is disabled (state !=3D STATE_ENABLED). * @extended: Denotes whether console is extended or not. * @release: Denotes whether kernel release version should be prepended * to the message. Depends on extended console. @@ -155,6 +162,7 @@ enum target_state { * local_mac (read-only) * remote_mac (read-write) * @buf: The buffer used to send the full msg to the network stack + * @resume_wq: Workqueue to resume deactivated target */ struct netconsole_target { struct list_head list; @@ -177,6 +185,7 @@ struct netconsole_target { struct netpoll np; /* protected by target_list_lock */ char buf[MAX_PRINT_CHUNK]; + struct work_struct resume_wq; }; =20 #ifdef CONFIG_NETCONSOLE_DYNAMIC @@ -267,6 +276,70 @@ static bool bound_by_mac(struct netconsole_target *nt) return is_valid_ether_addr(nt->np.dev_mac); } =20 +/* Attempts to resume logging to a deactivated target. */ +static void resume_target(struct netconsole_target *nt) +{ + if (netpoll_setup(&nt->np)) { + /* netpoll fails setup once, do not try again. */ + nt->state =3D STATE_DISABLED; + return; + } + + nt->state =3D STATE_ENABLED; + pr_info("network logging resumed on interface %s\n", nt->np.dev_name); +} + +/* Checks if a deactivated target matches a device. */ +static bool deactivated_target_match(struct netconsole_target *nt, + struct net_device *ndev) +{ + if (nt->state !=3D STATE_DEACTIVATED) + return false; + + if (bound_by_mac(nt)) + return !memcmp(nt->np.dev_mac, ndev->dev_addr, ETH_ALEN); + return !strncmp(nt->np.dev_name, ndev->name, IFNAMSIZ); +} + +/* Process work scheduled for target resume. */ +static void process_resume_target(struct work_struct *work) +{ + struct netconsole_target *nt; + unsigned long flags; + + nt =3D container_of(work, struct netconsole_target, resume_wq); + + dynamic_netconsole_mutex_lock(); + + spin_lock_irqsave(&target_list_lock, flags); + /* Check if target is still deactivated as it may have been disabled + * while resume was being scheduled. + */ + if (nt->state !=3D STATE_DEACTIVATED) { + spin_unlock_irqrestore(&target_list_lock, flags); + goto out_unlock; + } + + /* resume_target is IRQ unsafe, remove target from + * target_list in order to resume it with IRQ enabled. + */ + list_del_init(&nt->list); + spin_unlock_irqrestore(&target_list_lock, flags); + + resume_target(nt); + + /* At this point the target is either enabled or disabled and + * was cleaned up before getting deactivated. Either way, add it + * back to target list. + */ + spin_lock_irqsave(&target_list_lock, flags); + list_add(&nt->list, &target_list); + spin_unlock_irqrestore(&target_list_lock, flags); + +out_unlock: + dynamic_netconsole_mutex_unlock(); +} + /* Allocate and initialize with defaults. * Note that these targets get their config_item fields zeroed-out. */ @@ -289,6 +362,7 @@ static struct netconsole_target *alloc_and_init(void) nt->np.remote_port =3D 6666; eth_broadcast_addr(nt->np.remote_mac); nt->state =3D STATE_DISABLED; + INIT_WORK(&nt->resume_wq, process_resume_target); =20 return nt; } @@ -1353,13 +1427,29 @@ static struct config_group *make_netconsole_target(= struct config_group *group, static void drop_netconsole_target(struct config_group *group, struct config_item *item) { - unsigned long flags; struct netconsole_target *nt =3D to_target(item); + unsigned long flags; + + dynamic_netconsole_mutex_lock(); =20 spin_lock_irqsave(&target_list_lock, flags); + /* Disable deactivated target to prevent races between resume attempt + * and target removal. + */ + if (nt->state =3D=3D STATE_DEACTIVATED) + nt->state =3D STATE_DISABLED; list_del(&nt->list); spin_unlock_irqrestore(&target_list_lock, flags); =20 + dynamic_netconsole_mutex_unlock(); + + /* Now that the target has been marked disabled no further work + * can be scheduled. Existing work will skip as targets are not + * deactivated anymore. Cancel any scheduled resume and wait for + * completion. + */ + cancel_work_sync(&nt->resume_wq); + /* * The target may have never been enabled, or was manually disabled * before being removed so netpoll may have already been cleaned up. @@ -1461,13 +1551,14 @@ static int prepare_sysdata(struct netconsole_target= *nt) static int netconsole_netdev_event(struct notifier_block *this, unsigned long event, void *ptr) { - unsigned long flags; - struct netconsole_target *nt, *tmp; struct net_device *dev =3D netdev_notifier_info_to_dev(ptr); + struct netconsole_target *nt, *tmp; bool stopped =3D false; + unsigned long flags; =20 if (!(event =3D=3D NETDEV_CHANGENAME || event =3D=3D NETDEV_UNREGISTER || - event =3D=3D NETDEV_RELEASE || event =3D=3D NETDEV_JOIN)) + event =3D=3D NETDEV_RELEASE || event =3D=3D NETDEV_JOIN || + event =3D=3D NETDEV_REGISTER)) goto done; =20 mutex_lock(&target_cleanup_list_lock); @@ -1496,6 +1587,13 @@ static int netconsole_netdev_event(struct notifier_b= lock *this, stopped =3D true; } } + if ((event =3D=3D NETDEV_REGISTER || event =3D=3D NETDEV_CHANGENAME) && + deactivated_target_match(nt, dev)) + /* Schedule resume on a workqueue as it will attempt + * to UP the device, which can't be done as part of this + * notifier. + */ + queue_work(netconsole_wq, &nt->resume_wq); netconsole_target_put(nt); } spin_unlock_irqrestore(&target_list_lock, flags); @@ -1964,6 +2062,7 @@ static struct netconsole_target *alloc_param_target(c= har *target_config, /* Cleanup netpoll for given target (from boot/module param) and free it */ static void free_param_target(struct netconsole_target *nt) { + cancel_work_sync(&nt->resume_wq); netpoll_cleanup(&nt->np); #ifdef CONFIG_NETCONSOLE_DYNAMIC kfree(nt->userdata); @@ -2018,6 +2117,12 @@ static int __init init_netconsole(void) } } =20 + netconsole_wq =3D alloc_workqueue("netconsole", WQ_UNBOUND, 0); + if (!netconsole_wq) { + err =3D -ENOMEM; + goto fail; + } + err =3D register_netdevice_notifier(&netconsole_netdev_notifier); if (err) goto fail; @@ -2040,6 +2145,8 @@ static int __init init_netconsole(void) fail: pr_err("cleaning up\n"); =20 + if (netconsole_wq) + flush_workqueue(netconsole_wq); /* * Remove all targets and destroy them (only targets created * from the boot/module option exist here). Skipping the list @@ -2050,6 +2157,9 @@ static int __init init_netconsole(void) free_param_target(nt); } =20 + if (netconsole_wq) + destroy_workqueue(netconsole_wq); + return err; } =20 @@ -2063,6 +2173,7 @@ static void __exit cleanup_netconsole(void) unregister_console(&netconsole); dynamic_netconsole_exit(); unregister_netdevice_notifier(&netconsole_netdev_notifier); + flush_workqueue(netconsole_wq); =20 /* * Targets created via configfs pin references on our module @@ -2076,6 +2187,8 @@ static void __exit cleanup_netconsole(void) list_del(&nt->list); free_param_target(nt); } + + destroy_workqueue(netconsole_wq); } =20 /* --=20 2.52.0