From nobody Tue Dec 2 01:27:35 2025 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 8F2132D73A9 for ; Fri, 21 Nov 2025 12:49:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763729363; cv=none; b=JT0nrqIKEVE34UyiwzPedKbffkuBYxv7KKQ2tGpTgoYdAXQM8xUynt6LKuM1n3Qs2r+tS1+HGddLrMlNwDneEU60puPlujjKYz5as6xhctXL0SZJBH6mZbcNq8mwWPmSAMrSPRzP3ZbI1wZhJeIdSMA1bb7sQ0hjejgQzxb5mVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763729363; c=relaxed/simple; bh=xTW7lVbfJsgnlziO9m7HRTBaTgvYhjTEK5XGbQnoB3Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C+jZG+EoLBZ+HfjbMGdA9rj9nfM4oUeB5iepw0vbVk4iL0jW0ZWoGSnKrvvXTVSc5nTipzoIFNz+XhrkRwtrhzNjWQLgAPCssTm+O/gxqXa8Zuf1Hsuks9StnHANhkgJdD5YTh9OOARQwoifebre8gqtERjM8SI0niWoFkyClD4= 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=SuSyy081; arc=none smtp.client-ip=209.85.214.169 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="SuSyy081" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2953e415b27so23506145ad.2 for ; Fri, 21 Nov 2025 04:49:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763729361; x=1764334161; 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=uKBmUb8EWfQ3VixqXwZwtOjhnNqHJe7y4QanLPyxD5w=; b=SuSyy081RDHOKYo9u3icd9+cCB4iEvbdDcMvZGeOEWRBNJ0FL/GOaViCx4/AJOQrzX VQvcdps3MO7lw53crA0CudtCHlZ1f8r0CrVc4IGKfmwsmooZJzZ7PYSPF8ErlvRTR5rC xN6DEO2mC9DIod9kN9zpI+HJQbCQbQ/RqWdMbRwjXimF7a9scy4pvu/zTesFhlOMHYNq zilws2IYLnlBnA7A3KjO9vGciegwen1mYv9Q0wBnuuMQGAGpIi1w8U3orHrJEqJabUF7 GNC3t3exv9EtL1WaiLp698RTCYIZIjIMPJDr0M1ta9HfKi+SbEzPzcBzmM/ctSXJpYOC p6pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763729361; x=1764334161; 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=uKBmUb8EWfQ3VixqXwZwtOjhnNqHJe7y4QanLPyxD5w=; b=e3kZFd70ETaszkFSvwfe/WX4R6RMprV7CH/2AVWmKm9BDRbQ6jJTwpuzpmLnKDD8Q/ Kn3JQJ65XPnjflYMvZrrSA/n7U7TwFfQRfH0KEW8OHQoG3M7vjn9OWnl2D02oVDq7eC2 CdYj/iCtO25xjycAfNueH0O5SasLZ5RAXDA+2UEGMSVCrmxR8oRQZiox6intNOkrVRmn VxrQDqzX3+6jL5bSDehiKiYG5X/zYmo+6kwxQO7/nSSlibC+ajTZ/yib3s3wpHfBIlqm +X5XbbfB6bvg+wEdiILPzwPrBYYryVK7a8SXljMjrUsSz/JTZUl3Qm0xxt+4dTsJdsM4 Tvxg== X-Forwarded-Encrypted: i=1; AJvYcCV21u7rrXpBxz8zjz6YENALda4Ct2zgMuRDDMfs2eJNV7IHFfUB6kY7S1jjxe9jOF8HuEYfGw7+1Rzxmuk=@vger.kernel.org X-Gm-Message-State: AOJu0YxaWwFDcGxx+HC80Vt1xaf9LT9B+D90iv0rljzsjE47YLzvGPTX hC2VeGZSeJg8hJtsEdQzSS07JPjjWPsvtwdU43ocgo4K/i6xb22ZPqdL X-Gm-Gg: ASbGncv/uhmxDq4ehgOvLowCTiWjtuDJ+KIpI7hdJImH3yHAMy4EMO1+P/lVndVlEum pn7DP3m+t1K9qh7Ef/NJ1vrZVy+8KsB7UQpF8h/LlBm/x7bn73Uir1LM1Agq/Ouk28+cw1kXFwW mD3y1q+zDPAr4PhcyFe56vgmTuA/8/QIGNYNgC5hEZ7eZyKepJLFVZ5sIOoY+6voR06uIxza8zj HN1spQT5rotfM8uAXUaXVl1Q9JKxfggNecd7cw5+DjsEieNH0HgjFvIw6+j+eEgJHfcMkDUlI8d j6Y499xnVPSnIyaMGSVRK/4HGPGFiXjo/QbLcVRE09lfuNEucveqRd0UQQmqdHgwyqvwsfwGBZa +3eCe8ogSUOMRMUttgciWUgqJYiZAnSEozKF9OXTqcv9M5CCag4A5HQok3WEpRPZDQh0+2Z/pLt aiU3Nw8Mcku3dKliV9 X-Google-Smtp-Source: AGHT+IGADjPBSv6dneXmHvy/d7ImNW4K6lxe2fy+G/Ozmk9OtVRsRVjcF0a8edFY+XOXLca6s+ACgQ== X-Received: by 2002:a17:903:2c06:b0:297:fc22:3a9f with SMTP id d9443c01a7336-29b6bf19f1dmr29423045ad.38.1763729360830; Fri, 21 Nov 2025 04:49:20 -0800 (PST) Received: from [192.168.15.94] ([2804:7f1:ebc3:6e1:12e1:8eff:fe46:88b8]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29b5b274752sm56644045ad.75.2025.11.21.04.49.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Nov 2025 04:49:20 -0800 (PST) From: Andre Carvalho Date: Fri, 21 Nov 2025 12:49:00 +0000 Subject: [PATCH net-next v6 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: <20251121-netcons-retrigger-v6-1-9c03f5a2bd6f@gmail.com> References: <20251121-netcons-retrigger-v6-0-9c03f5a2bd6f@gmail.com> In-Reply-To: <20251121-netcons-retrigger-v6-0-9c03f5a2bd6f@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=1763729347; l=747; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=BLduFEel2At1ZpRoHzUB/43M6t0wpDLHJLh+eokOBeA=; b=i5LMsfARwRqneqwPou9ysaSmPXgBprcP+Cdxs4zWJpbgkFhrfOS1RNzxP4zJ9iujoEomejMWo TKx/4fNVTYbDBn+xFqIHIFbB4/zBHsT8jC7e3G5y4sHcD3GQNroRnUP 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 9cb4dfc242f5..e2ec09f238a0 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -119,6 +119,11 @@ enum sysdata_feature { MAX_SYSDATA_ITEMS =3D 4, }; =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 01:27:35 2025 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 BAFE53126C5 for ; Fri, 21 Nov 2025 12:49:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763729369; cv=none; b=ane3QWaS/enkT7viuntt+U0GAiNgi2xqGOYkKyo0BmdloTiCI4JLVLkxoSqWMUOuY0sXkeRIbT7MBhU+qtpwuxwaLQiE6qDf4xG+6+kiReaxhRK6FaTKgriQtxtgHTWW/IOjTleYYkYtVzahf5DQZZx4mswgPydvAoDbrR6bCG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763729369; c=relaxed/simple; bh=943o/E3WhvuTJbGcZYEZLtSogyGbkwqMFYHMQzSvjCQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HtPI86Z86LySqVen6V1nLt/8YTyBrZqk7VJ/WjAbH0oX16rfcb16tBGNeEREdwSzZCD6bA14m5WYrq0DoYQqfCbsmD+foEu9hkaGUbKZx4reb7jU//89yRSCwsydRCDLF1jv/0c4/pLFWNUthxzrKTyTaTx4CMYtimvcbY3Djtw= 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=Lu9wWn16; arc=none smtp.client-ip=209.85.214.176 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="Lu9wWn16" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2984dfae043so18367135ad.0 for ; Fri, 21 Nov 2025 04:49:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763729367; x=1764334167; 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=XOi063mzQTa4JvkotZ6ma8LlWFlm5oJE+mks/V5WdV8=; b=Lu9wWn16PVB6a9HoxOwq5W6bKhvhTF3aj3Spc33BeHpTWNRVYQ2corj3IPAKX84LLj Ea67JUHp7QYtttIQvje6OmkM7OjUOPzGlZ4VwLg7+SrPW+3FI8EA7ATCkX7XlzTN1sAE 6JYREnbkVKTTRvWGYBOVPOE37ACs7Jo//z1IRNqhyGkIhoeOXDLLJnAa+2/OZW7UPGvJ 96A7Ga6epPN3AXSNYcs7cUyfjiCQZvRpD7YkvKLe9geAdebfq6knNmdQZVqtrTGD4DsO Gw2k1Yduq50gZLQWMw/PakySb4i6AxVZFRpQB+jovCYDN22OQmDN9+It5+9n1L9jX2qc +lSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763729367; x=1764334167; 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=XOi063mzQTa4JvkotZ6ma8LlWFlm5oJE+mks/V5WdV8=; b=vkOCG8Q61VWsq2DvYZHwPYGpB9MIUSUSrVFNNvmSjUN09T9Ub++3makhea2zlCsiQg o65zOOg7nbIgTdTYO65GrCdYtvihIor/37F+dZQpt/AhipEb8+MVf21pIa/X4TUPgzg4 cdKndtu4CEUG7Pc1PvdhhcP4a/Dc+9NnCUkbQ3OmYQEC8AO38WK+9rLth3bilP2iEf55 gltkL71LGXxNgtflHRbppEgDo2IXy5f9CBeGy0hY6XsgI/vQhkvz67H0wnE2ZPfnosyt daTmqZHozsQ1zipiOJj5YpBfqDbxvfOtGa+rxcvdv/OebRAgUf+dz0StRQxvDoboY1QH 5r2A== X-Forwarded-Encrypted: i=1; AJvYcCW77nb2oS//+L5cZDcKjyebHryhkNVIs8gYf3XxYRW1Qf1/i1espPAXrb6OP1iLQfBleMMhpA0qHo92s4g=@vger.kernel.org X-Gm-Message-State: AOJu0YwWm037B8hyYVYOodsTk3tq3tBo6JAgmMFNzlBej/Mx34qGIN+S prLX7h0cLsxRnrqcFKnOvPT+a2tLknWHWFSfF1RrIUkgbfMP0/H62ind X-Gm-Gg: ASbGncvlhEHBSNhnrkR2l9ENJF+/Jr0WMYs0UWyP8eDNfy+gIztF6aCZh6XxU1XAVhv g3mD3pnt+nCzYITbEAamOsYUG6bmIRSyK/6bnBqB3g25MaESQwABI4Ei4gvdmcuftNk5RrBepPY BIzxlbmzH8mg+knDkaYDR2D23DcAvtE3UA0n0JN1SY7f4iO6EagD2CoCRSepkn9VZQ+lCuFVgha rReq8oERZWMFcWELSdPJEHQj6qydhTtKw8C7kFY+s11hURhQov76rqSg64L/56RDE5J1siCygL9 YKNv+/4RgJBlLMwc2rn9Ud8uYQh1aJAE/Un7+DbCQMBKQp3Sx20/rNaD6tIyYyzEmLkqmMnh/uB YxIypF9azQq7TwqQNJPqG4/80Qq5O9j2O8eQIo9ySJAl+RLAXttB4XRuTh8ofH9XqdSC1VhQ2Q4 xTH2YkorRfe0ehg81k X-Google-Smtp-Source: AGHT+IHZjut3DLUP7fZbcavzB1Ab59YsXD493M8mvRve2OHuj9woOxQFvnDZ0vVYtMS9y3UkFMvdhQ== X-Received: by 2002:a17:903:40cf:b0:295:105:c87d with SMTP id d9443c01a7336-29b6c571898mr26619785ad.32.1763729366824; Fri, 21 Nov 2025 04:49:26 -0800 (PST) Received: from [192.168.15.94] ([2804:7f1:ebc3:6e1:12e1:8eff:fe46:88b8]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29b5b274752sm56644045ad.75.2025.11.21.04.49.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Nov 2025 04:49:26 -0800 (PST) From: Andre Carvalho Date: Fri, 21 Nov 2025 12:49:01 +0000 Subject: [PATCH net-next v6 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: <20251121-netcons-retrigger-v6-2-9c03f5a2bd6f@gmail.com> References: <20251121-netcons-retrigger-v6-0-9c03f5a2bd6f@gmail.com> In-Reply-To: <20251121-netcons-retrigger-v6-0-9c03f5a2bd6f@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=1763729347; l=8901; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=943o/E3WhvuTJbGcZYEZLtSogyGbkwqMFYHMQzSvjCQ=; b=1HmsMOFjyC4EL1ONKMO0gUZ6h9k6a8xv0LG/leSVTvarJv5GXc1J14zSO1Kr33ZWmyYhtl+SF M1QmWAvoBb7C8+03LdQJI2K3v/VzlgOsmJDl8W8J9qx2PUEXmuNoah1 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 Reviewed-by: Breno Leitao --- 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 e2ec09f238a0..b21ecea60d52 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -135,12 +135,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. @@ -170,7 +170,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; @@ -262,6 +262,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; } @@ -280,7 +281,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 @@ -403,7 +404,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) @@ -570,8 +571,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); @@ -580,9 +581,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 @@ -615,16 +617,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 */ @@ -653,7 +655,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; @@ -680,7 +682,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; @@ -704,7 +706,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); @@ -725,7 +727,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; @@ -747,7 +749,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; @@ -770,7 +772,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; @@ -795,7 +797,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; @@ -830,7 +832,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; @@ -1326,7 +1328,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; } @@ -1725,7 +1727,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); } @@ -1745,7 +1748,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 @@ -1901,7 +1905,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 01:27:35 2025 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 67BB233EB11 for ; Fri, 21 Nov 2025 12:49:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763729375; cv=none; b=ubMFL5OZjqfWDcPRWKNB9GQynIUl1rHIJt3XoiJuQCXPXtGFCj76qt5VOd2WUdCFU2bRkhemehObGbHgWvPkxQo+VPdBzbsJRSHkPDkfq9szRoEB+Th9q1Ijv9pE0Rl5B/UkUoJ7A/XiNc86+CTCYQkrS3owmDSMox9/8LTT5NI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763729375; c=relaxed/simple; bh=oZlSrKc5HSf8OTgk8Y9zCO1ND/6B7m7anVTBiZTQDCE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jBJxQbGcACEN1mdbOMCeTKeWTsHtaGoFQfzWlQJYLtPQe6MZegF/FmatSlJjMAR+RJ+lxNhccV7gI2QqKwnf4ToGEpaHuHKUL3k+OUYHBiq/Q5F0+nU+sIJeFcstfMrcy1S840VsO1hKBFHgj+qZdwTx5r7IzlSAP33nERcppP8= 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=T/FulqFM; arc=none smtp.client-ip=209.85.214.180 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="T/FulqFM" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-29558061c68so26428905ad.0 for ; Fri, 21 Nov 2025 04:49:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763729373; x=1764334173; 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=J4d7URFdeCPYu3U6zdfTOnUzmMHd/kT6rS033v+6Sa8=; b=T/FulqFMD4RkJ8LEIhvIFbMjsEgbbCMtjeAWXHQTg2boHHy2v7YXbJBXQ+DQiAE/Fy efV2gv/VF2t9407tqcGVphyYQgt/GTxXP/9Rk71WCBaCXLl3+c2Xnw4p6ufwXYhcSuh0 Xm8PMcmjzxsmoRTlLVAnt2/VMjriXa2Kx87nOwa8dGPPnmECp91B1PmX5Oh9XyUjLAJr ue13kdTPi6NUN2kYPEfU5/ZWrZv29J7sxQIdzUmk7vZmlitHWr63TIYxFYVw7fF6QwBc myF51NMyKQJkA+XiP1QE3xiIN104iGeN5HbqeUva5+49chY6z7skduj6LHRky0ED+5hJ FiGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763729373; x=1764334173; 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=J4d7URFdeCPYu3U6zdfTOnUzmMHd/kT6rS033v+6Sa8=; b=OJ+tLIgAmsasocjHPWo7SOILyHrrTYUkpe6PtTQvuoqL2s/BB/XWCMqoEVYY/rLL4w 5/vn730MO65laasxsm+b6UF72wwcudessRtTSGyGw7z7yPnAHqFy+d20NZjlAS4jFPtt vuAHhqxqRzX0r0kWKIqZgMFQDdSTUGDOJR8WscFIIaz1otBerC3aD2CSXrAiRFbv67lq MWf7C55IBohqVSSOuE2UwyhuTKVNvTDQAMepWuGI6DD4wiLDIPnxxeyTeWwZcT6m4MEE AX+KFCG/0t+Ito4rE7o2LXVnddrddO5wHW6TFezmxIi//qWdcu1V7uorY/yLr3fyFrO+ GaZg== X-Forwarded-Encrypted: i=1; AJvYcCVaGac3RW2Cj2qo1nphxbUtcsNjFu2QNZTM9E0o6Yy5isEWkzjbvmMxeVQyLUvWlQTrLD+b/NjnwqCLlJk=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9nJcGxk9r6n6iXpaI4YC5mrcUByDiewaEsmpp5SCwgzMV2+my NbNkVnzScywoD46RS0QC+exx19i+uLaaz9EOyAdaxaxBLnNmjmi7y+r8 X-Gm-Gg: ASbGncukycUXnL/3/aThYNJpnNblYaf2rBxhqIa8OwSaNrmkc+OXBE73JG/Bp4z10hn E1bQNjh4F9Rrq8mOEvQUZCi5EgplbJyw7HfouXG+67EF1Cw0C+wc6Y9qaVvd5LlcacEU9NMr3aL kitO0a3qhrT+tf+idJB+ODke58zCBo1LUOB7mUuCyG7AJjwS1yRa1kP9KbBZkpAy5j93u5MjXxu kadg7pXRLLSZQMHnTC6mBIw06trmBt8UMv6MAqUn0YH7XN02Fx/rKkPuT4QkW/DrY13ZmUGGu91 9crjVruNpL3o8yNWl1d72SR/Xv6pDCfS9FITihyjPLnsKgEnuN6qxEhxcCpbLLu5aMv4wEIXARu +TR1C8tUgLfa6SnS2XLTMEvjO5Tl0wZdMNfuIIaQgOMH78TxSFWud7kdHVqqUK07JwWZ2UIhDpc JwOomRkLTh9TgW2R+7 X-Google-Smtp-Source: AGHT+IGjQY393wbPoRfTrgThZUbRXZ8/OuQlRpf2ILVHZvNAbrSjcZJduZN+Y2ALKisyM9NoH+L+Vg== X-Received: by 2002:a17:902:ccce:b0:297:dd30:8f07 with SMTP id d9443c01a7336-29b6bf806bcmr29078625ad.50.1763729372688; Fri, 21 Nov 2025 04:49:32 -0800 (PST) Received: from [192.168.15.94] ([2804:7f1:ebc3:6e1:12e1:8eff:fe46:88b8]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29b5b274752sm56644045ad.75.2025.11.21.04.49.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Nov 2025 04:49:32 -0800 (PST) From: Andre Carvalho Date: Fri, 21 Nov 2025 12:49:02 +0000 Subject: [PATCH net-next v6 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: <20251121-netcons-retrigger-v6-3-9c03f5a2bd6f@gmail.com> References: <20251121-netcons-retrigger-v6-0-9c03f5a2bd6f@gmail.com> In-Reply-To: <20251121-netcons-retrigger-v6-0-9c03f5a2bd6f@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=1763729347; l=2409; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=Bc0ee9DYK1oiSRrahxYGeDv2Y4gYudwUsG3FQq7nt2Y=; b=mUF4xs6Q425NCVpPCEL2wiPv3fqPZv2HRqxhVxxflU19F4YinKcf+E/B/ctw676dwZSgMMBni b80Fvf7Oud1BObj0an3VZA1S+MxE8rbrVuQ8R3OelHwa1uezyuAywYT 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 b21ecea60d52..7a1e5559fc0d 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -122,6 +122,7 @@ enum sysdata_feature { enum target_state { STATE_DISABLED, STATE_ENABLED, + STATE_DEACTIVATED, }; =20 /** @@ -580,6 +581,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) { @@ -1445,10 +1454,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 01:27:35 2025 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09C9734104D for ; Fri, 21 Nov 2025 12:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763729385; cv=none; b=SEgLkG1nkf/lweRPh23NkIjd8i4nwEItFr9cook53Yp7p+soEpWs47f/30YOV+Uv5RpIvJwlpvDceZiNnmkJ0s7co+TOMNNLydrfMEj+FZrYSR/iXiNl7KqecoavEG7X5+1Bi80y2TmVr1LD9CodMpx+9Cv9ULH2QAGujiuxsMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763729385; c=relaxed/simple; bh=tIo1ihv/ZyMpAJc0ot8C6fX6nMW0iP+Uvvhx7LuMZ44=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XFrYosxpaVbDo6Fx8Qtd5XwUR5NJI2Nu+iimEr5bIYhzz5NXUW7BDQbVBNSzgq60zzmSjc8U1E2CsRawmwZ80vQQFrFhisTgaN6juLbV37DFYYTxwALvrtGNaxjgGc8bP7dqHtVB0c386D97rVev3diU91ylfxWGr/1k+z5opJs= 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=biaJ3Diq; arc=none smtp.client-ip=209.85.214.181 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="biaJ3Diq" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2955623e6faso24098435ad.1 for ; Fri, 21 Nov 2025 04:49:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763729381; x=1764334181; 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=twzFm4emRBl3ugSRkzw7asEAUSM3TYyx9FDMT6PC5iU=; b=biaJ3Diq33bHMFmJwPDdugQqnVcldmHj48SUpkGwP9cBX44kelo4J1SpeohSiLeKN1 5JP7JKp82cFDgnmJy6a/Bexhz251IjPCgiVpbosuUr0W7V1VrXb0V+eXQ7SCeSOdacYb sspm+WvmMXjfk7l4RKXGaymwPuKH+hG0/mP3SiL3kax5v1UiUSQyrYON9alrJ31C9D5Q pGYQk7LYdHIGtrWxPQphC9rrwtKmOS0psMuPhXDczITVzj1+XWuJOfJWCZlzPlJm3dQK /FOzAuLlkBxPk1dS28kCbIUI0ege9tC1tlyh9HjBn1BPTIX3CAbTc+w4ETYLxv1CrSrU 0zng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763729381; x=1764334181; 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=twzFm4emRBl3ugSRkzw7asEAUSM3TYyx9FDMT6PC5iU=; b=vfX64fkFo/7svUT6OE7DbyfHuTe934qjutw2/+qsZ9cj5TInBKGPAvUo1GTQEbprZ7 3nNuAF/0p9gi1TOb5QdUBWhZhT96w57nx2V/9Cy4gl/EvlI3eoh+WtU6S36WYm3csIyE QXM4ZoZ5cJAtM2SBvc/80ZOy/eAt1IqbfUaEBbz/pqSiDu4VBoc0ZDeIwQYY3FuPb3hG dLsSenNCZEVNVXZ7iygrddAXcJQl1/8XNNYxLEvaNZqaUHspg9pn0ms3DVeSaUjL4Io2 T4UDER8tcWIxPKrh1hf3zvR2plt5iaFHuu4wBKe5sAvwajM6bmymsx6ucq1laBtakoLO Fm6Q== X-Forwarded-Encrypted: i=1; AJvYcCVK+mSsDE9u7ToEJ90djp2uRXCDOtcRkHZnelLNZQ6am484Itd4SpWcLbfb5TasQ7u1yaMXCKxi6bZ4bsM=@vger.kernel.org X-Gm-Message-State: AOJu0Yy66HFjyYkQQF71eAZ4JHz47CO4Cp0Je0GOym16jORJYaS6rBeF KqVD0ihAodpR4JYVUYeamBLfNdAsT2GEptfr5zuqzkv4LBDYd4Y0Cta+ X-Gm-Gg: ASbGncv121DgKTRnG3sIB+HB0IhhgtCTvNvCE9CmxK5gMykAUQD0E7xA+laqC7K0K2+ tcuZbGa9f2tPXKFnxUZBImcsI+wCwa4NSHif/3iUoezjjybDfmRj4yi5ynlpVDOYhKjqnHC889/ tW/4bH4grgKH9NQv+gRzI/WmX61/NedpMgtL+eWqYO7Fc4oUTt7WEsdoFB56iySVFh8PaGkOnbG odP/FhRXh4gfFTda665lwA1724yj1eKBsI/zl7B/SlktY7XdkQ8Y/ISr8ZtXZUvstVaypy0S/Uh v41XyP7bu9mZXC7wrV3GGM15/kNplqddONT15Rzg/UYSP0CBfDsmPqpusRk5BUSekaSlRjXFRkO Gxy3O0xe4M0/f0ua+K5cvu6WIBEImXRxasD3zzv20vO58wD2/z58mKBPjvQ+LH7dlpyZuaoXmU2 A4c9X/GIyG12rPFfJpcHbks5Y9/WY= X-Google-Smtp-Source: AGHT+IGj77Q4G5JSki9S4sZ8Icq5LKswCcfsVmzZ4PWYrvCxJ5l+h8U/aERHvy3ALA3r4RXKHnDHxA== X-Received: by 2002:a17:903:3c43:b0:298:d056:612d with SMTP id d9443c01a7336-29b6be94938mr22324195ad.9.1763729380475; Fri, 21 Nov 2025 04:49:40 -0800 (PST) Received: from [192.168.15.94] ([2804:7f1:ebc3:6e1:12e1:8eff:fe46:88b8]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29b5b274752sm56644045ad.75.2025.11.21.04.49.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Nov 2025 04:49:38 -0800 (PST) From: Andre Carvalho Date: Fri, 21 Nov 2025 12:49:03 +0000 Subject: [PATCH net-next v6 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: <20251121-netcons-retrigger-v6-4-9c03f5a2bd6f@gmail.com> References: <20251121-netcons-retrigger-v6-0-9c03f5a2bd6f@gmail.com> In-Reply-To: <20251121-netcons-retrigger-v6-0-9c03f5a2bd6f@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=1763729347; l=5495; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=tIo1ihv/ZyMpAJc0ot8C6fX6nMW0iP+Uvvhx7LuMZ44=; b=zbjtqpOX9o5U0GkqJgVJlnbHBLhjIh8nqad7fOQ13wlXV4HAGAD3T7HFcOXghvJsZwDvVE4uv XHLHfN1MMLnCLFshp+OlsI00UfQVVS6yuuLys9obU7n97H0nwS2Vgwe 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 7a1e5559fc0d..2dcdfb44a9e0 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -138,10 +138,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. @@ -1430,17 +1434,76 @@ static int prepare_sysdata(struct netconsole_target= *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); @@ -1469,6 +1532,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); @@ -1492,6 +1560,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 01:27:35 2025 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 AFDC93358BE for ; Fri, 21 Nov 2025 12:49:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763729392; cv=none; b=eEF/FaQrHedQE9ErMBbWIp7ah1GR0rp8lBAbU/KJoXlbfCzqxolcBQ5x4XwkLuijqRi4Ybqc/QgUzhEpE1/ygs+mfx284F8x4fFxCB8CklEGVNX94lA2FyPAP31lzHfaJHGJiS4aQeboVLwWO5Hfj6qCE38lBuA/tqNzFgWK8Tg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763729392; c=relaxed/simple; bh=kqZWWvJE2+BeMA1UYo5eXs9VYYbgCijUdgI80CmasXY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sz54XuUUM07cBoy1RiUAYOzcaeQ5qhjmicv+OkCZAbqhm37yiGBoiOf/57PFc82IebWl/rOqpe0WIGsq6P0jLrA1nx5C2m3eERpqynptQZHy1oVuPKmHe8uJ0s1wC/by1hG2E2ATKk9+HVIAyq/pvfNEPYuycimuvqZAJu92vkw= 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=GwPoXU4T; arc=none smtp.client-ip=209.85.214.175 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="GwPoXU4T" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-298145fe27eso30231125ad.1 for ; Fri, 21 Nov 2025 04:49:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763729387; x=1764334187; 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=gF9C7FxbCivSMf9nGQZ0aSleELaDVv0y36UrYer9UB0=; b=GwPoXU4T9XVozuqYfOoNXmHThFlsU3ozSNNX3pRVj9KFhDP6gHBhBFsChZ2inWODUj t6LWCF2PsosAm1YAn/Py23gGH4wsnl9BvDhvIZWBxZWvs0LSHhQ/m+kS5Ye2TeM+fgU9 /pUJ7iF7XaRyxi8GX2QGBeP6HVi57isoHlIbBI29JHwqNBuTBtQeIFFtOPptBQvV0cQA 7TgNOxvJdsFqrGV+gnSiug7mSZI1Z0SmW7HbWsx19QAOQ15QBDEJ9byW8rqAUEgwh5qT Lo93Gj2jRj+m94o+yK3OP/ejlzpuYUOuLbL2+F61MSNbIs42ZM9+3vWzur6v0y7bIx/K 2jZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763729387; x=1764334187; 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=gF9C7FxbCivSMf9nGQZ0aSleELaDVv0y36UrYer9UB0=; b=plMf1Nas2Kb5rn6dGokFzu/D9hbIa8IDhp6uK+zXIYq4vNuujPNJZmXv0/prg1IbAJ zUj9OwklVAduYXuXt7jbSq7r+MCZztZfoMDh3wpW0Zu4wAXewCq0lSq07hfqn/2l51I0 EotyLmbz0J+XsslMSIDhuhxAHiaFptEpQwlOmsSeYnuaReLI9MRf0HyNEvWN2Zljny5r 747qRZehuiW/eDfpeAJZ/cY+vX4/+3ahWKqk6RW+gcKl58W0EqQfpiDYLQ8o7Y7Pz4Y7 QkRAoZrw5e0Iru4vX+urk+118V4AzERRfZwZIm9xFENzYmYiXwD1XX7LV02TpDE7ipcf nz5w== X-Forwarded-Encrypted: i=1; AJvYcCW+9/vBYOkrX7v2mhmbwz01udRLJKJ1OlgoDmmx2beSoAH7M0gNhTDv3I+1vYiRyANyDdMKcjRjDPDmID4=@vger.kernel.org X-Gm-Message-State: AOJu0Yzb5nagxX7cA8anmhyQi/rOjakCqt6pbgil7pngJ5Iw4TRLCRPL A3bMOW1xAbqy46C5ZWAfCPxEaJXAXcfYyIFGFAD9QmkohzVzjpnWcf5+ X-Gm-Gg: ASbGncsCvpuOGn1xBPuzacz5Cs7xmUYISpO4yUqymLb5AmAEiewnfLBDI+r4ZCFznpE bPQhSUDxepn4m1/+Xh5K7BOTclHUQLUXJ2TWYYQLeAgzvtt1JTxv1HsRIE1xFcZlDtVKN7itqlf eHxTi1yXMI4wRRHGnYqOReUU5BlAiW1SHah9Aw4ca2Gk/F+yAu8sO1UE3oNMeWdNaxxBTKW73Ff EFhp58OAj0n3VudZE7B0Rpdvpi0f5duw3bq4JtBWy0v++LYHOHQaltXuAcCF7TKICqKDoBNauuj reFrKrdakzEb+eSsIpSr0WM1/0jkgSRcUDUQgBh8nGYIJEE906AmlL4pytMHWLgPmc1/MIWPw9Q LgHAvgoylmr0j7s1SsGpldZXCMxI3W6kdQkhxqzDgtxXOTRIPGi/aRxHlBrTJqwtCZcsZd6GZmh 6NmZ2HZ0QGvYMagThg X-Google-Smtp-Source: AGHT+IHC1JKCnOMw2/59gVa3PzETifZLbtyEkz7OvXPEbgtliFAPF8mvCgwW3K4qg9F31SlZY/UqKQ== X-Received: by 2002:a17:903:3a8b:b0:297:d6c0:90b3 with SMTP id d9443c01a7336-29b6beadf83mr27153795ad.23.1763729387458; Fri, 21 Nov 2025 04:49:47 -0800 (PST) Received: from [192.168.15.94] ([2804:7f1:ebc3:6e1:12e1:8eff:fe46:88b8]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29b5b274752sm56644045ad.75.2025.11.21.04.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Nov 2025 04:49:45 -0800 (PST) From: Andre Carvalho Date: Fri, 21 Nov 2025 12:49:04 +0000 Subject: [PATCH net-next v6 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: <20251121-netcons-retrigger-v6-5-9c03f5a2bd6f@gmail.com> References: <20251121-netcons-retrigger-v6-0-9c03f5a2bd6f@gmail.com> In-Reply-To: <20251121-netcons-retrigger-v6-0-9c03f5a2bd6f@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=1763729347; l=6488; i=asantostc@gmail.com; s=20250807; h=from:subject:message-id; bh=kqZWWvJE2+BeMA1UYo5eXs9VYYbgCijUdgI80CmasXY=; b=F4eRXdV9/TNvUYcbyjJRYBp0LlIie9BlHhDWtIquDYSOMzHak1y/VOOp2UcEPqH9t3KyguWXd sKugMmTzSGHA7IcythsNF+g+JrllWZ6M9+uiM/oO17AwX3gcz7RklCE 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 f5c71d993750..3eba569b3366 100644 --- a/tools/testing/selftests/drivers/net/Makefile +++ b/tools/testing/selftests/drivers/net/Makefile @@ -19,6 +19,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