Below is a mostly mechanical patch that wraps the SLIST head of knotes
inside another struct. The patch also introduces functions for adding
and removing knotes from these lists.

My intent is to extend the list struct so that the system can assert
when the knote list should be locked. The idea is that when you invoke
KNOTE(), you should hold the lock that serializes access to the knote
list. Combined with NOTE_SUBMIT as a signal to f_event to skip locking,
this should keep the locking patterns tractable.

OK?

Index: arch/arm64/dev/apm.c
===================================================================
RCS file: src/sys/arch/arm64/dev/apm.c,v
retrieving revision 1.3
diff -u -p -r1.3 apm.c
--- arch/arm64/dev/apm.c        20 Feb 2020 16:56:51 -0000      1.3
+++ arch/arm64/dev/apm.c        4 Apr 2020 13:25:56 -0000
@@ -271,7 +271,7 @@ filt_apmrdetach(struct knote *kn)
 {
        struct apm_softc *sc = (struct apm_softc *)kn->kn_hook;
 
-       SLIST_REMOVE(&sc->sc_note, kn, knote, kn_selnext);
+       klist_remove(&sc->sc_note, kn);
 }
 
 int
@@ -303,7 +303,7 @@ apmkqfilter(dev_t dev, struct knote *kn)
        }
 
        kn->kn_hook = (caddr_t)sc;
-       SLIST_INSERT_HEAD(&sc->sc_note, kn, kn_selnext);
+       klist_insert(&sc->sc_note, kn);
 
        return (0);
 }
Index: arch/i386/i386/apm.c
===================================================================
RCS file: src/sys/arch/i386/i386/apm.c,v
retrieving revision 1.122
diff -u -p -r1.122 apm.c
--- arch/i386/i386/apm.c        20 Feb 2020 16:56:51 -0000      1.122
+++ arch/i386/i386/apm.c        4 Apr 2020 13:25:57 -0000
@@ -1118,7 +1118,7 @@ filt_apmrdetach(struct knote *kn)
        struct apm_softc *sc = (struct apm_softc *)kn->kn_hook;
 
        rw_enter_write(&sc->sc_lock);
-       SLIST_REMOVE(&sc->sc_note, kn, knote, kn_selnext);
+       klist_remove(&sc->sc_note, kn);
        rw_exit_write(&sc->sc_lock);
 }
 
@@ -1152,7 +1152,7 @@ apmkqfilter(dev_t dev, struct knote *kn)
        kn->kn_hook = (caddr_t)sc;
 
        rw_enter_write(&sc->sc_lock);
-       SLIST_INSERT_HEAD(&sc->sc_note, kn, kn_selnext);
+       klist_insert(&sc->sc_note, kn);
        rw_exit_write(&sc->sc_lock);
        return (0);
 }
Index: arch/loongson/dev/apm.c
===================================================================
RCS file: src/sys/arch/loongson/dev/apm.c,v
retrieving revision 1.35
diff -u -p -r1.35 apm.c
--- arch/loongson/dev/apm.c     20 Feb 2020 16:56:51 -0000      1.35
+++ arch/loongson/dev/apm.c     4 Apr 2020 13:25:58 -0000
@@ -292,7 +292,7 @@ filt_apmrdetach(struct knote *kn)
 {
        struct apm_softc *sc = (struct apm_softc *)kn->kn_hook;
 
-       SLIST_REMOVE(&sc->sc_note, kn, knote, kn_selnext);
+       klist_remove(&sc->sc_note, kn);
 }
 
 int
@@ -324,7 +324,7 @@ apmkqfilter(dev_t dev, struct knote *kn)
        }
 
        kn->kn_hook = (caddr_t)sc;
-       SLIST_INSERT_HEAD(&sc->sc_note, kn, kn_selnext);
+       klist_insert(&sc->sc_note, kn);
 
        return (0);
 }
Index: arch/macppc/dev/apm.c
===================================================================
RCS file: src/sys/arch/macppc/dev/apm.c,v
retrieving revision 1.21
diff -u -p -r1.21 apm.c
--- arch/macppc/dev/apm.c       20 Feb 2020 16:56:51 -0000      1.21
+++ arch/macppc/dev/apm.c       4 Apr 2020 13:25:58 -0000
@@ -305,7 +305,7 @@ filt_apmrdetach(struct knote *kn)
 {
        struct apm_softc *sc = (struct apm_softc *)kn->kn_hook;
 
-       SLIST_REMOVE(&sc->sc_note, kn, knote, kn_selnext);
+       klist_remove(&sc->sc_note, kn);
 }
 
 int
@@ -337,7 +337,7 @@ apmkqfilter(dev_t dev, struct knote *kn)
        }
 
        kn->kn_hook = (caddr_t)sc;
-       SLIST_INSERT_HEAD(&sc->sc_note, kn, kn_selnext);
+       klist_insert(&sc->sc_note, kn);
 
        return (0);
 }
Index: dev/hotplug.c
===================================================================
RCS file: src/sys/dev/hotplug.c,v
retrieving revision 1.19
diff -u -p -r1.19 hotplug.c
--- dev/hotplug.c       20 Feb 2020 16:56:52 -0000      1.19
+++ dev/hotplug.c       4 Apr 2020 13:25:58 -0000
@@ -211,7 +211,7 @@ hotplugkqfilter(dev_t dev, struct knote 
        }
 
        s = splbio();
-       SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+       klist_insert(klist, kn);
        splx(s);
        return (0);
 }
@@ -222,7 +222,7 @@ filt_hotplugrdetach(struct knote *kn)
        int s;
 
        s = splbio();
-       SLIST_REMOVE(&hotplug_sel.si_note, kn, knote, kn_selnext);
+       klist_remove(&hotplug_sel.si_note, kn);
        splx(s);
 }
 
