Skip to contentSkip to conversation

net: introduce ethernet teaming device

PATCH Superseded Jiri Pirko 6 participants 9 messages Oct 24, 2011 – Oct 25, 2011

Subsystems (5)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

PATCH v4 1/1 net: introduce ethernet teaming device

This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.

Userspace library called libteam with couple of demo apps is available here:
https://github.com/jpirko/libteam
Note it's still in its dipers atm.

team<->libteam use generic netlink for communication. That and rtnl suppose to be the only way to configure team device, no sysfs etc.

Python binding basis for libteam was recently introduced (some need still need to be done on it though). Daemon providing arpmon/miimon active-backup functionality will be introduced shortly. All what's necessary is already implemented in kernel team driver.

v3->v4:
- remove redundant synchronize_rcu from __team_change_mode()
- revert "set and clear of mode_ops happens per pointer, not per byte"
- extend comment of function __team_change_mode()

v2->v3:
- team_change_mtu() user rcu version of list traversal to unwind
- set and clear of mode_ops happens per pointer, not per byte
- port hashlist changed to be embedded into team structure
- error branch in team_port_enter() does cleanup now
- fixed rtln->rtnl

v1->v2:
- modes are made as modules. Makes team more modular and extendable.
- several commenters' nitpicks found on v1 were fixed
- several other bugs were fixed.
- note I ignored Eric's comment about roundrobin port selector as Eric's way may be easily implemented as another mode (mode "random") in future.

---
 Documentation/networking/team.txt         |    2 +
 MAINTAINERS                               |    7 +
 drivers/net/Kconfig                       |    2 +
 drivers/net/Makefile                      |    1 +
 drivers/net/team/Kconfig                  |   38 +
 drivers/net/team/Makefile                 |    7 +
 drivers/net/team/team.c                   | 1573 +++++++++++++++++++++++++++++
 drivers/net/team/team_mode_activebackup.c |  152 +++
 drivers/net/team/team_mode_roundrobin.c   |  107 ++
 include/linux/Kbuild                      |    1 +
 include/linux/if.h                        |    1 +
 include/linux/if_team.h                   |  231 +++++
 include/linux/rculist.h                   |   14 +
 13 files changed, 2136 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/networking/team.txt
 create mode 100644 drivers/net/team/Kconfig
 create mode 100644 drivers/net/team/Makefile
 create mode 100644 drivers/net/team/team.c
 create mode 100644 drivers/net/team/team_mode_activebackup.c
 create mode 100644 drivers/net/team/team_mode_roundrobin.c
 create mode 100644 include/linux/if_team.h
Documentation/networking/team.txt new file +2 -0
new file mode 100644
index 0000000..5a01368
@@ -0,0 +1,2 @@
+Team devices are driven from userspace via libteam library which is here:
+	https://github.com/jpirko/libteam
MAINTAINERS +7 -0
index 5008b08..c33400d 100644
@@ -6372,6 +6372,13 @@ W:	http://tcp-lp-mod.sourceforge.net/
 S:	Maintained
 F:	net/ipv4/tcp_lp.c
 
+TEAM DRIVER
+M:	Jiri Pirko <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	drivers/net/team/
+F:	include/linux/if_team.h
+
 TEGRA SUPPORT
 M:	Colin Cross <[email protected]>
 M:	Erik Gilling <[email protected]>
drivers/net/Kconfig +2 -0
index 583f66c..b3020be 100644
@@ -125,6 +125,8 @@ config IFB
 	  'ifb1' etc.
 	  Look at the iproute2 documentation directory for usage etc
 
+source "drivers/net/team/Kconfig"
+
 config MACVLAN
 	tristate "MAC-VLAN support (EXPERIMENTAL)"
 	depends on EXPERIMENTAL
drivers/net/Makefile +1 -0
index fa877cd..4e4ebfe 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_NET) += Space.o loopback.o
 obj-$(CONFIG_NETCONSOLE) += netconsole.o
 obj-$(CONFIG_PHYLIB) += phy/
 obj-$(CONFIG_RIONET) += rionet.o
+obj-$(CONFIG_NET_TEAM) += team/
 obj-$(CONFIG_TUN) += tun.o
 obj-$(CONFIG_VETH) += veth.o
 obj-$(CONFIG_VIRTIO_NET) += virtio_net.o
