forked from Minki/linux
Merge branch 'ethtool-ringparam-upper-bound'
Tariq Toukan says:
====================
ethtool ringparam upper bound
This patchset by Jenny adds sanity checks in ethtool ringparam
operation for input upper bounds, similarly to what's done in
ethtool_set_channels.
The checks are added in patch 1, using a call to get_ringparam
prior to calling set_ringparam NDO.
Patch 2 changes the function's behavior in mlx4_en, so that
it returns an error for out-of-range input, instead of rounding
it to closest valid, similar to mlx5e.
Patch 3 removes the upper bound checks in mlx5e_ethtool_set_ringparam
as it becomes redundant.
Series generated against net-next commit:
f66faae2f8
Merge branch 'ipv6-ipv4-nexthop-align'
====================
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
commit
a67c01e209
@ -1094,12 +1094,21 @@ static int mlx4_en_set_ringparam(struct net_device *dev,
|
||||
if (param->rx_jumbo_pending || param->rx_mini_pending)
|
||||
return -EINVAL;
|
||||
|
||||
if (param->rx_pending < MLX4_EN_MIN_RX_SIZE) {
|
||||
en_warn(priv, "%s: rx_pending (%d) < min (%d)\n",
|
||||
__func__, param->rx_pending,
|
||||
MLX4_EN_MIN_RX_SIZE);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (param->tx_pending < MLX4_EN_MIN_TX_SIZE) {
|
||||
en_warn(priv, "%s: tx_pending (%d) < min (%lu)\n",
|
||||
__func__, param->tx_pending,
|
||||
MLX4_EN_MIN_TX_SIZE);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
rx_size = roundup_pow_of_two(param->rx_pending);
|
||||
rx_size = max_t(u32, rx_size, MLX4_EN_MIN_RX_SIZE);
|
||||
rx_size = min_t(u32, rx_size, MLX4_EN_MAX_RX_SIZE);
|
||||
tx_size = roundup_pow_of_two(param->tx_pending);
|
||||
tx_size = max_t(u32, tx_size, MLX4_EN_MIN_TX_SIZE);
|
||||
tx_size = min_t(u32, tx_size, MLX4_EN_MAX_TX_SIZE);
|
||||
|
||||
if (rx_size == (priv->port_up ? priv->rx_ring[0]->actual_size :
|
||||
priv->rx_ring[0]->size) &&
|
||||
|
@ -296,7 +296,6 @@ int mlx5e_ethtool_set_ringparam(struct mlx5e_priv *priv,
|
||||
struct mlx5e_channels new_channels = {};
|
||||
u32 rx_pending_wqes;
|
||||
u32 min_rq_size;
|
||||
u32 max_rq_size;
|
||||
u8 log_rq_size;
|
||||
u8 log_sq_size;
|
||||
u32 num_mtts;
|
||||
@ -315,8 +314,6 @@ int mlx5e_ethtool_set_ringparam(struct mlx5e_priv *priv,
|
||||
|
||||
min_rq_size = mlx5e_rx_wqes_to_packets(priv, rq_wq_type,
|
||||
1 << mlx5_min_log_rq_size(rq_wq_type));
|
||||
max_rq_size = mlx5e_rx_wqes_to_packets(priv, rq_wq_type,
|
||||
1 << mlx5_max_log_rq_size(rq_wq_type));
|
||||
rx_pending_wqes = mlx5e_packets_to_rx_wqes(priv, rq_wq_type,
|
||||
param->rx_pending);
|
||||
|
||||
@ -326,12 +323,6 @@ int mlx5e_ethtool_set_ringparam(struct mlx5e_priv *priv,
|
||||
min_rq_size);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (param->rx_pending > max_rq_size) {
|
||||
netdev_info(priv->netdev, "%s: rx_pending (%d) > max (%d)\n",
|
||||
__func__, param->rx_pending,
|
||||
max_rq_size);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
num_mtts = MLX5E_REQUIRED_MTTS(rx_pending_wqes);
|
||||
if (priv->channels.params.rq_wq_type == MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ &&
|
||||
@ -347,12 +338,6 @@ int mlx5e_ethtool_set_ringparam(struct mlx5e_priv *priv,
|
||||
1 << MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (param->tx_pending > (1 << MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE)) {
|
||||
netdev_info(priv->netdev, "%s: tx_pending (%d) > max (%d)\n",
|
||||
__func__, param->tx_pending,
|
||||
1 << MLX5E_PARAMS_MAXIMUM_LOG_SQ_SIZE);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
log_rq_size = order_base_2(rx_pending_wqes);
|
||||
log_sq_size = order_base_2(param->tx_pending);
|
||||
|
@ -1693,14 +1693,23 @@ 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;
|
||||
struct ethtool_ringparam ringparam, max = { .cmd = ETHTOOL_GRINGPARAM };
|
||||
|
||||
if (!dev->ethtool_ops->set_ringparam)
|
||||
if (!dev->ethtool_ops->set_ringparam || !dev->ethtool_ops->get_ringparam)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
|
||||
return -EFAULT;
|
||||
|
||||
dev->ethtool_ops->get_ringparam(dev, &max);
|
||||
|
||||
/* ensure new ring parameters are within the maximums */
|
||||
if (ringparam.rx_pending > max.rx_max_pending ||
|
||||
ringparam.rx_mini_pending > max.rx_mini_max_pending ||
|
||||
ringparam.rx_jumbo_pending > max.rx_jumbo_max_pending ||
|
||||
ringparam.tx_pending > max.tx_max_pending)
|
||||
return -EINVAL;
|
||||
|
||||
return dev->ethtool_ops->set_ringparam(dev, &ringparam);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user