On Tue, Feb 08, 2022 at 09:12:11AM +0000, Visa Hankala wrote:
> Now that poll(2) is based on kqueue, the old, non-MP-safe poll backend
> is not used any longer. Event sources can call KNOTE() directly instead
> of selwakeup().
>
> This diff does the KNOTE() conversion for pipes and sockets, removing
> a kernel-locked section from a frequently used code path. The related
> event filters do not use the hint value, hence passing 0 rather than
> NOTE_SUBMIT.
This patch had an unexpected effect of triggering NFS server hangs.
These hangs were possibly caused by a synchronization issue that was
exposed by the patch. The NFS subsystem is not MP-safe, but the NFS
socket upcall was run without the kernel lock. Now that this has been
fixed, the selwakeup-to-KNOTE conversion might work fine.
Could someone who saw the NFS problem test this patch?
Index: kern/sys_pipe.c
===================================================================
RCS file: src/sys/kern/sys_pipe.c,v
retrieving revision 1.133
diff -u -p -r1.133 sys_pipe.c
--- kern/sys_pipe.c 13 Dec 2021 14:56:55 -0000 1.133
+++ kern/sys_pipe.c 8 Feb 2022 08:59:05 -0000
@@ -381,12 +381,7 @@ pipeselwakeup(struct pipe *cpipe)
{
rw_assert_wrlock(cpipe->pipe_lock);
- if (cpipe->pipe_state & PIPE_SEL) {
- cpipe->pipe_state &= ~PIPE_SEL;
- selwakeup(&cpipe->pipe_sel);
- } else {
- KNOTE(&cpipe->pipe_sel.si_note, 0);
- }
+ KNOTE(&cpipe->pipe_sel.si_note, 0);
if (cpipe->pipe_state & PIPE_ASYNC)
pgsigio(&cpipe->pipe_sigio, SIGIO, 0);
Index: kern/uipc_socket.c
===================================================================
RCS file: src/sys/kern/uipc_socket.c,v
retrieving revision 1.271
diff -u -p -r1.271 uipc_socket.c
--- kern/uipc_socket.c 24 Dec 2021 06:50:16 -0000 1.271
+++ kern/uipc_socket.c 8 Feb 2022 08:59:05 -0000
@@ -2049,7 +2049,7 @@ void
sohasoutofband(struct socket *so)
{
pgsigio(&so->so_sigio, SIGURG, 0);
- selwakeup(&so->so_rcv.sb_sel);
+ KNOTE(&so->so_rcv.sb_sel.si_note, 0);
}
int
Index: kern/uipc_socket2.c
===================================================================
RCS file: src/sys/kern/uipc_socket2.c,v
retrieving revision 1.116
diff -u -p -r1.116 uipc_socket2.c
--- kern/uipc_socket2.c 6 Nov 2021 05:26:33 -0000 1.116
+++ kern/uipc_socket2.c 8 Feb 2022 08:59:06 -0000
@@ -423,7 +423,7 @@ sowakeup(struct socket *so, struct sockb
}
if (sb->sb_flags & SB_ASYNC)
pgsigio(&so->so_sigio, SIGIO, 0);
- selwakeup(&sb->sb_sel);
+ KNOTE(&sb->sb_sel.si_note, 0);
}
/*