Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern call f_touch with kq_lock held, and without KERNEL_...



details:   https://anonhg.NetBSD.org/src/rev/29920928b080
branches:  trunk
changeset: 958970:29920928b080
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Tue Jan 26 19:09:18 2021 +0000

description:
call f_touch with kq_lock held, and without KERNEL_LOCK() - for this
adjust EVFILT_USER, which is the only filter actually using that hook

kqueue_scan() now doesn't need to exit/enter the kq_lock when calling
f_touch, which removes another possible race

part of PR kern/50094

diffstat:

 sys/kern/kern_event.c |  17 ++++++-----------
 1 files changed, 6 insertions(+), 11 deletions(-)

diffs (68 lines):

diff -r 97b002e6e9eb -r 29920928b080 sys/kern/kern_event.c
--- a/sys/kern/kern_event.c     Tue Jan 26 18:38:57 2021 +0000
+++ b/sys/kern/kern_event.c     Tue Jan 26 19:09:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_event.c,v 1.115 2021/01/25 19:57:05 jdolecek Exp $        */
+/*     $NetBSD: kern_event.c,v 1.116 2021/01/26 19:09:18 jdolecek Exp $        */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.115 2021/01/25 19:57:05 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.116 2021/01/26 19:09:18 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -838,7 +838,8 @@
        struct kqueue *kq = kn->kn_kq;
        int ffctrl;
 
-       mutex_spin_enter(&kq->kq_lock);
+       KASSERT(mutex_owned(&kq->kq_lock));
+
        switch (type) {
        case EVENT_REGISTER:
                if (kev->fflags & NOTE_TRIGGER)
@@ -889,7 +890,6 @@
                panic("filt_usertouch() - invalid type (%ld)", type);
                break;
        }
-       mutex_spin_exit(&kq->kq_lock);
 }
 
 /*
@@ -925,7 +925,6 @@
        .f_attach = NULL,
        .f_detach = filt_seltruedetach,
        .f_event = filt_seltrue,
-       .f_touch = NULL,
 };
 
 int
@@ -1276,9 +1275,9 @@
        kn->kn_kevent.udata = kev->udata;
        KASSERT(kn->kn_fop != NULL);
        if (!kn->kn_fop->f_isfd && kn->kn_fop->f_touch != NULL) {
-               KERNEL_LOCK(1, NULL);                   /* XXXSMP */
+               mutex_spin_enter(&kq->kq_lock);
                (*kn->kn_fop->f_touch)(kn, kev, EVENT_REGISTER);
-               KERNEL_UNLOCK_ONE(NULL);                /* XXXSMP */
+               mutex_spin_exit(&kq->kq_lock);
        } else {
                kn->kn_sfflags = kev->fflags;
                kn->kn_sdata = kev->data;
@@ -1529,11 +1528,7 @@
                                kn->kn_fop->f_touch != NULL);
                /* XXXAD should be got from f_event if !oneshot. */
                if (touch) {
-                       mutex_spin_exit(&kq->kq_lock);
-                       KERNEL_LOCK(1, NULL);           /* XXXSMP */
                        (*kn->kn_fop->f_touch)(kn, kevp, EVENT_PROCESS);
-                       KERNEL_UNLOCK_ONE(NULL);        /* XXXSMP */
-                       mutex_spin_enter(&kq->kq_lock);
                } else {
                        *kevp = kn->kn_kevent;
                }



Home | Main Index | Thread Index | Old Index