Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Dec 2018 13:25:47 +0000 (UTC)
From:      Slava Shwartsman <slavash@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r341535 - head/sys/ofed/drivers/infiniband/ulp/ipoib
Message-ID:  <201812051325.wB5DPlBI070338@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: slavash
Date: Wed Dec  5 13:25:47 2018
New Revision: 341535
URL: https://svnweb.freebsd.org/changeset/base/341535

Log:
  ipoib: correct setting MTU from inside ipoib(4).
  
  It is not enough to set ifnet->if_mtu to change the interface MTU.
  System saves the MTU for route in the radix tree, and route cache keeps
  the interface MTU as well. Since addition of the multicast group causes
  recalculation of MTU, even bringing the interface up changes MTU from
  4042 to 1500, which makes the system configuration inconsistent. Worse,
  ip_output() prefers route MTU over interface MTU, so large packets are
  not fragmented and dropped on floor.
  
  Fix it for ipoib(4) using the same approach (or hack) as was applied
  for it_tun/if_tap in r339012.  Thanks to bz@ for giving the hint.
  
  Submitted by:   kib@
  Approved by:    hselasky (mentor)
  MFC after:      1 week
  Sponsored by:   Mellanox Technologies

Modified:
  head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib.h
  head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_main.c
  head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_multicast.c

Modified: head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib.h
==============================================================================
--- head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib.h	Wed Dec  5 13:25:13 2018	(r341534)
+++ head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib.h	Wed Dec  5 13:25:47 2018	(r341535)
@@ -518,7 +518,7 @@ void ipoib_path_iter_read(struct ipoib_path_iter *iter
 			  struct ipoib_path *path);
 #endif
 
-int ipoib_change_mtu(struct ipoib_dev_priv *priv, int new_mtu);
+int ipoib_change_mtu(struct ipoib_dev_priv *priv, int new_mtu, bool propagate);
 
 int ipoib_mcast_attach(struct ipoib_dev_priv *priv, u16 mlid,
 		       union ib_gid *mgid, int set_qkey);

Modified: head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_main.c
==============================================================================
--- head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_main.c	Wed Dec  5 13:25:13 2018	(r341534)
+++ head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_main.c	Wed Dec  5 13:25:47 2018	(r341535)
@@ -257,10 +257,34 @@ ipoib_stop(struct ipoib_dev_priv *priv)
 	return 0;
 }
 
+static int
+ipoib_propagate_ifnet_mtu(struct ipoib_dev_priv *priv, int new_mtu,
+    bool propagate)
+{
+	struct ifnet *ifp;
+	struct ifreq ifr;
+	int error;
+
+	ifp = priv->dev;
+	if (ifp->if_mtu == new_mtu)
+		return (0);
+	if (propagate) {
+		strlcpy(ifr.ifr_name, if_name(ifp), IFNAMSIZ);
+		ifr.ifr_mtu = new_mtu;
+		CURVNET_SET(ifp->if_vnet);
+		error = ifhwioctl(SIOCSIFMTU, ifp, (caddr_t)&ifr, curthread);
+		CURVNET_RESTORE();
+	} else {
+		ifp->if_mtu = new_mtu;
+		error = 0;
+	}
+	return (error);
+}
+
 int
-ipoib_change_mtu(struct ipoib_dev_priv *priv, int new_mtu)
+ipoib_change_mtu(struct ipoib_dev_priv *priv, int new_mtu, bool propagate)
 {
-	struct ifnet *dev = priv->dev;
+	int error, prev_admin_mtu;
 
 	/* dev->if_mtu > 2K ==> connected mode */
 	if (ipoib_cm_admin_enabled(priv)) {
@@ -271,20 +295,21 @@ ipoib_change_mtu(struct ipoib_dev_priv *priv, int new_
 			ipoib_warn(priv, "mtu > %d will cause multicast packet drops.\n",
 				   priv->mcast_mtu);
 
-		dev->if_mtu = new_mtu;
-		return 0;
+		return (ipoib_propagate_ifnet_mtu(priv, new_mtu, propagate));
 	}
 
 	if (new_mtu > IPOIB_UD_MTU(priv->max_ib_mtu))
 		return -EINVAL;
 
+	prev_admin_mtu = priv->admin_mtu;
 	priv->admin_mtu = new_mtu;
-
-	dev->if_mtu = min(priv->mcast_mtu, priv->admin_mtu);
-
-	queue_work(ipoib_workqueue, &priv->flush_light);
-
-	return 0;
+	error = ipoib_propagate_ifnet_mtu(priv, min(priv->mcast_mtu,
+	    priv->admin_mtu), propagate);
+	if (error == 0)
+		queue_work(ipoib_workqueue, &priv->flush_light);
+	else
+		priv->admin_mtu = prev_admin_mtu;
+	return (error);
 }
 
 static int
@@ -338,7 +363,7 @@ ipoib_ioctl(struct ifnet *ifp, u_long command, caddr_t
 		/*
 		 * Set the interface MTU.
 		 */
-		error = -ipoib_change_mtu(priv, ifr->ifr_mtu);
+		error = -ipoib_change_mtu(priv, ifr->ifr_mtu, false);
 		break;
 	default:
 		error = EINVAL;

Modified: head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
==============================================================================
--- head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_multicast.c	Wed Dec  5 13:25:13 2018	(r341534)
+++ head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_multicast.c	Wed Dec  5 13:25:47 2018	(r341535)
@@ -564,7 +564,8 @@ void ipoib_mcast_join_task(struct work_struct *work)
 	spin_unlock_irq(&priv->lock);
 
 	if (!ipoib_cm_admin_enabled(priv))
-		ipoib_change_mtu(priv, min(priv->mcast_mtu, priv->admin_mtu));
+		ipoib_change_mtu(priv, min(priv->mcast_mtu, priv->admin_mtu),
+		    true);
 
 	ipoib_dbg_mcast(priv, "successfully joined all multicast groups\n");
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201812051325.wB5DPlBI070338>