net: ethtool: require drivers to set supported_coalesce_params
authorJakub Kicinski <kuba@kernel.org>
Mon, 16 Mar 2020 20:47:12 +0000 (13:47 -0700)
committerDavid S. Miller <davem@davemloft.net>
Wed, 18 Mar 2020 03:56:58 +0000 (20:56 -0700)
Now that all in-tree drivers have been updated we can
make the supported_coalesce_params mandatory.

To save debugging time in case some driver was missed
(or is out of tree) add a warning when netdev is registered
with set_coalesce but without supported_coalesce_params.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Michal Kubecek <mkubecek@suse.cz>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/ethtool.h
net/core/dev.c
net/ethtool/common.c
net/ethtool/ioctl.c

index be355f37337d7de31c1e8ad7b1ad98dfe3c436cb..c1d379bf6ee1542eb420c83dc672a4c8f8ae3e77 100644 (file)
@@ -458,6 +458,8 @@ struct ethtool_ops {
                                         struct ethtool_stats *, u64 *);
 };
 
+int ethtool_check_ops(const struct ethtool_ops *ops);
+
 struct ethtool_rx_flow_rule {
        struct flow_rule        *rule;
        unsigned long           priv[0];
index d84541c2444640cc9ef2de40421212c13e360784..021e18251465cf218bb41d6bdbe7298e6c3259ea 100644 (file)
@@ -9283,6 +9283,10 @@ int register_netdevice(struct net_device *dev)
        BUG_ON(dev->reg_state != NETREG_UNINITIALIZED);
        BUG_ON(!net);
 
+       ret = ethtool_check_ops(dev->ethtool_ops);
+       if (ret)
+               return ret;
+
        spin_lock_init(&dev->addr_list_lock);
        lockdep_set_class(&dev->addr_list_lock, &dev->addr_list_lock_key);
 
index 0b22741b2f8f703e1e796c629095b0441aa97ee0..dab047eec94322337298e8b524228ab26ef0ed90 100644 (file)
@@ -289,3 +289,14 @@ out:
        kfree(indir);
        return ret;
 }
+
+int ethtool_check_ops(const struct ethtool_ops *ops)
+{
+       if (WARN_ON(ops->set_coalesce && !ops->supported_coalesce_params))
+               return -EINVAL;
+       /* NOTE: sufficiently insane drivers may swap ethtool_ops at runtime,
+        * the fact that ops are checked at registration time does not
+        * mean the ops attached to a netdev later on are sane.
+        */
+       return 0;
+}
index 258840b19fb5c3317dd869dcecfd8f9d246d7936..3852a58d7f95b3e19b8ae4e0f095894fff603d6c 100644 (file)
@@ -1519,9 +1519,6 @@ ethtool_set_coalesce_supported(struct net_device *dev,
        u32 supported_params = dev->ethtool_ops->supported_coalesce_params;
        u32 nonzero_params = 0;
 
-       if (!supported_params)
-               return true;
-
        if (coalesce->rx_coalesce_usecs)
                nonzero_params |= ETHTOOL_COALESCE_RX_USECS;
        if (coalesce->rx_max_coalesced_frames)