From owner-freebsd-bugs Tue Oct 29 2: 0: 6 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 61EFF37B401 for ; Tue, 29 Oct 2002 02:00:04 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id AFA1543E6E for ; Tue, 29 Oct 2002 02:00:03 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id g9TA03x3078399 for ; Tue, 29 Oct 2002 02:00:03 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id g9TA03AK078398; Tue, 29 Oct 2002 02:00:03 -0800 (PST) Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 26A3D37B401 for ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-1.0 Subject: kern/44585: bug in lockmgr Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 44585 >Category: kern >Synopsis: bug in lockmgr >Confidential: no >Severity: serious >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Oct 29 02:00:03 PST 2002 >Closed-Date: >Last-Modified: >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: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message