Index: dev/midi.c
===================================================================
RCS file: src/sys/dev/midi.c,v
retrieving revision 1.46
diff -u -p -r1.46 midi.c
--- dev/midi.c  20 Feb 2020 16:56:52 -0000      1.46
+++ dev/midi.c  4 Apr 2020 13:25:58 -0000
@@ -363,7 +363,7 @@ midikqfilter(dev_t dev, struct knote *kn
        kn->kn_hook = (void *)sc;
 
        mtx_enter(&audio_lock);
-       SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+       klist_insert(klist, kn);
        mtx_leave(&audio_lock);
 done:
        device_unref(&sc->dev);
@@ -376,7 +376,7 @@ filt_midirdetach(struct knote *kn)
        struct midi_softc *sc = (struct midi_softc *)kn->kn_hook;
 
        mtx_enter(&audio_lock);
-       SLIST_REMOVE(&sc->rsel.si_note, kn, knote, kn_selnext);
+       klist_remove(&sc->rsel.si_note, kn);
        mtx_leave(&audio_lock);
 }
 
@@ -399,7 +399,7 @@ filt_midiwdetach(struct knote *kn)
        struct midi_softc *sc = (struct midi_softc *)kn->kn_hook;
 
        mtx_enter(&audio_lock);
-       SLIST_REMOVE(&sc->wsel.si_note, kn, knote, kn_selnext);
+       klist_remove(&sc->wsel.si_note, kn);
        mtx_leave(&audio_lock);
 }
 
Index: dev/vscsi.c
===================================================================
RCS file: src/sys/dev/vscsi.c,v
retrieving revision 1.48
diff -u -p -r1.48 vscsi.c
--- dev/vscsi.c 20 Feb 2020 16:56:52 -0000      1.48
+++ dev/vscsi.c 4 Apr 2020 13:25:58 -0000
@@ -576,7 +576,7 @@ vscsikqfilter(dev_t dev, struct knote *k
        kn->kn_hook = sc;
 
        mtx_enter(&sc->sc_sel_mtx);
-       SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+       klist_insert(klist, kn);
        mtx_leave(&sc->sc_sel_mtx);
 
        /* device ref is given to the knote in the klist */
@@ -591,7 +591,7 @@ filt_vscsidetach(struct knote *kn)
        struct klist *klist = &sc->sc_sel.si_note;
  
        mtx_enter(&sc->sc_sel_mtx);
-       SLIST_REMOVE(klist, kn, knote, kn_selnext);
+       klist_remove(klist, kn);
        mtx_leave(&sc->sc_sel_mtx);
 
        device_unref(&sc->sc_dev);
Index: dev/acpi/acpi.c
===================================================================
RCS file: src/sys/dev/acpi/acpi.c,v
retrieving revision 1.379
diff -u -p -r1.379 acpi.c
--- dev/acpi/acpi.c     3 Apr 2020 08:24:52 -0000       1.379
+++ dev/acpi/acpi.c     4 Apr 2020 13:25:58 -0000
@@ -3476,7 +3476,7 @@ acpi_filtdetach(struct knote *kn)
        int s;
 
        s = spltty();
-       SLIST_REMOVE(sc->sc_note, kn, knote, kn_selnext);
+       klist_remove(sc->sc_note, kn);
        splx(s);
 }
 
@@ -3510,7 +3510,7 @@ acpikqfilter(dev_t dev, struct knote *kn
        kn->kn_hook = sc;
 
        s = spltty();
-       SLIST_INSERT_HEAD(sc->sc_note, kn, kn_selnext);
+       klist_insert(sc->sc_note, kn);
        splx(s);
 
        return (0);
Index: dev/pci/drm/drm_drv.c
===================================================================
RCS file: src/sys/dev/pci/drm/drm_drv.c,v
retrieving revision 1.173
diff -u -p -r1.173 drm_drv.c
--- dev/pci/drm/drm_drv.c       4 Mar 2020 21:19:15 -0000       1.173
+++ dev/pci/drm/drm_drv.c       4 Apr 2020 13:25:58 -0000
@@ -472,7 +472,7 @@ filt_drmdetach(struct knote *kn)
        int s;
 
        s = spltty();
-       SLIST_REMOVE(&dev->note, kn, knote, kn_selnext);
+       klist_remove(&dev->note, kn);
        splx(s);
 }
 
@@ -512,7 +512,7 @@ drmkqfilter(dev_t kdev, struct knote *kn
        kn->kn_hook = dev;
 
        s = spltty();
-       SLIST_INSERT_HEAD(&dev->note, kn, kn_selnext);
+       klist_insert(&dev->note, kn);
        splx(s);
 
        return (0);
Index: dev/usb/ugen.c
===================================================================
RCS file: src/sys/dev/usb/ugen.c,v
retrieving revision 1.104
diff -u -p -r1.104 ugen.c
--- dev/usb/ugen.c      3 Apr 2020 08:24:53 -0000       1.104
+++ dev/usb/ugen.c      4 Apr 2020 13:25:59 -0000
@@ -1298,7 +1298,7 @@ filt_ugenrdetach(struct knote *kn)
        int s;
 
        s = splusb();
-       SLIST_REMOVE(&sce->rsel.si_note, kn, knote, kn_selnext);
+       klist_remove(&sce->rsel.si_note, kn);
        splx(s);
 }
 
@@ -1418,7 +1418,7 @@ ugenkqfilter(dev_t dev, struct knote *kn
        kn->kn_hook = (void *)sce;
 
        s = splusb();
-       SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+       klist_insert(klist, kn);
        splx(s);
 
        return (0);
Index: dev/usb/uhid.c
===================================================================
RCS file: src/sys/dev/usb/uhid.c,v
retrieving revision 1.78
diff -u -p -r1.78 uhid.c
--- dev/usb/uhid.c      3 Apr 2020 08:24:53 -0000       1.78
+++ dev/usb/uhid.c      4 Apr 2020 13:25:59 -0000
@@ -447,7 +447,7 @@ filt_uhidrdetach(struct knote *kn)
        int s;
 
        s = splusb();
-       SLIST_REMOVE(&sc->sc_rsel.si_note, kn, knote, kn_selnext);
+       klist_remove(&sc->sc_rsel.si_note, kn);
        splx(s);
 }
 
