Skip to content

Commit d12040b

Browse files
dhowellsdavem330
authored andcommitted
rxrpc: Fix lack of conn cleanup when local endpoint is cleaned up [ver #2]
When a local endpoint is ceases to be in use, such as when the kafs module is unloaded, the kernel will emit an assertion failure if there are any outstanding client connections: rxrpc: Assertion failed ------------[ cut here ]------------ kernel BUG at net/rxrpc/local_object.c:433! and even beyond that, will evince other oopses if there are service connections still present. Fix this by: (1) Removing the triggering of connection reaping when an rxrpc socket is released. These don't actually clean up the connections anyway - and further, the local endpoint may still be in use through another socket. (2) Mark the local endpoint as dead when we start the process of tearing it down. (3) When destroying a local endpoint, strip all of its client connections from the idle list and discard the ref on each that the list was holding. (4) When destroying a local endpoint, call the service connection reaper directly (rather than through a workqueue) to immediately kill off all outstanding service connections. (5) Make the service connection reaper reap connections for which the local endpoint is marked dead. Only after destroying the connections can we close the socket lest we get an oops in a workqueue that's looking at a connection or a peer. Fixes: 3d18cbb ("rxrpc: Fix conn expiry timers") Signed-off-by: David Howells <dhowells@redhat.com> Tested-by: Marc Dionne <marc.dionne@auristor.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a285c1f commit d12040b

5 files changed

Lines changed: 50 additions & 5 deletions

File tree

net/rxrpc/af_rxrpc.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,6 @@ static void rxrpc_sock_destructor(struct sock *sk)
862862
static int rxrpc_release_sock(struct sock *sk)
863863
{
864864
struct rxrpc_sock *rx = rxrpc_sk(sk);
865-
struct rxrpc_net *rxnet = rxrpc_net(sock_net(&rx->sk));
866865

867866
_enter("%p{%d,%d}", sk, sk->sk_state, refcount_read(&sk->sk_refcnt));
868867

@@ -898,8 +897,6 @@ static int rxrpc_release_sock(struct sock *sk)
898897
rxrpc_release_calls_on_socket(rx);
899898
flush_workqueue(rxrpc_workqueue);
900899
rxrpc_purge_queue(&sk->sk_receive_queue);
901-
rxrpc_queue_work(&rxnet->service_conn_reaper);
902-
rxrpc_queue_work(&rxnet->client_conn_reaper);
903900

904901
rxrpc_unuse_local(rx->local);
905902
rx->local = NULL;

net/rxrpc/ar-internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,7 @@ void rxrpc_disconnect_client_call(struct rxrpc_call *);
910910
void rxrpc_put_client_conn(struct rxrpc_connection *);
911911
void rxrpc_discard_expired_client_conns(struct work_struct *);
912912
void rxrpc_destroy_all_client_connections(struct rxrpc_net *);
913+
void rxrpc_clean_up_local_conns(struct rxrpc_local *);
913914

914915
/*
915916
* conn_event.c

net/rxrpc/conn_client.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,3 +1162,47 @@ void rxrpc_destroy_all_client_connections(struct rxrpc_net *rxnet)
11621162

11631163
_leave("");
11641164
}
1165+
1166+
/*
1167+
* Clean up the client connections on a local endpoint.
1168+
*/
1169+
void rxrpc_clean_up_local_conns(struct rxrpc_local *local)
1170+
{
1171+
struct rxrpc_connection *conn, *tmp;
1172+
struct rxrpc_net *rxnet = local->rxnet;
1173+
unsigned int nr_active;
1174+
LIST_HEAD(graveyard);
1175+
1176+
_enter("");
1177+
1178+
spin_lock(&rxnet->client_conn_cache_lock);
1179+
nr_active = rxnet->nr_active_client_conns;
1180+
1181+
list_for_each_entry_safe(conn, tmp, &rxnet->idle_client_conns,
1182+
cache_link) {
1183+
if (conn->params.local == local) {
1184+
ASSERTCMP(conn->cache_state, ==, RXRPC_CONN_CLIENT_IDLE);
1185+
1186+
trace_rxrpc_client(conn, -1, rxrpc_client_discard);
1187+
if (!test_and_clear_bit(RXRPC_CONN_EXPOSED, &conn->flags))
1188+
BUG();
1189+
conn->cache_state = RXRPC_CONN_CLIENT_INACTIVE;
1190+
list_move(&conn->cache_link, &graveyard);
1191+
nr_active--;
1192+
}
1193+
}
1194+
1195+
rxnet->nr_active_client_conns = nr_active;
1196+
spin_unlock(&rxnet->client_conn_cache_lock);
1197+
ASSERTCMP(nr_active, >=, 0);
1198+
1199+
while (!list_empty(&graveyard)) {
1200+
conn = list_entry(graveyard.next,
1201+
struct rxrpc_connection, cache_link);
1202+
list_del_init(&conn->cache_link);
1203+
1204+
rxrpc_put_connection(conn);
1205+
}
1206+
1207+
_leave(" [culled]");
1208+
}

net/rxrpc/conn_object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ void rxrpc_service_connection_reaper(struct work_struct *work)
398398
if (conn->state == RXRPC_CONN_SERVICE_PREALLOC)
399399
continue;
400400

401-
if (rxnet->live) {
401+
if (rxnet->live && !conn->params.local->dead) {
402402
idle_timestamp = READ_ONCE(conn->idle_timestamp);
403403
expire_at = idle_timestamp + rxrpc_connection_expiry * HZ;
404404
if (conn->params.local->service_closed)

net/rxrpc/local_object.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,14 @@ static void rxrpc_local_destroyer(struct rxrpc_local *local)
426426

427427
_enter("%d", local->debug_id);
428428

429+
local->dead = true;
430+
429431
mutex_lock(&rxnet->local_mutex);
430432
list_del_init(&local->link);
431433
mutex_unlock(&rxnet->local_mutex);
432434

433-
ASSERT(RB_EMPTY_ROOT(&local->client_conns));
435+
rxrpc_clean_up_local_conns(local);
436+
rxrpc_service_connection_reaper(&rxnet->service_conn_reaper);
434437
ASSERT(!local->service);
435438

436439
if (socket) {

0 commit comments

Comments
 (0)