[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <05481f69-84d5-dc80-a620-7cd9f0e5a758@nvidia.com>
Date: Tue, 15 Feb 2022 13:10:06 +0200
From: Nikolay Aleksandrov <nikolay@...dia.com>
To: Vladimir Oltean <vladimir.oltean@....com>
CC: "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
Jakub Kicinski <kuba@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
Florian Fainelli <f.fainelli@...il.com>,
Andrew Lunn <andrew@...n.ch>,
Vivien Didelot <vivien.didelot@...il.com>,
Vladimir Oltean <olteanv@...il.com>,
Roopa Prabhu <roopa@...dia.com>, Jiri Pirko <jiri@...dia.com>,
Ido Schimmel <idosch@...dia.com>,
Rafael Richter <rafael.richter@....de>,
Daniel Klauer <daniel.klauer@....de>,
Tobias Waldekranz <tobias@...dekranz.com>
Subject: Re: [PATCH v2 net-next 1/8] net: bridge: vlan: notify switchdev only
when something changed
On 15/02/2022 13:08, Nikolay Aleksandrov wrote:
> On 15/02/2022 12:30, Vladimir Oltean wrote:
>> On Tue, Feb 15, 2022 at 12:12:11PM +0200, Nikolay Aleksandrov wrote:
>>> On 15/02/2022 11:54, Vladimir Oltean wrote:
>>>> On Tue, Feb 15, 2022 at 10:54:26AM +0200, Nikolay Aleksandrov wrote:
>>>>>> +/* return true if anything will change as a result of __vlan_add_flags,
>>>>>> + * false otherwise
>>>>>> + */
>>>>>> +static bool __vlan_flags_would_change(struct net_bridge_vlan *v, u16 flags)
>>>>>> +{
>>>>>> + struct net_bridge_vlan_group *vg;
>>>>>> + u16 old_flags = v->flags;
>>>>>> + bool pvid_changed;
>>>>>>
>>>>>> - return ret || !!(old_flags ^ v->flags);
>>>>>> + if (br_vlan_is_master(v))
>>>>>> + vg = br_vlan_group(v->br);
>>>>>> + else
>>>>>> + vg = nbp_vlan_group(v->port);
>>>>>> +
>>>>>> + if (flags & BRIDGE_VLAN_INFO_PVID)
>>>>>> + pvid_changed = (vg->pvid == v->vid);
>>>>>> + else
>>>>>> + pvid_changed = (vg->pvid != v->vid);
>>>>>> +
>>>>>> + return pvid_changed || !!(old_flags ^ v->flags);
>>>>>> }
>>>>>
>>>>> These two have to depend on each other, otherwise it's error-prone and
>>>>> surely in the future someone will forget to update both.
>>>>> How about add a "commit" argument to __vlan_add_flags and possibly rename
>>>>> it to __vlan_update_flags, then add 2 small helpers like __vlan_update_flags_precommit
>>>>> with commit == false and __vlan_update_flags_commit with commit == true.
>>>>> Or some other naming, the point is to always use the same flow and checks
>>>>> when updating the flags to make sure people don't forget.
>>>>
>>>> You want to squash __vlan_flags_would_change() and __vlan_add_flags()
>>>> into a single function? But "would_change" returns bool, and "add"
>>>> returns void.
>>>>
>>>
>>> Hence the wrappers for commit == false and commit == true. You could name the precommit
>>> one __vlan_flags_would_change or something more appropriate. The point is to make
>>> sure we always update both when flags are changed.
>>
>> I still have a little doubt that I understood you properly.
>> Do you mean like this?
>>
>
> By the way I just noticed that __vlan_flags_would_change has another bug, it's testing
> vlan's flags against themselves without any change (old_flags == v->flags).
>
> I meant something similar to this (quickly hacked, untested, add flags probably
> could be renamed to something more appropriate):
>
> diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
> index 1402d5ca242d..1de69090d3cb 100644
> --- a/net/bridge/br_vlan.c
> +++ b/net/bridge/br_vlan.c
[snip]
> +}
> +
> +static bool __vlan_flags_would_change(struct net_bridge_vlan *v, u16 flags)
> +{
> + return __vlan_add_flags(v, flags, false);
> +}
> +
> +static bool __vlan_flags_commit(struct net_bridge_vlan *v, u16 flags)
> +{
blah, obviously should be void here and ignore the return value
> + return __vlan_add_flags(v, flags, true);
> }
>
> static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
Powered by blists - more mailing lists