Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 2 | /* Maintain an RxRPC server socket to do AFS communications through |
| 3 | * |
| 4 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. |
| 5 | * Written by David Howells (dhowells@redhat.com) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 8 | #include <linux/slab.h> |
Ingo Molnar | 174cd4b | 2017-02-02 19:15:33 +0100 | [diff] [blame] | 9 | #include <linux/sched/signal.h> |
| 10 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 11 | #include <net/sock.h> |
| 12 | #include <net/af_rxrpc.h> |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 13 | #include "internal.h" |
| 14 | #include "afs_cm.h" |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 15 | #include "protocol_yfs.h" |
David Howells | 57af281 | 2022-10-06 21:45:42 +0100 | [diff] [blame] | 16 | #define RXRPC_TRACE_ONLY_DEFINE_ENUMS |
| 17 | #include <trace/events/rxrpc.h> |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 18 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 19 | struct workqueue_struct *afs_async_calls; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 20 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 21 | static void afs_wake_up_call_waiter(struct sock *, struct rxrpc_call *, unsigned long); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 22 | static void afs_wake_up_async_call(struct sock *, struct rxrpc_call *, unsigned long); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 23 | static void afs_process_async_call(struct work_struct *); |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 24 | static void afs_rx_new_call(struct sock *, struct rxrpc_call *, unsigned long); |
| 25 | static void afs_rx_discard_new_call(struct rxrpc_call *, unsigned long); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 26 | static int afs_deliver_cm_op_id(struct afs_call *); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 27 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 28 | /* asynchronous incoming call initial processing */ |
| 29 | static const struct afs_call_type afs_RXCMxxxx = { |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 30 | .name = "CB.xxxx", |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 31 | .deliver = afs_deliver_cm_op_id, |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 32 | }; |
| 33 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 34 | /* |
| 35 | * open an RxRPC socket and bind it to be a server for callback notifications |
| 36 | * - the socket is left in blocking mode and non-blocking ops use MSG_DONTWAIT |
| 37 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 38 | int afs_open_socket(struct afs_net *net) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 39 | { |
| 40 | struct sockaddr_rxrpc srx; |
| 41 | struct socket *socket; |
| 42 | int ret; |
| 43 | |
| 44 | _enter(""); |
| 45 | |
David Howells | 5b86d4f | 2018-05-18 11:46:15 +0100 | [diff] [blame] | 46 | ret = sock_create_kern(net->net, AF_RXRPC, SOCK_DGRAM, PF_INET6, &socket); |
David Howells | 0e119b4 | 2016-06-10 22:30:37 +0100 | [diff] [blame] | 47 | if (ret < 0) |
| 48 | goto error_1; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 49 | |
| 50 | socket->sk->sk_allocation = GFP_NOFS; |
| 51 | |
| 52 | /* bind the callback manager's address to make this a server socket */ |
David Howells | 3838d3e | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 53 | memset(&srx, 0, sizeof(srx)); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 54 | srx.srx_family = AF_RXRPC; |
| 55 | srx.srx_service = CM_SERVICE; |
| 56 | srx.transport_type = SOCK_DGRAM; |
David Howells | 3838d3e | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 57 | srx.transport_len = sizeof(srx.transport.sin6); |
| 58 | srx.transport.sin6.sin6_family = AF_INET6; |
| 59 | srx.transport.sin6.sin6_port = htons(AFS_CM_PORT); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 60 | |
Christoph Hellwig | 298cd88 | 2020-05-28 07:12:35 +0200 | [diff] [blame] | 61 | ret = rxrpc_sock_set_min_security_level(socket->sk, |
| 62 | RXRPC_SECURITY_ENCRYPT); |
David Howells | 4776cab | 2018-05-10 23:10:40 +0100 | [diff] [blame] | 63 | if (ret < 0) |
| 64 | goto error_2; |
| 65 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 66 | ret = kernel_bind(socket, (struct sockaddr *) &srx, sizeof(srx)); |
Marc Dionne | 83732ec | 2017-11-02 15:27:52 +0000 | [diff] [blame] | 67 | if (ret == -EADDRINUSE) { |
| 68 | srx.transport.sin6.sin6_port = 0; |
| 69 | ret = kernel_bind(socket, (struct sockaddr *) &srx, sizeof(srx)); |
| 70 | } |
David Howells | 0e119b4 | 2016-06-10 22:30:37 +0100 | [diff] [blame] | 71 | if (ret < 0) |
| 72 | goto error_2; |
| 73 | |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 74 | srx.srx_service = YFS_CM_SERVICE; |
| 75 | ret = kernel_bind(socket, (struct sockaddr *) &srx, sizeof(srx)); |
| 76 | if (ret < 0) |
| 77 | goto error_2; |
| 78 | |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 79 | /* Ideally, we'd turn on service upgrade here, but we can't because |
| 80 | * OpenAFS is buggy and leaks the userStatus field from packet to |
| 81 | * packet and between FS packets and CB packets - so if we try to do an |
| 82 | * upgrade on an FS packet, OpenAFS will leak that into the CB packet |
| 83 | * it sends back to us. |
| 84 | */ |
David Howells | 35dbfba | 2018-10-20 00:57:58 +0100 | [diff] [blame] | 85 | |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 86 | rxrpc_kernel_new_call_notification(socket, afs_rx_new_call, |
| 87 | afs_rx_discard_new_call); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 88 | |
David Howells | 0e119b4 | 2016-06-10 22:30:37 +0100 | [diff] [blame] | 89 | ret = kernel_listen(socket, INT_MAX); |
| 90 | if (ret < 0) |
| 91 | goto error_2; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 92 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 93 | net->socket = socket; |
| 94 | afs_charge_preallocation(&net->charge_preallocation_work); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 95 | _leave(" = 0"); |
| 96 | return 0; |
David Howells | 0e119b4 | 2016-06-10 22:30:37 +0100 | [diff] [blame] | 97 | |
| 98 | error_2: |
| 99 | sock_release(socket); |
| 100 | error_1: |
David Howells | 0e119b4 | 2016-06-10 22:30:37 +0100 | [diff] [blame] | 101 | _leave(" = %d", ret); |
| 102 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /* |
| 106 | * close the RxRPC socket AFS was using |
| 107 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 108 | void afs_close_socket(struct afs_net *net) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 109 | { |
| 110 | _enter(""); |
| 111 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 112 | kernel_listen(net->socket, 0); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 113 | flush_workqueue(afs_async_calls); |
| 114 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 115 | if (net->spare_incoming_call) { |
| 116 | afs_put_call(net->spare_incoming_call); |
| 117 | net->spare_incoming_call = NULL; |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 118 | } |
| 119 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 120 | _debug("outstanding %u", atomic_read(&net->nr_outstanding_calls)); |
Peter Zijlstra | ab1fbe3 | 2018-03-15 11:42:28 +0100 | [diff] [blame] | 121 | wait_var_event(&net->nr_outstanding_calls, |
| 122 | !atomic_read(&net->nr_outstanding_calls)); |
David Howells | 2f02f7a | 2016-04-07 17:23:03 +0100 | [diff] [blame] | 123 | _debug("no outstanding calls"); |
| 124 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 125 | kernel_sock_shutdown(net->socket, SHUT_RDWR); |
David Howells | 248f219 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 126 | flush_workqueue(afs_async_calls); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 127 | sock_release(net->socket); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 128 | |
| 129 | _debug("dework"); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 130 | _leave(""); |
| 131 | } |
| 132 | |
| 133 | /* |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 134 | * Allocate a call. |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 135 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 136 | static struct afs_call *afs_alloc_call(struct afs_net *net, |
| 137 | const struct afs_call_type *type, |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 138 | gfp_t gfp) |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 139 | { |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 140 | struct afs_call *call; |
| 141 | int o; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 142 | |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 143 | call = kzalloc(sizeof(*call), gfp); |
| 144 | if (!call) |
| 145 | return NULL; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 146 | |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 147 | call->type = type; |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 148 | call->net = net; |
David Howells | a25e21f | 2018-03-27 23:03:00 +0100 | [diff] [blame] | 149 | call->debug_id = atomic_inc_return(&rxrpc_debug_id); |
David Howells | c56f9ec8 | 2022-07-06 10:52:14 +0100 | [diff] [blame] | 150 | refcount_set(&call->ref, 1); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 151 | INIT_WORK(&call->async_work, afs_process_async_call); |
| 152 | init_waitqueue_head(&call->waitq); |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 153 | spin_lock_init(&call->state_lock); |
David Howells | fc27612 | 2019-11-21 09:12:17 +0000 | [diff] [blame] | 154 | call->iter = &call->def_iter; |
David Howells | 2f02f7a | 2016-04-07 17:23:03 +0100 | [diff] [blame] | 155 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 156 | o = atomic_inc_return(&net->nr_outstanding_calls); |
David Howells | 2757a4d | 2022-07-06 11:26:14 +0100 | [diff] [blame] | 157 | trace_afs_call(call->debug_id, afs_call_trace_alloc, 1, o, |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 158 | __builtin_return_address(0)); |
| 159 | return call; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | /* |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 163 | * Dispose of a reference on a call. |
David Howells | 6c67c7c | 2014-05-21 14:48:05 +0100 | [diff] [blame] | 164 | */ |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 165 | void afs_put_call(struct afs_call *call) |
David Howells | 6c67c7c | 2014-05-21 14:48:05 +0100 | [diff] [blame] | 166 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 167 | struct afs_net *net = call->net; |
David Howells | 2757a4d | 2022-07-06 11:26:14 +0100 | [diff] [blame] | 168 | unsigned int debug_id = call->debug_id; |
David Howells | c56f9ec8 | 2022-07-06 10:52:14 +0100 | [diff] [blame] | 169 | bool zero; |
| 170 | int r, o; |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 171 | |
David Howells | c56f9ec8 | 2022-07-06 10:52:14 +0100 | [diff] [blame] | 172 | zero = __refcount_dec_and_test(&call->ref, &r); |
| 173 | o = atomic_read(&net->nr_outstanding_calls); |
David Howells | 2757a4d | 2022-07-06 11:26:14 +0100 | [diff] [blame] | 174 | trace_afs_call(debug_id, afs_call_trace_put, r - 1, o, |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 175 | __builtin_return_address(0)); |
| 176 | |
David Howells | c56f9ec8 | 2022-07-06 10:52:14 +0100 | [diff] [blame] | 177 | if (zero) { |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 178 | ASSERT(!work_pending(&call->async_work)); |
| 179 | ASSERT(call->type->name != NULL); |
| 180 | |
| 181 | if (call->rxcall) { |
David Howells | e0416e7 | 2023-04-21 23:03:46 +0100 | [diff] [blame] | 182 | rxrpc_kernel_shutdown_call(net->socket, call->rxcall); |
| 183 | rxrpc_kernel_put_call(net->socket, call->rxcall); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 184 | call->rxcall = NULL; |
| 185 | } |
| 186 | if (call->type->destructor) |
| 187 | call->type->destructor(call); |
| 188 | |
David Howells | 977e5f8 | 2020-04-17 17:31:26 +0100 | [diff] [blame] | 189 | afs_unuse_server_notime(call->net, call->server, afs_server_trace_put_call); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 190 | afs_put_addrlist(call->alist); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 191 | kfree(call->request); |
David Howells | a25e21f | 2018-03-27 23:03:00 +0100 | [diff] [blame] | 192 | |
David Howells | 2757a4d | 2022-07-06 11:26:14 +0100 | [diff] [blame] | 193 | trace_afs_call(call->debug_id, afs_call_trace_free, 0, o, |
David Howells | a25e21f | 2018-03-27 23:03:00 +0100 | [diff] [blame] | 194 | __builtin_return_address(0)); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 195 | kfree(call); |
| 196 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 197 | o = atomic_dec_return(&net->nr_outstanding_calls); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 198 | if (o == 0) |
Peter Zijlstra | ab1fbe3 | 2018-03-15 11:42:28 +0100 | [diff] [blame] | 199 | wake_up_var(&net->nr_outstanding_calls); |
David Howells | 6c67c7c | 2014-05-21 14:48:05 +0100 | [diff] [blame] | 200 | } |
Nathaniel Wesley Filardo | 6cf1286 | 2014-05-21 16:04:11 +0100 | [diff] [blame] | 201 | } |
| 202 | |
David Howells | 7a75b00 | 2019-01-10 15:14:29 +0000 | [diff] [blame] | 203 | static struct afs_call *afs_get_call(struct afs_call *call, |
| 204 | enum afs_call_trace why) |
| 205 | { |
David Howells | c56f9ec8 | 2022-07-06 10:52:14 +0100 | [diff] [blame] | 206 | int r; |
David Howells | 7a75b00 | 2019-01-10 15:14:29 +0000 | [diff] [blame] | 207 | |
David Howells | c56f9ec8 | 2022-07-06 10:52:14 +0100 | [diff] [blame] | 208 | __refcount_inc(&call->ref, &r); |
| 209 | |
David Howells | 2757a4d | 2022-07-06 11:26:14 +0100 | [diff] [blame] | 210 | trace_afs_call(call->debug_id, why, r + 1, |
David Howells | 7a75b00 | 2019-01-10 15:14:29 +0000 | [diff] [blame] | 211 | atomic_read(&call->net->nr_outstanding_calls), |
| 212 | __builtin_return_address(0)); |
| 213 | return call; |
| 214 | } |
| 215 | |
Nathaniel Wesley Filardo | 6cf1286 | 2014-05-21 16:04:11 +0100 | [diff] [blame] | 216 | /* |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 217 | * Queue the call for actual work. |
Nathaniel Wesley Filardo | 6cf1286 | 2014-05-21 16:04:11 +0100 | [diff] [blame] | 218 | */ |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 219 | static void afs_queue_call_work(struct afs_call *call) |
Nathaniel Wesley Filardo | 6cf1286 | 2014-05-21 16:04:11 +0100 | [diff] [blame] | 220 | { |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 221 | if (call->type->work) { |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 222 | INIT_WORK(&call->work, call->type->work); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 223 | |
David Howells | 7a75b00 | 2019-01-10 15:14:29 +0000 | [diff] [blame] | 224 | afs_get_call(call, afs_call_trace_work); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 225 | if (!queue_work(afs_wq, &call->work)) |
| 226 | afs_put_call(call); |
| 227 | } |
David Howells | 6c67c7c | 2014-05-21 14:48:05 +0100 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 231 | * allocate a call with flat request and reply buffers |
| 232 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 233 | struct afs_call *afs_alloc_flat_call(struct afs_net *net, |
| 234 | const struct afs_call_type *type, |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 235 | size_t request_size, size_t reply_max) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 236 | { |
| 237 | struct afs_call *call; |
| 238 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 239 | call = afs_alloc_call(net, type, GFP_NOFS); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 240 | if (!call) |
| 241 | goto nomem_call; |
| 242 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 243 | if (request_size) { |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 244 | call->request_size = request_size; |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 245 | call->request = kmalloc(request_size, GFP_NOFS); |
| 246 | if (!call->request) |
| 247 | goto nomem_free; |
| 248 | } |
| 249 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 250 | if (reply_max) { |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 251 | call->reply_max = reply_max; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 252 | call->buffer = kmalloc(reply_max, GFP_NOFS); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 253 | if (!call->buffer) |
| 254 | goto nomem_free; |
| 255 | } |
| 256 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 257 | afs_extract_to_buf(call, call->reply_max); |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 258 | call->operation_ID = type->op; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 259 | init_waitqueue_head(&call->waitq); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 260 | return call; |
| 261 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 262 | nomem_free: |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 263 | afs_put_call(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 264 | nomem_call: |
| 265 | return NULL; |
| 266 | } |
| 267 | |
| 268 | /* |
| 269 | * clean up a call with flat buffer |
| 270 | */ |
| 271 | void afs_flat_call_destructor(struct afs_call *call) |
| 272 | { |
| 273 | _enter(""); |
| 274 | |
| 275 | kfree(call->request); |
| 276 | call->request = NULL; |
| 277 | kfree(call->buffer); |
| 278 | call->buffer = NULL; |
| 279 | } |
| 280 | |
| 281 | /* |
David Howells | e833251 | 2017-08-29 10:18:56 +0100 | [diff] [blame] | 282 | * Advance the AFS call state when the RxRPC call ends the transmit phase. |
| 283 | */ |
| 284 | static void afs_notify_end_request_tx(struct sock *sock, |
| 285 | struct rxrpc_call *rxcall, |
| 286 | unsigned long call_user_ID) |
| 287 | { |
| 288 | struct afs_call *call = (struct afs_call *)call_user_ID; |
| 289 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 290 | afs_set_call_state(call, AFS_CALL_CL_REQUESTING, AFS_CALL_CL_AWAIT_REPLY); |
David Howells | e833251 | 2017-08-29 10:18:56 +0100 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /* |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 294 | * Initiate a call and synchronously queue up the parameters for dispatch. Any |
| 295 | * error is stored into the call struct, which the caller must check for. |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 296 | */ |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 297 | void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 298 | { |
David Howells | 2feeaf8 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 299 | struct sockaddr_rxrpc *srx = &ac->alist->addrs[ac->index]; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 300 | struct rxrpc_call *rxcall; |
| 301 | struct msghdr msg; |
| 302 | struct kvec iov[1]; |
David Howells | f105da1 | 2020-02-06 14:22:28 +0000 | [diff] [blame] | 303 | size_t len; |
David Howells | e754eba | 2017-06-07 12:40:03 +0100 | [diff] [blame] | 304 | s64 tx_total_len; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 305 | int ret; |
| 306 | |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 307 | _enter(",{%pISp},", &srx->transport); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 308 | |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 309 | ASSERT(call->type != NULL); |
| 310 | ASSERT(call->type->name != NULL); |
| 311 | |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 312 | _debug("____MAKE %p{%s,%x} [%d]____", |
| 313 | call, call->type->name, key_serial(call->key), |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 314 | atomic_read(&call->net->nr_outstanding_calls)); |
David Howells | 00d3b7a | 2007-04-26 15:57:07 -0700 | [diff] [blame] | 315 | |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 316 | call->addr_ix = ac->index; |
| 317 | call->alist = afs_get_addrlist(ac->alist); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 318 | |
David Howells | e754eba | 2017-06-07 12:40:03 +0100 | [diff] [blame] | 319 | /* Work out the length we're going to transmit. This is awkward for |
| 320 | * calls such as FS.StoreData where there's an extra injection of data |
| 321 | * after the initial fixed part. |
| 322 | */ |
| 323 | tx_total_len = call->request_size; |
David Howells | bd80d8a | 2020-02-06 14:22:28 +0000 | [diff] [blame] | 324 | if (call->write_iter) |
| 325 | tx_total_len += iov_iter_count(call->write_iter); |
David Howells | e754eba | 2017-06-07 12:40:03 +0100 | [diff] [blame] | 326 | |
David Howells | 34fa476 | 2019-01-10 15:40:50 +0000 | [diff] [blame] | 327 | /* If the call is going to be asynchronous, we need an extra ref for |
| 328 | * the call to hold itself so the caller need not hang on to its ref. |
| 329 | */ |
David Howells | dde9f09 | 2020-03-13 13:46:08 +0000 | [diff] [blame] | 330 | if (call->async) { |
David Howells | 34fa476 | 2019-01-10 15:40:50 +0000 | [diff] [blame] | 331 | afs_get_call(call, afs_call_trace_get); |
David Howells | dde9f09 | 2020-03-13 13:46:08 +0000 | [diff] [blame] | 332 | call->drop_ref = true; |
| 333 | } |
David Howells | 34fa476 | 2019-01-10 15:40:50 +0000 | [diff] [blame] | 334 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 335 | /* create a call */ |
David Howells | 4d9df98 | 2017-11-02 15:27:47 +0000 | [diff] [blame] | 336 | rxcall = rxrpc_kernel_begin_call(call->net->socket, srx, call->key, |
David Howells | e754eba | 2017-06-07 12:40:03 +0100 | [diff] [blame] | 337 | (unsigned long)call, |
David Howells | db099c6 | 2023-04-28 21:27:56 +0100 | [diff] [blame] | 338 | tx_total_len, |
| 339 | call->max_lifespan, |
| 340 | gfp, |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 341 | (call->async ? |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 342 | afs_wake_up_async_call : |
David Howells | a68f4a2 | 2017-10-18 11:36:39 +0100 | [diff] [blame] | 343 | afs_wake_up_call_waiter), |
David Howells | a25e21f | 2018-03-27 23:03:00 +0100 | [diff] [blame] | 344 | call->upgrade, |
David Howells | e138aa7 | 2020-03-13 09:22:09 +0000 | [diff] [blame] | 345 | (call->intr ? RXRPC_PREINTERRUPTIBLE : |
| 346 | RXRPC_UNINTERRUPTIBLE), |
David Howells | a25e21f | 2018-03-27 23:03:00 +0100 | [diff] [blame] | 347 | call->debug_id); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 348 | if (IS_ERR(rxcall)) { |
| 349 | ret = PTR_ERR(rxcall); |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 350 | call->error = ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 351 | goto error_kill_call; |
| 352 | } |
| 353 | |
| 354 | call->rxcall = rxcall; |
David Howells | 7903192 | 2022-08-31 13:16:42 +0100 | [diff] [blame] | 355 | call->issue_time = ktime_get_real(); |
David Howells | 94f699c | 2019-05-16 13:21:59 +0100 | [diff] [blame] | 356 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 357 | /* send the request */ |
| 358 | iov[0].iov_base = call->request; |
| 359 | iov[0].iov_len = call->request_size; |
| 360 | |
| 361 | msg.msg_name = NULL; |
| 362 | msg.msg_namelen = 0; |
Al Viro | de4eda9 | 2022-09-15 20:25:47 -0400 | [diff] [blame] | 363 | iov_iter_kvec(&msg.msg_iter, ITER_SOURCE, iov, 1, call->request_size); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 364 | msg.msg_control = NULL; |
| 365 | msg.msg_controllen = 0; |
David Howells | bd80d8a | 2020-02-06 14:22:28 +0000 | [diff] [blame] | 366 | msg.msg_flags = MSG_WAITALL | (call->write_iter ? MSG_MORE : 0); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 367 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 368 | ret = rxrpc_kernel_send_data(call->net->socket, rxcall, |
David Howells | e833251 | 2017-08-29 10:18:56 +0100 | [diff] [blame] | 369 | &msg, call->request_size, |
| 370 | afs_notify_end_request_tx); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 371 | if (ret < 0) |
| 372 | goto error_do_abort; |
| 373 | |
David Howells | bd80d8a | 2020-02-06 14:22:28 +0000 | [diff] [blame] | 374 | if (call->write_iter) { |
| 375 | msg.msg_iter = *call->write_iter; |
| 376 | msg.msg_flags &= ~MSG_MORE; |
| 377 | trace_afs_send_data(call, &msg); |
| 378 | |
| 379 | ret = rxrpc_kernel_send_data(call->net->socket, |
| 380 | call->rxcall, &msg, |
| 381 | iov_iter_count(&msg.msg_iter), |
| 382 | afs_notify_end_request_tx); |
| 383 | *call->write_iter = msg.msg_iter; |
| 384 | |
| 385 | trace_afs_sent_data(call, &msg, ret); |
David Howells | 31143d5 | 2007-05-09 02:33:46 -0700 | [diff] [blame] | 386 | if (ret < 0) |
| 387 | goto error_do_abort; |
| 388 | } |
| 389 | |
David Howells | 34fa476 | 2019-01-10 15:40:50 +0000 | [diff] [blame] | 390 | /* Note that at this point, we may have received the reply or an abort |
| 391 | * - and an asynchronous call may already have completed. |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 392 | * |
| 393 | * afs_wait_for_call_to_complete(call, ac) |
| 394 | * must be called to synchronously clean up. |
David Howells | 34fa476 | 2019-01-10 15:40:50 +0000 | [diff] [blame] | 395 | */ |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 396 | return; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 397 | |
| 398 | error_do_abort: |
David Howells | 70af0e3 | 2017-03-16 16:27:47 +0000 | [diff] [blame] | 399 | if (ret != -ECONNABORTED) { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 400 | rxrpc_kernel_abort_call(call->net->socket, rxcall, |
David Howells | 57af281 | 2022-10-06 21:45:42 +0100 | [diff] [blame] | 401 | RX_USER_ABORT, ret, |
| 402 | afs_abort_send_data_error); |
David Howells | 70af0e3 | 2017-03-16 16:27:47 +0000 | [diff] [blame] | 403 | } else { |
David Howells | f105da1 | 2020-02-06 14:22:28 +0000 | [diff] [blame] | 404 | len = 0; |
Al Viro | de4eda9 | 2022-09-15 20:25:47 -0400 | [diff] [blame] | 405 | iov_iter_kvec(&msg.msg_iter, ITER_DEST, NULL, 0, 0); |
David Howells | eb9950e | 2018-08-03 17:06:56 +0100 | [diff] [blame] | 406 | rxrpc_kernel_recv_data(call->net->socket, rxcall, |
David Howells | f105da1 | 2020-02-06 14:22:28 +0000 | [diff] [blame] | 407 | &msg.msg_iter, &len, false, |
David Howells | eb9950e | 2018-08-03 17:06:56 +0100 | [diff] [blame] | 408 | &call->abort_code, &call->service_id); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 409 | ac->abort_code = call->abort_code; |
| 410 | ac->responded = true; |
David Howells | 70af0e3 | 2017-03-16 16:27:47 +0000 | [diff] [blame] | 411 | } |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 412 | call->error = ret; |
| 413 | trace_afs_call_done(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 414 | error_kill_call: |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 415 | if (call->type->done) |
| 416 | call->type->done(call); |
David Howells | 34fa476 | 2019-01-10 15:40:50 +0000 | [diff] [blame] | 417 | |
| 418 | /* We need to dispose of the extra ref we grabbed for an async call. |
| 419 | * The call, however, might be queued on afs_async_calls and we need to |
| 420 | * make sure we don't get any more notifications that might requeue it. |
| 421 | */ |
David Howells | e0416e7 | 2023-04-21 23:03:46 +0100 | [diff] [blame] | 422 | if (call->rxcall) |
| 423 | rxrpc_kernel_shutdown_call(call->net->socket, call->rxcall); |
David Howells | 34fa476 | 2019-01-10 15:40:50 +0000 | [diff] [blame] | 424 | if (call->async) { |
| 425 | if (cancel_work_sync(&call->async_work)) |
| 426 | afs_put_call(call); |
| 427 | afs_put_call(call); |
| 428 | } |
| 429 | |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 430 | ac->error = ret; |
David Howells | 34fa476 | 2019-01-10 15:40:50 +0000 | [diff] [blame] | 431 | call->state = AFS_CALL_COMPLETE; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 432 | _leave(" = %d", ret); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | /* |
David Howells | 0509275 | 2020-06-07 21:50:29 +0100 | [diff] [blame] | 436 | * Log remote abort codes that indicate that we have a protocol disagreement |
| 437 | * with the server. |
| 438 | */ |
| 439 | static void afs_log_error(struct afs_call *call, s32 remote_abort) |
| 440 | { |
| 441 | static int max = 0; |
| 442 | const char *msg; |
| 443 | int m; |
| 444 | |
| 445 | switch (remote_abort) { |
| 446 | case RX_EOF: msg = "unexpected EOF"; break; |
| 447 | case RXGEN_CC_MARSHAL: msg = "client marshalling"; break; |
| 448 | case RXGEN_CC_UNMARSHAL: msg = "client unmarshalling"; break; |
| 449 | case RXGEN_SS_MARSHAL: msg = "server marshalling"; break; |
| 450 | case RXGEN_SS_UNMARSHAL: msg = "server unmarshalling"; break; |
| 451 | case RXGEN_DECODE: msg = "opcode decode"; break; |
| 452 | case RXGEN_SS_XDRFREE: msg = "server XDR cleanup"; break; |
| 453 | case RXGEN_CC_XDRFREE: msg = "client XDR cleanup"; break; |
| 454 | case -32: msg = "insufficient data"; break; |
| 455 | default: |
| 456 | return; |
| 457 | } |
| 458 | |
| 459 | m = max; |
| 460 | if (m < 3) { |
| 461 | max = m + 1; |
| 462 | pr_notice("kAFS: Peer reported %s failure on %s [%pISp]\n", |
| 463 | msg, call->type->name, |
| 464 | &call->alist->addrs[call->addr_ix].transport); |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 469 | * deliver messages to a call |
| 470 | */ |
| 471 | static void afs_deliver_to_call(struct afs_call *call) |
| 472 | { |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 473 | enum afs_call_state state; |
David Howells | f105da1 | 2020-02-06 14:22:28 +0000 | [diff] [blame] | 474 | size_t len; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 475 | u32 abort_code, remote_abort = 0; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 476 | int ret; |
| 477 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 478 | _enter("%s", call->type->name); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 479 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 480 | while (state = READ_ONCE(call->state), |
| 481 | state == AFS_CALL_CL_AWAIT_REPLY || |
| 482 | state == AFS_CALL_SV_AWAIT_OP_ID || |
| 483 | state == AFS_CALL_SV_AWAIT_REQUEST || |
| 484 | state == AFS_CALL_SV_AWAIT_ACK |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 485 | ) { |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 486 | if (state == AFS_CALL_SV_AWAIT_ACK) { |
David Howells | f105da1 | 2020-02-06 14:22:28 +0000 | [diff] [blame] | 487 | len = 0; |
Al Viro | de4eda9 | 2022-09-15 20:25:47 -0400 | [diff] [blame] | 488 | iov_iter_kvec(&call->def_iter, ITER_DEST, NULL, 0, 0); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 489 | ret = rxrpc_kernel_recv_data(call->net->socket, |
David Howells | fc27612 | 2019-11-21 09:12:17 +0000 | [diff] [blame] | 490 | call->rxcall, &call->def_iter, |
David Howells | f105da1 | 2020-02-06 14:22:28 +0000 | [diff] [blame] | 491 | &len, false, &remote_abort, |
David Howells | a68f4a2 | 2017-10-18 11:36:39 +0100 | [diff] [blame] | 492 | &call->service_id); |
David Howells | fc27612 | 2019-11-21 09:12:17 +0000 | [diff] [blame] | 493 | trace_afs_receive_data(call, &call->def_iter, false, ret); |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 494 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 495 | if (ret == -EINPROGRESS || ret == -EAGAIN) |
| 496 | return; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 497 | if (ret < 0 || ret == 1) { |
| 498 | if (ret == 1) |
| 499 | ret = 0; |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 500 | goto call_complete; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 501 | } |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 502 | return; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 503 | } |
| 504 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 505 | ret = call->type->deliver(call); |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 506 | state = READ_ONCE(call->state); |
David Howells | 38355ee | 2020-04-08 16:13:20 +0100 | [diff] [blame] | 507 | if (ret == 0 && call->unmarshalling_error) |
| 508 | ret = -EBADMSG; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 509 | switch (ret) { |
| 510 | case 0: |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 511 | afs_queue_call_work(call); |
David Howells | f2686b0 | 2018-05-10 14:12:50 +0100 | [diff] [blame] | 512 | if (state == AFS_CALL_CL_PROC_REPLY) { |
David Howells | 2032596 | 2020-04-30 01:03:49 +0100 | [diff] [blame] | 513 | if (call->op) |
David Howells | f2686b0 | 2018-05-10 14:12:50 +0100 | [diff] [blame] | 514 | set_bit(AFS_SERVER_FL_MAY_HAVE_CB, |
David Howells | 2032596 | 2020-04-30 01:03:49 +0100 | [diff] [blame] | 515 | &call->op->server->flags); |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 516 | goto call_complete; |
David Howells | f2686b0 | 2018-05-10 14:12:50 +0100 | [diff] [blame] | 517 | } |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 518 | ASSERTCMP(state, >, AFS_CALL_CL_PROC_REPLY); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 519 | goto done; |
| 520 | case -EINPROGRESS: |
| 521 | case -EAGAIN: |
| 522 | goto out; |
David Howells | 70af0e3 | 2017-03-16 16:27:47 +0000 | [diff] [blame] | 523 | case -ECONNABORTED: |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 524 | ASSERTCMP(state, ==, AFS_CALL_COMPLETE); |
David Howells | 0509275 | 2020-06-07 21:50:29 +0100 | [diff] [blame] | 525 | afs_log_error(call, call->abort_code); |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 526 | goto done; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 527 | case -ENOTSUPP: |
David Howells | 1157f15 | 2017-03-16 16:27:47 +0000 | [diff] [blame] | 528 | abort_code = RXGEN_OPCODE; |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 529 | rxrpc_kernel_abort_call(call->net->socket, call->rxcall, |
David Howells | 57af281 | 2022-10-06 21:45:42 +0100 | [diff] [blame] | 530 | abort_code, ret, |
| 531 | afs_abort_op_not_supported); |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 532 | goto local_abort; |
David Howells | 4ac15ea | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 533 | case -EIO: |
| 534 | pr_err("kAFS: Call %u in bad state %u\n", |
| 535 | call->debug_id, state); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 536 | fallthrough; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 537 | case -ENODATA: |
| 538 | case -EBADMSG: |
| 539 | case -EMSGSIZE: |
David Howells | de696c47 | 2022-05-21 08:45:48 +0100 | [diff] [blame] | 540 | case -ENOMEM: |
| 541 | case -EFAULT: |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 542 | abort_code = RXGEN_CC_UNMARSHAL; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 543 | if (state != AFS_CALL_CL_AWAIT_REPLY) |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 544 | abort_code = RXGEN_SS_UNMARSHAL; |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 545 | rxrpc_kernel_abort_call(call->net->socket, call->rxcall, |
David Howells | 57af281 | 2022-10-06 21:45:42 +0100 | [diff] [blame] | 546 | abort_code, ret, |
| 547 | afs_abort_unmarshal_error); |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 548 | goto local_abort; |
David Howells | 8022c4b | 2019-04-13 08:37:37 +0100 | [diff] [blame] | 549 | default: |
David Howells | de696c47 | 2022-05-21 08:45:48 +0100 | [diff] [blame] | 550 | abort_code = RX_CALL_DEAD; |
David Howells | 8022c4b | 2019-04-13 08:37:37 +0100 | [diff] [blame] | 551 | rxrpc_kernel_abort_call(call->net->socket, call->rxcall, |
David Howells | 57af281 | 2022-10-06 21:45:42 +0100 | [diff] [blame] | 552 | abort_code, ret, |
| 553 | afs_abort_general_error); |
David Howells | 8022c4b | 2019-04-13 08:37:37 +0100 | [diff] [blame] | 554 | goto local_abort; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 555 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 556 | } |
| 557 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 558 | done: |
David Howells | 3bf0fb6 | 2018-10-20 00:57:59 +0100 | [diff] [blame] | 559 | if (call->type->done) |
| 560 | call->type->done(call); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 561 | out: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 562 | _leave(""); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 563 | return; |
| 564 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 565 | local_abort: |
| 566 | abort_code = 0; |
David Howells | 025db80 | 2017-11-02 15:27:51 +0000 | [diff] [blame] | 567 | call_complete: |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 568 | afs_set_call_complete(call, ret, remote_abort); |
| 569 | state = AFS_CALL_COMPLETE; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 570 | goto done; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | /* |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 574 | * Wait synchronously for a call to complete and clean up the call struct. |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 575 | */ |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 576 | long afs_wait_for_call_to_complete(struct afs_call *call, |
| 577 | struct afs_addr_cursor *ac) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 578 | { |
David Howells | 33cd7f2 | 2017-11-02 15:27:48 +0000 | [diff] [blame] | 579 | long ret; |
Marc Dionne | f7f1dd3 | 2019-04-12 16:34:02 +0100 | [diff] [blame] | 580 | bool rxrpc_complete = false; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 581 | |
| 582 | DECLARE_WAITQUEUE(myself, current); |
| 583 | |
| 584 | _enter(""); |
| 585 | |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 586 | ret = call->error; |
| 587 | if (ret < 0) |
| 588 | goto out; |
| 589 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 590 | add_wait_queue(&call->waitq, &myself); |
| 591 | for (;;) { |
David Howells | bc5e3a5 | 2017-10-18 11:07:31 +0100 | [diff] [blame] | 592 | set_current_state(TASK_UNINTERRUPTIBLE); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 593 | |
| 594 | /* deliver any messages that are in the queue */ |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 595 | if (!afs_check_call_state(call, AFS_CALL_COMPLETE) && |
| 596 | call->need_attention) { |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 597 | call->need_attention = false; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 598 | __set_current_state(TASK_RUNNING); |
| 599 | afs_deliver_to_call(call); |
| 600 | continue; |
| 601 | } |
| 602 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 603 | if (afs_check_call_state(call, AFS_CALL_COMPLETE)) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 604 | break; |
David Howells | bc5e3a5 | 2017-10-18 11:07:31 +0100 | [diff] [blame] | 605 | |
David Howells | 7d7587d | 2020-03-12 21:40:06 +0000 | [diff] [blame] | 606 | if (!rxrpc_kernel_check_life(call->net->socket, call->rxcall)) { |
Marc Dionne | f7f1dd3 | 2019-04-12 16:34:02 +0100 | [diff] [blame] | 607 | /* rxrpc terminated the call. */ |
| 608 | rxrpc_complete = true; |
| 609 | break; |
| 610 | } |
| 611 | |
David Howells | 7d7587d | 2020-03-12 21:40:06 +0000 | [diff] [blame] | 612 | schedule(); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | remove_wait_queue(&call->waitq, &myself); |
| 616 | __set_current_state(TASK_RUNNING); |
| 617 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 618 | if (!afs_check_call_state(call, AFS_CALL_COMPLETE)) { |
Marc Dionne | f7f1dd3 | 2019-04-12 16:34:02 +0100 | [diff] [blame] | 619 | if (rxrpc_complete) { |
| 620 | afs_set_call_complete(call, call->error, call->abort_code); |
| 621 | } else { |
| 622 | /* Kill off the call if it's still live. */ |
| 623 | _debug("call interrupted"); |
| 624 | if (rxrpc_kernel_abort_call(call->net->socket, call->rxcall, |
David Howells | 57af281 | 2022-10-06 21:45:42 +0100 | [diff] [blame] | 625 | RX_USER_ABORT, -EINTR, |
| 626 | afs_abort_interrupted)) |
Marc Dionne | f7f1dd3 | 2019-04-12 16:34:02 +0100 | [diff] [blame] | 627 | afs_set_call_complete(call, -EINTR, 0); |
| 628 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 629 | } |
| 630 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 631 | spin_lock_bh(&call->state_lock); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 632 | ac->abort_code = call->abort_code; |
| 633 | ac->error = call->error; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 634 | spin_unlock_bh(&call->state_lock); |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 635 | |
| 636 | ret = ac->error; |
| 637 | switch (ret) { |
| 638 | case 0: |
David Howells | ffba718 | 2019-05-09 22:22:50 +0100 | [diff] [blame] | 639 | ret = call->ret0; |
| 640 | call->ret0 = 0; |
| 641 | |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 642 | fallthrough; |
David Howells | d2ddc77 | 2017-11-02 15:27:50 +0000 | [diff] [blame] | 643 | case -ECONNABORTED: |
| 644 | ac->responded = true; |
| 645 | break; |
David Howells | 33cd7f2 | 2017-11-02 15:27:48 +0000 | [diff] [blame] | 646 | } |
| 647 | |
David Howells | 0b9bf38 | 2019-04-25 14:26:50 +0100 | [diff] [blame] | 648 | out: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 649 | _debug("call complete"); |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 650 | afs_put_call(call); |
David Howells | 33cd7f2 | 2017-11-02 15:27:48 +0000 | [diff] [blame] | 651 | _leave(" = %p", (void *)ret); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 652 | return ret; |
| 653 | } |
| 654 | |
| 655 | /* |
| 656 | * wake up a waiting call |
| 657 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 658 | static void afs_wake_up_call_waiter(struct sock *sk, struct rxrpc_call *rxcall, |
| 659 | unsigned long call_user_ID) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 660 | { |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 661 | struct afs_call *call = (struct afs_call *)call_user_ID; |
| 662 | |
| 663 | call->need_attention = true; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 664 | wake_up(&call->waitq); |
| 665 | } |
| 666 | |
| 667 | /* |
| 668 | * wake up an asynchronous call |
| 669 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 670 | static void afs_wake_up_async_call(struct sock *sk, struct rxrpc_call *rxcall, |
| 671 | unsigned long call_user_ID) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 672 | { |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 673 | struct afs_call *call = (struct afs_call *)call_user_ID; |
David Howells | c56f9ec8 | 2022-07-06 10:52:14 +0100 | [diff] [blame] | 674 | int r; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 675 | |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 676 | trace_afs_notify_call(rxcall, call); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 677 | call->need_attention = true; |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 678 | |
David Howells | c56f9ec8 | 2022-07-06 10:52:14 +0100 | [diff] [blame] | 679 | if (__refcount_inc_not_zero(&call->ref, &r)) { |
David Howells | 2757a4d | 2022-07-06 11:26:14 +0100 | [diff] [blame] | 680 | trace_afs_call(call->debug_id, afs_call_trace_wake, r + 1, |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 681 | atomic_read(&call->net->nr_outstanding_calls), |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 682 | __builtin_return_address(0)); |
| 683 | |
| 684 | if (!queue_work(afs_async_calls, &call->async_work)) |
| 685 | afs_put_call(call); |
| 686 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | /* |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 690 | * Perform I/O processing on an asynchronous call. The work item carries a ref |
| 691 | * to the call struct that we either need to release or to pass on. |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 692 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 693 | static void afs_process_async_call(struct work_struct *work) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 694 | { |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 695 | struct afs_call *call = container_of(work, struct afs_call, async_work); |
| 696 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 697 | _enter(""); |
| 698 | |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 699 | if (call->state < AFS_CALL_COMPLETE && call->need_attention) { |
| 700 | call->need_attention = false; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 701 | afs_deliver_to_call(call); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 702 | } |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 703 | |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 704 | afs_put_call(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 705 | _leave(""); |
| 706 | } |
| 707 | |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 708 | static void afs_rx_attach(struct rxrpc_call *rxcall, unsigned long user_call_ID) |
| 709 | { |
| 710 | struct afs_call *call = (struct afs_call *)user_call_ID; |
| 711 | |
| 712 | call->rxcall = rxcall; |
| 713 | } |
| 714 | |
| 715 | /* |
| 716 | * Charge the incoming call preallocation. |
| 717 | */ |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 718 | void afs_charge_preallocation(struct work_struct *work) |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 719 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 720 | struct afs_net *net = |
| 721 | container_of(work, struct afs_net, charge_preallocation_work); |
| 722 | struct afs_call *call = net->spare_incoming_call; |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 723 | |
| 724 | for (;;) { |
| 725 | if (!call) { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 726 | call = afs_alloc_call(net, &afs_RXCMxxxx, GFP_KERNEL); |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 727 | if (!call) |
| 728 | break; |
| 729 | |
David Howells | dde9f09 | 2020-03-13 13:46:08 +0000 | [diff] [blame] | 730 | call->drop_ref = true; |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 731 | call->async = true; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 732 | call->state = AFS_CALL_SV_AWAIT_OP_ID; |
David Howells | 56ff9c8 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 733 | init_waitqueue_head(&call->waitq); |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 734 | afs_extract_to_tmp(call); |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 735 | } |
| 736 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 737 | if (rxrpc_kernel_charge_accept(net->socket, |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 738 | afs_wake_up_async_call, |
| 739 | afs_rx_attach, |
| 740 | (unsigned long)call, |
David Howells | a25e21f | 2018-03-27 23:03:00 +0100 | [diff] [blame] | 741 | GFP_KERNEL, |
| 742 | call->debug_id) < 0) |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 743 | break; |
| 744 | call = NULL; |
| 745 | } |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 746 | net->spare_incoming_call = call; |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | /* |
| 750 | * Discard a preallocated call when a socket is shut down. |
| 751 | */ |
| 752 | static void afs_rx_discard_new_call(struct rxrpc_call *rxcall, |
| 753 | unsigned long user_call_ID) |
| 754 | { |
| 755 | struct afs_call *call = (struct afs_call *)user_call_ID; |
| 756 | |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 757 | call->rxcall = NULL; |
David Howells | 341f741 | 2017-01-05 10:38:36 +0000 | [diff] [blame] | 758 | afs_put_call(call); |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 759 | } |
| 760 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 761 | /* |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 762 | * Notification of an incoming call. |
| 763 | */ |
David Howells | 00e9071 | 2016-09-08 11:10:12 +0100 | [diff] [blame] | 764 | static void afs_rx_new_call(struct sock *sk, struct rxrpc_call *rxcall, |
| 765 | unsigned long user_call_ID) |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 766 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 767 | struct afs_net *net = afs_sock2net(sk); |
| 768 | |
| 769 | queue_work(afs_wq, &net->charge_preallocation_work); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /* |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 773 | * Grab the operation ID from an incoming cache manager call. The socket |
| 774 | * buffer is discarded on error or if we don't yet have sufficient data. |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 775 | */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 776 | static int afs_deliver_cm_op_id(struct afs_call *call) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 777 | { |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 778 | int ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 779 | |
David Howells | fc27612 | 2019-11-21 09:12:17 +0000 | [diff] [blame] | 780 | _enter("{%zu}", iov_iter_count(call->iter)); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 781 | |
| 782 | /* the operation ID forms the first four bytes of the request data */ |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 783 | ret = afs_extract_data(call, true); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 784 | if (ret < 0) |
| 785 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 786 | |
David Howells | 50a2c95 | 2016-10-13 08:27:10 +0100 | [diff] [blame] | 787 | call->operation_ID = ntohl(call->tmp); |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 788 | afs_set_call_state(call, AFS_CALL_SV_AWAIT_OP_ID, AFS_CALL_SV_AWAIT_REQUEST); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 789 | |
| 790 | /* ask the cache manager to route the call (it'll change the call type |
| 791 | * if successful) */ |
| 792 | if (!afs_cm_incoming_call(call)) |
| 793 | return -ENOTSUPP; |
| 794 | |
David Howells | 8e8d7f1 | 2017-01-05 10:38:34 +0000 | [diff] [blame] | 795 | trace_afs_cb_call(call); |
| 796 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 797 | /* pass responsibility for the remainer of this message off to the |
| 798 | * cache manager op */ |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 799 | return call->type->deliver(call); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | /* |
David Howells | e833251 | 2017-08-29 10:18:56 +0100 | [diff] [blame] | 803 | * Advance the AFS call state when an RxRPC service call ends the transmit |
| 804 | * phase. |
| 805 | */ |
| 806 | static void afs_notify_end_reply_tx(struct sock *sock, |
| 807 | struct rxrpc_call *rxcall, |
| 808 | unsigned long call_user_ID) |
| 809 | { |
| 810 | struct afs_call *call = (struct afs_call *)call_user_ID; |
| 811 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 812 | afs_set_call_state(call, AFS_CALL_SV_REPLYING, AFS_CALL_SV_AWAIT_ACK); |
David Howells | e833251 | 2017-08-29 10:18:56 +0100 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | /* |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 816 | * send an empty reply |
| 817 | */ |
| 818 | void afs_send_empty_reply(struct afs_call *call) |
| 819 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 820 | struct afs_net *net = call->net; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 821 | struct msghdr msg; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 822 | |
| 823 | _enter(""); |
| 824 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 825 | rxrpc_kernel_set_tx_length(net->socket, call->rxcall, 0); |
David Howells | e754eba | 2017-06-07 12:40:03 +0100 | [diff] [blame] | 826 | |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 827 | msg.msg_name = NULL; |
| 828 | msg.msg_namelen = 0; |
Al Viro | de4eda9 | 2022-09-15 20:25:47 -0400 | [diff] [blame] | 829 | iov_iter_kvec(&msg.msg_iter, ITER_SOURCE, NULL, 0, 0); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 830 | msg.msg_control = NULL; |
| 831 | msg.msg_controllen = 0; |
| 832 | msg.msg_flags = 0; |
| 833 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 834 | switch (rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, 0, |
David Howells | e833251 | 2017-08-29 10:18:56 +0100 | [diff] [blame] | 835 | afs_notify_end_reply_tx)) { |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 836 | case 0: |
| 837 | _leave(" [replied]"); |
| 838 | return; |
| 839 | |
| 840 | case -ENOMEM: |
| 841 | _debug("oom"); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 842 | rxrpc_kernel_abort_call(net->socket, call->rxcall, |
David Howells | 57af281 | 2022-10-06 21:45:42 +0100 | [diff] [blame] | 843 | RXGEN_SS_MARSHAL, -ENOMEM, |
| 844 | afs_abort_oom); |
Gustavo A. R. Silva | df561f66 | 2020-08-23 17:36:59 -0500 | [diff] [blame] | 845 | fallthrough; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 846 | default: |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 847 | _leave(" [error]"); |
| 848 | return; |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | /* |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 853 | * send a simple reply |
| 854 | */ |
| 855 | void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len) |
| 856 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 857 | struct afs_net *net = call->net; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 858 | struct msghdr msg; |
Al Viro | 2e90b1c | 2014-11-27 21:50:31 -0500 | [diff] [blame] | 859 | struct kvec iov[1]; |
David Howells | bd6dc74 | 2007-07-20 10:59:41 +0100 | [diff] [blame] | 860 | int n; |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 861 | |
| 862 | _enter(""); |
| 863 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 864 | rxrpc_kernel_set_tx_length(net->socket, call->rxcall, len); |
David Howells | e754eba | 2017-06-07 12:40:03 +0100 | [diff] [blame] | 865 | |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 866 | iov[0].iov_base = (void *) buf; |
| 867 | iov[0].iov_len = len; |
| 868 | msg.msg_name = NULL; |
| 869 | msg.msg_namelen = 0; |
Al Viro | de4eda9 | 2022-09-15 20:25:47 -0400 | [diff] [blame] | 870 | iov_iter_kvec(&msg.msg_iter, ITER_SOURCE, iov, 1, len); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 871 | msg.msg_control = NULL; |
| 872 | msg.msg_controllen = 0; |
| 873 | msg.msg_flags = 0; |
| 874 | |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 875 | n = rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, len, |
David Howells | e833251 | 2017-08-29 10:18:56 +0100 | [diff] [blame] | 876 | afs_notify_end_reply_tx); |
David Howells | bd6dc74 | 2007-07-20 10:59:41 +0100 | [diff] [blame] | 877 | if (n >= 0) { |
David Howells | 6c67c7c | 2014-05-21 14:48:05 +0100 | [diff] [blame] | 878 | /* Success */ |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 879 | _leave(" [replied]"); |
| 880 | return; |
David Howells | bd6dc74 | 2007-07-20 10:59:41 +0100 | [diff] [blame] | 881 | } |
David Howells | 6c67c7c | 2014-05-21 14:48:05 +0100 | [diff] [blame] | 882 | |
David Howells | bd6dc74 | 2007-07-20 10:59:41 +0100 | [diff] [blame] | 883 | if (n == -ENOMEM) { |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 884 | _debug("oom"); |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 885 | rxrpc_kernel_abort_call(net->socket, call->rxcall, |
David Howells | 57af281 | 2022-10-06 21:45:42 +0100 | [diff] [blame] | 886 | RXGEN_SS_MARSHAL, -ENOMEM, |
| 887 | afs_abort_oom); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 888 | } |
David Howells | bd6dc74 | 2007-07-20 10:59:41 +0100 | [diff] [blame] | 889 | _leave(" [error]"); |
David Howells | b908fe6 | 2007-04-26 15:58:17 -0700 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | /* |
David Howells | 372ee16 | 2016-08-03 14:11:40 +0100 | [diff] [blame] | 893 | * Extract a piece of data from the received data socket buffers. |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 894 | */ |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 895 | int afs_extract_data(struct afs_call *call, bool want_more) |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 896 | { |
David Howells | f044c88 | 2017-11-02 15:27:45 +0000 | [diff] [blame] | 897 | struct afs_net *net = call->net; |
David Howells | fc27612 | 2019-11-21 09:12:17 +0000 | [diff] [blame] | 898 | struct iov_iter *iter = call->iter; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 899 | enum afs_call_state state; |
Dan Carpenter | 7888da9 | 2018-01-02 10:02:19 +0000 | [diff] [blame] | 900 | u32 remote_abort = 0; |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 901 | int ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 902 | |
David Howells | f105da1 | 2020-02-06 14:22:28 +0000 | [diff] [blame] | 903 | _enter("{%s,%zu,%zu},%d", |
| 904 | call->type->name, call->iov_len, iov_iter_count(iter), want_more); |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 905 | |
David Howells | 12bdcf3 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 906 | ret = rxrpc_kernel_recv_data(net->socket, call->rxcall, iter, |
David Howells | f105da1 | 2020-02-06 14:22:28 +0000 | [diff] [blame] | 907 | &call->iov_len, want_more, &remote_abort, |
David Howells | a68f4a2 | 2017-10-18 11:36:39 +0100 | [diff] [blame] | 908 | &call->service_id); |
David Howells | 93368b6 | 2022-10-26 23:43:00 +0100 | [diff] [blame] | 909 | trace_afs_receive_data(call, call->iter, want_more, ret); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 910 | if (ret == 0 || ret == -EAGAIN) |
| 911 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 912 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 913 | state = READ_ONCE(call->state); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 914 | if (ret == 1) { |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 915 | switch (state) { |
| 916 | case AFS_CALL_CL_AWAIT_REPLY: |
| 917 | afs_set_call_state(call, state, AFS_CALL_CL_PROC_REPLY); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 918 | break; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 919 | case AFS_CALL_SV_AWAIT_REQUEST: |
| 920 | afs_set_call_state(call, state, AFS_CALL_SV_REPLYING); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 921 | break; |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 922 | case AFS_CALL_COMPLETE: |
| 923 | kdebug("prem complete %d", call->error); |
David Howells | f51375c | 2018-10-20 00:57:57 +0100 | [diff] [blame] | 924 | return afs_io_error(call, afs_io_error_extract); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 925 | default: |
| 926 | break; |
| 927 | } |
| 928 | return 0; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 929 | } |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 930 | |
David Howells | 98bf40c | 2017-11-02 15:27:53 +0000 | [diff] [blame] | 931 | afs_set_call_complete(call, ret, remote_abort); |
David Howells | d001648 | 2016-08-30 20:42:14 +0100 | [diff] [blame] | 932 | return ret; |
David Howells | 08e0e7c | 2007-04-26 15:55:03 -0700 | [diff] [blame] | 933 | } |
David Howells | 5f702c8 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 934 | |
| 935 | /* |
| 936 | * Log protocol error production. |
| 937 | */ |
David Howells | 7126ead | 2020-04-08 16:49:08 +0100 | [diff] [blame] | 938 | noinline int afs_protocol_error(struct afs_call *call, |
David Howells | 160cb95 | 2018-10-20 00:57:56 +0100 | [diff] [blame] | 939 | enum afs_eproto_cause cause) |
David Howells | 5f702c8 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 940 | { |
David Howells | 7126ead | 2020-04-08 16:49:08 +0100 | [diff] [blame] | 941 | trace_afs_protocol_error(call, cause); |
David Howells | 38355ee | 2020-04-08 16:13:20 +0100 | [diff] [blame] | 942 | if (call) |
| 943 | call->unmarshalling_error = true; |
David Howells | 7126ead | 2020-04-08 16:49:08 +0100 | [diff] [blame] | 944 | return -EBADMSG; |
David Howells | 5f702c8 | 2018-04-06 14:17:25 +0100 | [diff] [blame] | 945 | } |