From: mvs Date: Fri, 22 Mar 2024 17:34:11 +0000 (+0000) Subject: Use sorflush() instead of direct unp_scan(..., unp_discard) to discard X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=fdada4b1d06e7ba496cc0badc521a16b3635267a;p=openbsd Use sorflush() instead of direct unp_scan(..., unp_discard) to discard dead unix(4) sockets. The difference in direct unp_scan() and sorflush() is the mbuf(9) chain. For the first case it is still linked to the `so_rcv', for the second it is not. This is required to make `sb_mtx' mutex(9) the only `so_rcv' sockbuf protection and remove socket re-locking from the most of uipc_*send() paths. The unlinked mbuf(9) chain doesn't require any protection, so this allows to perform sleeping unp_discard() lockless. Also, the mbuf(9) chain of the discarded socket still contains addresses of file descriptors and it is much safer to unlink it before FRELE() them. This is the reason to commit this diff standalone. ok bluhm --- diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 85032afee9d..7b04935ef0d 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.320 2024/02/12 22:48:27 mvs Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.321 2024/03/22 17:34:11 mvs Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -65,7 +65,6 @@ void sotask(void *); void soreaper(void *); void soput(void *); int somove(struct socket *, int); -void sorflush(struct socket *); void filt_sordetach(struct knote *kn); int filt_soread(struct knote *kn, long hint); diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index b01cad482d6..7dc83db4d51 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_usrreq.c,v 1.201 2024/03/17 19:47:08 mvs Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.202 2024/03/22 17:34:11 mvs Exp $ */ /* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* @@ -1438,7 +1438,7 @@ unp_gc(void *arg __unused) */ so = unp->unp_socket; solock(so); - unp_scan(so->so_rcv.sb_mb, unp_discard); + sorflush(so); sounlock(so); } } diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index 9ef1cafe71a..dc34b1c5c61 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: socketvar.h,v 1.124 2024/02/12 22:48:27 mvs Exp $ */ +/* $OpenBSD: socketvar.h,v 1.125 2024/03/22 17:34:11 mvs Exp $ */ /* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */ /*- @@ -394,6 +394,7 @@ int sosend(struct socket *, struct mbuf *, struct uio *, struct mbuf *, struct mbuf *, int); int sosetopt(struct socket *, int, int, struct mbuf *); int soshutdown(struct socket *, int); +void sorflush(struct socket *); void sowakeup(struct socket *, struct sockbuf *); void sorwakeup(struct socket *); void sowwakeup(struct socket *);