NetBSD Problem Report #796

From gnats  Sat Feb 11 15:47:44 1995
Received: from pain.lcs.mit.edu (pain.lcs.mit.edu [128.52.46.239]) by sun-lamp.cs.berkeley.edu (8.6.9/8.6.9) with ESMTP id PAA00367 for <gnats-bugs@sun-lamp.cs.berkeley.edu>; Sat, 11 Feb 1995 15:47:43 -0800
Message-Id: <199502112320.SAA02167@kolvir.blrc.ma.us>
Date: Sat, 11 Feb 1995 18:20:05 -0500
From: John Kohl <jtk@kolvir.blrc.ma.us>
Reply-To: jtk@kolvir.blrc.ma.us
To: gnats-bugs@NetBSD.ORG
Cc: jsp@sequent.com
Subject: another union fs locking violation
X-Send-Pr-Version: 3.2

>Number:         796
>Category:       kern
>Synopsis:       two processes can race and deadlock in the union fs code
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 11 15:50:03 +0000 1995
>Closed-Date:    Thu May 16 03:31:25 +0000 1996
>Last-Modified:  Thu May 16 03:31:44 +0000 1996
>Originator:     John Kohl
>Release:        1.0-current
>Organization:
NetBSD Kernel Hackers `R` Us
>Environment:

System: NetBSD kolvir 1.0A NetBSD 1.0A (KOLVIR) #31: Sat Feb 11 13:13:13 EST 1995 jtk@kolvir:/u1/NetBSD-current/src/sys/arch/i386/compile/KOLVIR i386

>Description:
I have two processes deadlocked waiting for the other to release a vnode lock.

Both processes are trying to allocate a cover vnode for the same
underlying directory.

Process A's stack looks like:

ufs_lock(topvnode)
vget(topvnode)
ufs_lookup()
union_lookup1()
union_lookup()		looking up ../../../../arch/sys/param.h
					    ^ parse ptr here
lookup()
namei()
...

Process B's stack looks like:
sleep()
union_allocvp()
union_lookup()		looking up /u1/NetBSD-current/src/sys/arch/i386
							      ^ parse ptr here
lookup()
namei()
...

Process B has the upper vnodes for both /u1/NetBSD-current/src/sys and
/u1/NetBSD-current/src/sys/arch locked.  It looks like it had just
looked up "arch" in sys and acquired it locked [via VOP_LOOKUP() in
union_lookup1()], and is now preparing to union-ize it, and waits on the
union node lock.

Process A has the union version of "arch" locked (since it's in the
lookup routine), and is trying to look up `..' in `arch', using
VOP_LOOKUP() on the upper layer.  It found `..' in the name cache, and
tried to do a vget() to lock it and claim it from any free list it might
be on.  vget tries to lock the UFS vnode.

>How-To-Repeat:
Run emacs and a kernel build at the same time.

>Fix:
You must always take union node/underlying node locks in the same order,
even when constructing such nodes.  The name cache is getting in the
way.

JSP, any ideas?
>Release-Note:
>Audit-Trail:

From: John Kohl <jtk@kolvir.blrc.ma.us>
To: gnats-bugs@NetBSD.ORG
Subject: Re: kern/796: another union fs locking violation
Date: Sat, 18 Feb 1995 23:28:17 -0500


 This patch seems to take care of the bug kern/796 (locking violation in
 union fs when doing `..').

 I did note that there seems to be another bug lurking in the existing
 code.  If union_lookup1() does mount-point chasing, then upon return the
 union node is locked but the uppervp is not locked--it was unlocked
 during the mount-chasing.  In such a case the UN_ULOCK flag would still
 be set on the union vnode.  In the case of `..' processing, this patch
 *will* relock the uppervp, but what about the non-.. case?  Should
 uppervp be locked again in all cases if it's not the same as the the
 upperdvp returned by union_lookup1()?

 ===================================================================
 RCS file: RCS/union_vnops.c,v
 retrieving revision 1.3
 diff -ubw -r1.3 union_vnops.c
 --- 1.3	1995/01/30 02:49:40
 +++ union_vnops.c	1995/02/19 04:08:36
 @@ -201,8 +201,40 @@
  	 */
  	if (upperdvp != NULLVP) {
  		FIXUP(dun);
 +		/*
 +		 * If we're doing `..' in the underlying filesystem,
 +		 * we must drop our lock on the union node before
 +		 * going up the tree in the lower file system--if we block
 +		 * on the lowervp lock, and that's held by someone else
 +		 * coming down the tree and who's waiting for our lock,
 +		 * we would be hosed.
 +		 */
 +		if (cnp->cn_flags & ISDOTDOT) {
 +		    /* retain lock on underlying VP: */
 +		    dun->un_flags |= UN_KLOCK;
 +		    VOP_UNLOCK(dvp);
 +		}
  		uerror = union_lookup1(um->um_uppervp, &upperdvp,
  					&uppervp, cnp);
 +		if (cnp->cn_flags & ISDOTDOT) {
 +		    if (dun->un_uppervp == upperdvp) {
 +			/*
 +			 * we got the underlying bugger back locked...
 +			 * now take back the union node lock.  Since we
 +			 * hold the uppervp lock, we can diddle union
 +			 * locking flags at will. :)
 +			 */
 +			dun->un_flags |= UN_ULOCK;
 +		    }
 +		    /*
 +		     * if upperdvp got swapped out, it means we did
 +		     * some mount point magic, and we do not have
 +		     * dun->un_uppervp locked currently--so we get it
 +		     * locked here (don't set the UN_ULOCK flag).
 +		     */
 +		    VOP_LOCK(dvp);
 +		}
 +
  		/*if (uppervp == upperdvp)
  			dun->un_flags |= UN_KLOCK;*/

 @@ -248,6 +280,12 @@
  			saved_cred = cnp->cn_cred;
  			cnp->cn_cred = um->um_cred;
  		}
 +		/*
 +		 * we shouldn't have to worry about locking interactions
 +		 * between the lower layer and our union layer (w.r.t.
 +		 * `..' processing) because we don't futz with lowervp
 +		 * locks in the union-node instantiation code path.
 +		 */
  		lerror = union_lookup1(um->um_lowervp, &lowerdvp,
  				&lowervp, cnp);
  		if (um->um_op == UNMNT_BELOW)
State-Changed-From-To: open->closed 
State-Changed-By: jtk 
State-Changed-When: Wed May 15 23:31:25 EDT 1996 
State-Changed-Why:  
Patches applied to -current 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.