drivers/net/team/Kconfig new file +38 -0
new file mode 100644
index 0000000..70a43a6
@@ -0,0 +1,38 @@
+menuconfig NET_TEAM
+	tristate "Ethernet team driver support (EXPERIMENTAL)"
+	depends on EXPERIMENTAL
+	---help---
+	  This allows one to create virtual interfaces that teams together
+	  multiple ethernet devices.
+
+	  Team devices can be added using the "ip" command from the
+	  iproute2 package:
+
+	  "ip link add link [ address MAC ] [ NAME ] type team"
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called team.
+
+if NET_TEAM
+
+config NET_TEAM_MODE_ROUNDROBIN
+	tristate "Round-robin mode support"
+	depends on NET_TEAM
+	---help---
+	  Basic mode where port used for transmitting packets is selected in
+	  round-robin fashion using packet counter.
+
+	  To compile this team mode as a module, choose M here: the module
+	  will be called team_mode_roundrobin.
+
+config NET_TEAM_MODE_ACTIVEBACKUP
+	tristate "Active-backup mode support"
+	depends on NET_TEAM
+	---help---
+	  Only one port is active at a time and the rest of ports are used
+	  for backup.
+
+	  To compile this team mode as a module, choose M here: the module
+	  will be called team_mode_activebackup.
+
+endif # NET_TEAM
drivers/net/team/Makefile new file +7 -0
new file mode 100644
index 0000000..85f2028
@@ -0,0 +1,7 @@
+#
+# Makefile for the network team driver
+#
+
+obj-$(CONFIG_NET_TEAM) += team.o
+obj-$(CONFIG_NET_TEAM_MODE_ROUNDROBIN) += team_mode_roundrobin.o
+obj-$(CONFIG_NET_TEAM_MODE_ACTIVEBACKUP) += team_mode_activebackup.o
drivers/net/team/team.c new file +1573 -0

1,573 lines not on this page · raw message

drivers/net/team/team_mode_activebackup.c new file +152 -0

152 lines not on this page · raw message

drivers/net/team/team_mode_roundrobin.c new file +107 -0

107 lines not on this page · raw message

include/linux/Kbuild +1 -0
index 619b565..0b091b3 100644
@@ -185,6 +185,7 @@ header-y += if_pppol2tp.h
 header-y += if_pppox.h
 header-y += if_slip.h
 header-y += if_strip.h
+header-y += if_team.h
 header-y += if_tr.h
 header-y += if_tun.h
 header-y += if_tunnel.h
include/linux/if.h +1 -0
index db20bd4..06b6ef6 100644
@@ -79,6 +79,7 @@
 #define IFF_TX_SKB_SHARING	0x10000	/* The interface supports sharing
 					 * skbs on transmit */
 #define IFF_UNICAST_FLT	0x20000		/* Supports unicast filtering	*/
+#define IFF_TEAM_PORT	0x40000		/* device used as team port */
 
 #define IF_GET_IFACE	0x0001		/* for querying only */
 #define IF_GET_PROTO	0x0002
include/linux/if_team.h new file +231 -0

231 lines not on this page · raw message

include/linux/rculist.h +14 -0
index d079290..7586b2c 100644
@@ -288,6 +288,20 @@ static inline void list_splice_init_rcu(struct list_head *list,
 	     pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
 
 /**
+ * list_for_each_entry_continue_reverse_rcu - iterate backwards from the given point
+ * @pos:	the type * to use as a loop cursor.
+ * @head:	the head for your list.
+ * @member:	the name of the list_struct within the struct.
+ *
+ * Start to iterate over list of given type backwards, continuing after
+ * the current position.
+ */
+#define list_for_each_entry_continue_reverse_rcu(pos, head, member)	\
+	for (pos = list_entry_rcu(pos->member.prev, typeof(*pos), member); \
+	     &pos->member != (head);	\
+	     pos = list_entry_rcu(pos->member.prev, typeof(*pos), member))
+
+/**
  * hlist_del_rcu - deletes entry from hash list without re-initialization
  * @n: the element to delete from the hash list.
  *
Signature · 1 line
1.7.6
#1 lore raw
Quoted 40 lines · Jiri Pirko

This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.

Userspace library called libteam with couple of demo apps is available here:
https://github.com/jpirko/libteam
Note it's still in its dipers atm.

team<->libteam use generic netlink for communication. That and rtnl suppose to be the only way to configure team device, no sysfs etc.

Python binding basis for libteam was recently introduced (some need still need to be done on it though). Daemon providing arpmon/miimon active-backup functionality will be introduced shortly. All what's necessary is already implemented in kernel team driver.

v3->v4:
- remove redundant synchronize_rcu from __team_change_mode()
- revert "set and clear of mode_ops happens per pointer, not per byte"
- extend comment of function __team_change_mode()

v2->v3:
- team_change_mtu() user rcu version of list traversal to unwind
- set and clear of mode_ops happens per pointer, not per byte
- port hashlist changed to be embedded into team structure
- error branch in team_port_enter() does cleanup now
- fixed rtln->rtnl

v1->v2:
- modes are made as modules. Makes team more modular and extendable.
- several commenters' nitpicks found on v1 were fixed
- several other bugs were fixed.
- note I ignored Eric's comment about roundrobin port selector as Eric's way may be easily implemented as another mode (mode "random") in future.

Quoted 14 lines
---
 Documentation/networking/team.txt         |    2 +
 MAINTAINERS                               |    7 +
 drivers/net/Kconfig                       |    2 +
 drivers/net/Makefile                      |    1 +
 drivers/net/team/Kconfig                  |   38 +
 drivers/net/team/Makefile                 |    7 +
 drivers/net/team/team.c                   | 1573 +++++++++++++++++++++++++++++
 drivers/net/team/team_mode_activebackup.c |  152 +++
 drivers/net/team/team_mode_roundrobin.c   |  107 ++
 include/linux/Kbuild                      |    1 +
 include/linux/if.h                        |    1 +
 include/linux/if_team.h                   |  231 +++++
 include/linux/rculist.h                   |   14 +

I think you're missing some CC's for the modifications to this file. I've taken the liberty of adding Dipankar and Paul to the discussion.

Quoted 9 lines
 13 files changed, 2136 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/networking/team.txt
 create mode 100644 drivers/net/team/Kconfig
 create mode 100644 drivers/net/team/Makefile
 create mode 100644 drivers/net/team/team.c
 create mode 100644 drivers/net/team/team_mode_activebackup.c
 create mode 100644 drivers/net/team/team_mode_roundrobin.c
 create mode 100644 include/linux/if_team.h

[...]

Quoted 6 lines
drivers/net/team/team.c new file +1 -0
new file mode 100644
index 0000000..acfef4c
+

[...]

Quoted 30 lines
drivers/net/team/team.c new file +30 -0
+static int team_change_mtu(struct net_device *dev, int new_mtu)
+{
+	struct team *team = netdev_priv(dev);
+	struct team_port *port;
+	int err;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(port, &team->port_list, list) {
+		err = dev_set_mtu(port->dev, new_mtu);
+		if (err) {
+			netdev_err(dev, "Device %s failed to change mtu",
+				   port->dev->name);
+			goto unwind;
+		}
+	}
+	rcu_read_unlock();
+
+	dev->mtu = new_mtu;
+
+	return 0;
+
+unwind:
+	list_for_each_entry_continue_reverse_rcu(port, &team->port_list, list)
+		dev_set_mtu(port->dev, dev->mtu);
+
+	rcu_read_unlock();
+	return err;
+}
+
+

[...]

Quoted 11 lines
include/linux/rculist.h +3 -0
index d079290..7586b2c 100644
@@ -288,6 +288,20 @@ static inline void list_splice_init_rcu(struct list_head *list,
 	     pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
 
 /**
+ * list_for_each_entry_continue_reverse_rcu - iterate backwards from the given point
+ * @pos:	the type * to use as a loop cursor.
+ * @head:	the head for your list.

include/linux/rculist.h static inline void list_splice_init_rcu(struct list_head *list, · line 303

Quoted 10 lines
include/linux/rculist.h +10 -0
+ * @member:	the name of the list_struct within the struct.
+ *
+ * Start to iterate over list of given type backwards, continuing after
+ * the current position.
+ */
+#define list_for_each_entry_continue_reverse_rcu(pos, head, member)	\
+	for (pos = list_entry_rcu(pos->member.prev, typeof(*pos), member); \
+	     &pos->member != (head);	\
+	     pos = list_entry_rcu(pos->member.prev, typeof(*pos), member))
+

rcu lists can be modified while they are traversed with *_rcu() primitives. This benefit comes with the constraint that they may only be traversed forwards. This is implicit in the choice of *_rcu() list-traversal primitives: they only go forwards.

You suggest to add a backwards rcu list-traversal primitive. But consider what happens in this sequence:

CPU0 CPU1
list_for_each_entry_continue_reverse_rcu(...)
pos = list_entry_rcu(pos->member.prev, typeof(*pos), member)

					list_del_rcu(&pos->member)
					{ (&pos->member)->prev = LIST_POISON2 }

pos = list_entry_rcu(pos->member.prev, typeof(*pos), member)
= container_of(LIST_POISON2, typeof(*pos), member)
do_something(*pos)
BAM!

Going back to the problem you're trying to solve in team_change_mtu(), I think you could either:
1) take team->lock instead of rcu_read_lock() throughout this particular function
2) save each deleted element in a separate list on the side in case it's necessary to roll back
3) remove the rcu double locking, rely on rtnl and add some ASSERT_RTNL() if desired. You've said that you don't want to rely on rtnl and you want to use separate locking but I fail to see what advantage that brings to balance out the extra complexity in code and execution? Please clarify this.

Thanks,
-Ben

Quoted 7 lines
include/linux/rculist.h +1 -0
+/**
  * hlist_del_rcu - deletes entry from hash list without re-initialization
  * @n: the element to delete from the hash list.
  *
Signature · 1 line
1.7.6
author
#2 lore raw
Quoted 144 lines · Mon, Oct 24, 2011 at 03:09:19PM CEST, [email protected] wrote:
Quoted 40 lines · Jiri Pirko

This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.

Userspace library called libteam with couple of demo apps is available here:
https://github.com/jpirko/libteam
Note it's still in its dipers atm.

team<->libteam use generic netlink for communication. That and rtnl suppose to be the only way to configure team device, no sysfs etc.

Python binding basis for libteam was recently introduced (some need still need to be done on it though). Daemon providing arpmon/miimon active-backup functionality will be introduced shortly. All what's necessary is already implemented in kernel team driver.

v3->v4:
- remove redundant synchronize_rcu from __team_change_mode()
- revert "set and clear of mode_ops happens per pointer, not per byte"
- extend comment of function __team_change_mode()

v2->v3:
- team_change_mtu() user rcu version of list traversal to unwind
- set and clear of mode_ops happens per pointer, not per byte
- port hashlist changed to be embedded into team structure
- error branch in team_port_enter() does cleanup now
- fixed rtln->rtnl

v1->v2:
- modes are made as modules. Makes team more modular and extendable.
- several commenters' nitpicks found on v1 were fixed
- several other bugs were fixed.
- note I ignored Eric's comment about roundrobin port selector as Eric's way may be easily implemented as another mode (mode "random") in future.

Quoted 14 lines
---
 Documentation/networking/team.txt         |    2 +
 MAINTAINERS                               |    7 +
 drivers/net/Kconfig                       |    2 +
 drivers/net/Makefile                      |    1 +
 drivers/net/team/Kconfig                  |   38 +
 drivers/net/team/Makefile                 |    7 +
 drivers/net/team/team.c                   | 1573 +++++++++++++++++++++++++++++
 drivers/net/team/team_mode_activebackup.c |  152 +++
 drivers/net/team/team_mode_roundrobin.c   |  107 ++
 include/linux/Kbuild                      |    1 +
 include/linux/if.h                        |    1 +
 include/linux/if_team.h                   |  231 +++++
 include/linux/rculist.h                   |   14 +

I think you're missing some CC's for the modifications to this file. I've taken the liberty of adding Dipankar and Paul to the discussion.

Quoted 9 lines
 13 files changed, 2136 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/networking/team.txt
 create mode 100644 drivers/net/team/Kconfig
 create mode 100644 drivers/net/team/Makefile
 create mode 100644 drivers/net/team/team.c
 create mode 100644 drivers/net/team/team_mode_activebackup.c
 create mode 100644 drivers/net/team/team_mode_roundrobin.c
 create mode 100644 include/linux/if_team.h

[...]

Quoted 6 lines
drivers/net/team/team.c new file +1 -0
new file mode 100644
index 0000000..acfef4c
+

[...]

Quoted 30 lines
drivers/net/team/team.c new file +30 -0
+static int team_change_mtu(struct net_device *dev, int new_mtu)
+{
+	struct team *team = netdev_priv(dev);
+	struct team_port *port;
+	int err;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(port, &team->port_list, list) {
+		err = dev_set_mtu(port->dev, new_mtu);
+		if (err) {
+			netdev_err(dev, "Device %s failed to change mtu",
+				   port->dev->name);
+			goto unwind;
+		}
+	}
+	rcu_read_unlock();
+
+	dev->mtu = new_mtu;
+
+	return 0;
+
+unwind:
+	list_for_each_entry_continue_reverse_rcu(port, &team->port_list, list)
+		dev_set_mtu(port->dev, dev->mtu);
+
+	rcu_read_unlock();
+	return err;
+}
+
+

[...]

Quoted 11 lines
include/linux/rculist.h +3 -0
index d079290..7586b2c 100644
@@ -288,6 +288,20 @@ static inline void list_splice_init_rcu(struct list_head *list,
 	     pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
 
 /**
+ * list_for_each_entry_continue_reverse_rcu - iterate backwards from the given point
+ * @pos:	the type * to use as a loop cursor.
+ * @head:	the head for your list.

include/linux/rculist.h static inline void list_splice_init_rcu(struct list_head *list, · line 303

Quoted 10 lines
include/linux/rculist.h +10 -0
+ * @member:	the name of the list_struct within the struct.
+ *
+ * Start to iterate over list of given type backwards, continuing after
+ * the current position.
+ */
+#define list_for_each_entry_continue_reverse_rcu(pos, head, member)	\
+	for (pos = list_entry_rcu(pos->member.prev, typeof(*pos), member); \
+	     &pos->member != (head);	\
+	     pos = list_entry_rcu(pos->member.prev, typeof(*pos), member))
+

rcu lists can be modified while they are traversed with *_rcu() primitives. This benefit comes with the constraint that they may only be traversed forwards. This is implicit in the choice of *_rcu() list-traversal primitives: they only go forwards.

You suggest to add a backwards rcu list-traversal primitive. But consider what happens in this sequence:

CPU0 CPU1
list_for_each_entry_continue_reverse_rcu(...)
pos = list_entry_rcu(pos->member.prev, typeof(*pos), member)

Quoted 6 lines
					list_del_rcu(&pos->member)
					{ (&pos->member)->prev = LIST_POISON2 }

pos = list_entry_rcu(pos->member.prev, typeof(*pos), member)
= container_of(LIST_POISON2, typeof(*pos), member)
do_something(*pos)
BAM!

Doh, you are right. :(

Quoted 7 lines

Going back to the problem you're trying to solve in team_change_mtu(), I think you could either:
1) take team->lock instead of rcu_read_lock() throughout this particular function
2) save each deleted element in a separate list on the side in case it's necessary to roll back

I would go with this one.

Quoted 5 lines

3) remove the rcu double locking, rely on rtnl and add some ASSERT_RTNL() if desired. You've said that you don't want to rely on rtnl and you want to use separate locking but I fail to see what advantage that brings to balance out the extra complexity in code and execution? Please clarify this.

I do not want to use rtnl. For example in gennetlink code rtnl is not held so I need to depend on own lock.

Quoted 11 lines

Thanks,
-Ben

