Skip to contentSkip to conversation

Allow to switch off UDP-based tunnel offloads per netdevice

PATCH Superseded Sabrina Dubroca 2 participants 9 messages Jun 30, 2017 – Jul 4, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Allow to switch off UDP-based tunnel offloads per netdevice

This patchset adds a new netdevice feature to toggle tunnel offloads via ethtool. This is useful if the offload is causing issues, for example if the hardware is buggy.

The feature is added to all devices providing the ->ndo_udp_tunnel_add op, and enabled by default to preserve current behavior.

When the administrator disables this feature on a device, all currently offloaded ports are cleared from the device. When the feature is turned on, the stack notifies the device about all current ports.

Sabrina Dubroca (6):
net: add new netdevice feature for tunnel offloading
net: check tunnel offload feature before calling tunnel ndo ndo
net: add infrastructure to un-offload UDP tunnel port
net: call udp_tunnel_get_rx_info when NETIF_F_TUNNEL_OFFLOAD is
toggled
geneve/vxlan: add support for NETDEV_UDP_TUNNEL_DROP_INFO geneve/vxlan: offload ports on register/unregister events

 drivers/net/geneve.c            | 24 ++++++++++++++++++------
 drivers/net/vxlan.c             | 31 ++++++++++++++++++++++---------
 include/linux/netdev_features.h |  2 ++
 include/linux/netdevice.h       |  1 +
 include/net/udp_tunnel.h        |  8 ++++++++
 net/core/dev.c                  | 28 +++++++++++++++++++++++++++-
 net/core/ethtool.c              |  1 +
 net/ipv4/udp_tunnel.c           | 25 ++++++++++++++++++++++++-
 8 files changed, 103 insertions(+), 17 deletions(-)
Signature · 1 line
2.13.2
#1 lore raw

PATCH 1/6 net: add new netdevice feature for tunnel offloading

This adds a new netdevice feature, so that tunnel offloading can be disabled by the administrator on some netdevices, using the "tunnel-offload" ethtool feature.

This feature is set for all devices that provide ndo_udp_tunnel_add.

---
 include/linux/netdev_features.h | 2 ++
 net/core/dev.c                  | 6 ++++++
 net/core/ethtool.c              | 1 +
 3 files changed, 9 insertions(+)
include/linux/netdev_features.h +2 -0
index 1d4737cffc71..40a098e40d5d 100644
@@ -76,6 +76,7 @@ enum {
 	NETIF_F_HW_TC_BIT,		/* Offload TC infrastructure */
 	NETIF_F_HW_ESP_BIT,		/* Hardware ESP transformation offload */
 	NETIF_F_HW_ESP_TX_CSUM_BIT,	/* ESP with TX checksum offload */
+	NETIF_F_TUNNEL_OFFLOAD_BIT,     /* Tunnel offloads */
 
 	/*
 	 * Add your fresh new feature above and remember to update
@@ -140,6 +141,7 @@ enum {
 #define NETIF_F_HW_TC		__NETIF_F(HW_TC)
 #define NETIF_F_HW_ESP		__NETIF_F(HW_ESP)
 #define NETIF_F_HW_ESP_TX_CSUM	__NETIF_F(HW_ESP_TX_CSUM)
+#define	NETIF_F_TUNNEL_OFFLOAD  __NETIF_F(TUNNEL_OFFLOAD)
 
 #define for_each_netdev_feature(mask_addr, bit)	\
 	for_each_set_bit(bit, (unsigned long *)mask_addr, NETDEV_FEATURE_COUNT)
net/core/dev.c +6 -0
index a91572aa73d5..d97f7b39df23 100644
@@ -7505,6 +7505,12 @@ int register_netdevice(struct net_device *dev)
 	 */
 	dev->hw_features |= NETIF_F_SOFT_FEATURES;
 	dev->features |= NETIF_F_SOFT_FEATURES;
+
+	if (dev->netdev_ops->ndo_udp_tunnel_add) {
+		dev->features |= NETIF_F_TUNNEL_OFFLOAD;
+		dev->hw_features |= NETIF_F_TUNNEL_OFFLOAD;
+	}
+
 	dev->wanted_features = dev->features & dev->hw_features;
 
 	if (!(dev->flags & IFF_LOOPBACK))
net/core/ethtool.c +1 -0
index 03111a2d6653..b693421d5d71 100644
@@ -106,6 +106,7 @@ static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN]
 	[NETIF_F_HW_TC_BIT] =		 "hw-tc-offload",
 	[NETIF_F_HW_ESP_BIT] =		 "esp-hw-offload",
 	[NETIF_F_HW_ESP_TX_CSUM_BIT] =	 "esp-tx-csum-hw-offload",
+	[NETIF_F_TUNNEL_OFFLOAD_BIT] =	 "tunnel-offload",
 };
 
 static const char
Signature · 1 line
2.13.2
#2 lore raw

Re: [PATCH net-next 1/6] net: add new netdevice feature for tunnel offloading

Quoted 5 lines · Sabrina Dubroca

This adds a new netdevice feature, so that tunnel offloading can be disabled by the administrator on some netdevices, using the "tunnel-offload" ethtool feature.

This feature is set for all devices that provide ndo_udp_tunnel_add.

This patchset looks great, Sabrina! A few comments below.

include/linux/netdev_features.h enum { · line 79

Quoted 7 lines
include/linux/netdev_features.h +1 -0
@@ -76,6 +76,7 @@ enum {
 	NETIF_F_HW_TC_BIT,		/* Offload TC infrastructure */
 	NETIF_F_HW_ESP_BIT,		/* Hardware ESP transformation offload */
 	NETIF_F_HW_ESP_TX_CSUM_BIT,	/* ESP with TX checksum offload */
+	NETIF_F_TUNNEL_OFFLOAD_BIT,     /* Tunnel offloads */

"Tunnel offload" is very broad. Could we be more specific, e.g. "RSS tunnel offload" or such? NETIF_F_HW_TUNNEL_RSS?

net/core/ethtool.c static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] · line 110

Quoted 8 lines
net/core/ethtool.c +1 -0
@@ -106,6 +106,7 @@ static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN]
 	[NETIF_F_HW_TC_BIT] =		 "hw-tc-offload",
 	[NETIF_F_HW_ESP_BIT] =		 "esp-hw-offload",
 	[NETIF_F_HW_ESP_TX_CSUM_BIT] =	 "esp-tx-csum-hw-offload",
+	[NETIF_F_TUNNEL_OFFLOAD_BIT] =	 "tunnel-offload",
 };

And here, too. "rss-tunnel-offload"?

Thanks!

Jiri

#3 lore raw

Re: [PATCH net-next 1/6] net: add new netdevice feature for tunnel offloading

Quoted 9 lines · Jiri Benc
Quoted 5 lines · Sabrina Dubroca

This adds a new netdevice feature, so that tunnel offloading can be disabled by the administrator on some netdevices, using the "tunnel-offload" ethtool feature.

This feature is set for all devices that provide ndo_udp_tunnel_add.

This patchset looks great, Sabrina! A few comments below.

Quoted 10 lines

include/linux/netdev_features.h enum { · line 79

Quoted 7 lines
include/linux/netdev_features.h +1 -0
@@ -76,6 +76,7 @@ enum {
 	NETIF_F_HW_TC_BIT,		/* Offload TC infrastructure */
 	NETIF_F_HW_ESP_BIT,		/* Hardware ESP transformation offload */
 	NETIF_F_HW_ESP_TX_CSUM_BIT,	/* ESP with TX checksum offload */
+	NETIF_F_TUNNEL_OFFLOAD_BIT,     /* Tunnel offloads */

"Tunnel offload" is very broad. Could we be more specific, e.g. "RSS tunnel offload" or such? NETIF_F_HW_TUNNEL_RSS?

Yeah, "tunnel offload" is too broad. But RSS isn't correct here, since that's not the only thing that devices do with that feature.

Maybe "udp tunnel rx port" instead? Although, as Hannes pointed out yesterday, we're not really sure that drivers/devices will only use it for RX purposes either.

Quoted 10 lines

net/core/ethtool.c static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] · line 110

Quoted 8 lines
net/core/ethtool.c +1 -0
@@ -106,6 +106,7 @@ static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN]
 	[NETIF_F_HW_TC_BIT] =		 "hw-tc-offload",
 	[NETIF_F_HW_ESP_BIT] =		 "esp-hw-offload",
 	[NETIF_F_HW_ESP_TX_CSUM_BIT] =	 "esp-tx-csum-hw-offload",
