David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 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 | |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame] | 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 13 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | #include <linux/circ_buf.h> |
Tim Smith | 7727640 | 2014-03-03 23:04:45 +0000 | [diff] [blame] | 17 | #include <linux/spinlock_types.h> |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 18 | #include <net/sock.h> |
| 19 | #include <net/af_rxrpc.h> |
| 20 | #include "ar-internal.h" |
| 21 | |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 22 | /* |
| 23 | * Maximum lifetime of a call (in jiffies). |
| 24 | */ |
David Howells | dad8aff | 2016-03-09 23:22:56 +0000 | [diff] [blame] | 25 | unsigned int rxrpc_max_call_lifetime = 60 * HZ; |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 26 | |
| 27 | /* |
| 28 | * Time till dead call expires after last use (in jiffies). |
| 29 | */ |
David Howells | dad8aff | 2016-03-09 23:22:56 +0000 | [diff] [blame] | 30 | unsigned int rxrpc_dead_call_expiry = 2 * HZ; |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 31 | |
David Howells | 5b8848d | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 32 | const char *const rxrpc_call_states[NR__RXRPC_CALL_STATES] = { |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 33 | [RXRPC_CALL_UNINITIALISED] = "Uninit", |
| 34 | [RXRPC_CALL_CLIENT_AWAIT_CONN] = "ClWtConn", |
David Howells | 1f8481d | 2007-05-22 16:14:24 -0700 | [diff] [blame] | 35 | [RXRPC_CALL_CLIENT_SEND_REQUEST] = "ClSndReq", |
| 36 | [RXRPC_CALL_CLIENT_AWAIT_REPLY] = "ClAwtRpl", |
| 37 | [RXRPC_CALL_CLIENT_RECV_REPLY] = "ClRcvRpl", |
| 38 | [RXRPC_CALL_CLIENT_FINAL_ACK] = "ClFnlACK", |
| 39 | [RXRPC_CALL_SERVER_SECURING] = "SvSecure", |
| 40 | [RXRPC_CALL_SERVER_ACCEPTING] = "SvAccept", |
| 41 | [RXRPC_CALL_SERVER_RECV_REQUEST] = "SvRcvReq", |
| 42 | [RXRPC_CALL_SERVER_ACK_REQUEST] = "SvAckReq", |
| 43 | [RXRPC_CALL_SERVER_SEND_REPLY] = "SvSndRpl", |
| 44 | [RXRPC_CALL_SERVER_AWAIT_ACK] = "SvAwtACK", |
| 45 | [RXRPC_CALL_COMPLETE] = "Complete", |
| 46 | [RXRPC_CALL_SERVER_BUSY] = "SvBusy ", |
| 47 | [RXRPC_CALL_REMOTELY_ABORTED] = "RmtAbort", |
| 48 | [RXRPC_CALL_LOCALLY_ABORTED] = "LocAbort", |
| 49 | [RXRPC_CALL_NETWORK_ERROR] = "NetError", |
| 50 | [RXRPC_CALL_DEAD] = "Dead ", |
| 51 | }; |
| 52 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 53 | struct kmem_cache *rxrpc_call_jar; |
| 54 | LIST_HEAD(rxrpc_calls); |
| 55 | DEFINE_RWLOCK(rxrpc_call_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 56 | |
| 57 | static void rxrpc_destroy_call(struct work_struct *work); |
| 58 | static void rxrpc_call_life_expired(unsigned long _call); |
| 59 | static void rxrpc_dead_call_expired(unsigned long _call); |
| 60 | static void rxrpc_ack_time_expired(unsigned long _call); |
| 61 | static void rxrpc_resend_time_expired(unsigned long _call); |
| 62 | |
| 63 | /* |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 64 | * find an extant server call |
| 65 | * - called in process context with IRQs enabled |
| 66 | */ |
| 67 | struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *rx, |
| 68 | unsigned long user_call_ID) |
| 69 | { |
| 70 | struct rxrpc_call *call; |
| 71 | struct rb_node *p; |
| 72 | |
| 73 | _enter("%p,%lx", rx, user_call_ID); |
| 74 | |
| 75 | read_lock(&rx->call_lock); |
| 76 | |
| 77 | p = rx->calls.rb_node; |
| 78 | while (p) { |
| 79 | call = rb_entry(p, struct rxrpc_call, sock_node); |
| 80 | |
| 81 | if (user_call_ID < call->user_call_ID) |
| 82 | p = p->rb_left; |
| 83 | else if (user_call_ID > call->user_call_ID) |
| 84 | p = p->rb_right; |
| 85 | else |
| 86 | goto found_extant_call; |
| 87 | } |
| 88 | |
| 89 | read_unlock(&rx->call_lock); |
| 90 | _leave(" = NULL"); |
| 91 | return NULL; |
| 92 | |
| 93 | found_extant_call: |
| 94 | rxrpc_get_call(call); |
| 95 | read_unlock(&rx->call_lock); |
| 96 | _leave(" = %p [%d]", call, atomic_read(&call->usage)); |
| 97 | return call; |
| 98 | } |
| 99 | |
| 100 | /* |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 101 | * allocate a new call |
| 102 | */ |
| 103 | static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp) |
| 104 | { |
| 105 | struct rxrpc_call *call; |
| 106 | |
| 107 | call = kmem_cache_zalloc(rxrpc_call_jar, gfp); |
| 108 | if (!call) |
| 109 | return NULL; |
| 110 | |
| 111 | call->acks_winsz = 16; |
| 112 | call->acks_window = kmalloc(call->acks_winsz * sizeof(unsigned long), |
| 113 | gfp); |
| 114 | if (!call->acks_window) { |
| 115 | kmem_cache_free(rxrpc_call_jar, call); |
| 116 | return NULL; |
| 117 | } |
| 118 | |
| 119 | setup_timer(&call->lifetimer, &rxrpc_call_life_expired, |
| 120 | (unsigned long) call); |
| 121 | setup_timer(&call->deadspan, &rxrpc_dead_call_expired, |
| 122 | (unsigned long) call); |
| 123 | setup_timer(&call->ack_timer, &rxrpc_ack_time_expired, |
| 124 | (unsigned long) call); |
| 125 | setup_timer(&call->resend_timer, &rxrpc_resend_time_expired, |
| 126 | (unsigned long) call); |
| 127 | INIT_WORK(&call->destroyer, &rxrpc_destroy_call); |
| 128 | INIT_WORK(&call->processor, &rxrpc_process_call); |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 129 | INIT_LIST_HEAD(&call->link); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 130 | INIT_LIST_HEAD(&call->accept_link); |
| 131 | skb_queue_head_init(&call->rx_queue); |
| 132 | skb_queue_head_init(&call->rx_oos_queue); |
| 133 | init_waitqueue_head(&call->tx_waitq); |
| 134 | spin_lock_init(&call->lock); |
| 135 | rwlock_init(&call->state_lock); |
| 136 | atomic_set(&call->usage, 1); |
| 137 | call->debug_id = atomic_inc_return(&rxrpc_debug_id); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 138 | |
| 139 | memset(&call->sock_node, 0xed, sizeof(call->sock_node)); |
| 140 | |
| 141 | call->rx_data_expect = 1; |
| 142 | call->rx_data_eaten = 0; |
| 143 | call->rx_first_oos = 0; |
David Howells | 817913d | 2014-02-07 18:10:30 +0000 | [diff] [blame] | 144 | call->ackr_win_top = call->rx_data_eaten + 1 + rxrpc_rx_window_size; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 145 | call->creation_jif = jiffies; |
| 146 | return call; |
| 147 | } |
| 148 | |
| 149 | /* |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 150 | * Allocate a new client call. |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 151 | */ |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 152 | static struct rxrpc_call *rxrpc_alloc_client_call(struct rxrpc_sock *rx, |
| 153 | struct sockaddr_rxrpc *srx, |
| 154 | gfp_t gfp) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 155 | { |
| 156 | struct rxrpc_call *call; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 157 | |
| 158 | _enter(""); |
| 159 | |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 160 | ASSERT(rx->local != NULL); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 161 | |
| 162 | call = rxrpc_alloc_call(gfp); |
| 163 | if (!call) |
| 164 | return ERR_PTR(-ENOMEM); |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 165 | call->state = RXRPC_CALL_CLIENT_AWAIT_CONN; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 166 | |
| 167 | sock_hold(&rx->sk); |
| 168 | call->socket = rx; |
| 169 | call->rx_data_post = 1; |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 170 | call->service_id = srx->srx_service; |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 171 | |
| 172 | _leave(" = %p", call); |
| 173 | return call; |
| 174 | } |
| 175 | |
| 176 | /* |
| 177 | * Begin client call. |
| 178 | */ |
| 179 | static int rxrpc_begin_client_call(struct rxrpc_call *call, |
| 180 | struct rxrpc_conn_parameters *cp, |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 181 | struct sockaddr_rxrpc *srx, |
| 182 | gfp_t gfp) |
| 183 | { |
| 184 | int ret; |
| 185 | |
| 186 | /* Set up or get a connection record and set the protocol parameters, |
| 187 | * including channel number and call ID. |
| 188 | */ |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 189 | ret = rxrpc_connect_call(call, cp, srx, gfp); |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 190 | if (ret < 0) |
| 191 | return ret; |
| 192 | |
| 193 | call->state = RXRPC_CALL_CLIENT_SEND_REQUEST; |
| 194 | |
David Howells | 85f3227 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 195 | spin_lock(&call->conn->params.peer->lock); |
| 196 | hlist_add_head(&call->error_link, &call->conn->params.peer->error_targets); |
| 197 | spin_unlock(&call->conn->params.peer->lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 198 | |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 199 | call->lifetimer.expires = jiffies + rxrpc_max_call_lifetime; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 200 | add_timer(&call->lifetimer); |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 201 | return 0; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /* |
| 205 | * set up a call for the given data |
| 206 | * - called in process context with IRQs enabled |
| 207 | */ |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 208 | struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *rx, |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 209 | struct rxrpc_conn_parameters *cp, |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 210 | struct sockaddr_rxrpc *srx, |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 211 | unsigned long user_call_ID, |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 212 | gfp_t gfp) |
| 213 | { |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 214 | struct rxrpc_call *call, *xcall; |
| 215 | struct rb_node *parent, **pp; |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 216 | int ret; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 217 | |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 218 | _enter("%p,%lx", rx, user_call_ID); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 219 | |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 220 | call = rxrpc_alloc_client_call(rx, srx, gfp); |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 221 | if (IS_ERR(call)) { |
| 222 | _leave(" = %ld", PTR_ERR(call)); |
| 223 | return call; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 224 | } |
| 225 | |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 226 | /* Publish the call, even though it is incompletely set up as yet */ |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 227 | call->user_call_ID = user_call_ID; |
| 228 | __set_bit(RXRPC_CALL_HAS_USERID, &call->flags); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 229 | |
| 230 | write_lock(&rx->call_lock); |
| 231 | |
| 232 | pp = &rx->calls.rb_node; |
| 233 | parent = NULL; |
| 234 | while (*pp) { |
| 235 | parent = *pp; |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 236 | xcall = rb_entry(parent, struct rxrpc_call, sock_node); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 237 | |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 238 | if (user_call_ID < xcall->user_call_ID) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 239 | pp = &(*pp)->rb_left; |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 240 | else if (user_call_ID > xcall->user_call_ID) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 241 | pp = &(*pp)->rb_right; |
| 242 | else |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 243 | goto found_user_ID_now_present; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 244 | } |
| 245 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 246 | rxrpc_get_call(call); |
| 247 | |
| 248 | rb_link_node(&call->sock_node, parent, pp); |
| 249 | rb_insert_color(&call->sock_node, &rx->calls); |
| 250 | write_unlock(&rx->call_lock); |
| 251 | |
| 252 | write_lock_bh(&rxrpc_call_lock); |
| 253 | list_add_tail(&call->link, &rxrpc_calls); |
| 254 | write_unlock_bh(&rxrpc_call_lock); |
| 255 | |
David Howells | aa390bb | 2016-06-17 10:06:56 +0100 | [diff] [blame] | 256 | ret = rxrpc_begin_client_call(call, cp, srx, gfp); |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 257 | if (ret < 0) |
| 258 | goto error; |
| 259 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 260 | _net("CALL new %d on CONN %d", call->debug_id, call->conn->debug_id); |
| 261 | |
| 262 | _leave(" = %p [new]", call); |
| 263 | return call; |
| 264 | |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 265 | error: |
| 266 | write_lock(&rx->call_lock); |
| 267 | rb_erase(&call->sock_node, &rx->calls); |
| 268 | write_unlock(&rx->call_lock); |
| 269 | rxrpc_put_call(call); |
| 270 | |
| 271 | write_lock_bh(&rxrpc_call_lock); |
David Howells | d1e858c | 2016-04-04 14:00:39 +0100 | [diff] [blame] | 272 | list_del_init(&call->link); |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 273 | write_unlock_bh(&rxrpc_call_lock); |
| 274 | |
David Howells | 17b963e | 2016-08-08 13:06:41 +0100 | [diff] [blame] | 275 | set_bit(RXRPC_CALL_RELEASED, &call->flags); |
David Howells | d1e858c | 2016-04-04 14:00:39 +0100 | [diff] [blame] | 276 | call->state = RXRPC_CALL_DEAD; |
David Howells | 999b69f | 2016-06-17 15:42:35 +0100 | [diff] [blame] | 277 | rxrpc_put_call(call); |
| 278 | _leave(" = %d", ret); |
| 279 | return ERR_PTR(ret); |
| 280 | |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 281 | /* We unexpectedly found the user ID in the list after taking |
| 282 | * the call_lock. This shouldn't happen unless the user races |
| 283 | * with itself and tries to add the same user ID twice at the |
| 284 | * same time in different threads. |
| 285 | */ |
| 286 | found_user_ID_now_present: |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 287 | write_unlock(&rx->call_lock); |
David Howells | 17b963e | 2016-08-08 13:06:41 +0100 | [diff] [blame] | 288 | set_bit(RXRPC_CALL_RELEASED, &call->flags); |
David Howells | d1e858c | 2016-04-04 14:00:39 +0100 | [diff] [blame] | 289 | call->state = RXRPC_CALL_DEAD; |
David Howells | 2341e07 | 2016-06-09 23:02:51 +0100 | [diff] [blame] | 290 | rxrpc_put_call(call); |
| 291 | _leave(" = -EEXIST [%p]", call); |
| 292 | return ERR_PTR(-EEXIST); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /* |
| 296 | * set up an incoming call |
| 297 | * - called in process context with IRQs enabled |
| 298 | */ |
| 299 | struct rxrpc_call *rxrpc_incoming_call(struct rxrpc_sock *rx, |
| 300 | struct rxrpc_connection *conn, |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 301 | struct sk_buff *skb) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 302 | { |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 303 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 304 | struct rxrpc_call *call, *candidate; |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 305 | u32 call_id, chan; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 306 | |
David Howells | 843099c | 2016-04-07 17:23:37 +0100 | [diff] [blame] | 307 | _enter(",%d", conn->debug_id); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 308 | |
| 309 | ASSERT(rx != NULL); |
| 310 | |
David Howells | 843099c | 2016-04-07 17:23:37 +0100 | [diff] [blame] | 311 | candidate = rxrpc_alloc_call(GFP_NOIO); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 312 | if (!candidate) |
| 313 | return ERR_PTR(-EBUSY); |
| 314 | |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 315 | chan = sp->hdr.cid & RXRPC_CHANNELMASK; |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 316 | candidate->socket = rx; |
| 317 | candidate->conn = conn; |
| 318 | candidate->cid = sp->hdr.cid; |
| 319 | candidate->call_id = sp->hdr.callNumber; |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 320 | candidate->rx_data_post = 0; |
| 321 | candidate->state = RXRPC_CALL_SERVER_ACCEPTING; |
David Howells | dabe5a7 | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 322 | candidate->flags |= (1 << RXRPC_CALL_IS_SERVICE); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 323 | if (conn->security_ix > 0) |
| 324 | candidate->state = RXRPC_CALL_SERVER_SECURING; |
| 325 | |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 326 | spin_lock(&conn->channel_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 327 | |
| 328 | /* set the channel for this call */ |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 329 | call = rcu_dereference_protected(conn->channels[chan].call, |
| 330 | lockdep_is_held(&conn->channel_lock)); |
| 331 | |
David Howells | 01a90a4 | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 332 | _debug("channel[%u] is %p", candidate->cid & RXRPC_CHANNELMASK, call); |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 333 | if (call && call->call_id == sp->hdr.callNumber) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 334 | /* already set; must've been a duplicate packet */ |
| 335 | _debug("extant call [%d]", call->state); |
| 336 | ASSERTCMP(call->conn, ==, conn); |
| 337 | |
| 338 | read_lock(&call->state_lock); |
| 339 | switch (call->state) { |
| 340 | case RXRPC_CALL_LOCALLY_ABORTED: |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 341 | if (!test_and_set_bit(RXRPC_CALL_EV_ABORT, &call->events)) |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 342 | rxrpc_queue_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 343 | case RXRPC_CALL_REMOTELY_ABORTED: |
| 344 | read_unlock(&call->state_lock); |
| 345 | goto aborted_call; |
| 346 | default: |
| 347 | rxrpc_get_call(call); |
| 348 | read_unlock(&call->state_lock); |
| 349 | goto extant_call; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | if (call) { |
| 354 | /* it seems the channel is still in use from the previous call |
| 355 | * - ditch the old binding if its call is now complete */ |
| 356 | _debug("CALL: %u { %s }", |
| 357 | call->debug_id, rxrpc_call_states[call->state]); |
| 358 | |
| 359 | if (call->state >= RXRPC_CALL_COMPLETE) { |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 360 | __rxrpc_disconnect_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 361 | } else { |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 362 | spin_unlock(&conn->channel_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 363 | kmem_cache_free(rxrpc_call_jar, candidate); |
| 364 | _leave(" = -EBUSY"); |
| 365 | return ERR_PTR(-EBUSY); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | /* check the call number isn't duplicate */ |
| 370 | _debug("check dup"); |
David Howells | 42886ff | 2016-06-16 13:31:07 +0100 | [diff] [blame] | 371 | call_id = sp->hdr.callNumber; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 372 | |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 373 | /* We just ignore calls prior to the current call ID. Terminated calls |
| 374 | * are handled via the connection. |
| 375 | */ |
| 376 | if (call_id <= conn->channels[chan].call_counter) |
| 377 | goto old_call; /* TODO: Just drop packet */ |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 378 | |
| 379 | /* make the call available */ |
| 380 | _debug("new call"); |
| 381 | call = candidate; |
| 382 | candidate = NULL; |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 383 | conn->channels[chan].call_counter = call_id; |
| 384 | rcu_assign_pointer(conn->channels[chan].call, call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 385 | sock_hold(&rx->sk); |
David Howells | 5627cc8 | 2016-04-04 14:00:38 +0100 | [diff] [blame] | 386 | rxrpc_get_connection(conn); |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 387 | spin_unlock(&conn->channel_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 388 | |
David Howells | 85f3227 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 389 | spin_lock(&conn->params.peer->lock); |
| 390 | hlist_add_head(&call->error_link, &conn->params.peer->error_targets); |
| 391 | spin_unlock(&conn->params.peer->lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 392 | |
| 393 | write_lock_bh(&rxrpc_call_lock); |
| 394 | list_add_tail(&call->link, &rxrpc_calls); |
| 395 | write_unlock_bh(&rxrpc_call_lock); |
| 396 | |
David Howells | 19ffa01 | 2016-04-04 14:00:36 +0100 | [diff] [blame] | 397 | call->service_id = conn->params.service_id; |
Tim Smith | 7727640 | 2014-03-03 23:04:45 +0000 | [diff] [blame] | 398 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 399 | _net("CALL incoming %d on CONN %d", call->debug_id, call->conn->debug_id); |
| 400 | |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 401 | call->lifetimer.expires = jiffies + rxrpc_max_call_lifetime; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 402 | add_timer(&call->lifetimer); |
| 403 | _leave(" = %p {%d} [new]", call, call->debug_id); |
| 404 | return call; |
| 405 | |
| 406 | extant_call: |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 407 | spin_unlock(&conn->channel_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 408 | kmem_cache_free(rxrpc_call_jar, candidate); |
| 409 | _leave(" = %p {%d} [extant]", call, call ? call->debug_id : -1); |
| 410 | return call; |
| 411 | |
| 412 | aborted_call: |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 413 | spin_unlock(&conn->channel_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 414 | kmem_cache_free(rxrpc_call_jar, candidate); |
| 415 | _leave(" = -ECONNABORTED"); |
| 416 | return ERR_PTR(-ECONNABORTED); |
| 417 | |
| 418 | old_call: |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 419 | spin_unlock(&conn->channel_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 420 | kmem_cache_free(rxrpc_call_jar, candidate); |
| 421 | _leave(" = -ECONNRESET [old]"); |
| 422 | return ERR_PTR(-ECONNRESET); |
| 423 | } |
| 424 | |
| 425 | /* |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 426 | * detach a call from a socket and set up for release |
| 427 | */ |
| 428 | void rxrpc_release_call(struct rxrpc_call *call) |
| 429 | { |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 430 | struct rxrpc_connection *conn = call->conn; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 431 | struct rxrpc_sock *rx = call->socket; |
| 432 | |
| 433 | _enter("{%d,%d,%d,%d}", |
| 434 | call->debug_id, atomic_read(&call->usage), |
| 435 | atomic_read(&call->ackr_not_idle), |
| 436 | call->rx_first_oos); |
| 437 | |
| 438 | spin_lock_bh(&call->lock); |
| 439 | if (test_and_set_bit(RXRPC_CALL_RELEASED, &call->flags)) |
| 440 | BUG(); |
| 441 | spin_unlock_bh(&call->lock); |
| 442 | |
| 443 | /* dissociate from the socket |
| 444 | * - the socket's ref on the call is passed to the death timer |
| 445 | */ |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 446 | _debug("RELEASE CALL %p (%d CONN %p)", call, call->debug_id, conn); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 447 | |
David Howells | e653cfe | 2016-04-04 14:00:38 +0100 | [diff] [blame] | 448 | spin_lock(&conn->params.peer->lock); |
| 449 | hlist_del_init(&call->error_link); |
| 450 | spin_unlock(&conn->params.peer->lock); |
| 451 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 452 | write_lock_bh(&rx->call_lock); |
| 453 | if (!list_empty(&call->accept_link)) { |
| 454 | _debug("unlinking once-pending call %p { e=%lx f=%lx }", |
| 455 | call, call->events, call->flags); |
| 456 | ASSERT(!test_bit(RXRPC_CALL_HAS_USERID, &call->flags)); |
| 457 | list_del_init(&call->accept_link); |
| 458 | sk_acceptq_removed(&rx->sk); |
| 459 | } else if (test_bit(RXRPC_CALL_HAS_USERID, &call->flags)) { |
| 460 | rb_erase(&call->sock_node, &rx->calls); |
| 461 | memset(&call->sock_node, 0xdd, sizeof(call->sock_node)); |
| 462 | clear_bit(RXRPC_CALL_HAS_USERID, &call->flags); |
| 463 | } |
| 464 | write_unlock_bh(&rx->call_lock); |
| 465 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 466 | /* free up the channel for reuse */ |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 467 | write_lock_bh(&call->state_lock); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 468 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 469 | if (call->state < RXRPC_CALL_COMPLETE && |
| 470 | call->state != RXRPC_CALL_CLIENT_FINAL_ACK) { |
| 471 | _debug("+++ ABORTING STATE %d +++\n", call->state); |
| 472 | call->state = RXRPC_CALL_LOCALLY_ABORTED; |
David Howells | dc44b3a | 2016-04-07 17:23:30 +0100 | [diff] [blame] | 473 | call->local_abort = RX_CALL_DEAD; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 474 | } |
David Howells | a1399f8 | 2016-06-27 14:39:44 +0100 | [diff] [blame] | 475 | write_unlock_bh(&call->state_lock); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 476 | |
David Howells | e653cfe | 2016-04-04 14:00:38 +0100 | [diff] [blame] | 477 | rxrpc_disconnect_call(call); |
| 478 | |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 479 | /* clean up the Rx queue */ |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 480 | if (!skb_queue_empty(&call->rx_queue) || |
| 481 | !skb_queue_empty(&call->rx_oos_queue)) { |
| 482 | struct rxrpc_skb_priv *sp; |
| 483 | struct sk_buff *skb; |
| 484 | |
| 485 | _debug("purge Rx queues"); |
| 486 | |
| 487 | spin_lock_bh(&call->lock); |
| 488 | while ((skb = skb_dequeue(&call->rx_queue)) || |
| 489 | (skb = skb_dequeue(&call->rx_oos_queue))) { |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 490 | spin_unlock_bh(&call->lock); |
| 491 | |
Arnd Bergmann | 55cae7a | 2016-08-08 12:13:45 +0200 | [diff] [blame] | 492 | sp = rxrpc_skb(skb); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 493 | _debug("- zap %s %%%u #%u", |
| 494 | rxrpc_pkts[sp->hdr.type], |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 495 | sp->hdr.serial, sp->hdr.seq); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 496 | rxrpc_free_skb(skb); |
| 497 | spin_lock_bh(&call->lock); |
| 498 | } |
| 499 | spin_unlock_bh(&call->lock); |
| 500 | |
| 501 | ASSERTCMP(call->state, !=, RXRPC_CALL_COMPLETE); |
| 502 | } |
| 503 | |
| 504 | del_timer_sync(&call->resend_timer); |
| 505 | del_timer_sync(&call->ack_timer); |
| 506 | del_timer_sync(&call->lifetimer); |
David Howells | 5873c08 | 2014-02-07 18:58:44 +0000 | [diff] [blame] | 507 | call->deadspan.expires = jiffies + rxrpc_dead_call_expiry; |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 508 | add_timer(&call->deadspan); |
| 509 | |
| 510 | _leave(""); |
| 511 | } |
| 512 | |
| 513 | /* |
| 514 | * handle a dead call being ready for reaping |
| 515 | */ |
| 516 | static void rxrpc_dead_call_expired(unsigned long _call) |
| 517 | { |
| 518 | struct rxrpc_call *call = (struct rxrpc_call *) _call; |
| 519 | |
| 520 | _enter("{%d}", call->debug_id); |
| 521 | |
| 522 | write_lock_bh(&call->state_lock); |
| 523 | call->state = RXRPC_CALL_DEAD; |
| 524 | write_unlock_bh(&call->state_lock); |
| 525 | rxrpc_put_call(call); |
| 526 | } |
| 527 | |
| 528 | /* |
| 529 | * mark a call as to be released, aborting it if it's still in progress |
| 530 | * - called with softirqs disabled |
| 531 | */ |
| 532 | static void rxrpc_mark_call_released(struct rxrpc_call *call) |
| 533 | { |
| 534 | bool sched; |
| 535 | |
| 536 | write_lock(&call->state_lock); |
| 537 | if (call->state < RXRPC_CALL_DEAD) { |
| 538 | sched = false; |
| 539 | if (call->state < RXRPC_CALL_COMPLETE) { |
| 540 | _debug("abort call %p", call); |
| 541 | call->state = RXRPC_CALL_LOCALLY_ABORTED; |
David Howells | dc44b3a | 2016-04-07 17:23:30 +0100 | [diff] [blame] | 542 | call->local_abort = RX_CALL_DEAD; |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 543 | if (!test_and_set_bit(RXRPC_CALL_EV_ABORT, &call->events)) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 544 | sched = true; |
| 545 | } |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 546 | if (!test_and_set_bit(RXRPC_CALL_EV_RELEASE, &call->events)) |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 547 | sched = true; |
| 548 | if (sched) |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 549 | rxrpc_queue_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 550 | } |
| 551 | write_unlock(&call->state_lock); |
| 552 | } |
| 553 | |
| 554 | /* |
| 555 | * release all the calls associated with a socket |
| 556 | */ |
| 557 | void rxrpc_release_calls_on_socket(struct rxrpc_sock *rx) |
| 558 | { |
| 559 | struct rxrpc_call *call; |
| 560 | struct rb_node *p; |
| 561 | |
| 562 | _enter("%p", rx); |
| 563 | |
| 564 | read_lock_bh(&rx->call_lock); |
| 565 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 566 | /* kill the not-yet-accepted incoming calls */ |
| 567 | list_for_each_entry(call, &rx->secureq, accept_link) { |
| 568 | rxrpc_mark_call_released(call); |
| 569 | } |
| 570 | |
| 571 | list_for_each_entry(call, &rx->acceptq, accept_link) { |
| 572 | rxrpc_mark_call_released(call); |
| 573 | } |
| 574 | |
David Howells | f36b5e4 | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 575 | /* mark all the calls as no longer wanting incoming packets */ |
| 576 | for (p = rb_first(&rx->calls); p; p = rb_next(p)) { |
| 577 | call = rb_entry(p, struct rxrpc_call, sock_node); |
| 578 | rxrpc_mark_call_released(call); |
| 579 | } |
| 580 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 581 | read_unlock_bh(&rx->call_lock); |
| 582 | _leave(""); |
| 583 | } |
| 584 | |
| 585 | /* |
| 586 | * release a call |
| 587 | */ |
| 588 | void __rxrpc_put_call(struct rxrpc_call *call) |
| 589 | { |
| 590 | ASSERT(call != NULL); |
| 591 | |
| 592 | _enter("%p{u=%d}", call, atomic_read(&call->usage)); |
| 593 | |
| 594 | ASSERTCMP(atomic_read(&call->usage), >, 0); |
| 595 | |
| 596 | if (atomic_dec_and_test(&call->usage)) { |
| 597 | _debug("call %d dead", call->debug_id); |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 598 | WARN_ON(atomic_read(&call->skb_count) != 0); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 599 | ASSERTCMP(call->state, ==, RXRPC_CALL_DEAD); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 600 | rxrpc_queue_work(&call->destroyer); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 601 | } |
| 602 | _leave(""); |
| 603 | } |
| 604 | |
| 605 | /* |
David Howells | dee4636 | 2016-06-27 17:11:19 +0100 | [diff] [blame] | 606 | * Final call destruction under RCU. |
| 607 | */ |
| 608 | static void rxrpc_rcu_destroy_call(struct rcu_head *rcu) |
| 609 | { |
| 610 | struct rxrpc_call *call = container_of(rcu, struct rxrpc_call, rcu); |
| 611 | |
| 612 | rxrpc_purge_queue(&call->rx_queue); |
| 613 | kmem_cache_free(rxrpc_call_jar, call); |
| 614 | } |
| 615 | |
| 616 | /* |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 617 | * clean up a call |
| 618 | */ |
| 619 | static void rxrpc_cleanup_call(struct rxrpc_call *call) |
| 620 | { |
| 621 | _net("DESTROY CALL %d", call->debug_id); |
| 622 | |
| 623 | ASSERT(call->socket); |
| 624 | |
| 625 | memset(&call->sock_node, 0xcd, sizeof(call->sock_node)); |
| 626 | |
| 627 | del_timer_sync(&call->lifetimer); |
| 628 | del_timer_sync(&call->deadspan); |
| 629 | del_timer_sync(&call->ack_timer); |
| 630 | del_timer_sync(&call->resend_timer); |
| 631 | |
| 632 | ASSERT(test_bit(RXRPC_CALL_RELEASED, &call->flags)); |
| 633 | ASSERTCMP(call->events, ==, 0); |
| 634 | if (work_pending(&call->processor)) { |
| 635 | _debug("defer destroy"); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 636 | rxrpc_queue_work(&call->destroyer); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 637 | return; |
| 638 | } |
| 639 | |
David Howells | e653cfe | 2016-04-04 14:00:38 +0100 | [diff] [blame] | 640 | ASSERTCMP(call->conn, ==, NULL); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 641 | |
| 642 | if (call->acks_window) { |
| 643 | _debug("kill Tx window %d", |
| 644 | CIRC_CNT(call->acks_head, call->acks_tail, |
| 645 | call->acks_winsz)); |
| 646 | smp_mb(); |
| 647 | while (CIRC_CNT(call->acks_head, call->acks_tail, |
| 648 | call->acks_winsz) > 0) { |
| 649 | struct rxrpc_skb_priv *sp; |
| 650 | unsigned long _skb; |
| 651 | |
| 652 | _skb = call->acks_window[call->acks_tail] & ~1; |
David Howells | 0d12f8a | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 653 | sp = rxrpc_skb((struct sk_buff *)_skb); |
| 654 | _debug("+++ clear Tx %u", sp->hdr.seq); |
| 655 | rxrpc_free_skb((struct sk_buff *)_skb); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 656 | call->acks_tail = |
| 657 | (call->acks_tail + 1) & (call->acks_winsz - 1); |
| 658 | } |
| 659 | |
| 660 | kfree(call->acks_window); |
| 661 | } |
| 662 | |
| 663 | rxrpc_free_skb(call->tx_pending); |
| 664 | |
| 665 | rxrpc_purge_queue(&call->rx_queue); |
| 666 | ASSERT(skb_queue_empty(&call->rx_oos_queue)); |
| 667 | sock_put(&call->socket->sk); |
David Howells | dee4636 | 2016-06-27 17:11:19 +0100 | [diff] [blame] | 668 | call_rcu(&call->rcu, rxrpc_rcu_destroy_call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | /* |
| 672 | * destroy a call |
| 673 | */ |
| 674 | static void rxrpc_destroy_call(struct work_struct *work) |
| 675 | { |
| 676 | struct rxrpc_call *call = |
| 677 | container_of(work, struct rxrpc_call, destroyer); |
| 678 | |
David Howells | 01a90a4 | 2016-08-23 15:27:24 +0100 | [diff] [blame] | 679 | _enter("%p{%d,%x,%p}", |
| 680 | call, atomic_read(&call->usage), call->cid, call->conn); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 681 | |
| 682 | ASSERTCMP(call->state, ==, RXRPC_CALL_DEAD); |
| 683 | |
| 684 | write_lock_bh(&rxrpc_call_lock); |
| 685 | list_del_init(&call->link); |
| 686 | write_unlock_bh(&rxrpc_call_lock); |
| 687 | |
| 688 | rxrpc_cleanup_call(call); |
| 689 | _leave(""); |
| 690 | } |
| 691 | |
| 692 | /* |
| 693 | * preemptively destroy all the call records from a transport endpoint rather |
| 694 | * than waiting for them to time out |
| 695 | */ |
| 696 | void __exit rxrpc_destroy_all_calls(void) |
| 697 | { |
| 698 | struct rxrpc_call *call; |
| 699 | |
| 700 | _enter(""); |
| 701 | write_lock_bh(&rxrpc_call_lock); |
| 702 | |
| 703 | while (!list_empty(&rxrpc_calls)) { |
| 704 | call = list_entry(rxrpc_calls.next, struct rxrpc_call, link); |
| 705 | _debug("Zapping call %p", call); |
| 706 | |
| 707 | list_del_init(&call->link); |
| 708 | |
| 709 | switch (atomic_read(&call->usage)) { |
| 710 | case 0: |
| 711 | ASSERTCMP(call->state, ==, RXRPC_CALL_DEAD); |
| 712 | break; |
| 713 | case 1: |
| 714 | if (del_timer_sync(&call->deadspan) != 0 && |
| 715 | call->state != RXRPC_CALL_DEAD) |
| 716 | rxrpc_dead_call_expired((unsigned long) call); |
| 717 | if (call->state != RXRPC_CALL_DEAD) |
| 718 | break; |
| 719 | default: |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame] | 720 | pr_err("Call %p still in use (%d,%d,%s,%lx,%lx)!\n", |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 721 | call, atomic_read(&call->usage), |
| 722 | atomic_read(&call->ackr_not_idle), |
| 723 | rxrpc_call_states[call->state], |
| 724 | call->flags, call->events); |
| 725 | if (!skb_queue_empty(&call->rx_queue)) |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame] | 726 | pr_err("Rx queue occupied\n"); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 727 | if (!skb_queue_empty(&call->rx_oos_queue)) |
Joe Perches | 9b6d539 | 2016-06-02 12:08:52 -0700 | [diff] [blame] | 728 | pr_err("OOS queue occupied\n"); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 729 | break; |
| 730 | } |
| 731 | |
| 732 | write_unlock_bh(&rxrpc_call_lock); |
| 733 | cond_resched(); |
| 734 | write_lock_bh(&rxrpc_call_lock); |
| 735 | } |
| 736 | |
| 737 | write_unlock_bh(&rxrpc_call_lock); |
| 738 | _leave(""); |
| 739 | } |
| 740 | |
| 741 | /* |
| 742 | * handle call lifetime being exceeded |
| 743 | */ |
| 744 | static void rxrpc_call_life_expired(unsigned long _call) |
| 745 | { |
| 746 | struct rxrpc_call *call = (struct rxrpc_call *) _call; |
| 747 | |
| 748 | if (call->state >= RXRPC_CALL_COMPLETE) |
| 749 | return; |
| 750 | |
| 751 | _enter("{%d}", call->debug_id); |
| 752 | read_lock_bh(&call->state_lock); |
| 753 | if (call->state < RXRPC_CALL_COMPLETE) { |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 754 | set_bit(RXRPC_CALL_EV_LIFE_TIMER, &call->events); |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 755 | rxrpc_queue_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 756 | } |
| 757 | read_unlock_bh(&call->state_lock); |
| 758 | } |
| 759 | |
| 760 | /* |
| 761 | * handle resend timer expiry |
David Howells | 3b5bac2 | 2010-08-04 02:34:17 +0000 | [diff] [blame] | 762 | * - may not take call->state_lock as this can deadlock against del_timer_sync() |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 763 | */ |
| 764 | static void rxrpc_resend_time_expired(unsigned long _call) |
| 765 | { |
| 766 | struct rxrpc_call *call = (struct rxrpc_call *) _call; |
| 767 | |
| 768 | _enter("{%d}", call->debug_id); |
| 769 | |
| 770 | if (call->state >= RXRPC_CALL_COMPLETE) |
| 771 | return; |
| 772 | |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 773 | clear_bit(RXRPC_CALL_RUN_RTIMER, &call->flags); |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 774 | if (!test_and_set_bit(RXRPC_CALL_EV_RESEND_TIMER, &call->events)) |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 775 | rxrpc_queue_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | /* |
| 779 | * handle ACK timer expiry |
| 780 | */ |
| 781 | static void rxrpc_ack_time_expired(unsigned long _call) |
| 782 | { |
| 783 | struct rxrpc_call *call = (struct rxrpc_call *) _call; |
| 784 | |
| 785 | _enter("{%d}", call->debug_id); |
| 786 | |
| 787 | if (call->state >= RXRPC_CALL_COMPLETE) |
| 788 | return; |
| 789 | |
| 790 | read_lock_bh(&call->state_lock); |
| 791 | if (call->state < RXRPC_CALL_COMPLETE && |
David Howells | 4c198ad | 2016-03-04 15:53:46 +0000 | [diff] [blame] | 792 | !test_and_set_bit(RXRPC_CALL_EV_ACK, &call->events)) |
David Howells | 651350d | 2007-04-26 15:50:17 -0700 | [diff] [blame] | 793 | rxrpc_queue_call(call); |
David Howells | 17926a7 | 2007-04-26 15:48:28 -0700 | [diff] [blame] | 794 | read_unlock_bh(&call->state_lock); |
| 795 | } |