diff mbox series

[net,v2,1/4] bonding: add bond_ether_setup helper

Message ID 20230314111426.1254998-2-razor@blackwall.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series bonding: properly restore flags when bond changes ether type | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 21 this patch: 22
netdev/cc_maintainers fail 2 blamed authors not CCed: nikolay@cumulusnetworks.com monis@Voltaire.COM; 2 maintainers not CCed: nikolay@cumulusnetworks.com monis@Voltaire.COM
netdev/build_clang fail Errors and warnings before: 18 this patch: 20
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn fail Errors and warnings before: 21 this patch: 22
netdev/checkpatch warning WARNING: 'muticast' may be misspelled - perhaps 'multicast'? WARNING: Please use correct Fixes: style 'Fixes: <12 chars of sha1> ("<title line>")' - ie: 'Fixes: e36b9d16c6a6 ("bonding: clean muticast addresses when device changes type")'
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Nikolay Aleksandrov March 14, 2023, 11:14 a.m. UTC
Add bond_ether_setup helper which will be used in the following patches
to fix all ether_setup() calls in the bonding driver. It takes care of both
IFF_MASTER and IFF_SLAVE flags, the former is always restored and the
latter only if it was set.

Fixes: e36b9d16c6a6d ("bonding: clean muticast addresses when device changes type")
Fixes: 7d5cd2ce5292 ("bonding: correctly handle bonding type change on enslave failure")
Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
---
 drivers/net/bonding/bond_main.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Michal Kubiak March 14, 2023, 2:58 p.m. UTC | #1
On Tue, Mar 14, 2023 at 01:14:23PM +0200, Nikolay Aleksandrov wrote:
> Add bond_ether_setup helper which will be used in the following patches
> to fix all ether_setup() calls in the bonding driver. It takes care of both
> IFF_MASTER and IFF_SLAVE flags, the former is always restored and the
> latter only if it was set.
> 
> Fixes: e36b9d16c6a6d ("bonding: clean muticast addresses when device changes type")
> Fixes: 7d5cd2ce5292 ("bonding: correctly handle bonding type change on enslave failure")
> Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
> ---
>  drivers/net/bonding/bond_main.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index 00646aa315c3..d41024ad2c18 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
> @@ -1775,6 +1775,18 @@ void bond_lower_state_changed(struct slave *slave)
>  		slave_err(bond_dev, slave_dev, "Error: %s\n", errmsg);	\
>  } while (0)
>  
> +/* ether_setup() resets bond_dev's flags so we always have to restore
> + * IFF_MASTER, and only restore IFF_SLAVE if it was set
> + */

I would suggest using the kernel pattern for function documentation.
At first glance, the name "ether_setup" at the beginning is easy to be
confused with the function name (bond_ether_setup).

> +static void bond_ether_setup(struct net_device *bond_dev)
> +{
> +	unsigned int slave_flag = bond_dev->flags & IFF_SLAVE;
> +
> +	ether_setup(bond_dev);
> +	bond_dev->flags |= IFF_MASTER | slave_flag;
> +	bond_dev->priv_flags &= ~IFF_TX_SKB_SHARING;
> +}
> +
>  /* enslave device <slave> to bond device <master> */
>  int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
>  		 struct netlink_ext_ack *extack)

It seems you never call this newly added helper in the current patch. I
think it creates a compilation warning ("defined but not used").
Please add your function in the patch where you actually use it.

> -- 
> 2.39.2
> 


