bonding: vlan handling changes
Subsystems (3)
PATCH 2/3 bonding: change the bond's vlan syncing functions with the standard ones
In reply to Nikolay AleksandrovFrom: Nikolay Aleksandrov <Nikolay Aleksandrov [email protected]>
Now we have vlan_vids_add/del_by_dev() which serve the same purpose as bond's bond_add/del_vlans_on_slave() with the good side effect of reverting the changes if one of the additions fails.
--- drivers/net/bonding/bond_main.c | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-)
drivers/net/bonding/bond_main.c +5 -30
@@ -521,33 +521,6 @@ static int bond_vlan_rx_kill_vid(struct net_device *bond_dev,return __bond_vlan_rx_kill_vid (bond_dev, proto, vid); } -static void bond_add_vlans_on_slave (struct bonding *bond,struct net_device *slave_dev) -{ -struct vlan_entry *vlan; -int res; - -list_for_each_entry (vlan, &bond->vlan_list, vlan_list) { - res =vlan_vid_add (slave_dev,htons (ETH_P_8021Q ), - vlan->vlan_id); -if (res) -pr_warning ("%s: Failed to add vlan id %d to device %s\n" , - bond->dev->name, vlan->vlan_id, - slave_dev->name); - } -} - -static void bond_del_vlans_from_slave (struct bonding *bond, -struct net_device *slave_dev) -{ -struct vlan_entry *vlan; - -list_for_each_entry (vlan, &bond->vlan_list, vlan_list) { -if (!vlan->vlan_id) -continue ; -vlan_vid_del (slave_dev,htons (ETH_P_8021Q ), vlan->vlan_id); - } -} -/*------------------------------- Link status -------------------------------*/ /*
@@ -1656,7 +1629,9 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)dev_mc_add (slave_dev, lacpdu_multicast); } -bond_add_vlans_on_slave (bond, slave_dev); +if (vlan_vids_add_by_dev (slave_dev, bond_dev)) +pr_warn ("%s: couldn't add bond vlan ids to %s" , + bond_dev->name, slave_dev->name);write_lock_bh (&bond->lock);
@@ -1832,7 +1807,7 @@ err_detach:if (!USES_PRIMARY (bond->params.mode))bond_hw_addr_flush (bond_dev, slave_dev); -bond_del_vlans_from_slave (bond, slave_dev); +vlan_vids_del_by_dev (slave_dev, bond_dev);write_lock_bh (&bond->lock);bond_detach_slave (bond, new_slave);if (bond->primary_slave == new_slave)
@@ -2028,7 +2003,7 @@ static int __bond_release_one(struct net_device *bond_dev,/* must do this from outside any spinlocks */ bond_destroy_slave_symlinks (bond_dev, slave_dev); -bond_del_vlans_from_slave (bond, slave_dev); +vlan_vids_del_by_dev (slave_dev, bond_dev);/* If the mode USES_PRIMARY, then this cases was handled above by * bond_change_active_slave(..., NULL)
Signature · 1 line
1.8.1.4
PATCH 1/3 bonding: fix vlan 0 addition and removal
In reply to Nikolay AleksandrovFrom: Nikolay Aleksandrov <Nikolay Aleksandrov [email protected]>
Right now if we have 8021q module loaded vlan 0 is added to all network devices but since the bonding is a software device (and doesn't have hw filters) it doesn't really need it, and moreover it causes the bond to output warnings when a slave is being released if the slave's mac is in use by the bonding like:
Aug 5 14:02:53 localhost kernel: [163030.313576] bonding: bond0: Warning: clearing HW address of bond0 while it still has VLANs. Aug 5 14:02:53 localhost kernel: [163030.313584] bonding: bond0: When
re-adding slaves, make sure the bond's HW address matches its VLANs'.
Although there aren't any real vlans on the bonding, it also causes the ALB/TLB modes to transmit their learning packets tagged with vlan 0, and bond_vlan_used() always evaluates to true when 8021q is loaded without adding any vlans on the bonding.
This is fixed by forbidding the addition/removal of vlan 0 through the bond's ndo_vlan_rx_add/kill_vid functions, and adding/removing it only when vlan 0 is in fact being created (or destroyed) on top of a bond interface in the bond's netdev handling function.
--- drivers/net/bonding/bond_main.c | 55 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 6 deletions(-)
drivers/net/bonding/bond_main.c +49 -6
@@ -434,12 +434,13 @@ int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb,*/ /** -* bond_vlan_rx_add_vid - Propagates adding an id to slaves +* __bond_vlan_rx_add_vid - Propagates adding an id to slaves * @bond_dev: bonding net device that got called +* @proto: vlan protocol * @vid: vlan id being added */ -static int bond_vlan_rx_add_vid (struct net_device *bond_dev, -__be16 proto,u16 vid) +static int __bond_vlan_rx_add_vid (struct net_device *bond_dev, +__be16 proto,u16 vid) {struct bonding *bond =netdev_priv (bond_dev);struct slave *slave;
@@ -468,13 +469,27 @@ unwind:return res; } +/* Wrapper for ndo_vlan_rx_add_vid */ +static int bond_vlan_rx_add_vid (struct net_device *bond_dev, +__be16 proto,u16 vid) +{ +/* don't add vlan 0 through ndo_rx_vlan_add_vid +* it's taken care of in the netdev event code upon NETDEV_REGISTER +*/ +if (!vid) +return 0 ; + +return __bond_vlan_rx_add_vid (bond_dev, proto, vid); +} +/** -* bond_vlan_rx_kill_vid - Propagates deleting an id to slaves +* __bond_vlan_rx_kill_vid - Propagates deleting an id to slaves * @bond_dev: bonding net device that got called +* @proto: vlan protocol * @vid: vlan id being removed */ -static int bond_vlan_rx_kill_vid (struct net_device *bond_dev, -__be16 proto,u16 vid) +static int __bond_vlan_rx_kill_vid (struct net_device *bond_dev, +__be16 proto,u16 vid) {struct bonding *bond =netdev_priv (bond_dev);struct slave *slave;
@@ -493,6 +508,19 @@ static int bond_vlan_rx_kill_vid(struct net_device *bond_dev,return 0 ; } +/* Wrapper for ndo_vlan_rx_kill_vid */ +static int bond_vlan_rx_kill_vid (struct net_device *bond_dev, +__be16 proto,u16 vid) +{ +/* don't remove vlan 0 through ndo_rx_vlan_kill_vid +* it's taken care of in the netdev event code upon NETDEV_UNREGISTER +*/ +if (!vid) +return 0 ; + +return __bond_vlan_rx_kill_vid (bond_dev, proto, vid); +} +static void bond_add_vlans_on_slave (struct bonding *bond,struct net_device *slave_dev) {struct vlan_entry *vlan;
@@ -3175,11 +3203,26 @@ static int bond_netdev_event(struct notifier_block *this, unsigned long event, void *ptr) { struct net_device *event_dev = netdev_notifier_info_to_dev(ptr); +struct net_device *real_dev;pr_debug ("event_dev: %s, event: %lx\n" , event_dev ? event_dev->name :"None" , event); +/* Take care of addition/removal of vlan 0 on top of a bond interface */ +if (is_vlan_dev (event_dev)) { + real_dev =vlan_dev_real_dev (event_dev); +if (netif_is_bond_master (real_dev) && +vlan_dev_vlan_id (event_dev) ==0 ) { +__be16 proto =htons (ETH_P_8021Q ); + +if (event ==NETDEV_REGISTER ) +__bond_vlan_rx_add_vid (real_dev, proto,0 ); +else if (event ==NETDEV_UNREGISTER ) +__bond_vlan_rx_kill_vid (real_dev, proto,0 ); + } + } +if (!(event_dev->priv_flags &IFF_BONDING ))return NOTIFY_DONE ;
Signature · 1 line
1.8.1.4
PATCH 3/3 bonding: unwind on bond_add_vlan add failure
In reply to Nikolay AleksandrovFrom: Nikolay Aleksandrov <Nikolay Aleksandrov [email protected]>
In case of bond_add_vlan() failure currently we'll have the vlan's refcnt bumped up in all slaves, but it will never go down because it failed to get added to the bond, so properly unwind the added vlan if bond_add_vlan fails.
--- drivers/net/bonding/bond_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/bonding/bond_main.c +2 -2
@@ -456,13 +456,13 @@ static int __bond_vlan_rx_add_vid(struct net_device *bond_dev,if (res) {pr_err ("%s: Error: Failed to add vlan id %d\n" , bond_dev->name, vid); -return res; + goto unwind; }return 0 ; unwind: -/* unwind from head to the slave that failed */ +/* unwind from the slave that failed */ bond_for_each_slave_continue_reverse (bond, slave)vlan_vid_del (slave->dev, proto, vid);
Signature · 1 line
1.8.1.4
cover bonding: vlan handling changes
From: Nikolay Aleksandrov <Nikolay Aleksandrov [email protected]>
Hi,
I've queued all of these patches to net-next since they're tightly related and the bugs that get fixed are not critical, so it's better to soak the changes a bit. Also I'd much rather fix this with the slave list change in. If you decide that they need to be posted for -net, let me know.
Patch 01 - fixes vlan 0 addition/removal since when we have 8021q module loaded it gets added to all network devices, this causes the bonding to output false warnings, output tagged learning packets (though with 0 tag) The fix is by denying the addition/removal of vlan 0 through the ndo_vlan functions and do it ourselves in the bond's netdev event handler when a vlan 0 is added/removed from a bonding device. Also a small comment fix which adds the missing proto parameter.
Patch 02 - switches the bonding to the now standard vlan syncing functions vlan_vids_add/del_by_dev() and removes the bonding specific ones.
Patch 03 - reverts vlan addition in case of bond_add_vlan failure because otherwise we may get bad vlan refcounts in the slaves.
Best regards,
Nikolay Aleksandrov
Nikolay Aleksandrov (3):
bonding: fix vlan 0 addition and removal
bonding: change the bond's vlan syncing functions with the standard
ones
bonding: unwind on bond_add_vlan add failure
drivers/net/bonding/bond_main.c | 86 +++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 34 deletions(-)
Signature · 1 line
1.8.1.4
Re: [net-next,1/3] bonding: fix vlan 0 addition and removal
In reply to Nikolay AleksandrovOn Mon, Aug 05, 2013 at 03:28:22PM +0200, [email protected] wrote:
...snip...
Quoted 4 lines
This is fixed by forbidding the addition/removal of vlan 0 through the bond's ndo_vlan_rx_add/kill_vid functions, and adding/removing it only when vlan 0 is in fact being created (or destroyed) on top of a bond interface in the bond's netdev handling function.
Isn't that a bit too intrusive/hacky? I don't think we should treat vlan id 0 somehow differently in terms of adding/removing, though I might be wrong...
Maybe we should just fix the bond_vlan_used() function? Something like this (I've done only basic testing, can do more thorough if needed), though it's also not a really clean fix:
Quoted 1 line
From
1c89abefebe90568ed52d2df59fcfdd650bc4696Mon Sep 17 00:00:00 2001
From: Veaceslav Falico <[email protected]>
Date: Mon, 5 Aug 2013 23:29:12 +0200
Subject: [PATCH] bonding: add vlan_uses_dev_rcu() and make bond_vlan_used() use it
Currently, bond_vlan_used() looks for any vlan, including the pseudo-vlan id 0, and always returns true if 8021q is loaded. This creates several bad situations - some warnings in __bond_release_one() because it thinks that we still have vlans while removing, sending LB packets with vlan id 0 and, possibly, other caused by vlan id 0.
Fix it by adding a new call, vlan_uses_dev_rcu(), which is the same as vlan_uses_dev(), but uses rcu_dereference() instead of rtnl, and thus we can use it in bond_vlan_used() wrapped in rcu_read_lock().
Also, use the pure vlan_uses_dev() in __bond_release_one() cause the rtnl lock is held there.
--- drivers/net/bonding/bond_alb.c | 1 - drivers/net/bonding/bond_main.c | 3 +-- drivers/net/bonding/bonding.h | 10 +++++++++- include/linux/if_vlan.h | 6 ++++++ net/8021q/vlan_core.c | 11 +++++++++++ 5 files changed, 27 insertions(+), 4 deletions(-)
drivers/net/bonding/bond_alb.c +0 -1
@@ -34,7 +34,6 @@#include <linux/if_arp.h> #include <linux/if_ether.h> #include <linux/if_bonding.h> -#include <linux/if_vlan.h> #include <linux/in.h> #include <net/ipx.h> #include <net/arp.h>
drivers/net/bonding/bond_main.c +1 -2
@@ -69,7 +69,6 @@#include <net/arp.h> #include <linux/mii.h> #include <linux/ethtool.h> -#include <linux/if_vlan.h> #include <linux/if_bonding.h> #include <linux/jiffies.h> #include <linux/preempt.h>
@@ -1976,7 +1975,7 @@ static int __bond_release_one(struct net_device *bond_dev,bond_set_carrier (bond);eth_hw_addr_random (bond_dev); -if (bond_vlan_used (bond)) { +if (vlan_uses_dev (bond_dev)) {pr_warning ("%s: Warning: clearing HW address of %s while it still has VLANs.\n" , bond_dev->name, bond_dev->name); pr_warning("%s: When re-adding slaves, make sure the bond's HW address matches its VLANs'.\n",
drivers/net/bonding/bonding.h +9 -1
@@ -23,6 +23,7 @@#include <linux/netpoll.h> #include <linux/inetdevice.h> #include <linux/etherdevice.h> +#include <linux/if_vlan.h> #include "bond_3ad.h" #include "bond_alb.h"
@@ -267,9 +268,16 @@ struct bonding {#endif /* CONFIG_DEBUG_FS */ }; +/* use vlan_uses_dev() if under rtnl */ static inline bool bond_vlan_used (struct bonding *bond) { -return !list_empty (&bond->vlan_list); +bool ret; + +rcu_read_lock (); + ret =vlan_uses_dev_rcu (bond->dev); +rcu_read_unlock (); + +return ret; }#define bond_slave_get_rcu (dev) \
include/linux/if_vlan.h +6 -0
@@ -101,6 +101,7 @@ extern void vlan_vids_del_by_dev(struct net_device *dev, const struct net_device *by_dev);extern bool vlan_uses_dev (const struct net_device *dev); +extern bool vlan_uses_dev_rcu (const struct net_device *dev);#else static inline struct net_device * __vlan_find_dev_deep(struct net_device *real_dev,
@@ -155,6 +156,11 @@ static inline bool vlan_uses_dev(const struct net_device *dev) {return false; } + +static inline bool vlan_uses_dev_rcu (const struct net_device *dev) +{ +return false; +}#endif static inline bool vlan_hw_offload_capable(netdev_features_t features,
net/8021q/vlan_core.c +11 -0
@@ -399,3 +399,14 @@ bool vlan_uses_dev(const struct net_device *dev)return vlan_info->grp.nr_vlan_devs ? true : false; }EXPORT_SYMBOL (vlan_uses_dev); + +bool vlan_uses_dev_rcu (const struct net_device *dev) +{ +struct vlan_info *vlan_info; + + vlan_info =rcu_dereference (dev->vlan_info); +if (!vlan_info) +return false; +return vlan_info->grp.nr_vlan_devs ? true : false; +} +EXPORT_SYMBOL (vlan_uses_dev_rcu);
Signature · 1 line
1.8.1.4
Re: [net-next, 2/3] bonding: change the bond's vlan syncing functions with the standard ones
In reply to Nikolay AleksandrovQuoted 11 lines · On Mon, Aug 05, 2013 at 03:28:23PM +0200, [email protected] wrote:
From: Nikolay Aleksandrov <Nikolay Aleksandrov [email protected]>
Now we have vlan_vids_add/del_by_dev() which serve the same purpose as bond's bond_add/del_vlans_on_slave() with the good side effect of reverting the changes if one of the additions fails.
Signed-off-by Nikolay Aleksandrov <[email protected]>---
drivers/net/bonding/bond_main.c| 35 +++++------------------------------1 file changed, 5 insertions(+), 30 deletions(-)
-25, awesome, great one :)
Quoted 68 lines
drivers/net/bonding/bond_main.c +5
-30@@ -521,33 +521,6 @@ static int bond_vlan_rx_kill_vid(struct net_device *bond_dev,return __bond_vlan_rx_kill_vid (bond_dev, proto, vid); } -static void bond_add_vlans_on_slave (struct bonding *bond,struct net_device *slave_dev) -{ -struct vlan_entry *vlan; -int res; - -list_for_each_entry (vlan, &bond->vlan_list, vlan_list) { - res =vlan_vid_add (slave_dev,htons (ETH_P_8021Q ), - vlan->vlan_id); -if (res) -pr_warning ("%s: Failed to add vlan id %d to device %s\n" , - bond->dev->name, vlan->vlan_id, - slave_dev->name); - } -} - -static void bond_del_vlans_from_slave (struct bonding *bond, -struct net_device *slave_dev) -{ -struct vlan_entry *vlan; - -list_for_each_entry (vlan, &bond->vlan_list, vlan_list) { -if (!vlan->vlan_id) -continue ; -vlan_vid_del (slave_dev,htons (ETH_P_8021Q ), vlan->vlan_id); - } -} -/*------------------------------- Link status -------------------------------*/ /* @@ -1656,7 +1629,9 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)dev_mc_add (slave_dev, lacpdu_multicast); } -bond_add_vlans_on_slave (bond, slave_dev); +if (vlan_vids_add_by_dev (slave_dev, bond_dev)) +pr_warn ("%s: couldn't add bond vlan ids to %s" , + bond_dev->name, slave_dev->name);write_lock_bh (&bond->lock);@@ -1832,7 +1807,7 @@ err_detach:if (!USES_PRIMARY (bond->params.mode))bond_hw_addr_flush (bond_dev, slave_dev); -bond_del_vlans_from_slave (bond, slave_dev); +vlan_vids_del_by_dev (slave_dev, bond_dev);write_lock_bh (&bond->lock);bond_detach_slave (bond, new_slave);if (bond->primary_slave == new_slave)@@ -2028,7 +2003,7 @@ static int __bond_release_one(struct net_device *bond_dev,/* must do this from outside any spinlocks */ bond_destroy_slave_symlinks (bond_dev, slave_dev); -bond_del_vlans_from_slave (bond, slave_dev); +vlan_vids_del_by_dev (slave_dev, bond_dev);/* If the mode USES_PRIMARY, then this cases was handled above by * bond_change_active_slave(..., NULL)
Re: [net-next,3/3] bonding: unwind on bond_add_vlan add failure
In reply to Nikolay AleksandrovQuoted 8 lines · On Mon, Aug 05, 2013 at 03:28:24PM +0200, [email protected] wrote:
From: Nikolay Aleksandrov <Nikolay Aleksandrov [email protected]>
In case of
bond_add_vlan()failure currently we'll have the vlan's refcnt bumped up in all slaves, but it will never go down because it failed to get added to the bond, so properly unwind the added vlan ifbond_add_vlanfails.Signed-off-by Nikolay Aleksandrov <[email protected]>
In case patch 1/3 from series goes in... Otherwise I think it will be needed to patch bond_vlan_rx_add_vid().
Quoted 25 lines
---
drivers/net/bonding/bond_main.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/net/bonding/bond_main.c +1
-1@@ -456,13 +456,13 @@ static int __bond_vlan_rx_add_vid(struct net_device *bond_dev,if (res) {pr_err ("%s: Error: Failed to add vlan id %d\n" , bond_dev->name, vid); -return res; + goto unwind; }return 0 ;unwind:
drivers/net/bonding/bond_main.c +1
-1-/* unwind from head to the slave that failed */ +/* unwind from the slave that failed */ bond_for_each_slave_continue_reverse(bond, slave) vlan_vid_del(slave->dev, proto, vid);
David Miller
maintainerRe: [net-next,1/3] bonding: fix vlan 0 addition and removal
In reply to Veaceslav FalicoFrom: Veaceslav Falico <[email protected]>
Date: Mon, 5 Aug 2013 23:51:26 +0200
Quoted 9 lines
drivers/net/bonding/bond_main.c +0
-1@@ -69,7 +69,6 @@#include <net/arp.h> #include <linux/mii.h> #include <linux/ethtool.h> -#include <linux/if_vlan.h> #include <linux/if_bonding.h> #include <linux/jiffies.h> #include <linux/preempt.h>
drivers/net/bonding/bond_main.c static int __bond_release_one(struct net_device · line 1979
Quoted 5 lines
drivers/net/bonding/bond_main.c +1
-0@@ -1976,7 +1975,7 @@ static int __bond_release_one(struct net_device *bond_dev,bond_set_carrier (bond);eth_hw_addr_random (bond_dev); - if (bond_vlan_used(bond)) { +if (vlan_uses_dev (bond_dev)) {
If you're adding a use of vlan_uses_dev(), you should retain the if_vlan.h include, not remove it.
David Miller
maintainerRe: [net-next,3/3] bonding: unwind on bond_add_vlan add failure
In reply to Veaceslav FalicoFrom: Veaceslav Falico <[email protected]>
Date: Mon, 5 Aug 2013 23:59:21 +0200
Quoted 8 lines · On Mon, Aug 05, 2013 at 03:28:24PM +0200, [email protected] wrote:
Quoted 7 lines
From: Nikolay Aleksandrov <Nikolay Aleksandrov [email protected]>
In case of
bond_add_vlan()failure currently we'll have the vlan's refcnt bumped up in all slaves, but it will never go down because it failed to get added to the bond, so properly unwind the added vlan ifbond_add_vlanfails.
Quoted 4 lines
Quoted 1 line
Signed-off-by Nikolay Aleksandrov <[email protected]>In case patch 1/3 from series goes in... Otherwise I think it will be needed to patch
bond_vlan_rx_add_vid().
I'm not happy with patch #1 and it needs more discussion between you two.
Re: [net-next,1/3] bonding: fix vlan 0 addition and removal
In reply to David MillerQuoted 12 lines · David Miller
From: Veaceslav Falico <[email protected]>
Date: Mon, 5 Aug 2013 23:51:26 +0200Quoted 9 lines
drivers/net/bonding/bond_main.c +0
-1@@ -69,7 +69,6 @@#include <net/arp.h> #include <linux/mii.h> #include <linux/ethtool.h> -#include <linux/if_vlan.h> #include <linux/if_bonding.h> #include <linux/jiffies.h> #include <linux/preempt.h> @@ -1976,7 +1975,7 @@ static int __bond_release_one(struct net_device
Quoted 8 lines
drivers/net/bonding/bond_main.c static int __bond_release_one(struct net_device *bond_dev, · line 1978
Quoted 5 lines
drivers/net/bonding/bond_main.c +1
-0*bond_dev,bond_set_carrier (bond);eth_hw_addr_random (bond_dev); - if (bond_vlan_used(bond)) { +if (vlan_uses_dev (bond_dev)) {If you're adding a use of
vlan_uses_dev(), you should retain theif_vlan.hinclude, not remove it.
I've added the usage of vlan_uses_dev_rcu() to bonding.h, so bonding.h already includes linux/if_vlan.h, and thus any other bonding file doesn't need it, cause it always includes bonding.h.
Sorry, my bad, should have added it to the commit message.
Re: [net-next,1/3] bonding: fix vlan 0 addition and removal
In reply to Veaceslav FalicoQuoted 11 lines · Veaceslav Falico
On Mon, Aug 05, 2013 at 03:28:22PM +0200, [email protected] wrote:
...snip...Quoted 4 lines
This is fixed by forbidding the addition/removal of vlan 0 through the bond's ndo_vlan_rx_add/kill_vid functions, and adding/removing it only when vlan 0 is in fact being created (or destroyed) on top of a bond interface in the bond's netdev handling function.
Isn't that a bit too intrusive/hacky? I don't think we should treat vlan id 0 somehow differently in terms of adding/removing, though I might be wrong...
I didn't want to touch the vlan code, so I solved the problem entirely in the bonding, mind you there's still a bug when loading the 8021q module we'll bump up every slave's vlan 0 refcnt without adding the vlan, and it won't get bumped down.
In my patch that problem still persists but only when an actual vlan 0 is being created.
Quoted 4 lines
Maybe we should just fix the
bond_vlan_used()function? Something like this (I've done only basic testing, can do more thorough if needed), though it's also not a really clean fix:
Yes, that would be optimal and I agree.
Quoted 19 lines
From
1c89abefebe90568ed52d2df59fcfdd650bc4696Mon Sep 17 00:00:00 2001
From: Veaceslav Falico <[email protected]>
Date: Mon, 5 Aug 2013 23:29:12 +0200
Subject: [PATCH] bonding: addvlan_uses_dev_rcu()and makebond_vlan_used()use itCurrently,
bond_vlan_used()looks for any vlan, including the pseudo-vlan id 0, and always returns true if 8021q is loaded. This creates several bad situations - some warnings in__bond_release_one()because it thinks that we still have vlans while removing, sending LB packets with vlan id 0 and, possibly, other caused by vlan id 0.Fix it by adding a new call,
vlan_uses_dev_rcu(), which is the same asvlan_uses_dev(), but usesrcu_dereference()instead of rtnl, and thus we can use it inbond_vlan_used()wrapped inrcu_read_lock().Also, use the pure
vlan_uses_dev()in__bond_release_one()cause the rtnl lock is held there.
Quoted 6 lines
CC Jay Vosburgh <[email protected]>CC Andy Gospodarek <[email protected]>CC Patrick McHardy <[email protected]>CC "David S. Miller" <[email protected]>Signed-off-by Veaceslav Falico <[email protected]>---
I'm okay with this fix, if Dave is also okay with this version then you can submit it as a patch, I'll re-base my third one later and resubmit.
Re: [net-next,1/3] bonding: fix vlan 0 addition and removal
In reply to Veaceslav FalicoQuoted 12 lines
From
1c89abefebe90568ed52d2df59fcfdd650bc4696Mon Sep 17 00:00:00 2001
From: Veaceslav Falico <[email protected]>
Date: Mon, 5 Aug 2013 23:29:12 +0200
Subject: [PATCH] bonding: addvlan_uses_dev_rcu()and makebond_vlan_used()use itCurrently,
bond_vlan_used()looks for any vlan, including the pseudo-vlan id 0, and always returns true if 8021q is loaded. This creates several bad situations - some warnings in__bond_release_one()because it thinks that we still have vlans while removing, sending LB packets with vlan id 0 and, possibly, other caused by vlan id 0.
Quoted 7 lines
Fix it by adding a new call,
vlan_uses_dev_rcu(), which is the same asvlan_uses_dev(), but usesrcu_dereference()instead of rtnl, and thus we can use it inbond_vlan_used()wrapped inrcu_read_lock().Also, use the pure
vlan_uses_dev()in__bond_release_one()cause the rtnl lock is held there.
Just 1 more note, you can't trust nr_vlan_devs under RCU.
Re: [net-next,1/3] bonding: fix vlan 0 addition and removal
In reply to Nikolay AleksandrovQuoted 12 lines · Nikolay Aleksandrov
Quoted 11 lines · Veaceslav Falico
On Mon, Aug 05, 2013 at 03:28:22PM +0200, [email protected] wrote:
...snip...Quoted 4 lines
This is fixed by forbidding the addition/removal of vlan 0 through the bond's ndo_vlan_rx_add/kill_vid functions, and adding/removing it only when vlan 0 is in fact being created (or destroyed) on top of a bond interface in the bond's netdev handling function.
Isn't that a bit too intrusive/hacky? I don't think we should treat vlan id 0 somehow differently in terms of adding/removing, though I might be wrong...
Quoted 6 lines
I didn't want to touch the vlan code, so I solved the problem entirely in the bonding, mind you there's still a bug when loading the 8021q module we'll bump up every slave's vlan 0 refcnt without adding the vlan, and it won't get bumped down.
In my patch that problem still persists but only when an actual vlan 0 is being created.
I'll look into that, though maybe we'll require another patch to fix it.
Quoted 26 lines
Quoted 5 lines
Maybe we should just fix the
bond_vlan_used()function? Something like this (I've done only basic testing, can do more thorough if needed), though it's also not a really clean fix:Yes, that would be optimal and I agree.
Quoted 19 lines
From
1c89abefebe90568ed52d2df59fcfdd650bc4696Mon Sep 17 00:00:00 2001
From: Veaceslav Falico <[email protected]>
Date: Mon, 5 Aug 2013 23:29:12 +0200
Subject: [PATCH] bonding: addvlan_uses_dev_rcu()and makebond_vlan_used()use itCurrently,
bond_vlan_used()looks for any vlan, including the pseudo-vlan id 0, and always returns true if 8021q is loaded. This creates several bad situations - some warnings in__bond_release_one()because it thinks that we still have vlans while removing, sending LB packets with vlan id 0 and, possibly, other caused by vlan id 0.Fix it by adding a new call,
vlan_uses_dev_rcu(), which is the same asvlan_uses_dev(), but usesrcu_dereference()instead of rtnl, and thus we can use it inbond_vlan_used()wrapped inrcu_read_lock().Also, use the pure
vlan_uses_dev()in__bond_release_one()cause the rtnl lock is held there.
Quoted 8 lines
Quoted 6 lines
CC Jay Vosburgh <[email protected]>CC Andy Gospodarek <[email protected]>CC Patrick McHardy <[email protected]>CC "David S. Miller" <[email protected]>Signed-off-by Veaceslav Falico <[email protected]>---
I'm okay with this fix, if Dave is also okay with this version then you can submit it as a patch, I'll re-base my third one later and resubmit.
Ok, great, then I'll get some testing with this patch and submit it.
Re: [net-next,1/3] bonding: fix vlan 0 addition and removal
In reply to Nikolay AleksandrovQuoted 12 lines · Nikolay Aleksandrov
Quoted 12 lines
From
1c89abefebe90568ed52d2df59fcfdd650bc4696Mon Sep 17 00:00:00 2001
From: Veaceslav Falico <[email protected]>
Date: Mon, 5 Aug 2013 23:29:12 +0200
Subject: [PATCH] bonding: addvlan_uses_dev_rcu()and makebond_vlan_used()use itCurrently,
bond_vlan_used()looks for any vlan, including the pseudo-vlan id 0, and always returns true if 8021q is loaded. This creates several bad situations - some warnings in__bond_release_one()because it thinks that we still have vlans while removing, sending LB packets with vlan id 0 and, possibly, other caused by vlan id 0.
Quoted 8 lines
Quoted 7 lines
Fix it by adding a new call,
vlan_uses_dev_rcu(), which is the same asvlan_uses_dev(), but usesrcu_dereference()instead of rtnl, and thus we can use it inbond_vlan_used()wrapped inrcu_read_lock().Also, use the pure
vlan_uses_dev()in__bond_release_one()cause the rtnl lock is held there.Just 1 more note, you can't trust
nr_vlan_devsunder RCU.
Yes, you're right, however we actually don't care anyway if we race with (un)register_vlan_dev() - we'll end up either in using the (un)registered vlan or not, and in both cases it's ok. So I don't see a real problem here, tbh, though I'll look into this also.
Re: [net-next,1/3] bonding: fix vlan 0 addition and removal
In reply to Veaceslav FalicoQuoted 14 lines · Veaceslav Falico
Quoted 13 lines · Nikolay Aleksandrov
Quoted 12 lines · Veaceslav Falico
On Mon, Aug 05, 2013 at 03:28:22PM +0200, [email protected] wrote:
...snip...Quoted 5 lines
This is fixed by forbidding the addition/removal of vlan 0 through the bond's ndo_vlan_rx_add/kill_vid functions, and adding/removing it only when
vlan 0 is in fact being created (or destroyed) on top of a bond interface in the bond's netdev handling function.Isn't that a bit too intrusive/hacky? I don't think we should treat vlan id 0 somehow differently in terms of adding/removing, though I might be wrong...
Quoted 9 lines
Quoted 6 lines
I didn't want to touch the vlan code, so I solved the problem entirely in the bonding, mind you there's still a bug when loading the 8021q module we'll bump up every slave's vlan 0 refcnt without adding the vlan, and it won't get bumped down.
In my patch that problem still persists but only when an actual vlan 0 is being created.I'll look into that, though maybe we'll require another patch to fix it.
You can take a look at:
http://www.spinics.net/lists/netdev/msg241858.html#.UgC5rxoW2Y4
and
http://www.spinics.net/lists/netdev/msg241999.html#.UgC5_BoW2Y4
I think I've explained the refcnt bug well there.
Thanks,
Nik
Re: [net-next,1/3] bonding: fix vlan 0 addition and removal
In reply to Veaceslav FalicoQuoted 20 lines · Veaceslav Falico
Quoted 19 lines · Nikolay Aleksandrov
Quoted 19 lines
From
1c89abefebe90568ed52d2df59fcfdd650bc4696Mon Sep 17 00:00:00 2001
From: Veaceslav Falico <[email protected]>
Date: Mon, 5 Aug 2013 23:29:12 +0200
Subject: [PATCH] bonding: addvlan_uses_dev_rcu()and makebond_vlan_used()use itCurrently,
bond_vlan_used()looks for any vlan, including the pseudo-vlan id 0, and always returns true if 8021q is loaded. This creates several bad situations - some warnings in__bond_release_one()because it thinks that we still have vlans while removing, sending LB packets with vlan id 0 and, possibly, other caused by vlan id 0.Fix it by adding a new call,
vlan_uses_dev_rcu(), which is the same asvlan_uses_dev(), but usesrcu_dereference()instead of rtnl, and thus we can use it inbond_vlan_used()wrapped inrcu_read_lock().Also, use the pure
vlan_uses_dev()in__bond_release_one()cause the rtnl lock is held there.
Quoted 6 lines
Quoted 1 line
Just 1 more note, you can't trust
nr_vlan_devsunder RCU.Yes, you're right, however we actually don't care anyway if we race with (un)register_vlan_dev() - we'll end up either in using the (un)registered vlan or not, and in both cases it's ok. So I don't see a real problem here, tbh, though I'll look into this also.
You might have stale value in the cache, the implications don't stop there. I'd like to avoid inconsistent behaviour if there's a way.
A solution that can be relied on and works always would be much more preferable.
Re: [net-next,1/3] bonding: fix vlan 0 addition and removal
Quoted 2 lines · Nikolay Aleksandrov
Quoted 1 line · Veaceslav Falico
On Tue, Aug 06, 2013 at 10:39:22AM +0200, Nikolay Aleksandrov wrote:
...snip...
Quoted 10 lines
Quoted 6 lines
Quoted 1 line
Just 1 more note, you can't trust
nr_vlan_devsunder RCU.Yes, you're right, however we actually don't care anyway if we race with (un)register_vlan_dev() - we'll end up either in using the (un)registered vlan or not, and in both cases it's ok. So I don't see a real problem here, tbh, though I'll look into this also.
You might have stale value in the cache, the implications don't stop there. I'd like to avoid inconsistent behaviour if there's a way.
A solution that can be relied on and works always would be much more preferable.
Sure :). I currently don't see it, except of using quite offensive locking strategies, but I'll try to figure something out.