Skip to content

Commit 32ad1f7

Browse files
committed
net: provide pending ring configuration in net_device
Record the pending configuration in net_device struct. ethtool core duplicates the current config and the specific handlers (for now just ringparam) can modify it. Reviewed-by: Michael Chan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 743dea7 commit 32ad1f7

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

include/linux/netdevice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,12 @@ struct net_device {
24132413

24142414
/** @cfg: net_device queue-related configuration */
24152415
struct netdev_config *cfg;
2416+
/**
2417+
* @cfg_pending: same as @cfg but when device is being actively
2418+
* reconfigured includes any changes to the configuration
2419+
* requested by the user, but which may or may not be rejected.
2420+
*/
2421+
struct netdev_config *cfg_pending;
24162422
struct ethtool_netdev_state *ethtool;
24172423

24182424
/* protected by rtnl_lock */

net/core/dev.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11546,6 +11546,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
1154611546
dev->cfg = kzalloc(sizeof(*dev->cfg), GFP_KERNEL_ACCOUNT);
1154711547
if (!dev->cfg)
1154811548
goto free_all;
11549+
dev->cfg_pending = dev->cfg;
1154911550

1155011551
napi_config_sz = array_size(maxqs, sizeof(*dev->napi_config));
1155111552
dev->napi_config = kvzalloc(napi_config_sz, GFP_KERNEL_ACCOUNT);
@@ -11615,6 +11616,7 @@ void free_netdev(struct net_device *dev)
1161511616
return;
1161611617
}
1161711618

11619+
WARN_ON(dev->cfg != dev->cfg_pending);
1161811620
kfree(dev->cfg);
1161911621
kfree(dev->ethtool);
1162011622
netif_free_tx_queues(dev);

net/ethtool/netlink.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22

3+
#include <net/netdev_queues.h>
34
#include <net/sock.h>
45
#include <linux/ethtool_netlink.h>
56
#include <linux/phy_link_topology.h>
@@ -692,19 +693,33 @@ static int ethnl_default_set_doit(struct sk_buff *skb, struct genl_info *info)
692693
dev = req_info.dev;
693694

694695
rtnl_lock();
696+
dev->cfg_pending = kmemdup(dev->cfg, sizeof(*dev->cfg),
697+
GFP_KERNEL_ACCOUNT);
698+
if (!dev->cfg_pending) {
699+
ret = -ENOMEM;
700+
goto out_tie_cfg;
701+
}
702+
695703
ret = ethnl_ops_begin(dev);
696704
if (ret < 0)
697-
goto out_rtnl;
705+
goto out_free_cfg;
698706

699707
ret = ops->set(&req_info, info);
700-
if (ret <= 0)
708+
if (ret < 0)
709+
goto out_ops;
710+
711+
swap(dev->cfg, dev->cfg_pending);
712+
if (!ret)
701713
goto out_ops;
702714
ethtool_notify(dev, ops->set_ntf_cmd, NULL);
703715

704716
ret = 0;
705717
out_ops:
706718
ethnl_ops_complete(dev);
707-
out_rtnl:
719+
out_free_cfg:
720+
kfree(dev->cfg_pending);
721+
out_tie_cfg:
722+
dev->cfg_pending = dev->cfg;
708723
rtnl_unlock();
709724
out_dev:
710725
ethnl_parse_header_dev_put(&req_info);

net/ethtool/rings.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,11 @@ ethnl_set_rings(struct ethnl_req_info *req_info, struct genl_info *info)
294294
return -EINVAL;
295295
}
296296

297+
dev->cfg_pending->hds_config = kernel_ringparam.tcp_data_split;
298+
dev->cfg_pending->hds_thresh = kernel_ringparam.hds_thresh;
299+
297300
ret = dev->ethtool_ops->set_ringparam(dev, &ringparam,
298301
&kernel_ringparam, info->extack);
299-
if (!ret) {
300-
dev->cfg->hds_config = kernel_ringparam.tcp_data_split;
301-
dev->cfg->hds_thresh = kernel_ringparam.hds_thresh;
302-
}
303-
304302
return ret < 0 ? ret : 1;
305303
}
306304

0 commit comments

Comments
 (0)