Quoted 7 lines
include/linux/rculist.h +1 -0
+/**
  * hlist_del_rcu - deletes entry from hash list without re-initialization
  * @n: the element to delete from the hash list.
  *
Signature · 1 line
1.7.6
#3 lore raw
In reply to Benjamin Poirier
Quoted 56 lines · Benjamin Poirier
Quoted 40 lines · Jiri Pirko

This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.

Userspace library called libteam with couple of demo apps is available here:
https://github.com/jpirko/libteam
Note it's still in its dipers atm.

team<->libteam use generic netlink for communication. That and rtnl suppose to be the only way to configure team device, no sysfs etc.

Python binding basis for libteam was recently introduced (some need still need to be done on it though). Daemon providing arpmon/miimon active-backup functionality will be introduced shortly. All what's necessary is already implemented in kernel team driver.

v3->v4:
- remove redundant synchronize_rcu from __team_change_mode()
- revert "set and clear of mode_ops happens per pointer, not per byte"
- extend comment of function __team_change_mode()

v2->v3:
- team_change_mtu() user rcu version of list traversal to unwind
- set and clear of mode_ops happens per pointer, not per byte
- port hashlist changed to be embedded into team structure
- error branch in team_port_enter() does cleanup now
- fixed rtln->rtnl

v1->v2:
- modes are made as modules. Makes team more modular and extendable.
- several commenters' nitpicks found on v1 were fixed
- several other bugs were fixed.
- note I ignored Eric's comment about roundrobin port selector as Eric's way may be easily implemented as another mode (mode "random") in future.

Quoted 14 lines
---
 Documentation/networking/team.txt         |    2 +
 MAINTAINERS                               |    7 +
 drivers/net/Kconfig                       |    2 +
 drivers/net/Makefile                      |    1 +
 drivers/net/team/Kconfig                  |   38 +
 drivers/net/team/Makefile                 |    7 +
 drivers/net/team/team.c                   | 1573 +++++++++++++++++++++++++++++
 drivers/net/team/team_mode_activebackup.c |  152 +++
 drivers/net/team/team_mode_roundrobin.c   |  107 ++
 include/linux/Kbuild                      |    1 +
 include/linux/if.h                        |    1 +
 include/linux/if_team.h                   |  231 +++++
 include/linux/rculist.h                   |   14 +
Quoted 2 lines

I think you're missing some CC's for the modifications to this file. I've taken the liberty of adding Dipankar and Paul to the discussion.

Thank you, and please see below.

Quoted 92 lines
Quoted 9 lines
 13 files changed, 2136 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/networking/team.txt
 create mode 100644 drivers/net/team/Kconfig
 create mode 100644 drivers/net/team/Makefile
 create mode 100644 drivers/net/team/team.c
 create mode 100644 drivers/net/team/team_mode_activebackup.c
 create mode 100644 drivers/net/team/team_mode_roundrobin.c
 create mode 100644 include/linux/if_team.h

[...]

Quoted 6 lines
drivers/net/team/team.c new file +1 -0
new file mode 100644
index 0000000..acfef4c
+

[...]

Quoted 30 lines
drivers/net/team/team.c new file +30 -0
+static int team_change_mtu(struct net_device *dev, int new_mtu)
+{
+	struct team *team = netdev_priv(dev);
+	struct team_port *port;
+	int err;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(port, &team->port_list, list) {
+		err = dev_set_mtu(port->dev, new_mtu);
+		if (err) {
+			netdev_err(dev, "Device %s failed to change mtu",
+				   port->dev->name);
+			goto unwind;
+		}
+	}
+	rcu_read_unlock();
+
+	dev->mtu = new_mtu;
+
+	return 0;
+
+unwind:
+	list_for_each_entry_continue_reverse_rcu(port, &team->port_list, list)
+		dev_set_mtu(port->dev, dev->mtu);
+
+	rcu_read_unlock();
+	return err;
+}
+
+

[...]

Quoted 11 lines
include/linux/rculist.h +3 -0
index d079290..7586b2c 100644
@@ -288,6 +288,20 @@ static inline void list_splice_init_rcu(struct list_head *list,
 	     pos = list_entry_rcu(pos->member.next, typeof(*pos), member))
 
 /**
+ * list_for_each_entry_continue_reverse_rcu - iterate backwards from the given point
+ * @pos:	the type * to use as a loop cursor.
+ * @head:	the head for your list.

include/linux/rculist.h static inline void list_splice_init_rcu(struct list_head *list, · line 303

Quoted 10 lines
include/linux/rculist.h +10 -0
+ * @member:	the name of the list_struct within the struct.
+ *
+ * Start to iterate over list of given type backwards, continuing after
+ * the current position.
+ */
+#define list_for_each_entry_continue_reverse_rcu(pos, head, member)	\
+	for (pos = list_entry_rcu(pos->member.prev, typeof(*pos), member); \
+	     &pos->member != (head);	\
+	     pos = list_entry_rcu(pos->member.prev, typeof(*pos), member))
+

rcu lists can be modified while they are traversed with *_rcu() primitives. This benefit comes with the constraint that they may only be traversed forwards. This is implicit in the choice of *_rcu() list-traversal primitives: they only go forwards.

You suggest to add a backwards rcu list-traversal primitive. But consider what happens in this sequence:

CPU0 CPU1
list_for_each_entry_continue_reverse_rcu(...)
pos = list_entry_rcu(pos->member.prev, typeof(*pos), member)

					list_del_rcu(&pos->member)
					{ (&pos->member)->prev = LIST_POISON2 }

pos = list_entry_rcu(pos->member.prev, typeof(*pos), member)
= container_of(LIST_POISON2, typeof(*pos), member)
do_something(*pos)
BAM!

Quoted 11 lines

Going back to the problem you're trying to solve in team_change_mtu(), I think you could either:
1) take team->lock instead of rcu_read_lock() throughout this particular function
2) save each deleted element in a separate list on the side in case it's necessary to roll back
3) remove the rcu double locking, rely on rtnl and add some ASSERT_RTNL() if desired. You've said that you don't want to rely on rtnl and you want to use separate locking but I fail to see what advantage that brings to balance out the extra complexity in code and execution? Please clarify this.

Indeed -- the list_for_each_entry_continue_reverse_rcu() implementation above would only work if elements were never deleted from the list. But people would miss that fact, resulting in list-poison oopses. Furthermore, even if you avoid the poisoning, there is no guarantee that you will see the same objects in reverse that you saw going forward because some might have been added or deleted in the meantime.

So please take some other approach. For example, if the list has a fixed upper bound, perhaps just keeping track of what elements you visited would be workable.

Thanx, Paul

Quoted 11 lines

Thanks,
-Ben