Thanks,
Michal
Nikolay Aleksandrov March 14, 2023, 3:08 p.m. UTC | #2
On 14/03/2023 16:58, Michal Kubiak wrote:
> On Tue, Mar 14, 2023 at 01:14:23PM +0200, Nikolay Aleksandrov wrote:
>> Add bond_ether_setup helper which will be used in the following patches
>> to fix all ether_setup() calls in the bonding driver. It takes care of both
>> IFF_MASTER and IFF_SLAVE flags, the former is always restored and the
>> latter only if it was set.
>>
>> Fixes: e36b9d16c6a6d ("bonding: clean muticast addresses when device changes type")
>> Fixes: 7d5cd2ce5292 ("bonding: correctly handle bonding type change on enslave failure")
>> Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
>> ---
>>  drivers/net/bonding/bond_main.c | 12 ++++++++++++
>>  1 file changed, 12 insertions(+)
>>
>> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
>> index 00646aa315c3..d41024ad2c18 100644
>> --- a/drivers/net/bonding/bond_main.c
>> +++ b/drivers/net/bonding/bond_main.c
>> @@ -1775,6 +1775,18 @@ void bond_lower_state_changed(struct slave *slave)
>>  		slave_err(bond_dev, slave_dev, "Error: %s\n", errmsg);	\
>>  } while (0)
>>  
>> +/* ether_setup() resets bond_dev's flags so we always have to restore
>> + * IFF_MASTER, and only restore IFF_SLAVE if it was set
>> + */
> 
> I would suggest using the kernel pattern for function documentation.
> At first glance, the name "ether_setup" at the beginning is easy to be
> confused with the function name (bond_ether_setup).
> 

This is an internal helper, I don't think it needs a full kernel doc.

>> +static void bond_ether_setup(struct net_device *bond_dev)
>> +{
>> +	unsigned int slave_flag = bond_dev->flags & IFF_SLAVE;
>> +
>> +	ether_setup(bond_dev);
>> +	bond_dev->flags |= IFF_MASTER | slave_flag;
>> +	bond_dev->priv_flags &= ~IFF_TX_SKB_SHARING;
>> +}
>> +
>>  /* enslave device <slave> to bond device <master> */
>>  int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
>>  		 struct netlink_ext_ack *extack)
> 
> It seems you never call this newly added helper in the current patch. I
> think it creates a compilation warning ("defined but not used").
> Please add your function in the patch where you actually use it.
> 

I'm adding the helper in a separate patch to emphasize it and focus the review.
I have written in the commit message that the next two fixes will be using it.
IMO, this should be ok.

>> -- 
>> 2.39.2
>>
> 
> 
> Thanks,
> Michal

Cheers,
 Nik
Nikolay Aleksandrov March 14, 2023, 3:12 p.m. UTC | #3
On 14/03/2023 17:08, Nikolay Aleksandrov wrote:
> On 14/03/2023 16:58, Michal Kubiak wrote:
>> On Tue, Mar 14, 2023 at 01:14:23PM +0200, Nikolay Aleksandrov wrote:
>>> Add bond_ether_setup helper which will be used in the following patches
>>> to fix all ether_setup() calls in the bonding driver. It takes care of both
>>> IFF_MASTER and IFF_SLAVE flags, the former is always restored and the
>>> latter only if it was set.
>>>
>>> Fixes: e36b9d16c6a6d ("bonding: clean muticast addresses when device changes type")
>>> Fixes: 7d5cd2ce5292 ("bonding: correctly handle bonding type change on enslave failure")
>>> Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
>>> ---
>>>  drivers/net/bonding/bond_main.c | 12 ++++++++++++
>>>  1 file changed, 12 insertions(+)
>>>
[snip]
>> Please add your function in the patch where you actually use it.
>>
> 
> I'm adding the helper in a separate patch to emphasize it and focus the review.
> I have written in the commit message that the next two fixes will be using it.
> IMO, this should be ok.
> 

Also since both fixes are for different commits this should be backportable
for both, that makes it easier to pick if only one of the two would be ported to a
specific version (i.e. the first fix is for a commit from 2009, second 2015).

Cheers,
 Nik
Jay Vosburgh March 14, 2023, 3:34 p.m. UTC | #4
Nikolay Aleksandrov <razor@blackwall.org> wrote:

>Add bond_ether_setup helper which will be used in the following patches
>to fix all ether_setup() calls in the bonding driver. It takes care of both
>IFF_MASTER and IFF_SLAVE flags, the former is always restored and the
>latter only if it was set.
>
>Fixes: e36b9d16c6a6d ("bonding: clean muticast addresses when device changes type")
>Fixes: 7d5cd2ce5292 ("bonding: correctly handle bonding type change on enslave failure")
>Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
>---
> drivers/net/bonding/bond_main.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
>diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
>index 00646aa315c3..d41024ad2c18 100644
>--- a/drivers/net/bonding/bond_main.c
>+++ b/drivers/net/bonding/bond_main.c
>@@ -1775,6 +1775,18 @@ void bond_lower_state_changed(struct slave *slave)
> 		slave_err(bond_dev, slave_dev, "Error: %s\n", errmsg);	\
> } while (0)
> 
>+/* ether_setup() resets bond_dev's flags so we always have to restore
>+ * IFF_MASTER, and only restore IFF_SLAVE if it was set
>+ */
>+static void bond_ether_setup(struct net_device *bond_dev)
>+{
>+	unsigned int slave_flag = bond_dev->flags & IFF_SLAVE;
>+
>+	ether_setup(bond_dev);
>+	bond_dev->flags |= IFF_MASTER | slave_flag;
>+	bond_dev->priv_flags &= ~IFF_TX_SKB_SHARING;
>+}

	Is setting IFF_MASTER always correct here?  I note that patch #2
is replacing code that does not set IFF_MASTER, whereas patch #3 is
replacing code that does set IFF_MASTER.

	Presuming that this is the desired behavior, perhaps mention
explicitly in the commentary that bond_ether_setup() is only for use on
a bond master device.  The nomenclature "bond_dev" does imply that, but
it's not explicit.

	Also, why is the call to ether_setup() from bond_setup() not
also being converted to bond_ether_setup()?

	-J

>+
> /* enslave device <slave> to bond device <master> */
> int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
> 		 struct netlink_ext_ack *extack)
>-- 
>2.39.2
>

---
	-Jay Vosburgh, jay.vosburgh@canonical.com
Nikolay Aleksandrov March 14, 2023, 3:37 p.m. UTC | #5
On 14/03/2023 17:34, Jay Vosburgh wrote:
> Nikolay Aleksandrov <razor@blackwall.org> wrote:
> 
>> Add bond_ether_setup helper which will be used in the following patches
>> to fix all ether_setup() calls in the bonding driver. It takes care of both
>> IFF_MASTER and IFF_SLAVE flags, the former is always restored and the
>> latter only if it was set.
>>
>> Fixes: e36b9d16c6a6d ("bonding: clean muticast addresses when device changes type")
>> Fixes: 7d5cd2ce5292 ("bonding: correctly handle bonding type change on enslave failure")
>> Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
>> ---
>> drivers/net/bonding/bond_main.c | 12 ++++++++++++
>> 1 file changed, 12 insertions(+)
>>
>> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
>> index 00646aa315c3..d41024ad2c18 100644
>> --- a/drivers/net/bonding/bond_main.c
>> +++ b/drivers/net/bonding/bond_main.c
>> @@ -1775,6 +1775,18 @@ void bond_lower_state_changed(struct slave *slave)
>> 		slave_err(bond_dev, slave_dev, "Error: %s\n", errmsg);	\
>> } while (0)
>>
>> +/* ether_setup() resets bond_dev's flags so we always have to restore
>> + * IFF_MASTER, and only restore IFF_SLAVE if it was set
>> + */
>> +static void bond_ether_setup(struct net_device *bond_dev)
>> +{
>> +	unsigned int slave_flag = bond_dev->flags & IFF_SLAVE;
>> +
>> +	ether_setup(bond_dev);
>> +	bond_dev->flags |= IFF_MASTER | slave_flag;
>> +	bond_dev->priv_flags &= ~IFF_TX_SKB_SHARING;
>> +}
> 
> 	Is setting IFF_MASTER always correct here?  I note that patch #2
> is replacing code that does not set IFF_MASTER, whereas patch #3 is
> replacing code that does set IFF_MASTER.
> 
> 	Presuming that this is the desired behavior, perhaps mention
> explicitly in the commentary that bond_ether_setup() is only for use on
> a bond master device.  The nomenclature "bond_dev" does imply that, but
> it's not explicit.
> 

