From nobody@FreeBSD.org  Thu Dec  6 01:19:38 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 15A1256D
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  6 Dec 2012 01:19:38 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id EE0278FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  6 Dec 2012 01:19:37 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id qB61JbN6097985
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 6 Dec 2012 01:19:37 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id qB61Jbdh097984;
	Thu, 6 Dec 2012 01:19:37 GMT
	(envelope-from nobody)
Message-Id: <201212060119.qB61Jbdh097984@red.freebsd.org>
Date: Thu, 6 Dec 2012 01:19:37 GMT
From: Anthony Cornehl <accornehl@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: OFED sysfs/sysctl compat does not handle show/set attribute functions
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         174213
>Category:       kern
>Synopsis:       [patch] [fed] OFED sysfs/sysctl compat does not handle show/set attribute functions
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jhb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 06 01:20:00 UTC 2012
>Closed-Date:    Wed Aug 07 18:01:33 UTC 2013
>Last-Modified:  Wed Aug 07 18:01:33 UTC 2013
>Originator:     Anthony Cornehl
>Release:        9.1-RC2
>Organization:
EMC Isilon
>Environment:
FreeBSD Waltraute 9.1-RC2 FreeBSD 9.1-RC2 #2: Wed Dec  5 21:38:19 PST 2012     root@Waltraute:/usr/obj/usr/src/sys/KERN_IB  amd64
>Description:
Thread is here: http://lists.freebsd.org/pipermail/freebsd-infiniband/2012-November/000002.html

Mellanox Connect-X VPI cards allow the QSFP ports to be used for InfiniBand or Ethernet communication, by setting the port mode in sysfs/sysctl. But it appears that a sysfs/sysctl abstraction didn't get carried over all the for FreeBSD...

---
# sysctl sys.device.mlx4_core0.mlx4_port1
sys.device.mlx4_core0.mlx4_port1: ib

# sysctl sys.device.mlx4_core0.mlx4_port1=ib
sys.device.mlx4_core0.mlx4_port1: ib

sysctl: sys.device.mlx4_core0.mlx4_port1: Invalid argument
---

The problem is that sysfs allows our MLX4 code to use two functions in an attribute structure, .store and .show. The compat header for sysfs in `sys/ofed/include/linux/sysfs.h` is doing something wrong and never calls the .store function in `sys/ofed/drivers/net/mlx4/main.c` for this sysctl.

It looks like sysctl_handle_attr() should be handling this, but I'm not sure how. Yet.
>How-To-Repeat:
# pciconf -lv | grep -C2 'ConnectX VPI'
# kldload mlx4
# sysctl sys.device.mlx4_core0.mlx4_port1=eth

The value from `sysctl sys.device.mlx4_core0.mlx4_port1` should be "eth".
>Fix:


>Release-Note:
>Audit-Trail:

From: Garrett Cooper <yanegomi@gmail.com>
To: bug-followup@FreeBSD.org, accornehl@gmail.com
Cc:  
Subject: Re: kern/174213: [fed] OFED sysfs/sysctl compat does not handle
 show/set attribute functions
