Subject: Re: kern/36669: NetBSD 4.0_BETA2 crashes with "panic: lockmgr: locking against myself"
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: Antti Kantee <pooka@cs.hut.fi>
List: netbsd-bugs
Date: 07/21/2007 23:40:03
The following reply was made to PR kern/36669; it has been noted by GNATS.

From: Antti Kantee <pooka@cs.hut.fi>
To: gnats-bugs@netbsd.org, netbsd-bugs@netbsd.org, tron@zhadum.org.uk
Cc: 
Subject: Re: kern/36669: NetBSD 4.0_BETA2 crashes with "panic: lockmgr: locking against myself"
Date: Sun, 22 Jul 2007 02:35:01 +0300

 Had a discussion about this with David Holland and finally he suggested
 avoiding links to procfs itself.  This shouldn't hurt any real uses
 and makes the panics go away once again.  As a bonus, it's a totally
 procfs-contained approach.
 
 Index: procfs_vnops.c
 ===================================================================
 RCS file: /cvsroot/src/sys/miscfs/procfs/procfs_vnops.c,v
 retrieving revision 1.157
 diff -p -u -p -r1.157 procfs_vnops.c
 --- procfs_vnops.c	24 May 2007 00:37:41 -0000	1.157
 +++ procfs_vnops.c	21 Jul 2007 23:30:03 -0000
 @@ -584,6 +584,18 @@ procfs_dir(pfstype t, struct lwp *caller
  		return (NULL);
  	}
  
 +	/*
 +	 * XXX: this horrible kludge avoids locking panics when
 +	 * attempting to lookup links that point to within procfs
 +	 */
 +	if (vp != NULL && vp->v_tag == VT_PROCFS) {
 +		if (bpp) {
 +			*--bp = '/';
 +			*bpp = bp;
 +		}
 +		return vp;
 +	}
 +
  	if (rvp == NULL)
  		rvp = rootvnode;
  	mutex_exit(&target->p_mutex);	/* XXXSMP */
 @@ -1590,11 +1602,20 @@ procfs_readlink(v)
  			}
  			bp = path + MAXPATHLEN;
  			*--bp = '\0';
 -			vp = curproc->p_cwdi->cwdi_rdir;	/* XXXSMP */
 -			if (vp == NULL)
 -				vp = rootvnode;
 -			error = getcwd_common(vxp, vp, &bp, path,
 -			    MAXPATHLEN / 2, 0, curlwp);
 +
 +			/*
 +			 * XXX: kludge to avoid locking against ourselves
 +			 * in getcwd()
 +			 */
 +			if (vxp->v_tag == VT_PROCFS) {
 +				*--bp = '/';
 +			} else {
 +				vp = curproc->p_cwdi->cwdi_rdir; /* XXXSMP */
 +				if (vp == NULL)
 +					vp = rootvnode;
 +				error = getcwd_common(vxp, vp, &bp, path,
 +				    MAXPATHLEN / 2, 0, curlwp);
 +			}
  			FILE_UNUSE(fp, curlwp);
  			if (error)
  				break;
 
 -- 
 Antti Kantee <pooka@iki.fi>                     Of course he runs NetBSD
 http://www.iki.fi/pooka/                          http://www.NetBSD.org/
     "la qualité la plus indispensable du cuisinier est l'exactitude"