Sat Feb 12 15:51:29 2022 UTC ()
Add inline functions to manipulate the klists that link up knotes
via kn_selnext:

- klist_init()
- klist_fini()
- klist_insert()
- klist_remove()

These provide some API insulation from the implementation details of these
lists (but not completely; see vn_knote_attach() and vn_knote_detach()).
Currently just a wrapper around SLIST(9).

This will make it significantly easier to switch kn_selnext linkage
to a different kind of list.


(thorpej)
diff -r1.7 -r1.8 src/sys/arch/arm/xscale/pxa2x0_apm.c
diff -r1.13 -r1.14 src/sys/arch/mips/ralink/ralink_gpio.c
diff -r1.14 -r1.15 src/sys/dev/pci/xmm7360.c
diff -r1.1 -r1.2 src/sys/external/bsd/drm2/linux/linux_sync_file.c
diff -r1.139 -r1.140 src/sys/kern/kern_event.c
diff -r1.262 -r1.263 src/sys/kern/kern_proc.c
diff -r1.400 -r1.401 src/sys/kern/kern_sig.c
diff -r1.57 -r1.58 src/sys/kern/sys_select.c
diff -r1.53 -r1.54 src/sys/kern/vfs_init.c
diff -r1.554 -r1.555 src/sys/kern/vfs_syscalls.c
diff -r1.129 -r1.130 src/sys/kern/vfs_vnode.c
diff -r1.51 -r1.52 src/sys/sys/event.h
diff -r1.237 -r1.238 src/sys/sys/mount.h

cvs diff -r1.7 -r1.8 src/sys/arch/arm/xscale/pxa2x0_apm.c (expand / switch to unified diff)

--- src/sys/arch/arm/xscale/pxa2x0_apm.c 2021/09/26 16:36:18 1.7
+++ src/sys/arch/arm/xscale/pxa2x0_apm.c 2022/02/12 15:51:28 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pxa2x0_apm.c,v 1.7 2021/09/26 16:36:18 thorpej Exp $ */ 1/* $NetBSD: pxa2x0_apm.c,v 1.8 2022/02/12 15:51:28 thorpej Exp $ */
2/* $OpenBSD: pxa2x0_apm.c,v 1.28 2007/03/29 18:42:38 uwe Exp $ */ 2/* $OpenBSD: pxa2x0_apm.c,v 1.28 2007/03/29 18:42:38 uwe Exp $ */
3 3
4/*- 4/*-
5 * Copyright (c) 2001 Alexander Guy. All rights reserved. 5 * Copyright (c) 2001 Alexander Guy. All rights reserved.
6 * Copyright (c) 1998-2001 Michael Shalayeff. All rights reserved. 6 * Copyright (c) 1998-2001 Michael Shalayeff. All rights reserved.
7 * Copyright (c) 1995 John T. Kohl. All rights reserved. 7 * Copyright (c) 1995 John T. Kohl. All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -591,27 +591,27 @@ apm_record_event(struct pxa2x0_apm_softc @@ -591,27 +591,27 @@ apm_record_event(struct pxa2x0_apm_softc
591 591
592 apm_evindex++; 592 apm_evindex++;
593 KNOTE(&sc->sc_note, APM_EVENT_COMPOSE(type, apm_evindex)); 593 KNOTE(&sc->sc_note, APM_EVENT_COMPOSE(type, apm_evindex));
594 594
595 return (0); 595 return (0);
596} 596}
597 597
598void 598void
599filt_apmrdetach(struct knote *kn) 599filt_apmrdetach(struct knote *kn)
600{ 600{
601 struct pxa2x0_apm_softc *sc = 601 struct pxa2x0_apm_softc *sc =
602 (struct pxa2x0_apm_softc *)kn->kn_hook; 602 (struct pxa2x0_apm_softc *)kn->kn_hook;
603 603
604 SLIST_REMOVE(&sc->sc_note, kn, knote, kn_selnext); 604 klist_remove(&sc->sc_note, kn);
605} 605}
606 606
607int 607int
608filt_apmread(struct knote *kn, long hint) 608filt_apmread(struct knote *kn, long hint)
609{ 609{
610 /* XXX weird kqueue_scan() semantics */ 610 /* XXX weird kqueue_scan() semantics */
611 if (hint && !kn->kn_data) 611 if (hint && !kn->kn_data)
612 kn->kn_data = (int)hint; 612 kn->kn_data = (int)hint;
613 613
614 return (1); 614 return (1);
615} 615}
616 616
617int 617int
@@ -623,44 +623,45 @@ apmkqfilter(dev_t dev, struct knote *kn) @@ -623,44 +623,45 @@ apmkqfilter(dev_t dev, struct knote *kn)
623 if (!apm_cd.cd_ndevs || APMUNIT(dev) != 0 || 623 if (!apm_cd.cd_ndevs || APMUNIT(dev) != 0 ||
624 !(sc = apm_cd.cd_devs[APMUNIT(dev)])) 624 !(sc = apm_cd.cd_devs[APMUNIT(dev)]))
625 return (ENXIO); 625 return (ENXIO);
626 626
627 switch (kn->kn_filter) { 627 switch (kn->kn_filter) {
628 case EVFILT_READ: 628 case EVFILT_READ:
629 kn->kn_fop = &apmread_filtops; 629 kn->kn_fop = &apmread_filtops;
630 break; 630 break;
631 default: 631 default:
632 return (EINVAL); 632 return (EINVAL);
633 } 633 }
634 634
635 kn->kn_hook = (caddr_t)sc; 635 kn->kn_hook = (caddr_t)sc;
636 SLIST_INSERT_HEAD(&sc->sc_note, kn, kn_selnext); 636 klist_insert(&sc->sc_note, kn);
637 637
638 return (0); 638 return (0);
639} 639}
640 640
641void 641void
642pxa2x0_apm_attach_sub(struct pxa2x0_apm_softc *sc) 642pxa2x0_apm_attach_sub(struct pxa2x0_apm_softc *sc)
643{ 643{
644 644
645 sc->sc_iot = &pxa2x0_bs_tag; 645 sc->sc_iot = &pxa2x0_bs_tag;
646 646
647 if (bus_space_map(sc->sc_iot, PXA2X0_POWMAN_BASE, 647 if (bus_space_map(sc->sc_iot, PXA2X0_POWMAN_BASE,
648 PXA2X0_POWMAN_SIZE, 0, &sc->sc_pm_ioh)) { 648 PXA2X0_POWMAN_SIZE, 0, &sc->sc_pm_ioh)) {
649 printf("pxa2x0_apm_attach_sub: failed to map POWMAN\n"); 649 printf("pxa2x0_apm_attach_sub: failed to map POWMAN\n");
650 return; 650 return;
651 } 651 }
652 652
653 lockinit(&sc->sc_lock, PWAIT, "apmlk", 0, 0); 653 lockinit(&sc->sc_lock, PWAIT, "apmlk", 0, 0);
 654 klist_init(&sc->sc_note);
654 655
655 kthread_create_deferred(apm_thread_create, sc); 656 kthread_create_deferred(apm_thread_create, sc);
656 657
657 printf("\n"); 658 printf("\n");
658 659
659 if (bus_space_map(sc->sc_iot, PXA2X0_CLKMAN_BASE, PXA2X0_CLKMAN_SIZE, 660 if (bus_space_map(sc->sc_iot, PXA2X0_CLKMAN_BASE, PXA2X0_CLKMAN_SIZE,
660 0, &pxa2x0_clkman_ioh)) { 661 0, &pxa2x0_clkman_ioh)) {
661 printf("%s: failed to map CLKMAN\n", device_xname(sc->sc_dev)); 662 printf("%s: failed to map CLKMAN\n", device_xname(sc->sc_dev));
662 return; 663 return;
663 } 664 }
664 665
665 if (bus_space_map(sc->sc_iot, PXA2X0_MEMCTL_BASE, PXA2X0_MEMCTL_SIZE, 666 if (bus_space_map(sc->sc_iot, PXA2X0_MEMCTL_BASE, PXA2X0_MEMCTL_SIZE,
666 0, &pxa2x0_memctl_ioh)) { 667 0, &pxa2x0_memctl_ioh)) {

cvs diff -r1.13 -r1.14 src/sys/arch/mips/ralink/ralink_gpio.c (expand / switch to unified diff)

--- src/sys/arch/mips/ralink/ralink_gpio.c 2021/09/26 01:16:07 1.13
+++ src/sys/arch/mips/ralink/ralink_gpio.c 2022/02/12 15:51:29 1.14

cvs diff -r1.14 -r1.15 src/sys/dev/pci/xmm7360.c (expand / switch to unified diff)

--- src/sys/dev/pci/xmm7360.c 2022/02/12 03:24:36 1.14
+++ src/sys/dev/pci/xmm7360.c 2022/02/12 15:51:29 1.15
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: xmm7360.c,v 1.14 2022/02/12 03:24:36 riastradh Exp $ */ 1/* $NetBSD: xmm7360.c,v 1.15 2022/02/12 15:51:29 thorpej Exp $ */
2 2
3/* 3/*
4 * Device driver for Intel XMM7360 LTE modems, eg. Fibocom L850-GL. 4 * Device driver for Intel XMM7360 LTE modems, eg. Fibocom L850-GL.
5 * Written by James Wah 5 * Written by James Wah
6 * james@laird-wah.net 6 * james@laird-wah.net
7 * 7 *
8 * Development of this driver was supported by genua GmbH 8 * Development of this driver was supported by genua GmbH
9 * 9 *
10 * Copyright (c) 2020 genua GmbH <info@genua.de> 10 * Copyright (c) 2020 genua GmbH <info@genua.de>
11 * Copyright (c) 2020 James Wah <james@laird-wah.net> 11 * Copyright (c) 2020 James Wah <james@laird-wah.net>
12 * 12 *
13 * The OpenBSD and NetBSD support was written by Jaromir Dolecek for 13 * The OpenBSD and NetBSD support was written by Jaromir Dolecek for
14 * Moritz Systems Technology Company Sp. z o.o. 14 * Moritz Systems Technology Company Sp. z o.o.
@@ -65,27 +65,27 @@ MODULE_DEVICE_TABLE(pci, xmm7360_ids); @@ -65,27 +65,27 @@ MODULE_DEVICE_TABLE(pci, xmm7360_ids);
65 65
66#endif 66#endif
67 67
68#if defined(__OpenBSD__) || defined(__NetBSD__) 68#if defined(__OpenBSD__) || defined(__NetBSD__)
69 69
70#ifdef __OpenBSD__ 70#ifdef __OpenBSD__
71#include "bpfilter.h" 71#include "bpfilter.h"
72#endif 72#endif
73#ifdef __NetBSD__ 73#ifdef __NetBSD__
74#include "opt_inet.h" 74#include "opt_inet.h"
75#include "opt_gateway.h" 75#include "opt_gateway.h"
76 76
77#include <sys/cdefs.h> 77#include <sys/cdefs.h>
78__KERNEL_RCSID(0, "$NetBSD: xmm7360.c,v 1.14 2022/02/12 03:24:36 riastradh Exp $"); 78__KERNEL_RCSID(0, "$NetBSD: xmm7360.c,v 1.15 2022/02/12 15:51:29 thorpej Exp $");
79#endif 79#endif
80 80
81#include <sys/param.h> 81#include <sys/param.h>
82#include <sys/systm.h> 82#include <sys/systm.h>
83#include <sys/sockio.h> 83#include <sys/sockio.h>
84#include <sys/mbuf.h> 84#include <sys/mbuf.h>
85#include <sys/kernel.h> 85#include <sys/kernel.h>
86#include <sys/device.h> 86#include <sys/device.h>
87#include <sys/socket.h> 87#include <sys/socket.h>
88#include <sys/mutex.h> 88#include <sys/mutex.h>
89#include <sys/tty.h> 89#include <sys/tty.h>
90#include <sys/conf.h> 90#include <sys/conf.h>
91#include <sys/kthread.h> 91#include <sys/kthread.h>
@@ -248,30 +248,26 @@ typedef struct kmutex spinlock_t; @@ -248,30 +248,26 @@ typedef struct kmutex spinlock_t;
248}) 248})
249#define ifq_deq_rollback(ifq, m) m_freem(m) 249#define ifq_deq_rollback(ifq, m) m_freem(m)
250#define ifq_deq_commit(ifq, m) /* nothing to do */ 250#define ifq_deq_commit(ifq, m) /* nothing to do */
251#define ifq_is_oactive(ifq) true /* always restart queue */ 251#define ifq_is_oactive(ifq) true /* always restart queue */
252#define ifq_clr_oactive(ifq) /* nothing to do */ 252#define ifq_clr_oactive(ifq) /* nothing to do */
253#define ifq_empty(ifq) IFQ_IS_EMPTY(ifq) 253#define ifq_empty(ifq) IFQ_IS_EMPTY(ifq)
254#define ifq_purge(ifq) IF_PURGE(ifq) 254#define ifq_purge(ifq) IF_PURGE(ifq)
255#define if_enqueue(ifp, m) ifq_enqueue(ifp, m) 255#define if_enqueue(ifp, m) ifq_enqueue(ifp, m)
256#define if_ih_insert(ifp, func, arg) (ifp)->_if_input = (func) 256#define if_ih_insert(ifp, func, arg) (ifp)->_if_input = (func)
257#define if_ih_remove(ifp, func, arg) /* nothing to do */ 257#define if_ih_remove(ifp, func, arg) /* nothing to do */
258#define if_hardmtu if_mtu 258#define if_hardmtu if_mtu
259#define IF_OUTPUT_CONST const 259#define IF_OUTPUT_CONST const
260#define si_note sel_klist 260#define si_note sel_klist
261#define klist_insert(klist, kn) \ 
262 SLIST_INSERT_HEAD(klist, kn, kn_selnext) 
263#define klist_remove(klist, kn) \ 
264 SLIST_REMOVE(klist, kn, knote, kn_selnext) 
265#define XMM_KQ_ISFD_INITIALIZER .f_flags = FILTEROP_ISFD 261#define XMM_KQ_ISFD_INITIALIZER .f_flags = FILTEROP_ISFD
266#define tty_lock() mutex_spin_enter(&tty_lock) 262#define tty_lock() mutex_spin_enter(&tty_lock)
267#define tty_unlock() mutex_spin_exit(&tty_lock) 263#define tty_unlock() mutex_spin_exit(&tty_lock)
268#define tty_locked() KASSERT(mutex_owned(&tty_lock)) 264#define tty_locked() KASSERT(mutex_owned(&tty_lock))
269#define bpfattach(bpf, ifp, dlt, sz) bpf_attach(ifp, dlt, sz) 265#define bpfattach(bpf, ifp, dlt, sz) bpf_attach(ifp, dlt, sz)
270#define NBPFILTER 1 266#define NBPFILTER 1
271#define BPF_MTAP_OUT(ifp, m) bpf_mtap(ifp, m, BPF_D_OUT) 267#define BPF_MTAP_OUT(ifp, m) bpf_mtap(ifp, m, BPF_D_OUT)
272#endif /* __NetBSD__ */ 268#endif /* __NetBSD__ */
273 269
274#define __user /* nothing */ 270#define __user /* nothing */
275#define copy_from_user(kbuf, userbuf, sz) \ 271#define copy_from_user(kbuf, userbuf, sz) \
276({ \ 272({ \
277 int __ret = 0; \ 273 int __ret = 0; \

cvs diff -r1.1 -r1.2 src/sys/external/bsd/drm2/linux/linux_sync_file.c (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/linux/linux_sync_file.c 2021/12/19 10:45:50 1.1
+++ src/sys/external/bsd/drm2/linux/linux_sync_file.c 2022/02/12 15:51:29 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: linux_sync_file.c,v 1.1 2021/12/19 10:45:50 riastradh Exp $ */ 1/* $NetBSD: linux_sync_file.c,v 1.2 2022/02/12 15:51:29 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: linux_sync_file.c,v 1.1 2021/12/19 10:45:50 riastradh Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: linux_sync_file.c,v 1.2 2022/02/12 15:51:29 thorpej Exp $");
31 31
32#include <sys/event.h> 32#include <sys/event.h>
33#include <sys/fcntl.h> 33#include <sys/fcntl.h>
34#include <sys/file.h> 34#include <sys/file.h>
35#include <sys/filedesc.h> 35#include <sys/filedesc.h>
36#include <sys/kmem.h> 36#include <sys/kmem.h>
37#include <sys/mutex.h> 37#include <sys/mutex.h>
38#include <sys/poll.h> 38#include <sys/poll.h>
39#include <sys/select.h> 39#include <sys/select.h>
40#include <sys/queue.h> 40#include <sys/queue.h>
41 41
42#include <linux/dma-fence.h> 42#include <linux/dma-fence.h>
43#include <linux/sync_file.h> 43#include <linux/sync_file.h>
@@ -126,41 +126,41 @@ sync_file_poll(struct file *fp, int even @@ -126,41 +126,41 @@ sync_file_poll(struct file *fp, int even
126 126
127static const struct filterops sync_file_filtops; 127static const struct filterops sync_file_filtops;
128 128
129static int 129static int
130sync_file_kqfilter(struct file *fp, struct knote *kn) 130sync_file_kqfilter(struct file *fp, struct knote *kn)
131{ 131{
132 struct sync_file *sf = fp->f_data; 132 struct sync_file *sf = fp->f_data;
133 133
134 switch (kn->kn_filter) { 134 switch (kn->kn_filter) {
135 case EVFILT_READ: 135 case EVFILT_READ:
136 kn->kn_fop = &sync_file_filtops; 136 kn->kn_fop = &sync_file_filtops;
137 kn->kn_hook = sf; 137 kn->kn_hook = sf;
138 mutex_enter(&sf->sf_lock); 138 mutex_enter(&sf->sf_lock);
139 SLIST_INSERT_HEAD(&sf->sf_selq.sel_klist, kn, kn_selnext); 139 klist_insert(&sf->sf_selq.sel_klist, kn);
140 mutex_exit(&sf->sf_lock); 140 mutex_exit(&sf->sf_lock);
141 return 0; 141 return 0;
142 default: 142 default:
143 return EINVAL; 143 return EINVAL;
144 } 144 }
145} 145}
146 146
147static void 147static void
148filt_sync_file_detach(struct knote *kn) 148filt_sync_file_detach(struct knote *kn)
149{ 149{
150 struct sync_file *sf = kn->kn_hook; 150 struct sync_file *sf = kn->kn_hook;
151 151
152 mutex_enter(&sf->sf_lock); 152 mutex_enter(&sf->sf_lock);
153 SLIST_REMOVE(&sf->sf_selq.sel_klist, kn, knote, kn_selnext); 153 klist_remove(&sf->sf_selq.sel_klist, kn);
154 mutex_exit(&sf->sf_lock); 154 mutex_exit(&sf->sf_lock);
155} 155}
156 156
157static int 157static int
158filt_sync_file_event(struct knote *kn, long hint) 158filt_sync_file_event(struct knote *kn, long hint)
159{ 159{
160 struct sync_file *sf = kn->kn_hook; 160 struct sync_file *sf = kn->kn_hook;
161 int ret; 161 int ret;
162 162
163 if (hint == NOTE_SUBMIT) 163 if (hint == NOTE_SUBMIT)
164 KASSERT(mutex_owned(&sf->sf_lock)); 164 KASSERT(mutex_owned(&sf->sf_lock));
165 else 165 else
166 mutex_enter(&sf->sf_lock); 166 mutex_enter(&sf->sf_lock);

cvs diff -r1.139 -r1.140 src/sys/kern/kern_event.c (expand / switch to unified diff)

--- src/sys/kern/kern_event.c 2022/01/01 10:54:21 1.139
+++ src/sys/kern/kern_event.c 2022/02/12 15:51:29 1.140
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_event.c,v 1.139 2022/01/01 10:54:21 msaitoh Exp $ */ 1/* $NetBSD: kern_event.c,v 1.140 2022/02/12 15:51:29 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008, 2009, 2021 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008, 2009, 2021 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran. 8 * by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -53,27 +53,27 @@ @@ -53,27 +53,27 @@
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE. 56 * SUCH DAMAGE.
57 * 57 *
58 * FreeBSD: src/sys/kern/kern_event.c,v 1.27 2001/07/05 17:10:44 rwatson Exp 58 * FreeBSD: src/sys/kern/kern_event.c,v 1.27 2001/07/05 17:10:44 rwatson Exp
59 */ 59 */
60 60
61#ifdef _KERNEL_OPT 61#ifdef _KERNEL_OPT
62#include "opt_ddb.h" 62#include "opt_ddb.h"
63#endif /* _KERNEL_OPT */ 63#endif /* _KERNEL_OPT */
64 64
65#include <sys/cdefs.h> 65#include <sys/cdefs.h>
66__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.139 2022/01/01 10:54:21 msaitoh Exp $"); 66__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.140 2022/02/12 15:51:29 thorpej Exp $");
67 67
68#include <sys/param.h> 68#include <sys/param.h>
69#include <sys/systm.h> 69#include <sys/systm.h>
70#include <sys/kernel.h> 70#include <sys/kernel.h>
71#include <sys/wait.h> 71#include <sys/wait.h>
72#include <sys/proc.h> 72#include <sys/proc.h>
73#include <sys/file.h> 73#include <sys/file.h>
74#include <sys/select.h> 74#include <sys/select.h>
75#include <sys/queue.h> 75#include <sys/queue.h>
76#include <sys/event.h> 76#include <sys/event.h>
77#include <sys/eventvar.h> 77#include <sys/eventvar.h>
78#include <sys/poll.h> 78#include <sys/poll.h>
79#include <sys/kmem.h> 79#include <sys/kmem.h>
@@ -780,27 +780,27 @@ filt_procattach(struct knote *kn) @@ -780,27 +780,27 @@ filt_procattach(struct knote *kn)
780 mutex_exit(p->p_lock); 780 mutex_exit(p->p_lock);
781 return EACCES; 781 return EACCES;
782 } 782 }
783 783
784 kn->kn_obj = p; 784 kn->kn_obj = p;
785 kn->kn_flags |= EV_CLEAR; /* automatically set */ 785 kn->kn_flags |= EV_CLEAR; /* automatically set */
786 786
787 /* 787 /*
788 * NOTE_CHILD is only ever generated internally; don't let it 788 * NOTE_CHILD is only ever generated internally; don't let it
789 * leak in from user-space. See knote_proc_fork_track(). 789 * leak in from user-space. See knote_proc_fork_track().
790 */ 790 */
791 kn->kn_sfflags &= ~NOTE_CHILD; 791 kn->kn_sfflags &= ~NOTE_CHILD;
792 792
793 SLIST_INSERT_HEAD(&p->p_klist, kn, kn_selnext); 793 klist_insert(&p->p_klist, kn);
794 mutex_exit(p->p_lock); 794 mutex_exit(p->p_lock);
795 795
796 return 0; 796 return 0;
797} 797}
798 798
799/* 799/*
800 * Filter detach method for EVFILT_PROC. 800 * Filter detach method for EVFILT_PROC.
801 * 801 *
802 * The knote may be attached to a different process, which may exit, 802 * The knote may be attached to a different process, which may exit,
803 * leaving nothing for the knote to be attached to. So when the process 803 * leaving nothing for the knote to be attached to. So when the process
804 * exits, the knote is marked as DETACHED and also flagged as ONESHOT so 804 * exits, the knote is marked as DETACHED and also flagged as ONESHOT so
805 * it will be deleted when read out. However, as part of the knote deletion, 805 * it will be deleted when read out. However, as part of the knote deletion,
806 * this routine is called, so a check is needed to avoid actually performing 806 * this routine is called, so a check is needed to avoid actually performing
@@ -818,27 +818,27 @@ filt_procdetach(struct knote *kn) @@ -818,27 +818,27 @@ filt_procdetach(struct knote *kn)
818 * because we can't be sure kn->kn_obj is valid unless 818 * because we can't be sure kn->kn_obj is valid unless
819 * KN_DETACHED is not set. 819 * KN_DETACHED is not set.
820 */ 820 */
821 again: 821 again:
822 mutex_spin_enter(&kq->kq_lock); 822 mutex_spin_enter(&kq->kq_lock);
823 if ((kn->kn_status & KN_DETACHED) == 0) { 823 if ((kn->kn_status & KN_DETACHED) == 0) {
824 p = kn->kn_obj; 824 p = kn->kn_obj;
825 if (!mutex_tryenter(p->p_lock)) { 825 if (!mutex_tryenter(p->p_lock)) {
826 mutex_spin_exit(&kq->kq_lock); 826 mutex_spin_exit(&kq->kq_lock);
827 preempt_point(); 827 preempt_point();
828 goto again; 828 goto again;
829 } 829 }
830 kn->kn_status |= KN_DETACHED; 830 kn->kn_status |= KN_DETACHED;
831 SLIST_REMOVE(&p->p_klist, kn, knote, kn_selnext); 831 klist_remove(&p->p_klist, kn);
832 mutex_exit(p->p_lock); 832 mutex_exit(p->p_lock);
833 } 833 }
834 mutex_spin_exit(&kq->kq_lock); 834 mutex_spin_exit(&kq->kq_lock);
835} 835}
836 836
837/* 837/*
838 * Filter event method for EVFILT_PROC. 838 * Filter event method for EVFILT_PROC.
839 * 839 *
840 * Due to some of the complexities of process locking, we have special 840 * Due to some of the complexities of process locking, we have special
841 * entry points for delivering knote submissions. filt_proc() is used 841 * entry points for delivering knote submissions. filt_proc() is used
842 * only to check for activation from kqueue_register() and kqueue_scan(). 842 * only to check for activation from kqueue_register() and kqueue_scan().
843 */ 843 */
844static int 844static int
@@ -1009,27 +1009,27 @@ knote_proc_fork_track(struct proc *p1, s @@ -1009,27 +1009,27 @@ knote_proc_fork_track(struct proc *p1, s
1009 * having to take p2->p_lock twice. But this is OK because we 1009 * having to take p2->p_lock twice. But this is OK because we
1010 * hold fd_lock across the entire operation. 1010 * hold fd_lock across the entire operation.
1011 */ 1011 */
1012 1012
1013 mutex_enter(p2->p_lock); 1013 mutex_enter(p2->p_lock);
1014 error = kauth_authorize_process(curlwp->l_cred, 1014 error = kauth_authorize_process(curlwp->l_cred,
1015 KAUTH_PROCESS_KEVENT_FILTER, p2, NULL, NULL, NULL); 1015 KAUTH_PROCESS_KEVENT_FILTER, p2, NULL, NULL, NULL);
1016 if (__predict_false(error != 0)) { 1016 if (__predict_false(error != 0)) {
1017 mutex_exit(p2->p_lock); 1017 mutex_exit(p2->p_lock);
1018 mutex_exit(&fdp->fd_lock); 1018 mutex_exit(&fdp->fd_lock);
1019 error = EACCES; 1019 error = EACCES;
1020 goto out; 1020 goto out;
1021 } 1021 }
1022 SLIST_INSERT_HEAD(&p2->p_klist, kntrack, kn_selnext); 1022 klist_insert(&p2->p_klist, kntrack);
1023 mutex_exit(p2->p_lock); 1023 mutex_exit(p2->p_lock);
1024 1024
1025 KASSERT(fdp->fd_knhashmask != 0); 1025 KASSERT(fdp->fd_knhashmask != 0);
1026 KASSERT(fdp->fd_knhash != NULL); 1026 KASSERT(fdp->fd_knhash != NULL);
1027 struct klist *list = &fdp->fd_knhash[KN_HASH(kntrack->kn_id, 1027 struct klist *list = &fdp->fd_knhash[KN_HASH(kntrack->kn_id,
1028 fdp->fd_knhashmask)]; 1028 fdp->fd_knhashmask)];
1029 SLIST_INSERT_HEAD(list, kntrack, kn_link); 1029 SLIST_INSERT_HEAD(list, kntrack, kn_link);
1030 SLIST_INSERT_HEAD(list, knchild, kn_link); 1030 SLIST_INSERT_HEAD(list, knchild, kn_link);
1031 1031
1032 /* This adds references for knchild *and* kntrack. */ 1032 /* This adds references for knchild *and* kntrack. */
1033 atomic_add_int(&kntrack->kn_kfilter->refcnt, 2); 1033 atomic_add_int(&kntrack->kn_kfilter->refcnt, 2);
1034 1034
1035 knote_activate(knchild); 1035 knote_activate(knchild);

cvs diff -r1.262 -r1.263 src/sys/kern/kern_proc.c (expand / switch to unified diff)

--- src/sys/kern/kern_proc.c 2020/12/24 12:14:50 1.262
+++ src/sys/kern/kern_proc.c 2022/02/12 15:51:29 1.263
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_proc.c,v 1.262 2020/12/24 12:14:50 nia Exp $ */ 1/* $NetBSD: kern_proc.c,v 1.263 2022/02/12 15:51:29 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center, and by Andrew Doran. 9 * NASA Ames Research Center, and by Andrew Doran.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -52,27 +52,27 @@ @@ -52,27 +52,27 @@
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE. 59 * SUCH DAMAGE.
60 * 60 *
61 * @(#)kern_proc.c 8.7 (Berkeley) 2/14/95 61 * @(#)kern_proc.c 8.7 (Berkeley) 2/14/95
62 */ 62 */
63 63
64#include <sys/cdefs.h> 64#include <sys/cdefs.h>
65__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.262 2020/12/24 12:14:50 nia Exp $"); 65__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.263 2022/02/12 15:51:29 thorpej Exp $");
66 66
67#ifdef _KERNEL_OPT 67#ifdef _KERNEL_OPT
68#include "opt_kstack.h" 68#include "opt_kstack.h"
69#include "opt_maxuprc.h" 69#include "opt_maxuprc.h"
70#include "opt_dtrace.h" 70#include "opt_dtrace.h"
71#include "opt_compat_netbsd32.h" 71#include "opt_compat_netbsd32.h"
72#include "opt_kaslr.h" 72#include "opt_kaslr.h"
73#endif 73#endif
74 74
75#if defined(__HAVE_COMPAT_NETBSD32) && !defined(COMPAT_NETBSD32) \ 75#if defined(__HAVE_COMPAT_NETBSD32) && !defined(COMPAT_NETBSD32) \
76 && !defined(_RUMPKERNEL) 76 && !defined(_RUMPKERNEL)
77#define COMPAT_NETBSD32 77#define COMPAT_NETBSD32
78#endif 78#endif
@@ -344,27 +344,37 @@ proc_listener_cb(kauth_cred_t cred, kaut @@ -344,27 +344,37 @@ proc_listener_cb(kauth_cred_t cred, kaut
344 344
345 break; 345 break;
346 346
347 default: 347 default:
348 break; 348 break;
349 } 349 }
350 350
351 return result; 351 return result;
352} 352}
353 353
354static int 354static int
355proc_ctor(void *arg __unused, void *obj, int flags __unused) 355proc_ctor(void *arg __unused, void *obj, int flags __unused)
356{ 356{
357 memset(obj, 0, sizeof(struct proc)); 357 struct proc *p = obj;
 358
 359 memset(p, 0, sizeof(*p));
 360 klist_init(&p->p_klist);
 361
 362 /*
 363 * There is no need for a proc_dtor() to do a klist_fini(),
 364 * since knote_proc_exit() ensures that p->p_klist is empty
 365 * when a process exits.
 366 */
 367
358 return 0; 368 return 0;
359} 369}
360 370
361static pid_t proc_alloc_pid_slot(struct proc *, uintptr_t); 371static pid_t proc_alloc_pid_slot(struct proc *, uintptr_t);
362 372
363/* 373/*
364 * Initialize global process hashing structures. 374 * Initialize global process hashing structures.
365 */ 375 */
366void 376void
367procinit(void) 377procinit(void)
368{ 378{
369 const struct proclist_desc *pd; 379 const struct proclist_desc *pd;
370 u_int i; 380 u_int i;

cvs diff -r1.400 -r1.401 src/sys/kern/kern_sig.c (expand / switch to unified diff)

--- src/sys/kern/kern_sig.c 2021/10/27 04:45:42 1.400
+++ src/sys/kern/kern_sig.c 2022/02/12 15:51:29 1.401
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_sig.c,v 1.400 2021/10/27 04:45:42 thorpej Exp $ */ 1/* $NetBSD: kern_sig.c,v 1.401 2022/02/12 15:51:29 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2006, 2007, 2008, 2019 The NetBSD Foundation, Inc. 4 * Copyright (c) 2006, 2007, 2008, 2019 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran. 8 * by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -60,27 +60,27 @@ @@ -60,27 +60,27 @@
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE. 63 * SUCH DAMAGE.
64 * 64 *
65 * @(#)kern_sig.c 8.14 (Berkeley) 5/14/95 65 * @(#)kern_sig.c 8.14 (Berkeley) 5/14/95
66 */ 66 */
67 67
68/* 68/*
69 * Signal subsystem. 69 * Signal subsystem.
70 */ 70 */
71 71
72#include <sys/cdefs.h> 72#include <sys/cdefs.h>
73__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.400 2021/10/27 04:45:42 thorpej Exp $"); 73__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.401 2022/02/12 15:51:29 thorpej Exp $");
74 74
75#include "opt_execfmt.h" 75#include "opt_execfmt.h"
76#include "opt_ptrace.h" 76#include "opt_ptrace.h"
77#include "opt_dtrace.h" 77#include "opt_dtrace.h"
78#include "opt_compat_sunos.h" 78#include "opt_compat_sunos.h"
79#include "opt_compat_netbsd.h" 79#include "opt_compat_netbsd.h"
80#include "opt_compat_netbsd32.h" 80#include "opt_compat_netbsd32.h"
81#include "opt_pax.h" 81#include "opt_pax.h"
82 82
83#define SIGPROP /* include signal properties table */ 83#define SIGPROP /* include signal properties table */
84#include <sys/param.h> 84#include <sys/param.h>
85#include <sys/signalvar.h> 85#include <sys/signalvar.h>
86#include <sys/proc.h> 86#include <sys/proc.h>
@@ -2650,39 +2650,39 @@ repeat: @@ -2650,39 +2650,39 @@ repeat:
2650 ktrpsig(signo, action, mask, &ksi); 2650 ktrpsig(signo, action, mask, &ksi);
2651 } 2651 }
2652} 2652}
2653 2653
2654static int 2654static int
2655filt_sigattach(struct knote *kn) 2655filt_sigattach(struct knote *kn)
2656{ 2656{
2657 struct proc *p = curproc; 2657 struct proc *p = curproc;
2658 2658
2659 kn->kn_obj = p; 2659 kn->kn_obj = p;
2660 kn->kn_flags |= EV_CLEAR; /* automatically set */ 2660 kn->kn_flags |= EV_CLEAR; /* automatically set */
2661 2661
2662 mutex_enter(p->p_lock); 2662 mutex_enter(p->p_lock);
2663 SLIST_INSERT_HEAD(&p->p_klist, kn, kn_selnext); 2663 klist_insert(&p->p_klist, kn);
2664 mutex_exit(p->p_lock); 2664 mutex_exit(p->p_lock);
2665 2665
2666 return 0; 2666 return 0;
2667} 2667}
2668 2668
2669static void 2669static void
2670filt_sigdetach(struct knote *kn) 2670filt_sigdetach(struct knote *kn)
2671{ 2671{
2672 struct proc *p = kn->kn_obj; 2672 struct proc *p = kn->kn_obj;
2673 2673
2674 mutex_enter(p->p_lock); 2674 mutex_enter(p->p_lock);
2675 SLIST_REMOVE(&p->p_klist, kn, knote, kn_selnext); 2675 klist_remove(&p->p_klist, kn);
2676 mutex_exit(p->p_lock); 2676 mutex_exit(p->p_lock);
2677} 2677}
2678 2678
2679/* 2679/*
2680 * Signal knotes are shared with proc knotes, so we apply a mask to 2680 * Signal knotes are shared with proc knotes, so we apply a mask to
2681 * the hint in order to differentiate them from process hints. This 2681 * the hint in order to differentiate them from process hints. This
2682 * could be avoided by using a signal-specific knote list, but probably 2682 * could be avoided by using a signal-specific knote list, but probably
2683 * isn't worth the trouble. 2683 * isn't worth the trouble.
2684 */ 2684 */
2685static int 2685static int
2686filt_signal(struct knote *kn, long hint) 2686filt_signal(struct knote *kn, long hint)
2687{ 2687{
2688 2688

cvs diff -r1.57 -r1.58 src/sys/kern/sys_select.c (expand / switch to unified diff)

--- src/sys/kern/sys_select.c 2021/12/10 20:36:04 1.57
+++ src/sys/kern/sys_select.c 2022/02/12 15:51:29 1.58
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sys_select.c,v 1.57 2021/12/10 20:36:04 andvar Exp $ */ 1/* $NetBSD: sys_select.c,v 1.58 2022/02/12 15:51:29 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007, 2008, 2009, 2010, 2019, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2007, 2008, 2009, 2010, 2019, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran and Mindaugas Rasiukevicius. 8 * by Andrew Doran and Mindaugas Rasiukevicius.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -74,27 +74,27 @@ @@ -74,27 +74,27 @@
74 * 74 *
75 * The <object-lock> might be a device driver or another subsystem, e.g. 75 * The <object-lock> might be a device driver or another subsystem, e.g.
76 * socket or pipe. This lock is not exported, and thus invisible to this 76 * socket or pipe. This lock is not exported, and thus invisible to this
77 * subsystem. Mainly, synchronisation between selrecord() and selnotify() 77 * subsystem. Mainly, synchronisation between selrecord() and selnotify()
78 * routines depends on this lock, as it will be described in the comments. 78 * routines depends on this lock, as it will be described in the comments.
79 * 79 *
80 * Lock order 80 * Lock order
81 * 81 *
82 * <object-lock> -> 82 * <object-lock> ->
83 * selcluster_t::sc_lock 83 * selcluster_t::sc_lock
84 */ 84 */
85 85
86#include <sys/cdefs.h> 86#include <sys/cdefs.h>
87__KERNEL_RCSID(0, "$NetBSD: sys_select.c,v 1.57 2021/12/10 20:36:04 andvar Exp $"); 87__KERNEL_RCSID(0, "$NetBSD: sys_select.c,v 1.58 2022/02/12 15:51:29 thorpej Exp $");
88 88
89#include <sys/param.h> 89#include <sys/param.h>
90#include <sys/systm.h> 90#include <sys/systm.h>
91#include <sys/filedesc.h> 91#include <sys/filedesc.h>
92#include <sys/file.h> 92#include <sys/file.h>
93#include <sys/proc.h> 93#include <sys/proc.h>
94#include <sys/socketvar.h> 94#include <sys/socketvar.h>
95#include <sys/signalvar.h> 95#include <sys/signalvar.h>
96#include <sys/uio.h> 96#include <sys/uio.h>
97#include <sys/kernel.h> 97#include <sys/kernel.h>
98#include <sys/lwp.h> 98#include <sys/lwp.h>
99#include <sys/poll.h> 99#include <sys/poll.h>
100#include <sys/mount.h> 100#include <sys/mount.h>
@@ -665,42 +665,41 @@ selrecord(lwp_t *selector, struct selinf @@ -665,42 +665,41 @@ selrecord(lwp_t *selector, struct selinf
665 sip->sel_collision |= sc->sc_mask; 665 sip->sel_collision |= sc->sc_mask;
666 KASSERT(sip->sel_cluster != NULL); 666 KASSERT(sip->sel_cluster != NULL);
667 } 667 }
668} 668}
669 669
670/* 670/*
671 * Record a knote. 671 * Record a knote.
672 * 672 *
673 * The caller holds the same lock as for selrecord(). 673 * The caller holds the same lock as for selrecord().
674 */ 674 */
675void 675void
676selrecord_knote(struct selinfo *sip, struct knote *kn) 676selrecord_knote(struct selinfo *sip, struct knote *kn)
677{ 677{
678 SLIST_INSERT_HEAD(&sip->sel_klist, kn, kn_selnext); 678 klist_insert(&sip->sel_klist, kn);
679} 679}
680 680
681/* 681/*
682 * Remove a knote. 682 * Remove a knote.
683 * 683 *
684 * The caller holds the same lock as for selrecord(). 684 * The caller holds the same lock as for selrecord().
685 * 685 *
686 * Returns true if the last knote was removed and the list 686 * Returns true if the last knote was removed and the list
687 * is now empty. 687 * is now empty.
688 */ 688 */
689bool 689bool
690selremove_knote(struct selinfo *sip, struct knote *kn) 690selremove_knote(struct selinfo *sip, struct knote *kn)
691{ 691{
692 SLIST_REMOVE(&sip->sel_klist, kn, knote, kn_selnext); 692 return klist_remove(&sip->sel_klist, kn);
693 return SLIST_EMPTY(&sip->sel_klist); 
694} 693}
695 694
696/* 695/*
697 * sel_setevents: a helper function for selnotify(), to set the events 696 * sel_setevents: a helper function for selnotify(), to set the events
698 * for LWP sleeping in selcommon() or pollcommon(). 697 * for LWP sleeping in selcommon() or pollcommon().
699 */ 698 */
700static inline bool 699static inline bool
701sel_setevents(lwp_t *l, struct selinfo *sip, const int events) 700sel_setevents(lwp_t *l, struct selinfo *sip, const int events)
702{ 701{
703 const int oflag = l->l_selflag; 702 const int oflag = l->l_selflag;
704 int ret = 0; 703 int ret = 0;
705 704
706 /* 705 /*
@@ -904,45 +903,48 @@ selsysinit(struct cpu_info *ci) @@ -904,45 +903,48 @@ selsysinit(struct cpu_info *ci)
904 selcluster[index] = sc; 903 selcluster[index] = sc;
905 } 904 }
906 ci->ci_data.cpu_selcluster = sc; 905 ci->ci_data.cpu_selcluster = sc;
907} 906}
908 907
909/* 908/*
910 * Initialize a selinfo record. 909 * Initialize a selinfo record.
911 */ 910 */
912void 911void
913selinit(struct selinfo *sip) 912selinit(struct selinfo *sip)
914{ 913{
915 914
916 memset(sip, 0, sizeof(*sip)); 915 memset(sip, 0, sizeof(*sip));
 916 klist_init(&sip->sel_klist);
917} 917}
918 918
919/* 919/*
920 * Destroy a selinfo record. The owning object must not gain new 920 * Destroy a selinfo record. The owning object must not gain new
921 * references while this is in progress: all activity on the record 921 * references while this is in progress: all activity on the record
922 * must be stopped. 922 * must be stopped.
923 * 923 *
924 * Concurrency issues: we only need guard against a call to selclear() 924 * Concurrency issues: we only need guard against a call to selclear()
925 * by a thread exiting sel_do_scan(). The caller has prevented further 925 * by a thread exiting sel_do_scan(). The caller has prevented further
926 * references being made to the selinfo record via selrecord(), and it 926 * references being made to the selinfo record via selrecord(), and it
927 * will not call selnotify() again. 927 * will not call selnotify() again.
928 */ 928 */
929void 929void
930seldestroy(struct selinfo *sip) 930seldestroy(struct selinfo *sip)
931{ 931{
932 selcluster_t *sc; 932 selcluster_t *sc;
933 kmutex_t *lock; 933 kmutex_t *lock;
934 lwp_t *l; 934 lwp_t *l;
935 935
 936 klist_fini(&sip->sel_klist);
 937
936 if (sip->sel_lwp == NULL) 938 if (sip->sel_lwp == NULL)
937 return; 939 return;
938 940
939 /* 941 /*
940 * Lock out selclear(). The selcluster pointer can't change while 942 * Lock out selclear(). The selcluster pointer can't change while
941 * we are here since it is only ever changed in selrecord(), 943 * we are here since it is only ever changed in selrecord(),
942 * and that will not be entered again for this record because 944 * and that will not be entered again for this record because
943 * it is dying. 945 * it is dying.
944 */ 946 */
945 KASSERT(sip->sel_cluster != NULL); 947 KASSERT(sip->sel_cluster != NULL);
946 sc = sip->sel_cluster; 948 sc = sip->sel_cluster;
947 lock = sc->sc_lock; 949 lock = sc->sc_lock;
948 mutex_spin_enter(lock); 950 mutex_spin_enter(lock);

cvs diff -r1.53 -r1.54 src/sys/kern/vfs_init.c (expand / switch to unified diff)

--- src/sys/kern/vfs_init.c 2021/09/26 21:29:38 1.53
+++ src/sys/kern/vfs_init.c 2022/02/12 15:51:29 1.54
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vfs_init.c,v 1.53 2021/09/26 21:29:38 thorpej Exp $ */ 1/* $NetBSD: vfs_init.c,v 1.54 2022/02/12 15:51:29 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center. 9 * NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -57,27 +57,27 @@ @@ -57,27 +57,27 @@
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE. 64 * SUCH DAMAGE.
65 * 65 *
66 * @(#)vfs_init.c 8.5 (Berkeley) 5/11/95 66 * @(#)vfs_init.c 8.5 (Berkeley) 5/11/95
67 */ 67 */
68 68
69#include <sys/cdefs.h> 69#include <sys/cdefs.h>
70__KERNEL_RCSID(0, "$NetBSD: vfs_init.c,v 1.53 2021/09/26 21:29:38 thorpej Exp $"); 70__KERNEL_RCSID(0, "$NetBSD: vfs_init.c,v 1.54 2022/02/12 15:51:29 thorpej Exp $");
71 71
72#include <sys/param.h> 72#include <sys/param.h>
73#include <sys/mount.h> 73#include <sys/mount.h>
74#include <sys/time.h> 74#include <sys/time.h>
75#include <sys/vnode.h> 75#include <sys/vnode.h>
76#include <sys/stat.h> 76#include <sys/stat.h>
77#include <sys/namei.h> 77#include <sys/namei.h>
78#include <sys/ucred.h> 78#include <sys/ucred.h>
79#include <sys/buf.h> 79#include <sys/buf.h>
80#include <sys/errno.h> 80#include <sys/errno.h>
81#include <sys/kmem.h> 81#include <sys/kmem.h>
82#include <sys/systm.h> 82#include <sys/systm.h>
83#include <sys/module.h> 83#include <sys/module.h>
@@ -446,28 +446,30 @@ vfsinit(void) @@ -446,28 +446,30 @@ vfsinit(void)
446 * Initialise VFS hooks. 446 * Initialise VFS hooks.
447 */ 447 */
448 vfs_hooks_init(); 448 vfs_hooks_init();
449 449
450 mount_listener = kauth_listen_scope(KAUTH_SCOPE_SYSTEM, 450 mount_listener = kauth_listen_scope(KAUTH_SCOPE_SYSTEM,
451 mount_listener_cb, NULL); 451 mount_listener_cb, NULL);
452 452
453 /* 453 /*
454 * Establish each file system which was statically 454 * Establish each file system which was statically
455 * included in the kernel. 455 * included in the kernel.
456 */ 456 */
457 module_init_class(MODULE_CLASS_VFS); 457 module_init_class(MODULE_CLASS_VFS);
458 458
459 extern kmutex_t fs_klist_lock; 459 /*
460 mutex_init(&fs_klist_lock, MUTEX_DEFAULT, IPL_NONE); 460 * Initialize EVFILT_FS for kqueue.
 461 */
 462 vfs_evfilt_fs_init();
461} 463}
462 464
463/* 465/*
464 * Drop a reference to a file system type. 466 * Drop a reference to a file system type.
465 */ 467 */
466void 468void
467vfs_delref(struct vfsops *vfs) 469vfs_delref(struct vfsops *vfs)
468{ 470{
469 471
470 mutex_enter(&vfs_list_lock); 472 mutex_enter(&vfs_list_lock);
471 vfs->vfs_refcount--; 473 vfs->vfs_refcount--;
472 mutex_exit(&vfs_list_lock); 474 mutex_exit(&vfs_list_lock);
473} 475}

cvs diff -r1.554 -r1.555 src/sys/kern/vfs_syscalls.c (expand / switch to unified diff)

--- src/sys/kern/vfs_syscalls.c 2021/11/07 13:47:50 1.554
+++ src/sys/kern/vfs_syscalls.c 2022/02/12 15:51:29 1.555
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vfs_syscalls.c,v 1.554 2021/11/07 13:47:50 christos Exp $ */ 1/* $NetBSD: vfs_syscalls.c,v 1.555 2022/02/12 15:51:29 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2008, 2009, 2019, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008, 2009, 2019, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran. 8 * by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -60,27 +60,27 @@ @@ -60,27 +60,27 @@
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE. 63 * SUCH DAMAGE.
64 * 64 *
65 * @(#)vfs_syscalls.c 8.42 (Berkeley) 7/31/95 65 * @(#)vfs_syscalls.c 8.42 (Berkeley) 7/31/95
66 */ 66 */
67 67
68/* 68/*
69 * Virtual File System System Calls 69 * Virtual File System System Calls
70 */ 70 */
71 71
72#include <sys/cdefs.h> 72#include <sys/cdefs.h>
73__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.554 2021/11/07 13:47:50 christos Exp $"); 73__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.555 2022/02/12 15:51:29 thorpej Exp $");
74 74
75#ifdef _KERNEL_OPT 75#ifdef _KERNEL_OPT
76#include "opt_fileassoc.h" 76#include "opt_fileassoc.h"
77#include "veriexec.h" 77#include "veriexec.h"
78#endif 78#endif
79 79
80#include <sys/param.h> 80#include <sys/param.h>
81#include <sys/systm.h> 81#include <sys/systm.h>
82#include <sys/namei.h> 82#include <sys/namei.h>
83#include <sys/filedesc.h> 83#include <sys/filedesc.h>
84#include <sys/kernel.h> 84#include <sys/kernel.h>
85#include <sys/file.h> 85#include <sys/file.h>
86#include <sys/fcntl.h> 86#include <sys/fcntl.h>
@@ -158,48 +158,55 @@ const char * const mountcompatnames[] =  @@ -158,48 +158,55 @@ const char * const mountcompatnames[] =
158 MOUNT_MSDOS, /* 4 */ 158 MOUNT_MSDOS, /* 4 */
159 MOUNT_CD9660, /* 5 = MOUNT_ISOFS */ 159 MOUNT_CD9660, /* 5 = MOUNT_ISOFS */
160 MOUNT_FDESC, /* 6 */ 160 MOUNT_FDESC, /* 6 */
161 MOUNT_KERNFS, /* 7 */ 161 MOUNT_KERNFS, /* 7 */
162 NULL, /* 8 = MOUNT_DEVFS */ 162 NULL, /* 8 = MOUNT_DEVFS */
163 MOUNT_AFS, /* 9 */ 163 MOUNT_AFS, /* 9 */
164}; 164};
165 165
166const u_int nmountcompatnames = __arraycount(mountcompatnames); 166const u_int nmountcompatnames = __arraycount(mountcompatnames);
167 167
168/* 168/*
169 * Filter event method for EVFILT_FS. 169 * Filter event method for EVFILT_FS.
170 */ 170 */
171static struct klist fs_klist = SLIST_HEAD_INITIALIZER(&fs_klist); 171static struct klist fs_klist;
172kmutex_t fs_klist_lock; 172static kmutex_t fs_klist_lock;
173 173
174CTASSERT((NOTE_SUBMIT & VQ_MOUNT) == 0); 174CTASSERT((NOTE_SUBMIT & VQ_MOUNT) == 0);
175CTASSERT((NOTE_SUBMIT & VQ_UNMOUNT) == 0); 175CTASSERT((NOTE_SUBMIT & VQ_UNMOUNT) == 0);
176 176
 177void
 178vfs_evfilt_fs_init(void)
 179{
 180 klist_init(&fs_klist);
 181 mutex_init(&fs_klist_lock, MUTEX_DEFAULT, IPL_NONE);
 182}
 183
