Skip to contentSkip to conversation

udp_tunnel: convert mlx5 to the new udp_tunnel infrastructure

RFC New Jakub Kicinski 1 participant 5 messages Jul 22, 2020

Subsystems (8)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

cover udp_tunnel: convert mlx5 to the new udp_tunnel infrastructure

This set converts the last driver not using the new infrastructure - mlx5.

We need a small amount of special handling as mlx5 expects IANA VXLAN port to always be programmed into the device. ethtool will show such ports in a separate, type-less, fake table, at the end:

Tunnel information for eth0:
UDP port table 0:

    Size: 7
    Types: vxlan
    No entries
  UDP port table 1: 
    Size: 1
    Types: none (static entries)
    Entries (1):
        port 4789, vxlan

Posting as an RFC because the netdevsim patches will conflict with the Intel series but otherwise the work should be independent. Reviews and testing would be much appreciated.

Jakub Kicinski (4):
udp_tunnel: add the ability to hard-code IANA VXLAN
mlx5: convert to new udp_tunnel infrastructure
netdevsim: support the static IANA VXLAN port flag
selftests: net: add a test for static UDP tunnel ports

 Documentation/networking/ethtool-netlink.rst  |  3 +
 drivers/net/ethernet/mellanox/mlx5/core/en.h  |  2 -
 .../net/ethernet/mellanox/mlx5/core/en_main.c | 88 ++-----------------
 .../net/ethernet/mellanox/mlx5/core/en_rep.c  |  2 -
 .../ethernet/mellanox/mlx5/core/lib/vxlan.c   | 87 +++++++++---------
 .../ethernet/mellanox/mlx5/core/lib/vxlan.h   |  6 +-
 drivers/net/netdevsim/netdevsim.h             |  1 +
 drivers/net/netdevsim/udp_tunnels.c           |  4 +
 include/net/udp_tunnel.h                      |  5 ++
 net/ethtool/tunnels.c                         | 70 +++++++++++++--
 net/ipv4/udp_tunnel_nic.c                     |  7 ++
 .../drivers/net/netdevsim/udp_tunnel_nic.sh   | 58 ++++++++++++
 12 files changed, 190 insertions(+), 143 deletions(-)
Signature · 1 line
2.26.2
author maintainer
#3 lore raw

RFC 3/4 netdevsim: support the static IANA VXLAN port flag

Allow setting UDP_TUNNEL_NIC_INFO_STATIC_IANA_VXLAN.

---
 drivers/net/netdevsim/netdevsim.h   | 1 +
 drivers/net/netdevsim/udp_tunnels.c | 4 ++++
 2 files changed, 5 insertions(+)
drivers/net/netdevsim/netdevsim.h +1 -0
index 4335ab4e5ce0..8a8ba687cc59 100644
@@ -205,6 +205,7 @@ struct nsim_dev {
 		bool open_only;
 		bool ipv4_only;
 		bool shared;
+		bool static_iana_vxlan;
 		u32 sleep;
 	} udp_ports;
 };
drivers/net/netdevsim/udp_tunnels.c +4 -0
index 6b98e6d1188f..6ab023acefd6 100644
@@ -186,6 +186,8 @@ int nsim_udp_tunnels_info_create(struct nsim_dev *nsim_dev,
 		info->flags |= UDP_TUNNEL_NIC_INFO_IPV4_ONLY;
 	if (nsim_dev->udp_ports.shared)
 		info->shared = &nsim_dev->udp_ports.utn_shared;
+	if (nsim_dev->udp_ports.static_iana_vxlan)
+		info->flags |= UDP_TUNNEL_NIC_INFO_STATIC_IANA_VXLAN;
 
 	dev->udp_tunnel_nic_info = info;
 	return 0;
@@ -207,6 +209,8 @@ void nsim_udp_tunnels_debugfs_create(struct nsim_dev *nsim_dev)
 			    &nsim_dev->udp_ports.ipv4_only);
 	debugfs_create_bool("udp_ports_shared", 0600, nsim_dev->ddir,
 			    &nsim_dev->udp_ports.shared);
+	debugfs_create_bool("udp_ports_static_iana_vxlan", 0600, nsim_dev->ddir,
+			    &nsim_dev->udp_ports.static_iana_vxlan);
 	debugfs_create_u32("udp_ports_sleep", 0600, nsim_dev->ddir,
 			   &nsim_dev->udp_ports.sleep);
 }
Signature · 1 line
2.26.2
author maintainer
#1 lore raw

RFC 1/4 udp_tunnel: add the ability to hard-code IANA VXLAN

In reply to Jakub Kicinski

mlx5 has the IANA VXLAN port (4789) hard coded by the device, instead of being added dynamically when tunnels are created.

To support this add a workaround flag to struct udp_tunnel_nic_info. Skipping updates for the port is fairly trivial, dumping the hard coded port via ethtool requires some code duplication. The port is not a part of any real table, we dump it in a special table which has no tunnel types supported and only one entry.

This is the last known workaround / hack needed to convert all drivers to the new infra.

---
 Documentation/networking/ethtool-netlink.rst |  3 +
 include/net/udp_tunnel.h                     |  5 ++
 net/ethtool/tunnels.c                        | 69 +++++++++++++++++---
 net/ipv4/udp_tunnel_nic.c                    |  7 ++
 4 files changed, 76 insertions(+), 8 deletions(-)
Documentation/networking/ethtool-netlink.rst +3 -0
index 7d75f1e32152..d53bcb31645a 100644
@@ -1263,6 +1263,9 @@ Gets information about the tunnel state NIC is aware of.
  | | | | ``ETHTOOL_A_TUNNEL_UDP_ENTRY_TYPE``   | u32    | tunnel type         |
  +-+-+-+---------------------------------------+--------+---------------------+
 
+For UDP tunnel table empty ``ETHTOOL_A_TUNNEL_UDP_TABLE_TYPES`` indicates that
+the table contains static entries, hard-coded by the NIC.
+
 Request translation
 ===================
 
include/net/udp_tunnel.h +5 -0
index 7615d0d4d071..2ea453dac876 100644
@@ -193,6 +193,11 @@ enum udp_tunnel_nic_info_flags {
 	UDP_TUNNEL_NIC_INFO_OPEN_ONLY	= BIT(1),
 	/* Device supports only IPv4 tunnels */
 	UDP_TUNNEL_NIC_INFO_IPV4_ONLY	= BIT(2),
+	/* Device has hard-coded the IANA VXLAN port (4789) as VXLAN.
+	 * This port must not be counted towards n_entries of any table.
+	 * Driver will not receive any callback associated with port 4789.
+	 */
+	UDP_TUNNEL_NIC_INFO_STATIC_IANA_VXLAN	= BIT(3),
 };
 
 struct udp_tunnel_nic;
net/ethtool/tunnels.c +61 -8

117 lines not on this page · raw message

net/ipv4/udp_tunnel_nic.c +7 -0
index f15e247e9ef0..0d122edc368d 100644
@@ -7,6 +7,7 @@
 #include <linux/types.h>
 #include <linux/workqueue.h>
 #include <net/udp_tunnel.h>
