Re: [patch net-next v3 03/10] flow_offload: check for basic action hw stats type

Jiri Pirko
2020-03-10T10:13:39Z

Mon, Mar 09, 2020 at 08:17:22PM CET, kuba@kernel.org wrote:
>On Sat, 7 Mar 2020 07:59:48 +0100 Jiri Pirko wrote:
>> >> +static inline bool
>> >> +flow_action_hw_stats_types_check(const struct flow_action *action,
>> >> + struct netlink_ext_ack *extack,
>> >> + u8 allowed_hw_stats_type)
>> >> +{
>> >> + const struct flow_action_entry *action_entry;
>> >> +
>> >> + if (!flow_action_has_entries(action))
>> >> + return true;
>> >> + if (!flow_action_mixed_hw_stats_types_check(action, extack))
>> >> + return false;
>> >> + action_entry = flow_action_first_entry_get(action);
>> >> + if (!allowed_hw_stats_type &&
>> >> + action_entry->hw_stats_type != FLOW_ACTION_HW_STATS_TYPE_ANY) {
>> >> + NL_SET_ERR_MSG_MOD(extack, "Driver supports only default HW stats type \"any\"");
>> >> + return false;
>> >> + } else if (allowed_hw_stats_type &&
>> >> + action_entry->hw_stats_type != allowed_hw_stats_type) {
>> >
>> >Should this be an logical 'and' if we're doing it the bitfield way?
>>
>> No. I driver passes allowed_hw_stats_type != 0, means that allowed_hw_stats_type
>> should be checked against action_entry->hw_stats_type.
>
>Right, the "allowed_hw_stats_type &&" is fine.
>
>> With bitfield, this is a bit awkward, I didn't figure out to do it
>> better though.
>
>The bitfield passed from user space means any of the set bits, right?
>
>Condition would be better as:
>
>allowed_hw_stats_type && (allowed_hw_stats_type & entry->hw_stats_type)
>
>Otherwise passing more than one bit will not work well, no?
>
>Driver can pass IMMEDIATE | DELAYED, action has IMMEDIATE, your

Yeah, this is something that made more sense for non-bitfield. Basically
this is for simple driver which supports only one type. If the driver
supports more types (like mlxsw), it should not call this function.

>condition would reject it.. Same if driver has only one type and user
>space asks for any of a few.
>
>Drivers can't do a straight comparisons either, but:
>
>if (act->stats & TYPE1) {
> /* preferred stats type*/
>} else if (act->stats & TYPE2) {
> /* also supported, lower prio */
>} else if (act->Stats & TYPE3) {
> /* lowest prio */
>}