From nobody Tue Dec 2 02:32:14 2025 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.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 6823331ED71 for ; Wed, 19 Nov 2025 07:49:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538573; cv=none; b=DTDbwo35/X4lgFX+2Qy+LxQXir5N3q5davKTjczz/YN2T6zIkQtDVer706Gm8B5j5FcsphYflMVIm/3zOYp46CxsJ7I/U11lb7zE6Co82FQ1NUiu5bssf/K0gSMehbT+3rtvA8h1+33OXu406urbLk6ghLAxUUZqRnrRbPEIDRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538573; c=relaxed/simple; bh=DBsnCb1RGhHIHvd3TVQ3alBA0j/c8nR/NiX31PKWaxI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SNHpAjRiDUjfxf0vRphhWNS8SBATJVeY+XWCuD4tiqY9MmMqhUmMyOz7kBkQ883MUeIiF0ONinaoYaxRvYOetof/Lf+YcMGbsscUCJe9r7yYX/YwaHXQ3+LdxXtWCc5amfuVp3Lh0UgXn81fsKRgGOT7osPeAU/8vizxLcwvMVI= 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=jlcu4qWo; arc=none smtp.client-ip=209.85.128.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="jlcu4qWo" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4779adb38d3so32010595e9.2 for ; Tue, 18 Nov 2025 23:49:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763538570; x=1764143370; 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=9yl2sz1LCBOShtnkb+B0Wje+D4lWWLrs7LZhjMxASCY=; b=jlcu4qWoBT9ZkNROsLtAQQgubD1j3UN8FfGdgHum0Uv2c/CHidj+6qZ2Ov9ePGOS+Y +CXKACv8OIBNrf6wIGQvc7TPHU+2dXo06tX/mZlniTHIFDIG8UkvqVwJXeIp/xKqUw1H TkB2eFqMtx4wjOgKY1hLytBEBm4uAp1grQkN7GN/05de8b7NrN0ISnBqP81A8Pac7ktf i3+N00TDhugTS+T+C09aBKurc/3kANIDYoIaFl1rpZUIxmeIthbUPa75uNK60AQGcrMF SKMa6dNkxHeSawDtCdMCd9UlJQe0AM+Afrojjo+JGtKbzcnRGz5Fv7+3MHCjM4FMnXJR QVJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763538570; x=1764143370; 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=9yl2sz1LCBOShtnkb+B0Wje+D4lWWLrs7LZhjMxASCY=; b=CGmLAyABXcZE98PdMUcMInm4GpoHoZnilZPoFKf9sgRUBL8PmeExwRlEnGqWUqbaD8 fRyOfj507Ur44sdR9zHM5tOSEOQtY0JsGEoRuhGLfr3o73LqabWIV2+VF/MahnerUL1k xZxvAUtkypReCAgYFzG11hPQtFXU96VPQxwpYgtRPH/mo8BAYCkFSnmct4Pui1ajk4gi 9DmiJzljfjcoh7clJU1Lse4QF3wl3zXoHK0BCumz7obsSvdsnYgPadArEawZ51rNaDyv UaNTXvW6KDROJNGH3em0hqs8yZbExClC17FQZe1Ui9xt//o9OUYqNtaUELfJzuY/VgzN wlfw== X-Forwarded-Encrypted: i=1; AJvYcCVMSqZSTniyWoNDfD5cvHZd4R6owpr27dqhPtiHcD/awhYh6GWQ/lWD4sR11uZtdtZCNRG0ccOzQEC85+k=@vger.kernel.org X-Gm-Message-State: AOJu0YxgzkV3vMYd7d5lH5JDzkNrKVJdGHpFCxJpbzmdsK5AzfhyXY2O AR+3A+NNtRpXaGDbOcmcqVjolxr/UiDo4pb/vgCHzvSxYxbY7ibKKoNo X-Gm-Gg: ASbGncvO+ZziSUI14ImGPOSkCBvtlnoBLVjtBFQ9t9zaxPNtO99p7yPsBs1yeBMiWu8 BAA+IBoZLZJHCDAR+PSKI8MmCuWsPq67GuxjLfw3tF1JxDBthKI+JMDUY/qh/ooEYMSbwvtenIw rl9zFVm2KmatpUbMJub3sqFvUOFgaJvmE4J8INa9+6HtwqV3u5pE8TpRgIcChZ3EGW4JvyiKjWE W/1K3dLHDdVOsjFYseLXu13LfN8CkCYGhpKnjl4Ssh1gk7DIXnAA81fluUCstjb3MS5J4m1NWh1 kUaJFi5bfTc77mnCBT4PUSPfQefEEETPXbFADHlq8L2QN/hBbho6740YW/Qcn2jq4lXonf/hHtq fJDQyENnMg8wPqWWT1XQRH8yWllcFZ+RQMBrrhU8r1gy3t11m/nYoufRQWjS3N1UAyVTPSYYGSz YXzJYlnBXA+XHnSivu41xJV8mWvA== X-Google-Smtp-Source: AGHT+IGSnU9nBqcA4weQOAAZg3vUy9mdjD52QKfUOwY+oT+pWEQfLrnjUnPYigb7AGycMHO4iJWa1Q== X-Received: by 2002:a05:600c:6287:b0:46e:4e6d:79f4 with SMTP id 5b1f17b1804b1-4778fe68d7amr164382005e9.15.1763538569365; Tue, 18 Nov 2025 23:49:29 -0800 (PST) Received: from [192.168.1.243] ([143.58.192.81]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b53e91f2dsm37461146f8f.19.2025.11.18.23.49.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 23:49:28 -0800 (PST) From: Andre Carvalho Date: Wed, 19 Nov 2025 07:49:19 +0000 Subject: [PATCH net-next v5 1/5] 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: <20251119-netcons-retrigger-v5-1-2c7dda6055d6@gmail.com> References: <20251119-netcons-retrigger-v5-0-2c7dda6055d6@gmail.com> In-Reply-To: <20251119-netcons-retrigger-v5-0-2c7dda6055d6@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=1763538567; l=748; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=+ki/gSi1D4tq/a7wlghaz/ZnSK+KnYSdMinnxL+Akto=; b=PCuj2ZrbY6kRkAU9UYvmLEfFoDqdJhFwqW8/sGRWrgklEQpPJkwzdolyPLl1VUsnsNOh1Sbia 18CtCBVvCvHA2/rVy550dTw13lIMWK9k4Nqt4anQ+zyoti2J408vfo2 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 bb6e03a92956..7a7eba041e23 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.52.0 From nobody Tue Dec 2 02:32:14 2025 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 DCC8A32274B for ; Wed, 19 Nov 2025 07:49:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538575; cv=none; b=mNOMz/MWvrHnD6mONHQH/L9dbyCyeS3KrXFIfW+Hd9DGxpy7bSHtbmyB99eNXlbNno3kqYh5hpFIX1qopETX2jF4+YpjK7NzCZPqOXqQwRgB2AVbmqDezIUtBjIqfzTKCQy7J+CZPuPbUEaf4suKhPdVINUaOMFzTy3fDJs9uW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538575; c=relaxed/simple; bh=oUWokIEDld4kRUmAZyFGQq5Qe4DN3K6f1rTjOieZplk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MvSrB6BGfhv+UqHj/xm1jOoayHyzot5/lnVNe18414QzSKnWCDsEwkLAvudr8FdecTutVy51myA1baGqL0y8bEQb1mSzkWXUw9eZWVhcWgix1jLhoXszNrpVhhLapBEOlCX473lyxg4FlTh7QxzoFiizfDsM+cqyyWCnp0iQn70= 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=l2vdomgK; arc=none smtp.client-ip=209.85.128.53 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="l2vdomgK" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-477b198f4bcso2580045e9.3 for ; Tue, 18 Nov 2025 23:49:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763538571; x=1764143371; 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=n4WXY3ERbuZSOqVEVpN2MvADbktcFwK5vzpOBLwlIIs=; b=l2vdomgKks5mTCwq86hl7TA7JFjMRPt7lXxrOw1rr3pERu3xgk8JjXUTTp166bSpKv BGfKjuF1K0Vh3LUb+NDp5UqGKHiB23nQ6XRYO0NFgX+ieQS9HJtA4DTXFpeU9s8RIg2j aKSYvj6fWvdLek0be69oyDf+AhgBmtg64FuwzAJMkV7/3FOni7/qM1Tu3Oa2hB9QD+RJ wto0aQMy6tl1CsV2RQBonso6sVI0Gik/aE8hQtHIkfHLwMikMppj2MHS6TELyf4+xXlO 4KlV5yua9iUlGU1EZCUxb3PqOwY7DtjQqZ07dk9s3BxGJeUjUibEMeIWJ18i6FTsbIQe hO3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763538571; x=1764143371; 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=n4WXY3ERbuZSOqVEVpN2MvADbktcFwK5vzpOBLwlIIs=; b=Ut+/9Nz9MqzE1YMYpgPqOzGhCoiHg4fX8aMGad2NSKRcyGhOMHTEPf40fWCWvPJS3x 3x5vWhwPdL+GHmpzb7iyrl9ET9DN09RfptyJpXMszvxqum0in5hAogvwYhRbw5YV5heK HtK9HPR5LujXefQO+IlKYwqhlRaeg8Y+gthSD4oKx7QR+WOiJ+EXpvmNZ/zJnx40Y+Qq /kky9rncGG6LSyrNfoJr5qAuaGAUXsvy5XLA0/y/1OWLuMNLJ/3PAXQ1IPKtp0UhfWJ6 VadpgahIkA0XsS4Hfz6NWJ9KZ02DOmUqTzZXFlMmkBvvkTNNzSunY//TEuNOb/9qIC0p Z+4A== X-Forwarded-Encrypted: i=1; AJvYcCXnNa+pOwVwW3Q6BIrg30/K89a9BNgW2TCrdSsSk3NJ00dEYLsaEKqUW3ZAA5m71KenzrdIWBIBh+7G58Q=@vger.kernel.org X-Gm-Message-State: AOJu0YyDXyjGsgHkzcQ4+y6NSJt+r56JQT2m9qQxGqnkDd1subHgWQjE mYVKO7528K1FRDMW+cerrORB8nAMkcH5P7FCKL+9+hUNmeEVdEn7oQfN X-Gm-Gg: ASbGncsbbVbG0gsxjnUsKmch729HbY1YaYx19Gh5yX3a5oj6sQwIcLf5dQXrrLvPKUu zk+QaL6m9KgUIr1t+FvQmS72Fv3mhTOKnzVeNIZPlIryy6Rk2yk+oASt449TGprYDiubvD3IsNm vX7+PO1SRRyUlRQUQ/GYgzZ0FFVkn7ihfElCOMmy/lIoxEEy0Pq/xpvEDL8VQh/d7QWzA81STYq uT8CGTsvko5T274nd44VchstseMT/+/uliq5UMnpA863kfmqtVyciBqC0RrkJQsWrRPEtHadml5 YPCwLltu9L4drMNn3EFhCkeqxlBgkE9lJFUXE/STLQD2/+lwU7iCB3V80YqYV7/V42wN80ARICU 0frhlBpnjpnKMKuZGx/TIVzFdC6e3Fsfax6jRmzpsJhrV1ERPFfzcquovcFY/eMraNumLTomqNy RK814G6hJVdIQyxOM= X-Google-Smtp-Source: AGHT+IFLd20SEJufI6QIgNtFmAW/AlUvVsJ88uQFqanHuPhGS7kxwB6+3ppHJvfHNtUdevByTF89/A== X-Received: by 2002:a05:600c:3b8c:b0:477:afc5:fb02 with SMTP id 5b1f17b1804b1-477afc5fbd5mr26258475e9.21.1763538570691; Tue, 18 Nov 2025 23:49:30 -0800 (PST) Received: from [192.168.1.243] ([143.58.192.81]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b53e91f2dsm37461146f8f.19.2025.11.18.23.49.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 23:49:29 -0800 (PST) From: Andre Carvalho Date: Wed, 19 Nov 2025 07:49:20 +0000 Subject: [PATCH net-next v5 2/5] 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: <20251119-netcons-retrigger-v5-2-2c7dda6055d6@gmail.com> References: <20251119-netcons-retrigger-v5-0-2c7dda6055d6@gmail.com> In-Reply-To: <20251119-netcons-retrigger-v5-0-2c7dda6055d6@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=1763538567; l=8901; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=oUWokIEDld4kRUmAZyFGQq5Qe4DN3K6f1rTjOieZplk=; b=llAlo5ccn8ilJJIowC8V7B9nxxnfNcvliY64HiEOIuJvdQzdkEkFzxD+QCzmUHBhD8WZEMP83 n4iV0w8u+AdCVOjBgqDLY9ON66w+sVh8GDj6IIYYyEvom/mTMi5/kHo 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 7a7eba041e23..2d15f7ab7235 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; @@ -1330,7 +1332,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); @@ -1459,7 +1461,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; } @@ -1726,7 +1728,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); } @@ -1746,7 +1749,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 @@ -1902,7 +1906,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.52.0 From nobody Tue Dec 2 02:32:14 2025 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 B82E23254A1 for ; Wed, 19 Nov 2025 07:49:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538576; cv=none; b=LJ3NLPB3VkpTocmuiP/SN6he7aUNLIUJMZQbnJsg5eZW5a2TzhsBB2htN5OzblQBJVkeLOu8x0yGQM/WlB3hR+0c5oWusEDCs+zh4Lrz4D2Zfp1iATR9xFDBn7BC00JgqKdZyQokirN12uDvszpKI/+/BvOZLGijKR1UOYgq1D8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538576; c=relaxed/simple; bh=b8FscmmisLfC2hrZ743eM0Q8mvR5xh9F7WYVK3EV1tc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IDAoCdSGU7G9YNhSsegFjEn/kQUG6kc1TtjQLdTmiorMl0kBbf4uZ8m76Pv07bRUfx5SzP9da97QI3ufOL9VlGtJC7PUb8HmYLTHmtAwp/isqYlH4HW+8gH9lOzmCihv2kvKe3iaD/RSLFGZpYHJmUqPPyazxN83dKFq+LiR7S0= 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=GVT9wFUK; arc=none smtp.client-ip=209.85.221.44 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="GVT9wFUK" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-429c8632fcbso4465012f8f.1 for ; Tue, 18 Nov 2025 23:49:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763538572; x=1764143372; 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=6TImvYlNnQRMa8IRvJ9GWsrXwTK0Q8nmLpVv9SLrtH8=; b=GVT9wFUKcZnxOaXMo+JgG5fXyDxf5v0pPsOoc8E5WRFhLkKzjJmLZoRIou+Hc2eGUW Xs8EXfgW1oPqw7Q6NUhMjWidfRFQcMvbFcz46aK64zyUDzBiCtLU8IBqPs25owz34cJN gE0ORa2jzr1MU+J1pZRORitYG+vHzS3NT3vZID0EhVrb+QL4/Jlu+wsfsJkXmA3r4Rla 16Mzlqczbf0qjdVOLeV9p0HXHd3Fdthp9PcBrIpRLclrxLOwgBt31bgohxf414oGx6VS lgJwtjgB9PKp3KKO4hgPfRuyiTRpkGdsyB5XLS+6cZYj9eG8hvo7TSWb82IX+IoD5VFi XV0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763538572; x=1764143372; 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=6TImvYlNnQRMa8IRvJ9GWsrXwTK0Q8nmLpVv9SLrtH8=; b=HsjdQqtKvgDfEhGviQL8JsxGC4YaMzqrM7ryn4CmbSxw9FxrbYAvV+KlIMwV1z/44o lrBof+1982m7Uu0O7Tcs4SXJbnRzsQOFn5vCnMowECe/V3sZtGQE95K8qeEFcTkqbfAm BGYHHX4cRQXwLgL8mUFuA7b45CPkm+RlGVTcAuI7pVPpcvYBOHO/04TEq68xEwnmZBdY IoILlld7JkbTsDbfz0dLk+ZS5N5UPcvgxPwq+NgRq3yFeO6E+kGqN7bdUVNhIF49IG2V deH6UD+VER3XjHQjZ5vOrpVNsRQdEv0oHU5IW3iauCbMw3fQ3tNjp96p6/jpUZZlf5nV HYBA== X-Forwarded-Encrypted: i=1; AJvYcCXF4WhMH8dNqs+PJ4VOmvLDiktvnzlC834z2QEOFoSWhHs2vBZ+UXkP1qKemJ9VqSQewGsgQ5W55CslTAo=@vger.kernel.org X-Gm-Message-State: AOJu0YwrIcYmlViZQ7PExKVn6H6LfqMQ7EP+lMk2+0TcX6fW4HbVLdE1 KB7aTozhM0tc9JUYYybjn6XFJ+IKH/l7G1bIeUJ55E23NADeYGP2ptyk X-Gm-Gg: ASbGncuBU35PyC+ySbCuSpjJsh1l3gRIW+wWHUE8tni2KKfj3hsTCDMi8VJFoHwgvZQ wA1BqwjD/Yy8o9omynYPPkEbNBe7lWiY4MWjzxO0uqtd8FfDTbtEqHEzEPgmRlYa4v229VxgCVt p91yasUboyc8z51XyWNuK1Z/YXJM0QJ2qd+bXUtAwNJNun2opBv9HuTQ5oBEXn3TompNwpP5nUr DROhoVSTVuwWp2RPmUQcZzHVQENFPuLoZ5yjEmk4/ZgebNLlhglEbjFIfPv0Tyxnw9RrOq+Sn5z 7YzFKsUXulvBEGG6zlxrHKoICbKpIPYESHJnJDCIdfUTfX7aIfa3+/iECny9lz7b/M1lSdrhrRE xvC6ymevdUbhCs2YKChnqnJZJA/bDyEpsjmv/5yaw8XRvv3zg75oPrsk7SBbfobf1uaS/0yydSh oVXWzLC3DEJj5fQu0= X-Google-Smtp-Source: AGHT+IExKSEYuSjTPblU2hxyhKKajyovUPxWOzaGhBnrkrN3rrrRZSJw3ztuShNlULzBNBuZEh/Fkg== X-Received: by 2002:a05:6000:2913:b0:42b:3806:2ba0 with SMTP id ffacd0b85a97d-42b593234camr20195873f8f.2.1763538571920; Tue, 18 Nov 2025 23:49:31 -0800 (PST) Received: from [192.168.1.243] ([143.58.192.81]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b53e91f2dsm37461146f8f.19.2025.11.18.23.49.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 23:49:31 -0800 (PST) From: Andre Carvalho Date: Wed, 19 Nov 2025 07:49:21 +0000 Subject: [PATCH net-next v5 3/5] 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: <20251119-netcons-retrigger-v5-3-2c7dda6055d6@gmail.com> References: <20251119-netcons-retrigger-v5-0-2c7dda6055d6@gmail.com> In-Reply-To: <20251119-netcons-retrigger-v5-0-2c7dda6055d6@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=1763538567; l=2409; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=NaSr0aRo/KeIcHaXa24IkgHFUS2s0iyQ6sB/nOVkiyQ=; b=AfPaO140aeo7SeI9ECUWkGDzjLBwWiPAMfF6RVgFJC1p1ZvjcQ19wWNMVrRxj6cSX6acWoOQv t3krehSGJUFBLOPFXulnjSaBrIAZxriN8GXhpXcygPCr3NFSN1vyOH4 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. Devices (de)enslaving are marked STATE_DISABLED to prevent automatically resuming as enslaved interfaces cannot have netconsole enabled. Signed-off-by: Breno Leitao Signed-off-by: Andre Carvalho --- drivers/net/netconsole.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 2d15f7ab7235..81641070e8e2 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) { @@ -1460,10 +1469,19 @@ static int netconsole_netdev_event(struct notifier_= block *this, break; case NETDEV_RELEASE: case NETDEV_JOIN: - case NETDEV_UNREGISTER: + /* transition target to DISABLED instead of + * DEACTIVATED when (de)enslaving devices as + * their targets should not be automatically + * resumed when the interface is brought up. + */ nt->state =3D STATE_DISABLED; list_move(&nt->list, &target_cleanup_list); stopped =3D true; + break; + case NETDEV_UNREGISTER: + nt->state =3D STATE_DEACTIVATED; + list_move(&nt->list, &target_cleanup_list); + stopped =3D true; } } netconsole_target_put(nt); --=20 2.52.0 From nobody Tue Dec 2 02:32:14 2025 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 DAFEE32695F for ; Wed, 19 Nov 2025 07:49:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538577; cv=none; b=eGhf+sqvjXTS/cnApzd166Zb9hh7ZHpIUOo8scZMT2gHEDUWIyhZXa9+BPm9/UNHz1xCdzNz7chKf1e97XVJCgW0XmwcsQfsBmoneRDGwE2P2rSS8BNTgVnIxtPk3MEadZf4i2khwR2h0m73264pTWRVoFWMaiHLMltfal8uQNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538577; c=relaxed/simple; bh=9zaqmgBwxXnLcXgUwFa+jvCmIZuwMpmmytrg0AHbbKo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YpLfZC2LvJqO1q5BYWFhlCII2lhaFcP9seh+YCyPm0BUczjUuVEAtjnx3TUVrhTAbgHZ4kcDYOr3MkSmYvTmLhmaVXWd9CZ0h4ovg6VRZ8M/n4FhsnRlVLnAz4+C8qiKCeeaL94iDm/m1jOPL8p6p9lOimf2608f6q3kMiab8WU= 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=Kcy6oKi+; arc=none smtp.client-ip=209.85.221.49 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="Kcy6oKi+" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-42b31c610fcso5440961f8f.0 for ; Tue, 18 Nov 2025 23:49:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763538573; x=1764143373; 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=bAe1pwdEymBst1UNpxP2f2MyEcqzXU+P5wwloI7gzDE=; b=Kcy6oKi+Y3hcnV6AMMd4i0mwFzTkdgivBcVmQnM7OEjGujHxEQvUMcKHIc9YVG4J0S r2RrtI9odsX8Sgve6NVNzI4HMc+FD4ed/PuLNcnS1j2ep3vpmKbuH7JUcup9CPVJ0tkO ZymiTP+siLP4esWXz+xMYYtvD8s1IUF2D+GpOuVLwCgiTHo+b9Z1kuniTv6uy4z/OGwN 6EjPjFXGgZ5KcRkJTbP9qZQIZdNLlaF/QTk8iNI25bRRRqCrmFqfZ66ZIFGdwin3z2mM 3Qc8ZgZNeHDNSEJH7VzBFKa0/h6z9qGTU/QeyspkanJvamgBrmsFJNB6bCrzEPIbkWsD Fkqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763538573; x=1764143373; 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=bAe1pwdEymBst1UNpxP2f2MyEcqzXU+P5wwloI7gzDE=; b=gtYpvEccjS40LA37BxTWssn1uJBo+yqBd/tyIxbUmwOGB51N2JFKXLLG7vHXEqTvIl VKm3WGIsbdiTrGr229fwUIPrIM357SVTWZlhuc3q2iok7o2gUF3RaLY8Zr0qzZUFZYMP n83UapBKcyVKGe1e8x2BqIg+qWuVkx65isgbjQQzrFnTt1KcjooGoCW5Li9KZfVCiiEq FLmYdWfxEjjLfstccDriMzCRUP/0riqfZ1cd02HoSuaeQaMTcglisd+iaqAHAX9P7fEB QdYh0PTqZ8BDDIWBHCxqIGtVNx0F6iQdD7Q55RVAgSU7GSB9OES+R5vEboXi+8ZOh4Xt +9PQ== X-Forwarded-Encrypted: i=1; AJvYcCVipj0TYwH1RLvYPiXo65CEWFd06K6C6rzP0DfYfpzHJscWs0gycxL1BlfQQJYBhWnOh9KDxqmLy1XMqrs=@vger.kernel.org X-Gm-Message-State: AOJu0YyVoLMHxBJAcvcZLbBY6r/f6ERFJGV6pGBg+cRMN1FJ01cRCcaw VUyxvR1L4xnLtnkXcljVxlEUPpNZYMiex/bkGaHg3lrAl49BPWuz2mKr X-Gm-Gg: ASbGncvnG+crRMviLFiCKa1zKuzFzbnE1s59dVDtNxxKtizcjBRCXNx1N5et6qfzmyz RS2X1XTbKzd0FQiCzHqYB4/iX5MiHrWLSDNq95GRsfrAST67vDGzDFHXSOHfmeMaufJ7oOC3tAN SQeWQQ/IZ3znFIJ0G5OA5XzacOF0siqvlDVXVRosf0AtoMbNK0wixWJgd9piXQSaIX3ZHKYOxlF 1JgNJvrAvUHG9S0htRYgGNrIhwCsL0QHrhTaTRQnWp170Fs2MGdFqaWAzDCvyhU52ZmBYwNwQQM f8d3PGTT22/ZnFuh9ELjs/bONq924O3PZ0PYQH6UwbObPA2gR77uWH02UNrU9EGP4b6Gavsh19+ S2NOSMDnEn1SyuPSt0l13VDeY/9UmhIzklzXI8UdggHTtrUsCacKujRZFGsirBBnHfQI7n7GZ2a qxiffPqQ+LuKKcOeY= X-Google-Smtp-Source: AGHT+IERVxvk5iIz8m6CmGB4RzuWyuTcJ3Fb7iPOVqXTv11jEE1NU93NJ6Ei8X7dQH2Oeu1dBUM4rA== X-Received: by 2002:a05:6000:4284:b0:42b:30f9:79c9 with SMTP id ffacd0b85a97d-42b59386891mr17979875f8f.37.1763538573037; Tue, 18 Nov 2025 23:49:33 -0800 (PST) Received: from [192.168.1.243] ([143.58.192.81]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b53e91f2dsm37461146f8f.19.2025.11.18.23.49.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 23:49:32 -0800 (PST) From: Andre Carvalho Date: Wed, 19 Nov 2025 07:49:22 +0000 Subject: [PATCH net-next v5 4/5] 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: <20251119-netcons-retrigger-v5-4-2c7dda6055d6@gmail.com> References: <20251119-netcons-retrigger-v5-0-2c7dda6055d6@gmail.com> In-Reply-To: <20251119-netcons-retrigger-v5-0-2c7dda6055d6@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=1763538567; l=5497; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=9zaqmgBwxXnLcXgUwFa+jvCmIZuwMpmmytrg0AHbbKo=; b=OPacxqOGj015GBSqd/r2fPzk5Qh2IxiVUdWxqAZLykyZbPI/VkNNqSECQNSbeJHz6OKsTUFtO yrFPCdR7KtDAolFuNZV7+p2WRUJ43o6ohF1I/9QH1WtVaPr947Klv9T 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 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 are candidates for resuming are removed from the target list and added to a temp list, as __netpoll_setup is IRQ unsafe. __netpoll_setup assumes RTNL is held (which is guaranteed to be the case when handling the event). In case of success, hold a reference to the device which 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 Reviewed-by: Breno Leitao --- drivers/net/netconsole.c | 82 ++++++++++++++++++++++++++++++++++++++++++++= ---- 1 file changed, 76 insertions(+), 6 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 81641070e8e2..89d997e789e9 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -135,10 +135,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. @@ -1445,17 +1449,76 @@ static int prepare_extradata(struct netconsole_targ= et *nt) } #endif /* CONFIG_NETCONSOLE_DYNAMIC */ =20 +/* Attempts to resume logging to a deactivated target. */ +static void resume_target(struct netconsole_target *nt, struct net_device = *ndev) +{ + int ret; + + netdev_hold(ndev, &nt->np.dev_tracker, GFP_KERNEL); + + ret =3D __netpoll_setup(&nt->np, ndev); + if (ret) { + /* netpoll fails setup once, do not try again. */ + nt->state =3D STATE_DISABLED; + netdev_put(ndev, &nt->np.dev_tracker); + return; + } + + nt->state =3D STATE_ENABLED; + pr_info("network logging resumed on interface %s\n", nt->np.dev_name); +} + +/* Check if the target was bound by mac address. */ +static bool bound_by_mac(struct netconsole_target *nt) +{ + return is_valid_ether_addr(nt->np.dev_mac); +} + +/* 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 targets in resume_list and returns them to target_list */ +static void netconsole_process_resumable_targets(struct list_head *resume_= list, + struct net_device *ndev) +{ + struct netconsole_target *nt, *tmp; + unsigned long flags; + + list_for_each_entry_safe(nt, tmp, resume_list, list) { + resume_target(nt, ndev); + + /* 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_move(&nt->list, &target_list); + spin_unlock_irqrestore(&target_list_lock, flags); + } +} + /* Handle network interface device notifications */ 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; + LIST_HEAD(resume_list); 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_UP)) goto done; =20 mutex_lock(&target_cleanup_list_lock); @@ -1484,6 +1547,11 @@ static int netconsole_netdev_event(struct notifier_b= lock *this, stopped =3D true; } } + if (event =3D=3D NETDEV_UP && deactivated_target_match(nt, dev)) + /* resume_target is IRQ unsafe, remove target from + * target_list in order to resume it with IRQ enabled. + */ + list_move(&nt->list, &resume_list); netconsole_target_put(nt); } spin_unlock_irqrestore(&target_list_lock, flags); @@ -1507,6 +1575,8 @@ static int netconsole_netdev_event(struct notifier_bl= ock *this, dev->name, msg); } =20 + netconsole_process_resumable_targets(&resume_list, dev); + /* Process target_cleanup_list entries. By the end, target_cleanup_list * should be empty */ --=20 2.52.0 From nobody Tue Dec 2 02:32:14 2025 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.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 4117832862F for ; Wed, 19 Nov 2025 07:49:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538578; cv=none; b=j3VXIULpvUXo6pAtoV7xAv/gV51+pD0KZot9T7p6mkpbSwsCg36sDPe2ByfRvP4jvu6kh7goi/uJgMtJ/8U55K6CEF//BLKnwvTTxtpC/r3RasojB/IDB4C2pqnx9in5qWptKUjB0OJ6bHeoTWRPXSAtdko9SgbpThp66R1BMCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538578; c=relaxed/simple; bh=PJbVIE+FjlqZXAqh81T+nKN+VWQTjy5oRGltePRw6wo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WxtRNJ9n/5ODve67sqe5Y4LeJwcEqDxLbWhaBf/5SaDIJeE6fzUzmGmARTzuv18Asu9RKbdiJZesvESVaHualInmEiiYxRo8Pi8EiCK72i4GkWLEHuWY8S6yTmfPsw9tBbKNwPAPGPLGW4mSnlxuvME4+NCYnO30DIHYYxvggqQ= 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=MsqSWJYs; arc=none smtp.client-ip=209.85.221.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="MsqSWJYs" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-42b2e9ac45aso4090416f8f.0 for ; Tue, 18 Nov 2025 23:49:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763538574; x=1764143374; 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=3YO8hwlO2C7MvqjPC6EcWcIdUphHn/vVfWOEg+rLhE4=; b=MsqSWJYskP0psn59XxmZ7fbHIW18kVKs1jBUIh+Wglqztw0m9QzkjtBpd8N93QsYgx BCXkaoLOhjF9juCJIxnd515DCycvvSBitnDk6Ns2jhk5MwxjGDxQjmhQ4xWRHB82iNvf DdFtcfIOSfch8bTCNigj314SR/XuUXV4i7HA3cT25uiFWa92f/nqG7mpyXRtrBRQKlhO 3tA7QQRee04pfm38e4LseCuEZL7Dl24HR0b9yMZ05g6caqOEUnSBjySdlvaKUUhsf+C9 Ob6R1PZNK3eS+k5TptdZ+x5djKteG6tPnJVg/F+Gwq4lH7z+OUlheo6KCmW/1eOAa0d4 DtOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763538574; x=1764143374; 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=3YO8hwlO2C7MvqjPC6EcWcIdUphHn/vVfWOEg+rLhE4=; b=FLf5DnWUpeYsmRFsog/SH7VjFJdAd4e07FfwVXZ7ecAqFwkYqbdwhCsdwmhiQHhofa vPqWLTzjTolGaGuE/G2VKrbstort/XfdF8pLlF+G4HbStC3J5RXJ5xRX1TYq66rHxR++ dplP3H5Yr4gWQo7rc4RYNHs0jPYzomp+XP9hm/DhaXuvyrA8LyW/MJXBecBg5l9PFvkT ap4ChFKyUr37wctmEdK+NJYZAN85hHqKo32iR8gSHKAeVxr5bIA/yi5O7tdoD7ojiRtC HAVXrMxAzGGtisgV8YL5FkclEAk/aj2UaDY4eyk7AAK18P76d9LlUyGK2TPj8BLyMnHg SHaA== X-Forwarded-Encrypted: i=1; AJvYcCXIafbhUPg0dlfHCqip74SZM7mQa06oI8DvCpr8p7ssWcNRA6kmTpP7oaNtJdpXqq+ibfpMI1ZniQPo5hY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4K1G2SC8kPWS5dNgKIubZN8vI5lZPq4wEuY/eLznuz+4ckmEg +/oTiD5m2zOz+SAbyEAp8SI4sPgrERwAQ5fgB0dizIcwp0jDOWr6Uon/ X-Gm-Gg: ASbGnctnJYWZtKgC81B2x8fF5nraOxngttAYi49FI064/4DyRU2ammibmoUxXjM/QUS rbA9NJKbHwy//0+pSWRI9VhAszgQ6LQmaLI1xlcqJK7CKC2HzhCCJIK/+/Gmrp0sdguQ+mwqnPD UZTh7G6ov9f9R7dPzJu/4XLSLUqDS0D/N9sVUTWupAph9QiODteGK58klqLk3jeBGC9n1zQp/VH 9Hns3qCJQ5DiHqmdWO9bHXx4TDtnHvFAEoxksc7qiyctqFqXWBIrBsUENeBdlOsc6FjZbHHk+lr mA5ybqwvATJqlULwHBwD812GQFglFYoYIUfMXCXvDP8gofAWT0WP23IWmzm6UeP3uEKuvbTMpcm t5Pkkvq1enmM6jwuP6k4ert6ri1ug+//mvWYavrNnWRPg3qegp2cZpvW+aqNa4ul0B5p5ve09xq 5W/rdZIV5gwER6N/gSHBwHTdhELyhXVsJyQmS9 X-Google-Smtp-Source: AGHT+IGPDf3n7yw9tmvx3mRMsXmrPnlbEY7oesz8TUWhArbu2lVE770zOvsQLkEdWQLuDspCZ91xzQ== X-Received: by 2002:a5d:64e3:0:b0:42b:3592:1b92 with SMTP id ffacd0b85a97d-42b59398992mr19426502f8f.47.1763538574344; Tue, 18 Nov 2025 23:49:34 -0800 (PST) Received: from [192.168.1.243] ([143.58.192.81]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42b53e91f2dsm37461146f8f.19.2025.11.18.23.49.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Nov 2025 23:49:33 -0800 (PST) From: Andre Carvalho Date: Wed, 19 Nov 2025 07:49:23 +0000 Subject: [PATCH net-next v5 5/5] selftests: netconsole: validate target resume 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: <20251119-netcons-retrigger-v5-5-2c7dda6055d6@gmail.com> References: <20251119-netcons-retrigger-v5-0-2c7dda6055d6@gmail.com> In-Reply-To: <20251119-netcons-retrigger-v5-0-2c7dda6055d6@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=1763538567; l=6488; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=PJbVIE+FjlqZXAqh81T+nKN+VWQTjy5oRGltePRw6wo=; b=3e3WCZ8bN9e7l+IkkBwVS0veQgRbSFvgvYDsAXZseHDhoWoDryCb6ea8Xq+nxulgDN1iEOtph 8lttF8bxPr8AEN3OkDmGiY36oKaAFTA97/R4KcvPMGszKou6zzbKryw 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 we are able to resume targets that were bound by mac and interface name. Signed-off-by: Andre Carvalho Reviewed-by: Breno Leitao --- tools/testing/selftests/drivers/net/Makefile | 1 + .../selftests/drivers/net/lib/sh/lib_netcons.sh | 35 ++++++-- .../selftests/drivers/net/netcons_resume.sh | 97 ++++++++++++++++++= ++++ 3 files changed, 128 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/drivers/net/Makefile b/tools/testing/s= elftests/drivers/net/Makefile index 33f4816216ec..7dc9e5b23d5b 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -17,6 +17,7 @@ TEST_PROGS :=3D \ netcons_cmdline.sh \ netcons_fragmented_msg.sh \ netcons_overflow.sh \ + netcons_resume.sh \ netcons_sysdata.sh \ netcons_torture.sh \ netpoll_basic.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 87f89fd92f8c..239f44d4a45d 100644 --- a/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh +++ b/tools/testing/selftests/drivers/net/lib/sh/lib_netcons.sh @@ -203,19 +203,21 @@ function do_cleanup() { function cleanup_netcons() { # delete netconsole dynamic reconfiguration # do not fail if the target is already disabled - if [[ ! -d "${NETCONS_PATH}" ]] + local TARGET_PATH=3D${1:-${NETCONS_PATH}} + + if [[ ! -d "${TARGET_PATH}" ]] then # in some cases this is called before netcons path is created return fi - if [[ $(cat "${NETCONS_PATH}"/enabled) !=3D 0 ]] + if [[ $(cat "${TARGET_PATH}"/enabled) !=3D 0 ]] then - echo 0 > "${NETCONS_PATH}"/enabled || true + echo 0 > "${TARGET_PATH}"/enabled || true fi # Remove all the keys that got created during the selftest - find "${NETCONS_PATH}/userdata/" -mindepth 1 -type d -delete + find "${TARGET_PATH}/userdata/" -mindepth 1 -type d -delete # Remove the configfs entry - rmdir "${NETCONS_PATH}" + rmdir "${TARGET_PATH}" } =20 function cleanup() { @@ -377,6 +379,29 @@ function check_netconsole_module() { fi } =20 +function wait_target_state() { + local TARGET=3D${1} + local STATE=3D${2} + local TARGET_PATH=3D"${NETCONS_CONFIGFS}"/"${TARGET}" + local ENABLED=3D0 + + if [ "${STATE}" =3D=3D "enabled" ] + then + ENABLED=3D1 + fi + + if [ ! -d "$TARGET_PATH" ]; then + echo "FAIL: Target does not exist." >&2 + exit "${ksft_fail}" + fi + + local CHECK_CMD=3D"grep \"$ENABLED\" \"$TARGET_PATH/enabled\"" + slowwait 2 sh -c "test -n \"\$($CHECK_CMD)\"" || { + 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 000000000000..b9f2d5a7dc59 --- /dev/null +++ b/tools/testing/selftests/drivers/net/netcons_resume.sh @@ -0,0 +1,97 @@ +#!/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 + +function cleanup() { + cleanup_netcons "${NETCONS_CONFIGFS}/cmdline0" + do_cleanup + rmmod netconsole +} + +trap cleanup EXIT + +# 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 + + # 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" + + # 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 + + echo "${BINDMODE} : Test passed" >&2 +done + +trap - EXIT +exit "${ksft_pass}" --=20 2.52.0