xref: /openbmc/linux/net/rxrpc/call_object.c (revision db099c62)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
28c3e34a4SDavid Howells /* RxRPC individual remote procedure call handling
38c3e34a4SDavid Howells  *
48c3e34a4SDavid Howells  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
58c3e34a4SDavid Howells  * Written by David Howells (dhowells@redhat.com)
68c3e34a4SDavid Howells  */
78c3e34a4SDavid Howells 
88c3e34a4SDavid Howells #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
98c3e34a4SDavid Howells 
108c3e34a4SDavid Howells #include <linux/slab.h>
118c3e34a4SDavid Howells #include <linux/module.h>
128c3e34a4SDavid Howells #include <linux/circ_buf.h>
138c3e34a4SDavid Howells #include <linux/spinlock_types.h>
148c3e34a4SDavid Howells #include <net/sock.h>
158c3e34a4SDavid Howells #include <net/af_rxrpc.h>
168c3e34a4SDavid Howells #include "ar-internal.h"
178c3e34a4SDavid Howells 
188c3e34a4SDavid Howells const char *const rxrpc_call_states[NR__RXRPC_CALL_STATES] = {
19999b69f8SDavid Howells 	[RXRPC_CALL_UNINITIALISED]		= "Uninit  ",
20999b69f8SDavid Howells 	[RXRPC_CALL_CLIENT_AWAIT_CONN]		= "ClWtConn",
218c3e34a4SDavid Howells 	[RXRPC_CALL_CLIENT_SEND_REQUEST]	= "ClSndReq",
228c3e34a4SDavid Howells 	[RXRPC_CALL_CLIENT_AWAIT_REPLY]		= "ClAwtRpl",
238c3e34a4SDavid Howells 	[RXRPC_CALL_CLIENT_RECV_REPLY]		= "ClRcvRpl",
2400e90712SDavid Howells 	[RXRPC_CALL_SERVER_PREALLOC]		= "SvPrealc",
258c3e34a4SDavid Howells 	[RXRPC_CALL_SERVER_SECURING]		= "SvSecure",
268c3e34a4SDavid Howells 	[RXRPC_CALL_SERVER_RECV_REQUEST]	= "SvRcvReq",
278c3e34a4SDavid Howells 	[RXRPC_CALL_SERVER_ACK_REQUEST]		= "SvAckReq",
288c3e34a4SDavid Howells 	[RXRPC_CALL_SERVER_SEND_REPLY]		= "SvSndRpl",
298c3e34a4SDavid Howells 	[RXRPC_CALL_SERVER_AWAIT_ACK]		= "SvAwtACK",
308c3e34a4SDavid Howells 	[RXRPC_CALL_COMPLETE]			= "Complete",
31f5c17aaeSDavid Howells };
32f5c17aaeSDavid Howells 
33f5c17aaeSDavid Howells const char *const rxrpc_call_completions[NR__RXRPC_CALL_COMPLETIONS] = {
34f5c17aaeSDavid Howells 	[RXRPC_CALL_SUCCEEDED]			= "Complete",
358c3e34a4SDavid Howells 	[RXRPC_CALL_REMOTELY_ABORTED]		= "RmtAbort",
368c3e34a4SDavid Howells 	[RXRPC_CALL_LOCALLY_ABORTED]		= "LocAbort",
37f5c17aaeSDavid Howells 	[RXRPC_CALL_LOCAL_ERROR]		= "LocError",
388c3e34a4SDavid Howells 	[RXRPC_CALL_NETWORK_ERROR]		= "NetError",
398c3e34a4SDavid Howells };
408c3e34a4SDavid Howells 
418c3e34a4SDavid Howells struct kmem_cache *rxrpc_call_jar;
428c3e34a4SDavid Howells 
43b7a7d674SDavid Howells static struct semaphore rxrpc_call_limiter =
44b7a7d674SDavid Howells 	__SEMAPHORE_INITIALIZER(rxrpc_call_limiter, 1000);
45b7a7d674SDavid Howells static struct semaphore rxrpc_kernel_call_limiter =
46b7a7d674SDavid Howells 	__SEMAPHORE_INITIALIZER(rxrpc_kernel_call_limiter, 1000);
47b7a7d674SDavid Howells 
4815f661dcSDavid Howells void rxrpc_poke_call(struct rxrpc_call *call, enum rxrpc_call_poke_trace what)
4915f661dcSDavid Howells {
50f3441d41SDavid Howells 	struct rxrpc_local *local = call->local;
5115f661dcSDavid Howells 	bool busy;
5215f661dcSDavid Howells 
5303fc55adSDavid Howells 	if (!test_bit(RXRPC_CALL_DISCONNECTED, &call->flags)) {
5415f661dcSDavid Howells 		spin_lock_bh(&local->lock);
5515f661dcSDavid Howells 		busy = !list_empty(&call->attend_link);
5615f661dcSDavid Howells 		trace_rxrpc_poke_call(call, busy, what);
57a33395abSDavid Howells 		if (!busy && !rxrpc_try_get_call(call, rxrpc_call_get_poke))
58a33395abSDavid Howells 			busy = true;
5915f661dcSDavid Howells 		if (!busy) {
6015f661dcSDavid Howells 			list_add_tail(&call->attend_link, &local->call_attend_q);
6115f661dcSDavid Howells 		}
6215f661dcSDavid Howells 		spin_unlock_bh(&local->lock);
63a33395abSDavid Howells 		if (!busy)
6415f661dcSDavid Howells 			rxrpc_wake_up_io_thread(local);
6515f661dcSDavid Howells 	}
6615f661dcSDavid Howells }
6715f661dcSDavid Howells 
68e99e88a9SKees Cook static void rxrpc_call_timer_expired(struct timer_list *t)
69248f219cSDavid Howells {
70e99e88a9SKees Cook 	struct rxrpc_call *call = from_timer(call, t, timer);
71248f219cSDavid Howells 
72248f219cSDavid Howells 	_enter("%d", call->debug_id);
73248f219cSDavid Howells 
7496b4059fSDavid Howells 	if (!__rxrpc_call_is_complete(call)) {
75334dfbfcSDavid Howells 		trace_rxrpc_timer_expired(call, jiffies);
765e6ef4f1SDavid Howells 		rxrpc_poke_call(call, rxrpc_call_poke_timer);
77fc7ab6d2SDavid Howells 	}
78248f219cSDavid Howells }
798c3e34a4SDavid Howells 
804a7f62f9SDavid Howells void rxrpc_reduce_call_timer(struct rxrpc_call *call,
814a7f62f9SDavid Howells 			     unsigned long expire_at,
824a7f62f9SDavid Howells 			     unsigned long now,
834a7f62f9SDavid Howells 			     enum rxrpc_timer_trace why)
844a7f62f9SDavid Howells {
854a7f62f9SDavid Howells 	trace_rxrpc_timer(call, why, now);
863feda9d6SDavid Howells 	timer_reduce(&call->timer, expire_at);
874a7f62f9SDavid Howells }
884a7f62f9SDavid Howells 
899faaff59SDavid Howells static struct lock_class_key rxrpc_call_user_mutex_lock_class_key;
908c3e34a4SDavid Howells 
913feda9d6SDavid Howells static void rxrpc_destroy_call(struct work_struct *);
923feda9d6SDavid Howells 
938c3e34a4SDavid Howells /*
948c3e34a4SDavid Howells  * find an extant server call
958c3e34a4SDavid Howells  * - called in process context with IRQs enabled
968c3e34a4SDavid Howells  */
978c3e34a4SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *rx,
988c3e34a4SDavid Howells 					      unsigned long user_call_ID)
998c3e34a4SDavid Howells {
1008c3e34a4SDavid Howells 	struct rxrpc_call *call;
1018c3e34a4SDavid Howells 	struct rb_node *p;
1028c3e34a4SDavid Howells 
1038c3e34a4SDavid Howells 	_enter("%p,%lx", rx, user_call_ID);
1048c3e34a4SDavid Howells 
1058c3e34a4SDavid Howells 	read_lock(&rx->call_lock);
1068c3e34a4SDavid Howells 
1078c3e34a4SDavid Howells 	p = rx->calls.rb_node;
1088c3e34a4SDavid Howells 	while (p) {
1098c3e34a4SDavid Howells 		call = rb_entry(p, struct rxrpc_call, sock_node);
1108c3e34a4SDavid Howells 
1118c3e34a4SDavid Howells 		if (user_call_ID < call->user_call_ID)
1128c3e34a4SDavid Howells 			p = p->rb_left;
1138c3e34a4SDavid Howells 		else if (user_call_ID > call->user_call_ID)
1148c3e34a4SDavid Howells 			p = p->rb_right;
1158c3e34a4SDavid Howells 		else
1168c3e34a4SDavid Howells 			goto found_extant_call;
1178c3e34a4SDavid Howells 	}
1188c3e34a4SDavid Howells 
1198c3e34a4SDavid Howells 	read_unlock(&rx->call_lock);
1208c3e34a4SDavid Howells 	_leave(" = NULL");
1218c3e34a4SDavid Howells 	return NULL;
1228c3e34a4SDavid Howells 
1238c3e34a4SDavid Howells found_extant_call:
124cb0fc0c9SDavid Howells 	rxrpc_get_call(call, rxrpc_call_get_sendmsg);
1258c3e34a4SDavid Howells 	read_unlock(&rx->call_lock);
126a0575429SDavid Howells 	_leave(" = %p [%d]", call, refcount_read(&call->ref));
1278c3e34a4SDavid Howells 	return call;
1288c3e34a4SDavid Howells }
1298c3e34a4SDavid Howells 
1308c3e34a4SDavid Howells /*
1318c3e34a4SDavid Howells  * allocate a new call
1328c3e34a4SDavid Howells  */
133a25e21f0SDavid Howells struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *rx, gfp_t gfp,
134a25e21f0SDavid Howells 				    unsigned int debug_id)
1358c3e34a4SDavid Howells {
1368c3e34a4SDavid Howells 	struct rxrpc_call *call;
137d3be4d24SDavid Howells 	struct rxrpc_net *rxnet = rxrpc_net(sock_net(&rx->sk));
1388c3e34a4SDavid Howells 
1398c3e34a4SDavid Howells 	call = kmem_cache_zalloc(rxrpc_call_jar, gfp);
1408c3e34a4SDavid Howells 	if (!call)
1418c3e34a4SDavid Howells 		return NULL;
1428c3e34a4SDavid Howells 
143540b1c48SDavid Howells 	mutex_init(&call->user_mutex);
1449faaff59SDavid Howells 
1459faaff59SDavid Howells 	/* Prevent lockdep reporting a deadlock false positive between the afs
1469faaff59SDavid Howells 	 * filesystem and sys_sendmsg() via the mmap sem.
1479faaff59SDavid Howells 	 */
1489faaff59SDavid Howells 	if (rx->sk.sk_kern_sock)
1499faaff59SDavid Howells 		lockdep_set_class(&call->user_mutex,
1509faaff59SDavid Howells 				  &rxrpc_call_user_mutex_lock_class_key);
1519faaff59SDavid Howells 
152e99e88a9SKees Cook 	timer_setup(&call->timer, rxrpc_call_timer_expired, 0);
1533feda9d6SDavid Howells 	INIT_WORK(&call->destroyer, rxrpc_destroy_call);
154999b69f8SDavid Howells 	INIT_LIST_HEAD(&call->link);
1559d35d880SDavid Howells 	INIT_LIST_HEAD(&call->wait_link);
1568c3e34a4SDavid Howells 	INIT_LIST_HEAD(&call->accept_link);
157248f219cSDavid Howells 	INIT_LIST_HEAD(&call->recvmsg_link);
158248f219cSDavid Howells 	INIT_LIST_HEAD(&call->sock_link);
15915f661dcSDavid Howells 	INIT_LIST_HEAD(&call->attend_link);
160cf37b598SDavid Howells 	INIT_LIST_HEAD(&call->tx_sendmsg);
161a4ea4c47SDavid Howells 	INIT_LIST_HEAD(&call->tx_buffer);
1625d7edbc9SDavid Howells 	skb_queue_head_init(&call->recvmsg_queue);
1635d7edbc9SDavid Howells 	skb_queue_head_init(&call->rx_oos_queue);
16445025bceSDavid Howells 	init_waitqueue_head(&call->waitq);
16520acbd9aSDavid Howells 	spin_lock_init(&call->notify_lock);
166a4ea4c47SDavid Howells 	spin_lock_init(&call->tx_lock);
167a0575429SDavid Howells 	refcount_set(&call->ref, 1);
168a25e21f0SDavid Howells 	call->debug_id = debug_id;
169e754eba6SDavid Howells 	call->tx_total_len = -1;
170a158bdd3SDavid Howells 	call->next_rx_timo = 20 * HZ;
171a158bdd3SDavid Howells 	call->next_req_timo = 1 * HZ;
1725bbf9533SDavid Howells 	call->ackr_window = 1;
1735bbf9533SDavid Howells 	call->ackr_wtop = 1;
1748c3e34a4SDavid Howells 
1758c3e34a4SDavid Howells 	memset(&call->sock_node, 0xed, sizeof(call->sock_node));
1768c3e34a4SDavid Howells 
17775e42126SDavid Howells 	call->rx_winsize = rxrpc_rx_window_size;
178248f219cSDavid Howells 	call->tx_winsize = 16;
17957494343SDavid Howells 
1801fc4fa2aSDavid Howells 	if (RXRPC_TX_SMSS > 2190)
18157494343SDavid Howells 		call->cong_cwnd = 2;
1821fc4fa2aSDavid Howells 	else if (RXRPC_TX_SMSS > 1095)
1831fc4fa2aSDavid Howells 		call->cong_cwnd = 3;
1841fc4fa2aSDavid Howells 	else
1851fc4fa2aSDavid Howells 		call->cong_cwnd = 4;
186a4ea4c47SDavid Howells 	call->cong_ssthresh = RXRPC_TX_MAX_WINDOW;
187d3be4d24SDavid Howells 
188d3be4d24SDavid Howells 	call->rxnet = rxnet;
1894700c4d8SDavid Howells 	call->rtt_avail = RXRPC_CALL_RTT_AVAIL_MASK;
190d3be4d24SDavid Howells 	atomic_inc(&rxnet->nr_calls);
1918c3e34a4SDavid Howells 	return call;
1928c3e34a4SDavid Howells }
1938c3e34a4SDavid Howells 
1948c3e34a4SDavid Howells /*
195999b69f8SDavid Howells  * Allocate a new client call.
1968c3e34a4SDavid Howells  */
1979faaff59SDavid Howells static struct rxrpc_call *rxrpc_alloc_client_call(struct rxrpc_sock *rx,
1989faaff59SDavid Howells 						  struct sockaddr_rxrpc *srx,
199f3441d41SDavid Howells 						  struct rxrpc_conn_parameters *cp,
200f3441d41SDavid Howells 						  struct rxrpc_call_params *p,
201a25e21f0SDavid Howells 						  gfp_t gfp,
202a25e21f0SDavid Howells 						  unsigned int debug_id)
2038c3e34a4SDavid Howells {
2048c3e34a4SDavid Howells 	struct rxrpc_call *call;
20557494343SDavid Howells 	ktime_t now;
206f3441d41SDavid Howells 	int ret;
2078c3e34a4SDavid Howells 
2088c3e34a4SDavid Howells 	_enter("");
2098c3e34a4SDavid Howells 
210a25e21f0SDavid Howells 	call = rxrpc_alloc_call(rx, gfp, debug_id);
2118c3e34a4SDavid Howells 	if (!call)
2128c3e34a4SDavid Howells 		return ERR_PTR(-ENOMEM);
21357494343SDavid Howells 	now = ktime_get_real();
21457494343SDavid Howells 	call->acks_latest_ts	= now;
21557494343SDavid Howells 	call->cong_tstamp	= now;
216f3441d41SDavid Howells 	call->dest_srx		= *srx;
217f3441d41SDavid Howells 	call->interruptibility	= p->interruptibility;
218f3441d41SDavid Howells 	call->tx_total_len	= p->tx_total_len;
219f3441d41SDavid Howells 	call->key		= key_get(cp->key);
220f3441d41SDavid Howells 	call->local		= rxrpc_get_local(cp->local, rxrpc_local_get_call);
221fdb99487SDavid Howells 	call->security_level	= cp->security_level;
222f3441d41SDavid Howells 	if (p->kernel)
223f3441d41SDavid Howells 		__set_bit(RXRPC_CALL_KERNEL, &call->flags);
224f3441d41SDavid Howells 	if (cp->upgrade)
225f3441d41SDavid Howells 		__set_bit(RXRPC_CALL_UPGRADE, &call->flags);
226f3441d41SDavid Howells 	if (cp->exclusive)
227f3441d41SDavid Howells 		__set_bit(RXRPC_CALL_EXCLUSIVE, &call->flags);
228f3441d41SDavid Howells 
229*db099c62SDavid Howells 	if (p->timeouts.normal)
230*db099c62SDavid Howells 		call->next_rx_timo = min(msecs_to_jiffies(p->timeouts.normal), 1UL);
231*db099c62SDavid Howells 	if (p->timeouts.idle)
232*db099c62SDavid Howells 		call->next_req_timo = min(msecs_to_jiffies(p->timeouts.idle), 1UL);
233*db099c62SDavid Howells 	if (p->timeouts.hard)
234*db099c62SDavid Howells 		call->hard_timo = p->timeouts.hard * HZ;
235*db099c62SDavid Howells 
236f3441d41SDavid Howells 	ret = rxrpc_init_client_call_security(call);
237f3441d41SDavid Howells 	if (ret < 0) {
23896b4059fSDavid Howells 		rxrpc_prefail_call(call, RXRPC_CALL_LOCAL_ERROR, ret);
239f3441d41SDavid Howells 		rxrpc_put_call(call, rxrpc_call_put_discard_error);
240f3441d41SDavid Howells 		return ERR_PTR(ret);
241f3441d41SDavid Howells 	}
242f3441d41SDavid Howells 
24396b4059fSDavid Howells 	rxrpc_set_call_state(call, RXRPC_CALL_CLIENT_AWAIT_CONN);
24496b4059fSDavid Howells 
245f3441d41SDavid Howells 	trace_rxrpc_call(call->debug_id, refcount_read(&call->ref),
246f3441d41SDavid Howells 			 p->user_call_ID, rxrpc_call_new_client);
247999b69f8SDavid Howells 
248999b69f8SDavid Howells 	_leave(" = %p", call);
249999b69f8SDavid Howells 	return call;
250999b69f8SDavid Howells }
251999b69f8SDavid Howells 
252999b69f8SDavid Howells /*
253248f219cSDavid Howells  * Initiate the call ack/resend/expiry timer.
254999b69f8SDavid Howells  */
2559d35d880SDavid Howells void rxrpc_start_call_timer(struct rxrpc_call *call)
256999b69f8SDavid Howells {
257a158bdd3SDavid Howells 	unsigned long now = jiffies;
258a158bdd3SDavid Howells 	unsigned long j = now + MAX_JIFFY_OFFSET;
259999b69f8SDavid Howells 
260530403d9SDavid Howells 	call->delay_ack_at = j;
261bd1fdf8cSDavid Howells 	call->ack_lost_at = j;
262a158bdd3SDavid Howells 	call->resend_at = j;
263a158bdd3SDavid Howells 	call->ping_at = j;
2645e6ef4f1SDavid Howells 	call->keepalive_at = j;
265a158bdd3SDavid Howells 	call->expect_rx_by = j;
266a158bdd3SDavid Howells 	call->expect_req_by = j;
267*db099c62SDavid Howells 	call->expect_term_by = j + call->hard_timo;
268a158bdd3SDavid Howells 	call->timer.expires = now;
2698c3e34a4SDavid Howells }
2708c3e34a4SDavid Howells 
2718c3e34a4SDavid Howells /*
272b7a7d674SDavid Howells  * Wait for a call slot to become available.
273b7a7d674SDavid Howells  */
274b7a7d674SDavid Howells static struct semaphore *rxrpc_get_call_slot(struct rxrpc_call_params *p, gfp_t gfp)
275b7a7d674SDavid Howells {
276b7a7d674SDavid Howells 	struct semaphore *limiter = &rxrpc_call_limiter;
277b7a7d674SDavid Howells 
278b7a7d674SDavid Howells 	if (p->kernel)
279b7a7d674SDavid Howells 		limiter = &rxrpc_kernel_call_limiter;
280b7a7d674SDavid Howells 	if (p->interruptibility == RXRPC_UNINTERRUPTIBLE) {
281b7a7d674SDavid Howells 		down(limiter);
282b7a7d674SDavid Howells 		return limiter;
283b7a7d674SDavid Howells 	}
284b7a7d674SDavid Howells 	return down_interruptible(limiter) < 0 ? NULL : limiter;
285b7a7d674SDavid Howells }
286b7a7d674SDavid Howells 
287b7a7d674SDavid Howells /*
288b7a7d674SDavid Howells  * Release a call slot.
289b7a7d674SDavid Howells  */
290b7a7d674SDavid Howells static void rxrpc_put_call_slot(struct rxrpc_call *call)
291b7a7d674SDavid Howells {
292b7a7d674SDavid Howells 	struct semaphore *limiter = &rxrpc_call_limiter;
293b7a7d674SDavid Howells 
294b7a7d674SDavid Howells 	if (test_bit(RXRPC_CALL_KERNEL, &call->flags))
295b7a7d674SDavid Howells 		limiter = &rxrpc_kernel_call_limiter;
296b7a7d674SDavid Howells 	up(limiter);
297b7a7d674SDavid Howells }
298b7a7d674SDavid Howells 
299b7a7d674SDavid Howells /*
3009d35d880SDavid Howells  * Start the process of connecting a call.  We obtain a peer and a connection
3019d35d880SDavid Howells  * bundle, but the actual association of a call with a connection is offloaded
3029d35d880SDavid Howells  * to the I/O thread to simplify locking.
3039d35d880SDavid Howells  */
3049d35d880SDavid Howells static int rxrpc_connect_call(struct rxrpc_call *call, gfp_t gfp)
3059d35d880SDavid Howells {
3069d35d880SDavid Howells 	struct rxrpc_local *local = call->local;
30701644a1fSDavid Howells 	int ret = -ENOMEM;
3089d35d880SDavid Howells 
3099d35d880SDavid Howells 	_enter("{%d,%lx},", call->debug_id, call->user_call_ID);
3109d35d880SDavid Howells 
3119d35d880SDavid Howells 	call->peer = rxrpc_lookup_peer(local, &call->dest_srx, gfp);
3129d35d880SDavid Howells 	if (!call->peer)
3139d35d880SDavid Howells 		goto error;
3149d35d880SDavid Howells 
3159d35d880SDavid Howells 	ret = rxrpc_look_up_bundle(call, gfp);
3169d35d880SDavid Howells 	if (ret < 0)
3179d35d880SDavid Howells 		goto error;
3189d35d880SDavid Howells 
3199d35d880SDavid Howells 	trace_rxrpc_client(NULL, -1, rxrpc_client_queue_new_call);
3209d35d880SDavid Howells 	rxrpc_get_call(call, rxrpc_call_get_io_thread);
3219d35d880SDavid Howells 	spin_lock(&local->client_call_lock);
3229d35d880SDavid Howells 	list_add_tail(&call->wait_link, &local->new_client_calls);
3239d35d880SDavid Howells 	spin_unlock(&local->client_call_lock);
3249d35d880SDavid Howells 	rxrpc_wake_up_io_thread(local);
3259d35d880SDavid Howells 	return 0;
3269d35d880SDavid Howells 
3279d35d880SDavid Howells error:
3289d35d880SDavid Howells 	__set_bit(RXRPC_CALL_DISCONNECTED, &call->flags);
3299d35d880SDavid Howells 	return ret;
3309d35d880SDavid Howells }
3319d35d880SDavid Howells 
3329d35d880SDavid Howells /*
333540b1c48SDavid Howells  * Set up a call for the given parameters.
334540b1c48SDavid Howells  * - Called with the socket lock held, which it must release.
335540b1c48SDavid Howells  * - If it returns a call, the call's lock will need releasing by the caller.
3368c3e34a4SDavid Howells  */
3378c3e34a4SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *rx,
33819ffa01cSDavid Howells 					 struct rxrpc_conn_parameters *cp,
339999b69f8SDavid Howells 					 struct sockaddr_rxrpc *srx,
34048124178SDavid Howells 					 struct rxrpc_call_params *p,
341a25e21f0SDavid Howells 					 gfp_t gfp,
342a25e21f0SDavid Howells 					 unsigned int debug_id)
343540b1c48SDavid Howells 	__releases(&rx->sk.sk_lock.slock)
34488f2a825SDavid Howells 	__acquires(&call->user_mutex)
3458c3e34a4SDavid Howells {
3468c3e34a4SDavid Howells 	struct rxrpc_call *call, *xcall;
347d3be4d24SDavid Howells 	struct rxrpc_net *rxnet;
348b7a7d674SDavid Howells 	struct semaphore *limiter;
3498c3e34a4SDavid Howells 	struct rb_node *parent, **pp;
350999b69f8SDavid Howells 	int ret;
3518c3e34a4SDavid Howells 
35248124178SDavid Howells 	_enter("%p,%lx", rx, p->user_call_ID);
3538c3e34a4SDavid Howells 
354b7a7d674SDavid Howells 	limiter = rxrpc_get_call_slot(p, gfp);
355b0f571ecSDavid Howells 	if (!limiter) {
356b0f571ecSDavid Howells 		release_sock(&rx->sk);
357b7a7d674SDavid Howells 		return ERR_PTR(-ERESTARTSYS);
358b0f571ecSDavid Howells 	}
359b7a7d674SDavid Howells 
360f3441d41SDavid Howells 	call = rxrpc_alloc_client_call(rx, srx, cp, p, gfp, debug_id);
3618c3e34a4SDavid Howells 	if (IS_ERR(call)) {
362540b1c48SDavid Howells 		release_sock(&rx->sk);
363b7a7d674SDavid Howells 		up(limiter);
3648c3e34a4SDavid Howells 		_leave(" = %ld", PTR_ERR(call));
3658c3e34a4SDavid Howells 		return call;
3668c3e34a4SDavid Howells 	}
3678c3e34a4SDavid Howells 
368540b1c48SDavid Howells 	/* We need to protect a partially set up call against the user as we
369540b1c48SDavid Howells 	 * will be acting outside the socket lock.
370540b1c48SDavid Howells 	 */
371540b1c48SDavid Howells 	mutex_lock(&call->user_mutex);
372540b1c48SDavid Howells 
373999b69f8SDavid Howells 	/* Publish the call, even though it is incompletely set up as yet */
3748c3e34a4SDavid Howells 	write_lock(&rx->call_lock);
3758c3e34a4SDavid Howells 
3768c3e34a4SDavid Howells 	pp = &rx->calls.rb_node;
3778c3e34a4SDavid Howells 	parent = NULL;
3788c3e34a4SDavid Howells 	while (*pp) {
3798c3e34a4SDavid Howells 		parent = *pp;
3808c3e34a4SDavid Howells 		xcall = rb_entry(parent, struct rxrpc_call, sock_node);
3818c3e34a4SDavid Howells 
38248124178SDavid Howells 		if (p->user_call_ID < xcall->user_call_ID)
3838c3e34a4SDavid Howells 			pp = &(*pp)->rb_left;
38448124178SDavid Howells 		else if (p->user_call_ID > xcall->user_call_ID)
3858c3e34a4SDavid Howells 			pp = &(*pp)->rb_right;
3868c3e34a4SDavid Howells 		else
387357f5ef6SDavid Howells 			goto error_dup_user_ID;
3888c3e34a4SDavid Howells 	}
3898c3e34a4SDavid Howells 
390248f219cSDavid Howells 	rcu_assign_pointer(call->socket, rx);
39148124178SDavid Howells 	call->user_call_ID = p->user_call_ID;
392357f5ef6SDavid Howells 	__set_bit(RXRPC_CALL_HAS_USERID, &call->flags);
393cb0fc0c9SDavid Howells 	rxrpc_get_call(call, rxrpc_call_get_userid);
3948c3e34a4SDavid Howells 	rb_link_node(&call->sock_node, parent, pp);
3958c3e34a4SDavid Howells 	rb_insert_color(&call->sock_node, &rx->calls);
396248f219cSDavid Howells 	list_add(&call->sock_link, &rx->sock_calls);
397248f219cSDavid Howells 
3988c3e34a4SDavid Howells 	write_unlock(&rx->call_lock);
3998c3e34a4SDavid Howells 
400d3be4d24SDavid Howells 	rxnet = call->rxnet;
4013dd9c8b5SDavid Howells 	spin_lock(&rxnet->call_lock);
402ad25f5cbSDavid Howells 	list_add_tail_rcu(&call->link, &rxnet->calls);
4033dd9c8b5SDavid Howells 	spin_unlock(&rxnet->call_lock);
4048c3e34a4SDavid Howells 
405540b1c48SDavid Howells 	/* From this point on, the call is protected by its own lock. */
406540b1c48SDavid Howells 	release_sock(&rx->sk);
407540b1c48SDavid Howells 
408248f219cSDavid Howells 	/* Set up or get a connection record and set the protocol parameters,
409248f219cSDavid Howells 	 * including channel number and call ID.
410248f219cSDavid Howells 	 */
4111bab27afSDavid Howells 	ret = rxrpc_connect_call(call, gfp);
412999b69f8SDavid Howells 	if (ret < 0)
41365550098SDavid Howells 		goto error_attached_to_socket;
414999b69f8SDavid Howells 
4158c3e34a4SDavid Howells 	_leave(" = %p [new]", call);
4168c3e34a4SDavid Howells 	return call;
4178c3e34a4SDavid Howells 
4188c3e34a4SDavid Howells 	/* We unexpectedly found the user ID in the list after taking
4198c3e34a4SDavid Howells 	 * the call_lock.  This shouldn't happen unless the user races
4208c3e34a4SDavid Howells 	 * with itself and tries to add the same user ID twice at the
4218c3e34a4SDavid Howells 	 * same time in different threads.
4228c3e34a4SDavid Howells 	 */
423357f5ef6SDavid Howells error_dup_user_ID:
4248c3e34a4SDavid Howells 	write_unlock(&rx->call_lock);
425540b1c48SDavid Howells 	release_sock(&rx->sk);
42696b4059fSDavid Howells 	rxrpc_prefail_call(call, RXRPC_CALL_LOCAL_ERROR, -EEXIST);
427cb0fc0c9SDavid Howells 	trace_rxrpc_call(call->debug_id, refcount_read(&call->ref), 0,
428cb0fc0c9SDavid Howells 			 rxrpc_call_see_userid_exists);
429540b1c48SDavid Howells 	mutex_unlock(&call->user_mutex);
430cb0fc0c9SDavid Howells 	rxrpc_put_call(call, rxrpc_call_put_userid_exists);
43165550098SDavid Howells 	_leave(" = -EEXIST");
43265550098SDavid Howells 	return ERR_PTR(-EEXIST);
43365550098SDavid Howells 
43465550098SDavid Howells 	/* We got an error, but the call is attached to the socket and is in
4359d35d880SDavid Howells 	 * need of release.  However, we might now race with recvmsg() when it
4369d35d880SDavid Howells 	 * completion notifies the socket.  Return 0 from sys_sendmsg() and
43765550098SDavid Howells 	 * leave the error to recvmsg() to deal with.
43865550098SDavid Howells 	 */
43965550098SDavid Howells error_attached_to_socket:
440cb0fc0c9SDavid Howells 	trace_rxrpc_call(call->debug_id, refcount_read(&call->ref), ret,
441cb0fc0c9SDavid Howells 			 rxrpc_call_see_connect_failed);
4429d35d880SDavid Howells 	rxrpc_set_call_completion(call, RXRPC_CALL_LOCAL_ERROR, 0, ret);
44365550098SDavid Howells 	_leave(" = c=%08x [err]", call->debug_id);
44465550098SDavid Howells 	return call;
4458c3e34a4SDavid Howells }
4468c3e34a4SDavid Howells 
4478c3e34a4SDavid Howells /*
448248f219cSDavid Howells  * Set up an incoming call.  call->conn points to the connection.
449248f219cSDavid Howells  * This is called in BH context and isn't allowed to fail.
4508c3e34a4SDavid Howells  */
451248f219cSDavid Howells void rxrpc_incoming_call(struct rxrpc_sock *rx,
452248f219cSDavid Howells 			 struct rxrpc_call *call,
45342886ffeSDavid Howells 			 struct sk_buff *skb)
4548c3e34a4SDavid Howells {
455248f219cSDavid Howells 	struct rxrpc_connection *conn = call->conn;
45642886ffeSDavid Howells 	struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
457248f219cSDavid Howells 	u32 chan;
4588c3e34a4SDavid Howells 
459248f219cSDavid Howells 	_enter(",%d", call->conn->debug_id);
4608c3e34a4SDavid Howells 
461248f219cSDavid Howells 	rcu_assign_pointer(call->socket, rx);
462248f219cSDavid Howells 	call->call_id		= sp->hdr.callNumber;
463f3441d41SDavid Howells 	call->dest_srx.srx_service = sp->hdr.serviceId;
464248f219cSDavid Howells 	call->cid		= sp->hdr.cid;
46557494343SDavid Howells 	call->cong_tstamp	= skb->tstamp;
4668c3e34a4SDavid Howells 
467a343b174SDavid Howells 	__set_bit(RXRPC_CALL_EXPOSED, &call->flags);
46896b4059fSDavid Howells 	rxrpc_set_call_state(call, RXRPC_CALL_SERVER_SECURING);
469a343b174SDavid Howells 
4705e6ef4f1SDavid Howells 	spin_lock(&conn->state_lock);
4715e6ef4f1SDavid Howells 
4725e6ef4f1SDavid Howells 	switch (conn->state) {
4735e6ef4f1SDavid Howells 	case RXRPC_CONN_SERVICE_UNSECURED:
4745e6ef4f1SDavid Howells 	case RXRPC_CONN_SERVICE_CHALLENGING:
47596b4059fSDavid Howells 		rxrpc_set_call_state(call, RXRPC_CALL_SERVER_SECURING);
4765e6ef4f1SDavid Howells 		break;
4775e6ef4f1SDavid Howells 	case RXRPC_CONN_SERVICE:
47896b4059fSDavid Howells 		rxrpc_set_call_state(call, RXRPC_CALL_SERVER_RECV_REQUEST);
4795e6ef4f1SDavid Howells 		break;
4805e6ef4f1SDavid Howells 
481a00ce28bSDavid Howells 	case RXRPC_CONN_ABORTED:
48296b4059fSDavid Howells 		rxrpc_set_call_completion(call, conn->completion,
4835e6ef4f1SDavid Howells 					  conn->abort_code, conn->error);
4845e6ef4f1SDavid Howells 		break;
4855e6ef4f1SDavid Howells 	default:
4865e6ef4f1SDavid Howells 		BUG();
4875e6ef4f1SDavid Howells 	}
4885e6ef4f1SDavid Howells 
4895040011dSDavid Howells 	rxrpc_get_call(call, rxrpc_call_get_io_thread);
4905040011dSDavid Howells 
491248f219cSDavid Howells 	/* Set the channel for this call.  We don't get channel_lock as we're
492248f219cSDavid Howells 	 * only defending against the data_ready handler (which we're called
493248f219cSDavid Howells 	 * from) and the RESPONSE packet parser (which is only really
494248f219cSDavid Howells 	 * interested in call_counter and can cope with a disagreement with the
495248f219cSDavid Howells 	 * call pointer).
4968c3e34a4SDavid Howells 	 */
497248f219cSDavid Howells 	chan = sp->hdr.cid & RXRPC_CHANNELMASK;
498248f219cSDavid Howells 	conn->channels[chan].call_counter = call->call_id;
499248f219cSDavid Howells 	conn->channels[chan].call_id = call->call_id;
5009d35d880SDavid Howells 	conn->channels[chan].call = call;
5015e6ef4f1SDavid Howells 	spin_unlock(&conn->state_lock);
5028c3e34a4SDavid Howells 
5032cc80086SDavid Howells 	spin_lock(&conn->peer->lock);
50429fb4ec3SDavid Howells 	hlist_add_head(&call->error_link, &conn->peer->error_targets);
5052cc80086SDavid Howells 	spin_unlock(&conn->peer->lock);
5068c3e34a4SDavid Howells 
507248f219cSDavid Howells 	rxrpc_start_call_timer(call);
508248f219cSDavid Howells 	_leave("");
5098c3e34a4SDavid Howells }
5108c3e34a4SDavid Howells 
5118c3e34a4SDavid Howells /*
512e34d4234SDavid Howells  * Note the re-emergence of a call.
513e34d4234SDavid Howells  */
514cb0fc0c9SDavid Howells void rxrpc_see_call(struct rxrpc_call *call, enum rxrpc_call_trace why)
515e34d4234SDavid Howells {
516e34d4234SDavid Howells 	if (call) {
517cb0fc0c9SDavid Howells 		int r = refcount_read(&call->ref);
518e34d4234SDavid Howells 
519cb0fc0c9SDavid Howells 		trace_rxrpc_call(call->debug_id, r, 0, why);
520e34d4234SDavid Howells 	}
521e34d4234SDavid Howells }
522e34d4234SDavid Howells 
5235e6ef4f1SDavid Howells struct rxrpc_call *rxrpc_try_get_call(struct rxrpc_call *call,
5245e6ef4f1SDavid Howells 				      enum rxrpc_call_trace why)
5254a7f62f9SDavid Howells {
526cb0fc0c9SDavid Howells 	int r;
5274a7f62f9SDavid Howells 
5285e6ef4f1SDavid Howells 	if (!call || !__refcount_inc_not_zero(&call->ref, &r))
5295e6ef4f1SDavid Howells 		return NULL;
530cb0fc0c9SDavid Howells 	trace_rxrpc_call(call->debug_id, r + 1, 0, why);
5315e6ef4f1SDavid Howells 	return call;
5324a7f62f9SDavid Howells }
5334a7f62f9SDavid Howells 
534e34d4234SDavid Howells /*
535e34d4234SDavid Howells  * Note the addition of a ref on a call.
536e34d4234SDavid Howells  */
537cb0fc0c9SDavid Howells void rxrpc_get_call(struct rxrpc_call *call, enum rxrpc_call_trace why)
538e34d4234SDavid Howells {
539cb0fc0c9SDavid Howells 	int r;
540e34d4234SDavid Howells 
541cb0fc0c9SDavid Howells 	__refcount_inc(&call->ref, &r);
542cb0fc0c9SDavid Howells 	trace_rxrpc_call(call->debug_id, r + 1, 0, why);
543e34d4234SDavid Howells }
544e34d4234SDavid Howells 
545e34d4234SDavid Howells /*
546a4ea4c47SDavid Howells  * Clean up the Rx skb ring.
547a641fd00SDavid Howells  */
548a641fd00SDavid Howells static void rxrpc_cleanup_ring(struct rxrpc_call *call)
549a641fd00SDavid Howells {
5505d7edbc9SDavid Howells 	skb_queue_purge(&call->recvmsg_queue);
5515d7edbc9SDavid Howells 	skb_queue_purge(&call->rx_oos_queue);
552a641fd00SDavid Howells }
553a641fd00SDavid Howells 
554a641fd00SDavid Howells /*
555248f219cSDavid Howells  * Detach a call from its owning socket.
5568c3e34a4SDavid Howells  */
5578d94aa38SDavid Howells void rxrpc_release_call(struct rxrpc_sock *rx, struct rxrpc_call *call)
5588c3e34a4SDavid Howells {
559248f219cSDavid Howells 	struct rxrpc_connection *conn = call->conn;
5609d35d880SDavid Howells 	bool put = false, putu = false;
561248f219cSDavid Howells 
562a0575429SDavid Howells 	_enter("{%d,%d}", call->debug_id, refcount_read(&call->ref));
563248f219cSDavid Howells 
564cb0fc0c9SDavid Howells 	trace_rxrpc_call(call->debug_id, refcount_read(&call->ref),
565cb0fc0c9SDavid Howells 			 call->flags, rxrpc_call_see_release);
5668c3e34a4SDavid Howells 
5678c3e34a4SDavid Howells 	if (test_and_set_bit(RXRPC_CALL_RELEASED, &call->flags))
5688c3e34a4SDavid Howells 		BUG();
5698c3e34a4SDavid Howells 
570b7a7d674SDavid Howells 	rxrpc_put_call_slot(call);
5718c3e34a4SDavid Howells 
572248f219cSDavid Howells 	/* Make sure we don't get any more notifications */
573223f5901SDavid Howells 	spin_lock(&rx->recvmsg_lock);
574e653cfe4SDavid Howells 
575248f219cSDavid Howells 	if (!list_empty(&call->recvmsg_link)) {
5768c3e34a4SDavid Howells 		_debug("unlinking once-pending call %p { e=%lx f=%lx }",
5778c3e34a4SDavid Howells 		       call, call->events, call->flags);
578248f219cSDavid Howells 		list_del(&call->recvmsg_link);
579248f219cSDavid Howells 		put = true;
580248f219cSDavid Howells 	}
581248f219cSDavid Howells 
582248f219cSDavid Howells 	/* list_empty() must return false in rxrpc_notify_socket() */
583248f219cSDavid Howells 	call->recvmsg_link.next = NULL;
584248f219cSDavid Howells 	call->recvmsg_link.prev = NULL;
585248f219cSDavid Howells 
586223f5901SDavid Howells 	spin_unlock(&rx->recvmsg_lock);
587248f219cSDavid Howells 	if (put)
588cb0fc0c9SDavid Howells 		rxrpc_put_call(call, rxrpc_call_put_unnotify);
589248f219cSDavid Howells 
590248f219cSDavid Howells 	write_lock(&rx->call_lock);
591248f219cSDavid Howells 
592248f219cSDavid Howells 	if (test_and_clear_bit(RXRPC_CALL_HAS_USERID, &call->flags)) {
5938c3e34a4SDavid Howells 		rb_erase(&call->sock_node, &rx->calls);
5948c3e34a4SDavid Howells 		memset(&call->sock_node, 0xdd, sizeof(call->sock_node));
5959d35d880SDavid Howells 		putu = true;
5968c3e34a4SDavid Howells 	}
5978c3e34a4SDavid Howells 
598248f219cSDavid Howells 	list_del(&call->sock_link);
599248f219cSDavid Howells 	write_unlock(&rx->call_lock);
6008c3e34a4SDavid Howells 
601248f219cSDavid Howells 	_debug("RELEASE CALL %p (%d CONN %p)", call, call->debug_id, conn);
6028c3e34a4SDavid Howells 
6039d35d880SDavid Howells 	if (putu)
6049d35d880SDavid Howells 		rxrpc_put_call(call, rxrpc_call_put_userid);
6059d35d880SDavid Howells 
6068c3e34a4SDavid Howells 	_leave("");
6078c3e34a4SDavid Howells }
6088c3e34a4SDavid Howells 
6098c3e34a4SDavid Howells /*
6108c3e34a4SDavid Howells  * release all the calls associated with a socket
6118c3e34a4SDavid Howells  */
6128c3e34a4SDavid Howells void rxrpc_release_calls_on_socket(struct rxrpc_sock *rx)
6138c3e34a4SDavid Howells {
6148c3e34a4SDavid Howells 	struct rxrpc_call *call;
6158c3e34a4SDavid Howells 
6168c3e34a4SDavid Howells 	_enter("%p", rx);
6178c3e34a4SDavid Howells 
6180360da6dSDavid Howells 	while (!list_empty(&rx->to_be_accepted)) {
6190360da6dSDavid Howells 		call = list_entry(rx->to_be_accepted.next,
6200360da6dSDavid Howells 				  struct rxrpc_call, accept_link);
6210360da6dSDavid Howells 		list_del(&call->accept_link);
62257af281eSDavid Howells 		rxrpc_propose_abort(call, RX_CALL_DEAD, -ECONNRESET,
62357af281eSDavid Howells 				    rxrpc_abort_call_sock_release_tba);
624cb0fc0c9SDavid Howells 		rxrpc_put_call(call, rxrpc_call_put_release_sock_tba);
6250360da6dSDavid Howells 	}
6260360da6dSDavid Howells 
627248f219cSDavid Howells 	while (!list_empty(&rx->sock_calls)) {
628248f219cSDavid Howells 		call = list_entry(rx->sock_calls.next,
629248f219cSDavid Howells 				  struct rxrpc_call, sock_link);
630cb0fc0c9SDavid Howells 		rxrpc_get_call(call, rxrpc_call_get_release_sock);
63157af281eSDavid Howells 		rxrpc_propose_abort(call, RX_CALL_DEAD, -ECONNRESET,
63257af281eSDavid Howells 				    rxrpc_abort_call_sock_release);
6338d94aa38SDavid Howells 		rxrpc_release_call(rx, call);
634cb0fc0c9SDavid Howells 		rxrpc_put_call(call, rxrpc_call_put_release_sock);
6358c3e34a4SDavid Howells 	}
6368c3e34a4SDavid Howells 
6378c3e34a4SDavid Howells 	_leave("");
6388c3e34a4SDavid Howells }
6398c3e34a4SDavid Howells 
6408c3e34a4SDavid Howells /*
6418c3e34a4SDavid Howells  * release a call
6428c3e34a4SDavid Howells  */
643cb0fc0c9SDavid Howells void rxrpc_put_call(struct rxrpc_call *call, enum rxrpc_call_trace why)
6448c3e34a4SDavid Howells {
645d3be4d24SDavid Howells 	struct rxrpc_net *rxnet = call->rxnet;
64648c9e0ecSDavid Howells 	unsigned int debug_id = call->debug_id;
647a0575429SDavid Howells 	bool dead;
648cb0fc0c9SDavid Howells 	int r;
649e34d4234SDavid Howells 
6508c3e34a4SDavid Howells 	ASSERT(call != NULL);
6518c3e34a4SDavid Howells 
652cb0fc0c9SDavid Howells 	dead = __refcount_dec_and_test(&call->ref, &r);
653cb0fc0c9SDavid Howells 	trace_rxrpc_call(debug_id, r - 1, 0, why);
654a0575429SDavid Howells 	if (dead) {
65596b4059fSDavid Howells 		ASSERTCMP(__rxrpc_call_state(call), ==, RXRPC_CALL_COMPLETE);
656e34d4234SDavid Howells 
6572baec2c3SDavid Howells 		if (!list_empty(&call->link)) {
6583dd9c8b5SDavid Howells 			spin_lock(&rxnet->call_lock);
659248f219cSDavid Howells 			list_del_init(&call->link);
6603dd9c8b5SDavid Howells 			spin_unlock(&rxnet->call_lock);
6612baec2c3SDavid Howells 		}
662e34d4234SDavid Howells 
6638d94aa38SDavid Howells 		rxrpc_cleanup_call(call);
664e34d4234SDavid Howells 	}
6658c3e34a4SDavid Howells }
6668c3e34a4SDavid Howells 
6678c3e34a4SDavid Howells /*
6683feda9d6SDavid Howells  * Free up the call under RCU.
669dee46364SDavid Howells  */
6703feda9d6SDavid Howells static void rxrpc_rcu_free_call(struct rcu_head *rcu)
671dee46364SDavid Howells {
6723feda9d6SDavid Howells 	struct rxrpc_call *call = container_of(rcu, struct rxrpc_call, rcu);
6733feda9d6SDavid Howells 	struct rxrpc_net *rxnet = READ_ONCE(call->rxnet);
674dee46364SDavid Howells 
675dee46364SDavid Howells 	kmem_cache_free(rxrpc_call_jar, call);
676d3be4d24SDavid Howells 	if (atomic_dec_and_test(&rxnet->nr_calls))
6775bb053beSLinus Torvalds 		wake_up_var(&rxnet->nr_calls);
678dee46364SDavid Howells }
679dee46364SDavid Howells 
680dee46364SDavid Howells /*
6813feda9d6SDavid Howells  * Final call destruction - but must be done in process context.
682963485d4SDavid Howells  */
6833feda9d6SDavid Howells static void rxrpc_destroy_call(struct work_struct *work)
684963485d4SDavid Howells {
6853feda9d6SDavid Howells 	struct rxrpc_call *call = container_of(work, struct rxrpc_call, destroyer);
686a4ea4c47SDavid Howells 	struct rxrpc_txbuf *txb;
687a4ea4c47SDavid Howells 
6883feda9d6SDavid Howells 	del_timer_sync(&call->timer);
6898c3e34a4SDavid Howells 
690a641fd00SDavid Howells 	rxrpc_cleanup_ring(call);
691cf37b598SDavid Howells 	while ((txb = list_first_entry_or_null(&call->tx_sendmsg,
692cf37b598SDavid Howells 					       struct rxrpc_txbuf, call_link))) {
693cf37b598SDavid Howells 		list_del(&txb->call_link);
694cf37b598SDavid Howells 		rxrpc_put_txbuf(txb, rxrpc_txbuf_put_cleaned);
695cf37b598SDavid Howells 	}
696a4ea4c47SDavid Howells 	while ((txb = list_first_entry_or_null(&call->tx_buffer,
697a4ea4c47SDavid Howells 					       struct rxrpc_txbuf, call_link))) {
698a4ea4c47SDavid Howells 		list_del(&txb->call_link);
699a4ea4c47SDavid Howells 		rxrpc_put_txbuf(txb, rxrpc_txbuf_put_cleaned);
700a4ea4c47SDavid Howells 	}
7015e6ef4f1SDavid Howells 
702a4ea4c47SDavid Howells 	rxrpc_put_txbuf(call->tx_pending, rxrpc_txbuf_put_cleaned);
7033feda9d6SDavid Howells 	rxrpc_put_connection(call->conn, rxrpc_conn_put_call);
7041bab27afSDavid Howells 	rxrpc_deactivate_bundle(call->bundle);
7051bab27afSDavid Howells 	rxrpc_put_bundle(call->bundle, rxrpc_bundle_put_call);
7063feda9d6SDavid Howells 	rxrpc_put_peer(call->peer, rxrpc_peer_put_call);
707f3441d41SDavid Howells 	rxrpc_put_local(call->local, rxrpc_local_put_call);
7083feda9d6SDavid Howells 	call_rcu(&call->rcu, rxrpc_rcu_free_call);
7093feda9d6SDavid Howells }
7108c3e34a4SDavid Howells 
7113feda9d6SDavid Howells /*
7123feda9d6SDavid Howells  * clean up a call
7133feda9d6SDavid Howells  */
7143feda9d6SDavid Howells void rxrpc_cleanup_call(struct rxrpc_call *call)
7153feda9d6SDavid Howells {
7163feda9d6SDavid Howells 	memset(&call->sock_node, 0xcd, sizeof(call->sock_node));
7173feda9d6SDavid Howells 
71896b4059fSDavid Howells 	ASSERTCMP(__rxrpc_call_state(call), ==, RXRPC_CALL_COMPLETE);
7193feda9d6SDavid Howells 	ASSERT(test_bit(RXRPC_CALL_RELEASED, &call->flags));
7203feda9d6SDavid Howells 
7215e6ef4f1SDavid Howells 	del_timer(&call->timer);
7223feda9d6SDavid Howells 
7235e6ef4f1SDavid Howells 	if (rcu_read_lock_held())
7243feda9d6SDavid Howells 		/* Can't use the rxrpc workqueue as we need to cancel/flush
7253feda9d6SDavid Howells 		 * something that may be running/waiting there.
7263feda9d6SDavid Howells 		 */
7273feda9d6SDavid Howells 		schedule_work(&call->destroyer);
7283feda9d6SDavid Howells 	else
7293feda9d6SDavid Howells 		rxrpc_destroy_call(&call->destroyer);
7308c3e34a4SDavid Howells }
7318c3e34a4SDavid Howells 
7328c3e34a4SDavid Howells /*
7332baec2c3SDavid Howells  * Make sure that all calls are gone from a network namespace.  To reach this
7342baec2c3SDavid Howells  * point, any open UDP sockets in that namespace must have been closed, so any
7352baec2c3SDavid Howells  * outstanding calls cannot be doing I/O.
7368c3e34a4SDavid Howells  */
7372baec2c3SDavid Howells void rxrpc_destroy_all_calls(struct rxrpc_net *rxnet)
7388c3e34a4SDavid Howells {
7398c3e34a4SDavid Howells 	struct rxrpc_call *call;
7408c3e34a4SDavid Howells 
7418c3e34a4SDavid Howells 	_enter("");
7428d94aa38SDavid Howells 
743b1302342SDavid Howells 	if (!list_empty(&rxnet->calls)) {
7443dd9c8b5SDavid Howells 		spin_lock(&rxnet->call_lock);
7458c3e34a4SDavid Howells 
7462baec2c3SDavid Howells 		while (!list_empty(&rxnet->calls)) {
747b1302342SDavid Howells 			call = list_entry(rxnet->calls.next,
748b1302342SDavid Howells 					  struct rxrpc_call, link);
7498c3e34a4SDavid Howells 			_debug("Zapping call %p", call);
7508c3e34a4SDavid Howells 
751cb0fc0c9SDavid Howells 			rxrpc_see_call(call, rxrpc_call_see_zap);
7528c3e34a4SDavid Howells 			list_del_init(&call->link);
7538c3e34a4SDavid Howells 
754248f219cSDavid Howells 			pr_err("Call %p still in use (%d,%s,%lx,%lx)!\n",
755a0575429SDavid Howells 			       call, refcount_read(&call->ref),
75696b4059fSDavid Howells 			       rxrpc_call_states[__rxrpc_call_state(call)],
7578c3e34a4SDavid Howells 			       call->flags, call->events);
7588c3e34a4SDavid Howells 
7593dd9c8b5SDavid Howells 			spin_unlock(&rxnet->call_lock);
7608c3e34a4SDavid Howells 			cond_resched();
7613dd9c8b5SDavid Howells 			spin_lock(&rxnet->call_lock);
7628c3e34a4SDavid Howells 		}
7638c3e34a4SDavid Howells 
7643dd9c8b5SDavid Howells 		spin_unlock(&rxnet->call_lock);
765b1302342SDavid Howells 	}
766d3be4d24SDavid Howells 
767d3be4d24SDavid Howells 	atomic_dec(&rxnet->nr_calls);
7685bb053beSLinus Torvalds 	wait_var_event(&rxnet->nr_calls, !atomic_read(&rxnet->nr_calls));
7698c3e34a4SDavid Howells }
770