netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: ipa: always inline ipa_aggr_granularity_val()
@ 2021-08-10 16:02 Alex Elder
  2021-08-11 12:02 ` Leon Romanovsky
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Elder @ 2021-08-10 16:02 UTC (permalink / raw)
  To: davem, kuba
  Cc: bjorn.andersson, evgreen, cpratapa, subashab, lkp, elder, netdev,
	linux-kernel

It isn't required, but all callers of ipa_aggr_granularity_val()
pass a constant value (IPA_AGGR_GRANULARITY) as the usec argument.
Two of those callers are in ipa_validate_build(), with the result
being passed to BUILD_BUG_ON().

Evidently the "sparc64-linux-gcc" compiler (at least) doesn't always
inline ipa_aggr_granularity_val(), so the result of the function is
not constant at compile time, and that leads to build errors.

Define the function with the __always_inline attribute to avoid the
errors.  And given that the function is inline, we can switch the
WARN_ON() there to be BUILD_BUG_ON().

Fixes: 5bc5588466a1f ("net: ipa: use WARN_ON() rather than assertions")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Alex Elder <elder@linaro.org>
---

David/Jakub, this fixes a bug in a commit in net-next/master.  -Alex

 drivers/net/ipa/ipa_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c
index 25bbb456e0078..f90b3521e266b 100644
--- a/drivers/net/ipa/ipa_main.c
+++ b/drivers/net/ipa/ipa_main.c
@@ -255,9 +255,9 @@ ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data)
  * less than the number of timer ticks in the requested period.  0 is not
  * a valid granularity value.
  */
-static u32 ipa_aggr_granularity_val(u32 usec)
+static __always_inline u32 ipa_aggr_granularity_val(u32 usec)
 {
-	WARN_ON(!usec);
+	BUILD_BUG_ON(!usec);
 
 	return DIV_ROUND_CLOSEST(usec * TIMER_FREQUENCY, USEC_PER_SEC) - 1;
 }
-- 
2.27.0


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

* Re: [PATCH net-next] net: ipa: always inline ipa_aggr_granularity_val()
  2021-08-10 16:02 [PATCH net-next] net: ipa: always inline ipa_aggr_granularity_val() Alex Elder
@ 2021-08-11 12:02 ` Leon Romanovsky
  2021-08-11 12:06   ` Alex Elder
  0 siblings, 1 reply; 4+ messages in thread
From: Leon Romanovsky @ 2021-08-11 12:02 UTC (permalink / raw)
  To: Alex Elder
  Cc: davem, kuba, bjorn.andersson, evgreen, cpratapa, subashab, lkp,
	elder, netdev, linux-kernel

On Tue, Aug 10, 2021 at 11:02:13AM -0500, Alex Elder wrote:
> It isn't required, but all callers of ipa_aggr_granularity_val()
> pass a constant value (IPA_AGGR_GRANULARITY) as the usec argument.
> Two of those callers are in ipa_validate_build(), with the result
> being passed to BUILD_BUG_ON().
> 
> Evidently the "sparc64-linux-gcc" compiler (at least) doesn't always
> inline ipa_aggr_granularity_val(), so the result of the function is
> not constant at compile time, and that leads to build errors.
> 
> Define the function with the __always_inline attribute to avoid the
> errors.  And given that the function is inline, we can switch the
> WARN_ON() there to be BUILD_BUG_ON().
> 
> Fixes: 5bc5588466a1f ("net: ipa: use WARN_ON() rather than assertions")
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Alex Elder <elder@linaro.org>
> ---
> 
> David/Jakub, this fixes a bug in a commit in net-next/master.  -Alex
> 
>  drivers/net/ipa/ipa_main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c
> index 25bbb456e0078..f90b3521e266b 100644
> --- a/drivers/net/ipa/ipa_main.c
> +++ b/drivers/net/ipa/ipa_main.c
> @@ -255,9 +255,9 @@ ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data)
>   * less than the number of timer ticks in the requested period.  0 is not
>   * a valid granularity value.
>   */
> -static u32 ipa_aggr_granularity_val(u32 usec)
> +static __always_inline u32 ipa_aggr_granularity_val(u32 usec)
>  {
> -	WARN_ON(!usec);
> +	BUILD_BUG_ON(!usec);

So what exactly are you checking here if all callers pass same value?
It is in-kernel API, declared as static inside one module. There is no
need to protect from itself.

Thanks

>  
>  	return DIV_ROUND_CLOSEST(usec * TIMER_FREQUENCY, USEC_PER_SEC) - 1;
>  }
> -- 
> 2.27.0
> 

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

* Re: [PATCH net-next] net: ipa: always inline ipa_aggr_granularity_val()
  2021-08-11 12:02 ` Leon Romanovsky
@ 2021-08-11 12:06   ` Alex Elder
  2021-08-11 12:12     ` Leon Romanovsky
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Elder @ 2021-08-11 12:06 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: davem, kuba, bjorn.andersson, evgreen, cpratapa, subashab, lkp,
	elder, netdev, linux-kernel

