Replace struct selinfo with direct use of struct klist in bpf, kqueue
and pipes. These subsystems no longer utilize selwakeup().

OK?

Index: kern/kern_event.c
===================================================================
RCS file: src/sys/kern/kern_event.c,v
retrieving revision 1.191
diff -u -p -r1.191 kern_event.c
--- kern/kern_event.c   27 Jun 2022 13:35:21 -0000      1.191
+++ kern/kern_event.c   8 Jul 2022 15:32:26 -0000
@@ -38,7 +38,6 @@
 #include <sys/file.h>
 #include <sys/filedesc.h>
 #include <sys/fcntl.h>
-#include <sys/selinfo.h>
 #include <sys/queue.h>
 #include <sys/event.h>
 #include <sys/eventvar.h>
@@ -221,7 +220,7 @@ KQRELE(struct kqueue *kq)
        free(kq->kq_knlist, M_KEVENT, kq->kq_knlistsize *
            sizeof(struct knlist));
        hashfree(kq->kq_knhash, KN_HASHSIZE, M_KEVENT);
-       klist_free(&kq->kq_sel.si_note);
+       klist_free(&kq->kq_klist);
        pool_put(&kqueue_pool, kq);
 }
 
@@ -257,7 +256,7 @@ kqueue_kqfilter(struct file *fp, struct 
                return (EINVAL);
 
        kn->kn_fop = &kqread_filtops;
-       klist_insert(&kq->kq_sel.si_note, kn);
+       klist_insert(&kq->kq_klist, kn);
        return (0);
 }
 
@@ -266,7 +265,7 @@ filt_kqdetach(struct knote *kn)
 {
        struct kqueue *kq = kn->kn_fp->f_data;
 
-       klist_remove(&kq->kq_sel.si_note, kn);
+       klist_remove(&kq->kq_klist, kn);
 }
 
 int
@@ -849,7 +848,7 @@ kqueue_alloc(struct filedesc *fdp)
        TAILQ_INIT(&kq->kq_head);
        mtx_init(&kq->kq_lock, IPL_HIGH);
        task_set(&kq->kq_task, kqueue_task, kq);
-       klist_init_mutex(&kq->kq_sel.si_note, &kqueue_klist_lock);
+       klist_init_mutex(&kq->kq_klist, &kqueue_klist_lock);
 
        return (kq);
 }
@@ -1580,7 +1579,7 @@ kqueue_terminate(struct proc *p, struct 
         * Any knotes that were attached to this kqueue were deleted
         * by knote_fdclose() when this kqueue's file descriptor was closed.
         */
-       KASSERT(klist_empty(&kq->kq_sel.si_note));
+       KASSERT(klist_empty(&kq->kq_klist));
        if (state & KQ_TASK)
                taskq_del_barrier(systqmp, &kq->kq_task);
 }
@@ -1606,7 +1605,7 @@ kqueue_task(void *arg)
        struct kqueue *kq = arg;
 
        mtx_enter(&kqueue_klist_lock);
-       KNOTE(&kq->kq_sel.si_note, 0);
+       KNOTE(&kq->kq_klist, 0);
        mtx_leave(&kqueue_klist_lock);
 }
 
@@ -1619,7 +1618,7 @@ kqueue_wakeup(struct kqueue *kq)
                kq->kq_state &= ~KQ_SLEEP;
                wakeup(kq);
        }