+#include <net/vxlan.h>
 
 enum udp_tunnel_nic_table_entry_flags {
 	UDP_TUNNEL_NIC_ENTRY_ADD	= BIT(0),
@@ -507,6 +508,12 @@ __udp_tunnel_nic_add_port(struct net_device *dev, struct udp_tunnel_info *ti)
 		return;
 	if (!netif_running(dev) && info->flags & UDP_TUNNEL_NIC_INFO_OPEN_ONLY)
 		return;
+	if (info->flags & UDP_TUNNEL_NIC_INFO_STATIC_IANA_VXLAN &&
+	    ti->port == htons(IANA_VXLAN_UDP_PORT)) {
+		if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
+			netdev_warn(dev, "device assumes port 4789 will be used by vxlan tunnels\n");
+		return;
+	}
 
 	if (!udp_tunnel_nic_is_capable(dev, utn, ti))
 		return;
Signature · 1 line
2.26.2
author maintainer
#2 lore raw

RFC 2/4 mlx5: convert to new udp_tunnel infrastructure

In reply to Jakub Kicinski

Allocate nic_info dynamically - n_entries is not constant.

Drop the ndo callbacks from the reprs, those should be local to the same netns as the main netdev, no need to get the same callbacks multiple times.

Drop the udp_tunnel_drop_rx_info() call, it was not there until
commit b3c2ed21c0bd ("net/mlx5e: Fix VXLAN configuration restore after function reload") so the device doesn't need it, and core should handle reloads and
reset just fine.

---
 drivers/net/ethernet/mellanox/mlx5/core/en.h  |  2 -
 .../net/ethernet/mellanox/mlx5/core/en_main.c | 88 ++-----------------
 .../net/ethernet/mellanox/mlx5/core/en_rep.c  |  2 -
 .../ethernet/mellanox/mlx5/core/lib/vxlan.c   | 87 +++++++++---------
 .../ethernet/mellanox/mlx5/core/lib/vxlan.h   |  6 +-
 5 files changed, 50 insertions(+), 135 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +0 -2
index c44669102626..c3e399f3e834 100644
@@ -1113,8 +1113,6 @@ void mlx5e_build_rss_params(struct mlx5e_rss_params *rss_params,
 void mlx5e_rx_dim_work(struct work_struct *work);
 void mlx5e_tx_dim_work(struct work_struct *work);
 
-void mlx5e_add_vxlan_port(struct net_device *netdev, struct udp_tunnel_info *ti);
-void mlx5e_del_vxlan_port(struct net_device *netdev, struct udp_tunnel_info *ti);
 netdev_features_t mlx5e_features_check(struct sk_buff *skb,
 				       struct net_device *netdev,
 				       netdev_features_t features);
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +5 -83

118 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +0 -2
index c300729fb498..000a7f264fda 100644
@@ -633,8 +633,6 @@ static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
 	.ndo_has_offload_stats	 = mlx5e_rep_has_offload_stats,
 	.ndo_get_offload_stats	 = mlx5e_rep_get_offload_stats,
 	.ndo_change_mtu          = mlx5e_uplink_rep_change_mtu,
-	.ndo_udp_tunnel_add      = mlx5e_add_vxlan_port,
-	.ndo_udp_tunnel_del      = mlx5e_del_vxlan_port,
 	.ndo_features_check      = mlx5e_features_check,
 	.ndo_set_vf_mac          = mlx5e_set_vf_mac,
 	.ndo_set_vf_rate         = mlx5e_set_vf_rate,
drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.c +43 -44

144 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/lib/vxlan.h +2 -4
index 6d599f4a8acd..6b7eeb94ec35 100644
@@ -48,15 +48,13 @@ static inline bool mlx5_vxlan_allowed(struct mlx5_vxlan *vxlan)
 #if IS_ENABLED(CONFIG_VXLAN)
 struct mlx5_vxlan *mlx5_vxlan_create(struct mlx5_core_dev *mdev);
 void mlx5_vxlan_destroy(struct mlx5_vxlan *vxlan);
-int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port);
-int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port);
+void mlx5_vxlan_set_netdev_info(struct mlx5_vxlan *vxlan, struct net_device *netdev);
 bool mlx5_vxlan_lookup_port(struct mlx5_vxlan *vxlan, u16 port);
 #else
 static inline struct mlx5_vxlan*
 mlx5_vxlan_create(struct mlx5_core_dev *mdev) { return ERR_PTR(-EOPNOTSUPP); }
 static inline void mlx5_vxlan_destroy(struct mlx5_vxlan *vxlan) { return; }