On 8/11/21 7:02 AM, Leon Romanovsky wrote:
> On Tue, Aug 10, 2021 at 11:02:13AM -0500, Alex Elder wrote:
>> It isn't required, but all callers of ipa_aggr_granularity_val()
>> pass a constant value (IPA_AGGR_GRANULARITY) as the usec argument.
>> Two of those callers are in ipa_validate_build(), with the result
>> being passed to BUILD_BUG_ON().
>>
>> Evidently the "sparc64-linux-gcc" compiler (at least) doesn't always
>> inline ipa_aggr_granularity_val(), so the result of the function is
>> not constant at compile time, and that leads to build errors.
>>
>> Define the function with the __always_inline attribute to avoid the
>> errors.  And given that the function is inline, we can switch the
>> WARN_ON() there to be BUILD_BUG_ON().
>>
>> Fixes: 5bc5588466a1f ("net: ipa: use WARN_ON() rather than assertions")
>> Reported-by: kernel test robot <lkp@intel.com>
>> Signed-off-by: Alex Elder <elder@linaro.org>
>> ---
>>
>> David/Jakub, this fixes a bug in a commit in net-next/master.  -Alex
>>
>>  drivers/net/ipa/ipa_main.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c
>> index 25bbb456e0078..f90b3521e266b 100644
>> --- a/drivers/net/ipa/ipa_main.c
>> +++ b/drivers/net/ipa/ipa_main.c
>> @@ -255,9 +255,9 @@ ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data)
>>   * less than the number of timer ticks in the requested period.  0 is not
>>   * a valid granularity value.
>>   */
>> -static u32 ipa_aggr_granularity_val(u32 usec)
>> +static __always_inline u32 ipa_aggr_granularity_val(u32 usec)
>>  {
>> -	WARN_ON(!usec);
>> +	BUILD_BUG_ON(!usec);
> 
> So what exactly are you checking here if all callers pass same value?
> It is in-kernel API, declared as static inside one module. There is no
> need to protect from itself.

Yeah that's a good point.  It can just as well be removed.
I think the check was added before I knew it was only going
to be used with a single constant value.  That said, the
point was to check at runtime a required constraint.

I'll post version 2 that simply removes it.  Thanks.

					-Alex

> 
> Thanks
> 
>>  
>>  	return DIV_ROUND_CLOSEST(usec * TIMER_FREQUENCY, USEC_PER_SEC) - 1;
>>  }
>> -- 
>> 2.27.0
>>


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

* Re: [PATCH net-next] net: ipa: always inline ipa_aggr_granularity_val()
  2021-08-11 12:06   ` Alex Elder
@ 2021-08-11 12:12     ` Leon Romanovsky
  0 siblings, 0 replies; 4+ messages in thread
From: Leon Romanovsky @ 2021-08-11 12:12 UTC (permalink / raw)
  To: Alex Elder
  Cc: davem, kuba, bjorn.andersson, evgreen, cpratapa, subashab, lkp,
	elder, netdev, linux-kernel

On Wed, Aug 11, 2021 at 07:06:01AM -0500, Alex Elder wrote:
> On 8/11/21 7:02 AM, Leon Romanovsky wrote:
> > On Tue, Aug 10, 2021 at 11:02:13AM -0500, Alex Elder wrote:
> >> It isn't required, but all callers of ipa_aggr_granularity_val()
> >> pass a constant value (IPA_AGGR_GRANULARITY) as the usec argument.
> >> Two of those callers are in ipa_validate_build(), with the result
> >> being passed to BUILD_BUG_ON().
> >>
> >> Evidently the "sparc64-linux-gcc" compiler (at least) doesn't always
> >> inline ipa_aggr_granularity_val(), so the result of the function is
> >> not constant at compile time, and that leads to build errors.
> >>
> >> Define the function with the __always_inline attribute to avoid the
> >> errors.  And given that the function is inline, we can switch the
> >> WARN_ON() there to be BUILD_BUG_ON().
> >>
> >> Fixes: 5bc5588466a1f ("net: ipa: use WARN_ON() rather than assertions")
> >> Reported-by: kernel test robot <lkp@intel.com>
> >> Signed-off-by: Alex Elder <elder@linaro.org>
> >> ---
> >>
> >> David/Jakub, this fixes a bug in a commit in net-next/master.  -Alex
> >>
> >>  drivers/net/ipa/ipa_main.c | 4 ++--
> >>  1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/net/ipa/ipa_main.c b/drivers/net/ipa/ipa_main.c
> >> index 25bbb456e0078..f90b3521e266b 100644
> >> --- a/drivers/net/ipa/ipa_main.c
> >> +++ b/drivers/net/ipa/ipa_main.c
> >> @@ -255,9 +255,9 @@ ipa_hardware_config_qsb(struct ipa *ipa, const struct ipa_data *data)
> >>   * less than the number of timer ticks in the requested period.  0 is not
> >>   * a valid granularity value.
> >>   */
> >> -static u32 ipa_aggr_granularity_val(u32 usec)
> >> +static __always_inline u32 ipa_aggr_granularity_val(u32 usec)
> >>  {
> >> -	WARN_ON(!usec);
> >> +	BUILD_BUG_ON(!usec);
> > 
> > So what exactly are you checking here if all callers pass same value?
> > It is in-kernel API, declared as static inside one module. There is no
> > need to protect from itself.
> 
> Yeah that's a good point.  It can just as well be removed.
> I think the check was added before I knew it was only going
> to be used with a single constant value.  That said, the
> point was to check at runtime a required constraint.
> 
> I'll post version 2 that simply removes it.  Thanks.

Thanks
> 
> 					-Alex
> 
> > 
> > Thanks
> > 
> >>  
> >>  	return DIV_ROUND_CLOSEST(usec * TIMER_FREQUENCY, USEC_PER_SEC) - 1;
> >>  }
> >> -- 
> >> 2.27.0
> >>
> 

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

end of thread, other threads:[~2021-08-11 12:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-10 16:02 [PATCH net-next] net: ipa: always inline ipa_aggr_granularity_val() Alex Elder
2021-08-11 12:02 ` Leon Romanovsky
2021-08-11 12:06   ` Alex Elder
2021-08-11 12:12     ` Leon Romanovsky

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).