Setting IFF_MASTER is always correct because we're talking about a bond master device.
I.e. we're restoring the flags to a bond device itself. The bugs are different because
previously I had fixed the error path (partly, missed the IFF_SLAVE), but I just noticed
the normal enslave path while fixing the IFF_SLAVE one now. :)
So yes, both paths need the same treatment for both flags.

> 	Also, why is the call to ether_setup() from bond_setup() not
> also being converted to bond_ether_setup()?

That is more of a cleanup, the one there is correct because flags are set after that.
In that case only IFF_MASTER is needed, IFF_SLAVE cannot be set. Once these are
merged in net-next I'll send a followup to use it there, too.

> 
> 	-J
> 

Thanks,
 Nik

>> +
>> /* enslave device <slave> to bond device <master> */
>> int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
>> 		 struct netlink_ext_ack *extack)
>> -- 
>> 2.39.2
>>
> 
> ---
> 	-Jay Vosburgh, jay.vosburgh@canonical.com
Jakub Kicinski March 15, 2023, 7:55 a.m. UTC | #6
On Tue, 14 Mar 2023 13:14:23 +0200 Nikolay Aleksandrov wrote:
> +/* ether_setup() resets bond_dev's flags so we always have to restore
> + * IFF_MASTER, and only restore IFF_SLAVE if it was set
> + */
> +static void bond_ether_setup(struct net_device *bond_dev)
> +{
> +	unsigned int slave_flag = bond_dev->flags & IFF_SLAVE;
> +
> +	ether_setup(bond_dev);
> +	bond_dev->flags |= IFF_MASTER | slave_flag;
> +	bond_dev->priv_flags &= ~IFF_TX_SKB_SHARING;
> +}
> +

We can't split this from patch 2, it's going to generate a warning
under normal build flags, people may have WERROR set these days..
Nikolay Aleksandrov March 15, 2023, 8:21 a.m. UTC | #7
On 15/03/2023 09:55, Jakub Kicinski wrote:
> On Tue, 14 Mar 2023 13:14:23 +0200 Nikolay Aleksandrov wrote:
>> +/* ether_setup() resets bond_dev's flags so we always have to restore
>> + * IFF_MASTER, and only restore IFF_SLAVE if it was set
>> + */
>> +static void bond_ether_setup(struct net_device *bond_dev)
>> +{
>> +	unsigned int slave_flag = bond_dev->flags & IFF_SLAVE;
>> +
>> +	ether_setup(bond_dev);
>> +	bond_dev->flags |= IFF_MASTER | slave_flag;
>> +	bond_dev->priv_flags &= ~IFF_TX_SKB_SHARING;
>> +}
>> +
> 
> We can't split this from patch 2, it's going to generate a warning
> under normal build flags, people may have WERROR set these days..

Oh well, that's unfortunate. I'll leave a note in patch 03 that it depends
on the helper added in the other fix.

Thanks,
 Nik
diff mbox series

Patch

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 00646aa315c3..d41024ad2c18 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1775,6 +1775,18 @@  void bond_lower_state_changed(struct slave *slave)
 		slave_err(bond_dev, slave_dev, "Error: %s\n", errmsg);	\
 } while (0)
 
+/* ether_setup() resets bond_dev's flags so we always have to restore
+ * IFF_MASTER, and only restore IFF_SLAVE if it was set
+ */
+static void bond_ether_setup(struct net_device *bond_dev)
+{
+	unsigned int slave_flag = bond_dev->flags & IFF_SLAVE;
+
+	ether_setup(bond_dev);
+	bond_dev->flags |= IFF_MASTER | slave_flag;
+	bond_dev->priv_flags &= ~IFF_TX_SKB_SHARING;
+}
+
 /* enslave device <slave> to bond device <master> */
 int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
 		 struct netlink_ext_ack *extack)