DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] net/bnxt: fix memory allocation for command response
@ 2021-03-20  6:49 Kalesh A P
  2021-03-22 18:29 ` Ajit Khaparde
  0 siblings, 1 reply; 2+ messages in thread
From: Kalesh A P @ 2021-03-20  6:49 UTC (permalink / raw)
  To: dev; +Cc: ferruh.yigit, ajit.khaparde

From: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>

Driver re-allocates memory for the command response buffer
when the installed firmware version is newer (and has a larger
max response length) than the version of HWRM that was used to
build the PMD.

This change helps to avoid the re-allocation by allocating the
memory for the command response buffer with PAGE_SIZE.

Coverity issue: 366256, 366204, 366180
Fixes: b7778e8a1c00 ("net/bnxt: refactor to properly allocate resources for PF/VF")
Cc: stable@dpdk.org

Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
Reviewed-by: Ajit Kumar Khaparde <ajit.khaparde@broadcom.com>
Reviewed-by: Lance Richardson <lance.richardson@broadcom.com>
---
 drivers/net/bnxt/bnxt_ethdev.c |  2 +-
 drivers/net/bnxt/bnxt_hwrm.c   | 27 ++++-----------------------
 2 files changed, 5 insertions(+), 24 deletions(-)

diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index 3724752..ed2ae45 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -5608,7 +5608,7 @@ static int bnxt_drv_init(struct rte_eth_dev *eth_dev)
 	rc = bnxt_alloc_hwrm_resources(bp);
 	if (rc) {
 		PMD_DRV_LOG(ERR,
-			    "Failed to allocate hwrm resource rc: %x\n", rc);
+			    "Failed to allocate response buffer rc: %x\n", rc);
 		return rc;
 	}
 	rc = bnxt_alloc_leds_info(bp);
diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
index e3a0731..6a70b6e 100644
--- a/drivers/net/bnxt/bnxt_hwrm.c
+++ b/drivers/net/bnxt/bnxt_hwrm.c
@@ -1284,28 +1284,8 @@ int bnxt_hwrm_ver_get(struct bnxt *bp, uint32_t timeout)
 	max_resp_len = rte_le_to_cpu_16(resp->max_resp_len);
 	dev_caps_cfg = rte_le_to_cpu_32(resp->dev_caps_cfg);
 
-	if (bp->max_resp_len != max_resp_len) {
-		sprintf(type, "bnxt_hwrm_" PCI_PRI_FMT,
-			bp->pdev->addr.domain, bp->pdev->addr.bus,
-			bp->pdev->addr.devid, bp->pdev->addr.function);
-
-		rte_free(bp->hwrm_cmd_resp_addr);
-
-		bp->hwrm_cmd_resp_addr = rte_malloc(type, max_resp_len, 0);
-		if (bp->hwrm_cmd_resp_addr == NULL) {
-			rc = -ENOMEM;
-			goto error;
-		}
-		bp->hwrm_cmd_resp_dma_addr =
-			rte_malloc_virt2iova(bp->hwrm_cmd_resp_addr);
-		if (bp->hwrm_cmd_resp_dma_addr == RTE_BAD_IOVA) {
-			PMD_DRV_LOG(ERR,
-			"Unable to map response buffer to physical memory.\n");
-			rc = -ENOMEM;
-			goto error;
-		}
-		bp->max_resp_len = max_resp_len;
-	}
+	RTE_VERIFY(max_resp_len <= bp->max_resp_len);
+	bp->max_resp_len = max_resp_len;
 
 	if ((dev_caps_cfg &
 		HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
@@ -2804,7 +2784,7 @@ int bnxt_alloc_hwrm_resources(struct bnxt *bp)
 
 	sprintf(type, "bnxt_hwrm_" PCI_PRI_FMT, pdev->addr.domain,
 		pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
-	bp->max_resp_len = HWRM_MAX_RESP_LEN;
+	bp->max_resp_len = BNXT_PAGE_SIZE;
 	bp->hwrm_cmd_resp_addr = rte_malloc(type, bp->max_resp_len, 0);
 	if (bp->hwrm_cmd_resp_addr == NULL)
 		return -ENOMEM;
@@ -6057,6 +6037,7 @@ int bnxt_hwrm_poll_ver_get(struct bnxt *bp)
 	int rc = 0;
 
 	bp->max_req_len = HWRM_MAX_REQ_LEN;
+	bp->max_resp_len = BNXT_PAGE_SIZE;
 	bp->hwrm_cmd_timeout = SHORT_HWRM_CMD_TIMEOUT;
 
 	HWRM_PREP(&req, HWRM_VER_GET, BNXT_USE_CHIMP_MB);
-- 
2.10.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dpdk-dev] [PATCH] net/bnxt: fix memory allocation for command response
  2021-03-20  6:49 [dpdk-dev] [PATCH] net/bnxt: fix memory allocation for command response Kalesh A P
@ 2021-03-22 18:29 ` Ajit Khaparde
  0 siblings, 0 replies; 2+ messages in thread
From: Ajit Khaparde @ 2021-03-22 18:29 UTC (permalink / raw)
  To: Kalesh A P; +Cc: dpdk-dev, Ferruh Yigit

