From nobody Thu Oct 2 06:14:49 2025 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 5F78324DD0E for ; Sun, 21 Sep 2025 21:56:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758491782; cv=none; b=PcNYs1ZWP9PF9F5xKFisZXGR/9TF/I7LN395wJV7S40gamKwJK5+tKSEtIt30QcAGd/h1Qwl2jOqniV5hx2sYcD7u7196WmA4vgT+1vGcWaisgBgOMqDcgaeHUlpraZaltQo3S8vdfzUnY1jNx2oqW040FFN4J/yCbqJZ6Em77s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758491782; c=relaxed/simple; bh=b3zVpKcWVRzzAV4PoKPYfkAzAKs5wqpx9sDSqMK2hLM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Mb/E9gRTFO0AhjomolW/g7PuhXfHBmDmGdt/PpxIkxQhk9DL2JXra3KQCtx0Ci/wRJBUOXymqNju9oO9WZttbyav6+XfdS2AefLJZs7E9BPEkDsUatLA98byPthEXoUpgX9iAR1h9rAMzruGGMowInuJ3EFMXp1TDj3cr2HJRlM= 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=FjDEAJD9; arc=none smtp.client-ip=209.85.128.52 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="FjDEAJD9" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-45dd5e24d16so36145245e9.3 for ; Sun, 21 Sep 2025 14:56:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758491778; x=1759096578; 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=EhtGHWyefO4/6V0Mfz8aoHHvCaYrHjSgfLtudKA9GGM=; b=FjDEAJD9JBcnpD2YqE1HNJf68Kp16Nf7OIqKfiH3lZ5j9TASjXWCXnz+1MMqiPW3hQ eDQkGosQ7OSPKDuRlHw+2og2ngb0MtszLvTcwhoyHQJlP9qY527FX5g1K0OyHEJuWmum ip4jY/el2lNXz0ZN8uAQsB02RYybEwj3XDpPLqzvtS3YiJe2oLYyIR8UDgkb03jf9Rhl gjVtalOGuVb8BKVawrtn9fzbbUfvofrEsNKr6knKU29D72KavfYy6faQ09domfoSgynL 2FTN6kvzcghCfX/XcEHRyK7XbtUnTBWdnpIEJMtBoCqGe5yJK/DW6xsXvjr30mfDSSSj Rkcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758491778; x=1759096578; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EhtGHWyefO4/6V0Mfz8aoHHvCaYrHjSgfLtudKA9GGM=; b=wQC0dEXJ2D6+3KXu/fG7/LMDE0CF/olF03isk7wgRqitV8RqvMYu/fW1k83D3gmqn2 TbwVrOuZ2oTNrPdARp18DyFq3eFXZ/oZYe8CpnvoMD4o8aIc8aN9GvJ5ym5Xrh/D/r3q 8BuViWQAGWcMIa3AEj7NqC5+VwZz+hpxwxawnmUo+gdS7ex1TTpdkjyAb1YXXgyTJ5bw mARtho4JG/KPt1cC31vUevqHKBUSUTiK9ONvwD1Wfs2OJqgFtRL2lXaH240tV9ltwvf3 tAw/+3AiA9XgwSHhIne0W8Y9uAlJoj94QZIOeLLAX3BB0Wd9sEfrh8iA91g2Gzgl7uEr JQdg== X-Forwarded-Encrypted: i=1; AJvYcCXuikkE9t2yMhfceugk5w5I3gg9sOK2Bqbe2mH4dN0HgabLgKB/9P1wnoTrApHTGceO2FObVVbwYkNc450=@vger.kernel.org X-Gm-Message-State: AOJu0Yw7TeinGrYEgL6MhF7qGvtdW2U8xrIIWZNzDMhoo3N5/H7UusdL li8hRZCPySlu8qQl404OiWsmo1+0GHQxF75VKLJaXADvRGpuCuBibfTKAgA63vXN X-Gm-Gg: ASbGncvurg/CNJknc+n+8RAilI1mSO3YWLZ2UUpgiO8KFlzH0uWSEqIese2GcbIt5o8 8Lxo1zCncFmfI8KSwhoi0LqpBJ4XugtYa0x4UASkuhh/HS3PpiOkrCG8vPWv2BXmDBOPeEa3wgi 2Plcm592zSwZLoZ/Z8kSSkrN1Pw7wz5gZ+n2buraWyjLfNGQKUx5yYCq6kQ1aQLcC3BqarT0drh kPbYb5Qjb0KeYzBhPy8p0sncmmswul+jGBLTR1EIEkG4PeAHcD8iZBebq3JUHyU4RwU2HpVmun0 aNr1+WW+y7SplBMa9Zx1itCjQJoErN3+ay3nNRbMwl5SxELqFyxnrxbnVtSTt3VU36l7nywze8g uK7fBCbln+65IS/9F9MhsMjDnNew= X-Google-Smtp-Source: AGHT+IFT0qyTjpLKdlSbhcPvNOEnjMAPo5BNLKxqpXg6Yr7gdl5NTyeTy6K7cKPbDH0s64sbEvWqVQ== X-Received: by 2002:a05:600c:1d0a:b0:45d:d97c:235e with SMTP id 5b1f17b1804b1-467e75eb7c1mr99681985e9.12.1758491777778; Sun, 21 Sep 2025 14:56:17 -0700 (PDT) Received: from [192.168.1.243] ([143.58.192.81]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3f829e01a15sm5873427f8f.57.2025.09.21.14.56.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Sep 2025 14:56:17 -0700 (PDT) From: Andre Carvalho Date: Sun, 21 Sep 2025 22:55:41 +0100 Subject: [PATCH net-next v2 1/6] netconsole: add target_state enum 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: <20250921-netcons-retrigger-v2-1-a0e84006237f@gmail.com> References: <20250921-netcons-retrigger-v2-0-a0e84006237f@gmail.com> In-Reply-To: <20250921-netcons-retrigger-v2-0-a0e84006237f@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.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1758491774; l=804; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=8V6SGnkKJouMeVLTzdn4Y5ZWQGfJsCbNdTJXQi+AdQs=; b=GPUX/q1b7aI+x80Z5XhKXmAjDjPDbZN7GFNxh7sBmqOv0fRzHd9Xe9St57SEnKbucx6+t9YIp B9ffcgAWoWIDsCDTfQZq2MO4jk46AtFFsedK+33gImVrfK6MiwcQukg X-Developer-Key: i=asantostc@gmail.com; a=ed25519; pk=eWre+RwFHCxkiaQrZLsjC67mZ/pZnzSM/f7/+yFXY4Q= From: Breno Leitao Introduces a enum to track netconsole target state which is going to replace the enabled boolean. Signed-off-by: Breno Leitao Signed-off-by: Andre Carvalho --- drivers/net/netconsole.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 194570443493b1417570d3fe3250281cffe01316..b5e6a9fdc3155196d1fd7e81def= 584360ecbc3d2 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -117,6 +117,11 @@ enum sysdata_feature { SYSDATA_MSGID =3D BIT(3), }; =20 +enum target_state { + STATE_DISABLED, + STATE_ENABLED, +}; + /** * struct netconsole_target - Represents a configured netconsole target. * @list: Links this target into the target_list. --=20 2.51.0 From nobody Thu Oct 2 06:14:49 2025 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 EDF7F2D192B for ; Sun, 21 Sep 2025 21:56:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758491783; cv=none; b=e4G5RX4QUIZvU+2Z68+ZUx31FUHD2GAITNrc4idCppQNIht0cTlQCpzC3/8ZqftTxbfDGH5lphXJ/mPzMqgeg/aNNzV6C+z5ERqdVndUlxgjhdeNxBcD1lO+BNGdaIiUuGqn+fkDuybi6JWBRNtkrKxW4ojUIz79Kwz0Adz8BH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758491783; c=relaxed/simple; bh=4+rg/Gz1eysCw1FZDc5FEYkSkFXM3WUQDHMPBqpsv/g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R5JUIx76oc0zTL1W61LSl4DSPC9RQNSS/V6mz4VQhfBbE45yjMzweYV87u+/dlQVwGPPoWxrisbanZ5dc2nzk4rMNedELt9Rv21xHZTWMkV3X3Bm7FX/E/L3crb0WMJGFAZJwuV0Qs11bViG+oY2r3Xqtew86BR0l5Qfh3HlwqY= 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=CP1CopkP; arc=none smtp.client-ip=209.85.128.47 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="CP1CopkP" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-45f29dd8490so37186885e9.1 for ; Sun, 21 Sep 2025 14:56:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758491780; x=1759096580; 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=n+8+LQrrI546X3g2e/jgKl85KVqcdJ2/SBcOSdSAmgA=; b=CP1CopkPOxlL+HqMMiQkmm6c1UJFDrWB1zMUX6zdco/mtkXB4gC+g74ghnpWEDiy3O zIf8SJRwWD+luG5oD8t1tYZtdMaXOxZG45LFBYHAtaYhfV2vZdIO6PCObtp4njyxZn7t Cbq3VUXCDedFBZOPiGcl6BDG5huyCfZlo8+t5v7MF9s3FzY0ZNYDxx3oedCAGzMC+hv8 /YKYGGDzdZgHlO1LQI8YI8gqXuZGeH0Q3yNrJycPpBgpTe8MAzBdE8J0u3uh2CXkiZro 2XPWs/lxYjZ8YQHvuohUtrpXyQOIModWciDC0zN0+ib+H8Mj5ZaE1VuzbN89pJ8jTsjh HqmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758491780; x=1759096580; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n+8+LQrrI546X3g2e/jgKl85KVqcdJ2/SBcOSdSAmgA=; b=NYqWIuQmA2hVkaEy3o6bMKjOAJbaWJOcXGp+Za3N47qkrtXq0UqY38e9xaBM926YK9 1pVb2aeCX9Qhm1Iz+qBY8hdS5M35DT1Cj+CUL94iJyXHFpu0lTt1hRGZC3xvKp7XqOVA kMx8l3frNmVx0yfQ2F7zx8blUSCBrJu0gKGp3JryjT9DHqO9vYglKv+M2wE5JsX8loNy pr1a6XY4taWTowy8n2GLwCu1AXe25gyK4OcIS6BHk5Ff1sXuWSBEZ+mqtymLjKs4Yfn+ lPbEXHIGqlSlUmru8YZj/bJcF2ivGKmMEEha2Y/H//F3d1fAu2s9sKDlahaoctER/ihy LreA== X-Forwarded-Encrypted: i=1; AJvYcCUaFlOeBMnaffD2X3cQLNnWJLqrGkPXCQF1x5n0dwtAkN/EiBmHew1caoqw4xfn7hW/AFXb2oPEJhjOxY8=@vger.kernel.org X-Gm-Message-State: AOJu0YwQyZeiwM3ccW/D3i2tNRCwuRnUoAJb8rpWCsjYYTOE1Dx8UhP5 SQVrq5B3s/Q8MvEUpFuONkklJLQelqhAZW7VJ1McAth6cP1sNx00ALjJz1h+2flw X-Gm-Gg: ASbGncueRcmYXm3iq8nQw7EHGUbPp8J3I//xuLu5Y8uqzoLVKPW+p7ykY77fL9xkkfE K4E+rKwnJNLlDBwp2pkLCTds08WGhdmUY8fF18XUyREjmUnZ5SV88B18B2yweBPa31TROL1Lehw vrDqz0UP2cLYbTbikigulv6SwJ4SL8jJ1ZReOYrI2SQkoVppCJgBD9IvFqn5XO9H8TAIsLjx9TP i4XSxdJtuCyh+QDgILzp8OGLpmUxNo0xT+j3KrTH0ccRq1Ld0sv3jv8seUkl74HqvZWl5tCo1ur JAJLe+0QhY4oZ7/lQAmiTa+/gGxwJQ5x0p6XlCwmHaQlHewhLEcpLDSfSsNRrNWYvrzvKAsztt+ 6nOKutN5Ekx0w34WKyuLVotwOF/0= X-Google-Smtp-Source: AGHT+IEBttx6jQXzVxq2WSXXtU/eAlw1v+5DR7n3HJLoxuKnKWQJNg4GwSVXaN3tKB84Jri6tJMxyg== X-Received: by 2002:a05:600c:5251:b0:45b:9291:320d with SMTP id 5b1f17b1804b1-467f0b4fa71mr105315625e9.31.1758491779543; Sun, 21 Sep 2025 14:56:19 -0700 (PDT) Received: from [192.168.1.243] ([143.58.192.81]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3f829e01a15sm5873427f8f.57.2025.09.21.14.56.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Sep 2025 14:56:18 -0700 (PDT) From: Andre Carvalho Date: Sun, 21 Sep 2025 22:55:42 +0100 Subject: [PATCH net-next v2 2/6] netconsole: convert 'enabled' flag to enum for clearer state management 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: <20250921-netcons-retrigger-v2-2-a0e84006237f@gmail.com> References: <20250921-netcons-retrigger-v2-0-a0e84006237f@gmail.com> In-Reply-To: <20250921-netcons-retrigger-v2-0-a0e84006237f@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.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1758491774; l=8957; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=4+rg/Gz1eysCw1FZDc5FEYkSkFXM3WUQDHMPBqpsv/g=; b=CTuwGCtcP5yj/y0aPhAw49lJGI5ReykRrzo5RrQU0ICkoIiOdR4/h7iBEZ2aAxkxOjQQBB3rz s29oWhhbI6DCNvyOkcDAG6X6Y9Fseik8h4xAb0R4ZRohgx8sbdWoUJm X-Developer-Key: i=asantostc@gmail.com; a=ed25519; pk=eWre+RwFHCxkiaQrZLsjC67mZ/pZnzSM/f7/+yFXY4Q= This patch refactors the netconsole driver's target enabled state from a simple boolean to an explicit enum (`target_state`). This allow the states to be expanded to a new state in the upcoming change. Co-developed-by: Breno Leitao Signed-off-by: Breno Leitao Signed-off-by: Andre Carvalho --- drivers/net/netconsole.c | 52 ++++++++++++++++++++++++++------------------= ---- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index b5e6a9fdc3155196d1fd7e81def584360ecbc3d2..688ed670b37b56ab4a03d43fb3d= e94ca0e6a8360 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -132,12 +132,12 @@ enum target_state { * @sysdata_fields: Sysdata features enabled. * @msgcounter: Message sent counter. * @stats: Packet send stats for the target. Used for debugging. - * @enabled: On / off knob to enable / disable target. + * @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. * Also, other parameters of a target may be modified at - * runtime only when it is disabled (enabled =3D=3D 0). + * runtime only when it is disabled (state =3D=3D STATE_DISABLED). * @extended: Denotes whether console is extended or not. * @release: Denotes whether kernel release version should be prepended * to the message. Depends on extended console. @@ -165,7 +165,7 @@ struct netconsole_target { u32 msgcounter; #endif struct netconsole_target_stats stats; - bool enabled; + enum target_state state; bool extended; bool release; struct netpoll np; @@ -257,6 +257,7 @@ static struct netconsole_target *alloc_and_init(void) nt->np.local_port =3D 6665; nt->np.remote_port =3D 6666; eth_broadcast_addr(nt->np.remote_mac); + nt->state =3D STATE_DISABLED; =20 return nt; } @@ -275,7 +276,7 @@ static void netconsole_process_cleanups_core(void) mutex_lock(&target_cleanup_list_lock); list_for_each_entry_safe(nt, tmp, &target_cleanup_list, list) { /* all entries in the cleanup_list needs to be disabled */ - WARN_ON_ONCE(nt->enabled); + WARN_ON_ONCE(nt->state =3D=3D STATE_ENABLED); do_netpoll_cleanup(&nt->np); /* moved the cleaned target to target_list. Need to hold both * locks @@ -398,7 +399,7 @@ static void trim_newline(char *s, size_t maxlen) =20 static ssize_t enabled_show(struct config_item *item, char *buf) { - return sysfs_emit(buf, "%d\n", to_target(item)->enabled); + return sysfs_emit(buf, "%d\n", to_target(item)->state =3D=3D STATE_ENABLE= D); } =20 static ssize_t extended_show(struct config_item *item, char *buf) @@ -565,8 +566,8 @@ static ssize_t enabled_store(struct config_item *item, const char *buf, size_t count) { struct netconsole_target *nt =3D to_target(item); + bool enabled, current_enabled; unsigned long flags; - bool enabled; ssize_t ret; =20 mutex_lock(&dynamic_netconsole_mutex); @@ -575,9 +576,10 @@ static ssize_t enabled_store(struct config_item *item, goto out_unlock; =20 ret =3D -EINVAL; - if (enabled =3D=3D nt->enabled) { + current_enabled =3D nt->state =3D=3D STATE_ENABLED; + if (enabled =3D=3D current_enabled) { pr_info("network logging has already %s\n", - nt->enabled ? "started" : "stopped"); + current_enabled ? "started" : "stopped"); goto out_unlock; } =20 @@ -610,16 +612,16 @@ static ssize_t enabled_store(struct config_item *item, if (ret) goto out_unlock; =20 - nt->enabled =3D true; + nt->state =3D STATE_ENABLED; pr_info("network logging started\n"); } else { /* false */ /* We need to disable the netconsole before cleaning it up * otherwise we might end up in write_msg() with - * nt->np.dev =3D=3D NULL and nt->enabled =3D=3D true + * nt->np.dev =3D=3D NULL and nt->state =3D=3D STATE_ENABLED */ mutex_lock(&target_cleanup_list_lock); spin_lock_irqsave(&target_list_lock, flags); - nt->enabled =3D false; + nt->state =3D STATE_DISABLED; /* Remove the target from the list, while holding * target_list_lock */ @@ -648,7 +650,7 @@ static ssize_t release_store(struct config_item *item, = const char *buf, ssize_t ret; =20 mutex_lock(&dynamic_netconsole_mutex); - if (nt->enabled) { + if (nt->state =3D=3D STATE_ENABLED) { pr_err("target (%s) is enabled, disable to update parameters\n", config_item_name(&nt->group.cg_item)); ret =3D -EINVAL; @@ -675,7 +677,7 @@ static ssize_t extended_store(struct config_item *item,= const char *buf, ssize_t ret; =20 mutex_lock(&dynamic_netconsole_mutex); - if (nt->enabled) { + if (nt->state =3D=3D STATE_ENABLED) { pr_err("target (%s) is enabled, disable to update parameters\n", config_item_name(&nt->group.cg_item)); ret =3D -EINVAL; @@ -699,7 +701,7 @@ static ssize_t dev_name_store(struct config_item *item,= const char *buf, struct netconsole_target *nt =3D to_target(item); =20 mutex_lock(&dynamic_netconsole_mutex); - if (nt->enabled) { + if (nt->state =3D=3D STATE_ENABLED) { pr_err("target (%s) is enabled, disable to update parameters\n", config_item_name(&nt->group.cg_item)); mutex_unlock(&dynamic_netconsole_mutex); @@ -720,7 +722,7 @@ static ssize_t local_port_store(struct config_item *ite= m, const char *buf, ssize_t ret =3D -EINVAL; =20 mutex_lock(&dynamic_netconsole_mutex); - if (nt->enabled) { + if (nt->state =3D=3D STATE_ENABLED) { pr_err("target (%s) is enabled, disable to update parameters\n", config_item_name(&nt->group.cg_item)); goto out_unlock; @@ -742,7 +744,7 @@ static ssize_t remote_port_store(struct config_item *it= em, ssize_t ret =3D -EINVAL; =20 mutex_lock(&dynamic_netconsole_mutex); - if (nt->enabled) { + if (nt->state =3D=3D STATE_ENABLED) { pr_err("target (%s) is enabled, disable to update parameters\n", config_item_name(&nt->group.cg_item)); goto out_unlock; @@ -765,7 +767,7 @@ static ssize_t local_ip_store(struct config_item *item,= const char *buf, int ipv6; =20 mutex_lock(&dynamic_netconsole_mutex); - if (nt->enabled) { + if (nt->state =3D=3D STATE_ENABLED) { pr_err("target (%s) is enabled, disable to update parameters\n", config_item_name(&nt->group.cg_item)); goto out_unlock; @@ -790,7 +792,7 @@ static ssize_t remote_ip_store(struct config_item *item= , const char *buf, int ipv6; =20 mutex_lock(&dynamic_netconsole_mutex); - if (nt->enabled) { + if (nt->state =3D=3D STATE_ENABLED) { pr_err("target (%s) is enabled, disable to update parameters\n", config_item_name(&nt->group.cg_item)); goto out_unlock; @@ -839,7 +841,7 @@ static ssize_t remote_mac_store(struct config_item *ite= m, const char *buf, ssize_t ret =3D -EINVAL; =20 mutex_lock(&dynamic_netconsole_mutex); - if (nt->enabled) { + if (nt->state =3D=3D STATE_ENABLED) { pr_err("target (%s) is enabled, disable to update parameters\n", config_item_name(&nt->group.cg_item)); goto out_unlock; @@ -1315,7 +1317,7 @@ static void drop_netconsole_target(struct config_grou= p *group, * The target may have never been enabled, or was manually disabled * before being removed so netpoll may have already been cleaned up. */ - if (nt->enabled) + if (nt->state =3D=3D STATE_ENABLED) netpoll_cleanup(&nt->np); =20 config_item_put(&nt->group.cg_item); @@ -1444,7 +1446,7 @@ static int netconsole_netdev_event(struct notifier_bl= ock *this, case NETDEV_RELEASE: case NETDEV_JOIN: case NETDEV_UNREGISTER: - nt->enabled =3D false; + nt->state =3D STATE_DISABLED; list_move(&nt->list, &target_cleanup_list); stopped =3D true; } @@ -1711,7 +1713,8 @@ static void write_ext_msg(struct console *con, const = char *msg, =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)) + if (nt->extended && nt->state =3D=3D STATE_ENABLED && + netif_running(nt->np.dev)) send_ext_msg_udp(nt, msg, len); spin_unlock_irqrestore(&target_list_lock, flags); } @@ -1731,7 +1734,8 @@ static void write_msg(struct console *con, const char= *msg, unsigned int len) =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)) { + if (!nt->extended && nt->state =3D=3D STATE_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 @@ -1887,7 +1891,7 @@ static struct netconsole_target *alloc_param_target(c= har *target_config, */ goto fail; } else { - nt->enabled =3D true; + nt->state =3D STATE_ENABLED; } populate_configfs_item(nt, cmdline_count); =20 --=20 2.51.0 From nobody Thu Oct 2 06:14:49 2025 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 359F62D73BB for ; Sun, 21 Sep 2025 21:56:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758491786; cv=none; b=WkANr9WIT2SPqbHW6fxgUHdE15VCXQhVQjt1CaIAwSBpx/uaKVq3SMWEGvdmEA3i1AKjal2qUOfcwXOqvlW1z48znt/fQOXWEsTcqXT34voQ8Lw2PztxFg6V9xlmaUX+Sx4oJ8a1hZf0uZ6AYxZTWgH73NkW+83ALpWi9eB6+M0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758491786; c=relaxed/simple; bh=5mhr6jsCmNwNcnFO+5SOJs2r7HZGP3JEvC2ipj5IjA4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=geZ8rqHB7GM+NnqLSQrYWIwRtYbavrXbEdlqqxkgtJ5ivqfzIVNNRlrLcCx9pmJypxt3WaS5EdT1rcH+u/uvbyyc7e2+Xucf2FZ/iLv0yEkM+qws+nGQdsO1tFc1+adfpkWAkD04wzkrvYvxYhb0I2PfgIrwTkZeuQSS/MGXB2s= 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=exP9qs56; arc=none smtp.client-ip=209.85.221.48 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="exP9qs56" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-3f0ae439bc3so1206659f8f.1 for ; Sun, 21 Sep 2025 14:56:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758491781; x=1759096581; 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=LIdf/p+W7Ujz2zhxctFos5mKw5BeHeIDmEYf9Zo81XM=; b=exP9qs56EheJ0KTyavSfU4CutrSm3AZGDYNksp9wcRVQqwpjuPXEnbFGpsTif0XOEj u97F3L0MneGN2XahP07v54YBvcxyxGbmYw/75jwiwHV+w0EOroaskCGD690GBiUbGzkJ JIL8Xy0qpxzObRNfNLDW0vCq/cdIRvXpQK+y6n9ilojXJqZ1ECqbG4spQPEJl/hb7qav 2mKXShJ2Q9Ya4KmLyDf5/k+8ahg+CYkbqOkVIfni//AtjW1mSMPdk89XzTWPAk6XaYHS gODsMJwC5Bx019xmpU98NUsm2DYteFt7Bh1KFUZXnB7baUF2oBc/Zi+I/vm0GT8YNTxQ VTxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758491781; x=1759096581; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LIdf/p+W7Ujz2zhxctFos5mKw5BeHeIDmEYf9Zo81XM=; b=BEuBg0snqb9PRPe9jDc3tg7UuJCWtZnPyogIFe00kXTfwIiXCqjyA0mB1U6GTn795u a9/+iw+EE/DffDuA4yxMRjRvEKDocit4j88eava9JvjkuSeMPfJWQw8sRsZF/wcJr1cN sOEzx3mQC4fTnYJcqHNnGtv+O9XaT57yEUQACGTw0wYfoL/O3HhzRSEKFS5trYKyNnqU L/rI6idoBeGbZFnEVRUnwEdoXIewMy0r9kr9+3Ij9KHf8SOYXfV3VzPvKiwJI7vie40J xKuY7Err28AY5xbHd+NAf/2hZ8PiwpTskn5tj1HGLsIG0sqek4LcQzZB8sw2kl9gLywg pAkw== X-Forwarded-Encrypted: i=1; AJvYcCVoRExaBq+V+E6ea0d3hQlcjAjlpJxIL11Bs69/doTEs7P/oSbKS341hQLgWcu/H2Dx2QNVK5V8QOR6vmE=@vger.kernel.org X-Gm-Message-State: AOJu0YylPrPlLtc0oeudQuE7pIBMRy3nUxYCSDnQHP2giFM6jxDE37HJ BpFEV/UmUE0uiKXViprZET2T1tAnroyVXNL0smJWHokiyCuJk+UhShDQrWMSJktC X-Gm-Gg: ASbGncurTDHBrOCW1Y9dnxmaN4PUJc/+pc9j+k8wE/HmjTQ7rfRXzkWBE5Xyw+QaimG tKoGiGsTf+bOaqHuKn8q6H8N8HHYfB6XmSzspHhaWp1vd4XW0i8/GgJWHYSs5tJp9t9iN8ipuo7 O//uTXCmNxtEdiXF+9YqPxCRt5RRVkPlG8XmoKy68QG6GXu3qRI4laVr1py4meaH0m7v0e7omR1 0qh3wMWSGp/4pXaUyeYKMegEsM1B0q0LDJ3V9WvuXZmWnSvuocfVneodCoFvVNwtlMlHBy/nU8r erAPxgX3dWoXPdS91KXpz274nYFRqOg2tEsOo+8sXtAUXThBv79v2xRzGlJK6y1VHg3B89CL/7P b+ICDCpe3We7KS3UVGuMRp2mG01M= X-Google-Smtp-Source: AGHT+IGmt6XLl3zQskh0zYm6CtZaqKN29aHDDxgwtm82G8MAOnuWyw277HU2wC6kT7gu0jDroko1Iw== X-Received: by 2002:a05:6000:604:b0:3ea:80ec:8552 with SMTP id ffacd0b85a97d-3ee87327999mr8985604f8f.57.1758491781147; Sun, 21 Sep 2025 14:56:21 -0700 (PDT) Received: from [192.168.1.243] ([143.58.192.81]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3f829e01a15sm5873427f8f.57.2025.09.21.14.56.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Sep 2025 14:56:20 -0700 (PDT) From: Andre Carvalho Date: Sun, 21 Sep 2025 22:55:43 +0100 Subject: [PATCH net-next v2 3/6] netconsole: add STATE_DEACTIVATED to track targets disabled by low level 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: <20250921-netcons-retrigger-v2-3-a0e84006237f@gmail.com> References: <20250921-netcons-retrigger-v2-0-a0e84006237f@gmail.com> In-Reply-To: <20250921-netcons-retrigger-v2-0-a0e84006237f@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.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1758491774; l=2084; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=WsXzbr4oh2tgdkoPqzROUayYBAGNEehpMnq5WhfJccU=; b=LhIkGrcYxDjv8+RfVaEAQ724BmARmMrU8Kdv7X/xIwney+vtPBHaNAwvzpolmZrkvi0FXESSg D+YOAd9sg0IBqJ2kuYBNebJb9FcO7xuXnyWVV4iCp34zyq0e4cZ4Wn9 X-Developer-Key: i=asantostc@gmail.com; a=ed25519; pk=eWre+RwFHCxkiaQrZLsjC67mZ/pZnzSM/f7/+yFXY4Q= From: Breno Leitao When the low level interface brings a netconsole target down, record this using a new STATE_DEACTIVATED state. This allows netconsole to distinguish between targets explicitly disabled by users and those deactivated due to interface state changes. It also enables automatic recovery and re-enabling of targets if the underlying low-level interfaces come back online. From a code perspective, anything that is not STATE_ENABLED is disabled. Mark the device that is down due to NETDEV_UNREGISTER as STATE_DEACTIVATED, this, should be the same as STATE_DISABLED from a code perspective. Signed-off-by: Breno Leitao Signed-off-by: Andre Carvalho --- drivers/net/netconsole.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 688ed670b37b56ab4a03d43fb3de94ca0e6a8360..59d770bb4baa5f9616b10c0dfb3= 9ed45a4eb7710 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -120,6 +120,7 @@ enum sysdata_feature { enum target_state { STATE_DISABLED, STATE_ENABLED, + STATE_DEACTIVATED, }; =20 /** @@ -575,6 +576,14 @@ static ssize_t enabled_store(struct config_item *item, if (ret) goto out_unlock; =20 + /* When the user explicitly enables or disables a target that is + * currently deactivated, reset its state to disabled. The DEACTIVATED + * state only tracks interface-driven deactivation and should _not_ + * persist when the user manually changes the target's enabled state. + */ + if (nt->state =3D=3D STATE_DEACTIVATED) + nt->state =3D STATE_DISABLED; + ret =3D -EINVAL; current_enabled =3D nt->state =3D=3D STATE_ENABLED; if (enabled =3D=3D current_enabled) { @@ -1446,7 +1455,7 @@ static int netconsole_netdev_event(struct notifier_bl= ock *this, case NETDEV_RELEASE: case NETDEV_JOIN: case NETDEV_UNREGISTER: - nt->state =3D STATE_DISABLED; + nt->state =3D STATE_DEACTIVATED; list_move(&nt->list, &target_cleanup_list); stopped =3D true; } --=20 2.51.0 From nobody Thu Oct 2 06:14:49 2025 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 85F812D7804 for ; Sun, 21 Sep 2025 21:56:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758491786; cv=none; b=EYQzDFnd8QzeoAM9JH6UVjLEtcSmYKUo2IDuHWK4MlKRzuLuhmAXZxZfLlGnj5ejhVWbWIbytFIJoVu8/wgBHqh+0YbnzcoYhe+8Kp2Omgggw9plJcp3BP25oHENwafEoT8laxxrl13y5AdeqTZLtxwXkYnWDdDQr7odQYDpSa4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758491786; c=relaxed/simple; bh=yUxPsW1neulTDSc12DrjlnnLI2RxeIiDkeTBPbs2djs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l1z84+6pHKVVBSeo58oEdq5pY1YC/a0oJDlsAj0mZ/pLJ0PEV6PSuHa077gNLEZ5g6xyFjFlp5cPAzwt7Q74IAFRpKUzGpluVJUbbndzQL2GfEpahDmR+iyEg7FpCKjRaIAlQrIjlQa1JkcMIezAhM5GGGTzH7HhtIssNjDAzOo= 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=GruyAGKO; arc=none smtp.client-ip=209.85.221.51 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="GruyAGKO" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-3f2ae6fadb4so1764486f8f.1 for ; Sun, 21 Sep 2025 14:56:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758491782; x=1759096582; 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=bOfYi+evOXJssk3GreSh96Tr6S4alFUvF1o54q0ZtXY=; b=GruyAGKOwZLIpP4Lc160v/7prT9B6kNgcOT4tIIhXx6TFVygu2OwKIu3ZUexPLXQE2 wnBrv2LSC7d56narxHMSRFXDQbiXNJhuFQRPSIYdhuE649cwYnE3WWiBqC9jeu5fCi5v 9LAdWS3kwIwpesjX98q4k7XLMfltwC/NFa1qhl17L7aw2mLiA8p4Qo3gbs4O2RTd34Uw 7H6KmJJey2+WbzA3kcY5IslW6vVEs2wE3k8qQkdUm74zb+TP9z7k1lF5q7iam8yC7Dnb Clwln0EVjJMrEwfXYBANadSP7vadMOccdVYSJpbuMVBcBQ344jqdo8QKapUBYjEZu0Kp qEZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758491782; x=1759096582; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bOfYi+evOXJssk3GreSh96Tr6S4alFUvF1o54q0ZtXY=; b=gjrg0kI9BSLmW7/29Zkz/q1SaaR5rgttodS4pI97p210efNa8ZqWuhIf/o4aP+uVMa ATDmJof1HoBCOLPnWF20YsNslI5c6jj2RU4f0bcLFI3QjYaD5Ul0TsBJOS36Kfn1gPFz djG2ikCso/S9Z4eSCvTygQJD1Zdm5bsWmn1hKmZHrPJA3InCiKqXgxIKlVmjyXZp4585 6chlm23dCKeo7GYhs4J76BUqTHt0WNDaOVQIFHJJCBk0lv5PAhAUpvsKUbsFwnAyRgsl a7750g3T8KyrEHpRSD6lxKZwx9vB/CsBjAIeSwefimzoUpMqeYda5JMCAdKNvmfQd7V4 uhzQ== X-Forwarded-Encrypted: i=1; AJvYcCXOaX0NTbjkKdvYvupMiztr2/MjquzU5iM/4j8xUcgGkM1gWjXlqdnJ8BB0lP7lYShOaJsmPHWfOZMgSyo=@vger.kernel.org X-Gm-Message-State: AOJu0Yw8dnOAkGhvaqFQg3O+4wi1hFAVrX7hhurum1Z1lJiCj2dFAYk+ cdh6k3V/Of1emGLIsRKAfnJALvEsbK0RqdpYUscORgvCkfnwZ/O6jlLEULhPYW3J X-Gm-Gg: ASbGncuGddCRFbw9wj0htaapiY68FuC69zmHgLsgXV2NZhZkJSMdZruaeFrkl1dyYju GQXJTeSy5CJdxYnyFWozRBy1bL+9fdVuFdbXF1gyT5WfF4RqN9Il8YGdIOtnLq+CJ0f/obq6Quy Kn279ClHcTvNZupRQryOmgZU2MwoL7PXMjmwTUUsaRmD3z8p4DC6VuddbVi/YufA3plZWPz3fb4 UH5TKaK1PzcILamELYGuLHFaHMrgZ5gS7Kh+hA1A5zBoWuuUov+hyheU/ZX4AXrlAgDoJFSweQv ZHyD3F5Vo/l2i43vvB8N0PuqJEo4H4eh0n9rOEvjBGsZfmubi0PKiCWwLlCK2QUrUKcdUuFMrm0 JBQ7m9G+GsDvd63mcYm2kfNYopSw= X-Google-Smtp-Source: AGHT+IHkY8glqJbAdbx/HQxL8P57QDbgpjHvW7djVIuzTEhF8v7QKu+VXWTwdbbHVgsscAGah8UFmQ== X-Received: by 2002:a05:6000:1acc:b0:3fa:2316:c21 with SMTP id ffacd0b85a97d-3fa2316187bmr2371046f8f.17.1758491782460; Sun, 21 Sep 2025 14:56:22 -0700 (PDT) Received: from [192.168.1.243] ([143.58.192.81]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3f829e01a15sm5873427f8f.57.2025.09.21.14.56.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Sep 2025 14:56:21 -0700 (PDT) From: Andre Carvalho Date: Sun, 21 Sep 2025 22:55:44 +0100 Subject: [PATCH net-next v2 4/6] netpoll: add wrapper around __netpoll_setup with dev reference 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: <20250921-netcons-retrigger-v2-4-a0e84006237f@gmail.com> References: <20250921-netcons-retrigger-v2-0-a0e84006237f@gmail.com> In-Reply-To: <20250921-netcons-retrigger-v2-0-a0e84006237f@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.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1758491774; l=2309; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=yUxPsW1neulTDSc12DrjlnnLI2RxeIiDkeTBPbs2djs=; b=d2nNT4dGAA6498qUFNrx4Kp0pt0EnCm5K+QmHqWERTvkBThp1hPs+jdrh+xminlvQ1/FIh9Nb JRvwqeiYmuhAx7pLVrhPxTRorXRAuN2SpVG5juSaJuNj+g9+5QnxmXi X-Developer-Key: i=asantostc@gmail.com; a=ed25519; pk=eWre+RwFHCxkiaQrZLsjC67mZ/pZnzSM/f7/+yFXY4Q= Introduce __netpoll_setup_hold() which wraps __netpoll_setup() and on success holds a reference to the device. This helper requires caller to already hold RNTL and should be paired with netpoll_cleanup to ensure proper handling of the reference. This helper is going to be used by netconsole to setup netpoll in response to a NETDEV_UP event. Since netconsole always perform cleanup using netpoll_cleanup, this will ensure that reference counting is correct and handled entirely inside netpoll. Signed-off-by: Andre Carvalho --- include/linux/netpoll.h | 1 + net/core/netpoll.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h index f22eec4660405eaa654eb7746cbfdc89113fe312..345e741126748c0ee8d55dba594= d782bced4eeed 100644 --- a/include/linux/netpoll.h +++ b/include/linux/netpoll.h @@ -69,6 +69,7 @@ static inline void netpoll_poll_enable(struct net_device = *dev) { return; } =20 int netpoll_send_udp(struct netpoll *np, const char *msg, int len); int __netpoll_setup(struct netpoll *np, struct net_device *ndev); +int __netpoll_setup_hold(struct netpoll *np, struct net_device *ndev); int netpoll_setup(struct netpoll *np); void __netpoll_free(struct netpoll *np); void netpoll_cleanup(struct netpoll *np); diff --git a/net/core/netpoll.c b/net/core/netpoll.c index 60a05d3b7c2491096f79ea6cf82eeef222c3eac2..bf563c4259f6cb19c31613ff277= eb5a0e2165e43 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -608,6 +608,26 @@ int __netpoll_setup(struct netpoll *np, struct net_dev= ice *ndev) } EXPORT_SYMBOL_GPL(__netpoll_setup); =20 +/* + * Wrapper around __netpoll_setup that holds a reference to the device. + * The caller must pair this with netpoll_cleanup() to release the referen= ce. + */ +int __netpoll_setup_hold(struct netpoll *np, struct net_device *ndev) +{ + int err; + + ASSERT_RTNL(); + + err =3D __netpoll_setup(np, ndev); + if (err) + return err; + + netdev_hold(ndev, &np->dev_tracker, GFP_KERNEL); + + return 0; +} +EXPORT_SYMBOL_GPL(__netpoll_setup_hold); + /* * Returns a pointer to a string representation of the identifier used * to select the egress interface for the given netpoll instance. buf --=20 2.51.0 From nobody Thu Oct 2 06:14:49 2025 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 3C66426E708 for ; Sun, 21 Sep 2025 21:56:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758491788; cv=none; b=VdebA1bStgRDLPzwBPT+wxmFVoW5ojc8UIWyXy0gG46qNGacOpse1USVgO+8nZxDu9d94SI5wxFqVkMevZtyj/YClsenMPTJ7nkbLuaUqsaXpFEBUsz8oafgAK1hNzkhN+5i9Q5DJZH29Z5m7/HeJN7VhJmkl74SIZOQOZ6lvDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758491788; c=relaxed/simple; bh=eG/wddCuyCwaUxobhxivrMgFJ0iPulanstbx9NkmFWA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UXUXMPILZ4da/Q+0VMPPckVo3fLaxOzmVtIuv6rMmiAnD5iPXaE2snPNbGSi5rWzuHUpPiLDswEeIjb7I9tqA+OiMgqCxknK+mj9WjW0brOvVoXhmRBJufI2gb8wnHA5rJOr93Qtx1EMGFt1amzebvBKqz/ih7mgGKbcFytGPsU= 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=nphpGejE; arc=none smtp.client-ip=209.85.128.41 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="nphpGejE" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-45f2cf99bbbso17165945e9.0 for ; Sun, 21 Sep 2025 14:56:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758491784; x=1759096584; 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=ourFaYJ9tj+096hrV6X7BfBF4z5jW4POqWI8u8yvTF4=; b=nphpGejE0Ag7o4AcWV1T7WXnM/q4SqavvEtxoOgh1x2J+AWB7bSj+d2QEqDbzliPcU 1muJr/T5OzGlCO1M1teG0BJd6Vstpcpaza8J08hipvuo4wXNHfnKgYijnREs3WBtgLs6 VgRG7cn90vuYn13Ko9yQUWeqoMALFdPwirV7hqa/vbW5/XkhKFC025qSwOdRiNptsiyU RpPCXmpCyec/OmkurdNdK8mMAPH+/RwbiFc3ZTQTYnRV/VnzC5Xs8DUJrLfHxjqZm9dY YdaLbF3vHm7XD0FwBcMyHaXuqQw4PE38/Tb8Hlm8yuHRf8/IwmqwXaRILpjgOoMaXeoe cB/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758491784; x=1759096584; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ourFaYJ9tj+096hrV6X7BfBF4z5jW4POqWI8u8yvTF4=; b=Y+KH6uIJyjY58eCRVmJ24ddyzZvdqCYxsAMykNhn6bZDj1Mzm+tEjG9Qq7s4EtTbq2 lpW/qAHTJJyxiXFUg+P52YVqtY1T0kdtMYVbloRyxSZlbeyQj+R0CscD/d7pGxdo5lXN c6b7Tw1fzHb11Ct/71MGycGbcOiIj1jVTZxYqy3vhaIEBuVSUbqthxFlCCze5fpvN95w nYrTvlBraxyTLBPUzagYGJe0VA/4Nr+XUkjyGXz3rLfzUdwUxIEE9PWvgJiYg8o6tID6 /o73r2fg48QYPDBilQmnsv1hrpnl0BIW6QIOfh1dBzBcS3DBVH/aEhG/98xKBiecLmcw Ij1g== X-Forwarded-Encrypted: i=1; AJvYcCV2s4Np/MVLpaHEjJuEywvQ3brb6G+7CobVA21E8xApP6pbNE3n4ed4JwYqcJwV7WAxLingfJ4isRSsnV4=@vger.kernel.org X-Gm-Message-State: AOJu0YxkcfNCIROoiqt3R1vyy+epfI4gZDUaDFlNg76n99MYeg0jtwZl 2OwtZL7oZC2UcUlsMJOmdcQp6JxoBFeO+uNuLwbwNykX1xfH8PHL87tw9aanFsvb X-Gm-Gg: ASbGnct5tcbTGi1SYCx22pei51lytbpLxxglUjWxYIxr552Gs3nOcdYOuUBzZSm8pSb WLT2eT1CGQY8XIvYh0/jHTbz2W9cpJABIX63471r+DYgpfALfdNq0WgbRTu657Z09iB25NgqWgX iX/P1I1IGXnpeTrXPuYn6cA5RMgcAAYumSJuk99UxZBjyoHTs4/pdGV0GrUjLf/zzl4DMW3gvhq fzU5bH1LlBhcBnCtPxjf/nWWz8SrWgjvNTCiQSCqRHiD//bC9mzx9BoGclVzmbEg/Zwphys/5xo HoPHotHOOmv/U7T6Gr4+rVTtJEw/DP/Tqo87dXuubuVBdZ28ZFz7koqCVAbFuXfzZ8WWGeN1bUY DzDN7bTeyo5mfd2Eb4K7AsZtAX81IG9P/97C6Aw== X-Google-Smtp-Source: AGHT+IHyTHbqNtDqL/vdm0/JYC8pK90GjY4pzK8dB+l68eu9HRCPn+1F81ZrAgi/3sUNOSy2r6FxFA== X-Received: by 2002:a05:600c:1988:b0:46d:b665:1d95 with SMTP id 5b1f17b1804b1-46db6651ffdmr413745e9.32.1758491783929; Sun, 21 Sep 2025 14:56:23 -0700 (PDT) Received: from [192.168.1.243] ([143.58.192.81]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3f829e01a15sm5873427f8f.57.2025.09.21.14.56.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Sep 2025 14:56:22 -0700 (PDT) From: Andre Carvalho Date: Sun, 21 Sep 2025 22:55:45 +0100 Subject: [PATCH net-next v2 5/6] 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: <20250921-netcons-retrigger-v2-5-a0e84006237f@gmail.com> References: <20250921-netcons-retrigger-v2-0-a0e84006237f@gmail.com> In-Reply-To: <20250921-netcons-retrigger-v2-0-a0e84006237f@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.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1758491774; l=3810; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=eG/wddCuyCwaUxobhxivrMgFJ0iPulanstbx9NkmFWA=; b=RLs4+p+hnsheILQOg6DjKkDeiQvO/HvmIEGdPyYrCKeNMOOzLRQUaZeWhSGk3I3KuFg17svwn ZUn2iUP+Um+Ch0EtR2XtQZQ6w+I21fGeR8EdZxIZV4JbujigbL53tq4 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_UP event is received) by calling __netpoll_setup_hold on the device. For targets that were initally setup by mac address, their address is also compared with the interface address (while still verifying that the interface name matches). __netpoll_setup_hold assumes RTNL is held (which is guaranteed to be the case when handling the event) and holds a reference to the device in case of success. This reference will be removed upon target (or netconsole) removal by netpoll_cleanup. 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 | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 59d770bb4baa5f9616b10c0dfb39ed45a4eb7710..96485e979e61e0ed6c850ae3b29= f46d529923f2d 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -135,10 +135,12 @@ 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 netpoll the latter is + * due to interface state changes and may recover automatically. * 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. @@ -1430,6 +1432,31 @@ static int prepare_extradata(struct netconsole_targe= t *nt) } #endif /* CONFIG_NETCONSOLE_DYNAMIC */ =20 +/* Attempts to resume logging to a deactivated target. */ +static void maybe_resume_target(struct netconsole_target *nt, + struct net_device *ndev) +{ + int ret; + + if (strncmp(nt->np.dev_name, ndev->name, IFNAMSIZ)) + return; + + /* for targets specified by mac, also verify it matches the addr */ + if (!is_broadcast_ether_addr(nt->np.dev_mac) && + memcmp(nt->np.dev_mac, ndev->dev_addr, ETH_ALEN)) + return; + + ret =3D __netpoll_setup_hold(&nt->np, ndev); + if (ret) { + /* netpoll fails setup once, do not try again. */ + nt->state =3D STATE_DISABLED; + } else { + nt->state =3D STATE_ENABLED; + pr_info("network logging resumed on interface %s\n", + nt->np.dev_name); + } +} + /* Handle network interface device notifications */ static int netconsole_netdev_event(struct notifier_block *this, unsigned long event, void *ptr) @@ -1440,7 +1467,8 @@ static int netconsole_netdev_event(struct notifier_bl= ock *this, bool stopped =3D false; =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_UP)) goto done; =20 mutex_lock(&target_cleanup_list_lock); @@ -1460,6 +1488,8 @@ static int netconsole_netdev_event(struct notifier_bl= ock *this, stopped =3D true; } } + if (nt->state =3D=3D STATE_DEACTIVATED && event =3D=3D NETDEV_UP) + maybe_resume_target(nt, dev); netconsole_target_put(nt); } spin_unlock_irqrestore(&target_list_lock, flags); --=20 2.51.0 From nobody Thu Oct 2 06:14:49 2025 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 936152DC331 for ; Sun, 21 Sep 2025 21:56:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758491789; cv=none; b=sMi4MNRw9YEDn4QDNoHk2Yn6Y3y3zl24wosVGwVOXv55UTD9N97/Ema1qqhrjzRMx2OMG2SoCVwUXIbhLP+KSrtX9xzg1yE308d2uje1Rl/k5OrUpO8cN6KZ7TDMXsD/4LsV/reW2vZQmOvBk65ig+KsTm1l5GJCh6nAekav/54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758491789; c=relaxed/simple; bh=R3yengxGAdZ6SfJjU1VD10z3t2Uj/t+EUXjBtn9XPhs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SWiOmb96oSU8r9VfaXv3tktivHXSfpzrRm8XqWFLs9DIgRfuqDbhzIDESgd7H/55W/sRjEYQQn1Bow+cDoY9DtX/CCj6cMXF1ir17+OEGRmktkPg7XdpKso/YqElOC504Mm2WVtPqGXcUnA+N/gCkJeAI2cxfa70NY9TstKq1lI= 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=b0zEYnZW; arc=none smtp.client-ip=209.85.221.50 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="b0zEYnZW" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-3e8ef75b146so3525350f8f.0 for ; Sun, 21 Sep 2025 14:56:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758491786; x=1759096586; 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=FzkTk9ZGVrUO/YmVyv5ISDrea/09V1eF2f8GeR25nUE=; b=b0zEYnZWKWRkQOO0VYuUu0sfFnADqfeuXWFwzMLtTQZem6AChdmJoivcMwnlFUqmS4 ekz1ituRA96vRKJfNv0TfWoBx06LQkyupoppEBn4kFdi5mS67sqi9urqSDnDVAqpAsCQ qpJLYK853Gt9RJAvKAdCe1tHvRlOt6T2mVcCntCyREwPq68XeTcWVH4z7f44HxpUPrWw 7KHnsPYH5BoPi28Lj393LLXv8mZGn9GmzGJEYA0vtwETGwdLMDoXsNTBMWbFnyTVMnVy Yrxg5r47Y5CxUgQxiwlpJR1FS2KUfwpW3QeplsKR+bYsn5U68cgejrKA58Fc+SjqCW53 N4MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758491786; x=1759096586; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FzkTk9ZGVrUO/YmVyv5ISDrea/09V1eF2f8GeR25nUE=; b=tchKThM1rRnBVV7zxBgiiRcCJ5ttvP+IvH9tIiEXnp5rTGFbpLLa3sDry8vTdBVl7e gFEcaLxBiUOY13qkdCs1KupIK3P2ZgCP0BERqF3/BJaOQDWyJZZFTr0EfSndcOwMpVVa PA7PmH5pNWm5JMdcJjAIorJZs+KvRDSWrs4cstERUR1V+qzzuNGrYVGQ6uDFVO2p13FB hwCNTYBxihJUeYlBCiNPrCEUkZYkIAR9OVKOwdY/opxLYwHLDE+P3cYEAExosT7z/AGh DimOsGGIeeYVtclZiHW1UmepXo8ZoxoZZ5BmrdEez5a53xqKFuN99W0wmuCKHWRFRp14 fazw== X-Forwarded-Encrypted: i=1; AJvYcCURcB5vwEEVT/0RyvbegRUToDEgHaKwKLfaY3HABWcgLZh2uueUz/xEhRDYNcH5CZnwrxnf0xAFYdKhyMg=@vger.kernel.org X-Gm-Message-State: AOJu0YwQVw04wnLvcaKQxRq4xOoIfJ8+Kbl/ghRACqrGDlHxkcu3j0r3 axI/6ioWwxXJtlOTPMx1SM9DJYAUS2gmAOkR4/hgezSLkpKAODv3D4WvQx1T64vn X-Gm-Gg: ASbGncvuJxdxLboIzs1e7lsMdv82P++n7Rj8Gf3WOuA+VTyEdIPmfqKBnO0UI8B/ieL XTKH8eptMD15j3QIxkwKmwCIQfniVf5i0mshBNazPaZYo/HxhTUT6w1CQ6L1CeTd+Lxy48VmGcm DkrxFV2ENTgzoIISkXPuC77uE8mY6AHWMDQhBuoTeC4WAobaje5TrYyfclm1ncT00B+TIXQtFuC 0ymRotGKI5enOidhgbHKVhKHyAwBGWebvJVFBGcydOWeCHcKSwyHPlurwM9tlGFihqFPz6hgtyd ADztUjjL6a+bvPJBsKFwz7Hys++Nq9CO46hsiLGOxirCd6rAl3wh3+LhQ4pNrHC6OsL+SD8d9i/ /Pdlwn59lDLu1Dp2e6rjOGFOQBGE= X-Google-Smtp-Source: AGHT+IHEVkHeQQ75LjAl5tNj6JF2glhGPryv/AOyhtjgb89bmwUVUWqWMyYTbYI571pla3OfRIwgCA== X-Received: by 2002:a05:6000:18a9:b0:3e9:ee54:af54 with SMTP id ffacd0b85a97d-3ee7d0c8beamr8120070f8f.21.1758491785512; Sun, 21 Sep 2025 14:56:25 -0700 (PDT) Received: from [192.168.1.243] ([143.58.192.81]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3f829e01a15sm5873427f8f.57.2025.09.21.14.56.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Sep 2025 14:56:24 -0700 (PDT) From: Andre Carvalho Date: Sun, 21 Sep 2025 22:55:46 +0100 Subject: [PATCH net-next v2 6/6] selftests: netconsole: validate target reactivation 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: <20250921-netcons-retrigger-v2-6-a0e84006237f@gmail.com> References: <20250921-netcons-retrigger-v2-0-a0e84006237f@gmail.com> In-Reply-To: <20250921-netcons-retrigger-v2-0-a0e84006237f@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.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1758491774; l=6229; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=R3yengxGAdZ6SfJjU1VD10z3t2Uj/t+EUXjBtn9XPhs=; b=al6+LfV3Wlpo5KSptSKWJZhAtKi1BpcVuCY06ZSn8isevIQwvKwFczYQb13AWK+IPIlFZMmtW /heGcq1URIjCxvgBtq+/Cf/fPihGb4Kl5yZ4g5f43E4vg3oN+57AMMt X-Developer-Key: i=asantostc@gmail.com; a=ed25519; pk=eWre+RwFHCxkiaQrZLsjC67mZ/pZnzSM/f7/+yFXY4Q= Introduce a new netconsole selftest to validate that netconsole is able to resume a deactivated target when the low level interface comes back. The test setups the network using netdevsim, creates a netconsole target and then remove/add netdevsim in order to bring the same interfaces back. Afterwards, the test validates that the target works as expected. Targets are created via cmdline parameters to the module to ensure that resuming works for targets bound by interface name and mac address. Signed-off-by: Andre Carvalho --- tools/testing/selftests/drivers/net/Makefile | 1 + .../selftests/drivers/net/lib/sh/lib_netcons.sh | 30 ++++++- .../selftests/drivers/net/netcons_resume.sh | 92 ++++++++++++++++++= ++++ 3 files changed, 120 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/s= elftests/drivers/net/Makefile index 984ece05f7f92e836592107ba4c692da6d8ce1b3..a40b50c66d530b3fcbeaf93ca46= f79380b3a1949 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -16,6 +16,7 @@ TEST_PROGS :=3D \ netcons_cmdline.sh \ netcons_fragmented_msg.sh \ netcons_overflow.sh \ + netcons_resume.sh \ netcons_sysdata.sh \ netpoll_basic.py \ ping.py \ diff --git a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh b/to= ols/testing/selftests/drivers/net/lib/sh/lib_netcons.sh index 8e1085e896472d5c87ec8b236240878a5b2d00d2..88b4bdfa84cf4ab67ff0e04c3ed= 88e5ae9df49d2 100644 --- a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh +++ b/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh @@ -186,12 +186,13 @@ function do_cleanup() { } =20 function cleanup() { + local TARGETPATH=3D${1:-${NETCONS_PATH}} # delete netconsole dynamic reconfiguration - echo 0 > "${NETCONS_PATH}"/enabled + echo 0 > "${TARGETPATH}"/enabled # Remove all the keys that got created during the selftest - find "${NETCONS_PATH}/userdata/" -mindepth 1 -type d -delete + find "${TARGETPATH}/userdata/" -mindepth 1 -type d -delete # Remove the configfs entry - rmdir "${NETCONS_PATH}" + rmdir "${TARGETPATH}" =20 do_cleanup } @@ -350,6 +351,29 @@ function check_netconsole_module() { fi } =20 +function wait_target_state() { + local TARGET=3D${1} + local STATE=3D${2} + local FILE=3D"${NETCONS_CONFIGFS}"/"${TARGET}"/"enabled" + + if [ "${STATE}" =3D=3D "enabled" ] + then + ENABLED=3D1 + else + ENABLED=3D0 + fi + + if [ ! -f "$FILE" ]; then + echo "FAIL: Target does not exist." >&2 + exit "${ksft_fail}" + fi + + slowwait 2 sh -c "test -n \"\$(grep \"${ENABLED}\" \"${FILE}\")\"" || { + echo "FAIL: ${TARGET} is not ${STATE}." >&2 + exit "${ksft_fail}" + } +} + # A wrapper to translate protocol version to udp version function wait_for_port() { local NAMESPACE=3D${1} diff --git a/tools/testing/selftests/drivers/net/netcons_resume.sh b/tools/= testing/selftests/drivers/net/netcons_resume.sh new file mode 100755 index 0000000000000000000000000000000000000000..404df7abef1bcdbd29a128c304a= c9b39f19fc82d --- /dev/null +++ b/tools/testing/selftests/drivers/net/netcons_resume.sh @@ -0,0 +1,92 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0 + +# This test validates that netconsole is able to resume a target that was +# deactivated when its interface was removed when the interface is brought +# back up. +# +# The test configures a netconsole target and then removes netdevsim modul= e to +# cause the interface to disappear. Targets are configured via cmdline to = ensure +# targets bound by interface name and mac address can be resumed. +# The test verifies that the target moved to disabled state before adding +# netdevsim and the interface back. +# +# Finally, the test verifies that the target is re-enabled automatically a= nd +# the message is received on the destination interface. +# +# Author: Andre Carvalho + +set -euo pipefail + +SCRIPTDIR=3D$(dirname "$(readlink -e "${BASH_SOURCE[0]}")") + +source "${SCRIPTDIR}"/lib/sh/lib_netcons.sh + +modprobe netdevsim 2> /dev/null || true +rmmod netconsole 2> /dev/null || true + +check_netconsole_module + +# Run the test twice, with different cmdline parameters +for BINDMODE in "ifname" "mac" +do + echo "Running with bind mode: ${BINDMODE}" >&2 + # Set current loglevel to KERN_INFO(6), and default to KERN_NOTICE(5) + echo "6 5" > /proc/sys/kernel/printk + + # Create one namespace and two interfaces + set_network + trap do_cleanup EXIT + + # Create the command line for netconsole, with the configuration from + # the function above + CMDLINE=3D$(create_cmdline_str "${BINDMODE}") + + # The content of kmsg will be save to the following file + OUTPUT_FILE=3D"/tmp/${TARGET}-${BINDMODE}" + + # Load the module, with the cmdline set + modprobe netconsole "${CMDLINE}" + # Expose cmdline target in configfs + mkdir ${NETCONS_CONFIGFS}"/cmdline0" + trap 'cleanup "${NETCONS_CONFIGFS}"/cmdline0' EXIT + + # Target should be enabled + wait_target_state "cmdline0" "enabled" + + # Remove low level module + rmmod netdevsim + # Target should be disabled + wait_target_state "cmdline0" "disabled" + + # Add back low level module + modprobe netdevsim + # Recreate namespace and two interfaces + set_network + # Target should be enabled again + wait_target_state "cmdline0" "enabled" + + # Listen for netconsole port inside the namespace and destination + # interface + listen_port_and_save_to "${OUTPUT_FILE}" & + # Wait for socat to start and listen to the port. + wait_local_port_listen "${NAMESPACE}" "${PORT}" udp + # Send the message + echo "${MSG}: ${TARGET}" > /dev/kmsg + # Wait until socat saves the file to disk + busywait "${BUSYWAIT_TIMEOUT}" test -s "${OUTPUT_FILE}" + # Make sure the message was received in the dst part + # and exit + validate_msg "${OUTPUT_FILE}" + + # kill socat in case it is still running + pkill_socat + # Cleanup & unload the module + cleanup "${NETCONS_CONFIGFS}/cmdline0" + rmmod netconsole + trap - EXIT + + echo "${BINDMODE} : Test passed" >&2 +done + +exit "${ksft_pass}" --=20 2.51.0