summaryrefslogtreecommitdiffstats
path: root/sys/kern/uipc_sockbuf.c
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2004-06-19 03:23:14 +0000
committerrwatson <rwatson@FreeBSD.org>2004-06-19 03:23:14 +0000
commite5f4cab9820ea4056891ad32a9a5f47c2de9428d (patch)
tree246b5040fb2b9c62bee15bc81d3d21263d01e52a /sys/kern/uipc_sockbuf.c
parent6f4685cc9a4b463d82cde1be8325a1d0b845d3bd (diff)
downloadFreeBSD-src-e5f4cab9820ea4056891ad32a9a5f47c2de9428d.zip
FreeBSD-src-e5f4cab9820ea4056891ad32a9a5f47c2de9428d.tar.gz
Assert socket buffer lock in sb_lock() to protect socket buffer sleep
lock state. Convert tsleep() into msleep() with socket buffer mutex as argument. Hold socket buffer lock over sbunlock() to protect sleep lock state. Assert socket buffer lock in sbwait() to protect the socket buffer wait state. Convert tsleep() into msleep() with socket buffer mutex as argument. Modify sofree(), sosend(), and soreceive() to acquire SOCKBUF_LOCK() in order to call into these functions with the lock, as well as to start protecting other socket buffer use in their implementation. Drop the socket buffer mutexes around calls into the protocol layer, around potentially blocking operations, for copying to/from user space, and VM operations relating to zero-copy. Assert the socket buffer mutex strategically after code sections or at the beginning of loops. In some cases, modify return code to ensure locks are properly dropped. Convert the potentially blocking allocation of storage for the remote address in soreceive() into a non-blocking allocation; we may wish to move the allocation earlier so that it can block prior to acquisition of the socket buffer lock. Drop some spl use. NOTE: Some races exist in the current structuring of sosend() and soreceive(). This commit only merges basic socket locking in this code; follow-up commits will close additional races. As merged, these changes are not sufficient to run without Giant safely. Reviewed by: juli, tjr
Diffstat (limited to 'sys/kern/uipc_sockbuf.c')
-rw-r--r--sys/kern/uipc_sockbuf.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/sys/kern/uipc_sockbuf.c b/sys/kern/uipc_sockbuf.c
index c385253..0e4e99b 100644
--- a/sys/kern/uipc_sockbuf.c
+++ b/sys/kern/uipc_sockbuf.c
@@ -323,8 +323,10 @@ sbwait(sb)
struct sockbuf *sb;
{
+ SOCKBUF_LOCK_ASSERT(sb);
+
sb->sb_flags |= SB_WAIT;
- return (tsleep(&sb->sb_cc,
+ return (msleep(&sb->sb_cc, &sb->sb_mtx,
(sb->sb_flags & SB_NOINTR) ? PSOCK : PSOCK | PCATCH, "sbwait",
sb->sb_timeo));
}
@@ -339,9 +341,11 @@ sb_lock(sb)
{
int error;
+ SOCKBUF_LOCK_ASSERT(sb);
+
while (sb->sb_flags & SB_LOCK) {
sb->sb_flags |= SB_WANT;
- error = tsleep(&sb->sb_flags,
+ error = msleep(&sb->sb_flags, &sb->sb_mtx,
(sb->sb_flags & SB_NOINTR) ? PSOCK : PSOCK|PCATCH,
"sblock", 0);
if (error)
OpenPOWER on IntegriCloud