Orange Pi5 kernel

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

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