]>
Commit | Line | Data |
---|---|---|
17926a79 DH |
1 | /* RxRPC individual remote procedure call handling |
2 | * | |
3 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. | |
4 | * Written by David Howells (dhowells@redhat.com) | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version | |
9 | * 2 of the License, or (at your option) any later version. | |
10 | */ | |
11 | ||
9b6d5398 JP |
12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
13 | ||
5a0e3ad6 | 14 | #include <linux/slab.h> |
17926a79 DH |
15 | #include <linux/module.h> |
16 | #include <linux/circ_buf.h> | |
7727640c | 17 | #include <linux/spinlock_types.h> |
17926a79 DH |
18 | #include <net/sock.h> |
19 | #include <net/af_rxrpc.h> | |
20 | #include "ar-internal.h" | |
21 | ||
5873c083 DH |
22 | /* |
23 | * Maximum lifetime of a call (in jiffies). | |
24 | */ | |
dad8aff7 | 25 | unsigned int rxrpc_max_call_lifetime = 60 * HZ; |
5873c083 | 26 | |
5b8848d1 | 27 | const char *const rxrpc_call_states[NR__RXRPC_CALL_STATES] = { |
f5c17aae | 28 | [RXRPC_CALL_UNINITIALISED] = "Uninit ", |
999b69f8 | 29 | [RXRPC_CALL_CLIENT_AWAIT_CONN] = "ClWtConn", |
1f8481d1 DH |
30 | [RXRPC_CALL_CLIENT_SEND_REQUEST] = "ClSndReq", |
31 | [RXRPC_CALL_CLIENT_AWAIT_REPLY] = "ClAwtRpl", | |
32 | [RXRPC_CALL_CLIENT_RECV_REPLY] = "ClRcvRpl", | |
00e90712 | 33 | [RXRPC_CALL_SERVER_PREALLOC] = "SvPrealc", |
1f8481d1 DH |
34 | [RXRPC_CALL_SERVER_SECURING] = "SvSecure", |
35 | [RXRPC_CALL_SERVER_ACCEPTING] = "SvAccept", | |
36 | [RXRPC_CALL_SERVER_RECV_REQUEST] = "SvRcvReq", | |
37 | [RXRPC_CALL_SERVER_ACK_REQUEST] = "SvAckReq", | |
38 | [RXRPC_CALL_SERVER_SEND_REPLY] = "SvSndRpl", | |
39 | [RXRPC_CALL_SERVER_AWAIT_ACK] = "SvAwtACK", | |
40 | [RXRPC_CALL_COMPLETE] = "Complete", | |
f5c17aae DH |
41 | }; |
42 | ||
43 | const char *const rxrpc_call_completions[NR__RXRPC_CALL_COMPLETIONS] = { | |
44 | [RXRPC_CALL_SUCCEEDED] = "Complete", | |
1f8481d1 DH |
45 | [RXRPC_CALL_REMOTELY_ABORTED] = "RmtAbort", |
46 | [RXRPC_CALL_LOCALLY_ABORTED] = "LocAbort", | |
f5c17aae | 47 | [RXRPC_CALL_LOCAL_ERROR] = "LocError", |
1f8481d1 | 48 | [RXRPC_CALL_NETWORK_ERROR] = "NetError", |
1f8481d1 DH |
49 | }; |
50 | ||
fff72429 DH |
51 | const char rxrpc_call_traces[rxrpc_call__nr_trace][4] = { |
52 | [rxrpc_call_new_client] = "NWc", | |
53 | [rxrpc_call_new_service] = "NWs", | |
54 | [rxrpc_call_queued] = "QUE", | |
55 | [rxrpc_call_queued_ref] = "QUR", | |
56 | [rxrpc_call_seen] = "SEE", | |
57 | [rxrpc_call_got] = "GOT", | |
fff72429 | 58 | [rxrpc_call_got_userid] = "Gus", |
cbd00891 | 59 | [rxrpc_call_got_kernel] = "Gke", |
fff72429 | 60 | [rxrpc_call_put] = "PUT", |
fff72429 | 61 | [rxrpc_call_put_userid] = "Pus", |
cbd00891 | 62 | [rxrpc_call_put_kernel] = "Pke", |
fff72429 DH |
63 | [rxrpc_call_put_noqueue] = "PNQ", |
64 | }; | |
65 | ||
17926a79 DH |
66 | struct kmem_cache *rxrpc_call_jar; |
67 | LIST_HEAD(rxrpc_calls); | |
68 | DEFINE_RWLOCK(rxrpc_call_lock); | |
17926a79 | 69 | |
248f219c DH |
70 | static void rxrpc_call_timer_expired(unsigned long _call) |
71 | { | |
72 | struct rxrpc_call *call = (struct rxrpc_call *)_call; | |
73 | ||
74 | _enter("%d", call->debug_id); | |
75 | ||
76 | if (call->state < RXRPC_CALL_COMPLETE) | |
77 | rxrpc_queue_call(call); | |
78 | } | |
17926a79 | 79 | |
2341e077 DH |
80 | /* |
81 | * find an extant server call | |
82 | * - called in process context with IRQs enabled | |
83 | */ | |
84 | struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *rx, | |
85 | unsigned long user_call_ID) | |
86 | { | |
87 | struct rxrpc_call *call; | |
88 | struct rb_node *p; | |
89 | ||
90 | _enter("%p,%lx", rx, user_call_ID); | |
91 | ||
92 | read_lock(&rx->call_lock); | |
93 | ||
94 | p = rx->calls.rb_node; | |
95 | while (p) { | |
96 | call = rb_entry(p, struct rxrpc_call, sock_node); | |
97 | ||
98 | if (user_call_ID < call->user_call_ID) | |
99 | p = p->rb_left; | |
100 | else if (user_call_ID > call->user_call_ID) | |
101 | p = p->rb_right; | |
102 | else | |
103 | goto found_extant_call; | |
104 | } | |
105 | ||
106 | read_unlock(&rx->call_lock); | |
107 | _leave(" = NULL"); | |
108 | return NULL; | |
109 | ||
110 | found_extant_call: | |
fff72429 | 111 | rxrpc_get_call(call, rxrpc_call_got); |
2341e077 DH |
112 | read_unlock(&rx->call_lock); |
113 | _leave(" = %p [%d]", call, atomic_read(&call->usage)); | |
114 | return call; | |
115 | } | |
116 | ||
17926a79 DH |
117 | /* |
118 | * allocate a new call | |
119 | */ | |
00e90712 | 120 | struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp) |
17926a79 DH |
121 | { |
122 | struct rxrpc_call *call; | |
123 | ||
124 | call = kmem_cache_zalloc(rxrpc_call_jar, gfp); | |
125 | if (!call) | |
126 | return NULL; | |
127 | ||
248f219c DH |
128 | call->rxtx_buffer = kcalloc(RXRPC_RXTX_BUFF_SIZE, |
129 | sizeof(struct sk_buff *), | |
17926a79 | 130 | gfp); |
248f219c DH |
131 | if (!call->rxtx_buffer) |
132 | goto nomem; | |
17926a79 | 133 | |
248f219c DH |
134 | call->rxtx_annotations = kcalloc(RXRPC_RXTX_BUFF_SIZE, sizeof(u8), gfp); |
135 | if (!call->rxtx_annotations) | |
136 | goto nomem_2; | |
137 | ||
138 | setup_timer(&call->timer, rxrpc_call_timer_expired, | |
139 | (unsigned long)call); | |
17926a79 | 140 | INIT_WORK(&call->processor, &rxrpc_process_call); |
999b69f8 | 141 | INIT_LIST_HEAD(&call->link); |
45025bce | 142 | INIT_LIST_HEAD(&call->chan_wait_link); |
17926a79 | 143 | INIT_LIST_HEAD(&call->accept_link); |
248f219c DH |
144 | INIT_LIST_HEAD(&call->recvmsg_link); |
145 | INIT_LIST_HEAD(&call->sock_link); | |
45025bce | 146 | init_waitqueue_head(&call->waitq); |
17926a79 DH |
147 | spin_lock_init(&call->lock); |
148 | rwlock_init(&call->state_lock); | |
149 | atomic_set(&call->usage, 1); | |
150 | call->debug_id = atomic_inc_return(&rxrpc_debug_id); | |
17926a79 DH |
151 | |
152 | memset(&call->sock_node, 0xed, sizeof(call->sock_node)); | |
153 | ||
248f219c | 154 | /* Leave space in the ring to handle a maxed-out jumbo packet */ |
75e42126 | 155 | call->rx_winsize = rxrpc_rx_window_size; |
248f219c DH |
156 | call->tx_winsize = 16; |
157 | call->rx_expect_next = 1; | |
17926a79 | 158 | return call; |
248f219c DH |
159 | |
160 | nomem_2: | |
161 | kfree(call->rxtx_buffer); | |
162 | nomem: | |
163 | kmem_cache_free(rxrpc_call_jar, call); | |
164 | return NULL; | |
17926a79 DH |
165 | } |
166 | ||
167 | /* | |
999b69f8 | 168 | * Allocate a new client call. |
17926a79 | 169 | */ |
248f219c | 170 | static struct rxrpc_call *rxrpc_alloc_client_call(struct sockaddr_rxrpc *srx, |
aa390bbe | 171 | gfp_t gfp) |
17926a79 DH |
172 | { |
173 | struct rxrpc_call *call; | |
17926a79 DH |
174 | |
175 | _enter(""); | |
176 | ||
17926a79 DH |
177 | call = rxrpc_alloc_call(gfp); |
178 | if (!call) | |
179 | return ERR_PTR(-ENOMEM); | |
999b69f8 | 180 | call->state = RXRPC_CALL_CLIENT_AWAIT_CONN; |
999b69f8 | 181 | call->service_id = srx->srx_service; |
999b69f8 DH |
182 | |
183 | _leave(" = %p", call); | |
184 | return call; | |
185 | } | |
186 | ||
187 | /* | |
248f219c | 188 | * Initiate the call ack/resend/expiry timer. |
999b69f8 | 189 | */ |
248f219c | 190 | static void rxrpc_start_call_timer(struct rxrpc_call *call) |
999b69f8 | 191 | { |
248f219c DH |
192 | unsigned long expire_at; |
193 | ||
194 | expire_at = jiffies + rxrpc_max_call_lifetime; | |
195 | call->expire_at = expire_at; | |
196 | call->ack_at = expire_at; | |
197 | call->resend_at = expire_at; | |
198 | call->timer.expires = expire_at; | |
199 | add_timer(&call->timer); | |
17926a79 DH |
200 | } |
201 | ||
202 | /* | |
203 | * set up a call for the given data | |
204 | * - called in process context with IRQs enabled | |
205 | */ | |
2341e077 | 206 | struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *rx, |
19ffa01c | 207 | struct rxrpc_conn_parameters *cp, |
999b69f8 | 208 | struct sockaddr_rxrpc *srx, |
17926a79 | 209 | unsigned long user_call_ID, |
17926a79 DH |
210 | gfp_t gfp) |
211 | { | |
2341e077 DH |
212 | struct rxrpc_call *call, *xcall; |
213 | struct rb_node *parent, **pp; | |
e34d4234 | 214 | const void *here = __builtin_return_address(0); |
999b69f8 | 215 | int ret; |
17926a79 | 216 | |
999b69f8 | 217 | _enter("%p,%lx", rx, user_call_ID); |
17926a79 | 218 | |
248f219c | 219 | call = rxrpc_alloc_client_call(srx, gfp); |
2341e077 DH |
220 | if (IS_ERR(call)) { |
221 | _leave(" = %ld", PTR_ERR(call)); | |
222 | return call; | |
17926a79 DH |
223 | } |
224 | ||
2ab27215 DH |
225 | trace_rxrpc_call(call, 0, atomic_read(&call->usage), here, |
226 | (const void *)user_call_ID); | |
e34d4234 | 227 | |
999b69f8 | 228 | /* Publish the call, even though it is incompletely set up as yet */ |
2341e077 DH |
229 | call->user_call_ID = user_call_ID; |
230 | __set_bit(RXRPC_CALL_HAS_USERID, &call->flags); | |
17926a79 DH |
231 | |
232 | write_lock(&rx->call_lock); | |
233 | ||
234 | pp = &rx->calls.rb_node; | |
235 | parent = NULL; | |
236 | while (*pp) { | |
237 | parent = *pp; | |
2341e077 | 238 | xcall = rb_entry(parent, struct rxrpc_call, sock_node); |
17926a79 | 239 | |
2341e077 | 240 | if (user_call_ID < xcall->user_call_ID) |
17926a79 | 241 | pp = &(*pp)->rb_left; |
2341e077 | 242 | else if (user_call_ID > xcall->user_call_ID) |
17926a79 DH |
243 | pp = &(*pp)->rb_right; |
244 | else | |
2341e077 | 245 | goto found_user_ID_now_present; |
17926a79 DH |
246 | } |
247 | ||
248f219c | 248 | rcu_assign_pointer(call->socket, rx); |
fff72429 | 249 | rxrpc_get_call(call, rxrpc_call_got_userid); |
17926a79 DH |
250 | rb_link_node(&call->sock_node, parent, pp); |
251 | rb_insert_color(&call->sock_node, &rx->calls); | |
248f219c DH |
252 | list_add(&call->sock_link, &rx->sock_calls); |
253 | ||
17926a79 DH |
254 | write_unlock(&rx->call_lock); |
255 | ||
248f219c | 256 | write_lock(&rxrpc_call_lock); |
17926a79 | 257 | list_add_tail(&call->link, &rxrpc_calls); |
248f219c | 258 | write_unlock(&rxrpc_call_lock); |
17926a79 | 259 | |
248f219c DH |
260 | /* Set up or get a connection record and set the protocol parameters, |
261 | * including channel number and call ID. | |
262 | */ | |
263 | ret = rxrpc_connect_call(call, cp, srx, gfp); | |
999b69f8 DH |
264 | if (ret < 0) |
265 | goto error; | |
266 | ||
248f219c DH |
267 | spin_lock_bh(&call->conn->params.peer->lock); |
268 | hlist_add_head(&call->error_link, | |
269 | &call->conn->params.peer->error_targets); | |
270 | spin_unlock_bh(&call->conn->params.peer->lock); | |
271 | ||
272 | rxrpc_start_call_timer(call); | |
273 | ||
17926a79 DH |
274 | _net("CALL new %d on CONN %d", call->debug_id, call->conn->debug_id); |
275 | ||
276 | _leave(" = %p [new]", call); | |
277 | return call; | |
278 | ||
999b69f8 DH |
279 | error: |
280 | write_lock(&rx->call_lock); | |
281 | rb_erase(&call->sock_node, &rx->calls); | |
282 | write_unlock(&rx->call_lock); | |
fff72429 | 283 | rxrpc_put_call(call, rxrpc_call_put_userid); |
999b69f8 | 284 | |
248f219c | 285 | write_lock(&rxrpc_call_lock); |
d1e858c5 | 286 | list_del_init(&call->link); |
248f219c | 287 | write_unlock(&rxrpc_call_lock); |
999b69f8 | 288 | |
8d94aa38 DH |
289 | error_out: |
290 | __rxrpc_set_call_completion(call, RXRPC_CALL_LOCAL_ERROR, | |
291 | RX_CALL_DEAD, ret); | |
17b963e3 | 292 | set_bit(RXRPC_CALL_RELEASED, &call->flags); |
fff72429 | 293 | rxrpc_put_call(call, rxrpc_call_put); |
999b69f8 DH |
294 | _leave(" = %d", ret); |
295 | return ERR_PTR(ret); | |
296 | ||
2341e077 DH |
297 | /* We unexpectedly found the user ID in the list after taking |
298 | * the call_lock. This shouldn't happen unless the user races | |
299 | * with itself and tries to add the same user ID twice at the | |
300 | * same time in different threads. | |
301 | */ | |
302 | found_user_ID_now_present: | |
17926a79 | 303 | write_unlock(&rx->call_lock); |
8d94aa38 DH |
304 | ret = -EEXIST; |
305 | goto error_out; | |
17926a79 DH |
306 | } |
307 | ||
308 | /* | |
248f219c DH |
309 | * Set up an incoming call. call->conn points to the connection. |
310 | * This is called in BH context and isn't allowed to fail. | |
17926a79 | 311 | */ |
248f219c DH |
312 | void rxrpc_incoming_call(struct rxrpc_sock *rx, |
313 | struct rxrpc_call *call, | |
314 | struct sk_buff *skb) | |
17926a79 | 315 | { |
248f219c | 316 | struct rxrpc_connection *conn = call->conn; |
42886ffe | 317 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
248f219c | 318 | u32 chan; |
17926a79 | 319 | |
248f219c | 320 | _enter(",%d", call->conn->debug_id); |
e34d4234 | 321 | |
248f219c DH |
322 | rcu_assign_pointer(call->socket, rx); |
323 | call->call_id = sp->hdr.callNumber; | |
324 | call->service_id = sp->hdr.serviceId; | |
325 | call->cid = sp->hdr.cid; | |
326 | call->state = RXRPC_CALL_SERVER_ACCEPTING; | |
327 | if (sp->hdr.securityIndex > 0) | |
328 | call->state = RXRPC_CALL_SERVER_SECURING; | |
329 | ||
330 | /* Set the channel for this call. We don't get channel_lock as we're | |
331 | * only defending against the data_ready handler (which we're called | |
332 | * from) and the RESPONSE packet parser (which is only really | |
333 | * interested in call_counter and can cope with a disagreement with the | |
334 | * call pointer). | |
a1399f8b | 335 | */ |
248f219c DH |
336 | chan = sp->hdr.cid & RXRPC_CHANNELMASK; |
337 | conn->channels[chan].call_counter = call->call_id; | |
338 | conn->channels[chan].call_id = call->call_id; | |
a1399f8b | 339 | rcu_assign_pointer(conn->channels[chan].call, call); |
17926a79 | 340 | |
85f32278 DH |
341 | spin_lock(&conn->params.peer->lock); |
342 | hlist_add_head(&call->error_link, &conn->params.peer->error_targets); | |
343 | spin_unlock(&conn->params.peer->lock); | |
17926a79 | 344 | |
17926a79 DH |
345 | _net("CALL incoming %d on CONN %d", call->debug_id, call->conn->debug_id); |
346 | ||
248f219c DH |
347 | rxrpc_start_call_timer(call); |
348 | _leave(""); | |
17926a79 DH |
349 | } |
350 | ||
8d94aa38 DH |
351 | /* |
352 | * Queue a call's work processor, getting a ref to pass to the work queue. | |
353 | */ | |
354 | bool rxrpc_queue_call(struct rxrpc_call *call) | |
355 | { | |
356 | const void *here = __builtin_return_address(0); | |
357 | int n = __atomic_add_unless(&call->usage, 1, 0); | |
8d94aa38 DH |
358 | if (n == 0) |
359 | return false; | |
360 | if (rxrpc_queue_work(&call->processor)) | |
2ab27215 | 361 | trace_rxrpc_call(call, rxrpc_call_queued, n + 1, here, NULL); |
8d94aa38 DH |
362 | else |
363 | rxrpc_put_call(call, rxrpc_call_put_noqueue); | |
364 | return true; | |
365 | } | |
366 | ||
367 | /* | |
368 | * Queue a call's work processor, passing the callers ref to the work queue. | |
369 | */ | |
370 | bool __rxrpc_queue_call(struct rxrpc_call *call) | |
371 | { | |
372 | const void *here = __builtin_return_address(0); | |
373 | int n = atomic_read(&call->usage); | |
8d94aa38 DH |
374 | ASSERTCMP(n, >=, 1); |
375 | if (rxrpc_queue_work(&call->processor)) | |
2ab27215 | 376 | trace_rxrpc_call(call, rxrpc_call_queued_ref, n, here, NULL); |
8d94aa38 DH |
377 | else |
378 | rxrpc_put_call(call, rxrpc_call_put_noqueue); | |
379 | return true; | |
380 | } | |
381 | ||
e34d4234 DH |
382 | /* |
383 | * Note the re-emergence of a call. | |
384 | */ | |
385 | void rxrpc_see_call(struct rxrpc_call *call) | |
386 | { | |
387 | const void *here = __builtin_return_address(0); | |
388 | if (call) { | |
389 | int n = atomic_read(&call->usage); | |
e34d4234 | 390 | |
2ab27215 | 391 | trace_rxrpc_call(call, rxrpc_call_seen, n, here, NULL); |
e34d4234 DH |
392 | } |
393 | } | |
394 | ||
395 | /* | |
396 | * Note the addition of a ref on a call. | |
397 | */ | |
fff72429 | 398 | void rxrpc_get_call(struct rxrpc_call *call, enum rxrpc_call_trace op) |
e34d4234 DH |
399 | { |
400 | const void *here = __builtin_return_address(0); | |
401 | int n = atomic_inc_return(&call->usage); | |
e34d4234 | 402 | |
2ab27215 | 403 | trace_rxrpc_call(call, op, n, here, NULL); |
e34d4234 DH |
404 | } |
405 | ||
406 | /* | |
248f219c | 407 | * Detach a call from its owning socket. |
e34d4234 | 408 | */ |
248f219c | 409 | void rxrpc_release_call(struct rxrpc_sock *rx, struct rxrpc_call *call) |
e34d4234 | 410 | { |
248f219c DH |
411 | struct rxrpc_connection *conn = call->conn; |
412 | bool put = false; | |
413 | int i; | |
e34d4234 | 414 | |
248f219c | 415 | _enter("{%d,%d}", call->debug_id, atomic_read(&call->usage)); |
e34d4234 | 416 | |
248f219c | 417 | ASSERTCMP(call->state, ==, RXRPC_CALL_COMPLETE); |
17926a79 | 418 | |
e34d4234 DH |
419 | rxrpc_see_call(call); |
420 | ||
17926a79 DH |
421 | spin_lock_bh(&call->lock); |
422 | if (test_and_set_bit(RXRPC_CALL_RELEASED, &call->flags)) | |
423 | BUG(); | |
424 | spin_unlock_bh(&call->lock); | |
425 | ||
248f219c | 426 | del_timer_sync(&call->timer); |
17926a79 | 427 | |
248f219c DH |
428 | /* Make sure we don't get any more notifications */ |
429 | write_lock_bh(&rx->recvmsg_lock); | |
e653cfe4 | 430 | |
248f219c | 431 | if (!list_empty(&call->recvmsg_link)) { |
17926a79 DH |
432 | _debug("unlinking once-pending call %p { e=%lx f=%lx }", |
433 | call, call->events, call->flags); | |
248f219c DH |
434 | list_del(&call->recvmsg_link); |
435 | put = true; | |
436 | } | |
437 | ||
438 | /* list_empty() must return false in rxrpc_notify_socket() */ | |
439 | call->recvmsg_link.next = NULL; | |
440 | call->recvmsg_link.prev = NULL; | |
441 | ||
442 | write_unlock_bh(&rx->recvmsg_lock); | |
443 | if (put) | |
444 | rxrpc_put_call(call, rxrpc_call_put); | |
445 | ||
446 | write_lock(&rx->call_lock); | |
447 | ||
448 | if (test_and_clear_bit(RXRPC_CALL_HAS_USERID, &call->flags)) { | |
17926a79 DH |
449 | rb_erase(&call->sock_node, &rx->calls); |
450 | memset(&call->sock_node, 0xdd, sizeof(call->sock_node)); | |
8d94aa38 | 451 | rxrpc_put_call(call, rxrpc_call_put_userid); |
17926a79 | 452 | } |
17926a79 | 453 | |
248f219c DH |
454 | list_del(&call->sock_link); |
455 | write_unlock(&rx->call_lock); | |
456 | ||
457 | _debug("RELEASE CALL %p (%d CONN %p)", call, call->debug_id, conn); | |
458 | ||
459 | if (conn) | |
8d94aa38 | 460 | rxrpc_disconnect_call(call); |
e653cfe4 | 461 | |
248f219c DH |
462 | for (i = 0; i < RXRPC_RXTX_BUFF_SIZE; i++) { |
463 | rxrpc_free_skb(call->rxtx_buffer[i]); | |
464 | call->rxtx_buffer[i] = NULL; | |
17926a79 | 465 | } |
17926a79 DH |
466 | |
467 | _leave(""); | |
468 | } | |
469 | ||
17926a79 DH |
470 | /* |
471 | * release all the calls associated with a socket | |
472 | */ | |
473 | void rxrpc_release_calls_on_socket(struct rxrpc_sock *rx) | |
474 | { | |
475 | struct rxrpc_call *call; | |
17926a79 DH |
476 | |
477 | _enter("%p", rx); | |
478 | ||
0360da6d DH |
479 | while (!list_empty(&rx->to_be_accepted)) { |
480 | call = list_entry(rx->to_be_accepted.next, | |
481 | struct rxrpc_call, accept_link); | |
482 | list_del(&call->accept_link); | |
483 | rxrpc_abort_call("SKR", call, 0, RX_CALL_DEAD, ECONNRESET); | |
484 | rxrpc_send_call_packet(call, RXRPC_PACKET_TYPE_ABORT); | |
485 | rxrpc_release_call(rx, call); | |
486 | rxrpc_put_call(call, rxrpc_call_put); | |
487 | } | |
488 | ||
248f219c DH |
489 | while (!list_empty(&rx->sock_calls)) { |
490 | call = list_entry(rx->sock_calls.next, | |
491 | struct rxrpc_call, sock_link); | |
492 | rxrpc_get_call(call, rxrpc_call_got); | |
493 | rxrpc_abort_call("SKT", call, 0, RX_CALL_DEAD, ECONNRESET); | |
494 | rxrpc_send_call_packet(call, RXRPC_PACKET_TYPE_ABORT); | |
8d94aa38 | 495 | rxrpc_release_call(rx, call); |
248f219c | 496 | rxrpc_put_call(call, rxrpc_call_put); |
f36b5e44 DH |
497 | } |
498 | ||
17926a79 DH |
499 | _leave(""); |
500 | } | |
501 | ||
502 | /* | |
503 | * release a call | |
504 | */ | |
fff72429 | 505 | void rxrpc_put_call(struct rxrpc_call *call, enum rxrpc_call_trace op) |
17926a79 | 506 | { |
e34d4234 | 507 | const void *here = __builtin_return_address(0); |
2ab27215 | 508 | int n; |
17926a79 | 509 | |
e34d4234 | 510 | ASSERT(call != NULL); |
17926a79 | 511 | |
e34d4234 | 512 | n = atomic_dec_return(&call->usage); |
2ab27215 | 513 | trace_rxrpc_call(call, op, n, here, NULL); |
e34d4234 DH |
514 | ASSERTCMP(n, >=, 0); |
515 | if (n == 0) { | |
516 | _debug("call %d dead", call->debug_id); | |
248f219c | 517 | ASSERTCMP(call->state, ==, RXRPC_CALL_COMPLETE); |
17926a79 | 518 | |
248f219c DH |
519 | write_lock(&rxrpc_call_lock); |
520 | list_del_init(&call->link); | |
521 | write_unlock(&rxrpc_call_lock); | |
e34d4234 | 522 | |
8d94aa38 | 523 | rxrpc_cleanup_call(call); |
17926a79 | 524 | } |
17926a79 DH |
525 | } |
526 | ||
dee46364 DH |
527 | /* |
528 | * Final call destruction under RCU. | |
529 | */ | |
530 | static void rxrpc_rcu_destroy_call(struct rcu_head *rcu) | |
531 | { | |
532 | struct rxrpc_call *call = container_of(rcu, struct rxrpc_call, rcu); | |
533 | ||
df5d8bf7 | 534 | rxrpc_put_peer(call->peer); |
248f219c DH |
535 | kfree(call->rxtx_buffer); |
536 | kfree(call->rxtx_annotations); | |
dee46364 DH |
537 | kmem_cache_free(rxrpc_call_jar, call); |
538 | } | |
539 | ||
17926a79 DH |
540 | /* |
541 | * clean up a call | |
542 | */ | |
00e90712 | 543 | void rxrpc_cleanup_call(struct rxrpc_call *call) |
17926a79 | 544 | { |
248f219c | 545 | int i; |
17926a79 | 546 | |
248f219c | 547 | _net("DESTROY CALL %d", call->debug_id); |
17926a79 DH |
548 | |
549 | memset(&call->sock_node, 0xcd, sizeof(call->sock_node)); | |
550 | ||
248f219c | 551 | del_timer_sync(&call->timer); |
17926a79 | 552 | |
8d94aa38 | 553 | ASSERTCMP(call->state, ==, RXRPC_CALL_COMPLETE); |
17926a79 | 554 | ASSERT(test_bit(RXRPC_CALL_RELEASED, &call->flags)); |
e653cfe4 | 555 | ASSERTCMP(call->conn, ==, NULL); |
17926a79 | 556 | |
248f219c DH |
557 | /* Clean up the Rx/Tx buffer */ |
558 | for (i = 0; i < RXRPC_RXTX_BUFF_SIZE; i++) | |
559 | rxrpc_free_skb(call->rxtx_buffer[i]); | |
17926a79 DH |
560 | |
561 | rxrpc_free_skb(call->tx_pending); | |
562 | ||
dee46364 | 563 | call_rcu(&call->rcu, rxrpc_rcu_destroy_call); |
17926a79 DH |
564 | } |
565 | ||
566 | /* | |
8d94aa38 | 567 | * Make sure that all calls are gone. |
17926a79 DH |
568 | */ |
569 | void __exit rxrpc_destroy_all_calls(void) | |
570 | { | |
571 | struct rxrpc_call *call; | |
572 | ||
573 | _enter(""); | |
8d94aa38 DH |
574 | |
575 | if (list_empty(&rxrpc_calls)) | |
576 | return; | |
248f219c DH |
577 | |
578 | write_lock(&rxrpc_call_lock); | |
17926a79 DH |
579 | |
580 | while (!list_empty(&rxrpc_calls)) { | |
581 | call = list_entry(rxrpc_calls.next, struct rxrpc_call, link); | |
582 | _debug("Zapping call %p", call); | |
583 | ||
e34d4234 | 584 | rxrpc_see_call(call); |
17926a79 DH |
585 | list_del_init(&call->link); |
586 | ||
248f219c | 587 | pr_err("Call %p still in use (%d,%s,%lx,%lx)!\n", |
8d94aa38 | 588 | call, atomic_read(&call->usage), |
8d94aa38 DH |
589 | rxrpc_call_states[call->state], |
590 | call->flags, call->events); | |
17926a79 | 591 | |
248f219c | 592 | write_unlock(&rxrpc_call_lock); |
17926a79 | 593 | cond_resched(); |
248f219c | 594 | write_lock(&rxrpc_call_lock); |
17926a79 DH |
595 | } |
596 | ||
248f219c | 597 | write_unlock(&rxrpc_call_lock); |
17926a79 | 598 | } |