177static int 184static int
178filt_fsattach(struct knote *kn) 185filt_fsattach(struct knote *kn)
179{ 186{
180 mutex_enter(&fs_klist_lock); 187 mutex_enter(&fs_klist_lock);
181 kn->kn_flags |= EV_CLEAR; 188 kn->kn_flags |= EV_CLEAR;
182 SLIST_INSERT_HEAD(&fs_klist, kn, kn_selnext); 189 klist_insert(&fs_klist, kn);
183 mutex_exit(&fs_klist_lock); 190 mutex_exit(&fs_klist_lock);
184 191
185 return 0; 192 return 0;
186} 193}
187 194
188static void 195static void
189filt_fsdetach(struct knote *kn) 196filt_fsdetach(struct knote *kn)
190{ 197{
191 mutex_enter(&fs_klist_lock); 198 mutex_enter(&fs_klist_lock);
192 SLIST_REMOVE(&fs_klist, kn, knote, kn_selnext); 199 klist_remove(&fs_klist, kn);
193 mutex_exit(&fs_klist_lock); 200 mutex_exit(&fs_klist_lock);
194} 201}
195 202
196static int 203static int
197filt_fs(struct knote *kn, long hint) 204filt_fs(struct knote *kn, long hint)
198{ 205{
199 int rv; 206 int rv;
200 207
201 if (hint & NOTE_SUBMIT) { 208 if (hint & NOTE_SUBMIT) {
202 KASSERT(mutex_owned(&fs_klist_lock)); 209 KASSERT(mutex_owned(&fs_klist_lock));
203 kn->kn_fflags |= hint & ~NOTE_SUBMIT; 210 kn->kn_fflags |= hint & ~NOTE_SUBMIT;
204 } else { 211 } else {
205 mutex_enter(&fs_klist_lock); 212 mutex_enter(&fs_klist_lock);

cvs diff -r1.129 -r1.130 src/sys/kern/vfs_vnode.c (expand / switch to unified diff)

--- src/sys/kern/vfs_vnode.c 2022/02/08 08:57:11 1.129
+++ src/sys/kern/vfs_vnode.c 2022/02/12 15:51:29 1.130
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vfs_vnode.c,v 1.129 2022/02/08 08:57:11 hannken Exp $ */ 1/* $NetBSD: vfs_vnode.c,v 1.130 2022/02/12 15:51:29 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997-2011, 2019, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997-2011, 2019, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center, by Charles M. Hannum, and by Andrew Doran. 9 * NASA Ames Research Center, by Charles M. Hannum, and by Andrew Doran.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -138,27 +138,27 @@ @@ -138,27 +138,27 @@
138 * 138 *
139 * Reference counting 139 * Reference counting
140 * 140 *
141 * Vnode is considered active, if reference count (vnode_t::v_usecount) 141 * Vnode is considered active, if reference count (vnode_t::v_usecount)
142 * is non-zero. It is maintained using: vref(9) and vrele(9), as well 142 * is non-zero. It is maintained using: vref(9) and vrele(9), as well
143 * as vput(9), routines. Common points holding references are e.g. 143 * as vput(9), routines. Common points holding references are e.g.
144 * file openings, current working directory, mount points, etc.  144 * file openings, current working directory, mount points, etc.
145 * 145 *
146 * v_usecount is adjusted with atomic operations, however to change 146 * v_usecount is adjusted with atomic operations, however to change
147 * from a non-zero value to zero the interlock must also be held. 147 * from a non-zero value to zero the interlock must also be held.
148 */ 148 */
149 149
150#include <sys/cdefs.h> 150#include <sys/cdefs.h>
151__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.129 2022/02/08 08:57:11 hannken Exp $"); 151__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.130 2022/02/12 15:51:29 thorpej Exp $");
152 152
153#ifdef _KERNEL_OPT 153#ifdef _KERNEL_OPT
154#include "opt_pax.h" 154#include "opt_pax.h"
155#endif 155#endif
156 156
157#include <sys/param.h> 157#include <sys/param.h>
158#include <sys/kernel.h> 158#include <sys/kernel.h>
159 159
160#include <sys/atomic.h> 160#include <sys/atomic.h>
161#include <sys/buf.h> 161#include <sys/buf.h>
162#include <sys/conf.h> 162#include <sys/conf.h>
163#include <sys/device.h> 163#include <sys/device.h>
164#include <sys/hash.h> 164#include <sys/hash.h>
@@ -434,43 +434,45 @@ vfs_vnode_sysinit(void) @@ -434,43 +434,45 @@ vfs_vnode_sysinit(void)
434vnode_t * 434vnode_t *
435vnalloc_marker(struct mount *mp) 435vnalloc_marker(struct mount *mp)
436{ 436{
437 vnode_impl_t *vip; 437 vnode_impl_t *vip;
438 vnode_t *vp; 438 vnode_t *vp;
439 439
440 vip = pool_cache_get(vcache_pool, PR_WAITOK); 440 vip = pool_cache_get(vcache_pool, PR_WAITOK);
441 memset(vip, 0, sizeof(*vip)); 441 memset(vip, 0, sizeof(*vip));
442 vp = VIMPL_TO_VNODE(vip); 442 vp = VIMPL_TO_VNODE(vip);
443 uvm_obj_init(&vp->v_uobj, &uvm_vnodeops, true, 1); 443 uvm_obj_init(&vp->v_uobj, &uvm_vnodeops, true, 1);
444 vp->v_mount = mp; 444 vp->v_mount = mp;
445 vp->v_type = VBAD; 445 vp->v_type = VBAD;
446 vp->v_interlock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE); 446 vp->v_interlock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
 447 klist_init(&vp->v_klist);
447 vip->vi_state = VS_MARKER; 448 vip->vi_state = VS_MARKER;
448 449
449 return vp; 450 return vp;
450} 451}
451 452
452/* 453/*
453 * Free a marker vnode. 454 * Free a marker vnode.
454 */ 455 */
455void 456void
456vnfree_marker(vnode_t *vp) 457vnfree_marker(vnode_t *vp)
457{ 458{
458 vnode_impl_t *vip; 459 vnode_impl_t *vip;
459 460
460 vip = VNODE_TO_VIMPL(vp); 461 vip = VNODE_TO_VIMPL(vp);
461 KASSERT(vip->vi_state == VS_MARKER); 462 KASSERT(vip->vi_state == VS_MARKER);
462 mutex_obj_free(vp->v_interlock); 463 mutex_obj_free(vp->v_interlock);
463 uvm_obj_destroy(&vp->v_uobj, true); 464 uvm_obj_destroy(&vp->v_uobj, true);
 465 klist_fini(&vp->v_klist);
464 pool_cache_put(vcache_pool, vip); 466 pool_cache_put(vcache_pool, vip);
465} 467}
466 468
467/* 469/*
468 * Test a vnode for being a marker vnode. 470 * Test a vnode for being a marker vnode.
469 */ 471 */
470bool 472bool
471vnis_marker(vnode_t *vp) 473vnis_marker(vnode_t *vp)
472{ 474{
473 475
474 return (VNODE_TO_VIMPL(vp)->vi_state == VS_MARKER); 476 return (VNODE_TO_VIMPL(vp)->vi_state == VS_MARKER);
475} 477}
476 478
@@ -1297,26 +1299,27 @@ static vnode_impl_t * @@ -1297,26 +1299,27 @@ static vnode_impl_t *
1297vcache_alloc(void) 1299vcache_alloc(void)
1298{ 1300{
1299 vnode_impl_t *vip; 1301 vnode_impl_t *vip;
1300 vnode_t *vp; 1302 vnode_t *vp;
1301 1303
1302 vip = pool_cache_get(vcache_pool, PR_WAITOK); 1304 vip = pool_cache_get(vcache_pool, PR_WAITOK);
1303 vp = VIMPL_TO_VNODE(vip); 1305 vp = VIMPL_TO_VNODE(vip);
1304 memset(vip, 0, sizeof(*vip)); 1306 memset(vip, 0, sizeof(*vip));
1305 1307
1306 rw_init(&vip->vi_lock); 1308 rw_init(&vip->vi_lock);
1307 vp->v_interlock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE); 1309 vp->v_interlock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
1308 1310
1309 uvm_obj_init(&vp->v_uobj, &uvm_vnodeops, true, 1); 1311 uvm_obj_init(&vp->v_uobj, &uvm_vnodeops, true, 1);
 1312 klist_init(&vp->v_klist);
1310 cv_init(&vp->v_cv, "vnode"); 1313 cv_init(&vp->v_cv, "vnode");
1311 cache_vnode_init(vp); 1314 cache_vnode_init(vp);
1312 1315
1313 vp->v_usecount = 1; 1316 vp->v_usecount = 1;
1314 vp->v_type = VNON; 1317 vp->v_type = VNON;
1315 vp->v_size = vp->v_writesize = VSIZENOTSET; 1318 vp->v_size = vp->v_writesize = VSIZENOTSET;
1316 1319
1317 vip->vi_state = VS_LOADING; 1320 vip->vi_state = VS_LOADING;
1318 1321
1319 lru_requeue(vp, &lru_list[LRU_FREE]); 1322 lru_requeue(vp, &lru_list[LRU_FREE]);
1320 1323
1321 return vip; 1324 return vip;
1322} 1325}
@@ -1358,26 +1361,27 @@ vcache_free(vnode_impl_t *vip) @@ -1358,26 +1361,27 @@ vcache_free(vnode_impl_t *vip)
1358 KASSERT(vrefcnt(vp) == 0); 1361 KASSERT(vrefcnt(vp) == 0);
1359 KASSERT(vp->v_holdcnt == 0); 1362 KASSERT(vp->v_holdcnt == 0);
1360 KASSERT(vp->v_writecount == 0); 1363 KASSERT(vp->v_writecount == 0);
1361 lru_requeue(vp, NULL); 1364 lru_requeue(vp, NULL);
1362 mutex_exit(vp->v_interlock); 1365 mutex_exit(vp->v_interlock);
1363 1366
1364 vfs_insmntque(vp, NULL); 1367 vfs_insmntque(vp, NULL);
1365 if (vp->v_type == VBLK || vp->v_type == VCHR) 1368 if (vp->v_type == VBLK || vp->v_type == VCHR)
1366 spec_node_destroy(vp); 1369 spec_node_destroy(vp);
1367 1370
1368 mutex_obj_free(vp->v_interlock); 1371 mutex_obj_free(vp->v_interlock);
1369 rw_destroy(&vip->vi_lock); 1372 rw_destroy(&vip->vi_lock);
1370 uvm_obj_destroy(&vp->v_uobj, true); 1373 uvm_obj_destroy(&vp->v_uobj, true);
 1374 klist_fini(&vp->v_klist);
1371 cv_destroy(&vp->v_cv); 1375 cv_destroy(&vp->v_cv);
1372 cache_vnode_fini(vp); 1376 cache_vnode_fini(vp);
1373 pool_cache_put(vcache_pool, vip); 1377 pool_cache_put(vcache_pool, vip);
1374} 1378}
1375 1379
1376/* 1380/*
1377 * Try to get an initial reference on this cached vnode. 1381 * Try to get an initial reference on this cached vnode.
1378 * Returns zero on success or EBUSY if the vnode state is not LOADED. 1382 * Returns zero on success or EBUSY if the vnode state is not LOADED.
1379 * 1383 *
1380 * NB: lockless code sequences may rely on this not blocking. 1384 * NB: lockless code sequences may rely on this not blocking.
1381 */ 1385 */
1382int 1386int
1383vcache_tryvget(vnode_t *vp) 1387vcache_tryvget(vnode_t *vp)