-static inline int mlx5_vxlan_add_port(struct mlx5_vxlan *vxlan, u16 port) { return -EOPNOTSUPP; }
-static inline int mlx5_vxlan_del_port(struct mlx5_vxlan *vxlan, u16 port) { return -EOPNOTSUPP; }
+static inline void mlx5_vxlan_set_netdev_info(struct mlx5_vxlan *vxlan, struct net_device *netdev) { return; }
 static inline bool mlx5_vxlan_lookup_port(struct mlx5_vxlan *vxlan, u16 port) { return false; }
 #endif
 
Signature · 1 line
2.26.2
author maintainer
#4 lore raw

RFC 4/4 selftests: net: add a test for static UDP tunnel ports

In reply to Jakub Kicinski

Check UDP_TUNNEL_NIC_INFO_STATIC_IANA_VXLAN works as expected.

---
 .../drivers/net/netdevsim/udp_tunnel_nic.sh   | 58 +++++++++++++++++++
 1 file changed, 58 insertions(+)
tools/testing/selftests/drivers/net/netdevsim/udp_tunnel_nic.sh +58 -0
index 9225133784af..1b08e042cf94 100644
@@ -7,6 +7,7 @@ NSIM_DEV_SYS=/sys/bus/netdevsim/devices/netdevsim$NSIM_ID
 NSIM_DEV_DFS=/sys/kernel/debug/netdevsim/netdevsim$NSIM_ID
 NSIM_NETDEV=
 HAS_ETHTOOL=
+STATIC_ENTRIES=
 EXIT_STATUS=0
 num_cases=0
 num_errors=0
@@ -193,6 +194,21 @@ function check_tables {
 	sleep 0.02
 	((retries--))
     done
+
+    if [ -n "$HAS_ETHTOOL" -a -n "${STATIC_ENTRIES[0]}" ]; then
+	fail=0
+	for i in "${!STATIC_ENTRIES[@]}"; do
+	    pp_expected=`pre_ethtool ${STATIC_ENTRIES[i]}`
+	    cnt=$(ethtool --show-tunnels $NSIM_NETDEV | grep -c "$pp_expected")
+	    if [ $cnt -ne 1 ]; then
+		err_cnt "ethtool static entry: $pfx - $msg"
+		echo "       check_table: ethtool does not contain '$pp_expected'"
+		ethtool --show-tunnels $NSIM_NETDEV
+		fail=1
+	    fi
+	done
+	[ $fail == 0 ] && pass_cnt
+    fi
 }
 
 function print_table {
@@ -884,6 +900,48 @@ echo 2 > $NSIM_DEV_SYS/del_port
 
 cleanup_nsim
 
+# Static IANA port
+pfx="static IANA vxlan"
+
+echo $NSIM_ID > /sys/bus/netdevsim/new_device
+echo 0 > $NSIM_DEV_SYS/del_port
+
+echo 1 > $NSIM_DEV_DFS/udp_ports_static_iana_vxlan
+STATIC_ENTRIES=( `mke 4789 1` )
+
+port=1
+old_netdevs=$(ls /sys/class/net)
+echo $port > $NSIM_DEV_SYS/new_port
+NSIM_NETDEV=`get_netdev_name old_netdevs`
+
+msg="check empty"
+exp0=( 0 0 0 0 )
+exp1=( 0 0 0 0 )
+check_tables
+
+msg="add on static port"
+new_vxlan vxlan0 4789 $NSIM_NETDEV
+new_vxlan vxlan1 4789 $NSIM_NETDEV
+
+msg="add on different port"
+exp0=( `mke 4790 1` 0 0 0 )
+new_vxlan vxlan2 4790 $NSIM_NETDEV
+
+cleanup_tuns
+
+msg="tunnels destroyed"
+exp0=( 0 0 0 0 )
+exp1=( 0 0 0 0 )
+check_tables
+
+msg="different type"
+new_geneve gnv0	4789
+
+cleanup_tuns
+cleanup_nsim
+
+# END
+
 modprobe -r netdevsim
 
 if [ $num_errors -eq 0 ]; then
Signature · 1 line
2.26.2