+	[NETIF_F_TUNNEL_OFFLOAD_BIT] =	 "tunnel-offload",
 };

And here, too. "rss-tunnel-offload"?

Yep, I'll update all that when we figure out a reasonable name.

Another thing I was thinking about would be to modify ethtool to show these UDP tunneling features as a hierarchy (like we already have for tx-checksumming). Both for this new feature and the existing tx-udp_tnl-*.

Thanks for the comments,

Signature · 1 line
Sabrina
#4 lore raw

PATCH 2/6 net: check tunnel offload feature before calling tunnel ndo ndo

In reply to Sabrina Dubroca

If NETIF_F_TUNNEL_OFFLOAD was disabled on a given netdevice, skip the tunnel offload ndo call during tunnel port creation and deletion.

---
 net/ipv4/udp_tunnel.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
net/ipv4/udp_tunnel.c +6 -1
index 58bd39fb14b4..fc8336fddadf 100644
@@ -82,7 +82,8 @@ void udp_tunnel_push_rx_port(struct net_device *dev, struct socket *sock,
 	struct sock *sk = sock->sk;
 	struct udp_tunnel_info ti;
 
-	if (!dev->netdev_ops->ndo_udp_tunnel_add)
+	if (!dev->netdev_ops->ndo_udp_tunnel_add ||
+	    !(dev->features & NETIF_F_TUNNEL_OFFLOAD))
 		return;
 
 	ti.type = type;
@@ -109,6 +110,8 @@ void udp_tunnel_notify_add_rx_port(struct socket *sock, unsigned short type)
 	for_each_netdev_rcu(net, dev) {
 		if (!dev->netdev_ops->ndo_udp_tunnel_add)
 			continue;
+		if (!(dev->features & NETIF_F_TUNNEL_OFFLOAD))
+			continue;
 		dev->netdev_ops->ndo_udp_tunnel_add(dev, &ti);
 	}
 	rcu_read_unlock();
@@ -131,6 +134,8 @@ void udp_tunnel_notify_del_rx_port(struct socket *sock, unsigned short type)
 	for_each_netdev_rcu(net, dev) {
 		if (!dev->netdev_ops->ndo_udp_tunnel_del)
 			continue;
+		if (!(dev->features & NETIF_F_TUNNEL_OFFLOAD))
+			continue;
 		dev->netdev_ops->ndo_udp_tunnel_del(dev, &ti);
 	}
 	rcu_read_unlock();
Signature · 1 line
2.13.2
#5 lore raw

PATCH 3/6 net: add infrastructure to un-offload UDP tunnel port

In reply to Sabrina Dubroca

This adds a new NETDEV_UDP_TUNNEL_DROP_INFO event, similar to NETDEV_UDP_TUNNEL_PUSH_INFO, to signal to un-offload ports.

This also adds udp_tunnel_drop_rx_port(), which calls ndo_udp_tunnel_del.

---
 include/linux/netdevice.h |  1 +
 include/net/udp_tunnel.h  |  8 ++++++++
 net/ipv4/udp_tunnel.c     | 18 ++++++++++++++++++
 3 files changed, 27 insertions(+)
include/linux/netdevice.h +1 -0
index 85f01d673340..75cd0c31357d 100644
@@ -2307,6 +2307,7 @@ struct netdev_lag_lower_state_info {
 #define NETDEV_PRECHANGEUPPER	0x001A
 #define NETDEV_CHANGELOWERSTATE	0x001B
 #define NETDEV_UDP_TUNNEL_PUSH_INFO	0x001C
+#define NETDEV_UDP_TUNNEL_DROP_INFO	0x001D
 #define NETDEV_CHANGE_TX_QUEUE_LEN	0x001E
 
 int register_netdevice_notifier(struct notifier_block *nb);
include/net/udp_tunnel.h +8 -0
index 02c5be037451..10cce0dd4450 100644
@@ -115,6 +115,8 @@ struct udp_tunnel_info {
 /* Notify network devices of offloadable types */
 void udp_tunnel_push_rx_port(struct net_device *dev, struct socket *sock,
 			     unsigned short type);
+void udp_tunnel_drop_rx_port(struct net_device *dev, struct socket *sock,
+			     unsigned short type);
 void udp_tunnel_notify_add_rx_port(struct socket *sock, unsigned short type);
 void udp_tunnel_notify_del_rx_port(struct socket *sock, unsigned short type);
 
@@ -124,6 +126,12 @@ static inline void udp_tunnel_get_rx_info(struct net_device *dev)
 	call_netdevice_notifiers(NETDEV_UDP_TUNNEL_PUSH_INFO, dev);
 }
 
+static inline void udp_tunnel_drop_rx_info(struct net_device *dev)
+{
+	ASSERT_RTNL();
+	call_netdevice_notifiers(NETDEV_UDP_TUNNEL_DROP_INFO, dev);
+}
+
 /* Transmit the skb using UDP encapsulation. */
 void udp_tunnel_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb,
 			 __be32 src, __be32 dst, __u8 tos, __u8 ttl,
net/ipv4/udp_tunnel.c +18 -0
index fc8336fddadf..c5fd4350251f 100644
@@ -94,6 +94,24 @@ void udp_tunnel_push_rx_port(struct net_device *dev, struct socket *sock,
 }
 EXPORT_SYMBOL_GPL(udp_tunnel_push_rx_port);
 
+void udp_tunnel_drop_rx_port(struct net_device *dev, struct socket *sock,
+			     unsigned short type)
+{
+	struct sock *sk = sock->sk;
+	struct udp_tunnel_info ti;
+
+	if (!dev->netdev_ops->ndo_udp_tunnel_del ||
+	    !(dev->features & NETIF_F_TUNNEL_OFFLOAD))
+		return;
+
+	ti.type = type;
+	ti.sa_family = sk->sk_family;
+	ti.port = inet_sk(sk)->inet_sport;
+
+	dev->netdev_ops->ndo_udp_tunnel_del(dev, &ti);
+}
+EXPORT_SYMBOL_GPL(udp_tunnel_drop_rx_port);
+
 /* Notify netdevs that UDP port started listening */
 void udp_tunnel_notify_add_rx_port(struct socket *sock, unsigned short type)
 {
Signature · 1 line
2.13.2
#6 lore raw

PATCH 4/6 net: call udp_tunnel_get_rx_info when NETIF_F_TUNNEL_OFFLOAD is toggled

In reply to Sabrina Dubroca

NETIF_F_TUNNEL_OFFLOAD is special, in that we need to do more than just flip the bit in dev->features. When disabling we must also clear currently offloaded ports from the device, and when enabling we must tell the device to offload the ports it can.

Because vxlan stores its sockets in a hashtable and they are inserted at the head of per-bucket lists, switching the feature off and then on can result in a different set of ports being offloaded (depending on the HW's limits).

---
 net/core/dev.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
net/core/dev.c +21 -1
index d97f7b39df23..ba805fba38dd 100644
@@ -144,6 +144,7 @@
 #include <linux/netfilter_ingress.h>
 #include <linux/crash_dump.h>
 #include <linux/sctp.h>
+#include <net/udp_tunnel.h>
 
 #include "net-sysfs.h"
 
@@ -7302,8 +7303,27 @@ int __netdev_update_features(struct net_device *dev)
 	netdev_for_each_lower_dev(dev, lower, iter)
 		netdev_sync_lower_features(dev, lower, features);
 
-	if (!err)
+	if (!err) {
+		netdev_features_t diff = features ^ dev->features;
+
+		if (diff & NETIF_F_TUNNEL_OFFLOAD) {
+			/* udp_tunnel_{get,drop}_rx_info both need
+			 * NETIF_F_TUNNEL_OFFLOAD enabled on the
+			 * device, or they won't do anything.
+			 * Thus we need to update dev->features
+			 * *before* calling udp_tunnel_get_rx_info,
+			 * but *after* calling udp_tunnel_drop_rx_info.
+			 */
+			if (features & NETIF_F_TUNNEL_OFFLOAD) {
+				dev->features = features;
+				udp_tunnel_get_rx_info(dev);
+			} else {
+				udp_tunnel_drop_rx_info(dev);
+			}
+		}
+
 		dev->features = features;
+	}
 
 	return err < 0 ? 0 : 1;
 }
Signature · 1 line
2.13.2
#7 lore raw

PATCH 5/6 geneve/vxlan: add support for NETDEV_UDP_TUNNEL_DROP_INFO

In reply to Sabrina Dubroca

And call udp_tunnel_drop_rx_port() to handle that event.

---
 drivers/net/geneve.c | 19 +++++++++++++------
 drivers/net/vxlan.c  | 25 +++++++++++++++++--------
 2 files changed, 30 insertions(+), 14 deletions(-)
drivers/net/geneve.c +13 -6
index eb77201cb718..ba89dc69cb07 100644
@@ -998,16 +998,22 @@ static struct device_type geneve_type = {
  * supply the listening GENEVE udp ports. Callers are expected
  * to implement the ndo_udp_tunnel_add.
  */
-static void geneve_push_rx_ports(struct net_device *dev)
+static void geneve_offload_rx_ports(struct net_device *dev, bool push)
 {
 	struct net *net = dev_net(dev);
 	struct geneve_net *gn = net_generic(net, geneve_net_id);
 	struct geneve_sock *gs;
 
 	rcu_read_lock();
-	list_for_each_entry_rcu(gs, &gn->sock_list, list)
-		udp_tunnel_push_rx_port(dev, gs->sock,
-					UDP_TUNNEL_TYPE_GENEVE);
+	list_for_each_entry_rcu(gs, &gn->sock_list, list) {
+		if (push) {
+			udp_tunnel_push_rx_port(dev, gs->sock,
+						UDP_TUNNEL_TYPE_GENEVE);
+		} else {
+			udp_tunnel_drop_rx_port(dev, gs->sock,
+						UDP_TUNNEL_TYPE_GENEVE);
+		}
+	}
 	rcu_read_unlock();
 }
 
@@ -1410,8 +1416,9 @@ static int geneve_netdevice_event(struct notifier_block *unused,
 {
 	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
 
-	if (event == NETDEV_UDP_TUNNEL_PUSH_INFO)
-		geneve_push_rx_ports(dev);
+	if (event == NETDEV_UDP_TUNNEL_PUSH_INFO ||
+	    event == NETDEV_UDP_TUNNEL_DROP_INFO)
+		geneve_offload_rx_ports(dev, event == NETDEV_UDP_TUNNEL_PUSH_INFO);
 
 	return NOTIFY_DONE;
 }
drivers/net/vxlan.c +17 -8
index fd0ff97e3d81..03baa87a70f7 100644
@@ -2603,7 +2603,7 @@ static struct device_type vxlan_type = {
  * supply the listening VXLAN udp ports. Callers are expected
  * to implement the ndo_udp_tunnel_add.
  */
-static void vxlan_push_rx_ports(struct net_device *dev)
+static void vxlan_offload_rx_ports(struct net_device *dev, bool push)
 {
 	struct vxlan_sock *vs;
 	struct net *net = dev_net(dev);
@@ -2612,11 +2612,19 @@ static void vxlan_push_rx_ports(struct net_device *dev)
 
 	spin_lock(&vn->sock_lock);
 	for (i = 0; i < PORT_HASH_SIZE; ++i) {
-		hlist_for_each_entry_rcu(vs, &vn->sock_list[i], hlist)
-			udp_tunnel_push_rx_port(dev, vs->sock,
-						(vs->flags & VXLAN_F_GPE) ?
-						UDP_TUNNEL_TYPE_VXLAN_GPE :
-						UDP_TUNNEL_TYPE_VXLAN);
+		hlist_for_each_entry_rcu(vs, &vn->sock_list[i], hlist) {
+			unsigned short type;
+
+			if (vs->flags & VXLAN_F_GPE)
+				type = UDP_TUNNEL_TYPE_VXLAN_GPE;
+			else
+				type = UDP_TUNNEL_TYPE_VXLAN;
+
+			if (push)
+				udp_tunnel_push_rx_port(dev, vs->sock, type);
+			else
+				udp_tunnel_drop_rx_port(dev, vs->sock, type);
+		}
 	}
 	spin_unlock(&vn->sock_lock);
 }
@@ -3619,8 +3627,9 @@ static int vxlan_netdevice_event(struct notifier_block *unused,
 
 	if (event == NETDEV_UNREGISTER)
 		vxlan_handle_lowerdev_unregister(vn, dev);
-	else if (event == NETDEV_UDP_TUNNEL_PUSH_INFO)
-		vxlan_push_rx_ports(dev);
+	else if (event == NETDEV_UDP_TUNNEL_PUSH_INFO ||
+		 event == NETDEV_UDP_TUNNEL_DROP_INFO)
+		vxlan_offload_rx_ports(dev, event == NETDEV_UDP_TUNNEL_PUSH_INFO);
 
 	return NOTIFY_DONE;
 }
Signature · 1 line
2.13.2
#8 lore raw

PATCH 6/6 geneve/vxlan: offload ports on register/unregister events

In reply to Sabrina Dubroca

This improves consistency of handling when moving a netdev to another netns. Most drivers currently do a full reset when the device goes up, so that will flush the offload state anyway.

---
 drivers/net/geneve.c |  7 ++++++-
 drivers/net/vxlan.c  | 10 +++++++---
 2 files changed, 13 insertions(+), 4 deletions(-)
drivers/net/geneve.c +6 -1
index ba89dc69cb07..258c07a94915 100644
@@ -1417,8 +1417,13 @@ static int geneve_netdevice_event(struct notifier_block *unused,
 	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
 
 	if (event == NETDEV_UDP_TUNNEL_PUSH_INFO ||
-	    event == NETDEV_UDP_TUNNEL_DROP_INFO)
+	    event == NETDEV_UDP_TUNNEL_DROP_INFO) {
 		geneve_offload_rx_ports(dev, event == NETDEV_UDP_TUNNEL_PUSH_INFO);
+	} else if (event == NETDEV_UNREGISTER) {
+		geneve_offload_rx_ports(dev, false);
+	} else if (event == NETDEV_REGISTER) {
+		geneve_offload_rx_ports(dev, true);
+	}
 
 	return NOTIFY_DONE;
 }
drivers/net/vxlan.c +7 -3
index 03baa87a70f7..805db76b6e7e 100644
@@ -3625,11 +3625,15 @@ static int vxlan_netdevice_event(struct notifier_block *unused,
 	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
 	struct vxlan_net *vn = net_generic(dev_net(dev), vxlan_net_id);
 
-	if (event == NETDEV_UNREGISTER)
+	if (event == NETDEV_UNREGISTER) {
+		vxlan_offload_rx_ports(dev, false);
 		vxlan_handle_lowerdev_unregister(vn, dev);
-	else if (event == NETDEV_UDP_TUNNEL_PUSH_INFO ||
-		 event == NETDEV_UDP_TUNNEL_DROP_INFO)
+	} else if (event == NETDEV_REGISTER) {
+		vxlan_offload_rx_ports(dev, true);
+	} else if (event == NETDEV_UDP_TUNNEL_PUSH_INFO ||
+		   event == NETDEV_UDP_TUNNEL_DROP_INFO) {
 		vxlan_offload_rx_ports(dev, event == NETDEV_UDP_TUNNEL_PUSH_INFO);
+	}
 
 	return NOTIFY_DONE;
 }
Signature · 1 line
2.13.2