Date: Wed, 12 Dec 2012 21:50:05 -0800 (PST)

   This message is in MIME format.  The first part should be readable text,
   while the remaining parts are likely unreadable without MIME-aware tools.
 
 --967339439-20611481-1355377809=:90705
 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII
 
  	The attached patch fixes the issue and with the directions I 
 discussed on the mailing list, allowed me to flip between eth(ernet) mode 
 and ib mode.
 Thanks!
 -Garrett
 
 From 53d4589061fe5c0dbcb3b58c3bcbb25fb212585a Mon Sep 17 00:00:00 2001
 From: Garrett Cooper <yanegomi@gmail.com>
 Date: Tue, 11 Dec 2012 22:10:00 -0800
 Subject: [PATCH] Make the ofed sysctl<->sysfs handler more linux-like and
   optimize it
 
 Highlights:
 
 The previous code was incorrectly assuming that sysfs and sysctls have a
 1:1 relationship, but sysfs on Linux based on the documentation I've
 found (and the Linux driver / example code I've peeked at) assumes
 there's a trailing newline at the end of each value; so we need to
 append a newline to the sysctl buffer on store and remove it on show in
 order to be properly compatible between sysctl(9) and sysfs.
 
 Also, the wrong value was being passed into SYSCTL_IN (PAGE_SIZE). It
 should have been req->newlen.
 
 Lowlights:
 
 1. Many of the error conditions could have been simplified up-front
     (dealing with checking the kobj object and whether or not buf was
     NULL).
 2. buf was being leaked if the kobj object was invalid.
 3. The code now allows the user to store and show, store and not show,
     or show and not store.
 
 The issues highlighted address kern/174213.
 
 Sponsored-by: EMC Corporation
 Signed-off-by: Garrett Cooper <yanegomi@gmail.com>
 ---
   sys/ofed/include/linux/sysfs.h | 53 ++++++++++++++++++++++++++++--------------
   1 file changed, 35 insertions(+), 18 deletions(-)
 
 diff --git a/sys/ofed/include/linux/sysfs.h b/sys/ofed/include/linux/sysfs.h
 index 698f75e..1aff3c2 100644
 --- a/sys/ofed/include/linux/sysfs.h
 +++ b/sys/ofed/include/linux/sysfs.h
 @@ -69,6 +69,10 @@ struct attribute_group {
    *      a constant string:  point arg1 at it, arg2 is zero.
    */
 
 +/*
 + * XXX: should support iteration of pages as sysfs supports paging
 + * in/paging out data in PAGE_SIZE chunks.
 + */
   static inline int
   sysctl_handle_attr(SYSCTL_HANDLER_ARGS)
   {
 @@ -76,37 +80,50 @@ sysctl_handle_attr(SYSCTL_HANDLER_ARGS)
   	struct attribute *attr;
   	const struct sysfs_ops *ops;
   	void *buf;
 -	int error;
   	ssize_t len;
 +	int error = 0;
 
   	kobj = arg1;
   	attr = (struct attribute *)arg2;
 -	buf = (void *)get_zeroed_page(GFP_KERNEL);
 -	len = 1;	/* Copy out a NULL byte at least. */
   	if (kobj->ktype == NULL || kobj->ktype->sysfs_ops == NULL)
   		return (ENODEV);
 -	ops = kobj->ktype->sysfs_ops;
 +	buf = (void *)get_zeroed_page(GFP_KERNEL);
   	if (buf == NULL)
   		return (ENOMEM);
 -	if (ops->show) {
 -		len = ops->show(kobj, attr, buf);
 -		/*
 -		 * It's valid not to have a 'show' so we just return 1 byte
 -		 * of NULL.
 -	 	 */
 -		if (len < 0) {
 -			error = -len;
 -			len = 1;
 -			if (error != EIO)
 -				goto out;
 -		}
 +	ops = kobj->ktype->sysfs_ops;
 +
 +	/* Show */
 +	if (ops->show == NULL)
 +		goto store;
 +	len = ops->show(kobj, attr, buf);
 +	if (len < 0) {
 +		error = -len;
 +		len = 1;
 +		if (error != EIO)
 +			goto out;
   	}
 +	/* It's valid not to have a 'show' so we just return NUL. */
 +	else if (len == 0)
 +		len = 1;
 +	len -= 1;
 +	((char*)buf)[len] = '\0';
   	error = SYSCTL_OUT(req, buf, len);
 -	if (error || !req->newptr || ops->store == NULL)
 +	if (error)
 +		goto out;
 +
 +store:
 +	/* Store */
 +	if (!req->newptr || ops->store == NULL)
 +		goto out;
 +	if (req->newlen > PAGE_SIZE-2) { /* NUL terminated + '\n' */
 +		error = EINVAL;
   		goto out;
 -	error = SYSCTL_IN(req, buf, PAGE_SIZE);
 +	}
 +	error = SYSCTL_IN(req, buf, req->newlen);
   	if (error)
   		goto out;
 +	((char*)buf)[req->newlen] = '\n';
 +	((char*)buf)[req->newlen+1] = '\0';
   	len = ops->store(kobj, attr, buf, req->newlen);
   	if (len < 0)
   		error = -len;
 -- 
 1.8.0.1
 --967339439-20611481-1355377809=:90705
 Content-Type: TEXT/PLAIN; charset=US-ASCII; name=0001-Make-the-ofed-sysctl-sysfs-handler-more-linux-like-a.patch
 Content-Transfer-Encoding: BASE64
 Content-ID: <alpine.BSF.2.00.1212122150050.90705@toaster.local>
 Content-Description: 
 Content-Disposition: attachment; filename=0001-Make-the-ofed-sysctl-sysfs-handler-more-linux-like-a.patch
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wgb3BzLT5zdG9yZSA9PSBOVUxMKQ0KKwlp
 ZiAoZXJyb3IpDQorCQlnb3RvIG91dDsNCisNCitzdG9yZToNCisJLyogU3Rv
 cmUgKi8NCisJaWYgKCFyZXEtPm5ld3B0ciB8fCBvcHMtPnN0b3JlID09IE5V
 TEwpDQorCQlnb3RvIG91dDsNCisJaWYgKHJlcS0+bmV3bGVuID4gUEFHRV9T
 SVpFLTIpIHsgLyogTlVMIHRlcm1pbmF0ZWQgKyAnXG4nICovDQorCQllcnJv
 ciA9IEVJTlZBTDsNCiAJCWdvdG8gb3V0Ow0KLQllcnJvciA9IFNZU0NUTF9J
 TihyZXEsIGJ1ZiwgUEFHRV9TSVpFKTsNCisJfQ0KKwllcnJvciA9IFNZU0NU
 TF9JTihyZXEsIGJ1ZiwgcmVxLT5uZXdsZW4pOw0KIAlpZiAoZXJyb3IpDQog
 CQlnb3RvIG91dDsNCisJKChjaGFyKilidWYpW3JlcS0+bmV3bGVuXSA9ICdc
 bic7DQorCSgoY2hhciopYnVmKVtyZXEtPm5ld2xlbisxXSA9ICdcMCc7DQog
 CWxlbiA9IG9wcy0+c3RvcmUoa29iaiwgYXR0ciwgYnVmLCByZXEtPm5ld2xl
 bik7DQogCWlmIChsZW4gPCAwKQ0KIAkJZXJyb3IgPSAtbGVuOw0KLS0gDQox
 LjguMC4xDQoNCg==
 
 --967339439-20611481-1355377809=:90705--
State-Changed-From-To: open->patched 
State-Changed-By: jhb 
State-Changed-When: Thu Jul 18 14:07:24 UTC 2013 
State-Changed-Why:  
Modified version of Garrett's patch committed to HEAD. 


Responsible-Changed-From-To: freebsd-bugs->jhb 
Responsible-Changed-By: jhb 
Responsible-Changed-When: Thu Jul 18 14:07:24 UTC 2013 
Responsible-Changed-Why:  
Modified version of Garrett's patch committed to HEAD. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=174213 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/174213: commit references a PR
Date: Thu, 18 Jul 2013 14:06:14 +0000 (UTC)

 Author: jhb
 Date: Thu Jul 18 14:06:01 2013
 New Revision: 253449
 URL: http://svnweb.freebsd.org/changeset/base/253449
 
 Log:
   Rework the previous fix for the IB vs Ethernet sysctl handler to be more
   generic and apply to all sysfs attributes:
   - Use sysctl_handle_string() instead of reimplementing it.
   - Remove trailing newline from the current value before passing it to
     userland and append a newline to the new string value before passing it
     to the attribute's store function.
   - Don't leak the temporary buffer if the first error check triggers.
   - Revert earlier change to mlx4 port mode handler.
   
   PR:		kern/174213
   Submitted by:	Garrett Cooper
   Reviewed by:	Shakar Klein @ Mellanox
   MFC after:	1 week
 
 Modified:
   head/sys/ofed/drivers/net/mlx4/main.c
   head/sys/ofed/include/linux/sysfs.h
 
 Modified: head/sys/ofed/drivers/net/mlx4/main.c
 ==============================================================================
 --- head/sys/ofed/drivers/net/mlx4/main.c	Thu Jul 18 07:43:55 2013	(r253448)
 +++ head/sys/ofed/drivers/net/mlx4/main.c	Thu Jul 18 14:06:01 2013	(r253449)
 @@ -476,11 +476,11 @@ static ssize_t set_port_type(struct devi
  	int i;
  	int err = 0;
  
 -	if (!strcmp(buf, "ib"))
 +	if (!strcmp(buf, "ib\n"))
  		info->tmp_type = MLX4_PORT_TYPE_IB;
 -	else if (!strcmp(buf, "eth"))
 +	else if (!strcmp(buf, "eth\n"))
  		info->tmp_type = MLX4_PORT_TYPE_ETH;
 -	else if (!strcmp(buf, "auto"))
 +	else if (!strcmp(buf, "auto\n"))
  		info->tmp_type = MLX4_PORT_TYPE_AUTO;
  	else {
  		mlx4_err(mdev, "%s is not supported port type\n", buf);
 
 Modified: head/sys/ofed/include/linux/sysfs.h
 ==============================================================================
 --- head/sys/ofed/include/linux/sysfs.h	Thu Jul 18 07:43:55 2013	(r253448)
 +++ head/sys/ofed/include/linux/sysfs.h	Thu Jul 18 14:06:01 2013	(r253449)
 @@ -75,43 +75,41 @@ sysctl_handle_attr(SYSCTL_HANDLER_ARGS)
  	struct kobject *kobj;
  	struct attribute *attr;
  	const struct sysfs_ops *ops;
 -	void *buf;
 +	char *buf;
  	int error;
  	ssize_t len;
  
  	kobj = arg1;
  	attr = (struct attribute *)arg2;
 -	buf = (void *)get_zeroed_page(GFP_KERNEL);
 -	len = 1;	/* Copy out a NULL byte at least. */
  	if (kobj->ktype == NULL || kobj->ktype->sysfs_ops == NULL)
  		return (ENODEV);
 -	ops = kobj->ktype->sysfs_ops;
 +	buf = (char *)get_zeroed_page(GFP_KERNEL);
  	if (buf == NULL)
  		return (ENOMEM);
 +	ops = kobj->ktype->sysfs_ops;
  	if (ops->show) {
  		len = ops->show(kobj, attr, buf);
  		/*
 -		 * It's valid not to have a 'show' so we just return 1 byte
 -		 * of NULL.
 +		 * It's valid to not have a 'show' so just return an
 +		 * empty string.
  	 	 */
  		if (len < 0) {
  			error = -len;
 -			len = 1;
  			if (error != EIO)
  				goto out;
  		}
 +
 +		/* Trim trailing newline. */
 +		len--;
 +		buf[len] = '\0';
  	}
 -	error = SYSCTL_OUT(req, buf, len);
 -	if (error || !req->newptr || ops->store == NULL)
 -		goto out;
 -	len = req->newlen - req->newidx;
 -	if (len >= PAGE_SIZE)
 -		error = EINVAL;
 -	else 
 -		error = SYSCTL_IN(req, buf, len);
 -	if (error)
 +
 +	/* Leave one trailing byte to append a newline. */
 +	error = sysctl_handle_string(oidp, buf, PAGE_SIZE - 1, req);
 +	if (error != 0 || req->newptr == NULL || ops->store == NULL)
  		goto out;
 -	((char *)buf)[len] = '\0';
 +	len = strlcat(buf, "\n", PAGE_SIZE);
 +	KASSERT(len < PAGE_SIZE, ("new attribute truncated"));
  	len = ops->store(kobj, attr, buf, len);
  	if (len < 0)
  		error = -len;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/174213: commit references a PR
Date: Tue,  6 Aug 2013 19:24:21 +0000 (UTC)

 Author: jhb
 Date: Tue Aug  6 19:23:57 2013
 New Revision: 254006
 URL: http://svnweb.freebsd.org/changeset/base/254006
 
 Log:
   MFC 253048,253423,253449,253653,253774,253785:
   - Allow mlx4 devices to switch between Ethernet and Infiniband:
     - Fix sysfs attribute handling by using sysctl_handle_string() and
       properly handling trailing newlines in attribute values.
     - Remove check forbidding requests that would result in one port being
       set to Ethernet and the subsequent port being set to IB.
   - Avoid trashing IP fragments by correctly managing hardware checksumming.
   - Fix panics when downing or unloading the mlx4 driver.
   
   PR:		kern/179999, kern/174213, kern/180430, kern/180791
 
 Modified:
   stable/9/sys/ofed/drivers/net/mlx4/en_netdev.c
   stable/9/sys/ofed/drivers/net/mlx4/en_tx.c
   stable/9/sys/ofed/drivers/net/mlx4/main.c
   stable/9/sys/ofed/include/linux/sysfs.h
 Directory Properties:
   stable/9/sys/   (props changed)
 
 Modified: stable/9/sys/ofed/drivers/net/mlx4/en_netdev.c
 ==============================================================================
 --- stable/9/sys/ofed/drivers/net/mlx4/en_netdev.c	Tue Aug  6 19:14:02 2013	(r254005)
 +++ stable/9/sys/ofed/drivers/net/mlx4/en_netdev.c	Tue Aug  6 19:23:57 2013	(r254006)
 @@ -43,6 +43,7 @@
  #include <net/if_vlan_var.h>
  #include <sys/sockio.h>
  
 +static void mlx4_en_init_locked(struct mlx4_en_priv *priv);
  static void mlx4_en_sysctl_stat(struct mlx4_en_priv *priv);
  
  static void mlx4_en_vlan_rx_add_vid(void *arg, struct net_device *dev, u16 vid)
 @@ -495,11 +496,6 @@ static void mlx4_en_do_get_stats(struct 
  
  		queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
  	}
 -	if (mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port]) {
 -		panic("mlx4_en_do_get_stats: Unexpected mac removed for %d\n",
 -		    priv->port);
 -		mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port] = 0;
 -	}
  	mutex_unlock(&mdev->state_lock);
  }
  
 @@ -688,8 +684,8 @@ int mlx4_en_start_port(struct net_device
  	mlx4_en_set_multicast(dev);
  
  	/* Enable the queues. */
 -	atomic_clear_int(&dev->if_drv_flags, IFF_DRV_OACTIVE);
 -	atomic_set_int(&dev->if_drv_flags, IFF_DRV_RUNNING);
 +	dev->if_drv_flags &= ~IFF_DRV_OACTIVE;
 +	dev->if_drv_flags |= IFF_DRV_RUNNING;
  
  	callout_reset(&priv->watchdog_timer, MLX4_EN_WATCHDOG_TIMEOUT,
  	    mlx4_en_watchdog_timeout, priv);
 @@ -761,7 +757,7 @@ void mlx4_en_stop_port(struct net_device
  
  	callout_stop(&priv->watchdog_timer);
  
 -	atomic_clear_int(&dev->if_drv_flags, IFF_DRV_RUNNING);
 +	dev->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
  }
  
  static void mlx4_en_restart(struct work_struct *work)
 @@ -802,19 +798,30 @@ mlx4_en_init(void *arg)
  {
  	struct mlx4_en_priv *priv;
  	struct mlx4_en_dev *mdev;
 +
 +	priv = arg;
 +	mdev = priv->mdev;
 +	mutex_lock(&mdev->state_lock);
 +	mlx4_en_init_locked(priv);
 +	mutex_unlock(&mdev->state_lock);
 +}
 +
 +static void
 +mlx4_en_init_locked(struct mlx4_en_priv *priv)
 +{
 +
 +	struct mlx4_en_dev *mdev;
  	struct ifnet *dev;
  	int i;
  
 -	priv = arg;
  	dev = priv->dev;
  	mdev = priv->mdev;
 -	mutex_lock(&mdev->state_lock);
  	if (dev->if_drv_flags & IFF_DRV_RUNNING)
  		mlx4_en_stop_port(dev);
  
  	if (!mdev->device_up) {
  		en_err(priv, "Cannot open - device down/disabled\n");
 -		goto out;
 +		return;
  	}
  
  	/* Reset HW statistics and performance counters */
 @@ -835,9 +842,6 @@ mlx4_en_init(void *arg)
  	mlx4_en_set_default_moderation(priv);
  	if (mlx4_en_start_port(dev))
  		en_err(priv, "Failed starting port:%d\n", priv->port);
 -
 -out:
 -	mutex_unlock(&mdev->state_lock);
  }
  
  void mlx4_en_free_resources(struct mlx4_en_priv *priv)
 @@ -927,9 +931,14 @@ void mlx4_en_destroy_netdev(struct net_d
  	if (priv->sysctl)
  		sysctl_ctx_free(&priv->conf_ctx);
  
 +	mutex_lock(&mdev->state_lock);
 +	mlx4_en_stop_port(dev);
 +	mutex_unlock(&mdev->state_lock);
 +
  	cancel_delayed_work(&priv->stats_task);
  	/* flush any pending task for this netdev */
  	flush_workqueue(mdev->workqueue);
 +	callout_drain(&priv->watchdog_timer);
  
  	/* Detach the netdev so tasks would not attempt to access it */
  	mutex_lock(&mdev->state_lock);
 @@ -1091,31 +1100,32 @@ static int mlx4_en_ioctl(struct ifnet *d
  		error = -mlx4_en_change_mtu(dev, ifr->ifr_mtu);
  		break;
  	case SIOCSIFFLAGS:
 +		mutex_lock(&mdev->state_lock);
  		if (dev->if_flags & IFF_UP) {
 -			if ((dev->if_drv_flags & IFF_DRV_RUNNING) == 0) {
 -				mutex_lock(&mdev->state_lock);
 +			if ((dev->if_drv_flags & IFF_DRV_RUNNING) == 0)
  				mlx4_en_start_port(dev);
 -				mutex_unlock(&mdev->state_lock);
 -			} else
 +			else
  				mlx4_en_set_multicast(dev);
  		} else {
 -			mutex_lock(&mdev->state_lock);
  			if (dev->if_drv_flags & IFF_DRV_RUNNING) {
  				mlx4_en_stop_port(dev);
  				if_link_state_change(dev, LINK_STATE_DOWN);
  			}
 -			mutex_unlock(&mdev->state_lock);
  		}
 +		mutex_unlock(&mdev->state_lock);
  		break;
  	case SIOCADDMULTI:
  	case SIOCDELMULTI:
 +		mutex_lock(&mdev->state_lock);
  		mlx4_en_set_multicast(dev);
 +		mutex_unlock(&mdev->state_lock);
  		break;
  	case SIOCSIFMEDIA:
  	case SIOCGIFMEDIA:
  		error = ifmedia_ioctl(dev, ifr, &priv->media, command);
  		break;
  	case SIOCSIFCAP:
 +		mutex_lock(&mdev->state_lock);
  		mask = ifr->ifr_reqcap ^ dev->if_capenable;
  		if (mask & IFCAP_HWCSUM)
  			dev->if_capenable ^= IFCAP_HWCSUM;
 @@ -1130,7 +1140,8 @@ static int mlx4_en_ioctl(struct ifnet *d
  		if (mask & IFCAP_WOL_MAGIC)
  			dev->if_capenable ^= IFCAP_WOL_MAGIC;
  		if (dev->if_drv_flags & IFF_DRV_RUNNING)
 -			mlx4_en_init(priv);
 +			mlx4_en_init_locked(priv);
 +		mutex_unlock(&mdev->state_lock);
  		VLAN_CAPABILITIES(dev);
  		break;
  	default:
 
 Modified: stable/9/sys/ofed/drivers/net/mlx4/en_tx.c
 ==============================================================================
 --- stable/9/sys/ofed/drivers/net/mlx4/en_tx.c	Tue Aug  6 19:14:02 2013	(r254005)
 +++ stable/9/sys/ofed/drivers/net/mlx4/en_tx.c	Tue Aug  6 19:23:57 2013	(r254006)
 @@ -780,8 +780,12 @@ retry:
  	tx_desc->ctrl.srcrb_flags = cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE |
  						MLX4_WQE_CTRL_SOLICITED);
  	if (mb->m_pkthdr.csum_flags & (CSUM_IP|CSUM_TCP|CSUM_UDP)) {
 -		tx_desc->ctrl.srcrb_flags |= cpu_to_be32(MLX4_WQE_CTRL_IP_CSUM |
 -							 MLX4_WQE_CTRL_TCP_UDP_CSUM);
 +		if (mb->m_pkthdr.csum_flags & CSUM_IP)
 +			tx_desc->ctrl.srcrb_flags |=
 +			    cpu_to_be32(MLX4_WQE_CTRL_IP_CSUM);
 +		if (mb->m_pkthdr.csum_flags & (CSUM_TCP|CSUM_UDP))
 +			tx_desc->ctrl.srcrb_flags |=
 +			    cpu_to_be32(MLX4_WQE_CTRL_TCP_UDP_CSUM);
  		priv->port_stats.tx_chksum_offload++;
  	}
  
 
 Modified: stable/9/sys/ofed/drivers/net/mlx4/main.c
 ==============================================================================
 --- stable/9/sys/ofed/drivers/net/mlx4/main.c	Tue Aug  6 19:14:02 2013	(r254005)
 +++ stable/9/sys/ofed/drivers/net/mlx4/main.c	Tue Aug  6 19:23:57 2013	(r254006)
 @@ -209,9 +209,6 @@ int mlx4_check_port_params(struct mlx4_d
  					 "on this HCA, aborting.\n");
  				return -EINVAL;
  			}
 -			if (port_type[i] == MLX4_PORT_TYPE_ETH &&
 -			    port_type[i + 1] == MLX4_PORT_TYPE_IB)
 -				return -EINVAL;
  		}
  	}
  
 
 Modified: stable/9/sys/ofed/include/linux/sysfs.h
 ==============================================================================
 --- stable/9/sys/ofed/include/linux/sysfs.h	Tue Aug  6 19:14:02 2013	(r254005)
 +++ stable/9/sys/ofed/include/linux/sysfs.h	Tue Aug  6 19:23:57 2013	(r254006)
 @@ -75,39 +75,42 @@ sysctl_handle_attr(SYSCTL_HANDLER_ARGS)
  	struct kobject *kobj;
  	struct attribute *attr;
  	const struct sysfs_ops *ops;
 -	void *buf;
 +	char *buf;
  	int error;
  	ssize_t len;
  
  	kobj = arg1;
  	attr = (struct attribute *)arg2;
 -	buf = (void *)get_zeroed_page(GFP_KERNEL);
 -	len = 1;	/* Copy out a NULL byte at least. */
  	if (kobj->ktype == NULL || kobj->ktype->sysfs_ops == NULL)
  		return (ENODEV);
 -	ops = kobj->ktype->sysfs_ops;
 +	buf = (char *)get_zeroed_page(GFP_KERNEL);
  	if (buf == NULL)
  		return (ENOMEM);
 +	ops = kobj->ktype->sysfs_ops;
  	if (ops->show) {
  		len = ops->show(kobj, attr, buf);
  		/*
 -		 * It's valid not to have a 'show' so we just return 1 byte
 -		 * of NULL.
 +		 * It's valid to not have a 'show' so just return an
 +		 * empty string.
  	 	 */
  		if (len < 0) {
  			error = -len;
 -			len = 1;
  			if (error != EIO)
  				goto out;
  		}
 +
 +		/* Trim trailing newline. */
 +		len--;
 +		buf[len] = '\0';
  	}
 -	error = SYSCTL_OUT(req, buf, len);
 -	if (error || !req->newptr || ops->store == NULL)
 -		goto out;
 -	error = SYSCTL_IN(req, buf, PAGE_SIZE);
 -	if (error)
 +
 +	/* Leave one trailing byte to append a newline. */
 +	error = sysctl_handle_string(oidp, buf, PAGE_SIZE - 1, req);
 +	if (error != 0 || req->newptr == NULL || ops->store == NULL)
  		goto out;
 -	len = ops->store(kobj, attr, buf, req->newlen);
 +	len = strlcat(buf, "\n", PAGE_SIZE);
 +	KASSERT(len < PAGE_SIZE, ("new attribute truncated"));
 +	len = ops->store(kobj, attr, buf, len);
  	if (len < 0)
  		error = -len;
  out:
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/174213: commit references a PR
Date: Tue,  6 Aug 2013 20:04:58 +0000 (UTC)

 Author: jhb
 Date: Tue Aug  6 20:04:44 2013
 New Revision: 254007
 URL: http://svnweb.freebsd.org/changeset/base/254007
 
 Log:
   MFC 253048,253423,253449,253653,253774,253785:
   - Allow mlx4 devices to switch between Ethernet and Infiniband:
     - Fix sysfs attribute handling by using sysctl_handle_string() and
       properly handling trailing newlines in attribute values.
     - Remove check forbidding requests that would result in one port being
       set to Ethernet and the subsequent port being set to IB.
   - Avoid trashing IP fragments by correctly managing hardware checksumming.
   - Fix panics when downing or unloading the mlx4 driver.
   
   PR:		kern/179999, kern/174213, kern/180430, kern/180791
   Approved by:	re (kib)
 
 Modified:
   releng/9.2/sys/ofed/drivers/net/mlx4/en_netdev.c
   releng/9.2/sys/ofed/drivers/net/mlx4/en_tx.c
   releng/9.2/sys/ofed/drivers/net/mlx4/main.c
   releng/9.2/sys/ofed/include/linux/sysfs.h
 Directory Properties:
   releng/9.2/sys/   (props changed)
 
 Modified: releng/9.2/sys/ofed/drivers/net/mlx4/en_netdev.c
 ==============================================================================
 --- releng/9.2/sys/ofed/drivers/net/mlx4/en_netdev.c	Tue Aug  6 19:23:57 2013	(r254006)
 +++ releng/9.2/sys/ofed/drivers/net/mlx4/en_netdev.c	Tue Aug  6 20:04:44 2013	(r254007)
 @@ -43,6 +43,7 @@
  #include <net/if_vlan_var.h>
  #include <sys/sockio.h>
  
 +static void mlx4_en_init_locked(struct mlx4_en_priv *priv);
  static void mlx4_en_sysctl_stat(struct mlx4_en_priv *priv);
  
  static void mlx4_en_vlan_rx_add_vid(void *arg, struct net_device *dev, u16 vid)
 @@ -495,11 +496,6 @@ static void mlx4_en_do_get_stats(struct 
  
  		queue_delayed_work(mdev->workqueue, &priv->stats_task, STATS_DELAY);
  	}
 -	if (mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port]) {
 -		panic("mlx4_en_do_get_stats: Unexpected mac removed for %d\n",
 -		    priv->port);
 -		mdev->mac_removed[MLX4_MAX_PORTS + 1 - priv->port] = 0;
 -	}
  	mutex_unlock(&mdev->state_lock);
  }
  
 @@ -688,8 +684,8 @@ int mlx4_en_start_port(struct net_device
  	mlx4_en_set_multicast(dev);
  
  	/* Enable the queues. */
 -	atomic_clear_int(&dev->if_drv_flags, IFF_DRV_OACTIVE);
 -	atomic_set_int(&dev->if_drv_flags, IFF_DRV_RUNNING);
 +	dev->if_drv_flags &= ~IFF_DRV_OACTIVE;
 +	dev->if_drv_flags |= IFF_DRV_RUNNING;
  
  	callout_reset(&priv->watchdog_timer, MLX4_EN_WATCHDOG_TIMEOUT,
  	    mlx4_en_watchdog_timeout, priv);
 @@ -761,7 +757,7 @@ void mlx4_en_stop_port(struct net_device
  
  	callout_stop(&priv->watchdog_timer);
  
 -	atomic_clear_int(&dev->if_drv_flags, IFF_DRV_RUNNING);
 +	dev->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
  }
  
  static void mlx4_en_restart(struct work_struct *work)
 @@ -802,19 +798,30 @@ mlx4_en_init(void *arg)
  {
  	struct mlx4_en_priv *priv;
  	struct mlx4_en_dev *mdev;
 +
 +	priv = arg;
 +	mdev = priv->mdev;
 +	mutex_lock(&mdev->state_lock);
 +	mlx4_en_init_locked(priv);
 +	mutex_unlock(&mdev->state_lock);
 +}
 +
 +static void
 +mlx4_en_init_locked(struct mlx4_en_priv *priv)
 +{
 +
 +	struct mlx4_en_dev *mdev;
  	struct ifnet *dev;
  	int i;
  
 -	priv = arg;
  	dev = priv->dev;
  	mdev = priv->mdev;
 -	mutex_lock(&mdev->state_lock);
  	if (dev->if_drv_flags & IFF_DRV_RUNNING)
  		mlx4_en_stop_port(dev);
  
  	if (!mdev->device_up) {
  		en_err(priv, "Cannot open - device down/disabled\n");
 -		goto out;
 +		return;
  	}
  
  	/* Reset HW statistics and performance counters */
 @@ -835,9 +842,6 @@ mlx4_en_init(void *arg)
  	mlx4_en_set_default_moderation(priv);
  	if (mlx4_en_start_port(dev))
  		en_err(priv, "Failed starting port:%d\n", priv->port);
 -
 -out:
 -	mutex_unlock(&mdev->state_lock);
  }
  
  void mlx4_en_free_resources(struct mlx4_en_priv *priv)
 @@ -927,9 +931,14 @@ void mlx4_en_destroy_netdev(struct net_d
  	if (priv->sysctl)
  		sysctl_ctx_free(&priv->conf_ctx);
  
 +	mutex_lock(&mdev->state_lock);
 +	mlx4_en_stop_port(dev);
 +	mutex_unlock(&mdev->state_lock);
 +
  	cancel_delayed_work(&priv->stats_task);
  	/* flush any pending task for this netdev */
  	flush_workqueue(mdev->workqueue);
 +	callout_drain(&priv->watchdog_timer);
  
  	/* Detach the netdev so tasks would not attempt to access it */
  	mutex_lock(&mdev->state_lock);
 @@ -1091,31 +1100,32 @@ static int mlx4_en_ioctl(struct ifnet *d
  		error = -mlx4_en_change_mtu(dev, ifr->ifr_mtu);
  		break;
  	case SIOCSIFFLAGS:
 +		mutex_lock(&mdev->state_lock);
  		if (dev->if_flags & IFF_UP) {
 -			if ((dev->if_drv_flags & IFF_DRV_RUNNING) == 0) {
 -				mutex_lock(&mdev->state_lock);
 +			if ((dev->if_drv_flags & IFF_DRV_RUNNING) == 0)
  				mlx4_en_start_port(dev);
 -				mutex_unlock(&mdev->state_lock);
 -			} else
 +			else
  				mlx4_en_set_multicast(dev);
  		} else {
 -			mutex_lock(&mdev->state_lock);
  			if (dev->if_drv_flags & IFF_DRV_RUNNING) {
  				mlx4_en_stop_port(dev);
  				if_link_state_change(dev, LINK_STATE_DOWN);
  			}
 -			mutex_unlock(&mdev->state_lock);
  		}
 +		mutex_unlock(&mdev->state_lock);
  		break;
  	case SIOCADDMULTI:
  	case SIOCDELMULTI:
 +		mutex_lock(&mdev->state_lock);
  		mlx4_en_set_multicast(dev);
 +		mutex_unlock(&mdev->state_lock);
  		break;
  	case SIOCSIFMEDIA:
  	case SIOCGIFMEDIA:
  		error = ifmedia_ioctl(dev, ifr, &priv->media, command);
  		break;
  	case SIOCSIFCAP:
 +		mutex_lock(&mdev->state_lock);
  		mask = ifr->ifr_reqcap ^ dev->if_capenable;
  		if (mask & IFCAP_HWCSUM)
  			dev->if_capenable ^= IFCAP_HWCSUM;
 @@ -1130,7 +1140,8 @@ static int mlx4_en_ioctl(struct ifnet *d
  		if (mask & IFCAP_WOL_MAGIC)
  			dev->if_capenable ^= IFCAP_WOL_MAGIC;
  		if (dev->if_drv_flags & IFF_DRV_RUNNING)
 -			mlx4_en_init(priv);
 +			mlx4_en_init_locked(priv);
 +		mutex_unlock(&mdev->state_lock);
  		VLAN_CAPABILITIES(dev);
  		break;
  	default:
 
 Modified: releng/9.2/sys/ofed/drivers/net/mlx4/en_tx.c
 ==============================================================================
 --- releng/9.2/sys/ofed/drivers/net/mlx4/en_tx.c	Tue Aug  6 19:23:57 2013	(r254006)
 +++ releng/9.2/sys/ofed/drivers/net/mlx4/en_tx.c	Tue Aug  6 20:04:44 2013	(r254007)
 @@ -780,8 +780,12 @@ retry:
  	tx_desc->ctrl.srcrb_flags = cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE |
  						MLX4_WQE_CTRL_SOLICITED);
  	if (mb->m_pkthdr.csum_flags & (CSUM_IP|CSUM_TCP|CSUM_UDP)) {
 -		tx_desc->ctrl.srcrb_flags |= cpu_to_be32(MLX4_WQE_CTRL_IP_CSUM |
 -							 MLX4_WQE_CTRL_TCP_UDP_CSUM);
 +		if (mb->m_pkthdr.csum_flags & CSUM_IP)
 +			tx_desc->ctrl.srcrb_flags |=
 +			    cpu_to_be32(MLX4_WQE_CTRL_IP_CSUM);
 +		if (mb->m_pkthdr.csum_flags & (CSUM_TCP|CSUM_UDP))
 +			tx_desc->ctrl.srcrb_flags |=
 +			    cpu_to_be32(MLX4_WQE_CTRL_TCP_UDP_CSUM);
  		priv->port_stats.tx_chksum_offload++;
  	}
  
 
 Modified: releng/9.2/sys/ofed/drivers/net/mlx4/main.c
 ==============================================================================
 --- releng/9.2/sys/ofed/drivers/net/mlx4/main.c	Tue Aug  6 19:23:57 2013	(r254006)
 +++ releng/9.2/sys/ofed/drivers/net/mlx4/main.c	Tue Aug  6 20:04:44 2013	(r254007)
 @@ -209,9 +209,6 @@ int mlx4_check_port_params(struct mlx4_d
  					 "on this HCA, aborting.\n");
  				return -EINVAL;
  			}
 -			if (port_type[i] == MLX4_PORT_TYPE_ETH &&
 -			    port_type[i + 1] == MLX4_PORT_TYPE_IB)
 -				return -EINVAL;
  		}
  	}
  
 
 Modified: releng/9.2/sys/ofed/include/linux/sysfs.h
 ==============================================================================
 --- releng/9.2/sys/ofed/include/linux/sysfs.h	Tue Aug  6 19:23:57 2013	(r254006)
 +++ releng/9.2/sys/ofed/include/linux/sysfs.h	Tue Aug  6 20:04:44 2013	(r254007)
 @@ -75,39 +75,42 @@ sysctl_handle_attr(SYSCTL_HANDLER_ARGS)
  	struct kobject *kobj;
  	struct attribute *attr;
  	const struct sysfs_ops *ops;
 -	void *buf;
 +	char *buf;
  	int error;
  	ssize_t len;
  
  	kobj = arg1;
  	attr = (struct attribute *)arg2;
 -	buf = (void *)get_zeroed_page(GFP_KERNEL);
 -	len = 1;	/* Copy out a NULL byte at least. */
  	if (kobj->ktype == NULL || kobj->ktype->sysfs_ops == NULL)
  		return (ENODEV);
 -	ops = kobj->ktype->sysfs_ops;
 +	buf = (char *)get_zeroed_page(GFP_KERNEL);
  	if (buf == NULL)
  		return (ENOMEM);
 +	ops = kobj->ktype->sysfs_ops;
  	if (ops->show) {
  		len = ops->show(kobj, attr, buf);
  		/*
 -		 * It's valid not to have a 'show' so we just return 1 byte
 -		 * of NULL.
 +		 * It's valid to not have a 'show' so just return an
 +		 * empty string.
  	 	 */
  		if (len < 0) {
  			error = -len;
 -			len = 1;
  			if (error != EIO)
  				goto out;
  		}
 +
 +		/* Trim trailing newline. */
 +		len--;
 +		buf[len] = '\0';
  	}
 -	error = SYSCTL_OUT(req, buf, len);
 -	if (error || !req->newptr || ops->store == NULL)
 -		goto out;
 -	error = SYSCTL_IN(req, buf, PAGE_SIZE);
 -	if (error)
 +
 +	/* Leave one trailing byte to append a newline. */
 +	error = sysctl_handle_string(oidp, buf, PAGE_SIZE - 1, req);
 +	if (error != 0 || req->newptr == NULL || ops->store == NULL)
  		goto out;
 -	len = ops->store(kobj, attr, buf, req->newlen);
 +	len = strlcat(buf, "\n", PAGE_SIZE);
 +	KASSERT(len < PAGE_SIZE, ("new attribute truncated"));
 +	len = ops->store(kobj, attr, buf, len);
  	if (len < 0)
  		error = -len;
  out:
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: jhb 
State-Changed-When: Wed Aug 7 18:01:16 UTC 2013 
State-Changed-Why:  
Merged to 9 and 9.2. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=174213 
>Unformatted:
