net/hns3: validate requested maximum Rx frame length

When jumbo frame is enabled, the MTU size needs to be modified
based on 'max_rx_pkt_len'. Driver needs to check the validity
of 'max_rx_pkt_len'. And it should be in the range of
HNS3_DEFAULT_FRAME_LEN and HNS3_MAX_FRAME_LEN. Otherwise, it may
cause that the MTU size is inconsistent with jumbo frame offload.

Fixes: 19a3ca4c99cf ("net/hns3: add start/stop and configure operations")
Cc: stable@dpdk.org

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Signed-off-by: Lijun Ou <oulijun@huawei.com>
This commit is contained in:
Huisong Li 2021-02-03 20:23:57 +08:00 committed by Ferruh Yigit
parent ff81c6b7d0
commit b8a67b10ee
2 changed files with 26 additions and 12 deletions

View File

@ -2343,6 +2343,7 @@ hns3_dev_configure(struct rte_eth_dev *dev)
uint16_t nb_rx_q = dev->data->nb_rx_queues;
uint16_t nb_tx_q = dev->data->nb_tx_queues;
struct rte_eth_rss_conf rss_conf;
uint32_t max_rx_pkt_len;
uint16_t mtu;
bool gro_en;
int ret;
@ -2396,12 +2397,18 @@ hns3_dev_configure(struct rte_eth_dev *dev)
* according to the maximum RX packet length.
*/
if (conf->rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
/*
* Security of max_rx_pkt_len is guaranteed in dpdk frame.
* Maximum value of max_rx_pkt_len is HNS3_MAX_FRAME_LEN, so it
* can safely assign to "uint16_t" type variable.
*/
mtu = (uint16_t)HNS3_PKTLEN_TO_MTU(conf->rxmode.max_rx_pkt_len);
max_rx_pkt_len = conf->rxmode.max_rx_pkt_len;
if (max_rx_pkt_len > HNS3_MAX_FRAME_LEN ||
max_rx_pkt_len <= HNS3_DEFAULT_FRAME_LEN) {
hns3_err(hw, "maximum Rx packet length must be greater "
"than %u and less than %u when jumbo frame enabled.",
(uint16_t)HNS3_DEFAULT_FRAME_LEN,
(uint16_t)HNS3_MAX_FRAME_LEN);
ret = -EINVAL;
goto cfg_err;
}
mtu = (uint16_t)HNS3_PKTLEN_TO_MTU(max_rx_pkt_len);
ret = hns3_dev_mtu_set(dev, mtu);
if (ret)
goto cfg_err;

View File

@ -778,6 +778,7 @@ hns3vf_dev_configure(struct rte_eth_dev *dev)
uint16_t nb_rx_q = dev->data->nb_rx_queues;
uint16_t nb_tx_q = dev->data->nb_tx_queues;
struct rte_eth_rss_conf rss_conf;
uint32_t max_rx_pkt_len;
uint16_t mtu;
bool gro_en;
int ret;
@ -825,12 +826,18 @@ hns3vf_dev_configure(struct rte_eth_dev *dev)
* according to the maximum RX packet length.
*/
if (conf->rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
/*
* Security of max_rx_pkt_len is guaranteed in dpdk frame.
* Maximum value of max_rx_pkt_len is HNS3_MAX_FRAME_LEN, so it
* can safely assign to "uint16_t" type variable.
*/
mtu = (uint16_t)HNS3_PKTLEN_TO_MTU(conf->rxmode.max_rx_pkt_len);
max_rx_pkt_len = conf->rxmode.max_rx_pkt_len;
if (max_rx_pkt_len > HNS3_MAX_FRAME_LEN ||
max_rx_pkt_len <= HNS3_DEFAULT_FRAME_LEN) {
hns3_err(hw, "maximum Rx packet length must be greater "
"than %u and less than %u when jumbo frame enabled.",
(uint16_t)HNS3_DEFAULT_FRAME_LEN,
(uint16_t)HNS3_MAX_FRAME_LEN);
ret = -EINVAL;
goto cfg_err;
}
mtu = (uint16_t)HNS3_PKTLEN_TO_MTU(max_rx_pkt_len);
ret = hns3vf_dev_mtu_set(dev, mtu);
if (ret)
goto cfg_err;