mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next] net: microchip: vcap: Change how the rule id is generated
@ 2022-11-28 14:29 Horatiu Vultur
  2022-11-28 14:40 ` Alexander Lobakin
  2022-12-01  5:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Horatiu Vultur @ 2022-11-28 14:29 UTC (permalink / raw)
  To: linux-arm-kernel, netdev, linux-kernel
  Cc: davem, edumazet, kuba, pabeni, lars.povlsen, Steen.Hegelund,
	daniel.machon, UNGLinuxDriver, casper.casan, Horatiu Vultur

Currently whenever a new rule id is generated, it picks up the next
number bigger than previous id. So it would always be 1, 2, 3, etc.
When the rule with id 1 will be deleted and a new rule will be added,
it will have the id 4 and not id 1.
In theory this can be a problem if at some point a rule will be added
and removed ~0 times. Then no more rules can be added because there
are no more ids.

Change this such that when a new rule is added, search for an empty
rule id starting with value of 1 as value 0 is reserved.

Fixes: c9da1ac1c212 ("net: microchip: sparx5: Adding initial tc flower support for VCAP API")
Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
---
 drivers/net/ethernet/microchip/vcap/vcap_api.c | 7 +------
 drivers/net/ethernet/microchip/vcap/vcap_api.h | 1 -
 2 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c
index b50d002b646dc..b65819f3a927f 100644
--- a/drivers/net/ethernet/microchip/vcap/vcap_api.c
+++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c
@@ -974,17 +974,12 @@ static u32 vcap_next_rule_addr(u32 addr, struct vcap_rule_internal *ri)
 /* Assign a unique rule id and autogenerate one if id == 0 */
 static u32 vcap_set_rule_id(struct vcap_rule_internal *ri)
 {
-	u32 next_id;
-
 	if (ri->data.id != 0)
 		return ri->data.id;
 
-	next_id = ri->vctrl->rule_id + 1;
-
-	for (next_id = ri->vctrl->rule_id + 1; next_id < ~0; ++next_id) {
+	for (u32 next_id = 1; next_id < ~0; ++next_id) {
 		if (!vcap_lookup_rule(ri->vctrl, next_id)) {
 			ri->data.id = next_id;
-			ri->vctrl->rule_id = next_id;
 			break;
 		}
 	}
diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.h b/drivers/net/ethernet/microchip/vcap/vcap_api.h
index ca4499838306f..689c7270f2a89 100644
--- a/drivers/net/ethernet/microchip/vcap/vcap_api.h
+++ b/drivers/net/ethernet/microchip/vcap/vcap_api.h
@@ -268,7 +268,6 @@ struct vcap_operations {
 
 /* VCAP API Client control interface */
 struct vcap_control {
-	u32 rule_id; /* last used rule id (unique across VCAP instances) */
 	struct vcap_operations *ops;  /* client supplied operations */
 	const struct vcap_info *vcaps; /* client supplied vcap models */
 	const struct vcap_statistics *stats; /* client supplied vcap stats */
-- 
2.38.0


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

* Re: [PATCH net-next] net: microchip: vcap: Change how the rule id is generated
  2022-11-28 14:29 [PATCH net-next] net: microchip: vcap: Change how the rule id is generated Horatiu Vultur
@ 2022-11-28 14:40 ` Alexander Lobakin
  2022-11-29 11:00   ` Horatiu Vultur
  2022-12-01  5:50 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Alexander Lobakin @ 2022-11-28 14:40 UTC (permalink / raw)
  To: Horatiu Vultur
  Cc: Alexander Lobakin, linux-arm-kernel, netdev, linux-kernel, davem,
	edumazet, kuba, pabeni, lars.povlsen, Steen.Hegelund,
	daniel.machon, UNGLinuxDriver, casper.casan

From: Horatiu Vultur <horatiu.vultur@microchip.com>
Date: Mon, 28 Nov 2022 15:29:59 +0100

> Currently whenever a new rule id is generated, it picks up the next
> number bigger than previous id. So it would always be 1, 2, 3, etc.
> When the rule with id 1 will be deleted and a new rule will be added,
> it will have the id 4 and not id 1.
> In theory this can be a problem if at some point a rule will be added
> and removed ~0 times. Then no more rules can be added because there
> are no more ids.
> 
> Change this such that when a new rule is added, search for an empty
> rule id starting with value of 1 as value 0 is reserved.
> 
> Fixes: c9da1ac1c212 ("net: microchip: sparx5: Adding initial tc flower support for VCAP API")
> Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
> ---
>  drivers/net/ethernet/microchip/vcap/vcap_api.c | 7 +------
>  drivers/net/ethernet/microchip/vcap/vcap_api.h | 1 -
>  2 files changed, 1 insertion(+), 7 deletions(-)
> 
> diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c
> index b50d002b646dc..b65819f3a927f 100644
> --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c
> +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c
> @@ -974,17 +974,12 @@ static u32 vcap_next_rule_addr(u32 addr, struct vcap_rule_internal *ri)
>  /* Assign a unique rule id and autogenerate one if id == 0 */
>  static u32 vcap_set_rule_id(struct vcap_rule_internal *ri)
>  {
> -	u32 next_id;
> -
>  	if (ri->data.id != 0)
>  		return ri->data.id;
>  
> -	next_id = ri->vctrl->rule_id + 1;
> -
> -	for (next_id = ri->vctrl->rule_id + 1; next_id < ~0; ++next_id) {
> +	for (u32 next_id = 1; next_id < ~0; ++next_id) {
>  		if (!vcap_lookup_rule(ri->vctrl, next_id)) {

Or you can simply use IDA/IDR/XArray which takes care of all this :)


>  			ri->data.id = next_id;
> -			ri->vctrl->rule_id = next_id;
>  			break;
>  		}
>  	}
> diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.h b/drivers/net/ethernet/microchip/vcap/vcap_api.h
> index ca4499838306f..689c7270f2a89 100644
> --- a/drivers/net/ethernet/microchip/vcap/vcap_api.h
> +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.h
> @@ -268,7 +268,6 @@ struct vcap_operations {
>  
>  /* VCAP API Client control interface */
>  struct vcap_control {
> -	u32 rule_id; /* last used rule id (unique across VCAP instances) */
>  	struct vcap_operations *ops;  /* client supplied operations */
>  	const struct vcap_info *vcaps; /* client supplied vcap models */
>  	const struct vcap_statistics *stats; /* client supplied vcap stats */
> -- 
> 2.38.0

Thanks,
Olek

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

* Re: [PATCH net-next] net: microchip: vcap: Change how the rule id is generated
  2022-11-28 14:40 ` Alexander Lobakin