@@ -505,7 +505,7 @@ uhidkqfilter(dev_t dev, struct knote *kn
        kn->kn_hook = (void *)sc;
 
        s = splusb();
-       SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+       klist_insert(klist, kn);
        splx(s);
 
        return (0);
Index: dev/wscons/wsevent.c
===================================================================
RCS file: src/sys/dev/wscons/wsevent.c,v
retrieving revision 1.23
diff -u -p -r1.23 wsevent.c
--- dev/wscons/wsevent.c        20 Feb 2020 16:56:52 -0000      1.23
+++ dev/wscons/wsevent.c        4 Apr 2020 13:25:59 -0000
@@ -236,7 +236,7 @@ wsevent_kqfilter(struct wseventvar *ev, 
        kn->kn_hook = ev;
 
        s = splwsevent();
-       SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+       klist_insert(klist, kn);
        splx(s);
 
        return (0);
@@ -250,7 +250,7 @@ filt_wseventdetach(struct knote *kn)
        int s;
 
        s = splwsevent();
-       SLIST_REMOVE(klist, kn, knote, kn_selnext);
+       klist_remove(klist, kn);
        splx(s);
 }
 
Index: isofs/cd9660/cd9660_vnops.c
===================================================================
RCS file: src/sys/isofs/cd9660/cd9660_vnops.c,v
retrieving revision 1.82
diff -u -p -r1.82 cd9660_vnops.c
--- isofs/cd9660/cd9660_vnops.c 20 Feb 2020 16:56:52 -0000      1.82
+++ isofs/cd9660/cd9660_vnops.c 4 Apr 2020 13:25:59 -0000
@@ -1002,7 +1002,7 @@ cd9660_kqfilter(void *v)
 
        kn->kn_hook = (caddr_t)vp;
 
-       SLIST_INSERT_HEAD(&vp->v_selectinfo.si_note, kn, kn_selnext);
+       klist_insert(&vp->v_selectinfo.si_note, kn);
 
        return (0);
 }
@@ -1012,7 +1012,7 @@ filt_cd9660detach(struct knote *kn)
 {
        struct vnode *vp = (struct vnode *)kn->kn_hook;
 
-       SLIST_REMOVE(&vp->v_selectinfo.si_note, kn, knote, kn_selnext);
+       klist_remove(&vp->v_selectinfo.si_note, kn);
 }
 
 int
Index: kern/kern_event.c
===================================================================
RCS file: src/sys/kern/kern_event.c,v
retrieving revision 1.129
diff -u -p -r1.129 kern_event.c
--- kern/kern_event.c   2 Apr 2020 07:00:25 -0000       1.129
+++ kern/kern_event.c   4 Apr 2020 13:25:59 -0000
@@ -181,7 +181,8 @@ KQRELE(struct kqueue *kq)
                fdpunlock(fdp);
        }
 
-       free(kq->kq_knlist, M_KEVENT, kq->kq_knlistsize * sizeof(struct klist));
+       free(kq->kq_knlist, M_KEVENT, kq->kq_knlistsize *
+           sizeof(struct knlist));
        hashfree(kq->kq_knhash, KN_HASHSIZE, M_KEVENT);
        pool_put(&kqueue_pool, kq);
 }
@@ -212,7 +213,7 @@ kqueue_kqfilter(struct file *fp, struct 
                return (EINVAL);
 
        kn->kn_fop = &kqread_filtops;
-       SLIST_INSERT_HEAD(&kq->kq_sel.si_note, kn, kn_selnext);
+       klist_insert(&kq->kq_sel.si_note, kn);
        return (0);
 }
 
@@ -221,7 +222,7 @@ filt_kqdetach(struct knote *kn)
 {
        struct kqueue *kq = kn->kn_fp->f_data;
 
-       SLIST_REMOVE(&kq->kq_sel.si_note, kn, knote, kn_selnext);
+       klist_remove(&kq->kq_sel.si_note, kn);
 }
 
 int
@@ -266,7 +267,7 @@ filt_procattach(struct knote *kn)
        }
 
        /* XXX lock the proc here while adding to the list? */
-       SLIST_INSERT_HEAD(&pr->ps_klist, kn, kn_selnext);
+       klist_insert(&pr->ps_klist, kn);
 
        return (0);
 }
@@ -288,7 +289,7 @@ filt_procdetach(struct knote *kn)
                return;
 
        /* XXX locking?  this might modify another process. */
-       SLIST_REMOVE(&pr->ps_klist, kn, knote, kn_selnext);
+       klist_remove(&pr->ps_klist, kn);
 }
 
 int
@@ -320,7 +321,7 @@ filt_proc(struct knote *kn, long hint)
                splx(s);
                kn->kn_flags |= (EV_EOF | EV_ONESHOT);
                kn->kn_data = W_EXITCODE(pr->ps_xexit, pr->ps_xsig);
-               SLIST_REMOVE(&pr->ps_klist, kn, knote, kn_selnext);
+               klist_remove(&pr->ps_klist, kn);
                return (1);
        }
 
