From nobody@FreeBSD.org  Tue Oct 29 01:54:27 2002
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 26A3D37B401
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 29 Oct 2002 01:54:27 -0800 (PST)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id DC0E743E6E
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 29 Oct 2002 01:54:26 -0800 (PST)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.6/8.12.6) with ESMTP id g9T9sQ7R050012
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 29 Oct 2002 01:54:26 -0800 (PST)
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.6/8.12.6/Submit) id g9T9sQ9P050011;
	Tue, 29 Oct 2002 01:54:26 -0800 (PST)
Message-Id: <200210290954.g9T9sQ9P050011@www.freebsd.org>
Date: Tue, 29 Oct 2002 01:54:26 -0800 (PST)
From: Neal Fachan <neal@isilon.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: bug in lockmgr
X-Send-Pr-Version: www-1.0

>Number:         44585
>Category:       kern
>Synopsis:       bug in lockmgr
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 29 02:00:03 PST 2002
>Closed-Date:    Fri Oct 10 23:33:52 PDT 2003
>Last-Modified:  Fri Oct 10 23:33:52 PDT 2003
>Originator:     Neal Fachan
>Release:        5.0-CURRENT from a few months back
>Organization:
Isilon Systems, Inc.
>Environment:
>Description:
Imagine three threads.

Threads 1 and 2 get shared lock:

lk_sharecount = 2;
lk_flags = LK_SHARE_NONZERO;

Thread 3 goes to get exclusive. It gets through the first acquire
without sleeping (LK_HAVE_EXCL | LK_WANT_EXCL). It then sets
LK_WANT_EXCL and then sleeps on the second acquire:

lk_sharecount = 2;
lk_flags = LK_WANT_EXCL | LK_SHARE_NONZERO;
thread 3 sleeping on: !(LK_WANT_UPGRADE | LK_SHARE_NONZERO);

Thread 2 goes to sleep waiting on an upgrade:

lk_sharecount = 1;
lk_flags = LK_WANT_EXCL | LK_WANT_UPGRADE | LK_SHARE_NONZERO;
thread 2 sleeping on: !(LK_SHARE_NONZERO);
thread 3 sleeping on: !(LK_SHARE_NONZERO | LK_WANT_UPGRADE);

Thread 1 unlocks shared lock:

lk_sharecount = 0;
lk_flags = LK_WANT_EXCL | LK_WANT_UPGRADE;
thread 2 sleeping on: !(LK_SHARE_NONZERO);
thread 3 sleeping on: !(LK_SHARE_NONZERO | LK_WANT_UPGRADE);

Thread 2 wakes up first, and takes exclusive lock:

lk_exclusivecount = 1;
lk_flags = LK_WANT_EXCL | LK_HAVE_EXCL;
thread 3 sleeping on: !(LK_SHARE_NONZERO | LK_WANT_UPGRADE);

Thread 3 wakes up second, and also tries to take exclusive lock:

lk_exclusivecount = 2;  /* !!! big trouble for moose and squirrel */
lk_flags = LK_HAVE_EXCL;


>How-To-Repeat:
      
>Fix:
The fix is to put LK_HAVE_EXCL in the second acquire of the LK_EXCLUSIVE
path: change acquire(LK_WANT_UPGRADE | LK_SHARE_NONZERO) to
acquire(LK_HAS_EXCL | LK_WANT_UPGRADE | LK_SHARE_NONZERO).
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->feedback 
State-Changed-By: schweikh 
State-Changed-When: Wed Aug 6 12:16:27 PDT 2003 
State-Changed-Why:  
Is this still a problem with a recent -current? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=44585 
State-Changed-From-To: feedback->closed 
State-Changed-By: kris 
State-Changed-When: Fri Oct 10 23:33:36 PDT 2003 
State-Changed-Why:  
Feedback timeout 

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