Skip to contentSkip to conversation

macvtap, second try

RFC In review Arnd Bergmann 4 participants 15 messages Dec 3, 2009 – Dec 14, 2009

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover macvtap, second try

I did not get this ready for the merge window, but people asked what the status of this is so I'm posting it now to solicit feedback.

The first patch just adds some hooks into macvlan.c and is less invasive than the previous version. That part should be fine and I'd like this to get merged into macvlan for 2.6.33 if people agree that the approach is right.

The second patch adds the driver using it and is not ready for integration unfortunately, but maybe it could get into staging anyway. Please look at that patch carefully and provide feedback.

	Arnd <><

---

Arnd Bergmann (1):
macvlan: add tap device backend

Patrick Mullaney (1):
macvlan: Allow plugging in additional backends

 drivers/net/Kconfig        |   12 +
 drivers/net/Makefile       |    1 +
 drivers/net/macvlan.c      |  113 ++++-----
 drivers/net/macvtap.c      |  560 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/if_macvlan.h |   71 ++++++
 5 files changed, 693 insertions(+), 64 deletions(-)
 create mode 100644 drivers/net/macvtap.c
#1 lore raw

RFC 1/2 macvlan: Allow plugging in additional backends

This patch includes only the basic framework for overriding the receive path. With these hooks, we can add the macvtap driver and potentially other drivers that directly interface with a hypervisor.

Loosely based on a patch by Patrick Mullaney based on another patch by Arnd Bergmann.

Cc Patrick McHardy <[email protected]>
Cc Stephen Hemminger <[email protected]>
Cc David S. Miller" <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Herbert Xu <[email protected]>
Cc Patrick Mullaney <[email protected]>
---
 drivers/net/macvlan.c      |  113 +++++++++++++++++++-------------------------
 include/linux/if_macvlan.h |   71 +++++++++++++++++++++++++++
 2 files changed, 120 insertions(+), 64 deletions(-)
drivers/net/macvlan.c +49 -64
index e0436fd..4fb4370 100644
@@ -39,31 +39,6 @@ struct macvlan_port {
 	struct list_head	vlans;
 };
 
-/**
- *	struct macvlan_rx_stats - MACVLAN percpu rx stats
- *	@rx_packets: number of received packets
- *	@rx_bytes: number of received bytes
- *	@multicast: number of received multicast packets
- *	@rx_errors: number of errors
- */
-struct macvlan_rx_stats {
-	unsigned long rx_packets;
-	unsigned long rx_bytes;
-	unsigned long multicast;
-	unsigned long rx_errors;
-};
-
-struct macvlan_dev {
-	struct net_device	*dev;
-	struct list_head	list;
-	struct hlist_node	hlist;
-	struct macvlan_port	*port;
-	struct net_device	*lowerdev;
-	struct macvlan_rx_stats *rx_stats;
-	enum macvlan_mode	mode;
-};
-
-
 static struct macvlan_dev *macvlan_hash_lookup(const struct macvlan_port *port,
 					       const unsigned char *addr)
 {
@@ -118,31 +93,17 @@ static int macvlan_addr_busy(const struct macvlan_port *port,
 	return 0;
 }
 
-static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
-				    unsigned int len, bool success,
-				    bool multicast)
-{
-	struct macvlan_rx_stats *rx_stats;
-
-	rx_stats = per_cpu_ptr(vlan->rx_stats, smp_processor_id());
-	if (likely(success)) {
-		rx_stats->rx_packets++;;
-		rx_stats->rx_bytes += len;
-		if (multicast)
-			rx_stats->multicast++;
-	} else {
-		rx_stats->rx_errors++;
-	}
-}
 
