Skip to contentSkip to conversation

bonding: remove vlan special handling

PATCH Superseded Veaceslav Falico 3 participants 20 messages Aug 26, 2013 – Aug 28, 2013

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#6 lore raw

PATCH 4/9 bonding: make bond_arp_send_all use upper device list

In reply to Veaceslav Falico

Currently, bond_arp_send_all() is aware only of vlans, which breaks configurations like bond <- bridge (or any other 'upper' device) with IP (which is quite a common scenario for virt setups).

To fix this we convert the bond_arp_send_all() to first verify if the rt device is the bond itself, and if not - to go through its list of upper devices to see if any of them match the route device for the target. If the match is a vlan device - we also save its vlan_id and tag it in bond_arp_send().

Also, clean the function a bit to be more readable.

v1: use netdev_for_each_upper_dev()

CC Jay Vosburgh <[email protected]>
CC Andy Gospodarek <[email protected]>
---
 drivers/net/bonding/bond_main.c |   84 ++++++++++++++------------------------
 1 files changed, 31 insertions(+), 53 deletions(-)
drivers/net/bonding/bond_main.c +31 -53
index 7407e65..40eb250 100644
@@ -2444,30 +2444,16 @@ static void bond_arp_send(struct net_device *slave_dev, int arp_op, __be32 dest_
 
 static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
 {
-	int i, vlan_id;
-	__be32 *targets = bond->params.arp_targets;
-	struct vlan_entry *vlan;
-	struct net_device *vlan_dev = NULL;
+	struct net_device *upper;
+	struct list_head *iter;
 	struct rtable *rt;
+	__be32 *targets = bond->params.arp_targets, addr;
+	int i, vlan_id;
 
-	for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
-		__be32 addr;
-		if (!targets[i])
-			break;
+	for (i = 0; i < BOND_MAX_ARP_TARGETS && targets[i]; i++) {
 		pr_debug("basa: target %pI4\n", &targets[i]);
-		if (!bond_vlan_used(bond)) {
-			pr_debug("basa: empty vlan: arp_send\n");
-			addr = bond_confirm_addr(bond->dev, targets[i], 0);
-			bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
-				      addr, 0);
-			continue;
-		}
 
-		/*
-		 * If VLANs are configured, we do a route lookup to
-		 * determine which VLAN interface would be used, so we
-		 * can tag the ARP with the proper VLAN tag.
-		 */
+		/* Find out through which dev should the packet go */
 		rt = ip_route_output(dev_net(bond->dev), targets[i], 0,
 				     RTO_ONLINK, 0);
 		if (IS_ERR(rt)) {
@@ -2478,47 +2464,39 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
 			continue;
 		}
 
-		/*
-		 * This target is not on a VLAN
-		 */
-		if (rt->dst.dev == bond->dev) {
-			ip_rt_put(rt);
-			pr_debug("basa: rtdev == bond->dev: arp_send\n");
-			addr = bond_confirm_addr(bond->dev, targets[i], 0);
-			bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
-				      addr, 0);
-			continue;
-		}
-
 		vlan_id = 0;
-		list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
-			rcu_read_lock();
-			vlan_dev = __vlan_find_dev_deep(bond->dev,
-							htons(ETH_P_8021Q),
-							vlan->vlan_id);
-			rcu_read_unlock();
-			if (vlan_dev == rt->dst.dev) {
-				vlan_id = vlan->vlan_id;
-				pr_debug("basa: vlan match on %s %d\n",
-				       vlan_dev->name, vlan_id);
-				break;
-			}
-		}
 
-		if (vlan_id && vlan_dev) {
-			ip_rt_put(rt);
-			addr = bond_confirm_addr(vlan_dev, targets[i], 0);
-			bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
-				      addr, vlan_id);
-			continue;
+		/* bond device itself */
+		if (rt->dst.dev == bond->dev)
+			goto found;
+
+		/* search for upper device, like vlan/bridge/team/etc */
+		rcu_read_lock();
+		netdev_for_each_upper_dev(bond->dev, upper, iter) {
+			if (upper == rt->dst.dev) {
+				/* if it's a vlan - get its VID */
+				if (is_vlan_dev(rt->dst.dev))
+					vlan_id = vlan_dev_vlan_id(rt->dst.dev);
+
+				rcu_read_unlock();
+				goto found;
+			}
 		}
+		rcu_read_unlock();
 
-		if (net_ratelimit()) {
+		/* Not our device - skip */
+		if (net_ratelimit())
 			pr_warning("%s: no path to arp_ip_target %pI4 via rt.dev %s\n",
 				   bond->dev->name, &targets[i],
 				   rt->dst.dev ? rt->dst.dev->name : "NULL");
-		}
 		ip_rt_put(rt);
+		continue;
+
+found:
+		addr = bond_confirm_addr(rt->dst.dev, targets[i], 0);
+		ip_rt_put(rt);
+		bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
+			      addr, vlan_id);
 	}
 }
 
Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/9 net: add netdev_upper_get_next_dev(dev, iter)

In reply to Veaceslav Falico

This function returns the next dev in the dev->upper_dev_list after the struct list_head **iter position, and updates *iter accordingly. Returns NULL if there are no devices left.

v1: new patch

CC "David S. Miller" <[email protected]>
CC Eric Dumazet <[email protected]>
CC Jiri Pirko <[email protected]>
CC Alexander Duyck <[email protected]>
CC Cong Wang <[email protected]>
---
 net/core/dev.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
net/core/dev.c +25 -0
index 1ed2b66..566e99a 100644
@@ -4477,6 +4477,31 @@ struct net_device *netdev_master_upper_dev_get(struct net_device *dev)
 }
 EXPORT_SYMBOL(netdev_master_upper_dev_get);
 
