* [PATCH net v3] octeontx2-af: Initialize maps.
@ 2024-01-31 2:41 Ratheesh Kannoth
2024-01-31 17:30 ` Brett Creeley
2024-02-01 9:31 ` Simon Horman
0 siblings, 2 replies; 6+ messages in thread
From: Ratheesh Kannoth @ 2024-01-31 2:41 UTC (permalink / raw)
To: netdev, linux-kernel
Cc: sgoutham, davem, edumazet, horms, kuba, pabeni, bcreeley,
sbhatta, gakula, hkelam, sumang, Ratheesh Kannoth
kmalloc_array() without __GFP_ZERO flag does not initialize
memory to zero. This causes issues. Use __GFP_ZERO flag for maps and
bitmap_zalloc() for bimaps.
Fixes: dd7842878633 ("octeontx2-af: Add new devlink param to configure maximum usable NIX block LFs")
Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com>
---
ChangeLogs:
v2 -> v3: Used GFP_ZERO for normal map arrays
v1 -> v2: Used bitmap_zalloc() API.
v0 -> v1: Removed devm_kcalloc()._
---
.../ethernet/marvell/octeontx2/af/rvu_npc.c | 26 ++++++++++---------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
index 167145bdcb75..6a8f0efd96a5 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
@@ -1850,8 +1850,8 @@ void npc_mcam_rsrcs_deinit(struct rvu *rvu)
{
struct npc_mcam *mcam = &rvu->hw->mcam;
- kfree(mcam->bmap);
- kfree(mcam->bmap_reverse);
+ bitmap_free(mcam->bmap);
+ bitmap_free(mcam->bmap_reverse);
kfree(mcam->entry2pfvf_map);
kfree(mcam->cntr2pfvf_map);
kfree(mcam->entry2cntr_map);
@@ -1904,13 +1904,11 @@ 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;
@@ -1918,7 +1916,8 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
/* Alloc memory for saving entry to RVU PFFUNC allocation mapping */
mcam->entry2pfvf_map = kmalloc_array(mcam->bmap_entries,
- sizeof(u16), GFP_KERNEL);
+ sizeof(u16),
+ GFP_KERNEL | __GFP_ZERO);
if (!mcam->entry2pfvf_map)
goto free_bmap_reverse;
@@ -1942,7 +1941,8 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
goto free_entry_map;
mcam->cntr2pfvf_map = kmalloc_array(mcam->counters.max,
- sizeof(u16), GFP_KERNEL);
+ sizeof(u16),
+ GFP_KERNEL | __GFP_ZERO);
if (!mcam->cntr2pfvf_map)
goto free_cntr_bmap;
@@ -1950,12 +1950,14 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
* counter's reference count.
*/
mcam->entry2cntr_map = kmalloc_array(mcam->bmap_entries,
- sizeof(u16), GFP_KERNEL);
+ sizeof(u16),
+ GFP_KERNEL | __GFP_ZERO);
if (!mcam->entry2cntr_map)
goto free_cntr_map;
mcam->cntr_refcnt = kmalloc_array(mcam->counters.max,
- sizeof(u16), GFP_KERNEL);
+ sizeof(u16),
+ GFP_KERNEL | __GFP_ZERO);
if (!mcam->cntr_refcnt)
goto free_entry_cntr_map;
@@ -1988,9 +1990,9 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
free_entry_map:
kfree(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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net v3] octeontx2-af: Initialize maps.
2024-01-31 2:41 [PATCH net v3] octeontx2-af: Initialize maps Ratheesh Kannoth
@ 2024-01-31 17:30 ` Brett Creeley
2024-02-01 9:31 ` Simon Horman
1 sibling, 0 replies; 6+ messages in thread
From: Brett Creeley @ 2024-01-31 17:30 UTC (permalink / raw)
To: Ratheesh Kannoth, netdev, linux-kernel
Cc: sgoutham, davem, edumazet, horms, kuba, pabeni, sbhatta, gakula,
hkelam, sumang
On 1/30/2024 6:41 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. Use __GFP_ZERO flag for maps and
> bitmap_zalloc() for bimaps.
>
> Fixes: dd7842878633 ("octeontx2-af: Add new devlink param to configure maximum usable NIX block LFs")
> Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com>
> ---
>
> ChangeLogs:
> v2 -> v3: Used GFP_ZERO for normal map arrays
> v1 -> v2: Used bitmap_zalloc() API.
> v0 -> v1: Removed devm_kcalloc()._
> ---
> .../ethernet/marvell/octeontx2/af/rvu_npc.c | 26 ++++++++++---------
> 1 file changed, 14 insertions(+), 12 deletions(-)
LGTM.
Reviewed-by: Brett Creeley <brett.creeley@amd.com>
>
> diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
> index 167145bdcb75..6a8f0efd96a5 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
> @@ -1850,8 +1850,8 @@ void npc_mcam_rsrcs_deinit(struct rvu *rvu)
> {
> struct npc_mcam *mcam = &rvu->hw->mcam;
>
> - kfree(mcam->bmap);
> - kfree(mcam->bmap_reverse);
> + bitmap_free(mcam->bmap);
> + bitmap_free(mcam->bmap_reverse);
> kfree(mcam->entry2pfvf_map);
> kfree(mcam->cntr2pfvf_map);
> kfree(mcam->entry2cntr_map);
> @@ -1904,13 +1904,11 @@ 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;
>
> @@ -1918,7 +1916,8 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
>
> /* Alloc memory for saving entry to RVU PFFUNC allocation mapping */
> mcam->entry2pfvf_map = kmalloc_array(mcam->bmap_entries,
> - sizeof(u16), GFP_KERNEL);
> + sizeof(u16),
> + GFP_KERNEL | __GFP_ZERO);
> if (!mcam->entry2pfvf_map)
> goto free_bmap_reverse;
>
> @@ -1942,7 +1941,8 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
> goto free_entry_map;
>
> mcam->cntr2pfvf_map = kmalloc_array(mcam->counters.max,
> - sizeof(u16), GFP_KERNEL);
> + sizeof(u16),
> + GFP_KERNEL | __GFP_ZERO);
> if (!mcam->cntr2pfvf_map)
> goto free_cntr_bmap;
>
> @@ -1950,12 +1950,14 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
> * counter's reference count.
> */
> mcam->entry2cntr_map = kmalloc_array(mcam->bmap_entries,
> - sizeof(u16), GFP_KERNEL);
> + sizeof(u16),
> + GFP_KERNEL | __GFP_ZERO);
> if (!mcam->entry2cntr_map)
> goto free_cntr_map;
>
> mcam->cntr_refcnt = kmalloc_array(mcam->counters.max,
> - sizeof(u16), GFP_KERNEL);
> + sizeof(u16),
> + GFP_KERNEL | __GFP_ZERO);
> if (!mcam->cntr_refcnt)
> goto free_entry_cntr_map;
>
> @@ -1988,9 +1990,9 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
> free_entry_map:
> kfree(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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net v3] octeontx2-af: Initialize maps.
2024-01-31 2:41 [PATCH net v3] octeontx2-af: Initialize maps Ratheesh Kannoth
2024-01-31 17:30 ` Brett Creeley
@ 2024-02-01 9:31 ` Simon Horman
2024-02-01 9:35 ` [EXT] " Ratheesh Kannoth
1 sibling, 1 reply; 6+ messages in thread
From: Simon Horman @ 2024-02-01 9:31 UTC (permalink / raw)
To: Ratheesh Kannoth
Cc: netdev, linux-kernel, sgoutham, davem, edumazet, kuba, pabeni,
bcreeley, sbhatta, gakula, hkelam, sumang
On Wed, Jan 31, 2024 at 08:11:18AM +0530, Ratheesh Kannoth wrote:
> kmalloc_array() without __GFP_ZERO flag does not initialize
> memory to zero. This causes issues. Use __GFP_ZERO flag for maps and
> bitmap_zalloc() for bimaps.
>
> Fixes: dd7842878633 ("octeontx2-af: Add new devlink param to configure maximum usable NIX block LFs")
> Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com>
> ---
>
> ChangeLogs:
> v2 -> v3: Used GFP_ZERO for normal map arrays
> v1 -> v2: Used bitmap_zalloc() API.
> v0 -> v1: Removed devm_kcalloc()._
> ---
> .../ethernet/marvell/octeontx2/af/rvu_npc.c | 26 ++++++++++---------
> 1 file changed, 14 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
> index 167145bdcb75..6a8f0efd96a5 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
> @@ -1850,8 +1850,8 @@ void npc_mcam_rsrcs_deinit(struct rvu *rvu)
> {
> struct npc_mcam *mcam = &rvu->hw->mcam;
>
> - kfree(mcam->bmap);
> - kfree(mcam->bmap_reverse);
> + bitmap_free(mcam->bmap);
> + bitmap_free(mcam->bmap_reverse);
> kfree(mcam->entry2pfvf_map);
> kfree(mcam->cntr2pfvf_map);
> kfree(mcam->entry2cntr_map);
> @@ -1904,13 +1904,11 @@ 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;
>
> @@ -1918,7 +1916,8 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
>
> /* Alloc memory for saving entry to RVU PFFUNC allocation mapping */
> mcam->entry2pfvf_map = kmalloc_array(mcam->bmap_entries,
> - sizeof(u16), GFP_KERNEL);
> + sizeof(u16),
> + GFP_KERNEL | __GFP_ZERO);
Hi Ratheesh,
The use of bitmap_zalloc()/bitmap_free() looks good to me.
But for the kmalloc_array(..., GFP_KERNEL | __GFP_ZERO) cases
I think kcalloc() is the way to go.
> if (!mcam->entry2pfvf_map)
> goto free_bmap_reverse;
>
> @@ -1942,7 +1941,8 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
> goto free_entry_map;
>
> mcam->cntr2pfvf_map = kmalloc_array(mcam->counters.max,
> - sizeof(u16), GFP_KERNEL);
> + sizeof(u16),
> + GFP_KERNEL | __GFP_ZERO);
> if (!mcam->cntr2pfvf_map)
> goto free_cntr_bmap;
>
> @@ -1950,12 +1950,14 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
> * counter's reference count.
> */
> mcam->entry2cntr_map = kmalloc_array(mcam->bmap_entries,
> - sizeof(u16), GFP_KERNEL);
> + sizeof(u16),
> + GFP_KERNEL | __GFP_ZERO);
> if (!mcam->entry2cntr_map)
> goto free_cntr_map;
>
> mcam->cntr_refcnt = kmalloc_array(mcam->counters.max,
> - sizeof(u16), GFP_KERNEL);
> + sizeof(u16),
> + GFP_KERNEL | __GFP_ZERO);
> if (!mcam->cntr_refcnt)
> goto free_entry_cntr_map;
>
> @@ -1988,9 +1990,9 @@ int npc_mcam_rsrcs_init(struct rvu *rvu, int blkaddr)
> free_entry_map:
> kfree(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
>
--
pw-bot: changes-requested
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [EXT] Re: [PATCH net v3] octeontx2-af: Initialize maps.
2024-02-01 9:31 ` Simon Horman
@ 2024-02-01 9:35 ` Ratheesh Kannoth
2024-02-01 16:27 ` Jakub Kicinski
0 siblings, 1 reply; 6+ messages in thread
From: Ratheesh Kannoth @ 2024-02-01 9:35 UTC (permalink / raw)
To: Simon Horman
Cc: netdev, linux-kernel, Sunil Kovvuri Goutham, davem, edumazet,
kuba, pabeni, bcreeley, Subbaraya Sundeep Bhatta,
Geethasowjanya Akula, Hariprasad Kelam, Suman Ghosh
> From: Simon Horman <horms@kernel.org>
> Subject: [EXT] Re: [PATCH net v3] octeontx2-af: Initialize maps.
> > /* Alloc memory for saving entry to RVU PFFUNC allocation mapping
> */
> > mcam->entry2pfvf_map = kmalloc_array(mcam->bmap_entries,
> > - sizeof(u16), GFP_KERNEL);
> > + sizeof(u16),
> > + GFP_KERNEL | __GFP_ZERO);
>
> Hi Ratheesh,
>
> The use of bitmap_zalloc()/bitmap_free() looks good to me.
> But for the kmalloc_array(..., GFP_KERNEL | __GFP_ZERO) cases I think
> kcalloc() is the way to go.
Kcalloc() is a wrapper around kmalloc_array(). Why do you think kcalloc()
Is better ?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [EXT] Re: [PATCH net v3] octeontx2-af: Initialize maps.
2024-02-01 9:35 ` [EXT] " Ratheesh Kannoth
@ 2024-02-01 16:27 ` Jakub Kicinski
2024-02-02 7:32 ` Ratheesh Kannoth
0 siblings, 1 reply; 6+ messages in thread
From: Jakub Kicinski @ 2024-02-01 16:27 UTC (permalink / raw)
To: Ratheesh Kannoth
Cc: Simon Horman, netdev, linux-kernel, Sunil Kovvuri Goutham, davem,
edumazet, pabeni, bcreeley, Subbaraya Sundeep Bhatta,
Geethasowjanya Akula, Hariprasad Kelam, Suman Ghosh
On Thu, 1 Feb 2024 09:35:15 +0000 Ratheesh Kannoth wrote:
> > The use of bitmap_zalloc()/bitmap_free() looks good to me.
> > But for the kmalloc_array(..., GFP_KERNEL | __GFP_ZERO) cases I think
> > kcalloc() is the way to go.
> Kcalloc() is a wrapper around kmalloc_array(). Why do you think kcalloc()
> Is better ?
AFAICT this is not the first time you're questioning Simon's obviously
correct feedback. Are you genuinely asking for an explanation why
kcalloc() is better than kmalloc_array()? It's an equivalent to
the standard C function, calloc().
The reviewers are the most valuable part of this community, we will
not take frustrating them lightly :|
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [EXT] Re: [PATCH net v3] octeontx2-af: Initialize maps.
2024-02-01 16:27 ` Jakub Kicinski
@ 2024-02-02 7:32 ` Ratheesh Kannoth
0 siblings, 0 replies; 6+ messages in thread
From: Ratheesh Kannoth @ 2024-02-02 7:32 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Simon Horman, netdev, linux-kernel, Sunil Kovvuri Goutham, davem,
edumazet, pabeni, bcreeley, Subbaraya Sundeep Bhatta,
Geethasowjanya Akula, Hariprasad Kelam, Suman Ghosh
>From: Jakub Kicinski <kuba@kernel.org>
> Subject: Re: [EXT] Re: [PATCH net v3] octeontx2-af: Initialize maps.
>
> On Thu, 1 Feb 2024 09:35:15 +0000 Ratheesh Kannoth wrote:
> > > The use of bitmap_zalloc()/bitmap_free() looks good to me.
> > > But for the kmalloc_array(..., GFP_KERNEL | __GFP_ZERO) cases I
> > > think
> > > kcalloc() is the way to go.
> > Kcalloc() is a wrapper around kmalloc_array(). Why do you think
> > kcalloc() Is better ?
>
> Are you genuinely asking for an explanation why
> kcalloc() is better than kmalloc_array()?
Yes.
>It's an equivalent to the standard C
> function, calloc().
Thanks.
>
> The reviewers are the most valuable part of this community, we will not take
> frustrating them lightly :|
I learn a lot from review comments provided by this community and do value
them. I am sorry if my "English" sounded harsh.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-02-02 7:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-31 2:41 [PATCH net v3] octeontx2-af: Initialize maps Ratheesh Kannoth
2024-01-31 17:30 ` Brett Creeley
2024-02-01 9:31 ` Simon Horman
2024-02-01 9:35 ` [EXT] " Ratheesh Kannoth
2024-02-01 16:27 ` Jakub Kicinski
2024-02-02 7:32 ` Ratheesh Kannoth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).