From: mvs Date: Fri, 14 Jun 2024 08:32:22 +0000 (+0000) Subject: Switch AF_ROUTE sockets to the new locking scheme. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=dfc54264df1e287f7ea83d7741905efb8de33c5f;p=openbsd Switch AF_ROUTE sockets to the new locking scheme. At sockets layer only mark buffers as SB_MTXLOCK. At PCB layer only protect `so_rcv' with corresponding `sb_mtx' mutex(9). SS_ISCONNECTED and SS_CANTRCVMORE bits are redundant for AF_ROUTE sockets. Since SS_CANTRCVMORE modifications performed with both solock() and `sb_mtx' held, the 'unlocked' SS_CANTRCVMORE check in rtm_senddesync() is safe. ok bluhm --- diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 1097f16022f..12818fb706c 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_socket.c,v 1.335 2024/05/17 19:11:14 mvs Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.336 2024/06/14 08:32:22 mvs Exp $ */ /* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* @@ -166,6 +166,7 @@ soalloc(const struct protosw *prp, int wait) } break; case AF_KEY: + case AF_ROUTE: case AF_UNIX: so->so_snd.sb_flags |= SB_MTXLOCK; so->so_rcv.sb_flags |= SB_MTXLOCK; diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 2dd04a0fd28..4031033b110 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.373 2023/12/03 10:51:17 mvs Exp $ */ +/* $OpenBSD: rtsock.c,v 1.374 2024/06/14 08:32:22 mvs Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -313,10 +313,12 @@ route_rcvd(struct socket *so) * If we are in a FLUSH state, check if the buffer is * empty so that we can clear the flag. */ + + mtx_enter(&so->so_rcv.sb_mtx); if (((rop->rop_flags & ROUTECB_FLAG_FLUSH) != 0) && - ((sbspace(rop->rop_socket, &rop->rop_socket->so_rcv) == - rop->rop_socket->so_rcv.sb_hiwat))) + ((sbspace(so, &so->so_rcv) == so->so_rcv.sb_hiwat))) rop->rop_flags &= ~ROUTECB_FLAG_FLUSH; + mtx_leave(&so->so_rcv.sb_mtx); } int @@ -478,8 +480,14 @@ rtm_senddesync(struct socket *so) */ desync_mbuf = rtm_msg1(RTM_DESYNC, NULL); if (desync_mbuf != NULL) { - if (sbappendaddr(so, &so->so_rcv, &route_src, - desync_mbuf, NULL) != 0) { + int ret; + + mtx_enter(&so->so_rcv.sb_mtx); + ret = sbappendaddr(so, &so->so_rcv, &route_src, + desync_mbuf, NULL); + mtx_leave(&so->so_rcv.sb_mtx); + + if (ret != 0) { rop->rop_flags &= ~ROUTECB_FLAG_DESYNC; sorwakeup(rop->rop_socket); return; @@ -586,6 +594,7 @@ rtm_sendup(struct socket *so, struct mbuf *m0) { struct rtpcb *rop = sotortpcb(so); struct mbuf *m; + int send_desync = 0; soassertlocked(so); @@ -593,8 +602,13 @@ rtm_sendup(struct socket *so, struct mbuf *m0) if (m == NULL) return (ENOMEM); + mtx_enter(&so->so_rcv.sb_mtx); if (sbspace(so, &so->so_rcv) < (2 * MSIZE) || - sbappendaddr(so, &so->so_rcv, &route_src, m, NULL) == 0) { + sbappendaddr(so, &so->so_rcv, &route_src, m, NULL) == 0) + send_desync = 1; + mtx_leave(&so->so_rcv.sb_mtx); + + if (send_desync) { /* Flag socket as desync'ed and flush required */ rop->rop_flags |= ROUTECB_FLAG_DESYNC | ROUTECB_FLAG_FLUSH; rtm_senddesync(so);