From nobody@FreeBSD.org  Fri Sep 21 06:47:59 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 767CD1065670
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 21 Sep 2012 06:47:59 +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 48D9D8FC18
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 21 Sep 2012 06:47:59 +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 q8L6lxRg003329
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 21 Sep 2012 06:47:59 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id q8L6lxSI003328;
	Fri, 21 Sep 2012 06:47:59 GMT
	(envelope-from nobody)
Message-Id: <201209210647.q8L6lxSI003328@red.freebsd.org>
Date: Fri, 21 Sep 2012 06:47:59 GMT
From: Venkat Duvvuru <venkatduvvuru.ml@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Possible lock reversal and duplicate locks as reported by Witness
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         171838
>Category:       kern
>Synopsis:       [oce] [patch] Possible lock reversal and duplicate locks as reported by Witness
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jpaetzel
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Sep 21 06:50:07 UTC 2012
>Closed-Date:    Thu Feb 14 17:34:57 UTC 2013
>Last-Modified:  Thu Feb 14 17:40:00 UTC 2013
>Originator:     Venkat Duvvuru
>Release:        9.0-RELEASE
>Organization:
Emulex
>Environment:
FreeBSD root@xxx FreeBsd 9.0-RELEASE FreeBSD 9.0-RELEASE #12: Thu Aug 23 23:42:39 IST 2012     root@root@xxx FreeBsd:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
This patch is for Freebsd nic "oce" driver (http://svn.freebsd.org/base/head/sys/dev/oce/)

I am attaching a patch which fixes some issues which were reported by witness. Specifically,
- Calling mtx_init with same name causes WITNESS to report possible lock reversal and duplicate lock issues.
- release mtx_lock before invoking taskqueue_drain.

>How-To-Repeat:

>Fix:
Fix is attached in the form of patch.

Patch attached with submission follows:

Index: oce_if.c
===================================================================
--- oce_if.c	(revision 233768)
+++ oce_if.c	(working copy)
@@ -1816,6 +1816,9 @@
 }
 
 
+/* NOTE : This should only be called holding
+ *        DEVICE_LOCK.
+*/
 static void
 oce_if_deactivate(POCE_SOFTC sc)
 {
@@ -1845,11 +1848,17 @@
 	/* Stop intrs and finish any bottom halves pending */
 	oce_hw_intr_disable(sc);
 
+    /* Since taskqueue_drain takes a Gaint Lock, We should not acquire
+       any other lock. So unlock device lock and require after
+       completing taskqueue_drain.
+    */
+    UNLOCK(&sc->dev_lock);
 	for (i = 0; i < sc->intr_count; i++) {
 		if (sc->intrs[i].tq != NULL) {
 			taskqueue_drain(sc->intrs[i].tq, &sc->intrs[i].task);
 		}
 	}
+    LOCK(&sc->dev_lock);
 
 	/* Delete RX queue in card with flush param */
 	oce_stop_rx(sc);
Index: oce_if.h
===================================================================
--- oce_if.h	(revision 233768)
+++ oce_if.h	(working copy)
@@ -493,7 +493,7 @@
 #define LOCK_CREATE(lock, desc) 		{ \
 	strncpy((lock)->name, (desc), MAX_LOCK_DESC_LEN); \
 	(lock)->name[MAX_LOCK_DESC_LEN] = '\0'; \
-	mtx_init(&(lock)->mutex, (lock)->name, MTX_NETWORK_LOCK, MTX_DEF); \
+	mtx_init(&(lock)->mutex, (lock)->name, NULL, MTX_DEF); \
 }
 #define LOCK_DESTROY(lock) 			\
 		if (mtx_initialized(&(lock)->mutex))\


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sun Oct 14 23:30:23 UTC 2012 
Responsible-Changed-Why:  
Over to maintainer(s). 

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

From: Venkat Duvvuru <venkatduvvuru.ml@gmail.com>
To: FreeBSD-gnats-submit@freebsd.org, freebsd-bugs@freebsd.org
Cc:  
Subject: Re: misc/171838: Possible lock reversal and duplicate locks as
 reported by Witness
Date: Tue, 6 Nov 2012 13:10:43 +0530

 --14dae93411552656d804cdceb81f
 Content-Type: text/plain; charset=ISO-8859-1
 
 Could you please let me know when this will be pulled in?
 
 /Venkat
 
 On Fri, Sep 21, 2012 at 12:20 PM, <FreeBSD-gnats-submit@freebsd.org> wrote:
 
 > Thank you very much for your problem report.
 > It has the internal identification `misc/171838'.
 > The individual assigned to look at your
 > report is: freebsd-bugs.
 >
 > You can access the state of your problem report at any time
 > via this link:
 >
 > http://www.freebsd.org/cgi/query-pr.cgi?pr=171838
 >
 > >Category:       misc
 > >Responsible:    freebsd-bugs
 > >Synopsis:       Possible lock reversal and duplicate locks as reported by
 > Witness
 > >Arrival-Date:   Fri Sep 21 06:50:07 UTC 2012
 >
 
 --14dae93411552656d804cdceb81f
 Content-Type: text/html; charset=ISO-8859-1
 Content-Transfer-Encoding: quoted-printable
 
 Could you please let me know when this will be pulled in?<div><br></div><di=
 v>/Venkat<br><br><div class=3D"gmail_quote">On Fri, Sep 21, 2012 at 12:20 P=
 M,  <span dir=3D"ltr">&lt;<a href=3D"mailto:FreeBSD-gnats-submit@freebsd.or=
 g" target=3D"_blank">FreeBSD-gnats-submit@freebsd.org</a>&gt;</span> wrote:=
 <br>
 <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
 x #ccc solid;padding-left:1ex">Thank you very much for your problem report.=
 <br>
 It has the internal identification `misc/171838&#39;.<br>
 The individual assigned to look at your<br>
 report is: freebsd-bugs.<br>
 <br>
 You can access the state of your problem report at any time<br>
 via this link:<br>
 <br>
 <a href=3D"http://www.freebsd.org/cgi/query-pr.cgi?pr=3D171838" target=3D"_=
 blank">http://www.freebsd.org/cgi/query-pr.cgi?pr=3D171838</a><br>
 <br>
 &gt;Category: =A0 =A0 =A0 misc<br>
 &gt;Responsible: =A0 =A0freebsd-bugs<br>
 &gt;Synopsis: =A0 =A0 =A0 Possible lock reversal and duplicate locks as rep=
 orted by Witness<br>
 &gt;Arrival-Date: =A0 Fri Sep 21 06:50:07 UTC 2012<br>
 </blockquote></div><br></div>
 
 --14dae93411552656d804cdceb81f--
Responsible-Changed-From-To: freebsd-net->jpaetzel 
Responsible-Changed-By: jpaetzel 
Responsible-Changed-When: Wed Feb 13 21:25:24 UTC 2013 
Responsible-Changed-Why:  
I'll take this one. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=171838 
State-Changed-From-To: open->closed 
State-Changed-By: jpaetzel 
State-Changed-When: Thu Feb 14 17:34:38 UTC 2013 
State-Changed-Why:  
Committed, thanks! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/171838: commit references a PR
Date: Thu, 14 Feb 2013 17:34:27 +0000 (UTC)

 Author: jpaetzel
 Date: Thu Feb 14 17:34:17 2013
 New Revision: 246799
 URL: http://svnweb.freebsd.org/changeset/base/246799
 
 Log:
   Resolve issue that caused WITNESS to report LORs.
   
   PR:	kern/171838
   Submitted by:	Venkat Duvvuru <venkatduvvuru.ml@gmail.com>
   MFC after:	2 weeks
 
 Modified:
   head/sys/dev/oce/oce_if.c
   head/sys/dev/oce/oce_if.h
 
 Modified: head/sys/dev/oce/oce_if.c
 ==============================================================================
 --- head/sys/dev/oce/oce_if.c	Thu Feb 14 15:43:37 2013	(r246798)
 +++ head/sys/dev/oce/oce_if.c	Thu Feb 14 17:34:17 2013	(r246799)
 @@ -1817,6 +1817,9 @@ oce_local_timer(void *arg)
  }
  
  
 +/* NOTE : This should only be called holding
 + *        DEVICE_LOCK.
 +*/
  static void
  oce_if_deactivate(POCE_SOFTC sc)
  {
 @@ -1846,11 +1849,17 @@ oce_if_deactivate(POCE_SOFTC sc)
  	/* Stop intrs and finish any bottom halves pending */
  	oce_hw_intr_disable(sc);
  
 +    /* Since taskqueue_drain takes a Giant Lock, We should not acquire
 +       any other lock. So unlock device lock and require after
 +       completing taskqueue_drain.
 +    */
 +    UNLOCK(&sc->dev_lock);
  	for (i = 0; i < sc->intr_count; i++) {
  		if (sc->intrs[i].tq != NULL) {
  			taskqueue_drain(sc->intrs[i].tq, &sc->intrs[i].task);
  		}
  	}
 +    LOCK(&sc->dev_lock);
  
  	/* Delete RX queue in card with flush param */
  	oce_stop_rx(sc);
 
 Modified: head/sys/dev/oce/oce_if.h
 ==============================================================================
 --- head/sys/dev/oce/oce_if.h	Thu Feb 14 15:43:37 2013	(r246798)
 +++ head/sys/dev/oce/oce_if.h	Thu Feb 14 17:34:17 2013	(r246799)
 @@ -493,7 +493,7 @@ struct oce_lock {
  #define LOCK_CREATE(lock, desc) 		{ \
  	strncpy((lock)->name, (desc), MAX_LOCK_DESC_LEN); \
  	(lock)->name[MAX_LOCK_DESC_LEN] = '\0'; \
 -	mtx_init(&(lock)->mutex, (lock)->name, MTX_NETWORK_LOCK, MTX_DEF); \
 +	mtx_init(&(lock)->mutex, (lock)->name, NULL, MTX_DEF); \
  }
  #define LOCK_DESTROY(lock) 			\
  		if (mtx_initialized(&(lock)->mutex))\
 _______________________________________________
 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"
 
>Unformatted:
