Subject: Re: [PATCH net] net: avoid race between device unregistration and set_channels

From: Jakub Kicinski <[email-masked]>
Date: Tue, 14 Jan 2025 11:24:01 -0800

On Mon, 13 Jan 2025 17:18:40 +0100 Antoine Tenart wrote:
> This is because unregister_netdevice_many_notify might run before
> set_channels (both are under rtnl). 

But that is very bad, not at all sane. The set call should not proceed
once dismantle begins.

How about this?

diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 849c98e637c6..913c8e329a06 100644
--- a/net/ethtool/netlink.c
+++ b/net/ethtool/netlink.c
@@ -90,7 +90,7 @@ int ethnl_ops_begin(struct net_device *dev)
                pm_runtime_get_sync(dev->dev.parent);
 
        if (!netif_device_present(dev) ||
-           dev->reg_state == NETREG_UNREGISTERING) {
+           dev->reg_state > NETREG_REGISTERED) {
                ret = -ENODEV;
                goto err;
        }