* [PATCH net-next v3 0/2] netconsole: Populate dynamic entry even if netpoll fails
@ 2024-08-22 11:10 Breno Leitao
2024-08-22 11:10 ` [PATCH net-next v3 1/2] netpoll: Ensure clean state on setup failures Breno Leitao
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Breno Leitao @ 2024-08-22 11:10 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni; +Cc: netdev, linux-kernel
The current implementation of netconsole removes the entry and fails
entirely if netpoll fails to initialize. This approach is suboptimal, as
it prevents reconfiguration or re-enabling of the target through
configfs.
While this issue might seem minor if it were rare, it actually occurs
frequently when the network module is configured as a loadable module.
In such cases, the network is unavailable when netconsole initializes,
causing netpoll to fail. This failure forces users to reconfigure the
target from scratch, discarding any settings provided via the command
line.
The proposed change would keep the target available in configfs, albeit
in a disabled state. This modification allows users to adjust settings
or simply re-enable the target once the network module has loaded,
providing a more flexible and user-friendly solution.
Changelog:
v3:
* Remove patch 2, that was only pr_err() at netconsole (Jakub)
* Rework the "if" loop to be more readable (Jakub)
* Print the cmdline number in the error log (Jakub)
v2:
* Avoid late cleanup, and always returning an np in a clear slate when
failing (Paolo)
* Added another commit to log (pr_err) when netconsole doesn't fail,
avoiding silent failures.
* https://lore.kernel.org/all/20240819103616.2260006-1-leitao@debian.org/
v1:
* https://lore.kernel.org/all/20240809161935.3129104-1-leitao@debian.org/
Breno Leitao (2):
netpoll: Ensure clean state on setup failures
net: netconsole: Populate dynamic entry even if netpoll fails
drivers/net/netconsole.c | 15 +++++++++++----
net/core/netpoll.c | 15 ++++++++++-----
2 files changed, 21 insertions(+), 9 deletions(-)
--
2.43.5
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net-next v3 1/2] netpoll: Ensure clean state on setup failures
2024-08-22 11:10 [PATCH net-next v3 0/2] netconsole: Populate dynamic entry even if netpoll fails Breno Leitao
@ 2024-08-22 11:10 ` Breno Leitao
2024-08-22 11:10 ` [PATCH net-next v3 2/2] net: netconsole: Populate dynamic entry even if netpoll fails Breno Leitao
2024-08-26 16:40 ` [PATCH net-next v3 0/2] " patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Breno Leitao @ 2024-08-22 11:10 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni; +Cc: netdev, linux-kernel, Rik van Riel
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 <pabeni@redhat.com>
Signed-off-by: Breno Leitao <leitao@debian.org>
---
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();
--
2.43.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net-next v3 2/2] net: netconsole: Populate dynamic entry even if netpoll fails
2024-08-22 11:10 [PATCH net-next v3 0/2] netconsole: Populate dynamic entry even if netpoll fails Breno Leitao
2024-08-22 11:10 ` [PATCH net-next v3 1/2] netpoll: Ensure clean state on setup failures Breno Leitao
@ 2024-08-22 11:10 ` Breno Leitao
2024-08-26 16:40 ` [PATCH net-next v3 0/2] " patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Breno Leitao @ 2024-08-22 11:10 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni; +Cc: netdev, linux-kernel, Aijay Adams
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 <aijay@meta.com>
Signed-off-by: Breno Leitao <leitao@debian.org>
---
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;
--
2.43.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v3 0/2] netconsole: Populate dynamic entry even if netpoll fails
2024-08-22 11:10 [PATCH net-next v3 0/2] netconsole: Populate dynamic entry even if netpoll fails Breno Leitao
2024-08-22 11:10 ` [PATCH net-next v3 1/2] netpoll: Ensure clean state on setup failures Breno Leitao
2024-08-22 11:10 ` [PATCH net-next v3 2/2] net: netconsole: Populate dynamic entry even if netpoll fails Breno Leitao
@ 2024-08-26 16:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-08-26 16:40 UTC (permalink / raw)
To: Breno Leitao; +Cc: davem, edumazet, kuba, pabeni, netdev, linux-kernel
Hello:
This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 22 Aug 2024 04:10:46 -0700 you wrote:
> The current implementation of netconsole removes the entry and fails
> entirely if netpoll fails to initialize. This approach is suboptimal, as
> it prevents reconfiguration or re-enabling of the target through
> configfs.
>
> While this issue might seem minor if it were rare, it actually occurs
> frequently when the network module is configured as a loadable module.
>
> [...]
Here is the summary with links:
- [net-next,v3,1/2] netpoll: Ensure clean state on setup failures
https://git.kernel.org/netdev/net-next/c/ae5a0456e0b4
- [net-next,v3,2/2] net: netconsole: Populate dynamic entry even if netpoll fails
https://git.kernel.org/netdev/net-next/c/908ee298c8fb
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-08-26 16:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-22 11:10 [PATCH net-next v3 0/2] netconsole: Populate dynamic entry even if netpoll fails Breno Leitao
2024-08-22 11:10 ` [PATCH net-next v3 1/2] netpoll: Ensure clean state on setup failures Breno Leitao
2024-08-22 11:10 ` [PATCH net-next v3 2/2] net: netconsole: Populate dynamic entry even if netpoll fails Breno Leitao
2024-08-26 16:40 ` [PATCH net-next v3 0/2] " patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).