Commit e653cfe4 authored by David Howells's avatar David Howells

rxrpc: Release a call's connection ref on call disconnection

When a call is disconnected, clear the call's pointer to the connection and
release the associated ref on that connection.  This means that the call no
longer pins the connection and the connection can be discarded even before
the call is.

As the code currently stands, the call struct is effectively pinned by
userspace until userspace has enacted a recvmsg() to retrieve the final
call state as sk_buffs on the receive queue pin the call to which they're
related because:

 (1) The rxrpc_call struct contains the userspace ID that recvmsg() has to
     include in the control message buffer to indicate which call is being
     referred to.  This ID must remain valid until the terminal packet is
     completely read and must be invalidated immediately at that point as
     userspace is entitled to immediately reuse it.

 (2) The final ACK to the reply to a client call isn't sent until the last
     data packet is entirely read (it's probably worth altering this in
     future to be send the ACK as soon as all the data has been received).

This change requires a bit of rearrangement to make sure that the call
isn't going to try and access the connection again after protocol

 (1) Delete the error link earlier when we're releasing the call.  Possibly
     network errors should be distributed via connections at the cost of
     adding in an access to the rxrpc_connection struct.

 (2) Remove the call from the connection's call tree before disconnecting
     the call.  The call tree needs to be removed anyway and incoming
     packets delivered by channel pointer instead.

 (3) The release call event should be considered last after all other
     events have been processed so that we don't need access to the
     connection again.

 (4) Move the channel_lock taking from rxrpc_release_call() to
     rxrpc_disconnect_call() where it will be required in future.
Signed-off-by: default avatarDavid Howells <>
parent d1e858c5
...@@ -858,11 +858,6 @@ void rxrpc_process_call(struct work_struct *work) ...@@ -858,11 +858,6 @@ void rxrpc_process_call(struct work_struct *work)
iov[0].iov_len = sizeof(whdr); iov[0].iov_len = sizeof(whdr);
/* deal with events of a final nature */ /* deal with events of a final nature */
if (test_bit(RXRPC_CALL_EV_RELEASE, &call->events)) {
clear_bit(RXRPC_CALL_EV_RELEASE, &call->events);
if (test_bit(RXRPC_CALL_EV_RCVD_ERROR, &call->events)) { if (test_bit(RXRPC_CALL_EV_RCVD_ERROR, &call->events)) {
enum rxrpc_skb_mark mark; enum rxrpc_skb_mark mark;
int error; int error;
...@@ -1144,6 +1139,11 @@ void rxrpc_process_call(struct work_struct *work) ...@@ -1144,6 +1139,11 @@ void rxrpc_process_call(struct work_struct *work)
goto maybe_reschedule; goto maybe_reschedule;
} }
if (test_bit(RXRPC_CALL_EV_RELEASE, &call->events)) {
clear_bit(RXRPC_CALL_EV_RELEASE, &call->events);
/* other events may have been raised since we started checking */ /* other events may have been raised since we started checking */
goto maybe_reschedule; goto maybe_reschedule;
...@@ -628,6 +628,10 @@ void rxrpc_release_call(struct rxrpc_call *call) ...@@ -628,6 +628,10 @@ void rxrpc_release_call(struct rxrpc_call *call)
*/ */
_debug("RELEASE CALL %p (%d CONN %p)", call, call->debug_id, conn); _debug("RELEASE CALL %p (%d CONN %p)", call, call->debug_id, conn);
write_lock_bh(&rx->call_lock); write_lock_bh(&rx->call_lock);
if (!list_empty(&call->accept_link)) { if (!list_empty(&call->accept_link)) {
_debug("unlinking once-pending call %p { e=%lx f=%lx }", _debug("unlinking once-pending call %p { e=%lx f=%lx }",
...@@ -643,25 +647,22 @@ void rxrpc_release_call(struct rxrpc_call *call) ...@@ -643,25 +647,22 @@ void rxrpc_release_call(struct rxrpc_call *call)
write_unlock_bh(&rx->call_lock); write_unlock_bh(&rx->call_lock);
/* free up the channel for reuse */ /* free up the channel for reuse */
write_lock_bh(&conn->lock); write_lock_bh(&conn->lock);
write_lock(&call->state_lock); write_lock(&call->state_lock);
if (call->state < RXRPC_CALL_COMPLETE && if (call->state < RXRPC_CALL_COMPLETE &&
_debug("+++ ABORTING STATE %d +++\n", call->state); _debug("+++ ABORTING STATE %d +++\n", call->state);
call->local_abort = RX_CALL_DEAD; call->local_abort = RX_CALL_DEAD;
set_bit(RXRPC_CALL_EV_ABORT, &call->events);
} }
write_unlock(&call->state_lock); write_unlock(&call->state_lock);
rb_erase(&call->conn_node, &conn->calls);
write_unlock_bh(&conn->lock); write_unlock_bh(&conn->lock);
/* clean up the Rx queue */ /* clean up the Rx queue */
if (!skb_queue_empty(&call->rx_queue) || if (!skb_queue_empty(&call->rx_queue) ||
!skb_queue_empty(&call->rx_oos_queue)) { !skb_queue_empty(&call->rx_oos_queue)) {
...@@ -817,16 +818,7 @@ static void rxrpc_cleanup_call(struct rxrpc_call *call) ...@@ -817,16 +818,7 @@ static void rxrpc_cleanup_call(struct rxrpc_call *call)
return; return;
} }
if (call->conn) { ASSERTCMP(call->conn, ==, NULL);
rb_erase(&call->conn_node, &call->conn->calls);
/* Remove the call from the hash */ /* Remove the call from the hash */
rxrpc_call_hash_del(call); rxrpc_call_hash_del(call);
...@@ -540,11 +540,19 @@ void rxrpc_disconnect_call(struct rxrpc_call *call) ...@@ -540,11 +540,19 @@ void rxrpc_disconnect_call(struct rxrpc_call *call)
_enter("%d,%d", conn->debug_id, call->channel); _enter("%d,%d", conn->debug_id, call->channel);
if (conn->channels[chan] == call) { if (conn->channels[chan] == call) {
rcu_assign_pointer(conn->channels[chan], NULL); rcu_assign_pointer(conn->channels[chan], NULL);
atomic_inc(&conn->avail_chans); atomic_inc(&conn->avail_chans);
wake_up(&conn->channel_wq); wake_up(&conn->channel_wq);
} }
call->conn = NULL;
} }
/* /*
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment