Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* RxRPC virtual connection handler, common bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2007, 2016 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "ar-internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * Time till a connection expires after last use (in seconds).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) unsigned int __read_mostly rxrpc_connection_expiry = 10 * 60;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) unsigned int __read_mostly rxrpc_closed_conn_expiry = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static void rxrpc_destroy_connection(struct rcu_head *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static void rxrpc_connection_timer(struct timer_list *timer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct rxrpc_connection *conn =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		container_of(timer, struct rxrpc_connection, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	rxrpc_queue_conn(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * allocate a new connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct rxrpc_connection *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	_enter("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	conn = kzalloc(sizeof(struct rxrpc_connection), gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		INIT_LIST_HEAD(&conn->cache_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		timer_setup(&conn->timer, &rxrpc_connection_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		INIT_WORK(&conn->processor, &rxrpc_process_connection);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		INIT_LIST_HEAD(&conn->proc_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		INIT_LIST_HEAD(&conn->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		skb_queue_head_init(&conn->rx_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		conn->security = &rxrpc_no_security;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		spin_lock_init(&conn->state_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		conn->size_align = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		conn->idle_timestamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	_leave(" = %p{%d}", conn, conn ? conn->debug_id : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * Look up a connection in the cache by protocol parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * If successful, a pointer to the connection is returned, but no ref is taken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  * NULL is returned if there is no match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * When searching for a service call, if we find a peer but no connection, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * return that through *_peer in case we need to create a new service call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * The caller must be holding the RCU read lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 						   struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 						   struct rxrpc_peer **_peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct rxrpc_connection *conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct rxrpc_conn_proto k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct sockaddr_rxrpc srx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct rxrpc_peer *peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	_enter(",%x", sp->hdr.cid & RXRPC_CIDMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (rxrpc_extract_addr_from_skb(&srx, skb) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (srx.transport.family != local->srx.transport.family &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	    (srx.transport.family == AF_INET &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	     local->srx.transport.family != AF_INET6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		pr_warn_ratelimited("AF_RXRPC: Protocol mismatch %u not %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 				    srx.transport.family,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 				    local->srx.transport.family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	k.epoch	= sp->hdr.epoch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	k.cid	= sp->hdr.cid & RXRPC_CIDMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (rxrpc_to_server(sp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		/* We need to look up service connections by the full protocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		 * parameter set.  We look up the peer first as an intermediate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		 * step and then the connection from the peer's tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		peer = rxrpc_lookup_peer_rcu(local, &srx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		if (!peer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		*_peer = peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		conn = rxrpc_find_service_conn_rcu(peer, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		if (!conn || atomic_read(&conn->usage) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		_leave(" = %p", conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		return conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		/* Look up client connections by connection ID alone as their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		 * IDs are unique for this machine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		conn = idr_find(&rxrpc_client_conn_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 				sp->hdr.cid >> RXRPC_CIDSHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		if (!conn || atomic_read(&conn->usage) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			_debug("no conn");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		if (conn->proto.epoch != k.epoch ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		    conn->params.local != local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		peer = conn->params.peer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		switch (srx.transport.family) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		case AF_INET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			if (peer->srx.transport.sin.sin_port !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			    srx.transport.sin.sin_port ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			    peer->srx.transport.sin.sin_addr.s_addr !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			    srx.transport.sin.sin_addr.s_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 				goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #ifdef CONFIG_AF_RXRPC_IPV6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		case AF_INET6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			if (peer->srx.transport.sin6.sin6_port !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			    srx.transport.sin6.sin6_port ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			    memcmp(&peer->srx.transport.sin6.sin6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 				   &srx.transport.sin6.sin6_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				   sizeof(struct in6_addr)) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 				goto not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		_leave(" = %p", conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		return conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) not_found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	_leave(" = NULL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * Disconnect a call and clear any channel it occupies when that call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  * terminates.  The caller must hold the channel_lock and must release the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  * call's ref on the connection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) void __rxrpc_disconnect_call(struct rxrpc_connection *conn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			     struct rxrpc_call *call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct rxrpc_channel *chan =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		&conn->channels[call->cid & RXRPC_CHANNELMASK];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	_enter("%d,%x", conn->debug_id, call->cid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (rcu_access_pointer(chan->call) == call) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		/* Save the result of the call so that we can repeat it if necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		 * through the channel, whilst disposing of the actual call record.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		trace_rxrpc_disconnect_call(call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		switch (call->completion) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		case RXRPC_CALL_SUCCEEDED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			chan->last_seq = call->rx_hard_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			chan->last_type = RXRPC_PACKET_TYPE_ACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		case RXRPC_CALL_LOCALLY_ABORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			chan->last_abort = call->abort_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			chan->last_type = RXRPC_PACKET_TYPE_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 			chan->last_abort = RX_USER_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			chan->last_type = RXRPC_PACKET_TYPE_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		/* Sync with rxrpc_conn_retransmit(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		chan->last_call = chan->call_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		chan->call_id = chan->call_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		rcu_assign_pointer(chan->call, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	_leave("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  * Disconnect a call and clear any channel it occupies when that call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  * terminates.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) void rxrpc_disconnect_call(struct rxrpc_call *call)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	struct rxrpc_connection *conn = call->conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	call->peer->cong_cwnd = call->cong_cwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (!hlist_unhashed(&call->error_link)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		spin_lock_bh(&call->peer->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		hlist_del_rcu(&call->error_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		spin_unlock_bh(&call->peer->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (rxrpc_is_client_call(call))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		return rxrpc_disconnect_client_call(conn->bundle, call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	spin_lock(&conn->bundle->channel_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	__rxrpc_disconnect_call(conn, call);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	spin_unlock(&conn->bundle->channel_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	set_bit(RXRPC_CALL_DISCONNECTED, &call->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	conn->idle_timestamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  * Kill off a connection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) void rxrpc_kill_connection(struct rxrpc_connection *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct rxrpc_net *rxnet = conn->params.local->rxnet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	ASSERT(!rcu_access_pointer(conn->channels[0].call) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	       !rcu_access_pointer(conn->channels[1].call) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	       !rcu_access_pointer(conn->channels[2].call) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	       !rcu_access_pointer(conn->channels[3].call));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	ASSERT(list_empty(&conn->cache_link));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	write_lock(&rxnet->conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	list_del_init(&conn->proc_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	write_unlock(&rxnet->conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	/* Drain the Rx queue.  Note that even though we've unpublished, an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	 * incoming packet could still be being added to our Rx queue, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	 * will need to drain it again in the RCU cleanup handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	rxrpc_purge_queue(&conn->rx_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	/* Leave final destruction to RCU.  The connection processor work item
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	 * must carry a ref on the connection to prevent us getting here whilst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	 * it is queued or running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	call_rcu(&conn->rcu, rxrpc_destroy_connection);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)  * Queue a connection's work processor, getting a ref to pass to the work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  * queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) bool rxrpc_queue_conn(struct rxrpc_connection *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	const void *here = __builtin_return_address(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	int n = atomic_fetch_add_unless(&conn->usage, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (n == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (rxrpc_queue_work(&conn->processor))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		trace_rxrpc_conn(conn->debug_id, rxrpc_conn_queued, n + 1, here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		rxrpc_put_connection(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)  * Note the re-emergence of a connection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) void rxrpc_see_connection(struct rxrpc_connection *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	const void *here = __builtin_return_address(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		int n = atomic_read(&conn->usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		trace_rxrpc_conn(conn->debug_id, rxrpc_conn_seen, n, here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  * Get a ref on a connection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) struct rxrpc_connection *rxrpc_get_connection(struct rxrpc_connection *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	const void *here = __builtin_return_address(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	int n = atomic_inc_return(&conn->usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	trace_rxrpc_conn(conn->debug_id, rxrpc_conn_got, n, here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	return conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  * Try to get a ref on a connection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct rxrpc_connection *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) rxrpc_get_connection_maybe(struct rxrpc_connection *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	const void *here = __builtin_return_address(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	if (conn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		int n = atomic_fetch_add_unless(&conn->usage, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		if (n > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			trace_rxrpc_conn(conn->debug_id, rxrpc_conn_got, n + 1, here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			conn = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	return conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  * Set the service connection reap timer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static void rxrpc_set_service_reap_timer(struct rxrpc_net *rxnet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 					 unsigned long reap_at)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	if (rxnet->live)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		timer_reduce(&rxnet->service_conn_reap_timer, reap_at);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  * Release a service connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) void rxrpc_put_service_conn(struct rxrpc_connection *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	const void *here = __builtin_return_address(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	unsigned int debug_id = conn->debug_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	n = atomic_dec_return(&conn->usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	trace_rxrpc_conn(debug_id, rxrpc_conn_put_service, n, here);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	ASSERTCMP(n, >=, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	if (n == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		rxrpc_set_service_reap_timer(conn->params.local->rxnet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 					     jiffies + rxrpc_connection_expiry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)  * destroy a virtual connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static void rxrpc_destroy_connection(struct rcu_head *rcu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	struct rxrpc_connection *conn =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		container_of(rcu, struct rxrpc_connection, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	_enter("{%d,u=%d}", conn->debug_id, atomic_read(&conn->usage));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	ASSERTCMP(atomic_read(&conn->usage), ==, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	_net("DESTROY CONN %d", conn->debug_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	del_timer_sync(&conn->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	rxrpc_purge_queue(&conn->rx_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	conn->security->clear(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	key_put(conn->params.key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	key_put(conn->server_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	rxrpc_put_bundle(conn->bundle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	rxrpc_put_peer(conn->params.peer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	if (atomic_dec_and_test(&conn->params.local->rxnet->nr_conns))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		wake_up_var(&conn->params.local->rxnet->nr_conns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	rxrpc_put_local(conn->params.local);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	kfree(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	_leave("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)  * reap dead service connections
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) void rxrpc_service_connection_reaper(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	struct rxrpc_connection *conn, *_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	struct rxrpc_net *rxnet =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		container_of(work, struct rxrpc_net, service_conn_reaper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	unsigned long expire_at, earliest, idle_timestamp, now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	LIST_HEAD(graveyard);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	_enter("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	earliest = now + MAX_JIFFY_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	write_lock(&rxnet->conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	list_for_each_entry_safe(conn, _p, &rxnet->service_conns, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		ASSERTCMP(atomic_read(&conn->usage), >, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		if (likely(atomic_read(&conn->usage) > 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		if (conn->state == RXRPC_CONN_SERVICE_PREALLOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		if (rxnet->live && !conn->params.local->dead) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			idle_timestamp = READ_ONCE(conn->idle_timestamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			expire_at = idle_timestamp + rxrpc_connection_expiry * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 			if (conn->params.local->service_closed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 				expire_at = idle_timestamp + rxrpc_closed_conn_expiry * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 			_debug("reap CONN %d { u=%d,t=%ld }",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 			       conn->debug_id, atomic_read(&conn->usage),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 			       (long)expire_at - (long)now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 			if (time_before(now, expire_at)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 				if (time_before(expire_at, earliest))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 					earliest = expire_at;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		/* The usage count sits at 1 whilst the object is unused on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		 * list; we reduce that to 0 to make the object unavailable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		if (atomic_cmpxchg(&conn->usage, 1, 0) != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		trace_rxrpc_conn(conn->debug_id, rxrpc_conn_reap_service, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		if (rxrpc_conn_is_client(conn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 			BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 			rxrpc_unpublish_service_conn(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		list_move_tail(&conn->link, &graveyard);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	write_unlock(&rxnet->conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	if (earliest != now + MAX_JIFFY_OFFSET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		_debug("reschedule reaper %ld", (long)earliest - (long)now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		ASSERT(time_after(earliest, now));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		rxrpc_set_service_reap_timer(rxnet, earliest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	while (!list_empty(&graveyard)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		conn = list_entry(graveyard.next, struct rxrpc_connection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 				  link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		list_del_init(&conn->link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		ASSERTCMP(atomic_read(&conn->usage), ==, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		rxrpc_kill_connection(conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	_leave("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)  * preemptively destroy all the service connection records rather than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)  * waiting for them to time out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) void rxrpc_destroy_all_connections(struct rxrpc_net *rxnet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	struct rxrpc_connection *conn, *_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	bool leak = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	_enter("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	atomic_dec(&rxnet->nr_conns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	rxrpc_destroy_all_client_connections(rxnet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	del_timer_sync(&rxnet->service_conn_reap_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	rxrpc_queue_work(&rxnet->service_conn_reaper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	flush_workqueue(rxrpc_workqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	write_lock(&rxnet->conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	list_for_each_entry_safe(conn, _p, &rxnet->service_conns, link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		pr_err("AF_RXRPC: Leaked conn %p {%d}\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		       conn, atomic_read(&conn->usage));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		leak = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	write_unlock(&rxnet->conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	BUG_ON(leak);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	ASSERT(list_empty(&rxnet->conn_proc_list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	/* We need to wait for the connections to be destroyed by RCU as they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	 * pin things that we still need to get rid of.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	wait_var_event(&rxnet->nr_conns, !atomic_read(&rxnet->nr_conns));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	_leave("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }