summaryrefslogtreecommitdiff
path: root/sys/kern/uipc_socket2.c
diff options
context:
space:
mode:
authorVitaliy Makkoveev <mvs@cvs.openbsd.org>2024-05-03 17:43:10 +0000
committerVitaliy Makkoveev <mvs@cvs.openbsd.org>2024-05-03 17:43:10 +0000
commit31c0314d856f0cea7768e497fb8b0b3c26e417d7 (patch)
tree379ae8da7a7a8be13947cf5a1da3b848326caa8b /sys/kern/uipc_socket2.c
parent874cd7bc9c5ec380227b021588cf616960e97c68 (diff)
Push solock() down to sosend() and remove it from soreceive() paths fro
unix(4) sockets. Push solock() deep down to sosend() and remove it from soreceive() paths for unix(4) sockets. The transmission of unix(4) sockets already half-unlocked because connected peer is not locked by solock() during sbappend*() call. Use `sb_mtx' mutex(9) and `sb_lock' rwlock(9) to protect both `so_snd' and `so_rcv'. Since the `so_snd' is protected by `sb_mtx' mutex(9) the re-locking is not required in uipc_rcvd(). Do direct `so_rcv' dispose and cleanup in sofree(). This sockets is almost dead and unlinked from everywhere include spliced peer, so concurrent sotask() thread will just exit. This required to keep locks order between `i_lock' and `sb_lock'. Also this removes re-locking from sofree() for all sockets. SB_OWNLOCK became redundant with SB_MTXLOCK, so remove it. SB_MTXLOCK was kept because checks against SB_MTXLOCK within sb*() routines are mor consistent. Feedback and ok bluhm
Diffstat (limited to 'sys/kern/uipc_socket2.c')
-rw-r--r--sys/kern/uipc_socket2.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c
index f454f21bfdb..e8401225fdb 100644
--- a/sys/kern/uipc_socket2.c
+++ b/sys/kern/uipc_socket2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_socket2.c,v 1.152 2024/05/02 21:26:52 mvs Exp $ */
+/* $OpenBSD: uipc_socket2.c,v 1.153 2024/05/03 17:43:09 mvs Exp $ */
/* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */
/*
@@ -228,9 +228,10 @@ sonewconn(struct socket *head, int connstatus, int wait)
*/
if (soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat))
goto fail;
+
+ mtx_enter(&head->so_snd.sb_mtx);
so->so_snd.sb_wat = head->so_snd.sb_wat;
so->so_snd.sb_lowat = head->so_snd.sb_lowat;
- mtx_enter(&head->so_snd.sb_mtx);
so->so_snd.sb_timeo_nsecs = head->so_snd.sb_timeo_nsecs;
mtx_leave(&head->so_snd.sb_mtx);
@@ -543,7 +544,7 @@ sblock(struct socket *so, struct sockbuf *sb, int flags)
{
int error = 0, prio = PSOCK;
- if (sb->sb_flags & SB_OWNLOCK) {
+ if (sb->sb_flags & SB_MTXLOCK) {
int rwflags = RW_WRITE;
if (!(flags & SBL_NOINTR || sb->sb_flags & SB_NOINTR))
@@ -586,7 +587,7 @@ out:
void
sbunlock_locked(struct socket *so, struct sockbuf *sb)
{
- if (sb->sb_flags & SB_OWNLOCK) {
+ if (sb->sb_flags & SB_MTXLOCK) {
rw_exit(&sb->sb_lock);
return;
}
@@ -603,7 +604,7 @@ sbunlock_locked(struct socket *so, struct sockbuf *sb)
void
sbunlock(struct socket *so, struct sockbuf *sb)
{
- if (sb->sb_flags & SB_OWNLOCK) {
+ if (sb->sb_flags & SB_MTXLOCK) {
rw_exit(&sb->sb_lock);
return;
}