]> www.infradead.org Git - users/hch/misc.git/commitdiff
net: ethtool: fix ioctl confusing drivers about desired HDS user config
authorJakub Kicinski <kuba@kernel.org>
Fri, 21 Feb 2025 02:51:40 +0000 (18:51 -0800)
committerJakub Kicinski <kuba@kernel.org>
Mon, 24 Feb 2025 22:15:42 +0000 (14:15 -0800)
The legacy ioctl path does not have support for extended attributes.
So we issue a GET to fetch the current settings from the driver,
in an attempt to keep them unchanged. HDS is a bit "special" as
the GET only returns on/off while the SET takes a "ternary" argument
(on/off/default). If the driver was in the "default" setting -
executing the ioctl path binds it to on or off, even tho the user
did not intend to change HDS config.

Factor the relevant logic out of the netlink code and reuse it.

Fixes: 87c8f8496a05 ("bnxt_en: add support for tcp-data-split ethtool command")
Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Tested-by: Daniel Xu <dxu@dxuuu.xyz>
Tested-by: Taehee Yoo <ap420073@gmail.com>
Link: https://patch.msgid.link/20250221025141.1132944-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ethtool/common.c
net/ethtool/common.h
net/ethtool/ioctl.c
net/ethtool/rings.c

index d88e9080643b843d18e15a486d8e94cdadbe3b53..b97374b508f6723f8ecb155411db407aec7987f7 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/rtnetlink.h>
 #include <linux/ptp_clock_kernel.h>
 #include <linux/phy_link_topology.h>
+#include <net/netdev_queues.h>
 
 #include "netlink.h"
 #include "common.h"
@@ -771,6 +772,21 @@ int ethtool_check_ops(const struct ethtool_ops *ops)
        return 0;
 }
 
+void ethtool_ringparam_get_cfg(struct net_device *dev,
+                              struct ethtool_ringparam *param,
+                              struct kernel_ethtool_ringparam *kparam,
+                              struct netlink_ext_ack *extack)
+{
+       memset(param, 0, sizeof(*param));
+       memset(kparam, 0, sizeof(*kparam));
+
+       param->cmd = ETHTOOL_GRINGPARAM;
+       dev->ethtool_ops->get_ringparam(dev, param, kparam, extack);
+
+       /* Driver gives us current state, we want to return current config */
+       kparam->tcp_data_split = dev->cfg->hds_config;
+}
+
 static void ethtool_init_tsinfo(struct kernel_ethtool_ts_info *info)
 {
        memset(info, 0, sizeof(*info));
index 58e9e7db06f90d6e41197a88de89da2645aa5348..a1088c2441d0a5658abbb5b0eb77f7d5c821620a 100644 (file)
@@ -51,6 +51,12 @@ int ethtool_check_max_channel(struct net_device *dev,
                              struct ethtool_channels channels,
                              struct genl_info *info);
 int ethtool_check_rss_ctx_busy(struct net_device *dev, u32 rss_context);
+
+void ethtool_ringparam_get_cfg(struct net_device *dev,
+                              struct ethtool_ringparam *param,
+                              struct kernel_ethtool_ringparam *kparam,
+                              struct netlink_ext_ack *extack);
+
 int __ethtool_get_ts_info(struct net_device *dev, struct kernel_ethtool_ts_info *info);
 int ethtool_get_ts_info_by_phc(struct net_device *dev,
                               struct kernel_ethtool_ts_info *info,
index 7609ce2b2c5e2ead90aceab08b6610955914340b..1c3ba2247776bc31a167ea066301efd70e36c534 100644 (file)
@@ -2059,8 +2059,8 @@ static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
 
 static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
 {
-       struct ethtool_ringparam ringparam, max = { .cmd = ETHTOOL_GRINGPARAM };
        struct kernel_ethtool_ringparam kernel_ringparam;
+       struct ethtool_ringparam ringparam, max;
        int ret;
 
        if (!dev->ethtool_ops->set_ringparam || !dev->ethtool_ops->get_ringparam)
@@ -2069,7 +2069,7 @@ static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
        if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
                return -EFAULT;
 
-       dev->ethtool_ops->get_ringparam(dev, &max, &kernel_ringparam, NULL);
+       ethtool_ringparam_get_cfg(dev, &max, &kernel_ringparam, NULL);
 
        /* ensure new ring parameters are within the maximums */
        if (ringparam.rx_pending > max.rx_max_pending ||
index 7839bfd1ac6a0f81e76b32f7b4819ef11033c8cf..aeedd5ec6b8cdfc298042587172d78d0ef3d36a3 100644 (file)
@@ -215,17 +215,16 @@ ethnl_set_rings_validate(struct ethnl_req_info *req_info,
 static int
 ethnl_set_rings(struct ethnl_req_info *req_info, struct genl_info *info)
 {
-       struct kernel_ethtool_ringparam kernel_ringparam = {};
-       struct ethtool_ringparam ringparam = {};
+       struct kernel_ethtool_ringparam kernel_ringparam;
        struct net_device *dev = req_info->dev;
+       struct ethtool_ringparam ringparam;
        struct nlattr **tb = info->attrs;
        const struct nlattr *err_attr;
        bool mod = false;
        int ret;
 
-       dev->ethtool_ops->get_ringparam(dev, &ringparam,
-                                       &kernel_ringparam, info->extack);
-       kernel_ringparam.tcp_data_split = dev->cfg->hds_config;
+       ethtool_ringparam_get_cfg(dev, &ringparam, &kernel_ringparam,
+                                 info->extack);
 
        ethnl_update_u32(&ringparam.rx_pending, tb[ETHTOOL_A_RINGS_RX], &mod);
        ethnl_update_u32(&ringparam.rx_mini_pending,