[-- Attachment #1: Type: text/plain, Size: 4106 bytes --]

On Fri, Mar 19, 2021 at 11:27 PM Kalesh A P
<kalesh-anakkur.purayil@broadcom.com> wrote:
>
> From: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
>
> Driver re-allocates memory for the command response buffer
> when the installed firmware version is newer (and has a larger
> max response length) than the version of HWRM that was used to
> build the PMD.
>
> This change helps to avoid the re-allocation by allocating the
> memory for the command response buffer with PAGE_SIZE.
>
> Coverity issue: 366256, 366204, 366180
> Fixes: b7778e8a1c00 ("net/bnxt: refactor to properly allocate resources for PF/VF")
> Cc: stable@dpdk.org
>
> Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
> Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
> Reviewed-by: Ajit Kumar Khaparde <ajit.khaparde@broadcom.com>
> Reviewed-by: Lance Richardson <lance.richardson@broadcom.com>
Patch applied to dpdk-next-net-brcm. Thanks

> ---
>  drivers/net/bnxt/bnxt_ethdev.c |  2 +-
>  drivers/net/bnxt/bnxt_hwrm.c   | 27 ++++-----------------------
>  2 files changed, 5 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
> index 3724752..ed2ae45 100644
> --- a/drivers/net/bnxt/bnxt_ethdev.c
> +++ b/drivers/net/bnxt/bnxt_ethdev.c
> @@ -5608,7 +5608,7 @@ static int bnxt_drv_init(struct rte_eth_dev *eth_dev)
>         rc = bnxt_alloc_hwrm_resources(bp);
>         if (rc) {
>                 PMD_DRV_LOG(ERR,
> -                           "Failed to allocate hwrm resource rc: %x\n", rc);
> +                           "Failed to allocate response buffer rc: %x\n", rc);
>                 return rc;
>         }
>         rc = bnxt_alloc_leds_info(bp);
> diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c
> index e3a0731..6a70b6e 100644
> --- a/drivers/net/bnxt/bnxt_hwrm.c
> +++ b/drivers/net/bnxt/bnxt_hwrm.c
> @@ -1284,28 +1284,8 @@ int bnxt_hwrm_ver_get(struct bnxt *bp, uint32_t timeout)
>         max_resp_len = rte_le_to_cpu_16(resp->max_resp_len);
>         dev_caps_cfg = rte_le_to_cpu_32(resp->dev_caps_cfg);
>
> -       if (bp->max_resp_len != max_resp_len) {
> -               sprintf(type, "bnxt_hwrm_" PCI_PRI_FMT,
> -                       bp->pdev->addr.domain, bp->pdev->addr.bus,
> -                       bp->pdev->addr.devid, bp->pdev->addr.function);
> -
> -               rte_free(bp->hwrm_cmd_resp_addr);
> -
> -               bp->hwrm_cmd_resp_addr = rte_malloc(type, max_resp_len, 0);
> -               if (bp->hwrm_cmd_resp_addr == NULL) {
> -                       rc = -ENOMEM;
> -                       goto error;
> -               }
> -               bp->hwrm_cmd_resp_dma_addr =
> -                       rte_malloc_virt2iova(bp->hwrm_cmd_resp_addr);
> -               if (bp->hwrm_cmd_resp_dma_addr == RTE_BAD_IOVA) {
> -                       PMD_DRV_LOG(ERR,
> -                       "Unable to map response buffer to physical memory.\n");
> -                       rc = -ENOMEM;
> -                       goto error;
> -               }
> -               bp->max_resp_len = max_resp_len;
> -       }
> +       RTE_VERIFY(max_resp_len <= bp->max_resp_len);
> +       bp->max_resp_len = max_resp_len;
>
>         if ((dev_caps_cfg &
>                 HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
> @@ -2804,7 +2784,7 @@ int bnxt_alloc_hwrm_resources(struct bnxt *bp)
>
>         sprintf(type, "bnxt_hwrm_" PCI_PRI_FMT, pdev->addr.domain,
>                 pdev->addr.bus, pdev->addr.devid, pdev->addr.function);
> -       bp->max_resp_len = HWRM_MAX_RESP_LEN;
> +       bp->max_resp_len = BNXT_PAGE_SIZE;
>         bp->hwrm_cmd_resp_addr = rte_malloc(type, bp->max_resp_len, 0);
>         if (bp->hwrm_cmd_resp_addr == NULL)
>                 return -ENOMEM;
> @@ -6057,6 +6037,7 @@ int bnxt_hwrm_poll_ver_get(struct bnxt *bp)
>         int rc = 0;
>
>         bp->max_req_len = HWRM_MAX_REQ_LEN;
> +       bp->max_resp_len = BNXT_PAGE_SIZE;
>         bp->hwrm_cmd_timeout = SHORT_HWRM_CMD_TIMEOUT;
>
>         HWRM_PREP(&req, HWRM_VER_GET, BNXT_USE_CHIMP_MB);
> --
> 2.10.1
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-22 18:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-20  6:49 [dpdk-dev] [PATCH] net/bnxt: fix memory allocation for command response Kalesh A P
2021-03-22 18:29 ` Ajit Khaparde

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git