summaryrefslogtreecommitdiffstats
path: root/sys/netgraph/bluetooth/socket
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2004-06-02 04:15:39 +0000
committerrwatson <rwatson@FreeBSD.org>2004-06-02 04:15:39 +0000
commit576b26bafdee61ede4fafa63fd78e21930f5bc2e (patch)
tree6cd76268318837a9c462ad6283cb7d6cabe7d0e5 /sys/netgraph/bluetooth/socket
parenta22e58fe44a2fe47575e6ddbeef0217aeebcae2f (diff)
downloadFreeBSD-src-576b26bafdee61ede4fafa63fd78e21930f5bc2e.zip
FreeBSD-src-576b26bafdee61ede4fafa63fd78e21930f5bc2e.tar.gz
Integrate accept locking from rwatson_netperf, introducing a new
global mutex, accept_mtx, which serializes access to the following fields across all sockets: so_qlen so_incqlen so_qstate so_comp so_incomp so_list so_head While providing only coarse granularity, this approach avoids lock order issues between sockets by avoiding ownership of the fields by a specific socket and its per-socket mutexes. While here, rewrite soclose(), sofree(), soaccept(), and sonewconn() to add assertions, close additional races and address lock order concerns. In particular: - Reorganize the optimistic concurrency behavior in accept1() to always allocate a file descriptor with falloc() so that if we do find a socket, we don't have to encounter the "Oh, there wasn't a socket" race that can occur if falloc() sleeps in the current code, which broke inbound accept() ordering, not to mention requiring backing out socket state changes in a way that raced with the protocol level. We may want to add a lockless read of the queue state if polling of empty queues proves to be important to optimize. - In accept1(), soref() the socket while holding the accept lock so that the socket cannot be free'd in a race with the protocol layer. Likewise in netgraph equivilents of the accept1() code. - In sonewconn(), loop waiting for the queue to be small enough to insert our new socket once we've committed to inserting it, or races can occur that cause the incomplete socket queue to overfill. In the previously implementation, it was sufficient to simply tested once since calling soabort() didn't release synchronization permitting another thread to insert a socket as we discard a previous one. - In soclose()/sofree()/et al, it is the responsibility of the caller to remove a socket from the incomplete connection queue before calling soabort(), which prevents soabort() from having to walk into the accept socket to release the socket from its queue, and avoids races when releasing the accept mutex to enter soabort(), permitting soabort() to avoid lock ordering issues with the caller. - Generally cluster accept queue related operations together throughout these functions in order to facilitate locking. Annotate new locking in socketvar.h.
Diffstat (limited to 'sys/netgraph/bluetooth/socket')
-rw-r--r--sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c b/sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c
index e521dd9..a048ac8 100644
--- a/sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c
+++ b/sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c
@@ -1353,10 +1353,11 @@ ng_btsocket_rfcomm_session_accept(ng_btsocket_rfcomm_session_p s0)
return (error);
}
+ ACCEPT_LOCK();
if (TAILQ_EMPTY(&s0->l2so->so_comp)) {
+ ACCEPT_UNLOCK();
if (s0->l2so->so_state & SS_CANTRCVMORE)
return (ECONNABORTED);
-
return (EWOULDBLOCK);
}
@@ -1367,11 +1368,11 @@ ng_btsocket_rfcomm_session_accept(ng_btsocket_rfcomm_session_p s0)
TAILQ_REMOVE(&s0->l2so->so_comp, l2so, so_list);
s0->l2so->so_qlen --;
-
- soref(l2so);
l2so->so_qstate &= ~SQ_COMP;
- l2so->so_state |= SS_NBIO;
l2so->so_head = NULL;
+ soref(l2so);
+ l2so->so_state |= SS_NBIO;
+ ACCEPT_UNLOCK();
error = soaccept(l2so, (struct sockaddr **) &l2sa);
if (error != 0) {
OpenPOWER on IntegriCloud