Commit 1ab9b5ea authored by David S. Miller's avatar David S. Miller

Merge branch 'ethtool-set_channels-add-a-few-more-checks'

Jakub Kicinski says:

====================
ethtool: set_channels: add a few more checks

There seems to be a few more things we can check in the core before
we call drivers' ethtool_ops->set_channels. Adding the checks to
the core simplifies the drivers. This set only includes changes
to the NFP driver as an example.

There is a small risk in the first patch that someone actually
purposefully accepts a strange configuration without RX or TX
channels, but I couldn't find such a driver in the tree.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents a0c1d0ea 75c36dbb
...@@ -1438,8 +1438,7 @@ static int nfp_net_set_channels(struct net_device *netdev, ...@@ -1438,8 +1438,7 @@ static int nfp_net_set_channels(struct net_device *netdev,
unsigned int total_rx, total_tx; unsigned int total_rx, total_tx;
/* Reject unsupported */ /* Reject unsupported */
if (!channel->combined_count || if (channel->other_count != NFP_NET_NON_Q_VECTORS ||
channel->other_count != NFP_NET_NON_Q_VECTORS ||
(channel->rx_count && channel->tx_count)) (channel->rx_count && channel->tx_count))
return -EINVAL; return -EINVAL;
......
...@@ -129,13 +129,13 @@ int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info) ...@@ -129,13 +129,13 @@ int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info)
{ {
struct nlattr *tb[ETHTOOL_A_CHANNELS_MAX + 1]; struct nlattr *tb[ETHTOOL_A_CHANNELS_MAX + 1];
unsigned int from_channel, old_total, i; unsigned int from_channel, old_total, i;
bool mod = false, mod_combined = false;
struct ethtool_channels channels = {}; struct ethtool_channels channels = {};
struct ethnl_req_info req_info = {}; struct ethnl_req_info req_info = {};
const struct nlattr *err_attr; const struct nlattr *err_attr;
const struct ethtool_ops *ops; const struct ethtool_ops *ops;
struct net_device *dev; struct net_device *dev;
u32 max_rx_in_use = 0; u32 max_rx_in_use = 0;
bool mod = false;
int ret; int ret;
ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb, ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb,
...@@ -170,7 +170,8 @@ int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info) ...@@ -170,7 +170,8 @@ int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info)
ethnl_update_u32(&channels.other_count, ethnl_update_u32(&channels.other_count,
tb[ETHTOOL_A_CHANNELS_OTHER_COUNT], &mod); tb[ETHTOOL_A_CHANNELS_OTHER_COUNT], &mod);
ethnl_update_u32(&channels.combined_count, ethnl_update_u32(&channels.combined_count,
tb[ETHTOOL_A_CHANNELS_COMBINED_COUNT], &mod); tb[ETHTOOL_A_CHANNELS_COMBINED_COUNT], &mod_combined);
mod |= mod_combined;
ret = 0; ret = 0;
if (!mod) if (!mod)
goto out_ops; goto out_ops;
...@@ -193,6 +194,21 @@ int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info) ...@@ -193,6 +194,21 @@ int ethnl_set_channels(struct sk_buff *skb, struct genl_info *info)
goto out_ops; goto out_ops;
} }
/* ensure there is at least one RX and one TX channel */
if (!channels.combined_count && !channels.rx_count)
err_attr = tb[ETHTOOL_A_CHANNELS_RX_COUNT];
else if (!channels.combined_count && !channels.tx_count)
err_attr = tb[ETHTOOL_A_CHANNELS_TX_COUNT];
else
err_attr = NULL;
if (err_attr) {
if (mod_combined)
err_attr = tb[ETHTOOL_A_CHANNELS_COMBINED_COUNT];
ret = -EINVAL;
NL_SET_ERR_MSG_ATTR(info->extack, err_attr, "requested channel counts would result in no RX or TX channel being configured");
goto out_ops;
}
/* ensure the new Rx count fits within the configured Rx flow /* ensure the new Rx count fits within the configured Rx flow
* indirection table settings * indirection table settings
*/ */
......
...@@ -1669,6 +1669,12 @@ static noinline_for_stack int ethtool_set_channels(struct net_device *dev, ...@@ -1669,6 +1669,12 @@ static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
dev->ethtool_ops->get_channels(dev, &curr); dev->ethtool_ops->get_channels(dev, &curr);
if (channels.rx_count == curr.rx_count &&
channels.tx_count == curr.tx_count &&
channels.combined_count == curr.combined_count &&
channels.other_count == curr.other_count)
return 0;
/* ensure new counts are within the maximums */ /* ensure new counts are within the maximums */
if (channels.rx_count > curr.max_rx || if (channels.rx_count > curr.max_rx ||
channels.tx_count > curr.max_tx || channels.tx_count > curr.max_tx ||
...@@ -1676,6 +1682,11 @@ static noinline_for_stack int ethtool_set_channels(struct net_device *dev, ...@@ -1676,6 +1682,11 @@ static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
channels.other_count > curr.max_other) channels.other_count > curr.max_other)
return -EINVAL; return -EINVAL;
/* ensure there is at least one RX and one TX channel */
if (!channels.combined_count &&
(!channels.rx_count || !channels.tx_count))
return -EINVAL;
/* ensure the new Rx count fits within the configured Rx flow /* ensure the new Rx count fits within the configured Rx flow
* indirection table settings */ * indirection table settings */
if (netif_is_rxfh_configured(dev) && if (netif_is_rxfh_configured(dev) &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment