Skip to content

Commit 9f08ae4

Browse files
committed
Merge branch 'netconsole-populate-dynamic-entry-even-if-netpoll-fails'
Breno Leitao says: ==================== netconsole: Populate dynamic entry even if netpoll fails 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. v2: https://lore.kernel.org/[email protected] v1: https://lore.kernel.org/[email protected] ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents f086d18 + 908ee29 commit 9f08ae4

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

drivers/net/netconsole.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,11 +1258,18 @@ static struct netconsole_target *alloc_param_target(char *target_config,
12581258
goto fail;
12591259

12601260
err = netpoll_setup(&nt->np);
1261-
if (err)
1262-
goto fail;
1263-
1261+
if (err) {
1262+
pr_err("Not enabling netconsole for %s%d. Netpoll setup failed\n",
1263+
NETCONSOLE_PARAM_TARGET_PREFIX, cmdline_count);
1264+
if (!IS_ENABLED(CONFIG_NETCONSOLE_DYNAMIC))
1265+
/* only fail if dynamic reconfiguration is set,
1266+
* otherwise, keep the target in the list, but disabled.
1267+
*/
1268+
goto fail;
1269+
} else {
1270+
nt->enabled = true;
1271+
}
12641272
populate_configfs_item(nt, cmdline_count);
1265-
nt->enabled = true;
12661273

12671274
return nt;
12681275

net/core/netpoll.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -624,12 +624,9 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
624624
const struct net_device_ops *ops;
625625
int err;
626626

627-
np->dev = ndev;
628-
strscpy(np->dev_name, ndev->name, IFNAMSIZ);
629-
630627
if (ndev->priv_flags & IFF_DISABLE_NETPOLL) {
631628
np_err(np, "%s doesn't support polling, aborting\n",
632-
np->dev_name);
629+
ndev->name);
633630
err = -ENOTSUPP;
634631
goto out;
635632
}
@@ -647,7 +644,7 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
647644

648645
refcount_set(&npinfo->refcnt, 1);
649646

650-
ops = np->dev->netdev_ops;
647+
ops = ndev->netdev_ops;
651648
if (ops->ndo_netpoll_setup) {
652649
err = ops->ndo_netpoll_setup(ndev, npinfo);
653650
if (err)
@@ -658,6 +655,8 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
658655
refcount_inc(&npinfo->refcnt);
659656
}
660657

658+
np->dev = ndev;
659+
strscpy(np->dev_name, ndev->name, IFNAMSIZ);
661660
npinfo->netpoll = np;
662661

663662
/* last thing to do is link it to the net device structure */
@@ -675,6 +674,7 @@ EXPORT_SYMBOL_GPL(__netpoll_setup);
675674
int netpoll_setup(struct netpoll *np)
676675
{
677676
struct net_device *ndev = NULL;
677+
bool ip_overwritten = false;
678678
struct in_device *in_dev;
679679
int err;
680680

@@ -739,6 +739,7 @@ int netpoll_setup(struct netpoll *np)
739739
}
740740

741741
np->local_ip.ip = ifa->ifa_local;
742+
ip_overwritten = true;
742743
np_info(np, "local IP %pI4\n", &np->local_ip.ip);
743744
} else {
744745
#if IS_ENABLED(CONFIG_IPV6)
@@ -755,6 +756,7 @@ int netpoll_setup(struct netpoll *np)
755756
!!(ipv6_addr_type(&np->remote_ip.in6) & IPV6_ADDR_LINKLOCAL))
756757
continue;
757758
np->local_ip.in6 = ifp->addr;
759+
ip_overwritten = true;
758760
err = 0;
759761
break;
760762
}
@@ -785,6 +787,9 @@ int netpoll_setup(struct netpoll *np)
785787
return 0;
786788

787789
put:
790+
DEBUG_NET_WARN_ON_ONCE(np->dev);
791+
if (ip_overwritten)
792+
memset(&np->local_ip, 0, sizeof(np->local_ip));
788793
netdev_put(ndev, &np->dev_tracker);
789794
unlock:
790795
rtnl_unlock();

0 commit comments

Comments
 (0)