-       if (!klist_empty(&kq->kq_sel.si_note)) {
+       if (!klist_empty(&kq->kq_klist)) {
                /* Defer activation to avoid recursion. */
                kq->kq_state |= KQ_TASK;
                task_add(systqmp, &kq->kq_task);
Index: kern/sys_pipe.c
===================================================================
RCS file: src/sys/kern/sys_pipe.c,v
retrieving revision 1.140
diff -u -p -r1.140 sys_pipe.c
--- kern/sys_pipe.c     20 Jun 2022 01:39:44 -0000      1.140
+++ kern/sys_pipe.c     8 Jul 2022 15:32:26 -0000
@@ -371,7 +371,7 @@ pipeselwakeup(struct pipe *cpipe)
 {
        rw_assert_wrlock(cpipe->pipe_lock);
 
-       KNOTE(&cpipe->pipe_sel.si_note, 0);
+       KNOTE(&cpipe->pipe_klist, 0);
 
        if (cpipe->pipe_state & PIPE_ASYNC)
                pgsigio(&cpipe->pipe_sigio, SIGIO, 0);
@@ -854,7 +854,7 @@ pipe_kqfilter(struct file *fp, struct kn
        case EVFILT_READ:
                kn->kn_fop = &pipe_rfiltops;
                kn->kn_hook = rpipe;
-               klist_insert_locked(&rpipe->pipe_sel.si_note, kn);
+               klist_insert_locked(&rpipe->pipe_klist, kn);
                break;
        case EVFILT_WRITE:
                if (wpipe == NULL) {
@@ -864,7 +864,7 @@ pipe_kqfilter(struct file *fp, struct kn
                }
                kn->kn_fop = &pipe_wfiltops;
                kn->kn_hook = wpipe;
-               klist_insert_locked(&wpipe->pipe_sel.si_note, kn);
+               klist_insert_locked(&wpipe->pipe_klist, kn);
                break;
        case EVFILT_EXCEPT:
                if (kn->kn_flags & __EV_SELECT) {
@@ -879,7 +879,7 @@ pipe_kqfilter(struct file *fp, struct kn
                }
                kn->kn_fop = &pipe_efiltops;
                kn->kn_hook = rpipe;
-               klist_insert_locked(&rpipe->pipe_sel.si_note, kn);
+               klist_insert_locked(&rpipe->pipe_klist, kn);
                break;
        default:
                error = EINVAL;
@@ -895,7 +895,7 @@ filt_pipedetach(struct knote *kn)
 {
        struct pipe *cpipe = kn->kn_hook;
 
-       klist_remove(&cpipe->pipe_sel.si_note, kn);
+       klist_remove(&cpipe->pipe_klist, kn);
 }
 
 int
@@ -1011,8 +1011,8 @@ pipe_pair_create(void)
        pp->pp_wpipe.pipe_lock = &pp->pp_lock;
        pp->pp_rpipe.pipe_lock = &pp->pp_lock;
 
-       klist_init_rwlock(&pp->pp_wpipe.pipe_sel.si_note, &pp->pp_lock);
-       klist_init_rwlock(&pp->pp_rpipe.pipe_sel.si_note, &pp->pp_lock);
+       klist_init_rwlock(&pp->pp_wpipe.pipe_klist, &pp->pp_lock);
+       klist_init_rwlock(&pp->pp_rpipe.pipe_klist, &pp->pp_lock);
 
        if (pipe_create(&pp->pp_wpipe) || pipe_create(&pp->pp_rpipe))
                goto err;
@@ -1026,7 +1026,7 @@ err:
 void
 pipe_pair_destroy(struct pipe_pair *pp)
 {
-       klist_free(&pp->pp_wpipe.pipe_sel.si_note);
-       klist_free(&pp->pp_rpipe.pipe_sel.si_note);
+       klist_free(&pp->pp_wpipe.pipe_klist);
+       klist_free(&pp->pp_rpipe.pipe_klist);
        pool_put(&pipe_pair_pool, pp);
 }
Index: net/bpf.c
===================================================================
RCS file: src/sys/net/bpf.c,v
retrieving revision 1.218
diff -u -p -r1.218 bpf.c
--- net/bpf.c   5 Jul 2022 15:06:16 -0000       1.218
+++ net/bpf.c   8 Jul 2022 15:32:26 -0000
@@ -54,10 +54,11 @@
 #include <sys/sysctl.h>
 #include <sys/rwlock.h>
 #include <sys/atomic.h>
+#include <sys/event.h>
+#include <sys/mutex.h>
 #include <sys/refcnt.h>
 #include <sys/smr.h>
 #include <sys/specdev.h>
-#include <sys/selinfo.h>
 #include <sys/sigio.h>
 #include <sys/task.h>
 #include <sys/time.h>
@@ -393,7 +394,7 @@ bpfopen(dev_t dev, int flag, int mode, s
        task_set(&bd->bd_wake_task, bpf_wakeup_cb, bd);
        smr_init(&bd->bd_smr);
        sigio_init(&bd->bd_sigio);
-       klist_init_mutex(&bd->bd_sel.si_note, &bd->bd_mtx);
+       klist_init_mutex(&bd->bd_klist, &bd->bd_mtx);
 
        bd->bd_rtout = 0;       /* no timeout by default */
 
@@ -585,7 +586,7 @@ bpf_wakeup(struct bpf_d *d)
        if (d->bd_nreaders)
                wakeup(d);
 
-       KNOTE(&d->bd_sel.si_note, 0);
+       KNOTE(&d->bd_klist, 0);
 
        /*
         * As long as pgsigio() needs to be protected
@@ -1161,7 +1162,7 @@ bpfkqfilter(dev_t dev, struct knote *kn)
 
        switch (kn->kn_filter) {
        case EVFILT_READ:
-               klist = &d->bd_sel.si_note;
+               klist = &d->bd_klist;
                kn->kn_fop = &bpfread_filtops;
                break;
        default:
@@ -1180,7 +1181,7 @@ filt_bpfrdetach(struct knote *kn)
 {
        struct bpf_d *d = kn->kn_hook;
 
-       klist_remove(&d->bd_sel.si_note, kn);
+       klist_remove(&d->bd_klist, kn);
        bpf_put(d);
 }
 
@@ -1591,7 +1592,7 @@ bpf_d_smr(void *smr)
        if (bd->bd_wfilter != NULL)
                bpf_prog_smr(bd->bd_wfilter);
 
-       klist_free(&bd->bd_sel.si_note);
+       klist_free(&bd->bd_klist);
        free(bd, M_DEVBUF, sizeof(*bd));
 }
 
@@ -1684,7 +1685,7 @@ bpfsdetach(void *p)
 
        while ((bd = SMR_SLIST_FIRST_LOCKED(&bp->bif_dlist))) {
                vdevgone(maj, bd->bd_unit, bd->bd_unit, VCHR);
-               klist_invalidate(&bd->bd_sel.si_note);
+               klist_invalidate(&bd->bd_klist);
        }
 
        for (tbp = bpf_iflist; tbp; tbp = tbp->bif_next) {
Index: net/bpfdesc.h
===================================================================
RCS file: src/sys/net/bpfdesc.h,v
retrieving revision 1.46
diff -u -p -r1.46 bpfdesc.h
--- net/bpfdesc.h       17 Mar 2022 14:22:03 -0000      1.46
+++ net/bpfdesc.h       8 Jul 2022 15:32:26 -0000
@@ -99,7 +99,7 @@ struct bpf_d {
        struct sigio_ref
                        bd_sigio;       /* async I/O registration */
        struct refcnt   bd_refcnt;      /* reference count */
-       struct selinfo  bd_sel;         /* bsd select info */
+       struct klist    bd_klist;       /* list of knotes */
        int             bd_unit;        /* logical unit number */
        LIST_ENTRY(bpf_d) bd_list;      /* descriptor list */
 
Index: sys/eventvar.h
===================================================================
RCS file: src/sys/sys/eventvar.h,v
retrieving revision 1.16
diff -u -p -r1.16 eventvar.h
--- sys/eventvar.h      27 Jun 2022 13:35:21 -0000      1.16
+++ sys/eventvar.h      8 Jul 2022 15:32:26 -0000
@@ -41,6 +41,7 @@
 /*
  * Locking:
  *     I       immutable after creation
+ *     L       kqueue_klist_lock
  *     a       atomic operations
  *     q       kq_lock
  */
@@ -49,7 +50,7 @@ struct kqueue {
        TAILQ_HEAD(, knote) kq_head;            /* [q] list of pending event */
        int             kq_count;               /* [q] # of pending events */
        struct          refcnt kq_refcnt;       /* [a] # of references */
-       struct          selinfo kq_sel;
+       struct          klist kq_klist;         /* [L] knotes of other kqs */
        struct          filedesc *kq_fdp;       /* [I] fd table of this kq */
 
        LIST_ENTRY(kqueue) kq_next;
Index: sys/pipe.h
===================================================================
RCS file: src/sys/sys/pipe.h,v
retrieving revision 1.28
diff -u -p -r1.28 pipe.h
--- sys/pipe.h  20 Jun 2022 01:39:44 -0000      1.28
+++ sys/pipe.h  8 Jul 2022 15:32:26 -0000
@@ -26,9 +26,9 @@
 
 #ifndef _KERNEL
 #include <sys/time.h>                  /* for struct timespec */
-#include <sys/selinfo.h>               /* for struct selinfo */
 #endif /* _KERNEL */
 
+#include <sys/event.h>                 /* for struct klist */
 #include <sys/sigio.h>                 /* for struct sigio_ref */
 
 /*
@@ -80,7 +80,7 @@ struct pipe_pair;
 struct pipe {
        struct  rwlock *pipe_lock;
        struct  pipebuf pipe_buffer;    /* [p] data storage */
-       struct  selinfo pipe_sel;       /* [p] for compat with select */
+       struct  klist pipe_klist;       /* [p] list of knotes */
        struct  timespec pipe_atime;    /* [p] time of last access */
        struct  timespec pipe_mtime;    /* [p] time of last modify */
        struct  timespec pipe_ctime;    /* [I] time of status change */

Reply via email to