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/22/2007 11:55:02
The following reply was made to PR kern/36669; it has been noted by GNATS.

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

 On Sun Jul 22 2007 at 12:48:36 +0100, Matthias Scheler wrote:
 > Can you create a patch against "netbsd-4", please? This machine is my
 > server which quite a few threaded daemons that wouldn't work with
 > a current kernel on top of 4.0_BETA2 userland.
 
 Here.  Remeber to start with a clean netbsd-4 procfs_vnops.c ;)
 
 Index: procfs_vnops.c
 ===================================================================
 RCS file: /cvsroot/src/sys/miscfs/procfs/procfs_vnops.c,v
 retrieving revision 1.140.2.5
 diff -p -u -r1.140.2.5 procfs_vnops.c
 --- procfs_vnops.c	31 Mar 2007 16:13:18 -0000	1.140.2.5
 +++ procfs_vnops.c	22 Jul 2007 11:53:08 -0000
 @@ -537,6 +537,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;
  	if (vp == NULL || getcwd_common(vp, rvp, bp ? &bp : NULL, path,
 @@ -1451,11 +1463,20 @@ procfs_readlink(v)
  			}
  			bp = path + MAXPATHLEN;
  			*--bp = '\0';
 -			vp = curproc->p_cwdi->cwdi_rdir;
 -			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, proc_representative_lwp(pown));
  			if (error) {
  				free(path, M_TEMP);
 
 -- 
 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"