+/* netdev_upper_get_next_dev - Get the next dev from upper list
+ * @dev: device
+ * @iter: list_head ** of the current position
+ *
+ * Gets the next device from the dev's upper list, starting from iter
+ * position. The caller must hold RCU read lock.
+ */
+struct net_device *netdev_upper_get_next_dev(struct net_device *dev,
+					     struct list_head **iter)
+{
+	struct netdev_upper *upper;
+
+	WARN_ON_ONCE(!rcu_read_lock_held());
+
+	upper = list_entry_rcu((*iter)->next, struct netdev_upper, list);
+
+	if (&upper->list == &dev->upper_dev_list)
+		return NULL;
+
+	*iter = &upper->list;
+
+	return upper->dev;
+}
+EXPORT_SYMBOL(netdev_upper_get_next_dev);
+
 /**
  * netdev_master_upper_dev_get_rcu - Get master upper device
  * @dev: device
Signature · 1 line
1.7.1
#0 lore raw

cover bonding: remove vlan special handling

v1: Per Jiri's advice, remove the exported netdev_upper struct to keep it
inside dev.c only, and instead implement a macro to iterate over the list and return only net_device *.

The aim of this patchset is to remove bondings' own vlan handling as much as possible and replace it with the netdev upper device functionality.

This is achieved by adding a helper function to upper dev list handling - netdev_upper_get_next_dev(dev, iter), which returns the next device after the list_head **iter, and sets *iter to the next list_head *. This patchset also adds netdev_for_each_upper_dev(dev, upper, iter), which iterates through the whole dev->upper_dev_list, setting upper to the net_device. The only special treatment of vlans remains in rlb code.

This patchset solves several issues with bonding, simplifies it overall, RCUify further and exports upper list functions for any other users which might also want to get rid of its own vlan_lists.

I'm testing it continuously currently, no issues found, will update on anything.

CC Jay Vosburgh <[email protected]>
CC Andy Gospodarek <[email protected]>
CC "David S. Miller" <[email protected]>
CC Eric Dumazet <[email protected]>
CC Jiri Pirko <[email protected]>
CC Alexander Duyck <[email protected]>
CC Cong Wang <[email protected]>
---
 drivers/net/bonding/bond_alb.c  |   75 ++++++------
 drivers/net/bonding/bond_alb.h  |    2 -
 drivers/net/bonding/bond_main.c |  244 ++++++++-------------------------------
 drivers/net/bonding/bonding.h   |   21 +++-
 include/linux/netdevice.h       |   10 ++
 net/core/dev.c                  |   25 ++++
 6 files changed, 133 insertions(+), 244 deletions(-)
#7 lore raw

PATCH 5/9 bonding: convert bond_has_this_ip() to use upper devices

Currently, bond_has_this_ip() is aware only of vlan upper devices, and thus will return false if the address is associated with the upper bridge or any other device, and thus will break the arp logic.

Fix this by using the upper device list. For every upper device we verify if the address associated with it is our address, and if yes - return true.

v1: use netdev_for_each_upper_dev()

CC Jay Vosburgh <[email protected]>
CC Andy Gospodarek <[email protected]>
---
 drivers/net/bonding/bond_main.c |   25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)
drivers/net/bonding/bond_main.c +13 -12
index 40eb250..dbac1ce 100644
@@ -2392,24 +2392,25 @@ re_arm:
 	}
 }
 
-static int bond_has_this_ip(struct bonding *bond, __be32 ip)
+static bool bond_has_this_ip(struct bonding *bond, __be32 ip)
 {
-	struct vlan_entry *vlan;
-	struct net_device *vlan_dev;
+	struct net_device *upper;
+	struct list_head *iter;
+	bool ret = false;
 
 	if (ip == bond_confirm_addr(bond->dev, 0, ip))
-		return 1;
+		return true;
 
-	list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
-		rcu_read_lock();
-		vlan_dev = __vlan_find_dev_deep(bond->dev, htons(ETH_P_8021Q),
-						vlan->vlan_id);
-		rcu_read_unlock();
-		if (vlan_dev && ip == bond_confirm_addr(vlan_dev, 0, ip))
-			return 1;
+	rcu_read_lock();
+	netdev_for_each_upper_dev(bond->dev, upper, iter) {
+		if (ip == bond_confirm_addr(upper, 0, ip)) {
+			ret = true;
+			break;
+		}
 	}
+	rcu_read_unlock();
 
-	return 0;
+	return ret;
 }
 
 /*
Signature · 1 line
1.7.1
#4 lore raw

PATCH 2/9 net: add netdev_for_each_upper_dev()

In reply to Veaceslav Falico

The new macro netdev_for_each_upper_dev(dev, upper, iter) iterates through the dev->upper_dev_list starting from the first element, using the netdev_upper_get_next_dev(dev, &iter).

Must be called under RCU read lock.

v1: new patch

CC "David S. Miller" <[email protected]>
CC Eric Dumazet <[email protected]>
CC Jiri Pirko <[email protected]>
CC Alexander Duyck <[email protected]>
CC Cong Wang <[email protected]>
---
 include/linux/netdevice.h |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
include/linux/netdevice.h +10 -0
index 077363d..85590b6 100644
@@ -2767,6 +2767,16 @@ extern int		bpf_jit_enable;
 extern bool netdev_has_upper_dev(struct net_device *dev,
 				 struct net_device *upper_dev);
 extern bool netdev_has_any_upper_dev(struct net_device *dev);
+extern struct net_device *netdev_upper_get_next_dev(struct net_device *dev,
+						    struct list_head **iter);
+
+/* iterate through upper list, must be called under RCU read lock */
+#define netdev_for_each_upper_dev(dev, upper, iter) \
+	for (iter = &(dev)->upper_dev_list, \
+	     upper = netdev_upper_get_next_dev(dev, &(iter)); \
+	     upper; \
+	     upper = netdev_upper_get_next_dev(dev, &(iter)))
+
 extern struct net_device *netdev_master_upper_dev_get(struct net_device *dev);
 extern struct net_device *netdev_master_upper_dev_get_rcu(struct net_device *dev);
 extern int netdev_upper_dev_link(struct net_device *dev,
Signature · 1 line
1.7.1
#18 lore raw

PATCH 8/9 bonding: make alb_send_learning_packets() use upper dev list

In reply to Veaceslav Falico

Currently, if there are vlans on top of bond, alb_send_learning_packets() will never send LPs from the bond itself (i.e. untagged), which might leave untagged clients unupdated.

Also, the 'circular vlan' logic (i.e. update only MAX_LP_BURST vlans at a time, and save the last vlan for the next update) is really suboptimal - in case of lots of vlans it will take a lot of time to update every vlan. It is also never called in any hot path and sends only a few small packets - thus the optimization by itself is useless.

So remove the whole current_alb_vlan/MAX_LP_BURST logic from alb_send_learning_packets(). Instead, we'll first send a packet untagged and then traverse the upper dev list, sending a tagged packet for each vlan found. Also, remove the MAX_LP_BURST define - we already don't need it.

v1: use netdev_for_each_upper_dev()

CC Jay Vosburgh <[email protected]>
CC Andy Gospodarek <[email protected]>
---
 drivers/net/bonding/bond_alb.c |   33 +++++++++++++--------------------
 drivers/net/bonding/bond_alb.h |    1 -
 2 files changed, 13 insertions(+), 21 deletions(-)
drivers/net/bonding/bond_alb.c +11 -18
index 3ca3c85..676d6d6 100644
@@ -1013,27 +1013,20 @@ static void alb_send_lp_vid(struct slave *slave, u8 mac_addr[],
 static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
 {
 	struct bonding *bond = bond_get_bond_by_slave(slave);
-	u16 vlan_id;
-	int i;
-
-	for (i = 0; i < MAX_LP_BURST; i++) {
-		vlan_id = 0;
-
-		if (bond_vlan_used(bond)) {
-			struct vlan_entry *vlan;
+	struct net_device *upper;
+	struct list_head *iter;
 
-			vlan = bond_next_vlan(bond,
-					      bond->alb_info.current_alb_vlan);
-
-			bond->alb_info.current_alb_vlan = vlan;
-			if (!vlan)
-				continue;
-
-			vlan_id = vlan->vlan_id;
-		}
+	/* send untagged */
+	alb_send_lp_vid(slave, mac_addr, 0);
 
-		alb_send_lp_vid(slave, mac_addr, vlan_id);
+	/* loop through vlans and send one packet for each */
+	rcu_read_lock();
+	netdev_for_each_upper_dev(bond->dev, upper, iter) {
+		if (upper->priv_flags & IFF_802_1Q_VLAN)
+			alb_send_lp_vid(slave, mac_addr,
+					vlan_dev_vlan_id(upper));
 	}
+	rcu_read_unlock();
 }
 
 static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[])
drivers/net/bonding/bond_alb.h +0 -1
index e7a5b8b..e139172 100644
@@ -53,7 +53,6 @@ struct slave;
 
 
 #define TLB_NULL_INDEX		0xffffffff
-#define MAX_LP_BURST		3
 
 /* rlb defs */
 #define RLB_HASH_TABLE_SIZE	256
Signature · 1 line
1.7.1
#19 lore raw

PATCH 9/9 bonding: remove vlan_list/current_alb_vlan

In reply to Veaceslav Falico

Currently there are no real users of vlan_list/current_alb_vlan, only the helpers which maintain them, so remove them.

v1: no change

CC Jay Vosburgh <[email protected]>
CC Andy Gospodarek <[email protected]>
---
 drivers/net/bonding/bond_alb.c  |    5 --
 drivers/net/bonding/bond_alb.h  |    1 -
 drivers/net/bonding/bond_main.c |  133 +--------------------------------------
 drivers/net/bonding/bonding.h   |    6 --
 4 files changed, 2 insertions(+), 143 deletions(-)
drivers/net/bonding/bond_alb.c +0 -5
index 676d6d6..17e2cef 100644
@@ -1763,11 +1763,6 @@ int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr)
 
 void bond_alb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
 {
-	if (bond->alb_info.current_alb_vlan &&
-	    (bond->alb_info.current_alb_vlan->vlan_id == vlan_id)) {
-		bond->alb_info.current_alb_vlan = NULL;
-	}
-
 	if (bond->alb_info.rlb_enabled) {
 		rlb_clear_vlan(bond, vlan_id);
 	}
drivers/net/bonding/bond_alb.h +0 -1
index e139172..e02c9c5 100644
@@ -169,7 +169,6 @@ struct alb_bond_info {
 						 * rx traffic should be
 						 * rebalanced
 						 */
-	struct vlan_entry	*current_alb_vlan;
 };
 
 int bond_alb_initialize(struct bonding *bond, int rlb_enabled);
drivers/net/bonding/bond_main.c +2 -131

173 lines not on this page · raw message

drivers/net/bonding/bonding.h +0 -6
index 9392e00..a26b134 100644
@@ -185,11 +185,6 @@ struct bond_parm_tbl {
 
 #define BOND_MAX_MODENAME_LEN 20
 
-struct vlan_entry {
-	struct list_head vlan_list;
-	unsigned short vlan_id;
-};
-
 struct slave {
 	struct net_device *dev; /* first - useful for panic debug */
 	struct list_head list;
@@ -254,7 +249,6 @@ struct bonding {
 	struct   ad_bond_info ad_info;
 	struct   alb_bond_info alb_info;
 	struct   bond_params params;
-	struct   list_head vlan_list;
 	struct   workqueue_struct *wq;
 	struct   delayed_work mii_work;
 	struct   delayed_work arp_work;
Signature · 1 line
1.7.1
#16 lore raw

PATCH 6/9 bonding: use vlan_uses_dev() in __bond_release_one()

In reply to Veaceslav Falico

We always hold the rtnl_lock() in __bond_release_one(), so use vlan_uses_dev() instead of bond_vlan_used().

v1: no change

CC Jay Vosburgh <[email protected]>
CC Andy Gospodarek <[email protected]>
---
 drivers/net/bonding/bond_main.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/bonding/bond_main.c +1 -1
index dbac1ce..aaf14a0 100644
@@ -1954,7 +1954,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",
Signature · 1 line
1.7.1
#17 lore raw

PATCH 7/9 bonding: split alb_send_learning_packets()

In reply to Veaceslav Falico

Create alb_send_lp_vid(), which will handle the skb/lp creation, vlan tagging and sending, and use it in alb_send_learning_packets().

This way all the logic remains in alb_send_learning_packets(), which becomes a lot more cleaner and easier to understand.

v1: no change

CC Jay Vosburgh <[email protected]>
CC Andy Gospodarek <[email protected]>
---
 drivers/net/bonding/bond_alb.c |   59 +++++++++++++++++++++++----------------
 1 files changed, 35 insertions(+), 24 deletions(-)
drivers/net/bonding/bond_alb.c +35 -24
index 3a5db7b..3ca3c85 100644
@@ -971,35 +971,53 @@ static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
 
 /*********************** tlb/rlb shared functions *********************/
 
-static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
+static void alb_send_lp_vid(struct slave *slave, u8 mac_addr[],
+			    u16 vid)
 {
-	struct bonding *bond = bond_get_bond_by_slave(slave);
 	struct learning_pkt pkt;
+	struct sk_buff *skb;
 	int size = sizeof(struct learning_pkt);
-	int i;
+	char *data;
 
 	memset(&pkt, 0, size);
 	memcpy(pkt.mac_dst, mac_addr, ETH_ALEN);
 	memcpy(pkt.mac_src, mac_addr, ETH_ALEN);
 	pkt.type = cpu_to_be16(ETH_P_LOOP);
 
-	for (i = 0; i < MAX_LP_BURST; i++) {
-		struct sk_buff *skb;
-		char *data;
+	skb = dev_alloc_skb(size);
+	if (!skb)
+		return;
 
-		skb = dev_alloc_skb(size);
+	data = skb_put(skb, size);
+	memcpy(data, &pkt, size);
+
+	skb_reset_mac_header(skb);
+	skb->network_header = skb->mac_header + ETH_HLEN;
+	skb->protocol = pkt.type;
+	skb->priority = TC_PRIO_CONTROL;
+	skb->dev = slave->dev;
+
+	if (vid) {
+		skb = vlan_put_tag(skb, htons(ETH_P_8021Q), vid);
 		if (!skb) {
+			pr_err("%s: Error: failed to insert VLAN tag\n",
+			       slave->bond->dev->name);
 			return;
 		}
+	}
 
-		data = skb_put(skb, size);
-		memcpy(data, &pkt, size);
+	dev_queue_xmit(skb);
+}
 
-		skb_reset_mac_header(skb);
-		skb->network_header = skb->mac_header + ETH_HLEN;
-		skb->protocol = pkt.type;
-		skb->priority = TC_PRIO_CONTROL;
-		skb->dev = slave->dev;
+
+static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
+{
+	struct bonding *bond = bond_get_bond_by_slave(slave);
+	u16 vlan_id;
+	int i;
+
+	for (i = 0; i < MAX_LP_BURST; i++) {
+		vlan_id = 0;
 
 		if (bond_vlan_used(bond)) {
 			struct vlan_entry *vlan;
@@ -1008,20 +1026,13 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
 					      bond->alb_info.current_alb_vlan);
 
 			bond->alb_info.current_alb_vlan = vlan;
-			if (!vlan) {
-				kfree_skb(skb);
+			if (!vlan)
 				continue;
-			}
 
-			skb = vlan_put_tag(skb, htons(ETH_P_8021Q), vlan->vlan_id);
-			if (!skb) {
-				pr_err("%s: Error: failed to insert VLAN tag\n",
-				       bond->dev->name);
-				continue;
-			}
+			vlan_id = vlan->vlan_id;
 		}
 
-		dev_queue_xmit(skb);
+		alb_send_lp_vid(slave, mac_addr, vlan_id);
 	}
 }
 
Signature · 1 line
1.7.1
#5 lore raw

PATCH 3/9 bonding: use netdev_upper list in bond_vlan_used

In reply to Veaceslav Falico

Convert bond_vlan_used() to traverse the upper device list to see if we have any vlans above us. It's protected by rcu, and in case we are holding rtnl_lock we should call vlan_uses_dev() instead - it's faster.

v1: use netdev_for_each_upper_dev()

CC Jay Vosburgh <[email protected]>
CC Andy Gospodarek <[email protected]>
---
 drivers/net/bonding/bonding.h |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
drivers/net/bonding/bonding.h +14 -1
index 4bf52d5..9392e00 100644
@@ -267,9 +267,22 @@ struct bonding {
 #endif /* CONFIG_DEBUG_FS */
 };
 
+/* if we hold rtnl_lock() - call vlan_uses_dev() */
 static inline bool bond_vlan_used(struct bonding *bond)
 {
-	return !list_empty(&bond->vlan_list);
+	struct net_device *upper;
+	struct list_head *iter;
+
+	rcu_read_lock();
+	netdev_for_each_upper_dev(bond->dev, upper, iter) {
+		if (upper->priv_flags & IFF_802_1Q_VLAN) {
+			rcu_read_unlock();
+			return true;
+		}
+	}
+	rcu_read_unlock();
+
+	return false;
 }
 
 #define bond_slave_get_rcu(dev) \
Signature · 1 line
1.7.1
#8 lore raw

Re: [PATCH net-next v1 5/9] bonding: convert bond_has_this_ip() to use upper devices

In reply to Veaceslav Falico
Quoted 40 lines · Mon, Aug 26, 2013 at 10:32:38PM CEST, [email protected] wrote:

Currently, bond_has_this_ip() is aware only of vlan upper devices, and thus will return false if the address is associated with the upper bridge or any other device, and thus will break the arp logic.

Fix this by using the upper device list. For every upper device we verify if the address associated with it is our address, and if yes - return true.

v1: use netdev_for_each_upper_dev()

CC Jay Vosburgh <[email protected]>
CC Andy Gospodarek <[email protected]>

---
drivers/net/bonding/bond_main.c | 25 +++++++++++++------------

1 files changed, 13 insertions(+), 12 deletions(-)
drivers/net/bonding/bond_main.c +5 -7
index 40eb250..dbac1ce 100644
@@ -2392,24 +2392,25 @@ re_arm:
 	}
 }
 
-static int bond_has_this_ip(struct bonding *bond, __be32 ip)
+static bool bond_has_this_ip(struct bonding *bond, __be32 ip)
 {
-	struct vlan_entry *vlan;
-	struct net_device *vlan_dev;
+	struct net_device *upper;
+	struct list_head *iter;
+	bool ret = false;
 
 	if (ip == bond_confirm_addr(bond->dev, 0, ip))
-		return 1;
+		return true;
 
-	list_for_each_entry(vlan, &bond->vlan_list, vlan_list) {
-		rcu_read_lock();
-		vlan_dev = __vlan_find_dev_deep(bond->dev, htons(ETH_P_8021Q),

drivers/net/bonding/bond_main.c re_arm: · line 2409

Quoted 10 lines
drivers/net/bonding/bond_main.c +6 -4
-						vlan->vlan_id);
-		rcu_read_unlock();
-		if (vlan_dev && ip == bond_confirm_addr(vlan_dev, 0, ip))
-			return 1;
+	rcu_read_lock();
+	netdev_for_each_upper_dev(bond->dev, upper, iter) {
+		if (ip == bond_confirm_addr(upper, 0, ip)) {
+			ret = true;
+			break;
+		}

You need the same recursion __vlan_find_dev_deep() is doing. If you do not do that, you will miss anything over the first upper level.

Quoted 15 lines
drivers/net/bonding/bond_main.c +2 -1
 	}
+	rcu_read_unlock();
 
-	return 0;
+	return ret;
 }
 
 /*
Signature · 6 lines
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

Re: [PATCH net-next v1 1/9] net: add netdev_upper_get_next_dev(dev, iter)

In reply to Veaceslav Falico
Quoted 23 lines · Mon, Aug 26, 2013 at 10:32:34PM CEST, [email protected] wrote:

This function returns the next dev in the dev->upper_dev_list after the struct list_head **iter position, and updates *iter accordingly. Returns NULL if there are no devices left.

v1: new patch

CC "David S. Miller" <[email protected]>
CC Eric Dumazet <[email protected]>
CC Jiri Pirko <[email protected]>
CC Alexander Duyck <[email protected]>
CC Cong Wang <[email protected]>

---
net/core/dev.c | 25 +++++++++++++++++++++++++

1 files changed, 25 insertions(+), 0 deletions(-)
net/core/dev.c +0 -0
index 1ed2b66..566e99a 100644
@@ -4477,6 +4477,31 @@ struct net_device *netdev_master_upper_dev_get(struct net_device *dev)
 }
 EXPORT_SYMBOL(netdev_master_upper_dev_get);

net/core/dev.c struct net_device *netdev_master_upper_dev_get(struct net_device *dev) · line 4488

Quoted 10 lines
net/core/dev.c +9 -0
 
+/* netdev_upper_get_next_dev - Get the next dev from upper list
+ * @dev: device
+ * @iter: list_head ** of the current position
+ *
+ * Gets the next device from the dev's upper list, starting from iter
+ * position. The caller must hold RCU read lock.
+ */
+struct net_device *netdev_upper_get_next_dev(struct net_device *dev,
+					     struct list_head **iter)

This should be probably rather named "netdev_upper_get_next_dev_rcu" That way it is clear right away. Also if you introduce non-rcu variant in future, you won't introduce confusion :)

Quoted 22 lines
net/core/dev.c +16 -0
+{
+	struct netdev_upper *upper;
+
+	WARN_ON_ONCE(!rcu_read_lock_held());
+
+	upper = list_entry_rcu((*iter)->next, struct netdev_upper, list);
+
+	if (&upper->list == &dev->upper_dev_list)
+		return NULL;
+
+	*iter = &upper->list;
+
+	return upper->dev;
+}
+EXPORT_SYMBOL(netdev_upper_get_next_dev);
+
 /**
 * netdev_master_upper_dev_get_rcu - Get master upper device
 * @dev: device
Signature · 1 line
1.7.1
#3 lore raw

Re: [PATCH net-next v1 1/9] net: add netdev_upper_get_next_dev(dev, iter)

Quoted 1 line · Jiri Pirko

Mon, Aug 26, 2013 at 10:32:34PM CEST, [email protected] wrote:

...snip...

Quoted 7 lines

net/core/dev.c struct net_device *netdev_master_upper_dev_get(struct net_device *dev) · line 4488

Quoted 2 lines
net/core/dev.c +2 -0
+struct net_device *netdev_upper_get_next_dev(struct net_device *dev,
+					     struct list_head **iter)

This should be probably rather named "netdev_upper_get_next_dev_rcu" That way it is clear right away. Also if you introduce non-rcu variant in future, you won't introduce confusion :)

Agreed, it will be easier, will do in v2.

#9 lore raw

Re: [PATCH net-next v1 5/9] bonding: convert bond_has_this_ip() to use upper devices

In reply to Jiri Pirko
Quoted 1 line · Jiri Pirko

Mon, Aug 26, 2013 at 10:32:38PM CEST, [email protected] wrote:

...snip...

Quoted 9 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+	rcu_read_lock();
+	netdev_for_each_upper_dev(bond->dev, upper, iter) {
+		if (ip == bond_confirm_addr(upper, 0, ip)) {
+			ret = true;
+			break;
+		}

You need the same recursion __vlan_find_dev_deep() is doing. If you do not do that, you will miss anything over the first upper level.

Good point, and it's true for other uses also - bond_arp_send_all(), for example, will also miss anything that's higher than the first upper level.

I can't think of a use case scenario when we would need only the first upper level - so maybe we should either make netdev_for_each_upper_dev() recursive by default (I don't know how it can be done easily, tbh, without modifying the existing code), or add something like:

net/core/dev.c +25 -0
index 566e99a..4a4468f 100644
@@ -4387,6 +4387,31 @@ static void __append_search_uppers(struct list_head *search_list,
 	}
 }
 
+struct net_device *netdev_upper_recursive_do_rcu(struct net_device *dev,
+						 struct net_device *orig_dev,
+						 bool (*f)(struct net_device *,
+							   struct net_device *))
+{
+	struct netdev_upper *upper;
+	struct net_device *ret = NULL;
+
+	list_for_each_entry_rcu(upper, &dev->upper_dev_list, list) {
+		if (f(orig_dev, upper->dev)) {
+			ret = upper->dev;
+			break;
+		}
+
+		if (!list_empty(&upper->dev->upper_dev_list)) {
+			ret = netdev_upper_recursive_do_rcu(upper->dev,
+							    orig_dev, f);
+			if (ret)
+				break;
+		}
+	}
+
+	return ret;
+}
+
 static bool __netdev_search_upper_dev(struct net_device *dev,
 				      struct net_device *upper_dev)
 {

How do you think?

#10 lore raw

Re: [PATCH net-next v1 5/9] bonding: convert bond_has_this_ip() to use upper devices

Quoted 57 lines · Tue, Aug 27, 2013 at 01:16:48PM CEST, [email protected] wrote:
Quoted 1 line · Jiri Pirko

Mon, Aug 26, 2013 at 10:32:38PM CEST, [email protected] wrote:

...snip...

Quoted 9 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+	rcu_read_lock();
+	netdev_for_each_upper_dev(bond->dev, upper, iter) {
+		if (ip == bond_confirm_addr(upper, 0, ip)) {
+			ret = true;
+			break;
+		}

You need the same recursion __vlan_find_dev_deep() is doing. If you do not do that, you will miss anything over the first upper level.

Good point, and it's true for other uses also - bond_arp_send_all(), for example, will also miss anything that's higher than the first upper level.

I can't think of a use case scenario when we would need only the first upper level - so maybe we should either make netdev_for_each_upper_dev() recursive by default (I don't know how it can be done easily, tbh, without modifying the existing code), or add something like:

net/core/dev.c +25 -0
index 566e99a..4a4468f 100644
@@ -4387,6 +4387,31 @@ static void __append_search_uppers(struct list_head *search_list,
 	}
 }
+struct net_device *netdev_upper_recursive_do_rcu(struct net_device *dev,
+						 struct net_device *orig_dev,
+						 bool (*f)(struct net_device *,
+							   struct net_device *))
+{
+	struct netdev_upper *upper;
+	struct net_device *ret = NULL;
+
+	list_for_each_entry_rcu(upper, &dev->upper_dev_list, list) {
+		if (f(orig_dev, upper->dev)) {
+			ret = upper->dev;
+			break;
+		}
+
+		if (!list_empty(&upper->dev->upper_dev_list)) {
+			ret = netdev_upper_recursive_do_rcu(upper->dev,
+							    orig_dev, f);
+			if (ret)
+				break;
+		}
+	}
+
+	return ret;
+}
+
 static bool __netdev_search_upper_dev(struct net_device *dev,
 				      struct net_device *upper_dev)
 {
 
Quoted 1 line

How do you think?

I do not like this. How about to put all levels to upper_dev list and mark those who are not direct (not level1) ? Then we can use single list for all purposes.

#11 lore raw

Re: [PATCH net-next v1 5/9] bonding: convert bond_has_this_ip() to use upper devices

Quoted 58 lines · Jiri Pirko
Quoted 57 lines · Tue, Aug 27, 2013 at 01:16:48PM CEST, [email protected] wrote:
Quoted 1 line · Jiri Pirko

Mon, Aug 26, 2013 at 10:32:38PM CEST, [email protected] wrote:

...snip...

Quoted 9 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+	rcu_read_lock();
+	netdev_for_each_upper_dev(bond->dev, upper, iter) {
+		if (ip == bond_confirm_addr(upper, 0, ip)) {
+			ret = true;
+			break;
+		}

You need the same recursion __vlan_find_dev_deep() is doing. If you do not do that, you will miss anything over the first upper level.

Good point, and it's true for other uses also - bond_arp_send_all(), for example, will also miss anything that's higher than the first upper level.

I can't think of a use case scenario when we would need only the first upper level - so maybe we should either make netdev_for_each_upper_dev() recursive by default (I don't know how it can be done easily, tbh, without modifying the existing code), or add something like:

net/core/dev.c +25 -0
index 566e99a..4a4468f 100644
@@ -4387,6 +4387,31 @@ static void __append_search_uppers(struct list_head *search_list,
 	}
 }
+struct net_device *netdev_upper_recursive_do_rcu(struct net_device *dev,
+						 struct net_device *orig_dev,
+						 bool (*f)(struct net_device *,
+							   struct net_device *))
+{
+	struct netdev_upper *upper;
+	struct net_device *ret = NULL;
+
+	list_for_each_entry_rcu(upper, &dev->upper_dev_list, list) {
+		if (f(orig_dev, upper->dev)) {
+			ret = upper->dev;
+			break;
+		}
+
+		if (!list_empty(&upper->dev->upper_dev_list)) {
+			ret = netdev_upper_recursive_do_rcu(upper->dev,
+							    orig_dev, f);
+			if (ret)
+				break;
+		}
+	}
+
+	return ret;
+}
+
 static bool __netdev_search_upper_dev(struct net_device *dev,
 				      struct net_device *upper_dev)
 {
 
Quoted 5 lines
Quoted 1 line

How do you think?

I do not like this. How about to put all levels to upper_dev list and mark those who are not direct (not level1) ? Then we can use single list for all purposes.

I don't see how it can be done on attach/removal of upper devices, cause we don't have a way to know the 'lower' devices, and will break scenarios like

bond -> bridge ->+ vlan

when vlan is added, we can't update bond's upper_dev_list.

And if we'll start doing it 'on the fly', while searching, by using search_list (or something new), we'll be racy and require locking, not just RCU.

Am I again missing something? :)

#12 lore raw

Re: [PATCH net-next v1 5/9] bonding: convert bond_has_this_ip() to use upper devices

In reply to Jiri Pirko
Quoted 58 lines · Jiri Pirko
Quoted 57 lines · Tue, Aug 27, 2013 at 01:16:48PM CEST, [email protected] wrote:
Quoted 1 line · Jiri Pirko

Mon, Aug 26, 2013 at 10:32:38PM CEST, [email protected] wrote:

...snip...

Quoted 9 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+	rcu_read_lock();
+	netdev_for_each_upper_dev(bond->dev, upper, iter) {
+		if (ip == bond_confirm_addr(upper, 0, ip)) {
+			ret = true;
+			break;
+		}

You need the same recursion __vlan_find_dev_deep() is doing. If you do not do that, you will miss anything over the first upper level.

Good point, and it's true for other uses also - bond_arp_send_all(), for example, will also miss anything that's higher than the first upper level.

I can't think of a use case scenario when we would need only the first upper level - so maybe we should either make netdev_for_each_upper_dev() recursive by default (I don't know how it can be done easily, tbh, without modifying the existing code), or add something like:

net/core/dev.c +25 -0
index 566e99a..4a4468f 100644
@@ -4387,6 +4387,31 @@ static void __append_search_uppers(struct list_head *search_list,
 	}
 }
+struct net_device *netdev_upper_recursive_do_rcu(struct net_device *dev,
+						 struct net_device *orig_dev,
+						 bool (*f)(struct net_device *,
+							   struct net_device *))
+{
+	struct netdev_upper *upper;
+	struct net_device *ret = NULL;
+
+	list_for_each_entry_rcu(upper, &dev->upper_dev_list, list) {
+		if (f(orig_dev, upper->dev)) {
+			ret = upper->dev;
+			break;
+		}
+
+		if (!list_empty(&upper->dev->upper_dev_list)) {
+			ret = netdev_upper_recursive_do_rcu(upper->dev,
+							    orig_dev, f);
+			if (ret)
+				break;
+		}
+	}
+
+	return ret;
+}
+
 static bool __netdev_search_upper_dev(struct net_device *dev,
 				      struct net_device *upper_dev)
 {
 
Quoted 5 lines
Quoted 1 line

How do you think?

I do not like this. How about to put all levels to upper_dev list and mark those who are not direct (not level1) ? Then we can use single list for all purposes.

I've looked at the code a bit more and I really don't see a way to do non-recursive, RCUed way to traverse the whole list of upper devices.

I see three ways to handle this situation:

1) The one that I've posted, recursive search and calling a provided function (the function should also get as a parameter a user-provided void *pointer). It's, indeed, a bit hacky, however will work perfectly.

2) Implementing the search (recursive) in bonding (or any further device) itself. Less intrusive, however it'll be code duplication actually for point 1).

3) Adding lower_dev_list, populating it accordingly, and also adding an int distance to the netdev_upper (or, with this approach, rather netdev_adjacent or something like that), which will help to implement your idea - a device will have lower/upper_dev_list populated with all lower/upper devices and their distance (i.e. distance == 1 means that it's first level of lower/upper device). With this approach, we might also afterwards get rid of slave lists from 'grouping' devices like bonding/team/bridge/etc. and, thus, the locking.

Now I'd rather go with 1), but if you don't like it - I can go with 2). And, if 3) sounds ok, I can implement it also and try to get rid of bonding slave list (hopefully).

Do you have any other ideas/thoughts?

#13 lore raw

Re: [PATCH net-next v1 5/9] bonding: convert bond_has_this_ip() to use upper devices

On Tue, Aug 27, 2013 at 08:10:01PM +0200, Veaceslav Falico wrote:
...snip...

Quoted 8 lines

3) Adding lower_dev_list, populating it accordingly, and also adding an int distance to the netdev_upper (or, with this approach, rather netdev_adjacent or something like that), which will help to implement your idea - a device will have lower/upper_dev_list populated with all lower/upper devices and their distance (i.e. distance == 1 means that it's first level of lower/upper device). With this approach, we might also afterwards get rid of slave lists from 'grouping' devices like bonding/team/bridge/etc. and, thus, the locking.

Just FYI, I've taken this approach in the next version, seems to (suddenly) work fine, FWIW...

I'll send the v2 in few minutes.

Thanks again!

#14 lore raw

Re: [PATCH net-next v1 5/9] bonding: convert bond_has_this_ip() to use upper devices

In reply to Veaceslav Falico
Quoted 92 lines · Veaceslav Falico
Quoted 62 lines · Jiri Pirko
Quoted 61 lines · Tue, Aug 27, 2013 at 01:16:48PM CEST, [email protected] wrote:
Quoted 1 line · Jiri Pirko

Mon, Aug 26, 2013 at 10:32:38PM CEST, [email protected] wrote:

...snip...

Quoted 9 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+    rcu_read_lock();
+    netdev_for_each_upper_dev(bond->dev, upper, iter) {
+        if (ip == bond_confirm_addr(upper, 0, ip)) {
+            ret = true;
+            break;
+        }

You need the same recursion __vlan_find_dev_deep() is doing. If you do not do that, you will miss anything over the first upper level.

Good point, and it's true for other uses also - bond_arp_send_all(), for example, will also miss anything that's higher than the first upper level.

I can't think of a use case scenario when we would need only the first upper level - so maybe we should either make netdev_for_each_upper_dev() recursive by default (I don't know how it can be done easily, tbh, without
modifying the existing code), or add something like:

net/core/dev.c +25 -0
index 566e99a..4a4468f 100644
@@ -4387,6 +4387,31 @@ static void __append_search_uppers(struct
 list_head *search_list,
    }
 }
+struct net_device *netdev_upper_recursive_do_rcu(struct net_device
 *dev,
+                         struct net_device *orig_dev,
+                         bool (*f)(struct net_device *,
+                               struct net_device *))
+{
+    struct netdev_upper *upper;
+    struct net_device *ret = NULL;
+
+    list_for_each_entry_rcu(upper, &dev->upper_dev_list, list) {
+        if (f(orig_dev, upper->dev)) {
+            ret = upper->dev;
+            break;
+        }
+
+        if (!list_empty(&upper->dev->upper_dev_list)) {
+            ret = netdev_upper_recursive_do_rcu(upper->dev,
+                                orig_dev, f);
+            if (ret)
+                break;
+        }
+    }
+
+    return ret;
+}
+
 static bool __netdev_search_upper_dev(struct net_device *dev,
                      struct net_device *upper_dev)

{

Quoted 5 lines
Quoted 1 line

How do you think?

I do not like this. How about to put all levels to upper_dev list and mark those who are not direct (not level1) ? Then we can use single list for all purposes.

I've looked at the code a bit more and I really don't see a way to do non-recursive, RCUed way to traverse the whole list of upper devices.

I see three ways to handle this situation:

1) The one that I've posted, recursive search and calling a provided function (the function should also get as a parameter a user-provided void *pointer). It's, indeed, a bit hacky, however will work perfectly.

2) Implementing the search (recursive) in bonding (or any further device) itself. Less intrusive, however it'll be code duplication actually for point 1).

3) Adding lower_dev_list, populating it accordingly, and also adding an int distance to the netdev_upper (or, with this approach, rather netdev_adjacent
or something like that), which will help to implement your idea - a device will have lower/upper_dev_list populated with all lower/upper devices and their distance (i.e. distance == 1 means that it's first level of lower/upper device). With this approach, we might also afterwards get rid of slave lists from 'grouping' devices like bonding/team/bridge/etc. and, thus, the locking.

Quoted 5 lines

Now I'd rather go with 1), but if you don't like it - I can go with 2). And, if 3) sounds ok, I can implement it also and try to get rid of bonding slave list (hopefully).

Do you have any other ideas/thoughts?

I've been playing with approach 2 for some work I am doing for macvtap-over-bond, but I like you idea for 3 better.

It would make things simpler in the long run.

-vlad

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#15 lore raw

Re: [PATCH net-next v1 5/9] bonding: convert bond_has_this_ip() to use upper devices

On Wed, Aug 28, 2013 at 10:56:32AM -0400, Vlad Yasevich wrote:
...snip...

Quoted 4 lines

I've been playing with approach 2 for some work I am doing for macvtap-over-bond, but I like you idea for 3 better.

It would make things simpler in the long run.

I've just sent the third version of the 3rd approach, which implements lower/upper device lists for every device that are guaranteed, under RCU, tu have all the upper/lower devices linked to the device. It also permits to distinguish the 'neighbour' devices (i.e. linked on the first level, i.e. direct-linked) from the 'distant' ones, which are not directly linked but rather inherited.

It also implements the first function (and the only one that I've needed to get rid of vlan lists in bonding) - netdev_for_each_upper_dev_rcu(), which can be used as a loop:

struct net_device *upper;
struct list_head *iter;

rcu_read_lock(); netdev_for_each_upper_dev_rcu(dev, upper, iter) {
... do whatever you want with the upper dev ...
}
rcu_read_unlock();

In case you'll need, you can easily implement the same way netdev_for_each_lower_dev_rcu().

Hope that helps.

Quoted 2 lines

-vlad