From eecaef6e6fcadc9dba44b9b1cd03f84c2cb3cc90 Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Wed, 3 May 2023 16:49:28 -0700 Subject: [PATCH] modules/mqnic: Add some additional range enforcement Signed-off-by: Alex Forencich --- modules/mqnic/mqnic_ethtool.c | 9 +++++++++ modules/mqnic/mqnic_netdev.c | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/mqnic/mqnic_ethtool.c b/modules/mqnic/mqnic_ethtool.c index eab7cad70..2538ec9a3 100644 --- a/modules/mqnic/mqnic_ethtool.c +++ b/modules/mqnic/mqnic_ethtool.c @@ -161,6 +161,15 @@ static int mqnic_set_channels(struct net_device *ndev, int port_up = priv->port_up; int ret = 0; + if (channel->combined_count || channel->other_count) + return -EINVAL; + + if (priv->rxq_count > mqnic_res_get_count(priv->interface->rxq_res)) + return -EINVAL; + + if (priv->txq_count > mqnic_res_get_count(priv->interface->txq_res)) + return -EINVAL; + rxq_count = channel->rx_count; txq_count = channel->tx_count; diff --git a/modules/mqnic/mqnic_netdev.c b/modules/mqnic/mqnic_netdev.c index 412efa5d8..b91616cb3 100644 --- a/modules/mqnic/mqnic_netdev.c +++ b/modules/mqnic/mqnic_netdev.c @@ -570,8 +570,10 @@ struct net_device *mqnic_create_netdev(struct mqnic_if *interface, int index, in priv->txq_count = min_t(u32, mqnic_res_get_count(interface->txq_res), 256); priv->rxq_count = min_t(u32, mqnic_res_get_count(interface->rxq_res), num_online_cpus()); - priv->tx_ring_size = mqnic_num_txq_entries; - priv->rx_ring_size = mqnic_num_rxq_entries; + priv->tx_ring_size = roundup_pow_of_two(clamp_t(u32, mqnic_num_txq_entries, + MQNIC_MIN_TX_RING_SZ, MQNIC_MAX_TX_RING_SZ)); + priv->rx_ring_size = roundup_pow_of_two(clamp_t(u32, mqnic_num_rxq_entries, + MQNIC_MIN_RX_RING_SZ, MQNIC_MAX_RX_RING_SZ)); init_rwsem(&priv->txq_table_sem); INIT_RADIX_TREE(&priv->txq_table, GFP_KERNEL);