From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D8F77438F5; Thu, 18 Jan 2024 19:05:49 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AC9C94029F; Thu, 18 Jan 2024 19:05:49 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 7489840295; Thu, 18 Jan 2024 19:05:48 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1004) id 8FF0A20DFD82; Thu, 18 Jan 2024 10:05:47 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8FF0A20DFD82 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxonhyperv.com; s=default; t=1705601147; bh=2AO7xLtaBVYXfQyIcJEBzSzsNeEgBBJH9tTbL1BO9pk=; h=From:To:Cc:Subject:Date:From; b=jEfxvE7J3n9f8SqvysxbK2D68zhvyOpiWg/F6pZ73k+pa2BRDhCwR2MuHltlSEI/o 7t8l/t44GqQZKOJobw+z2n2mhx/3Ty+WiqFGolKjG+/5WonM9WcUd4Z7oJOF2DXEDF vNGBQdhiZkAmEccxjvfT+qhdSbt56VHfktsKGz0s= From: longli@linuxonhyperv.com To: Ferruh Yigit , Andrew Rybchenko Cc: dev@dpdk.org, Long Li , stable@dpdk.org Subject: [PATCH] net/mana: prevent values overflow returned from RDMA layer Date: Thu, 18 Jan 2024 10:05:37 -0800 Message-Id: <1705601137-4235-1-git-send-email-longli@linuxonhyperv.com> X-Mailer: git-send-email 1.8.3.1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Long Li The device capabilities reported from RDMA layer are in int. Those values can overflow with the data types defined in dev_info_get(). Fix this by doing a upper bound before returning those values. Fixes: 517ed6e2d590 ("net/mana: add basic driver with build environment") Cc: stable@dpdk.org Signed-off-by: Long Li --- drivers/net/mana/mana.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/net/mana/mana.c b/drivers/net/mana/mana.c index 781ed76139..471beed19e 100644 --- a/drivers/net/mana/mana.c +++ b/drivers/net/mana/mana.c @@ -296,8 +296,8 @@ mana_dev_info_get(struct rte_eth_dev *dev, dev_info->min_rx_bufsize = MIN_RX_BUF_SIZE; dev_info->max_rx_pktlen = MANA_MAX_MTU + RTE_ETHER_HDR_LEN; - dev_info->max_rx_queues = priv->max_rx_queues; - dev_info->max_tx_queues = priv->max_tx_queues; + dev_info->max_rx_queues = RTE_MIN(priv->max_rx_queues, UINT16_MAX); + dev_info->max_tx_queues = RTE_MIN(priv->max_tx_queues, UINT16_MAX); dev_info->max_mac_addrs = MANA_MAX_MAC_ADDR; dev_info->max_hash_mac_addrs = 0; @@ -338,16 +338,20 @@ mana_dev_info_get(struct rte_eth_dev *dev, /* Buffer limits */ dev_info->rx_desc_lim.nb_min = MIN_BUFFERS_PER_QUEUE; - dev_info->rx_desc_lim.nb_max = priv->max_rx_desc; + dev_info->rx_desc_lim.nb_max = RTE_MIN(priv->max_rx_desc, UINT16_MAX); dev_info->rx_desc_lim.nb_align = MIN_BUFFERS_PER_QUEUE; - dev_info->rx_desc_lim.nb_seg_max = priv->max_recv_sge; - dev_info->rx_desc_lim.nb_mtu_seg_max = priv->max_recv_sge; + dev_info->rx_desc_lim.nb_seg_max = + RTE_MIN(priv->max_recv_sge, UINT16_MAX); + dev_info->rx_desc_lim.nb_mtu_seg_max = + RTE_MIN(priv->max_recv_sge, UINT16_MAX); dev_info->tx_desc_lim.nb_min = MIN_BUFFERS_PER_QUEUE; - dev_info->tx_desc_lim.nb_max = priv->max_tx_desc; + dev_info->tx_desc_lim.nb_max = RTE_MIN(priv->max_tx_desc, UINT16_MAX); dev_info->tx_desc_lim.nb_align = MIN_BUFFERS_PER_QUEUE; - dev_info->tx_desc_lim.nb_seg_max = priv->max_send_sge; - dev_info->rx_desc_lim.nb_mtu_seg_max = priv->max_recv_sge; + dev_info->tx_desc_lim.nb_seg_max = + RTE_MIN(priv->max_send_sge, UINT16_MAX); + dev_info->tx_desc_lim.nb_mtu_seg_max = + RTE_MIN(priv->max_send_sge, UINT16_MAX); /* Speed */ dev_info->speed_capa = RTE_ETH_LINK_SPEED_100G; @@ -1385,9 +1389,9 @@ mana_probe_port(struct ibv_device *ibdev, struct ibv_device_attr_ex *dev_attr, priv->max_mr = dev_attr->orig_attr.max_mr; priv->max_mr_size = dev_attr->orig_attr.max_mr_size; - DRV_LOG(INFO, "dev %s max queues %d desc %d sge %d", + DRV_LOG(INFO, "dev %s max queues %d desc %d sge %d mr %lu", name, priv->max_rx_queues, priv->max_rx_desc, - priv->max_send_sge); + priv->max_send_sge, priv->max_mr_size); rte_eth_copy_pci_info(eth_dev, pci_dev); -- 2.25.1