Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/sys Setting EV_EOF requires modifying kn->kn_flags. How...
details: https://anonhg.NetBSD.org/src/rev/bd2c7489fd78
branches: trunk
changeset: 989058:bd2c7489fd78
user: thorpej <thorpej%NetBSD.org@localhost>
date: Mon Oct 11 01:07:36 2021 +0000
description:
Setting EV_EOF requires modifying kn->kn_flags. However, that relies on
holding the kq_lock of that note's kq. Rather than exposing this directly,
add new knote_set_eof() and knote_clear_eof() functions that handle the
necessary locking and don't leak as many implementation details to modules.
NetBSD 9.99.91
diffstat:
sys/dev/pci/xmm7360.c | 7 ++++---
sys/kern/kern_event.c | 31 +++++++++++++++++++++++++++++--
sys/kern/sys_pipe.c | 8 ++++----
sys/kern/tty_pty.c | 6 +++---
sys/kern/uipc_socket.c | 8 ++++----
sys/miscfs/fifofs/fifo_vnops.c | 12 ++++++------
sys/miscfs/genfs/genfs_vnops.c | 17 +++++------------
sys/nfs/nfs_kq.c | 13 ++++---------
sys/sys/event.h | 4 +++-
sys/sys/param.h | 4 ++--
10 files changed, 64 insertions(+), 46 deletions(-)
diffs (truncated from 370 to 300 lines):
diff -r 137e675587df -r bd2c7489fd78 sys/dev/pci/xmm7360.c
--- a/sys/dev/pci/xmm7360.c Mon Oct 11 00:25:05 2021 +0000
+++ b/sys/dev/pci/xmm7360.c Mon Oct 11 01:07:36 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xmm7360.c,v 1.10 2021/09/26 01:16:09 thorpej Exp $ */
+/* $NetBSD: xmm7360.c,v 1.11 2021/10/11 01:07:36 thorpej Exp $ */
/*
* Device driver for Intel XMM7360 LTE modems, eg. Fibocom L850-GL.
@@ -75,7 +75,7 @@
#include "opt_gateway.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xmm7360.c,v 1.10 2021/09/26 01:16:09 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xmm7360.c,v 1.11 2021/10/11 01:07:36 thorpej Exp $");
#endif
#include <sys/param.h>
@@ -166,6 +166,7 @@
#define device_private(devt) (void *)devt;
#define if_deferred_start_init(ifp, arg) /* nothing */
#define IF_OUTPUT_CONST /* nothing */
+#define knote_set_eof(kn, f) (kn)->kn_flags |= EV_EOF | (f)
#define tty_lock() int s = spltty()
#define tty_unlock() splx(s)
#define tty_locked() /* nothing */
@@ -2762,7 +2763,7 @@
kn->kn_data = 0;
if (!qp->open) {
- kn->kn_flags |= EV_EOF;
+ knote_set_eof(kn, 0);
return (1);
} else {
kn->kn_data = xmm7360_qp_has_data(qp) ? 1 : 0;
diff -r 137e675587df -r bd2c7489fd78 sys/kern/kern_event.c
--- a/sys/kern/kern_event.c Mon Oct 11 00:25:05 2021 +0000
+++ b/sys/kern/kern_event.c Mon Oct 11 01:07:36 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_event.c,v 1.130 2021/10/10 19:11:56 thorpej Exp $ */
+/* $NetBSD: kern_event.c,v 1.131 2021/10/11 01:07:36 thorpej Exp $ */
/*-
* Copyright (c) 2008, 2009, 2021 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
#endif /* _KERNEL_OPT */
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.130 2021/10/10 19:11:56 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.131 2021/10/11 01:07:36 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -2578,3 +2578,30 @@
out:
mutex_spin_exit(&kq->kq_lock);
}
+
+/*
+ * Set EV_EOF on the specified knote. Also allows additional
+ * EV_* flags to be set (e.g. EV_ONESHOT).
+ */
+void
+knote_set_eof(struct knote *kn, uint32_t flags)
+{
+ struct kqueue *kq = kn->kn_kq;
+
+ mutex_spin_enter(&kq->kq_lock);
+ kn->kn_flags |= EV_EOF | flags;
+ mutex_spin_exit(&kq->kq_lock);
+}
+
+/*
+ * Clear EV_EOF on the specified knote.
+ */
+void
+knote_clear_eof(struct knote *kn)
+{
+ struct kqueue *kq = kn->kn_kq;
+
+ mutex_spin_enter(&kq->kq_lock);
+ kn->kn_flags &= ~EV_EOF;
+ mutex_spin_exit(&kq->kq_lock);
+}
diff -r 137e675587df -r bd2c7489fd78 sys/kern/sys_pipe.c
--- a/sys/kern/sys_pipe.c Mon Oct 11 00:25:05 2021 +0000
+++ b/sys/kern/sys_pipe.c Mon Oct 11 01:07:36 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_pipe.c,v 1.157 2021/10/02 07:35:40 hannken Exp $ */
+/* $NetBSD: sys_pipe.c,v 1.158 2021/10/11 01:07:36 thorpej Exp $ */
/*-
* Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.157 2021/10/02 07:35:40 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.158 2021/10/11 01:07:36 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -1056,7 +1056,7 @@
if ((rpipe->pipe_state & PIPE_EOF) ||
(wpipe == NULL) || (wpipe->pipe_state & PIPE_EOF)) {
- kn->kn_flags |= EV_EOF;
+ knote_set_eof(kn, 0);
rv = 1;
} else {
rv = kn->kn_data > 0;
@@ -1082,7 +1082,7 @@
if ((wpipe == NULL) || (wpipe->pipe_state & PIPE_EOF)) {
kn->kn_data = 0;
- kn->kn_flags |= EV_EOF;
+ knote_set_eof(kn, 0);
rv = 1;
} else {
kn->kn_data = wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt;
diff -r 137e675587df -r bd2c7489fd78 sys/kern/tty_pty.c
--- a/sys/kern/tty_pty.c Mon Oct 11 00:25:05 2021 +0000
+++ b/sys/kern/tty_pty.c Mon Oct 11 01:07:36 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tty_pty.c,v 1.148 2021/09/29 13:14:39 thorpej Exp $ */
+/* $NetBSD: tty_pty.c,v 1.149 2021/10/11 01:07:36 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty_pty.c,v 1.148 2021/09/29 13:14:39 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_pty.c,v 1.149 2021/10/11 01:07:36 thorpej Exp $");
#include "opt_ptm.h"
@@ -939,7 +939,7 @@
kn->kn_data++;
}
if (!ISSET(tp->t_state, TS_CARR_ON)) {
- kn->kn_flags |= EV_EOF;
+ knote_set_eof(kn, 0);
canread = 1;
}
diff -r 137e675587df -r bd2c7489fd78 sys/kern/uipc_socket.c
--- a/sys/kern/uipc_socket.c Mon Oct 11 00:25:05 2021 +0000
+++ b/sys/kern/uipc_socket.c Mon Oct 11 01:07:36 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_socket.c,v 1.298 2021/09/29 13:15:45 thorpej Exp $ */
+/* $NetBSD: uipc_socket.c,v 1.299 2021/10/11 01:07:36 thorpej Exp $ */
/*
* Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.298 2021/09/29 13:15:45 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.299 2021/10/11 01:07:36 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@@ -2242,7 +2242,7 @@
solock(so);
kn->kn_data = so->so_rcv.sb_cc;
if (so->so_state & SS_CANTRCVMORE) {
- kn->kn_flags |= EV_EOF;
+ knote_set_eof(kn, 0);
kn->kn_fflags = so->so_error;
rv = 1;
} else if (so->so_error || so->so_rerror)
@@ -2280,7 +2280,7 @@
solock(so);
kn->kn_data = sbspace(&so->so_snd);
if (so->so_state & SS_CANTSENDMORE) {
- kn->kn_flags |= EV_EOF;
+ knote_set_eof(kn, 0);
kn->kn_fflags = so->so_error;
rv = 1;
} else if (so->so_error)
diff -r 137e675587df -r bd2c7489fd78 sys/miscfs/fifofs/fifo_vnops.c
--- a/sys/miscfs/fifofs/fifo_vnops.c Mon Oct 11 00:25:05 2021 +0000
+++ b/sys/miscfs/fifofs/fifo_vnops.c Mon Oct 11 01:07:36 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fifo_vnops.c,v 1.90 2021/10/02 18:39:15 thorpej Exp $ */
+/* $NetBSD: fifo_vnops.c,v 1.91 2021/10/11 01:07:36 thorpej Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fifo_vnops.c,v 1.90 2021/10/02 18:39:15 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fifo_vnops.c,v 1.91 2021/10/11 01:07:36 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -608,10 +608,10 @@
solock(so);
kn->kn_data = so->so_rcv.sb_cc;
if (so->so_state & SS_CANTRCVMORE) {
- kn->kn_flags |= EV_EOF;
+ knote_set_eof(kn, 0);
rv = 1;
} else {
- kn->kn_flags &= ~EV_EOF;
+ knote_clear_eof(kn);
rv = (kn->kn_data >= so->so_rcv.sb_lowat);
}
if (hint != NOTE_SUBMIT)
@@ -642,10 +642,10 @@
solock(so);
kn->kn_data = sbspace(&so->so_snd);
if (so->so_state & SS_CANTSENDMORE) {
- kn->kn_flags |= EV_EOF;
+ knote_set_eof(kn, 0);
rv = 1;
} else {
- kn->kn_flags &= ~EV_EOF;
+ knote_clear_eof(kn);
rv = (kn->kn_data >= so->so_snd.sb_lowat);
}
if (hint != NOTE_SUBMIT)
diff -r 137e675587df -r bd2c7489fd78 sys/miscfs/genfs/genfs_vnops.c
--- a/sys/miscfs/genfs/genfs_vnops.c Mon Oct 11 00:25:05 2021 +0000
+++ b/sys/miscfs/genfs/genfs_vnops.c Mon Oct 11 01:07:36 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: genfs_vnops.c,v 1.213 2021/10/10 23:46:23 thorpej Exp $ */
+/* $NetBSD: genfs_vnops.c,v 1.214 2021/10/11 01:07:36 thorpej Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.213 2021/10/10 23:46:23 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.214 2021/10/11 01:07:36 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -68,7 +68,6 @@
#include <sys/namei.h>
#include <sys/vnode_impl.h>
#include <sys/fcntl.h>
-#include <sys/eventvar.h> /* XXX for kq->kq_lock */
#include <sys/kmem.h>
#include <sys/poll.h>
#include <sys/mman.h>
@@ -526,9 +525,7 @@
switch (hint) {
case NOTE_REVOKE:
KASSERT(mutex_owned(vp->v_interlock));
- mutex_spin_enter(&kn->kn_kq->kq_lock);
- kn->kn_flags |= (EV_EOF | EV_ONESHOT);
- mutex_spin_exit(&kn->kn_kq->kq_lock);
+ knote_set_eof(kn, EV_ONESHOT);
return (1);
case 0:
mutex_enter(vp->v_interlock);
@@ -555,9 +552,7 @@
switch (hint) {
case NOTE_REVOKE:
KASSERT(mutex_owned(vp->v_interlock));
- mutex_spin_enter(&kn->kn_kq->kq_lock);
- kn->kn_flags |= (EV_EOF | EV_ONESHOT);
- mutex_spin_exit(&kn->kn_kq->kq_lock);
+ knote_set_eof(kn, EV_ONESHOT);
return (1);
case 0:
mutex_enter(vp->v_interlock);
@@ -580,9 +575,7 @@
switch (hint) {
case NOTE_REVOKE:
KASSERT(mutex_owned(vp->v_interlock));
- mutex_spin_enter(&kn->kn_kq->kq_lock);
- kn->kn_flags |= EV_EOF;
- mutex_spin_exit(&kn->kn_kq->kq_lock);
+ knote_set_eof(kn, 0);
if ((kn->kn_sfflags & hint) != 0)
kn->kn_fflags |= hint;
return (1);
diff -r 137e675587df -r bd2c7489fd78 sys/nfs/nfs_kq.c
--- a/sys/nfs/nfs_kq.c Mon Oct 11 00:25:05 2021 +0000
+++ b/sys/nfs/nfs_kq.c Mon Oct 11 01:07:36 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: nfs_kq.c,v 1.29 2021/10/10 23:46:22 thorpej Exp $ */
+/* $NetBSD: nfs_kq.c,v 1.30 2021/10/11 01:07:36 thorpej Exp $ */
/*-
* Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nfs_kq.c,v 1.29 2021/10/10 23:46:22 thorpej Exp $");
Home |
Main Index |
Thread Index |
Old Index