From patchwork Thu Aug 22 11:10:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13773217 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC0C918453F; Thu, 22 Aug 2024 11:11:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724325067; cv=none; b=s2+Epgs01bx3MNlBtBUbcRQBEj9A0l4WgLkiqosCf8I6cOtI1ocG1ZHBkMfejmnMVTUWmVHH/nyClZmE4JHbjBIfJqXy/0ge92gc1Hrmf8oROO7YP5gnkIsB5F5NKuseb4G7Po1hwwtPFIcnT9Y1lTD9PppPIgK9SbQClY8X83o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724325067; c=relaxed/simple; bh=M/PmFDpdZFaBf7+pWLNAYBuslNFTP9mFmrdhr859Z+0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kZbdnS7m2oaFKhTRWrxW142X9Mj5lcp50zRdwa060GoGZ6O4hAoiDAas5o3SxHuXlnuTsICAxLSnP1TTlI4UxZOqwkLQRysv6ujTFkm3rN0pRz9KaEUkp9sLldezfmjKXWi6TW0KkJtlbsEmBBozwnmNnjQMooV4AasJ/xk7N8w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a7ab5fc975dso82341366b.1; Thu, 22 Aug 2024 04:11:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724325064; x=1724929864; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XUXyWsZ9L+lxzJt/JKaoXYfJk6aufjVbNH6bOrUE/QY=; b=ndkhTZMxJcFJxXVQ8ddoimArSBdyY3Rojwmi/N/EdMoeGZwPtbOhp6okCh5a1DNelc EiEG4nPcTyOpjCfpbTONlMQRrxPGsXXqNhwrI0JEQX2J1xemSt26GN1iWAMsXgHT/RJM DB6N6lQgQsJbqexKjqv1sMFhSWsDMhFwWhD2jXzfRz5Q1yeI1nyTr7hbVJrso3LO4ns9 T9apErpmZzsEdvOCTdWKPkzQj427n/P8362m36K+WPux8qVo58xEra/xjSmHzSc6uNc9 JtY8K4wbqa/RHeYtyS/oujHSj3dlRLfur4+GNz6vS7DiQ15UrzsUQLDca50rtItT3f4q zQrw== X-Forwarded-Encrypted: i=1; AJvYcCX9YHIFpkdAoSwy7By9aBIglvAO7l2AASa5gDhrALRHymb9Lijvk/rT81TG5qdDzja7ZnZABObwElyKTeE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz3hqvgaf4O9Q6XqmQiNE/UFqziobbaGBcp/3ItbUYmJ+iqrZ1r JlHSW0Sk8pCg+IFrFAZWld++cKCVh/FU73Sl9Tk6hk48konVby+u X-Google-Smtp-Source: AGHT+IGdlMAV8iQTUrF/ulPlsHCFNyCUOE/hLu5HPUO4KineJYFOE6PhVFVuSf4v1mXj1tsnchqkuw== X-Received: by 2002:a17:907:3f24:b0:a86:86f2:f3f1 with SMTP id a640c23a62f3a-a8686f2f635mr269638666b.27.1724325063438; Thu, 22 Aug 2024 04:11:03 -0700 (PDT) Received: from localhost (fwdproxy-lla-005.fbsv.net. [2a03:2880:30ff:5::face:b00c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a868f2200bcsm104736266b.4.2024.08.22.04.11.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 04:11:02 -0700 (PDT) From: Breno Leitao To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Rik van Riel Subject: [PATCH net-next v3 1/2] netpoll: Ensure clean state on setup failures Date: Thu, 22 Aug 2024 04:10:47 -0700 Message-ID: <20240822111051.179850-2-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240822111051.179850-1-leitao@debian.org> References: <20240822111051.179850-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Modify netpoll_setup() and __netpoll_setup() to ensure that the netpoll structure (np) is left in a clean state if setup fails for any reason. This prevents carrying over misconfigured fields in case of partial setup success. Key changes: - np->dev is now set only after successful setup, ensuring it's always NULL if netpoll is not configured or if netpoll_setup() fails. - np->local_ip is zeroed if netpoll setup doesn't complete successfully. - Added DEBUG_NET_WARN_ON_ONCE() checks to catch unexpected states. - Reordered some operations in __netpoll_setup() for better logical flow. These changes improve the reliability of netpoll configuration, since it assures that the structure is fully initialized or totally unset. Suggested-by: Paolo Abeni Signed-off-by: Breno Leitao --- net/core/netpoll.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/net/core/netpoll.c b/net/core/netpoll.c index a58ea724790c..647db1e45548 100644 --- a/net/core/netpoll.c +++ b/net/core/netpoll.c @@ -626,12 +626,9 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev) const struct net_device_ops *ops; int err; - np->dev = ndev; - strscpy(np->dev_name, ndev->name, IFNAMSIZ); - if (ndev->priv_flags & IFF_DISABLE_NETPOLL) { np_err(np, "%s doesn't support polling, aborting\n", - np->dev_name); + ndev->name); err = -ENOTSUPP; goto out; } @@ -649,7 +646,7 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev) refcount_set(&npinfo->refcnt, 1); - ops = np->dev->netdev_ops; + ops = ndev->netdev_ops; if (ops->ndo_netpoll_setup) { err = ops->ndo_netpoll_setup(ndev, npinfo); if (err) @@ -660,6 +657,8 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev) refcount_inc(&npinfo->refcnt); } + np->dev = ndev; + strscpy(np->dev_name, ndev->name, IFNAMSIZ); npinfo->netpoll = np; /* last thing to do is link it to the net device structure */ @@ -677,6 +676,7 @@ EXPORT_SYMBOL_GPL(__netpoll_setup); int netpoll_setup(struct netpoll *np) { struct net_device *ndev = NULL; + bool ip_overwritten = false; struct in_device *in_dev; int err; @@ -741,6 +741,7 @@ int netpoll_setup(struct netpoll *np) } np->local_ip.ip = ifa->ifa_local; + ip_overwritten = true; np_info(np, "local IP %pI4\n", &np->local_ip.ip); } else { #if IS_ENABLED(CONFIG_IPV6) @@ -757,6 +758,7 @@ int netpoll_setup(struct netpoll *np) !!(ipv6_addr_type(&np->remote_ip.in6) & IPV6_ADDR_LINKLOCAL)) continue; np->local_ip.in6 = ifp->addr; + ip_overwritten = true; err = 0; break; } @@ -787,6 +789,9 @@ int netpoll_setup(struct netpoll *np) return 0; put: + DEBUG_NET_WARN_ON_ONCE(np->dev); + if (ip_overwritten) + memset(&np->local_ip, 0, sizeof(np->local_ip)); netdev_put(ndev, &np->dev_tracker); unlock: rtnl_unlock(); From patchwork Thu Aug 22 11:10:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13773218 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D015F184559; Thu, 22 Aug 2024 11:11:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724325069; cv=none; b=nz5PbEn59b73/GJZ0rBXk2pA8x5aOIDP2NuLlDvD1hG49kXw775h6f8FlEmRPa/d3IxnIkizdo/gHIdVWfdIYKduVyojcjddWCTN2kQEMUL/G7QFgQ8dg6XhOKmKMBbsi7m3zKuwMLP2YnsEJ+N5ny6ALgk/VaYbYIzFJt3I2iE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724325069; c=relaxed/simple; bh=AK/RADRaNEcV+njaXGREya+0xoBG1DLSBupzD9CJ2gQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SRPS8cbD7Ex3yqTxQuAH8kfSxEl6XIzuFhLzW5rrtYMSqdBVk0S+Vk/W/RbiAtThcGAx9auaDN39cpqktCko7c0nf/2ruyf/L4HiyfaK6dEhRLXeQkMiv7lA0UErT2GrrprVgSe7PHY5RNE3rVXI3NFesOVGiHIvaWC94ehg0gg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5bf006f37daso1138829a12.1; Thu, 22 Aug 2024 04:11:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724325066; x=1724929866; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7aJgFwXL8yYu3Ta7WXwhw8U8Fneee8uRNrJ2/htuey8=; b=uOAjmGxjgifcsrcSZoba99gSJqAb9Wuvf88kq3sssTNbtPDaDUXVriorg4j9kL59/R ITK9JRSug06U3Avqz/5pSEZxUerqnUtwez/NFMaPj3saH6suPXkZXmiLOkMX6wN4boXF cqbyrujbWuHCGxxWydqVBN0i+GjQRyP1f1I0UDsrxQMc363wIzfa9yow+8nIs4H8/34O A/lq23FztzUheoX0FpcecpZy1bAcxUoWmsfiDrta411Dq9YaW/5BYsW24N7cS4J5BF1U cprfFmXdoDPPEuZT7vnC8uHHnvdYVk6VG+3ACwa6W7lwtLP346BlY9wqVqVnPDcpwRHw oinQ== X-Forwarded-Encrypted: i=1; AJvYcCUMCErgeUHSNAZpH5XnrnqUQhvHj5N2z8EB7tu/YL4JxvSTQ+3hXvSjQIPr0G8i8vjMgb7UfVHr44babWA=@vger.kernel.org X-Gm-Message-State: AOJu0YzMFhTIjg4LFDimFTVUjUZmECQswzRhLon3H3rKy+1hIx2khF25 KMHL3+F8INTcCi/9qll3OHbeFbYSu5FEluVv4Jydg8LFAVlfsXa/ X-Google-Smtp-Source: AGHT+IEXvb1JKvKR6a2ucE1kEQX9BJckT6JZiCBzT+sMEzhhyy/GkakP9jv5P8Jbo4D7pmyJqyrlEg== X-Received: by 2002:a05:6402:4305:b0:5be:c92d:b893 with SMTP id 4fb4d7f45d1cf-5bf2c04bc84mr2309949a12.15.1724325065411; Thu, 22 Aug 2024 04:11:05 -0700 (PDT) Received: from localhost (fwdproxy-lla-011.fbsv.net. [2a03:2880:30ff:b::face:b00c]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c04a3ca017sm822339a12.24.2024.08.22.04.11.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 04:11:04 -0700 (PDT) From: Breno Leitao To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Aijay Adams Subject: [PATCH net-next v3 2/2] net: netconsole: Populate dynamic entry even if netpoll fails Date: Thu, 22 Aug 2024 04:10:48 -0700 Message-ID: <20240822111051.179850-3-leitao@debian.org> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240822111051.179850-1-leitao@debian.org> References: <20240822111051.179850-1-leitao@debian.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Currently, netconsole discards targets that fail during initialization, causing two issues: 1) Inconsistency between target list and configfs entries * user pass cmdline0, cmdline1. If cmdline0 fails, then cmdline1 becomes cmdline0 in configfs. 2) Inability to manage failed targets from userspace * If user pass a target that fails with netpoll (interface not loaded at netcons initialization time, such as interface is a module), then the target will not exist in the configfs, so, user cannot re-enable or modify it from userspace. Failed targets are now added to the target list and configfs, but remain disabled until manually enabled or reconfigured. This change does not change the behaviour if CONFIG_NETCONSOLE_DYNAMIC is not set. CC: Aijay Adams Signed-off-by: Breno Leitao --- drivers/net/netconsole.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index 72384c1ecc5c..01cf33fa7503 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1258,11 +1258,18 @@ static struct netconsole_target *alloc_param_target(char *target_config, goto fail; err = netpoll_setup(&nt->np); - if (err) - goto fail; - + if (err) { + pr_err("Not enabling netconsole for %s%d. Netpoll setup failed\n", + NETCONSOLE_PARAM_TARGET_PREFIX, cmdline_count); + if (!IS_ENABLED(CONFIG_NETCONSOLE_DYNAMIC)) + /* only fail if dynamic reconfiguration is set, + * otherwise, keep the target in the list, but disabled. + */ + goto fail; + } else { + nt->enabled = true; + } populate_configfs_item(nt, cmdline_count); - nt->enabled = true; return nt;