@@ -671,7 +672,7 @@ kqueue_register(struct kqueue *kq, struc
        const struct filterops *fops = NULL;
        struct file *fp = NULL;
        struct knote *kn = NULL, *newkn = NULL;
-       struct klist *list = NULL;
+       struct knlist *list = NULL;
        int s, error = 0;
 
        if (kev->filter < 0) {
@@ -1087,7 +1088,7 @@ kqueue_close(struct file *fp, struct pro
        kq->kq_state |= KQ_DYING;
        kqueue_wakeup(kq);
 
-       KASSERT(SLIST_EMPTY(&kq->kq_sel.si_note));
+       KASSERT(klist_empty(&kq->kq_sel.si_note));
        task_del(systq, &kq->kq_task);
 
        KQRELE(kq);
@@ -1117,7 +1118,7 @@ kqueue_wakeup(struct kqueue *kq)
        if (kq->kq_state & KQ_SEL) {
                kq->kq_state &= ~KQ_SEL;
                selwakeup(&kq->kq_sel);
-       } else if (!SLIST_EMPTY(&kq->kq_sel.si_note)) {
+       } else if (!klist_empty(&kq->kq_sel.si_note)) {
                /* Defer activation to avoid recursion. */
                KQREF(kq);
                if (!task_add(systq, &kq->kq_task))
@@ -1128,7 +1129,7 @@ kqueue_wakeup(struct kqueue *kq)
 static void
 kqueue_expand_hash(struct kqueue *kq)
 {
-       struct klist *hash;
+       struct knlist *hash;
        u_long hashmask;
 
        if (kq->kq_knhashmask == 0) {
@@ -1146,7 +1147,7 @@ kqueue_expand_hash(struct kqueue *kq)
 static void
 kqueue_expand_list(struct kqueue *kq, int fd)
 {
-       struct klist *list;
+       struct knlist *list;
        int size;
 
        if (kq->kq_knlistsize <= fd) {
@@ -1234,16 +1235,16 @@ knote(struct klist *list, long hint)
 {
        struct knote *kn, *kn0;
 
-       SLIST_FOREACH_SAFE(kn, list, kn_selnext, kn0)
+       SLIST_FOREACH_SAFE(kn, &list->kl_list, kn_selnext, kn0)
                if (kn->kn_fop->f_event(kn, hint))
                        knote_activate(kn);
 }
 
 /*
- * remove all knotes from a specified klist
+ * remove all knotes from a specified knlist
  */
 void
-knote_remove(struct proc *p, struct klist *list)
+knote_remove(struct proc *p, struct knlist *list)
 {
        struct knote *kn;
        int s;
@@ -1268,7 +1269,7 @@ knote_fdclose(struct proc *p, int fd)
 {
        struct filedesc *fdp = p->p_p->ps_fd;
        struct kqueue *kq;
-       struct klist *list;
+       struct knlist *list;
 
        /*
         * fdplock can be ignored if the file descriptor table is being freed
@@ -1303,14 +1304,14 @@ knote_processexit(struct proc *p)
        KNOTE(&pr->ps_klist, NOTE_EXIT);
 
        /* remove other knotes hanging off the process */
-       knote_remove(p, &pr->ps_klist);
+       knote_remove(p, &pr->ps_klist.kl_list);
 }
 
 void
 knote_attach(struct knote *kn)
 {
        struct kqueue *kq = kn->kn_kq;
-       struct klist *list;
+       struct knlist *list;
 
        if (kn->kn_fop->f_flags & FILTEROP_ISFD) {
                KASSERT(kq->kq_knlistsize > kn->kn_id);
@@ -1330,7 +1331,7 @@ void
 knote_drop(struct knote *kn, struct proc *p)
 {
        struct kqueue *kq = kn->kn_kq;
-       struct klist *list;
+       struct knlist *list;
        int s;
 
        KASSERT(kn->kn_filter != EVFILT_MARKER);
@@ -1389,6 +1390,24 @@ knote_dequeue(struct knote *kn)
 }
 
 void
+klist_insert(struct klist *klist, struct knote *kn)
+{
+       SLIST_INSERT_HEAD(&klist->kl_list, kn, kn_selnext);
+}
+
+void
+klist_remove(struct klist *klist, struct knote *kn)
+{
+       SLIST_REMOVE(&klist->kl_list, kn, knote, kn_selnext);
+}
+
+int
+klist_empty(struct klist *klist)
+{
+       return (SLIST_EMPTY(&klist->kl_list));
+}
+
+void
 klist_invalidate(struct klist *list)
 {
        struct knote *kn;
@@ -1401,7 +1420,7 @@ klist_invalidate(struct klist *list)
        NET_ASSERT_UNLOCKED();
 
        s = splhigh();
-       while ((kn = SLIST_FIRST(list)) != NULL) {
+       while ((kn = SLIST_FIRST(&list->kl_list)) != NULL) {
                if (!knote_acquire(kn))
                        continue;
                splx(s);
Index: kern/kern_sig.c
===================================================================
RCS file: src/sys/kern/kern_sig.c,v
retrieving revision 1.255
diff -u -p -r1.255 kern_sig.c
--- kern/kern_sig.c     20 Mar 2020 08:14:07 -0000      1.255
+++ kern/kern_sig.c     4 Apr 2020 13:25:59 -0000
@@ -1811,7 +1811,7 @@ filt_sigattach(struct knote *kn)
        kn->kn_flags |= EV_CLEAR;               /* automatically set */
 
        /* XXX lock the proc here while adding to the list? */
-       SLIST_INSERT_HEAD(&pr->ps_klist, kn, kn_selnext);
+       klist_insert(&pr->ps_klist, kn);
 
        return (0);
 }
@@ -1821,7 +1821,7 @@ filt_sigdetach(struct knote *kn)
 {
        struct process *pr = kn->kn_ptr.p_process;
 
-       SLIST_REMOVE(&pr->ps_klist, kn, knote, kn_selnext);
+       klist_remove(&pr->ps_klist, kn);
 }
 
 /*
Index: kern/subr_log.c
===================================================================
RCS file: src/sys/kern/subr_log.c,v
retrieving revision 1.65
diff -u -p -r1.65 subr_log.c
--- kern/subr_log.c     20 Feb 2020 16:56:52 -0000      1.65
+++ kern/subr_log.c     4 Apr 2020 13:25:59 -0000
@@ -278,7 +278,7 @@ logkqfilter(dev_t dev, struct knote *kn)
        kn->kn_hook = (void *)msgbufp;
 
        s = splhigh();
-       SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+       klist_insert(klist, kn);
        splx(s);
 
        return (0);
@@ -290,7 +290,7 @@ filt_logrdetach(struct knote *kn)
        int s;
 
        s = splhigh();
-       SLIST_REMOVE(&logsoftc.sc_selp.si_note, kn, knote, kn_selnext);
+       klist_remove(&logsoftc.sc_selp.si_note, kn);
        splx(s);
 }
 
Index: kern/sys_pipe.c
===================================================================
RCS file: src/sys/kern/sys_pipe.c,v
retrieving revision 1.118
diff -u -p -r1.118 sys_pipe.c
--- kern/sys_pipe.c     20 Feb 2020 16:56:52 -0000      1.118
+++ kern/sys_pipe.c     4 Apr 2020 13:25:59 -0000
@@ -908,7 +908,7 @@ pipe_kqfilter(struct file *fp, struct kn
        switch (kn->kn_filter) {
        case EVFILT_READ:
                kn->kn_fop = &pipe_rfiltops;
-               SLIST_INSERT_HEAD(&rpipe->pipe_sel.si_note, kn, kn_selnext);
+               klist_insert(&rpipe->pipe_sel.si_note, kn);
                break;
        case EVFILT_WRITE:
                if (wpipe == NULL) {
@@ -917,7 +917,7 @@ pipe_kqfilter(struct file *fp, struct kn
                        break;
                }
                kn->kn_fop = &pipe_wfiltops;
-               SLIST_INSERT_HEAD(&wpipe->pipe_sel.si_note, kn, kn_selnext);
+               klist_insert(&wpipe->pipe_sel.si_note, kn);
                break;
        default:
                error = EINVAL;
@@ -939,12 +939,12 @@ filt_pipedetach(struct knote *kn)
 
        switch (kn->kn_filter) {
        case EVFILT_READ:
-               SLIST_REMOVE(&rpipe->pipe_sel.si_note, kn, knote, kn_selnext);
+               klist_remove(&rpipe->pipe_sel.si_note, kn);
                break;
        case EVFILT_WRITE:
                if (wpipe == NULL)
                        break;
-               SLIST_REMOVE(&wpipe->pipe_sel.si_note, kn, knote, kn_selnext);
+               klist_remove(&wpipe->pipe_sel.si_note, kn);
                break;
        }
 
Index: kern/tty.c
===================================================================
RCS file: src/sys/kern/tty.c,v
retrieving revision 1.153
diff -u -p -r1.153 tty.c
--- kern/tty.c  20 Feb 2020 16:56:52 -0000      1.153
+++ kern/tty.c  4 Apr 2020 13:25:59 -0000
@@ -1126,7 +1126,7 @@ ttkqfilter(dev_t dev, struct knote *kn)
        kn->kn_hook = tp;
 
        s = spltty();
-       SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+       klist_insert(klist, kn);
        splx(s);
 
        return (0);
@@ -1139,7 +1139,7 @@ filt_ttyrdetach(struct knote *kn)
        int s;
 
        s = spltty();
-       SLIST_REMOVE(&tp->t_rsel.si_note, kn, knote, kn_selnext);
+       klist_remove(&tp->t_rsel.si_note, kn);
        splx(s);
 }
 
@@ -1166,7 +1166,7 @@ filt_ttywdetach(struct knote *kn)
        int s;
 
        s = spltty();
-       SLIST_REMOVE(&tp->t_wsel.si_note, kn, knote, kn_selnext);
+       klist_remove(&tp->t_wsel.si_note, kn);
        splx(s);
 }
 
Index: kern/tty_pty.c
===================================================================
RCS file: src/sys/kern/tty_pty.c,v
retrieving revision 1.97
diff -u -p -r1.97 tty_pty.c
--- kern/tty_pty.c      20 Feb 2020 16:56:52 -0000      1.97
+++ kern/tty_pty.c      4 Apr 2020 13:25:59 -0000
@@ -655,7 +655,7 @@ filt_ptcrdetach(struct knote *kn)
        int s;
 
        s = spltty();
-       SLIST_REMOVE(&pti->pt_selr.si_note, kn, knote, kn_selnext);
+       klist_remove(&pti->pt_selr.si_note, kn);
        splx(s);
 }
 
@@ -691,7 +691,7 @@ filt_ptcwdetach(struct knote *kn)
        int s;
 
        s = spltty();
-       SLIST_REMOVE(&pti->pt_selw.si_note, kn, knote, kn_selnext);
+       klist_remove(&pti->pt_selw.si_note, kn);
        splx(s);
 }
 
@@ -753,7 +753,7 @@ ptckqfilter(dev_t dev, struct knote *kn)
        kn->kn_hook = (caddr_t)pti;
 
        s = spltty();
-       SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+       klist_insert(klist, kn);
        splx(s);
 
        return (0);
Index: kern/uipc_socket.c
===================================================================
RCS file: src/sys/kern/uipc_socket.c,v
retrieving revision 1.242
diff -u -p -r1.242 uipc_socket.c
--- kern/uipc_socket.c  11 Mar 2020 22:21:28 -0000      1.242
+++ kern/uipc_socket.c  4 Apr 2020 13:25:59 -0000
@@ -2022,7 +2022,7 @@ soo_kqfilter(struct file *fp, struct kno
                return (EINVAL);
        }
 
-       SLIST_INSERT_HEAD(&sb->sb_sel.si_note, kn, kn_selnext);
+       klist_insert(&sb->sb_sel.si_note, kn);
        sb->sb_flagsintr |= SB_KNOTE;
 
        return (0);
@@ -2035,8 +2035,8 @@ filt_sordetach(struct knote *kn)
 
        KERNEL_ASSERT_LOCKED();
 
-       SLIST_REMOVE(&so->so_rcv.sb_sel.si_note, kn, knote, kn_selnext);
-       if (SLIST_EMPTY(&so->so_rcv.sb_sel.si_note))
+       klist_remove(&so->so_rcv.sb_sel.si_note, kn);
+       if (klist_empty(&so->so_rcv.sb_sel.si_note))
                so->so_rcv.sb_flagsintr &= ~SB_KNOTE;
 }
 
@@ -2078,8 +2078,8 @@ filt_sowdetach(struct knote *kn)
 
        KERNEL_ASSERT_LOCKED();
 
-       SLIST_REMOVE(&so->so_snd.sb_sel.si_note, kn, knote, kn_selnext);
-       if (SLIST_EMPTY(&so->so_snd.sb_sel.si_note))
+       klist_remove(&so->so_snd.sb_sel.si_note, kn);
+       if (klist_empty(&so->so_snd.sb_sel.si_note))
                so->so_snd.sb_flagsintr &= ~SB_KNOTE;
 }
 
Index: miscfs/fifofs/fifo_vnops.c
===================================================================
RCS file: src/sys/miscfs/fifofs/fifo_vnops.c,v
retrieving revision 1.73
diff -u -p -r1.73 fifo_vnops.c
--- miscfs/fifofs/fifo_vnops.c  20 Feb 2020 16:56:52 -0000      1.73
+++ miscfs/fifofs/fifo_vnops.c  4 Apr 2020 13:25:59 -0000
@@ -525,7 +525,7 @@ fifo_kqfilter(void *v)
 
        ap->a_kn->kn_hook = so;
 
-       SLIST_INSERT_HEAD(&sb->sb_sel.si_note, ap->a_kn, kn_selnext);
+       klist_insert(&sb->sb_sel.si_note, ap->a_kn);
        sb->sb_flagsintr |= SB_KNOTE;
 
        return (0);
@@ -536,8 +536,8 @@ filt_fifordetach(struct knote *kn)
 {
        struct socket *so = (struct socket *)kn->kn_hook;
 
-       SLIST_REMOVE(&so->so_rcv.sb_sel.si_note, kn, knote, kn_selnext);
-       if (SLIST_EMPTY(&so->so_rcv.sb_sel.si_note))
+       klist_remove(&so->so_rcv.sb_sel.si_note, kn);
+       if (klist_empty(&so->so_rcv.sb_sel.si_note))
                so->so_rcv.sb_flagsintr &= ~SB_KNOTE;
 }
 
@@ -568,8 +568,8 @@ filt_fifowdetach(struct knote *kn)
 {
        struct socket *so = (struct socket *)kn->kn_hook;
 
-       SLIST_REMOVE(&so->so_snd.sb_sel.si_note, kn, knote, kn_selnext);
-       if (SLIST_EMPTY(&so->so_snd.sb_sel.si_note))
+       klist_remove(&so->so_snd.sb_sel.si_note, kn);
+       if (klist_empty(&so->so_snd.sb_sel.si_note))
                so->so_snd.sb_flagsintr &= ~SB_KNOTE;
 }
 
Index: miscfs/fuse/fuse_device.c
===================================================================
RCS file: src/sys/miscfs/fuse/fuse_device.c,v
retrieving revision 1.32
diff -u -p -r1.32 fuse_device.c
--- miscfs/fuse/fuse_device.c   3 Apr 2020 08:08:51 -0000       1.32
+++ miscfs/fuse/fuse_device.c   4 Apr 2020 13:25:59 -0000
@@ -564,7 +564,7 @@ fusekqfilter(dev_t dev, struct knote *kn
 
        kn->kn_hook = fd;
 
-       SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+       klist_insert(klist, kn);
 
        return (0);
 }
@@ -575,7 +575,7 @@ filt_fuse_rdetach(struct knote *kn)
        struct fuse_d *fd = kn->kn_hook;
        struct klist *klist = &fd->fd_rsel.si_note;
 
-       SLIST_REMOVE(klist, kn, knote, kn_selnext);
+       klist_remove(klist, kn);
 }
 
 int
Index: miscfs/fuse/fuse_vnops.c
===================================================================
RCS file: src/sys/miscfs/fuse/fuse_vnops.c,v
retrieving revision 1.58
diff -u -p -r1.58 fuse_vnops.c
--- miscfs/fuse/fuse_vnops.c    20 Feb 2020 16:56:52 -0000      1.58
+++ miscfs/fuse/fuse_vnops.c    4 Apr 2020 13:25:59 -0000
@@ -154,7 +154,7 @@ fusefs_kqfilter(void *v)
 
        kn->kn_hook = (caddr_t)vp;
 
-       SLIST_INSERT_HEAD(&vp->v_selectinfo.si_note, kn, kn_selnext);
+       klist_insert(&vp->v_selectinfo.si_note, kn);
 
        return (0);
 }
@@ -164,7 +164,7 @@ filt_fusefsdetach(struct knote *kn)
 {
        struct vnode *vp = (struct vnode *)kn->kn_hook;
 
-       SLIST_REMOVE(&vp->v_selectinfo.si_note, kn, knote, kn_selnext);
+       klist_remove(&vp->v_selectinfo.si_note, kn);
 }
 
 int
Index: msdosfs/msdosfs_vnops.c
===================================================================
RCS file: src/sys/msdosfs/msdosfs_vnops.c,v
retrieving revision 1.131
diff -u -p -r1.131 msdosfs_vnops.c
--- msdosfs/msdosfs_vnops.c     24 Mar 2020 14:03:30 -0000      1.131
+++ msdosfs/msdosfs_vnops.c     4 Apr 2020 13:25:59 -0000
@@ -1980,7 +1980,7 @@ msdosfs_kqfilter(void *v)
 
        kn->kn_hook = (caddr_t)vp;
 
-       SLIST_INSERT_HEAD(&vp->v_selectinfo.si_note, kn, kn_selnext);
+       klist_insert(&vp->v_selectinfo.si_note, kn);
 
        return (0);
 }
@@ -1990,7 +1990,7 @@ filt_msdosfsdetach(struct knote *kn)
 {
        struct vnode *vp = (struct vnode *)kn->kn_hook;
 
-       SLIST_REMOVE(&vp->v_selectinfo.si_note, kn, knote, kn_selnext);
+       klist_remove(&vp->v_selectinfo.si_note, kn);
 }
 
 int
Index: net/bpf.c
===================================================================
RCS file: src/sys/net/bpf.c,v
retrieving revision 1.188
diff -u -p -r1.188 bpf.c
--- net/bpf.c   20 Feb 2020 16:56:52 -0000      1.188
+++ net/bpf.c   4 Apr 2020 13:25:59 -0000
@@ -1190,7 +1190,7 @@ bpfkqfilter(dev_t dev, struct knote *kn)
 
        bpf_get(d);
        kn->kn_hook = d;
-       SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+       klist_insert(klist, kn);
 
        mtx_enter(&d->bd_mtx);
        if (d->bd_rtout != -1 && d->bd_rdStart == 0)
@@ -1207,7 +1207,7 @@ filt_bpfrdetach(struct knote *kn)
 
        KERNEL_ASSERT_LOCKED();
 
-       SLIST_REMOVE(&d->bd_sel.si_note, kn, knote, kn_selnext);
+       klist_remove(&d->bd_sel.si_note, kn);
        bpf_put(d);
 }
 
Index: net/if_pppx.c
===================================================================
RCS file: src/sys/net/if_pppx.c,v
retrieving revision 1.78
diff -u -p -r1.78 if_pppx.c
--- net/if_pppx.c       1 Apr 2020 07:15:59 -0000       1.78
+++ net/if_pppx.c       4 Apr 2020 13:25:59 -0000
@@ -529,7 +529,7 @@ pppxkqfilter(dev_t dev, struct knote *kn
        kn->kn_hook = (caddr_t)pxd;
 
        mtx_enter(mtx);
-       SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+       klist_insert(klist, kn);
        mtx_leave(mtx);
 
        return (0);
@@ -542,7 +542,7 @@ filt_pppx_rdetach(struct knote *kn)
        struct klist *klist = &pxd->pxd_rsel.si_note;
 
        mtx_enter(&pxd->pxd_rsel_mtx);
-       SLIST_REMOVE(klist, kn, knote, kn_selnext);
+       klist_remove(klist, kn);
        mtx_leave(&pxd->pxd_rsel_mtx);
 }
 
@@ -563,7 +563,7 @@ filt_pppx_wdetach(struct knote *kn)
        struct klist *klist = &pxd->pxd_wsel.si_note;
 
        mtx_enter(&pxd->pxd_wsel_mtx);
-       SLIST_REMOVE(klist, kn, knote, kn_selnext);
+       klist_remove(klist, kn);
        mtx_leave(&pxd->pxd_wsel_mtx);
 }
 
@@ -1451,7 +1451,7 @@ pppackqfilter(dev_t dev, struct knote *k
        kn->kn_hook = sc;
 
        mtx_enter(mtx);
-       SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+       klist_insert(klist, kn);
        mtx_leave(mtx);
 
        return (0);
@@ -1464,7 +1464,7 @@ filt_pppac_rdetach(struct knote *kn)
        struct klist *klist = &sc->sc_rsel.si_note;
 
        mtx_enter(&sc->sc_rsel_mtx);
-       SLIST_REMOVE(klist, kn, knote, kn_selnext);
+       klist_remove(klist, kn);
        mtx_leave(&sc->sc_rsel_mtx);
 }
 
@@ -1485,7 +1485,7 @@ filt_pppac_wdetach(struct knote *kn)
        struct klist *klist = &sc->sc_wsel.si_note;
 
        mtx_enter(&sc->sc_wsel_mtx);
-       SLIST_REMOVE(klist, kn, knote, kn_selnext);
+       klist_remove(klist, kn);
        mtx_leave(&sc->sc_wsel_mtx);
 }
 
Index: net/if_tun.c
===================================================================
RCS file: src/sys/net/if_tun.c,v
retrieving revision 1.219
diff -u -p -r1.219 if_tun.c
--- net/if_tun.c        20 Feb 2020 16:56:52 -0000      1.219
+++ net/if_tun.c        4 Apr 2020 13:25:59 -0000
@@ -1001,7 +1001,7 @@ tun_dev_kqfilter(dev_t dev, struct knote
        kn->kn_hook = (caddr_t)sc; /* XXX give the sc_ref to the hook? */
 
        s = splhigh();
-       SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+       klist_insert(klist, kn);
        splx(s);
 
 put:
@@ -1016,7 +1016,7 @@ filt_tunrdetach(struct knote *kn)
        struct tun_softc        *sc = kn->kn_hook;
 
        s = splhigh();
-       SLIST_REMOVE(&sc->sc_rsel.si_note, kn, knote, kn_selnext);
+       klist_remove(&sc->sc_rsel.si_note, kn);
        splx(s);
 }
 
@@ -1038,7 +1038,7 @@ filt_tunwdetach(struct knote *kn)
        struct tun_softc        *sc = kn->kn_hook;
 
        s = splhigh();
-       SLIST_REMOVE(&sc->sc_wsel.si_note, kn, knote, kn_selnext);
+       klist_remove(&sc->sc_wsel.si_note, kn);
        splx(s);
 }
 
Index: net/switchctl.c
===================================================================
RCS file: src/sys/net/switchctl.c,v
retrieving revision 1.20
diff -u -p -r1.20 switchctl.c
--- net/switchctl.c     20 Feb 2020 16:56:52 -0000      1.20
+++ net/switchctl.c     4 Apr 2020 13:25:59 -0000
@@ -409,7 +409,7 @@ switchkqfilter(dev_t dev, struct knote *
 
        kn->kn_hook = (caddr_t)sc;
 
-       SLIST_INSERT_HEAD(klist, kn, kn_selnext);
+       klist_insert(klist, kn);
 
        return (0);
 }
@@ -420,7 +420,7 @@ filt_switch_rdetach(struct knote *kn)
        struct switch_softc     *sc = (struct switch_softc *)kn->kn_hook;
        struct klist            *klist = &sc->sc_swdev->swdev_rsel.si_note;
 
-       SLIST_REMOVE(klist, kn, knote, kn_selnext);
+       klist_remove(klist, kn);
 }
 
 int
@@ -444,7 +444,7 @@ filt_switch_wdetach(struct knote *kn)
        struct switch_softc     *sc = (struct switch_softc *)kn->kn_hook;
        struct klist            *klist = &sc->sc_swdev->swdev_wsel.si_note;
 
-       SLIST_REMOVE(klist, kn, knote, kn_selnext);
+       klist_remove(klist, kn);
 }
 
 int
Index: nfs/nfs_kq.c
===================================================================
RCS file: src/sys/nfs/nfs_kq.c,v
retrieving revision 1.29
diff -u -p -r1.29 nfs_kq.c
--- nfs/nfs_kq.c        20 Feb 2020 16:56:52 -0000      1.29
+++ nfs/nfs_kq.c        4 Apr 2020 13:25:59 -0000
@@ -184,7 +184,7 @@ filt_nfsdetach(struct knote *kn)
        struct vnode *vp = (struct vnode *)kn->kn_hook;
        struct kevq *ke;
 
-       SLIST_REMOVE(&vp->v_selectinfo.si_note, kn, knote, kn_selnext);
+       klist_remove(&vp->v_selectinfo.si_note, kn);
 
        /* Remove the vnode from watch list */
        rw_enter_write(&nfskevq_lock);
@@ -339,7 +339,7 @@ nfs_kqfilter(void *v)
        /* kick the poller */
        wakeup(pnfskq);
 
-       SLIST_INSERT_HEAD(&vp->v_selectinfo.si_note, kn, kn_selnext);
+       klist_insert(&vp->v_selectinfo.si_note, kn);
 
 out:
        rw_exit_write(&nfskevq_lock);
Index: sys/event.h
===================================================================
RCS file: src/sys/sys/event.h,v
retrieving revision 1.34
diff -u -p -r1.34 event.h
--- sys/event.h 4 Apr 2020 08:57:36 -0000       1.34
+++ sys/event.h 4 Apr 2020 13:25:59 -0000
@@ -121,7 +121,11 @@ struct kevent {
  */
 #include <sys/queue.h>
 struct knote;
-SLIST_HEAD(klist, knote);
+SLIST_HEAD(knlist, knote);
+
+struct klist {
+       struct knlist            kl_list;
+};
 
 #ifdef _KERNEL
 
@@ -191,13 +195,16 @@ extern const struct filterops sig_filtop
 
 extern void    knote(struct klist *list, long hint);
 extern void    knote_activate(struct knote *);
-extern void    knote_remove(struct proc *p, struct klist *list);
+extern void    knote_remove(struct proc *p, struct knlist *list);
 extern void    knote_fdclose(struct proc *p, int fd);
 extern void    knote_processexit(struct proc *);
 extern int     kqueue_register(struct kqueue *kq,
                    struct kevent *kev, struct proc *p);
 extern int     filt_seltrue(struct knote *kn, long hint);
 extern int     seltrue_kqfilter(dev_t, struct knote *);
+extern void    klist_insert(struct klist *, struct knote *);
+extern void    klist_remove(struct klist *, struct knote *);
+extern int     klist_empty(struct klist *);
 extern void    klist_invalidate(struct klist *);
 
 #else  /* !_KERNEL */
Index: sys/eventvar.h
===================================================================
RCS file: src/sys/sys/eventvar.h,v
retrieving revision 1.8
diff -u -p -r1.8 eventvar.h
--- sys/eventvar.h      14 Feb 2020 16:50:25 -0000      1.8
+++ sys/eventvar.h      4 Apr 2020 13:25:59 -0000
@@ -49,10 +49,10 @@ struct kqueue {
 
        LIST_ENTRY(kqueue) kq_next;
 
-       int             kq_knlistsize;          /* size of knlist */
-       struct          klist *kq_knlist;       /* list of attached knotes */
-       u_long          kq_knhashmask;          /* size of knhash */
-       struct          klist *kq_knhash;       /* hash table for attached 
knotes */
+       int             kq_knlistsize;          /* size of kq_knlist */
+       struct          knlist *kq_knlist;      /* list of attached knotes */
+       u_long          kq_knhashmask;          /* size of kq_knhash */
+       struct          knlist *kq_knhash;      /* hash table for attached 
knotes */
        struct          task kq_task;           /* deferring of activation */
 
        int             kq_state;
Index: tmpfs/tmpfs_vnops.c
===================================================================
RCS file: src/sys/tmpfs/tmpfs_vnops.c,v
retrieving revision 1.39
diff -u -p -r1.39 tmpfs_vnops.c
--- tmpfs/tmpfs_vnops.c 20 Feb 2020 16:56:52 -0000      1.39
+++ tmpfs/tmpfs_vnops.c 4 Apr 2020 13:25:59 -0000
@@ -2631,7 +2631,7 @@ tmpfs_kqfilter(void *v)
 
        kn->kn_hook = (caddr_t)vp;
 
-       SLIST_INSERT_HEAD(&vp->v_selectinfo.si_note, kn, kn_selnext);
+       klist_insert(&vp->v_selectinfo.si_note, kn);
 
        return (0);
 }
@@ -2641,7 +2641,7 @@ filt_tmpfsdetach(struct knote *kn)
 {
        struct vnode *vp = (struct vnode *)kn->kn_hook;
 
-       SLIST_REMOVE(&vp->v_selectinfo.si_note, kn, knote, kn_selnext);
+       klist_remove(&vp->v_selectinfo.si_note, kn);
 }
 
 int
Index: ufs/ufs/ufs_vnops.c
===================================================================
RCS file: src/sys/ufs/ufs/ufs_vnops.c,v
retrieving revision 1.149
diff -u -p -r1.149 ufs_vnops.c
--- ufs/ufs/ufs_vnops.c 27 Feb 2020 09:10:31 -0000      1.149
+++ ufs/ufs/ufs_vnops.c 4 Apr 2020 13:26:00 -0000
@@ -1934,7 +1934,7 @@ ufs_kqfilter(void *v)
 
        kn->kn_hook = (caddr_t)vp;
 
-       SLIST_INSERT_HEAD(&vp->v_selectinfo.si_note, kn, kn_selnext);
+       klist_insert(&vp->v_selectinfo.si_note, kn);
 
        return (0);
 }
@@ -1944,7 +1944,7 @@ filt_ufsdetach(struct knote *kn)
 {
        struct vnode *vp = (struct vnode *)kn->kn_hook;
 
-       SLIST_REMOVE(&vp->v_selectinfo.si_note, kn, knote, kn_selnext);
+       klist_remove(&vp->v_selectinfo.si_note, kn);
 }
 
 int

Reply via email to