cvs diff -r1.51 -r1.52 src/sys/sys/event.h (expand / switch to unified diff)

--- src/sys/sys/event.h 2021/10/23 01:28:33 1.51
+++ src/sys/sys/event.h 2022/02/12 15:51:29 1.52
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: event.h,v 1.51 2021/10/23 01:28:33 thorpej Exp $ */ 1/* $NetBSD: event.h,v 1.52 2022/02/12 15:51:29 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org> 4 * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -324,26 +324,51 @@ int kevent_fetch_changes(void *, const s @@ -324,26 +324,51 @@ int kevent_fetch_changes(void *, const s
324 size_t, int); 324 size_t, int);
325int kevent_put_events(void *, struct kevent *, struct kevent *, size_t, 325int kevent_put_events(void *, struct kevent *, struct kevent *, size_t,
326 int); 326 int);
327int kevent1(register_t *, int, const struct kevent *, 327int kevent1(register_t *, int, const struct kevent *,
328 size_t, struct kevent *, size_t, const struct timespec *, 328 size_t, struct kevent *, size_t, const struct timespec *,
329 const struct kevent_ops *); 329 const struct kevent_ops *);
330 330
331int kfilter_register(const char *, const struct filterops *, int *); 331int kfilter_register(const char *, const struct filterops *, int *);
332int kfilter_unregister(const char *); 332int kfilter_unregister(const char *);
333 333
334int filt_seltrue(struct knote *, long); 334int filt_seltrue(struct knote *, long);
335extern const struct filterops seltrue_filtops; 335extern const struct filterops seltrue_filtops;
336 336
 337static inline void
 338klist_init(struct klist *list)
 339{
 340 SLIST_INIT(list);
 341}
 342
 343static inline void
 344klist_fini(struct klist *list)
 345{
 346 /* Nothing, for now. */
 347}
 348
 349static inline void
 350klist_insert(struct klist *list, struct knote *kn)
 351{
 352 SLIST_INSERT_HEAD(list, kn, kn_selnext);
 353}
 354
 355static inline bool
 356klist_remove(struct klist *list, struct knote *kn)
 357{
 358 SLIST_REMOVE(list, kn, knote, kn_selnext);
 359 return SLIST_EMPTY(list);
 360}
 361