-static int macvlan_broadcast_one(struct sk_buff *skb, struct net_device *dev,
+static int macvlan_broadcast_one(struct sk_buff *skb,
+				 const struct macvlan_dev *vlan,
 				 const struct ethhdr *eth, bool local)
 {
+	struct net_device *dev = vlan->dev;
 	if (!skb)
 		return NET_RX_DROP;
 
 	if (local)
-		return dev_forward_skb(dev, skb);
+		return vlan->forward(dev, skb);
 
 	skb->dev = dev;
 	if (!compare_ether_addr_64bits(eth->h_dest,
@@ -151,7 +112,7 @@ static int macvlan_broadcast_one(struct sk_buff *skb, struct net_device *dev,
 	else
 		skb->pkt_type = PACKET_MULTICAST;
 
-	return netif_receive_skb(skb);
+	return vlan->receive(skb);
 }
 
 static void macvlan_broadcast(struct sk_buff *skb,
@@ -175,7 +136,7 @@ static void macvlan_broadcast(struct sk_buff *skb,
 				continue;
 
 			nskb = skb_clone(skb, GFP_ATOMIC);
-			err = macvlan_broadcast_one(nskb, vlan->dev, eth,
+			err = macvlan_broadcast_one(nskb, vlan, eth,
 					 mode == MACVLAN_MODE_BRIDGE);
 			macvlan_count_rx(vlan, skb->len + ETH_HLEN,
 					 err == NET_RX_SUCCESS, 1);
@@ -238,7 +199,7 @@ static struct sk_buff *macvlan_handle_frame(struct sk_buff *skb)
 	skb->dev = dev;
 	skb->pkt_type = PACKET_HOST;
 
-	netif_receive_skb(skb);
+	vlan->receive(skb);
 	return NULL;
 }
 
@@ -260,7 +221,7 @@ static int macvlan_queue_xmit(struct sk_buff *skb, struct net_device *dev)
 		dest = macvlan_hash_lookup(port, eth->h_dest);
 		if (dest && dest->mode == MACVLAN_MODE_BRIDGE) {
 			unsigned int length = skb->len + ETH_HLEN;
-			int ret = dev_forward_skb(dest->dev, skb);
+			int ret = dest->forward(dest->dev, skb);
 			macvlan_count_rx(dest, length,
 					 ret == NET_RX_SUCCESS, 0);
 
@@ -273,8 +234,8 @@ xmit_world:
 	return dev_queue_xmit(skb);
 }
 
-static netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
-				      struct net_device *dev)
+netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
+			       struct net_device *dev)
 {
 	int i = skb_get_queue_mapping(skb);
 	struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
@@ -290,6 +251,7 @@ static netdev_tx_t macvlan_start_xmit(struct sk_buff *skb,
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(macvlan_start_xmit);
 
 static int macvlan_hard_header(struct sk_buff *skb, struct net_device *dev,
 			       unsigned short type, const void *daddr,
@@ -623,8 +585,11 @@ static int macvlan_get_tx_queues(struct net *net,
 	return 0;
 }
 
-static int macvlan_newlink(struct net *src_net, struct net_device *dev,
-			   struct nlattr *tb[], struct nlattr *data[])
+int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
+			   struct nlattr *tb[], struct nlattr *data[],
+			   int (*receive)(struct sk_buff *skb),
+			   int (*forward)(struct net_device *dev,
+					  struct sk_buff *skb))
 {
 	struct macvlan_dev *vlan = netdev_priv(dev);
 	struct macvlan_port *port;
@@ -664,6 +629,8 @@ static int macvlan_newlink(struct net *src_net, struct net_device *dev,
 	vlan->lowerdev = lowerdev;
 	vlan->dev      = dev;
 	vlan->port     = port;
+	vlan->receive  = netif_receive_skb;
+	vlan->forward  = dev_forward_skb;
 
 	vlan->mode     = MACVLAN_MODE_VEPA;
 	if (data && data[IFLA_MACVLAN_MODE])
@@ -677,8 +644,17 @@ static int macvlan_newlink(struct net *src_net, struct net_device *dev,
 	netif_stacked_transfer_operstate(lowerdev, dev);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(macvlan_common_newlink);
 
-static void macvlan_dellink(struct net_device *dev, struct list_head *head)
+static int macvlan_newlink(struct net *src_net, struct net_device *dev,
+			   struct nlattr *tb[], struct nlattr *data[])
+{
+	return macvlan_common_newlink(src_net, dev, tb, data,
+				      netif_receive_skb,
+				      dev_forward_skb);
+}
+
+void macvlan_dellink(struct net_device *dev, struct list_head *head)
 {
 	struct macvlan_dev *vlan = netdev_priv(dev);
 	struct macvlan_port *port = vlan->port;
@@ -689,6 +665,7 @@ static void macvlan_dellink(struct net_device *dev, struct list_head *head)
 	if (list_empty(&port->vlans))
 		macvlan_port_destroy(port->dev);
 }
+EXPORT_SYMBOL_GPL(macvlan_dellink);
 
 static int macvlan_changelink(struct net_device *dev,
 		struct nlattr *tb[], struct nlattr *data[])
@@ -720,19 +697,27 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
 	[IFLA_MACVLAN_MODE] = { .type = NLA_U32 },
 };
 
-static struct rtnl_link_ops macvlan_link_ops __read_mostly = {
+int macvlan_link_register(struct rtnl_link_ops *ops)
+{
+	/* common fields */
+	ops->priv_size		= sizeof(struct macvlan_dev);
+	ops->get_tx_queues	= macvlan_get_tx_queues;
+	ops->setup		= macvlan_setup;
+	ops->validate		= macvlan_validate;
+	ops->maxtype		= IFLA_MACVLAN_MAX;
+	ops->policy		= macvlan_policy;
+	ops->changelink		= macvlan_changelink;
+	ops->get_size		= macvlan_get_size;
+	ops->fill_info		= macvlan_fill_info;
+
+	return rtnl_link_register(ops);
+};
+EXPORT_SYMBOL_GPL(macvlan_link_register);
+
+static struct rtnl_link_ops macvlan_link_ops = {
 	.kind		= "macvlan",
-	.priv_size	= sizeof(struct macvlan_dev),
-	.get_tx_queues  = macvlan_get_tx_queues,
-	.setup		= macvlan_setup,
-	.validate	= macvlan_validate,
 	.newlink	= macvlan_newlink,
 	.dellink	= macvlan_dellink,
-	.maxtype	= IFLA_MACVLAN_MAX,
-	.policy		= macvlan_policy,
-	.changelink	= macvlan_changelink,
-	.get_size	= macvlan_get_size,
-	.fill_info	= macvlan_fill_info,
 };
 
 static int macvlan_device_event(struct notifier_block *unused,
@@ -761,7 +746,7 @@ static int macvlan_device_event(struct notifier_block *unused,
 		break;
 	case NETDEV_UNREGISTER:
 		list_for_each_entry_safe(vlan, next, &port->vlans, list)
-			macvlan_dellink(vlan->dev, NULL);
+			vlan->dev->rtnl_link_ops->dellink(vlan->dev, NULL);
 		break;
 	}
 	return NOTIFY_DONE;
@@ -778,7 +763,7 @@ static int __init macvlan_init_module(void)
 	register_netdevice_notifier(&macvlan_notifier_block);
 	macvlan_handle_frame_hook = macvlan_handle_frame;
 
-	err = rtnl_link_register(&macvlan_link_ops);
+	err = macvlan_link_register(&macvlan_link_ops);
 	if (err < 0)
 		goto err1;
 	return 0;
include/linux/if_macvlan.h +71 -0

77 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#2 lore raw

Re: [RFC 1/2] macvlan: Allow plugging in additional backends

Quoted 7 lines · Arnd Bergmann

This patch includes only the basic framework for overriding the receive path. With these hooks, we can add the macvtap driver and potentially other drivers that directly interface with a hypervisor.

Loosely based on a patch by Patrick Mullaney based on another patch by Arnd Bergmann.

This patch looks fine to me.

#3 lore raw

RFC 1/1 macvlan: add tap device backend

In reply to Arnd Bergmann

This is a second prototype of a new interface into the network stack, to eventually replace tun/tap and the bridge driver in certain virtual machine setups. The code has changed significantly, but the goals still remain.

Background
----------
The 'Edge Virtual Bridging' working group is discussing ways to overcome the limitation of virtual bridges in hypervisors. One important part of this is the Virtual Ethernet Port Aggregator (VEPA), as described in
http://www.ieee802.org/1/files/public/docs2009/new-evb-congdon-vepa-modular-0709-v01.pdf

In short, the idea of VEPA is that virtual machines do not communicate with each other through direct bridging in the hypervisor but only via an external managed switch that is already well integrated into the data center, including network filtering, accounting and monitoring. While we can do most of that efficiently in the Linux bridge code, doing it externally simplifies the overall setup.

The macvlan code itself now has a bridge-like mode that allows its slaves to communicate directly, without any of the overhead or the features of the bridge code.

Related work
------------
The Linux bridge code can now be configured to hairpin mode as the remote end for macvlan in VEPA mode, thanks to patches from Anna Fischer. The respective patches to implement VEPA itself in the bridge code did not get merged because macvlan can do this better.

Or Gerlitz posted a "raw" packet socket backend for qemu to deal with this, at http://marc.info/?l=qemu-devel&m=124653801212767 and at least three other people have done a similar functionality independently. For use with qemu, that raw socket on macvlan should have similar performance characteristics as macvtap, but would not allow managing priviledges or doing some of the planned features.

This driver
-----------
While the other approaches should work as well, doing it using a tap interface should give additional benefits:

* We can keep using the optimizations for jumbo frames that we have put into the tun/tap driver.

* No need for root permissions that packet sockets need, just use 'ip link add link type macvtap' to create a new device and give it the right permissions using udev (using one tap per macvlan netdev).

* support for multiqueue network adapters by opening the tap device multiple times, using one file descriptor per guest CPU/network queue/interrupt (if the adapter supports multiple queues on a single MAC address).

* support for zero-copy receive/transmit using async I/O on the tap device (if the adapter supports per MAC rx queues).

* The same framework in macvlan can be used to add a third backend into a future kernel based virtio-net implementation.

This version of the driver does not support any of those features, but they all appear possible to add ;).
The driver is currently called 'macvtap', which seems to have stuck, although I would prefer if someone came up with a clearer name for this thing.

The code is pretty much complete for integration into the staging tree, but it has seen zero testing since the last major rework that changed the code to be based around struct sock as Michael suggested. I'm pretty sure that it does not work as is, but I don't expect large changes to be necessary.

I'm posting this mainly to solicit feedback. Not sure how chances for integration into 2.6.33 are, given that the merge window is opening already.

Cc Patrick McHardy <[email protected]>
Cc Stephen Hemminger <[email protected]>
Cc David S. Miller" <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Herbert Xu <[email protected]>
Cc Or Gerlitz <[email protected]>
Cc "Fischer, Anna" <[email protected]>
Cc Anthony Liguori <[email protected]>
Cc Edge Virtual Bridging <[email protected]>
---
 drivers/net/Kconfig   |   12 +
 drivers/net/Makefile  |    1 +
 drivers/net/macvtap.c |  561 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 574 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/macvtap.c
drivers/net/Kconfig +12 -0
index 0bbd5ae..c072027 100644
@@ -90,6 +90,18 @@ config MACVLAN
 	  To compile this driver as a module, choose M here: the module
 	  will be called macvlan.
 
+config MACVTAP
+	tristate "MAC-VLAN based tap driver (EXPERIMENTAL)"
+	depends on MACVLAN
+	help
+	  This adds a specialized tap character device driver that is based
+	  on the MAC-VLAN network interface, called macvtap. A macvtap device
+	  can be added in the same way as a macvlan device, using 'type
+	  macvlan', and then be accessed through the tap user space interface.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called macvtap.
+
 config EQUALIZER
 	tristate "EQL (serial line load balancing) support"
 	---help---
drivers/net/Makefile +1 -0
index 246323d..ae553fb 100644
@@ -167,6 +167,7 @@ obj-$(CONFIG_XEN_NETDEV_FRONTEND) += xen-netfront.o
 obj-$(CONFIG_DUMMY) += dummy.o
 obj-$(CONFIG_IFB) += ifb.o
 obj-$(CONFIG_MACVLAN) += macvlan.o
+obj-$(CONFIG_MACVTAP) += macvtap.o
 obj-$(CONFIG_DE600) += de600.o
 obj-$(CONFIG_DE620) += de620.o
 obj-$(CONFIG_LANCE) += lance.o
drivers/net/macvtap.c new file +561 -0

561 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#4 lore raw

Re: [RFC] macvlan: add tap device backend

Quoted 4 lines · Arnd Bergmann

This is a second prototype of a new interface into the network stack, to eventually replace tun/tap and the bridge driver in certain virtual machine setups. The code has changed significantly, but the goals still remain.

The idea looks pretty sound to me.

Quoted 3 lines

I'm posting this mainly to solicit feedback. Not sure how chances for integration into 2.6.33 are, given that the merge window is opening already.

It's way too late for 2.6.33. But the earlier this becomes ready then the earlier it can go into linux-next.

Thanks,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#5 lore raw

Re: [RFC] macvlan: add tap device backend

Quoted 7 lines · Herbert Xu
Quoted 4 lines · Arnd Bergmann

This is a second prototype of a new interface into the network stack, to eventually replace tun/tap and the bridge driver in certain virtual machine setups. The code has changed significantly, but the goals still remain.

The idea looks pretty sound to me.

Thanks!

Quoted 6 lines
Quoted 3 lines

I'm posting this mainly to solicit feedback. Not sure how chances for integration into 2.6.33 are, given that the merge window is opening already.

It's way too late for 2.6.33. But the earlier this becomes ready then the earlier it can go into linux-next.

Right. Since the code is basically working (I have two known bugs I'm still working on) and people want to test it, what is the best path? I could
a) keep my git tree for myself,
b) have it added to linux-next,
c) prepare a combined patch for net-next.git, or
d) have it added to drivers/staging

Arnd

maintainer
#6 lore raw

Re: [RFC] macvlan: add tap device backend

From: Arnd Bergmann <[email protected]>
Date: Mon, 14 Dec 2009 13:00:36 +0100

Quoted 1 line

c) prepare a combined patch for net-next.git, or

This is probably fine.

I'll be taking patches into net-next-2.6 right after Linus releases 2.6.33-rc1.

maintainer
#7 lore raw

Re: [RFC] macvlan: add tap device backend

In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>
Date: Mon, 14 Dec 2009 13:00:36 +0100

Quoted 1 line

c) prepare a combined patch for net-next.git, or

This is probably fine.

I'll be taking patches into net-next-2.6 right after Linus releases 2.6.33-rc1.

#8 lore raw

Re: [RFC] macvlan: add tap device backend

In reply to Herbert Xu
Quoted 7 lines · Herbert Xu
Quoted 4 lines · Arnd Bergmann

This is a second prototype of a new interface into the network stack, to eventually replace tun/tap and the bridge driver in certain virtual machine setups. The code has changed significantly, but the goals still remain.

The idea looks pretty sound to me.

Thanks!

Quoted 6 lines
Quoted 3 lines

I'm posting this mainly to solicit feedback. Not sure how chances for integration into 2.6.33 are, given that the merge window is opening already.

It's way too late for 2.6.33. But the earlier this becomes ready then the earlier it can go into linux-next.

Right. Since the code is basically working (I have two known bugs I'm still working on) and people want to test it, what is the best path? I could
a) keep my git tree for myself,
b) have it added to linux-next,
c) prepare a combined patch for net-next.git, or
d) have it added to drivers/staging

Arnd

#9 lore raw

Re: [RFC] macvlan: add tap device backend

In reply to Arnd Bergmann
Quoted 4 lines · Arnd Bergmann

This is a second prototype of a new interface into the network stack, to eventually replace tun/tap and the bridge driver in certain virtual machine setups. The code has changed significantly, but the goals still remain.

The idea looks pretty sound to me.

Quoted 3 lines

I'm posting this mainly to solicit feedback. Not sure how chances for integration into 2.6.33 are, given that the merge window is opening already.

It's way too late for 2.6.33. But the earlier this becomes ready then the earlier it can go into linux-next.

Thanks,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#10 lore raw

Re: [RFC] macvlan: add tap device backend

In reply to Arnd Bergmann
Quoted 12 lines · Arnd Bergmann
drivers/net/macvtap.c new file +12 -0
+static int macvtap_newlink(struct net *src_net,
+			   struct net_device *dev,
+			   struct nlattr *tb[],
+			   struct nlattr *data[])
+{
+	struct device *classdev;
+	dev_t devt;
+	int err;
+
+	err = macvlan_common_newlink(src_net, dev, tb, data,
+				     macvtap_receive, macvtap_forward);
+	if (err)

drivers/net/macvtap.c line 217

Quoted 10 lines
drivers/net/macvtap.c new file +10 -0
+		goto out;
+
+	devt = MKDEV(MAJOR(macvtap_major), dev->ifindex);
+
+	classdev = device_create(macvtap_class, &dev->dev, devt,
+				 dev, "tap%d", dev->ifindex);
+	if (IS_ERR(classdev)) {
+		err = PTR_ERR(classdev);
+		macvtap_del_queues(dev);
+		macvlan_dellink(dev, NULL);

I think this may cause a double free since macvlan_dellink() will free the device and rtnl_newlink() will free it again on error.

Quoted 21 lines
drivers/net/macvtap.c new file +21 -0
+	}
+
+out:
+	return err;
+}
+
+static void macvtap_dellink(struct net_device *dev,
+			    struct list_head *head)
+{
+	device_destroy(macvtap_class,
+		       MKDEV(MAJOR(macvtap_major), dev->ifindex));
+
+	macvtap_del_queues(dev);
+	macvlan_dellink(dev, head);
+}
+
+static struct rtnl_link_ops macvtap_link_ops __read_mostly = {
+	.kind		= "macvtap",
+	.newlink	= macvtap_newlink,
+	.dellink	= macvtap_dellink,
+};
#11 lore raw

Re: [RFC] macvlan: add tap device backend

Quoted 9 lines · Patrick McHardy

drivers/net/macvtap.c line 217

Quoted 6 lines
drivers/net/macvtap.c new file +6 -0
+     classdev = device_create(macvtap_class, &dev->dev, devt,
+                              dev, "tap%d", dev->ifindex);
+     if (IS_ERR(classdev)) {
+             err = PTR_ERR(classdev);
+             macvtap_del_queues(dev);
+             macvlan_dellink(dev, NULL);

I think this may cause a double free since macvlan_dellink() will free the device and rtnl_newlink() will free it again on error.

Ah, right. I've changed this part a few times now, but I think introduced the same bug again in the current version. I'll send out what I have now if you want to take another look.

Arnd

#12 lore raw

Re: [RFC] macvlan: add tap device backend

In reply to Patrick McHardy
Quoted 9 lines · Patrick McHardy

drivers/net/macvtap.c line 217

Quoted 6 lines
drivers/net/macvtap.c new file +6 -0
+     classdev = device_create(macvtap_class, &dev->dev, devt,
+                              dev, "tap%d", dev->ifindex);
+     if (IS_ERR(classdev)) {
+             err = PTR_ERR(classdev);
+             macvtap_del_queues(dev);
+             macvlan_dellink(dev, NULL);

I think this may cause a double free since macvlan_dellink() will free the device and rtnl_newlink() will free it again on error.

Ah, right. I've changed this part a few times now, but I think introduced the same bug again in the current version. I'll send out what I have now if you want to take another look.

Arnd

#13 lore raw

Re: [RFC] macvlan: add tap device backend

In reply to Arnd Bergmann
Quoted 12 lines · Arnd Bergmann
drivers/net/macvtap.c new file +12 -0
+static int macvtap_newlink(struct net *src_net,
+			   struct net_device *dev,
+			   struct nlattr *tb[],
+			   struct nlattr *data[])
+{
+	struct device *classdev;
+	dev_t devt;
+	int err;
+
+	err = macvlan_common_newlink(src_net, dev, tb, data,
+				     macvtap_receive, macvtap_forward);
+	if (err)

drivers/net/macvtap.c line 217

Quoted 10 lines
drivers/net/macvtap.c new file +10 -0
+		goto out;
+
+	devt = MKDEV(MAJOR(macvtap_major), dev->ifindex);
+
+	classdev = device_create(macvtap_class, &dev->dev, devt,
+				 dev, "tap%d", dev->ifindex);
+	if (IS_ERR(classdev)) {
+		err = PTR_ERR(classdev);
+		macvtap_del_queues(dev);
+		macvlan_dellink(dev, NULL);

I think this may cause a double free since macvlan_dellink() will free the device and rtnl_newlink() will free it again on error.

Quoted 21 lines
drivers/net/macvtap.c new file +21 -0
+	}
+
+out:
+	return err;
+}
+
+static void macvtap_dellink(struct net_device *dev,
+			    struct list_head *head)
+{
+	device_destroy(macvtap_class,
+		       MKDEV(MAJOR(macvtap_major), dev->ifindex));
+
+	macvtap_del_queues(dev);
+	macvlan_dellink(dev, head);
+}
+
+static struct rtnl_link_ops macvtap_link_ops __read_mostly = {
+	.kind		= "macvtap",
+	.newlink	= macvtap_newlink,
+	.dellink	= macvtap_dellink,
+};
#14 lore raw

RFC 1/1 macvlan: add tap device backend

In reply to Arnd Bergmann

This is a second prototype of a new interface into the network stack, to eventually replace tun/tap and the bridge driver in certain virtual machine setups. The code has changed significantly, but the goals still remain.

Background
----------
The 'Edge Virtual Bridging' working group is discussing ways to overcome the limitation of virtual bridges in hypervisors. One important part of this is the Virtual Ethernet Port Aggregator (VEPA), as described in
http://www.ieee802.org/1/files/public/docs2009/new-evb-congdon-vepa-modular-0709-v01.pdf

In short, the idea of VEPA is that virtual machines do not communicate with each other through direct bridging in the hypervisor but only via an external managed switch that is already well integrated into the data center, including network filtering, accounting and monitoring. While we can do most of that efficiently in the Linux bridge code, doing it externally simplifies the overall setup.

The macvlan code itself now has a bridge-like mode that allows its slaves to communicate directly, without any of the overhead or the features of the bridge code.

Related work
------------
The Linux bridge code can now be configured to hairpin mode as the remote end for macvlan in VEPA mode, thanks to patches from Anna Fischer. The respective patches to implement VEPA itself in the bridge code did not get merged because macvlan can do this better.

Or Gerlitz posted a "raw" packet socket backend for qemu to deal with this, at http://marc.info/?l=qemu-devel&m=124653801212767 and at least three other people have done a similar functionality independently. For use with qemu, that raw socket on macvlan should have similar performance characteristics as macvtap, but would not allow managing priviledges or doing some of the planned features.

This driver
-----------
While the other approaches should work as well, doing it using a tap interface should give additional benefits:

* We can keep using the optimizations for jumbo frames that we have put into the tun/tap driver.

* No need for root permissions that packet sockets need, just use 'ip link add link type macvtap' to create a new device and give it the right permissions using udev (using one tap per macvlan netdev).

* support for multiqueue network adapters by opening the tap device multiple times, using one file descriptor per guest CPU/network queue/interrupt (if the adapter supports multiple queues on a single MAC address).

* support for zero-copy receive/transmit using async I/O on the tap device (if the adapter supports per MAC rx queues).

* The same framework in macvlan can be used to add a third backend into a future kernel based virtio-net implementation.

This version of the driver does not support any of those features, but they all appear possible to add ;).
The driver is currently called 'macvtap', which seems to have stuck, although I would prefer if someone came up with a clearer name for this thing.

The code is pretty much complete for integration into the staging tree, but it has seen zero testing since the last major rework that changed the code to be based around struct sock as Michael suggested. I'm pretty sure that it does not work as is, but I don't expect large changes to be necessary.

I'm posting this mainly to solicit feedback. Not sure how chances for integration into 2.6.33 are, given that the merge window is opening already.

Cc Patrick McHardy <[email protected]>
Cc Stephen Hemminger <[email protected]>
Cc David S. Miller" <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Herbert Xu <[email protected]>
Cc Or Gerlitz <[email protected]>
Cc "Fischer, Anna" <[email protected]>
Cc Anthony Liguori <[email protected]>
Cc Edge Virtual Bridging <[email protected]>
---
 drivers/net/Kconfig   |   12 +
 drivers/net/Makefile  |    1 +
 drivers/net/macvtap.c |  561 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 574 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/macvtap.c
drivers/net/Kconfig +12 -0
index 0bbd5ae..c072027 100644
@@ -90,6 +90,18 @@ config MACVLAN
 	  To compile this driver as a module, choose M here: the module
 	  will be called macvlan.
 
+config MACVTAP
+	tristate "MAC-VLAN based tap driver (EXPERIMENTAL)"
+	depends on MACVLAN
+	help
+	  This adds a specialized tap character device driver that is based
+	  on the MAC-VLAN network interface, called macvtap. A macvtap device
+	  can be added in the same way as a macvlan device, using 'type
+	  macvlan', and then be accessed through the tap user space interface.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called macvtap.
+
 config EQUALIZER
 	tristate "EQL (serial line load balancing) support"
 	---help---
drivers/net/Makefile +1 -0
index 246323d..ae553fb 100644
@@ -167,6 +167,7 @@ obj-$(CONFIG_XEN_NETDEV_FRONTEND) += xen-netfront.o
 obj-$(CONFIG_DUMMY) += dummy.o
 obj-$(CONFIG_IFB) += ifb.o
 obj-$(CONFIG_MACVLAN) += macvlan.o
+obj-$(CONFIG_MACVTAP) += macvtap.o
 obj-$(CONFIG_DE600) += de600.o
 obj-$(CONFIG_DE620) += de620.o
 obj-$(CONFIG_LANCE) += lance.o
drivers/net/macvtap.c new file +561 -0

561 lines not on this page · raw message

Signature · 1 line
1.6.3.3