diff mbox series

[net-next,2/9] net/sched: act_pedit, setup offload action for action stats query

Message ID 20230201161039.20714-3-ozsh@nvidia.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: flow_offload: add support for per action hw stats | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 5 maintainers not CCed: pabeni@redhat.com kuba@kernel.org edumazet@google.com xiyou.wangcong@gmail.com davem@davemloft.net
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
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: 0 this patch: 0
netdev/checkpatch warning WARNING: line length of 96 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Oz Shlomo Feb. 1, 2023, 4:10 p.m. UTC
A single tc pedit action may be translated to multiple flow_offload
actions.
Offload only actions that translate to a single pedit command value.

Signed-off-by: Oz Shlomo <ozsh@nvidia.com>
---
 net/sched/act_pedit.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

Comments

Pedro Tammela Feb. 1, 2023, 8:59 p.m. UTC | #1
On 01/02/2023 13:10, Oz Shlomo wrote:
> A single tc pedit action may be translated to multiple flow_offload
> actions.
> Offload only actions that translate to a single pedit command value.
> 
> Signed-off-by: Oz Shlomo <ozsh@nvidia.com>
> ---
>   net/sched/act_pedit.c | 24 +++++++++++++++++++++++-
>   1 file changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
> index a0378e9f0121..abceef794f28 100644
> --- a/net/sched/act_pedit.c
> +++ b/net/sched/act_pedit.c
> @@ -522,7 +522,29 @@ static int tcf_pedit_offload_act_setup(struct tc_action *act, void *entry_data,
>   		}
>   		*index_inc = k;
>   	} else {
> -		return -EOPNOTSUPP;
> +		struct flow_offload_action *fl_action = entry_data;
> +		u32 last_cmd;
> +		int k;
> +
> +		for (k = 0; k < tcf_pedit_nkeys(act); k++) {
> +			u32 cmd = tcf_pedit_cmd(act, k);
> +
> +			if (k && cmd != last_cmd)
> +				return -EOPNOTSUPP;

I believe an extack message here is very valuable

> +
> +			last_cmd = cmd;
> +			switch (cmd) {
> +			case TCA_PEDIT_KEY_EX_CMD_SET:
> +				fl_action->id = FLOW_ACTION_MANGLE;
> +				break;
> +			case TCA_PEDIT_KEY_EX_CMD_ADD:
> +				fl_action->id = FLOW_ACTION_ADD;
> +				break;
> +			default:
> +				NL_SET_ERR_MSG_MOD(extack, "Unsupported pedit command offload");
> +				return -EOPNOTSUPP;
> +			}
> +		}

Shouldn't this switch case be outside of the for-loop?

>   	}
>   
>   	return 0;
Oz Shlomo Feb. 2, 2023, 7:21 a.m. UTC | #2
On 01/02/2023 22:59, Pedro Tammela wrote:
> On 01/02/2023 13:10, Oz Shlomo wrote:
>> A single tc pedit action may be translated to multiple flow_offload
>> actions.
>> Offload only actions that translate to a single pedit command value.
>>
>> Signed-off-by: Oz Shlomo <ozsh@nvidia.com>
>> ---
>>   net/sched/act_pedit.c | 24 +++++++++++++++++++++++-
>>   1 file changed, 23 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
>> index a0378e9f0121..abceef794f28 100644
>> --- a/net/sched/act_pedit.c
>> +++ b/net/sched/act_pedit.c
>> @@ -522,7 +522,29 @@ static int tcf_pedit_offload_act_setup(struct 
>> tc_action *act, void *entry_data,
>>           }
>>           *index_inc = k;
>>       } else {
>> -        return -EOPNOTSUPP;
>> +        struct flow_offload_action *fl_action = entry_data;
>> +        u32 last_cmd;
>> +        int k;
>> +
>> +        for (k = 0; k < tcf_pedit_nkeys(act); k++) {
>> +            u32 cmd = tcf_pedit_cmd(act, k);
>> +
>> +            if (k && cmd != last_cmd)
>> +                return -EOPNOTSUPP;
>
> I believe an extack message here is very valuable
Sure thing, I will add one
>
>> +
>> +            last_cmd = cmd;
>> +            switch (cmd) {
>> +            case TCA_PEDIT_KEY_EX_CMD_SET:
>> +                fl_action->id = FLOW_ACTION_MANGLE;
>> +                break;
>> +            case TCA_PEDIT_KEY_EX_CMD_ADD:
>> +                fl_action->id = FLOW_ACTION_ADD;
>> +                break;
>> +            default:
>> +                NL_SET_ERR_MSG_MOD(extack, "Unsupported pedit 
>> command offload");
>> +                return -EOPNOTSUPP;
>> +            }
>> +        }
>
> Shouldn't this switch case be outside of the for-loop?

You are right, this can be done outside the for loop.

I will refactor the code

>
>>       }
>>         return 0;
>
Marcelo Ricardo Leitner Feb. 3, 2023, 3:31 p.m. UTC | #3
On Thu, Feb 02, 2023 at 09:21:15AM +0200, Oz Shlomo wrote:
>
> On 01/02/2023 22:59, Pedro Tammela wrote:
> > On 01/02/2023 13:10, Oz Shlomo wrote:
> > > A single tc pedit action may be translated to multiple flow_offload
> > > actions.
> > > Offload only actions that translate to a single pedit command value.
> > >
> > > Signed-off-by: Oz Shlomo <ozsh@nvidia.com>
> > > ---
> > >   net/sched/act_pedit.c | 24 +++++++++++++++++++++++-
> > >   1 file changed, 23 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
> > > index a0378e9f0121..abceef794f28 100644
> > > --- a/net/sched/act_pedit.c
> > > +++ b/net/sched/act_pedit.c
> > > @@ -522,7 +522,29 @@ static int tcf_pedit_offload_act_setup(struct
> > > tc_action *act, void *entry_data,
> > >           }
> > >           *index_inc = k;
> > >       } else {
> > > -        return -EOPNOTSUPP;
> > > +        struct flow_offload_action *fl_action = entry_data;
> > > +        u32 last_cmd;
> > > +        int k;
> > > +
> > > +        for (k = 0; k < tcf_pedit_nkeys(act); k++) {
> > > +            u32 cmd = tcf_pedit_cmd(act, k);
> > > +
> > > +            if (k && cmd != last_cmd)
> > > +                return -EOPNOTSUPP;
> >
> > I believe an extack message here is very valuable
> Sure thing, I will add one
> >
> > > +
> > > +            last_cmd = cmd;
> > > +            switch (cmd) {
> > > +            case TCA_PEDIT_KEY_EX_CMD_SET:
> > > +                fl_action->id = FLOW_ACTION_MANGLE;
> > > +                break;
> > > +            case TCA_PEDIT_KEY_EX_CMD_ADD:
> > > +                fl_action->id = FLOW_ACTION_ADD;
> > > +                break;
> > > +            default:
> > > +                NL_SET_ERR_MSG_MOD(extack, "Unsupported pedit
> > > command offload");
> > > +                return -EOPNOTSUPP;
> > > +            }
> > > +        }
> >
> > Shouldn't this switch case be outside of the for-loop?
>
> You are right, this can be done outside the for loop.

To before the for-loop, that is?
Because otherwise it will parse all commands and then fail, which seems heavier
than how it is here.

- validate the first one
- ensure the rest follows

>
> I will refactor the code
>
> >
> > >       }
> > >         return 0;
> >
>
Oz Shlomo Feb. 5, 2023, 1 p.m. UTC | #4
On 03/02/2023 17:31, Marcelo Ricardo Leitner wrote:
> On Thu, Feb 02, 2023 at 09:21:15AM +0200, Oz Shlomo wrote:
>> On 01/02/2023 22:59, Pedro Tammela wrote:
>>> On 01/02/2023 13:10, Oz Shlomo wrote:
>>>> A single tc pedit action may be translated to multiple flow_offload
>>>> actions.
>>>> Offload only actions that translate to a single pedit command value.
>>>>
>>>> Signed-off-by: Oz Shlomo <ozsh@nvidia.com>
>>>> ---
>>>>    net/sched/act_pedit.c | 24 +++++++++++++++++++++++-
>>>>    1 file changed, 23 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
>>>> index a0378e9f0121..abceef794f28 100644
>>>> --- a/net/sched/act_pedit.c
>>>> +++ b/net/sched/act_pedit.c
>>>> @@ -522,7 +522,29 @@ static int tcf_pedit_offload_act_setup(struct
>>>> tc_action *act, void *entry_data,
>>>>            }
>>>>            *index_inc = k;
>>>>        } else {
>>>> -        return -EOPNOTSUPP;
>>>> +        struct flow_offload_action *fl_action = entry_data;
>>>> +        u32 last_cmd;
>>>> +        int k;
>>>> +
>>>> +        for (k = 0; k < tcf_pedit_nkeys(act); k++) {
>>>> +            u32 cmd = tcf_pedit_cmd(act, k);
>>>> +
>>>> +            if (k && cmd != last_cmd)
>>>> +                return -EOPNOTSUPP;
>>> I believe an extack message here is very valuable
>> Sure thing, I will add one
>>>> +
>>>> +            last_cmd = cmd;
>>>> +            switch (cmd) {
>>>> +            case TCA_PEDIT_KEY_EX_CMD_SET:
>>>> +                fl_action->id = FLOW_ACTION_MANGLE;
>>>> +                break;
>>>> +            case TCA_PEDIT_KEY_EX_CMD_ADD:
>>>> +                fl_action->id = FLOW_ACTION_ADD;
>>>> +                break;
>>>> +            default:
>>>> +                NL_SET_ERR_MSG_MOD(extack, "Unsupported pedit
>>>> command offload");
>>>> +                return -EOPNOTSUPP;
>>>> +            }
>>>> +        }
>>> Shouldn't this switch case be outside of the for-loop?
>> You are right, this can be done outside the for loop.
> To before the for-loop, that is?
> Because otherwise it will parse all commands and then fail, which seems heavier
> than how it is here.
>
> - validate the first one
> - ensure the rest follows
Right
>> I will refactor the code
>>
>>>>        }
>>>>          return 0;
diff mbox series

Patch

diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
index a0378e9f0121..abceef794f28 100644
--- a/net/sched/act_pedit.c
+++ b/net/sched/act_pedit.c
@@ -522,7 +522,29 @@  static int tcf_pedit_offload_act_setup(struct tc_action *act, void *entry_data,
 		}
 		*index_inc = k;
 	} else {
-		return -EOPNOTSUPP;
+		struct flow_offload_action *fl_action = entry_data;
+		u32 last_cmd;
+		int k;
+
+		for (k = 0; k < tcf_pedit_nkeys(act); k++) {
+			u32 cmd = tcf_pedit_cmd(act, k);
+
+			if (k && cmd != last_cmd)
+				return -EOPNOTSUPP;
+
+			last_cmd = cmd;
+			switch (cmd) {
+			case TCA_PEDIT_KEY_EX_CMD_SET:
+				fl_action->id = FLOW_ACTION_MANGLE;
+				break;
+			case TCA_PEDIT_KEY_EX_CMD_ADD:
+				fl_action->id = FLOW_ACTION_ADD;
+				break;
+			default:
+				NL_SET_ERR_MSG_MOD(extack, "Unsupported pedit command offload");
+				return -EOPNOTSUPP;
+			}
+		}
 	}
 
 	return 0;