337#else /* !_KERNEL */ 362#else /* !_KERNEL */
338 363
339#include <sys/cdefs.h> 364#include <sys/cdefs.h>
340struct timespec; 365struct timespec;
341 366
342__BEGIN_DECLS 367__BEGIN_DECLS
343#if defined(_NETBSD_SOURCE) 368#if defined(_NETBSD_SOURCE)
344int kqueue(void); 369int kqueue(void);
345int kqueue1(int); 370int kqueue1(int);
346#ifndef __LIBC12_SOURCE__ 371#ifndef __LIBC12_SOURCE__
347int kevent(int, const struct kevent *, size_t, struct kevent *, size_t, 372int kevent(int, const struct kevent *, size_t, struct kevent *, size_t,
348 const struct timespec *) __RENAME(__kevent50); 373 const struct timespec *) __RENAME(__kevent50);
349#endif 374#endif

cvs diff -r1.237 -r1.238 src/sys/sys/mount.h (expand / switch to unified diff)

--- src/sys/sys/mount.h 2021/02/04 21:07:06 1.237
+++ src/sys/sys/mount.h 2022/02/12 15:51:29 1.238
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: mount.h,v 1.237 2021/02/04 21:07:06 jdolecek Exp $ */ 1/* $NetBSD: mount.h,v 1.238 2022/02/12 15:51:29 thorpej Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1989, 1991, 1993 4 * Copyright (c) 1989, 1991, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -440,26 +440,27 @@ void vfs_syncer_remove_from_worklist(str @@ -440,26 +440,27 @@ void vfs_syncer_remove_from_worklist(str
440 440
441extern struct vfsops *vfssw[]; /* filesystem type table */ 441extern struct vfsops *vfssw[]; /* filesystem type table */
442extern int nvfssw; 442extern int nvfssw;
443extern kmutex_t vfs_list_lock; 443extern kmutex_t vfs_list_lock;
444 444
445void vfs_mount_sysinit(void); 445void vfs_mount_sysinit(void);
446long makefstype(const char *); 446long makefstype(const char *);
447int mount_domount(struct lwp *, struct vnode **, struct vfsops *, 447int mount_domount(struct lwp *, struct vnode **, struct vfsops *,
448 const char *, int, void *, size_t *); 448 const char *, int, void *, size_t *);
449int dounmount(struct mount *, int, struct lwp *); 449int dounmount(struct mount *, int, struct lwp *);
450int do_sys_mount(struct lwp *, const char *, enum uio_seg, const char *, 450int do_sys_mount(struct lwp *, const char *, enum uio_seg, const char *,
451 int, void *, enum uio_seg, size_t, register_t *); 451 int, void *, enum uio_seg, size_t, register_t *);
452void vfsinit(void); 452void vfsinit(void);
 453void vfs_evfilt_fs_init(void);
453void vfs_opv_init(const struct vnodeopv_desc * const *); 454void vfs_opv_init(const struct vnodeopv_desc * const *);
454void vfs_opv_free(const struct vnodeopv_desc * const *); 455void vfs_opv_free(const struct vnodeopv_desc * const *);
455#ifdef DEBUG 456#ifdef DEBUG
456void vfs_bufstats(void); 457void vfs_bufstats(void);
457#endif 458#endif
458 459
459int mount_specific_key_create(specificdata_key_t *, specificdata_dtor_t); 460int mount_specific_key_create(specificdata_key_t *, specificdata_dtor_t);
460void mount_specific_key_delete(specificdata_key_t); 461void mount_specific_key_delete(specificdata_key_t);
461void mount_initspecific(struct mount *); 462void mount_initspecific(struct mount *);
462void mount_finispecific(struct mount *); 463void mount_finispecific(struct mount *);
463void * mount_getspecific(struct mount *, specificdata_key_t); 464void * mount_getspecific(struct mount *, specificdata_key_t);
464void mount_setspecific(struct mount *, specificdata_key_t, void *); 465void mount_setspecific(struct mount *, specificdata_key_t, void *);
465 466