@ 2022-11-29 11:00   ` Horatiu Vultur
  0 siblings, 0 replies; 4+ messages in thread
From: Horatiu Vultur @ 2022-11-29 11:00 UTC (permalink / raw)
  To: Alexander Lobakin
  Cc: linux-arm-kernel, netdev, linux-kernel, davem, edumazet, kuba,
	pabeni, lars.povlsen, Steen.Hegelund, daniel.machon,
	UNGLinuxDriver, casper.casan

The 11/28/2022 15:40, Alexander Lobakin wrote:

Hi Olek,

> 
> From: Horatiu Vultur <horatiu.vultur@microchip.com>
> Date: Mon, 28 Nov 2022 15:29:59 +0100
> 
> > Currently whenever a new rule id is generated, it picks up the next
> > number bigger than previous id. So it would always be 1, 2, 3, etc.
> > When the rule with id 1 will be deleted and a new rule will be added,
> > it will have the id 4 and not id 1.
> > In theory this can be a problem if at some point a rule will be added
> > and removed ~0 times. Then no more rules can be added because there
> > are no more ids.
> >
> > Change this such that when a new rule is added, search for an empty
> > rule id starting with value of 1 as value 0 is reserved.
> >
> > Fixes: c9da1ac1c212 ("net: microchip: sparx5: Adding initial tc flower support for VCAP API")
> > Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
> > ---
> >  drivers/net/ethernet/microchip/vcap/vcap_api.c | 7 +------
> >  drivers/net/ethernet/microchip/vcap/vcap_api.h | 1 -
> >  2 files changed, 1 insertion(+), 7 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.c b/drivers/net/ethernet/microchip/vcap/vcap_api.c
> > index b50d002b646dc..b65819f3a927f 100644
> > --- a/drivers/net/ethernet/microchip/vcap/vcap_api.c
> > +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.c
> > @@ -974,17 +974,12 @@ static u32 vcap_next_rule_addr(u32 addr, struct vcap_rule_internal *ri)
> >  /* Assign a unique rule id and autogenerate one if id == 0 */
> >  static u32 vcap_set_rule_id(struct vcap_rule_internal *ri)
> >  {
> > -     u32 next_id;
> > -
> >       if (ri->data.id != 0)
> >               return ri->data.id;
> >
> > -     next_id = ri->vctrl->rule_id + 1;
> > -
> > -     for (next_id = ri->vctrl->rule_id + 1; next_id < ~0; ++next_id) {
> > +     for (u32 next_id = 1; next_id < ~0; ++next_id) {
> >               if (!vcap_lookup_rule(ri->vctrl, next_id)) {
> 
> Or you can simply use IDA/IDR/XArray which takes care of all this :)

Thanks for the great suggestion. From what I can see IDR would be a
great match for this. Then we can also change the function
'vcap_lookup_rule' to use IDR.
On the other side, we will not continuously add/remove entries from the
VCAP, so I was not sure if it is worth bringing the IDR(with the radix
tree) for this.
Anyway I am open for IDR suggestion.
But lets wait for the VCAP maintainer to see what he thinks.

> 
> 
> >                       ri->data.id = next_id;
> > -                     ri->vctrl->rule_id = next_id;
> >                       break;
> >               }
> >       }
> > diff --git a/drivers/net/ethernet/microchip/vcap/vcap_api.h b/drivers/net/ethernet/microchip/vcap/vcap_api.h
> > index ca4499838306f..689c7270f2a89 100644
> > --- a/drivers/net/ethernet/microchip/vcap/vcap_api.h
> > +++ b/drivers/net/ethernet/microchip/vcap/vcap_api.h
> > @@ -268,7 +268,6 @@ struct vcap_operations {
> >
> >  /* VCAP API Client control interface */
> >  struct vcap_control {
> > -     u32 rule_id; /* last used rule id (unique across VCAP instances) */
> >       struct vcap_operations *ops;  /* client supplied operations */
> >       const struct vcap_info *vcaps; /* client supplied vcap models */
> >       const struct vcap_statistics *stats; /* client supplied vcap stats */
> > --
> > 2.38.0
> 
> Thanks,
> Olek

-- 
/Horatiu

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

* Re: [PATCH net-next] net: microchip: vcap: Change how the rule id is generated
  2022-11-28 14:29 [PATCH net-next] net: microchip: vcap: Change how the rule id is generated Horatiu Vultur
  2022-11-28 14:40 ` Alexander Lobakin
@ 2022-12-01  5:50 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-12-01  5:50 UTC (permalink / raw)
  To: Horatiu Vultur
  Cc: linux-arm-kernel, netdev, linux-kernel, davem, edumazet, kuba,
	pabeni, lars.povlsen, Steen.Hegelund, daniel.machon,
	UNGLinuxDriver, casper.casan

Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 28 Nov 2022 15:29:59 +0100 you wrote:
> Currently whenever a new rule id is generated, it picks up the next
> number bigger than previous id. So it would always be 1, 2, 3, etc.
> When the rule with id 1 will be deleted and a new rule will be added,
> it will have the id 4 and not id 1.
> In theory this can be a problem if at some point a rule will be added
> and removed ~0 times. Then no more rules can be added because there
> are no more ids.
> 
> [...]

Here is the summary with links:
  - [net-next] net: microchip: vcap: Change how the rule id is generated
    https://git.kernel.org/netdev/net-next/c/c1d8e3fb1a3b

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-12-01  5:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-28 14:29 [PATCH net-next] net: microchip: vcap: Change how the rule id is generated Horatiu Vultur
2022-11-28 14:40 ` Alexander Lobakin
2022-11-29 11:00   ` Horatiu Vultur
2022-12-01  5:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®