Quoted 7 lines
include/linux/rculist.h +1 -0
+/**
  * hlist_del_rcu - deletes entry from hash list without re-initialization
  * @n: the element to delete from the hash list.
  *
Signature · 1 line
1.7.6
#4 lore raw
In reply to Jiri Pirko

2011/10/24 Jiri Pirko <[email protected]>:

Quoted 3 lines

This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.

[...]

Quoted 3 lines

 drivers/net/team/team.c                   | 1573 +++++++++++++++++++++++++++++ drivers/net/team/team_mode_activebackup.c |  152 +++ drivers/net/team/team_mode_roundrobin.c   |  107 ++

I think this mode-modularity is overkill. One mode will compile to at most a few hundred bytes of code+data, but will use at least 10 times that to get loaded and tracked properly. How often/how many more modes you anticipate to be introduced? You could just keep the modular design but drop the kernel module separation and maybe have modes conditionally compiled (for those from the embedded world squeezing every byte).

Best Regards,
Michał Mirosław

author
#5 lore raw
Quoted 9 lines · Mon, Oct 24, 2011 at 07:22:36PM CEST, [email protected] wrote:

2011/10/24 Jiri Pirko <[email protected]>:

Quoted 3 lines

This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.

[...]

Quoted 3 lines

 drivers/net/team/team.c                   | 1573 +++++++++++++++++++++++++++++ drivers/net/team/team_mode_activebackup.c |  152 +++ drivers/net/team/team_mode_roundrobin.c   |  107 ++

Quoted 7 lines

I think this mode-modularity is overkill. One mode will compile to at most a few hundred bytes of code+data, but will use at least 10 times that to get loaded and tracked properly. How often/how many more modes you anticipate to be introduced? You could just keep the modular design but drop the kernel module separation and maybe have modes conditionally compiled (for those from the embedded world squeezing every byte).

~3-4 modes are coming in at least. I presume it would be possible to squeeze "bacic modes" like roundrobin and activebackup directly into team.c (or into team_basic_modes.c compiled in team.ko). But I would leave that to future follow up patch.

Quoted 3 lines

Best Regards,
Michał Mirosław

#6 lore raw
In reply to Michał Mirosław
Quoted 10 lines · On Mon, 24 Oct 2011 19:22:36 +0200 Michał Mirosław <[email protected]> wrote:

2011/10/24 Jiri Pirko <[email protected]>:

Quoted 3 lines

This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.

[...]

Quoted 4 lines

 drivers/net/team/team.c                   | 1573
+++++++++++++++++++++++++++++
drivers/net/team/team_mode_activebackup.c |  152 +++ drivers/net/team/team_mode_roundrobin.c   |  107 ++

Quoted 8 lines

I think this mode-modularity is overkill. One mode will compile to at most a few hundred bytes of code+data, but will use at least 10 times that to get loaded and tracked properly. How often/how many more modes you anticipate to be introduced? You could just keep the modular design but drop the kernel module separation and maybe have modes conditionally compiled (for those from the embedded world squeezing every byte).

Please keep the modes separated. Security and embedded folks will thank you. If you are concerned with the overhead which still should be small and doesn't impact performance, you can compile as built-in. The good thing is that you can choose the best option for you while doing the opposite doesn't offer that.

Also, if in the future we need to add module parameters, the namespace is clean.

I would ask to keep it as the work is done already.

fbl

#7 lore raw
In reply to Jiri Pirko
Quoted 32 lines · Jiri Pirko

This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.

Userspace library called libteam with couple of demo apps is available here:
https://github.com/jpirko/libteam
Note it's still in its dipers atm.

team<->libteam use generic netlink for communication. That and rtnl suppose to be the only way to configure team device, no sysfs etc.

Python binding basis for libteam was recently introduced (some need still need to be done on it though). Daemon providing arpmon/miimon active-backup functionality will be introduced shortly. All what's necessary is already implemented in kernel team driver.

v3->v4:
- remove redundant synchronize_rcu from __team_change_mode()
- revert "set and clear of mode_ops happens per pointer, not per byte"
- extend comment of function __team_change_mode()

v2->v3:
- team_change_mtu() user rcu version of list traversal to unwind
- set and clear of mode_ops happens per pointer, not per byte
- port hashlist changed to be embedded into team structure
- error branch in team_port_enter() does cleanup now
- fixed rtln->rtnl

Quoted 8 lines

v1->v2:
- modes are made as modules. Makes team more modular and extendable.
- several commenters' nitpicks found on v1 were fixed
- several other bugs were fixed.
- note I ignored Eric's comment about roundrobin port selector as Eric's way may be easily implemented as another mode (mode "random") in future.

Jiri,

I've been following this work closely since your first post and now to wonder if you could create a 'team' tree somewhere. It would be nice if there was a repo that we could clone for testing and a base for others to help with the development and provide patches.

It also might avoid so much of this back and forth, so that you are not on v37 by the time the code meets everyones needs. :-)

Once the code goes mainline and Dave pulls your tree, you could then remove it.

-andy

author
#8 lore raw
Quoted 49 lines · Tue, Oct 25, 2011 at 02:02:33AM CEST, [email protected] wrote:
Quoted 32 lines · Jiri Pirko

This patch introduces new network device called team. It supposes to be very fast, simple, userspace-driven alternative to existing bonding driver.

Userspace library called libteam with couple of demo apps is available here:
https://github.com/jpirko/libteam
Note it's still in its dipers atm.

team<->libteam use generic netlink for communication. That and rtnl suppose to be the only way to configure team device, no sysfs etc.

Python binding basis for libteam was recently introduced (some need still need to be done on it though). Daemon providing arpmon/miimon active-backup functionality will be introduced shortly. All what's necessary is already implemented in kernel team driver.

v3->v4:
- remove redundant synchronize_rcu from __team_change_mode()
- revert "set and clear of mode_ops happens per pointer, not per byte"
- extend comment of function __team_change_mode()

v2->v3:
- team_change_mtu() user rcu version of list traversal to unwind
- set and clear of mode_ops happens per pointer, not per byte
- port hashlist changed to be embedded into team structure
- error branch in team_port_enter() does cleanup now
- fixed rtln->rtnl

Quoted 8 lines

v1->v2:
- modes are made as modules. Makes team more modular and extendable.
- several commenters' nitpicks found on v1 were fixed
- several other bugs were fixed.
- note I ignored Eric's comment about roundrobin port selector as Eric's way may be easily implemented as another mode (mode "random") in future.

Jiri,

I've been following this work closely since your first post and now to wonder if you could create a 'team' tree somewhere. It would be nice if there was a repo that we could clone for testing and a base for others to help with the development and provide patches.

Quoted 5 lines

It also might avoid so much of this back and forth, so that you are not on v37 by the time the code meets everyones needs. :-)

Once the code goes mainline and Dave pulls your tree, you could then remove it.

I believe v5 will be the one :)

Jirka

Quoted 3 lines

-andy