diff mbox series

[v3,1/2] net: page_pool: check page pool ethtool stats

Message ID be2yyb4ksuzj2d4yhvfzj43fswdtqmcqxv5dplmi6qy7vr4don@ksativ2xr33e (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: page_pool: check page pool ethtool stats | expand

Checks

Context Check Description
netdev/series_format warning Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1362 this patch: 1362
netdev/cc_maintainers warning 5 maintainers not CCed: pabeni@redhat.com edumazet@google.com kuba@kernel.org davem@davemloft.net hawk@kernel.org
netdev/build_clang success Errors and warnings before: 1386 this patch: 1386
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1387 this patch: 1387
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Sven Auhagen Oct. 15, 2023, 12:37 p.m. UTC
If the page_pool variable is null while passing it to
the page_pool_get_stats function we receive a kernel error.

Check if the page_pool variable is at least valid.

Signed-off-by: Sven Auhagen <sven.auhagen@voleatech.de>
Reported-by: Paulo Da Silva <Paulo.DaSilva@kyberna.com>
---
 net/core/page_pool.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Leon Romanovsky Oct. 15, 2023, 5:27 p.m. UTC | #1
On Sun, Oct 15, 2023 at 02:37:27PM +0200, Sven Auhagen wrote:
> If the page_pool variable is null while passing it to
> the page_pool_get_stats function we receive a kernel error.
> 
> Check if the page_pool variable is at least valid.
> 
> Signed-off-by: Sven Auhagen <sven.auhagen@voleatech.de>
> Reported-by: Paulo Da Silva <Paulo.DaSilva@kyberna.com>
> ---
>  net/core/page_pool.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/net/core/page_pool.c b/net/core/page_pool.c
> index 2396c99bedea..4c5dca6b4a16 100644
> --- a/net/core/page_pool.c
> +++ b/net/core/page_pool.c
> @@ -65,6 +65,9 @@ bool page_pool_get_stats(struct page_pool *pool,
>  	if (!stats)
>  		return false;
>  
> +	if (!pool)
> +		return false;
> +

I would argue that both pool and stats shouldn't be NULL and must be
checked by caller. This API call named get-stats-from-pool.

Thanks

>  	/* The caller is responsible to initialize stats. */
>  	stats->alloc_stats.fast += pool->alloc_stats.fast;
>  	stats->alloc_stats.slow += pool->alloc_stats.slow;
> -- 
> 2.42.0
> 
>
Sven Auhagen Oct. 25, 2023, 2:12 a.m. UTC | #2
On Sun, Oct 15, 2023 at 08:27:10PM +0300, Leon Romanovsky wrote:
> On Sun, Oct 15, 2023 at 02:37:27PM +0200, Sven Auhagen wrote:
> > If the page_pool variable is null while passing it to
> > the page_pool_get_stats function we receive a kernel error.
> > 
> > Check if the page_pool variable is at least valid.
> > 
> > Signed-off-by: Sven Auhagen <sven.auhagen@voleatech.de>
> > Reported-by: Paulo Da Silva <Paulo.DaSilva@kyberna.com>
> > ---
> >  net/core/page_pool.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/net/core/page_pool.c b/net/core/page_pool.c
> > index 2396c99bedea..4c5dca6b4a16 100644
> > --- a/net/core/page_pool.c
> > +++ b/net/core/page_pool.c
> > @@ -65,6 +65,9 @@ bool page_pool_get_stats(struct page_pool *pool,
> >  	if (!stats)
> >  		return false;
> >  
> > +	if (!pool)
> > +		return false;
> > +
> 
> I would argue that both pool and stats shouldn't be NULL and must be
> checked by caller. This API call named get-stats-from-pool.
> 
> Thanks

I can do it either way, I only need to know which version to send.
Can someone let me know how to proceed with the patch?

Best
Sven

> 
> >  	/* The caller is responsible to initialize stats. */
> >  	stats->alloc_stats.fast += pool->alloc_stats.fast;
> >  	stats->alloc_stats.slow += pool->alloc_stats.slow;
> > -- 
> > 2.42.0
> > 
> >
Yunsheng Lin Oct. 25, 2023, 2:28 a.m. UTC | #3
On 2023/10/25 10:12, Sven Auhagen wrote:
> On Sun, Oct 15, 2023 at 08:27:10PM +0300, Leon Romanovsky wrote:
>> On Sun, Oct 15, 2023 at 02:37:27PM +0200, Sven Auhagen wrote:
>>> If the page_pool variable is null while passing it to
>>> the page_pool_get_stats function we receive a kernel error.
>>>
>>> Check if the page_pool variable is at least valid.
>>>
>>> Signed-off-by: Sven Auhagen <sven.auhagen@voleatech.de>
>>> Reported-by: Paulo Da Silva <Paulo.DaSilva@kyberna.com>
>>> ---
>>>  net/core/page_pool.c | 3 +++
>>>  1 file changed, 3 insertions(+)
>>>
>>> diff --git a/net/core/page_pool.c b/net/core/page_pool.c
>>> index 2396c99bedea..4c5dca6b4a16 100644
>>> --- a/net/core/page_pool.c
>>> +++ b/net/core/page_pool.c
>>> @@ -65,6 +65,9 @@ bool page_pool_get_stats(struct page_pool *pool,
>>>  	if (!stats)
>>>  		return false;
>>>  
>>> +	if (!pool)
>>> +		return false;
>>> +
>>
>> I would argue that both pool and stats shouldn't be NULL and must be
>> checked by caller. This API call named get-stats-from-pool.
>>
>> Thanks
> 
> I can do it either way, I only need to know which version to send.
> Can someone let me know how to proceed with the patch?

From the message in v1, it seems more appropriate to check it in
the driver, because:
1. if the driver only support page pool, then the check is not
   really necessary.
2. if the driver support both page_pool API and alloc_pages()
   API, then a check is already needed in the driver to switch
   between those two API, it might be better to reuse that check.

"First the page pool is only available if the bm is not used.
The page pool is also not allocated when the port is stopped.
It can also be not allocated in case of errors."

> 
> Best
> Sven
> 
>>
>>>  	/* The caller is responsible to initialize stats. */
>>>  	stats->alloc_stats.fast += pool->alloc_stats.fast;
>>>  	stats->alloc_stats.slow += pool->alloc_stats.slow;
>>> -- 
>>> 2.42.0
>>>
>>>
> 
> .
>
diff mbox series

Patch

diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 2396c99bedea..4c5dca6b4a16 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -65,6 +65,9 @@  bool page_pool_get_stats(struct page_pool *pool,
 	if (!stats)
 		return false;
 
+	if (!pool)
+		return false;
+
 	/* The caller is responsible to initialize stats. */
 	stats->alloc_stats.fast += pool->alloc_stats.fast;
 	stats->alloc_stats.slow += pool->alloc_stats.slow;