Re: LOR: kern_exec.c and vfs_cache.c

From: Kostik Belousov <kostikbel_at_gmail.com>
Date: Sat, 5 Sep 2009 22:41:43 +0300
On Sat, Sep 05, 2009 at 07:59:13PM +0100, Bruce Cran wrote:
> I got this LOR on 8.0-BETA3 when running pmcstat:
> 
> lock order reversal:
>  1st 0xc55716a0 ufs (ufs) _at_ /usr/src/sys/kern/kern_exec.c:570
>  2nd 0xc98f5a2c filedesc structure (filedesc structure)
> _at_ /usr/src/sys/kern/vfs_cache.c:999 KDB: stack backtrace:
> db_trace_self_wrapper(c0c6be4a,e6b5494c,c08bd7f5,c08ae67b,c0c6ed1d,...)
> at db_trace_self_wrapper+0x26
> kdb_backtrace(c08ae67b,c0c6ed1d,c452f500,c452c1d0,e6b549a8,...) at
> kdb_backtrace+0x29
> _witness_debugger(c0c6ed1d,c98f5a2c,c0c638c6,c452c1d0,c0c74e88,...) at
> _witness_debugger+0x25
> witness_checkorder(c98f5a2c,1,c0c74e88,3e7,0,...) at
> witness_checkorder+0x839
> _sx_slock(c98f5a2c,0,c0c74e88,3e7,c497a6c0,...) at _sx_slock+0x85
> vn_fullpath(c497a6c0,c5571648,e6b54aa4,e6b54aa0,0,...) at
> vn_fullpath+0x74 pmc_getfilename(c0c60fc0,3,c497a6c0,e6b54a60,246,...)
> at pmc_getfilename+0x2e
> pmc_hook_handler(c497a6c0,1,e6b54c1c,318,c0c90edb,...) at
> pmc_hook_handler+0x279
> kern_execve(c497a6c0,e6b54c58,0,283052a8,28305348,e164d000,e164d000,e164d020,e164d485,e168d000,3fb7b,3,24,0)
> at kern_execve+0xe1c execve(c497a6c0,e6b54cfc,c,c497a6c0,c0d4e474,...)
> at execve+0x4c syscall(e6b54d38) at syscall+0x2a3 Xint0x80_syscall() at
> Xint0x80_syscall+0x20 --- syscall (59, FreeBSD ELF32, execve), eip =
> 0x28173eaf, esp = 0xbfbfe34c, ebp = 0xbfbfe378 ---

The following should fix the LOR and make vfs_mark_atime more resistent
to the supplied doomed vnode.

diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index e770d07..a90968f 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
_at__at_ -786,10 +786,12 _at__at_ interpret:
 	 */
 	if (PMC_SYSTEM_SAMPLING_ACTIVE() || PMC_PROC_IS_USING_PMCS(p)) {
 		PROC_UNLOCK(p);
+		VOP_UNLOCK(imgp->vp, 0);
 		pe.pm_credentialschanged = credential_changing;
 		pe.pm_entryaddr = imgp->entry_addr;
 
 		PMC_CALL_HOOK_X(td, PMC_FN_PROCESS_EXEC, (void *) &pe);
+		vn_lock(imgp->vp, LK_EXCLUSIVE | LK_RETRY);
 	} else
 		PROC_UNLOCK(p);
 #else  /* !HWPMC_HOOKS */
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 3beb881..f3ec565 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
_at__at_ -4269,8 +4269,12 _at__at_ vfs_read_dirent(struct vop_readdir_args *ap, struct dirent *dp, off_t off)
 void
 vfs_mark_atime(struct vnode *vp, struct ucred *cred)
 {
+	struct mount *mp;
 
-	if ((vp->v_mount->mnt_flag & (MNT_NOATIME | MNT_RDONLY)) == 0)
+	mp = vp->v_mount;
+	VFS_ASSERT_GIANT(mp);
+	ASSERT_VOP_LOCKED(vp, "vfs_mark_atime");
+	if (mp != NULL && (mp->mnt_flag & (MNT_NOATIME | MNT_RDONLY)) == 0)
 		(void)VOP_MARKATIME(vp);
 }
 

Received on Sat Sep 05 2009 - 17:41:51 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:54 UTC