summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2020-02-14 14:32:45 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2020-02-14 14:32:45 +0000
commite8fbcde15c6527550bb779333bec26d7ef4598a4 (patch)
tree93b561ab30a53614cf0e6ae3c217e5d340562cfe /sys/kern
parent579439cd720092209bd8cc615534911bdf05a6d8 (diff)
Push the KERNEL_LOCK() insidge pgsigio() and selwakeup().
The 3 subsystems: signal, poll/select and kqueue can now be addressed separatly. Note that bpf(4) and audio(4) currently delay the wakeups to a separate context in order to respect the KERNEL_LOCK() requirement. Sockets (UDP, TCP) and pipes spin to grab the lock for the sames reasons. ok anton@, visa@
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_sig.c4
-rw-r--r--sys/kern/sys_generic.c17
-rw-r--r--sys/kern/sys_pipe.c13
-rw-r--r--sys/kern/uipc_socket.c4
-rw-r--r--sys/kern/uipc_socket2.c4
5 files changed, 25 insertions, 17 deletions
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 1e781ac7018..bc4d54495b4 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sig.c,v 1.245 2020/02/01 15:52:34 anton Exp $ */
+/* $OpenBSD: kern_sig.c,v 1.246 2020/02/14 14:32:44 mpi Exp $ */
/* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */
/*
@@ -740,6 +740,7 @@ pgsigio(struct sigio_ref *sir, int sig, int checkctty)
if (sir->sir_sigio == NULL)
return;
+ KERNEL_LOCK();
mtx_enter(&sigio_lock);
sigio = sir->sir_sigio;
if (sigio == NULL)
@@ -756,6 +757,7 @@ pgsigio(struct sigio_ref *sir, int sig, int checkctty)
}
out:
mtx_leave(&sigio_lock);
+ KERNEL_UNLOCK();
}
/*
diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c
index 7a5a1a18749..eb021208d0f 100644
--- a/sys/kern/sys_generic.c
+++ b/sys/kern/sys_generic.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_generic.c,v 1.129 2020/02/01 08:57:27 anton Exp $ */
+/* $OpenBSD: sys_generic.c,v 1.130 2020/02/14 14:32:44 mpi Exp $ */
/* $NetBSD: sys_generic.c,v 1.24 1996/03/29 00:25:32 cgd Exp $ */
/*
@@ -73,6 +73,7 @@ int dopselect(struct proc *, int, fd_set *, fd_set *, fd_set *,
struct timespec *, const sigset_t *, register_t *);
int doppoll(struct proc *, struct pollfd *, u_int, struct timespec *,
const sigset_t *, register_t *);
+void doselwakeup(struct selinfo *);
int
iovec_copyin(const struct iovec *uiov, struct iovec **iovp, struct iovec *aiov,
@@ -750,6 +751,8 @@ selrecord(struct proc *selector, struct selinfo *sip)
struct proc *p;
pid_t mytid;
+ KERNEL_ASSERT_LOCKED();
+
mytid = selector->p_tid;
if (sip->si_seltid == mytid)
return;
@@ -766,9 +769,19 @@ selrecord(struct proc *selector, struct selinfo *sip)
void
selwakeup(struct selinfo *sip)
{
+ KERNEL_LOCK();
+ KNOTE(&sip->si_note, NOTE_SUBMIT);
+ doselwakeup(sip);
+ KERNEL_UNLOCK();
+}
+
+void
+doselwakeup(struct selinfo *sip)
+{
struct proc *p;
- KNOTE(&sip->si_note, NOTE_SUBMIT);
+ KERNEL_ASSERT_LOCKED();
+
if (sip->si_seltid == 0)
return;
if (sip->si_flags & SI_COLL) {
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c
index d266a201d3d..ddc41bed9b6 100644
--- a/sys/kern/sys_pipe.c
+++ b/sys/kern/sys_pipe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_pipe.c,v 1.115 2020/02/01 15:52:34 anton Exp $ */
+/* $OpenBSD: sys_pipe.c,v 1.116 2020/02/14 14:32:44 mpi Exp $ */
/*
* Copyright (c) 1996 John S. Dyson
@@ -372,20 +372,17 @@ pipeselwakeup(struct pipe *cpipe)
{
rw_assert_wrlock(cpipe->pipe_lock);
- KERNEL_LOCK();
-
- /* Kernel lock needed in order to prevent race with kevent. */
if (cpipe->pipe_state & PIPE_SEL) {
cpipe->pipe_state &= ~PIPE_SEL;
selwakeup(&cpipe->pipe_sel);
- } else
+ } else {
+ KERNEL_LOCK();
KNOTE(&cpipe->pipe_sel.si_note, NOTE_SUBMIT);
+ KERNEL_UNLOCK();
+ }
- /* Kernel lock needed since pgsigio() calls ptsignal(). */
if (cpipe->pipe_state & PIPE_ASYNC)
pgsigio(&cpipe->pipe_sigio, SIGIO, 0);
-
- KERNEL_UNLOCK();
}
int
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index 7d497af7426..c14924082a1 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_socket.c,v 1.239 2020/01/15 13:17:35 mpi Exp $ */
+/* $OpenBSD: uipc_socket.c,v 1.240 2020/02/14 14:32:44 mpi Exp $ */
/* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */
/*
@@ -1988,10 +1988,8 @@ sogetopt(struct socket *so, int level, int optname, struct mbuf *m)
void
sohasoutofband(struct socket *so)
{
- KERNEL_LOCK();
pgsigio(&so->so_sigio, SIGURG, 0);
selwakeup(&so->so_rcv.sb_sel);
- KERNEL_UNLOCK();
}
int
diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c
index 9c2492f39a5..f1ef9593c4c 100644
--- a/sys/kern/uipc_socket2.c
+++ b/sys/kern/uipc_socket2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_socket2.c,v 1.102 2020/01/15 13:17:35 mpi Exp $ */
+/* $OpenBSD: uipc_socket2.c,v 1.103 2020/02/14 14:32:44 mpi Exp $ */
/* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */
/*
@@ -408,11 +408,9 @@ sowakeup(struct socket *so, struct sockbuf *sb)
sb->sb_flags &= ~SB_WAIT;
wakeup(&sb->sb_cc);
}
- KERNEL_LOCK();
if (so->so_state & SS_ASYNC)
pgsigio(&so->so_sigio, SIGIO, 0);
selwakeup(&sb->sb_sel);
- KERNEL_UNLOCK();
}
/*