Module Name:    src
Committed By:   rmind
Date:           Thu Nov 17 22:41:55 UTC 2011

Modified Files:
        src/sys/kern: kern_event.c

Log Message:
kqueue_register: avoid calling fd_getfile() with filedesc_t::fd_lock held.

Fixes PR/45479 by KOGULE Ryo.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sys/kern/kern_event.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/kern_event.c
diff -u src/sys/kern/kern_event.c:1.73 src/sys/kern/kern_event.c:1.74
--- src/sys/kern/kern_event.c:1.73	Thu Nov 17 01:19:37 2011
+++ src/sys/kern/kern_event.c	Thu Nov 17 22:41:55 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_event.c,v 1.73 2011/11/17 01:19:37 christos Exp $	*/
+/*	$NetBSD: kern_event.c,v 1.74 2011/11/17 22:41:55 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.73 2011/11/17 01:19:37 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.74 2011/11/17 22:41:55 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -916,18 +916,16 @@ kqueue_register(struct kqueue *kq, struc
 		return (EINVAL);
 	}
 
- 	mutex_enter(&fdp->fd_lock);
-
 	/* search if knote already exists */
 	if (kfilter->filtops->f_isfd) {
 		/* monitoring a file descriptor */
 		fd = kev->ident;
 		if ((fp = fd_getfile(fd)) == NULL) {
-		 	mutex_exit(&fdp->fd_lock);
 			rw_exit(&kqueue_filter_lock);
 			kmem_free(newkn, sizeof(*newkn));
 			return EBADF;
 		}
+		mutex_enter(&fdp->fd_lock);
 		ff = fdp->fd_dt->dt_ff[fd];
 		if (fd <= fdp->fd_lastkqfile) {
 			SLIST_FOREACH(kn, &ff->ff_knlist, kn_link) {
@@ -941,6 +939,7 @@ kqueue_register(struct kqueue *kq, struc
 		 * not monitoring a file descriptor, so
 		 * lookup knotes in internal hash table
 		 */
+		mutex_enter(&fdp->fd_lock);
 		if (fdp->fd_knhashmask != 0) {
 			list = &fdp->fd_knhash[
 			    KN_HASH((u_long)kev->ident, fdp->fd_knhashmask)];

Reply via email to