diff mbox series

[net,v2] octeontx2-af: Initialize bitmap arrays.

Message ID 20240129052319.4093083-1-rkannoth@marvell.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net,v2] octeontx2-af: Initialize bitmap arrays. | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success SINGLE THREAD; Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 0 of 0 maintainers
netdev/build_clang success Errors and warnings before: 1081 this patch: 1081
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1088 this patch: 1088
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 117 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-01-31--00-00 (tests: 711)

Commit Message

Ratheesh Kannoth Jan. 29, 2024, 5:23 a.m. UTC
kmalloc_array() without __GFP_ZERO flag does not initialize
memory to zero. This causes issues with bitmap.
Use bitmap_zalloc() API to fix this issue.

Fixes: dd7842878633 ("octeontx2-af: Add new devlink param to configure maximum usable NIX block LFs")
Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com>

ChangeLogs:
v1 -> v2: Used bitmap_zalloc() API.
v0 -> v1: Removed devm_kcalloc()._
---
 .../net/ethernet/marvell/octeontx2/af/rvu.h   | 10 ++--
 .../ethernet/marvell/octeontx2/af/rvu_npc.c   | 48 ++++++++-----------
 2 files changed, 26 insertions(+), 32 deletions(-)

Comments

Brett Creeley Jan. 29, 2024, 5:13 p.m. UTC | #1
On 1/28/2024 9:23 PM, Ratheesh Kannoth wrote:
> Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
> 
> 
> kmalloc_array() without __GFP_ZERO flag does not initialize
> memory to zero. This causes issues with bitmap.
> Use bitmap_zalloc() API to fix this issue.
> 
> Fixes: dd7842878633 ("octeontx2-af: Add new devlink param to configure maximum usable NIX block LFs")
> Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com>
> 
> ChangeLogs:
> v1 -> v2: Used bitmap_zalloc() API.
> v0 -> v1: Removed devm_kcalloc()._
> ---
>   .../net/ethernet/marvell/octeontx2/af/rvu.h   | 10 ++--
>   .../ethernet/marvell/octeontx2/af/rvu_npc.c   | 48 ++++++++-----------
>   2 files changed, 26 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h b/drivers/net/ethernet/marvell/octeontx2/af/rvu.h
> index 43be37dd1f32..679bd6e87066 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu.h
> @@ -184,11 +184,11 @@ struct npc_mcam {
>          unsigned long   *bmap_reverse;  /* Reverse bitmap, bmap_entries => 0 */
>          u16     bmap_entries;   /* Number of unreserved MCAM entries */
>          u16     bmap_fcnt;      /* MCAM entries free count */
> -       u16     *entry2pfvf_map;
> -       u16     *entry2cntr_map;
> -       u16     *cntr2pfvf_map;
> -       u16     *cntr_refcnt;
> -       u16     *entry2target_pffunc;
> +       unsigned long   *entry2pfvf_map;
> +       unsigned long   *entry2cntr_map;
> +       unsigned long   *cntr2pfvf_map;
> +       unsigned long   *cntr_refcnt;
> +       unsigned long   *entry2target_pffunc;

I'm not sure you want all of these at bitmaps? It was recommended to use 
bitmap_zalloc, but that was specifically for the bitmaps.

>          u8      keysize;        /* MCAM keysize 112/224/448 bits */
>          u8      banks;          /* Number of MCAM banks */
>          u8      banks_per_entry;/* Number of keywords in key */
> diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
> index 167145bdcb75..367f842e365d 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
> @@ -1850,13 +1850,13 @@ void npc_mcam_rsrcs_deinit(struct rvu *rvu)
>   {
>          struct npc_mcam *mcam = &rvu->hw->mcam;
> 
> -       kfree(mcam->bmap);
> -       kfree(mcam->bmap_reverse);
> -       kfree(mcam->entry2pfvf_map);
> -       kfree(mcam->cntr2pfvf_map);
> -       kfree(mcam->entry2cntr_map);
> -       kfree(mcam->cntr_refcnt);
> -       kfree(mcam->entry2target_pffunc);
> +       bitmap_free(mcam->bmap);
> +       bitmap_free(mcam->bmap_reverse);
> +       bitmap_free(mcam->entry2pfvf_map);
> +       bitmap_free(mcam->cntr2pfvf_map);
> +       bitmap_free(mcam->entry2cntr_map);
> +       bitmap_free(mcam->cntr_refcnt);
> +       bitmap_free(mcam->entry2target_pffunc);
>          kfree(mcam->counters.bmap);
>   }
> 
> @@ -1904,21 +1904,18 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
>          mcam->pf_offset = mcam->nixlf_offset + nixlf_count;
> 
>          /* Allocate bitmaps for managing MCAM entries */
> -       mcam->bmap = kmalloc_array(BITS_TO_LONGS(mcam->bmap_entries),
> -                                  sizeof(long), GFP_KERNEL);
> +       mcam->bmap = bitmap_zalloc(mcam->bmap_entries, GFP_KERNEL) >          if (!mcam->bmap)
>                  return -ENOMEM;
> 
> -       mcam->bmap_reverse = kmalloc_array(BITS_TO_LONGS(mcam->bmap_entries),
> -                                          sizeof(long), GFP_KERNEL);
> +       mcam->bmap_reverse = bitmap_zalloc(mcam->bmap_entries, GFP_KERNEL);
>          if (!mcam->bmap_reverse)
>                  goto free_bmap;
> 
>          mcam->bmap_fcnt = mcam->bmap_entries;
> 
>          /* Alloc memory for saving entry to RVU PFFUNC allocation mapping */
> -       mcam->entry2pfvf_map = kmalloc_array(mcam->bmap_entries,
> -                                            sizeof(u16), GFP_KERNEL);
> +       mcam->entry2pfvf_map = bitmap_zalloc(mcam->bmap_entries, GFP_KERNEL);

Are you sure you want to use bitmap_zalloc() here?

>          if (!mcam->entry2pfvf_map)
>                  goto free_bmap_reverse;
> 
> @@ -1941,27 +1938,24 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
>          if (err)
>                  goto free_entry_map;
> 
> -       mcam->cntr2pfvf_map = kmalloc_array(mcam->counters.max,
> -                                           sizeof(u16), GFP_KERNEL);
> +       mcam->cntr2pfvf_map = bitmap_zalloc(mcam->counters.max, GFP_KERNEL);
>          if (!mcam->cntr2pfvf_map)
>                  goto free_cntr_bmap;
> 
>          /* Alloc memory for MCAM entry to counter mapping and for tracking
>           * counter's reference count.
>           */
> -       mcam->entry2cntr_map = kmalloc_array(mcam->bmap_entries,
> -                                            sizeof(u16), GFP_KERNEL);
> +       mcam->entry2cntr_map = bitmap_zalloc(mcam->bmap_entries, GFP_KERNEL);

Are you sure you want to use bitmap_zalloc() here?

>          if (!mcam->entry2cntr_map)
>                  goto free_cntr_map;
> 
> -       mcam->cntr_refcnt = kmalloc_array(mcam->counters.max,
> -                                         sizeof(u16), GFP_KERNEL);
> +       mcam->cntr_refcnt = bitmap_zalloc(mcam->counters.max, GFP_KERNEL);

Are you sure you want to use bitmap_zalloc() here?


>          if (!mcam->cntr_refcnt)
>                  goto free_entry_cntr_map;
> 
>          /* Alloc memory for saving target device of mcam rule */
> -       mcam->entry2target_pffunc = kmalloc_array(mcam->total_entries,
> -                                                 sizeof(u16), GFP_KERNEL);
> +       mcam->entry2target_pffunc = bitmap_zalloc(mcam->total_entries,
> +                                                 GFP_KERNEL);

Are you sure you want to use bitmap_zalloc() here?

>          if (!mcam->entry2target_pffunc)
>                  goto free_cntr_refcnt;
> 
> @@ -1978,19 +1972,19 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
>          return 0;
> 
>   free_cntr_refcnt:
> -       kfree(mcam->cntr_refcnt);
> +       bitmap_free(mcam->cntr_refcnt);
>   free_entry_cntr_map:
> -       kfree(mcam->entry2cntr_map);
> +       bitmap_free(mcam->entry2cntr_map);
>   free_cntr_map:
> -       kfree(mcam->cntr2pfvf_map);
> +       bitmap_free(mcam->cntr2pfvf_map);
>   free_cntr_bmap:
>          kfree(mcam->counters.bmap);
>   free_entry_map:
> -       kfree(mcam->entry2pfvf_map);
> +       bitmap_free(mcam->entry2pfvf_map);
>   free_bmap_reverse:
> -       kfree(mcam->bmap_reverse);
> +       bitmap_free(mcam->bmap_reverse);
>   free_bmap:
> -       kfree(mcam->bmap);
> +       bitmap_free(mcam->bmap);
> 
>          return -ENOMEM;
>   }
> --
> 2.25.1
>
Ratheesh Kannoth Jan. 30, 2024, 2:40 a.m. UTC | #2
> From: Brett Creeley <bcreeley@amd.com>
> Subject: [EXT] Re: [PATCH net v2] octeontx2-af: Initialize bitmap arrays.
> > --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h
> > +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu.h
> > @@ -184,11 +184,11 @@ struct npc_mcam {
> >          unsigned long   *bmap_reverse;  /* Reverse bitmap, bmap_entries =>
> 0 */
> >          u16     bmap_entries;   /* Number of unreserved MCAM entries */
> >          u16     bmap_fcnt;      /* MCAM entries free count */
> > -       u16     *entry2pfvf_map;
> > -       u16     *entry2cntr_map;
> > -       u16     *cntr2pfvf_map;
> > -       u16     *cntr_refcnt;
> > -       u16     *entry2target_pffunc;
> > +       unsigned long   *entry2pfvf_map;
> > +       unsigned long   *entry2cntr_map;
> > +       unsigned long   *cntr2pfvf_map;
> > +       unsigned long   *cntr_refcnt;
> > +       unsigned long   *entry2target_pffunc;
> 
> I'm not sure you want all of these at bitmaps? It was recommended to use
> bitmap_zalloc, but that was specifically for the bitmaps.
Sorry, I didn't get you. 
Bitmap_zalloc() returns unsigned long * 
"unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags)"
Ratheesh Kannoth Jan. 30, 2024, 4:16 a.m. UTC | #3
> From: Brett Creeley <bcreeley@amd.com>
> > +       unsigned long   *entry2pfvf_map;
> > +       unsigned long   *entry2cntr_map;
> > +       unsigned long   *cntr2pfvf_map;
> > +       unsigned long   *cntr_refcnt;
> > +       unsigned long   *entry2target_pffunc;
> 
> I'm not sure you want all of these at bitmaps? It was recommended to use
> bitmap_zalloc, but that was specifically for the bitmaps.
Got it. Will post new patch.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h b/drivers/net/ethernet/marvell/octeontx2/af/rvu.h
index 43be37dd1f32..679bd6e87066 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu.h
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu.h
@@ -184,11 +184,11 @@  struct npc_mcam {
 	unsigned long	*bmap_reverse;	/* Reverse bitmap, bmap_entries => 0 */
 	u16	bmap_entries;	/* Number of unreserved MCAM entries */
 	u16	bmap_fcnt;	/* MCAM entries free count */
-	u16	*entry2pfvf_map;
-	u16	*entry2cntr_map;
-	u16	*cntr2pfvf_map;
-	u16	*cntr_refcnt;
-	u16	*entry2target_pffunc;
+	unsigned long	*entry2pfvf_map;
+	unsigned long	*entry2cntr_map;
+	unsigned long	*cntr2pfvf_map;
+	unsigned long	*cntr_refcnt;
+	unsigned long	*entry2target_pffunc;
 	u8	keysize;	/* MCAM keysize 112/224/448 bits */
 	u8	banks;		/* Number of MCAM banks */
 	u8	banks_per_entry;/* Number of keywords in key */
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
index 167145bdcb75..367f842e365d 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
@@ -1850,13 +1850,13 @@  void npc_mcam_rsrcs_deinit(struct rvu *rvu)
 {
 	struct npc_mcam *mcam = &rvu->hw->mcam;
 
-	kfree(mcam->bmap);
-	kfree(mcam->bmap_reverse);
-	kfree(mcam->entry2pfvf_map);
-	kfree(mcam->cntr2pfvf_map);
-	kfree(mcam->entry2cntr_map);
-	kfree(mcam->cntr_refcnt);
-	kfree(mcam->entry2target_pffunc);
+	bitmap_free(mcam->bmap);
+	bitmap_free(mcam->bmap_reverse);
+	bitmap_free(mcam->entry2pfvf_map);
+	bitmap_free(mcam->cntr2pfvf_map);
+	bitmap_free(mcam->entry2cntr_map);
+	bitmap_free(mcam->cntr_refcnt);
+	bitmap_free(mcam->entry2target_pffunc);
 	kfree(mcam->counters.bmap);
 }
 
@@ -1904,21 +1904,18 @@  int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
 	mcam->pf_offset = mcam->nixlf_offset + nixlf_count;
 
 	/* Allocate bitmaps for managing MCAM entries */
-	mcam->bmap = kmalloc_array(BITS_TO_LONGS(mcam->bmap_entries),
-				   sizeof(long), GFP_KERNEL);
+	mcam->bmap = bitmap_zalloc(mcam->bmap_entries, GFP_KERNEL);
 	if (!mcam->bmap)
 		return -ENOMEM;
 
-	mcam->bmap_reverse = kmalloc_array(BITS_TO_LONGS(mcam->bmap_entries),
-					   sizeof(long), GFP_KERNEL);
+	mcam->bmap_reverse = bitmap_zalloc(mcam->bmap_entries, GFP_KERNEL);
 	if (!mcam->bmap_reverse)
 		goto free_bmap;
 
 	mcam->bmap_fcnt = mcam->bmap_entries;
 
 	/* Alloc memory for saving entry to RVU PFFUNC allocation mapping */
-	mcam->entry2pfvf_map = kmalloc_array(mcam->bmap_entries,
-					     sizeof(u16), GFP_KERNEL);
+	mcam->entry2pfvf_map = bitmap_zalloc(mcam->bmap_entries, GFP_KERNEL);
 	if (!mcam->entry2pfvf_map)
 		goto free_bmap_reverse;
 
@@ -1941,27 +1938,24 @@  int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
 	if (err)
 		goto free_entry_map;
 
-	mcam->cntr2pfvf_map = kmalloc_array(mcam->counters.max,
-					    sizeof(u16), GFP_KERNEL);
+	mcam->cntr2pfvf_map = bitmap_zalloc(mcam->counters.max, GFP_KERNEL);
 	if (!mcam->cntr2pfvf_map)
 		goto free_cntr_bmap;
 
 	/* Alloc memory for MCAM entry to counter mapping and for tracking
 	 * counter's reference count.
 	 */
-	mcam->entry2cntr_map = kmalloc_array(mcam->bmap_entries,
-					     sizeof(u16), GFP_KERNEL);
+	mcam->entry2cntr_map = bitmap_zalloc(mcam->bmap_entries, GFP_KERNEL);
 	if (!mcam->entry2cntr_map)
 		goto free_cntr_map;
 
-	mcam->cntr_refcnt = kmalloc_array(mcam->counters.max,
-					  sizeof(u16), GFP_KERNEL);
+	mcam->cntr_refcnt = bitmap_zalloc(mcam->counters.max, GFP_KERNEL);
 	if (!mcam->cntr_refcnt)
 		goto free_entry_cntr_map;
 
 	/* Alloc memory for saving target device of mcam rule */
-	mcam->entry2target_pffunc = kmalloc_array(mcam->total_entries,
-						  sizeof(u16), GFP_KERNEL);
+	mcam->entry2target_pffunc = bitmap_zalloc(mcam->total_entries,
+						  GFP_KERNEL);
 	if (!mcam->entry2target_pffunc)
 		goto free_cntr_refcnt;
 
@@ -1978,19 +1972,19 @@  int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
 	return 0;
 
 free_cntr_refcnt:
-	kfree(mcam->cntr_refcnt);
+	bitmap_free(mcam->cntr_refcnt);
 free_entry_cntr_map:
-	kfree(mcam->entry2cntr_map);
+	bitmap_free(mcam->entry2cntr_map);
 free_cntr_map:
-	kfree(mcam->cntr2pfvf_map);
+	bitmap_free(mcam->cntr2pfvf_map);
 free_cntr_bmap:
 	kfree(mcam->counters.bmap);
 free_entry_map:
-	kfree(mcam->entry2pfvf_map);
+	bitmap_free(mcam->entry2pfvf_map);
 free_bmap_reverse:
-	kfree(mcam->bmap_reverse);
+	bitmap_free(mcam->bmap_reverse);
 free_bmap:
-	kfree(mcam->bmap);
+	bitmap_free(mcam->bmap);
 
 	return -ENOMEM;
 }