GNU Linux-libre 4.14.265-gnu1
[releases.git] / net / rxrpc / call_accept.c
1 /* incoming call handling
2  *
3  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
14 #include <linux/module.h>
15 #include <linux/net.h>
16 #include <linux/skbuff.h>
17 #include <linux/errqueue.h>
18 #include <linux/udp.h>
19 #include <linux/in.h>
20 #include <linux/in6.h>
21 #include <linux/icmp.h>
22 #include <linux/gfp.h>
23 #include <linux/circ_buf.h>
24 #include <net/sock.h>
25 #include <net/af_rxrpc.h>
26 #include <net/ip.h>
27 #include "ar-internal.h"
28
29 static void rxrpc_dummy_notify(struct sock *sk, struct rxrpc_call *call,
30                                unsigned long user_call_ID)
31 {
32 }
33
34 /*
35  * Preallocate a single service call, connection and peer and, if possible,
36  * give them a user ID and attach the user's side of the ID to them.
37  */
38 static int rxrpc_service_prealloc_one(struct rxrpc_sock *rx,
39                                       struct rxrpc_backlog *b,
40                                       rxrpc_notify_rx_t notify_rx,
41                                       rxrpc_user_attach_call_t user_attach_call,
42                                       unsigned long user_call_ID, gfp_t gfp)
43 {
44         const void *here = __builtin_return_address(0);
45         struct rxrpc_call *call;
46         struct rxrpc_net *rxnet = rxrpc_net(sock_net(&rx->sk));
47         int max, tmp;
48         unsigned int size = RXRPC_BACKLOG_MAX;
49         unsigned int head, tail, call_head, call_tail;
50
51         max = rx->sk.sk_max_ack_backlog;
52         tmp = rx->sk.sk_ack_backlog;
53         if (tmp >= max) {
54                 _leave(" = -ENOBUFS [full %u]", max);
55                 return -ENOBUFS;
56         }
57         max -= tmp;
58
59         /* We don't need more conns and peers than we have calls, but on the
60          * other hand, we shouldn't ever use more peers than conns or conns
61          * than calls.
62          */
63         call_head = b->call_backlog_head;
64         call_tail = READ_ONCE(b->call_backlog_tail);
65         tmp = CIRC_CNT(call_head, call_tail, size);
66         if (tmp >= max) {
67                 _leave(" = -ENOBUFS [enough %u]", tmp);
68                 return -ENOBUFS;
69         }
70         max = tmp + 1;
71
72         head = b->peer_backlog_head;
73         tail = READ_ONCE(b->peer_backlog_tail);
74         if (CIRC_CNT(head, tail, size) < max) {
75                 struct rxrpc_peer *peer = rxrpc_alloc_peer(rx->local, gfp);
76                 if (!peer)
77                         return -ENOMEM;
78                 b->peer_backlog[head] = peer;
79                 smp_store_release(&b->peer_backlog_head,
80                                   (head + 1) & (size - 1));
81         }
82
83         head = b->conn_backlog_head;
84         tail = READ_ONCE(b->conn_backlog_tail);
85         if (CIRC_CNT(head, tail, size) < max) {
86                 struct rxrpc_connection *conn;
87
88                 conn = rxrpc_prealloc_service_connection(rxnet, gfp);
89                 if (!conn)
90                         return -ENOMEM;
91                 b->conn_backlog[head] = conn;
92                 smp_store_release(&b->conn_backlog_head,
93                                   (head + 1) & (size - 1));
94
95                 trace_rxrpc_conn(conn, rxrpc_conn_new_service,
96                                  atomic_read(&conn->usage), here);
97         }
98
99         /* Now it gets complicated, because calls get registered with the
100          * socket here, particularly if a user ID is preassigned by the user.
101          */
102         call = rxrpc_alloc_call(rx, gfp);
103         if (!call)
104                 return -ENOMEM;
105         call->flags |= (1 << RXRPC_CALL_IS_SERVICE);
106         call->state = RXRPC_CALL_SERVER_PREALLOC;
107
108         trace_rxrpc_call(call, rxrpc_call_new_service,
109                          atomic_read(&call->usage),
110                          here, (const void *)user_call_ID);
111
112         write_lock(&rx->call_lock);
113         if (user_attach_call) {
114                 struct rxrpc_call *xcall;
115                 struct rb_node *parent, **pp;
116
117                 /* Check the user ID isn't already in use */
118                 pp = &rx->calls.rb_node;
119                 parent = NULL;
120                 while (*pp) {
121                         parent = *pp;
122                         xcall = rb_entry(parent, struct rxrpc_call, sock_node);
123                         if (user_call_ID < xcall->user_call_ID)
124                                 pp = &(*pp)->rb_left;
125                         else if (user_call_ID > xcall->user_call_ID)
126                                 pp = &(*pp)->rb_right;
127                         else
128                                 goto id_in_use;
129                 }
130
131                 call->user_call_ID = user_call_ID;
132                 call->notify_rx = notify_rx;
133                 rxrpc_get_call(call, rxrpc_call_got_kernel);
134                 user_attach_call(call, user_call_ID);
135                 rxrpc_get_call(call, rxrpc_call_got_userid);
136                 rb_link_node(&call->sock_node, parent, pp);
137                 rb_insert_color(&call->sock_node, &rx->calls);
138                 set_bit(RXRPC_CALL_HAS_USERID, &call->flags);
139         }
140
141         list_add(&call->sock_link, &rx->sock_calls);
142
143         write_unlock(&rx->call_lock);
144
145         write_lock(&rxnet->call_lock);
146         list_add_tail(&call->link, &rxnet->calls);
147         write_unlock(&rxnet->call_lock);
148
149         b->call_backlog[call_head] = call;
150         smp_store_release(&b->call_backlog_head, (call_head + 1) & (size - 1));
151         _leave(" = 0 [%d -> %lx]", call->debug_id, user_call_ID);
152         return 0;
153
154 id_in_use:
155         write_unlock(&rx->call_lock);
156         rxrpc_cleanup_call(call);
157         _leave(" = -EBADSLT");
158         return -EBADSLT;
159 }
160
161 /*
162  * Preallocate sufficient service connections, calls and peers to cover the
163  * entire backlog of a socket.  When a new call comes in, if we don't have
164  * sufficient of each available, the call gets rejected as busy or ignored.
165  *
166  * The backlog is replenished when a connection is accepted or rejected.
167  */
168 int rxrpc_service_prealloc(struct rxrpc_sock *rx, gfp_t gfp)
169 {
170         struct rxrpc_backlog *b = rx->backlog;
171
172         if (!b) {
173                 b = kzalloc(sizeof(struct rxrpc_backlog), gfp);
174                 if (!b)
175                         return -ENOMEM;
176                 rx->backlog = b;
177         }
178
179         if (rx->discard_new_call)
180                 return 0;
181
182         while (rxrpc_service_prealloc_one(rx, b, NULL, NULL, 0, gfp) == 0)
183                 ;
184
185         return 0;
186 }
187
188 /*
189  * Discard the preallocation on a service.
190  */
191 void rxrpc_discard_prealloc(struct rxrpc_sock *rx)
192 {
193         struct rxrpc_backlog *b = rx->backlog;
194         struct rxrpc_net *rxnet = rxrpc_net(sock_net(&rx->sk));
195         unsigned int size = RXRPC_BACKLOG_MAX, head, tail;
196
197         if (!b)
198                 return;
199         rx->backlog = NULL;
200
201         /* Make sure that there aren't any incoming calls in progress before we
202          * clear the preallocation buffers.
203          */
204         spin_lock_bh(&rx->incoming_lock);
205         spin_unlock_bh(&rx->incoming_lock);
206
207         head = b->peer_backlog_head;
208         tail = b->peer_backlog_tail;
209         while (CIRC_CNT(head, tail, size) > 0) {
210                 struct rxrpc_peer *peer = b->peer_backlog[tail];
211                 kfree(peer);
212                 tail = (tail + 1) & (size - 1);
213         }
214
215         head = b->conn_backlog_head;
216         tail = b->conn_backlog_tail;
217         while (CIRC_CNT(head, tail, size) > 0) {
218                 struct rxrpc_connection *conn = b->conn_backlog[tail];
219                 write_lock(&rxnet->conn_lock);
220                 list_del(&conn->link);
221                 list_del(&conn->proc_link);
222                 write_unlock(&rxnet->conn_lock);
223                 kfree(conn);
224                 tail = (tail + 1) & (size - 1);
225         }
226
227         head = b->call_backlog_head;
228         tail = b->call_backlog_tail;
229         while (CIRC_CNT(head, tail, size) > 0) {
230                 struct rxrpc_call *call = b->call_backlog[tail];
231                 call->socket = rx;
232                 if (rx->discard_new_call) {
233                         _debug("discard %lx", call->user_call_ID);
234                         rx->discard_new_call(call, call->user_call_ID);
235                         if (call->notify_rx)
236                                 call->notify_rx = rxrpc_dummy_notify;
237                         rxrpc_put_call(call, rxrpc_call_put_kernel);
238                 }
239                 rxrpc_call_completed(call);
240                 rxrpc_release_call(rx, call);
241                 rxrpc_put_call(call, rxrpc_call_put);
242                 tail = (tail + 1) & (size - 1);
243         }
244
245         kfree(b);
246 }
247
248 /*
249  * Allocate a new incoming call from the prealloc pool, along with a connection
250  * and a peer as necessary.
251  */
252 static struct rxrpc_call *rxrpc_alloc_incoming_call(struct rxrpc_sock *rx,
253                                                     struct rxrpc_local *local,
254                                                     struct rxrpc_connection *conn,
255                                                     struct sk_buff *skb)
256 {
257         struct rxrpc_backlog *b = rx->backlog;
258         struct rxrpc_peer *peer, *xpeer;
259         struct rxrpc_call *call;
260         unsigned short call_head, conn_head, peer_head;
261         unsigned short call_tail, conn_tail, peer_tail;
262         unsigned short call_count, conn_count;
263
264         /* #calls >= #conns >= #peers must hold true. */
265         call_head = smp_load_acquire(&b->call_backlog_head);
266         call_tail = b->call_backlog_tail;
267         call_count = CIRC_CNT(call_head, call_tail, RXRPC_BACKLOG_MAX);
268         conn_head = smp_load_acquire(&b->conn_backlog_head);
269         conn_tail = b->conn_backlog_tail;
270         conn_count = CIRC_CNT(conn_head, conn_tail, RXRPC_BACKLOG_MAX);
271         ASSERTCMP(conn_count, >=, call_count);
272         peer_head = smp_load_acquire(&b->peer_backlog_head);
273         peer_tail = b->peer_backlog_tail;
274         ASSERTCMP(CIRC_CNT(peer_head, peer_tail, RXRPC_BACKLOG_MAX), >=,
275                   conn_count);
276
277         if (call_count == 0)
278                 return NULL;
279
280         if (!conn) {
281                 /* No connection.  We're going to need a peer to start off
282                  * with.  If one doesn't yet exist, use a spare from the
283                  * preallocation set.  We dump the address into the spare in
284                  * anticipation - and to save on stack space.
285                  */
286                 xpeer = b->peer_backlog[peer_tail];
287                 if (rxrpc_extract_addr_from_skb(local, &xpeer->srx, skb) < 0)
288                         return NULL;
289
290                 peer = rxrpc_lookup_incoming_peer(local, xpeer);
291                 if (peer == xpeer) {
292                         b->peer_backlog[peer_tail] = NULL;
293                         smp_store_release(&b->peer_backlog_tail,
294                                           (peer_tail + 1) &
295                                           (RXRPC_BACKLOG_MAX - 1));
296                 }
297
298                 /* Now allocate and set up the connection */
299                 conn = b->conn_backlog[conn_tail];
300                 b->conn_backlog[conn_tail] = NULL;
301                 smp_store_release(&b->conn_backlog_tail,
302                                   (conn_tail + 1) & (RXRPC_BACKLOG_MAX - 1));
303                 rxrpc_get_local(local);
304                 conn->params.local = local;
305                 conn->params.peer = peer;
306                 rxrpc_see_connection(conn);
307                 rxrpc_new_incoming_connection(rx, conn, skb);
308         } else {
309                 rxrpc_get_connection(conn);
310         }
311
312         /* And now we can allocate and set up a new call */
313         call = b->call_backlog[call_tail];
314         b->call_backlog[call_tail] = NULL;
315         smp_store_release(&b->call_backlog_tail,
316                           (call_tail + 1) & (RXRPC_BACKLOG_MAX - 1));
317
318         rxrpc_see_call(call);
319         call->conn = conn;
320         call->peer = rxrpc_get_peer(conn->params.peer);
321         call->cong_cwnd = call->peer->cong_cwnd;
322         return call;
323 }
324
325 /*
326  * Set up a new incoming call.  Called in BH context with the RCU read lock
327  * held.
328  *
329  * If this is for a kernel service, when we allocate the call, it will have
330  * three refs on it: (1) the kernel service, (2) the user_call_ID tree, (3) the
331  * retainer ref obtained from the backlog buffer.  Prealloc calls for userspace
332  * services only have the ref from the backlog buffer.  We want to pass this
333  * ref to non-BH context to dispose of.
334  *
335  * If we want to report an error, we mark the skb with the packet type and
336  * abort code and return NULL.
337  *
338  * The call is returned with the user access mutex held.
339  */
340 struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *local,
341                                            struct rxrpc_connection *conn,
342                                            struct sk_buff *skb)
343 {
344         struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
345         struct rxrpc_sock *rx;
346         struct rxrpc_call *call;
347         u16 service_id = sp->hdr.serviceId;
348
349         _enter("");
350
351         /* Get the socket providing the service */
352         rx = rcu_dereference(local->service);
353         if (rx && (service_id == rx->srx.srx_service ||
354                    service_id == rx->second_service))
355                 goto found_service;
356
357         trace_rxrpc_abort("INV", sp->hdr.cid, sp->hdr.callNumber, sp->hdr.seq,
358                           RX_INVALID_OPERATION, EOPNOTSUPP);
359         skb->mark = RXRPC_SKB_MARK_LOCAL_ABORT;
360         skb->priority = RX_INVALID_OPERATION;
361         _leave(" = NULL [service]");
362         return NULL;
363
364 found_service:
365         spin_lock(&rx->incoming_lock);
366         if (rx->sk.sk_state == RXRPC_SERVER_LISTEN_DISABLED ||
367             rx->sk.sk_state == RXRPC_CLOSE) {
368                 trace_rxrpc_abort("CLS", sp->hdr.cid, sp->hdr.callNumber,
369                                   sp->hdr.seq, RX_INVALID_OPERATION, ESHUTDOWN);
370                 skb->mark = RXRPC_SKB_MARK_LOCAL_ABORT;
371                 skb->priority = RX_INVALID_OPERATION;
372                 _leave(" = NULL [close]");
373                 call = NULL;
374                 goto out;
375         }
376
377         call = rxrpc_alloc_incoming_call(rx, local, conn, skb);
378         if (!call) {
379                 skb->mark = RXRPC_SKB_MARK_BUSY;
380                 _leave(" = NULL [busy]");
381                 call = NULL;
382                 goto out;
383         }
384
385         trace_rxrpc_receive(call, rxrpc_receive_incoming,
386                             sp->hdr.serial, sp->hdr.seq);
387
388         /* Lock the call to prevent rxrpc_kernel_send/recv_data() and
389          * sendmsg()/recvmsg() inconveniently stealing the mutex once the
390          * notification is generated.
391          *
392          * The BUG should never happen because the kernel should be well
393          * behaved enough not to access the call before the first notification
394          * event and userspace is prevented from doing so until the state is
395          * appropriate.
396          */
397         if (!mutex_trylock(&call->user_mutex))
398                 BUG();
399
400         /* Make the call live. */
401         rxrpc_incoming_call(rx, call, skb);
402         conn = call->conn;
403
404         if (rx->notify_new_call)
405                 rx->notify_new_call(&rx->sk, call, call->user_call_ID);
406         else
407                 sk_acceptq_added(&rx->sk);
408
409         spin_lock(&conn->state_lock);
410         switch (conn->state) {
411         case RXRPC_CONN_SERVICE_UNSECURED:
412                 conn->state = RXRPC_CONN_SERVICE_CHALLENGING;
413                 set_bit(RXRPC_CONN_EV_CHALLENGE, &call->conn->events);
414                 rxrpc_queue_conn(call->conn);
415                 break;
416
417         case RXRPC_CONN_SERVICE:
418                 write_lock(&call->state_lock);
419                 if (rx->discard_new_call)
420                         call->state = RXRPC_CALL_SERVER_RECV_REQUEST;
421                 else
422                         call->state = RXRPC_CALL_SERVER_ACCEPTING;
423                 write_unlock(&call->state_lock);
424                 break;
425
426         case RXRPC_CONN_REMOTELY_ABORTED:
427                 rxrpc_set_call_completion(call, RXRPC_CALL_REMOTELY_ABORTED,
428                                           conn->abort_code, conn->error);
429                 break;
430         case RXRPC_CONN_LOCALLY_ABORTED:
431                 rxrpc_abort_call("CON", call, sp->hdr.seq,
432                                  conn->abort_code, conn->error);
433                 break;
434         default:
435                 BUG();
436         }
437         spin_unlock(&conn->state_lock);
438
439         if (call->state == RXRPC_CALL_SERVER_ACCEPTING)
440                 rxrpc_notify_socket(call);
441
442         /* We have to discard the prealloc queue's ref here and rely on a
443          * combination of the RCU read lock and refs held either by the socket
444          * (recvmsg queue, to-be-accepted queue or user ID tree) or the kernel
445          * service to prevent the call from being deallocated too early.
446          */
447         rxrpc_put_call(call, rxrpc_call_put);
448
449         _leave(" = %p{%d}", call, call->debug_id);
450 out:
451         spin_unlock(&rx->incoming_lock);
452         return call;
453 }
454
455 /*
456  * handle acceptance of a call by userspace
457  * - assign the user call ID to the call at the front of the queue
458  * - called with the socket locked.
459  */
460 struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *rx,
461                                      unsigned long user_call_ID,
462                                      rxrpc_notify_rx_t notify_rx)
463         __releases(&rx->sk.sk_lock.slock)
464 {
465         struct rxrpc_call *call;
466         struct rb_node *parent, **pp;
467         int ret;
468
469         _enter(",%lx", user_call_ID);
470
471         ASSERT(!irqs_disabled());
472
473         write_lock(&rx->call_lock);
474
475         if (list_empty(&rx->to_be_accepted)) {
476                 write_unlock(&rx->call_lock);
477                 release_sock(&rx->sk);
478                 kleave(" = -ENODATA [empty]");
479                 return ERR_PTR(-ENODATA);
480         }
481
482         /* check the user ID isn't already in use */
483         pp = &rx->calls.rb_node;
484         parent = NULL;
485         while (*pp) {
486                 parent = *pp;
487                 call = rb_entry(parent, struct rxrpc_call, sock_node);
488
489                 if (user_call_ID < call->user_call_ID)
490                         pp = &(*pp)->rb_left;
491                 else if (user_call_ID > call->user_call_ID)
492                         pp = &(*pp)->rb_right;
493                 else
494                         goto id_in_use;
495         }
496
497         /* Dequeue the first call and check it's still valid.  We gain
498          * responsibility for the queue's reference.
499          */
500         call = list_entry(rx->to_be_accepted.next,
501                           struct rxrpc_call, accept_link);
502         write_unlock(&rx->call_lock);
503
504         /* We need to gain the mutex from the interrupt handler without
505          * upsetting lockdep, so we have to release it there and take it here.
506          * We are, however, still holding the socket lock, so other accepts
507          * must wait for us and no one can add the user ID behind our backs.
508          */
509         if (mutex_lock_interruptible(&call->user_mutex) < 0) {
510                 release_sock(&rx->sk);
511                 kleave(" = -ERESTARTSYS");
512                 return ERR_PTR(-ERESTARTSYS);
513         }
514
515         write_lock(&rx->call_lock);
516         list_del_init(&call->accept_link);
517         sk_acceptq_removed(&rx->sk);
518         rxrpc_see_call(call);
519
520         /* Find the user ID insertion point. */
521         pp = &rx->calls.rb_node;
522         parent = NULL;
523         while (*pp) {
524                 parent = *pp;
525                 call = rb_entry(parent, struct rxrpc_call, sock_node);
526
527                 if (user_call_ID < call->user_call_ID)
528                         pp = &(*pp)->rb_left;
529                 else if (user_call_ID > call->user_call_ID)
530                         pp = &(*pp)->rb_right;
531                 else
532                         BUG();
533         }
534
535         write_lock_bh(&call->state_lock);
536         switch (call->state) {
537         case RXRPC_CALL_SERVER_ACCEPTING:
538                 call->state = RXRPC_CALL_SERVER_RECV_REQUEST;
539                 break;
540         case RXRPC_CALL_COMPLETE:
541                 ret = call->error;
542                 goto out_release;
543         default:
544                 BUG();
545         }
546
547         /* formalise the acceptance */
548         call->notify_rx = notify_rx;
549         call->user_call_ID = user_call_ID;
550         rxrpc_get_call(call, rxrpc_call_got_userid);
551         rb_link_node(&call->sock_node, parent, pp);
552         rb_insert_color(&call->sock_node, &rx->calls);
553         if (test_and_set_bit(RXRPC_CALL_HAS_USERID, &call->flags))
554                 BUG();
555
556         write_unlock_bh(&call->state_lock);
557         write_unlock(&rx->call_lock);
558         rxrpc_notify_socket(call);
559         rxrpc_service_prealloc(rx, GFP_KERNEL);
560         release_sock(&rx->sk);
561         _leave(" = %p{%d}", call, call->debug_id);
562         return call;
563
564 out_release:
565         _debug("release %p", call);
566         write_unlock_bh(&call->state_lock);
567         write_unlock(&rx->call_lock);
568         rxrpc_release_call(rx, call);
569         rxrpc_put_call(call, rxrpc_call_put);
570         goto out;
571
572 id_in_use:
573         ret = -EBADSLT;
574         write_unlock(&rx->call_lock);
575 out:
576         rxrpc_service_prealloc(rx, GFP_KERNEL);
577         release_sock(&rx->sk);
578         _leave(" = %d", ret);
579         return ERR_PTR(ret);
580 }
581
582 /*
583  * Handle rejection of a call by userspace
584  * - reject the call at the front of the queue
585  */
586 int rxrpc_reject_call(struct rxrpc_sock *rx)
587 {
588         struct rxrpc_call *call;
589         bool abort = false;
590         int ret;
591
592         _enter("");
593
594         ASSERT(!irqs_disabled());
595
596         write_lock(&rx->call_lock);
597
598         if (list_empty(&rx->to_be_accepted)) {
599                 write_unlock(&rx->call_lock);
600                 return -ENODATA;
601         }
602
603         /* Dequeue the first call and check it's still valid.  We gain
604          * responsibility for the queue's reference.
605          */
606         call = list_entry(rx->to_be_accepted.next,
607                           struct rxrpc_call, accept_link);
608         list_del_init(&call->accept_link);
609         sk_acceptq_removed(&rx->sk);
610         rxrpc_see_call(call);
611
612         write_lock_bh(&call->state_lock);
613         switch (call->state) {
614         case RXRPC_CALL_SERVER_ACCEPTING:
615                 __rxrpc_abort_call("REJ", call, 1, RX_USER_ABORT, -ECONNABORTED);
616                 abort = true;
617                 /* fall through */
618         case RXRPC_CALL_COMPLETE:
619                 ret = call->error;
620                 goto out_discard;
621         default:
622                 BUG();
623         }
624
625 out_discard:
626         write_unlock_bh(&call->state_lock);
627         write_unlock(&rx->call_lock);
628         if (abort) {
629                 rxrpc_send_abort_packet(call);
630                 rxrpc_release_call(rx, call);
631                 rxrpc_put_call(call, rxrpc_call_put);
632         }
633         rxrpc_service_prealloc(rx, GFP_KERNEL);
634         _leave(" = %d", ret);
635         return ret;
636 }
637
638 /*
639  * rxrpc_kernel_charge_accept - Charge up socket with preallocated calls
640  * @sock: The socket on which to preallocate
641  * @notify_rx: Event notification function for the call
642  * @user_attach_call: Func to attach call to user_call_ID
643  * @user_call_ID: The tag to attach to the preallocated call
644  * @gfp: The allocation conditions.
645  *
646  * Charge up the socket with preallocated calls, each with a user ID.  A
647  * function should be provided to effect the attachment from the user's side.
648  * The user is given a ref to hold on the call.
649  *
650  * Note that the call may be come connected before this function returns.
651  */
652 int rxrpc_kernel_charge_accept(struct socket *sock,
653                                rxrpc_notify_rx_t notify_rx,
654                                rxrpc_user_attach_call_t user_attach_call,
655                                unsigned long user_call_ID, gfp_t gfp)
656 {
657         struct rxrpc_sock *rx = rxrpc_sk(sock->sk);
658         struct rxrpc_backlog *b = rx->backlog;
659
660         if (sock->sk->sk_state == RXRPC_CLOSE)
661                 return -ESHUTDOWN;
662
663         return rxrpc_service_prealloc_one(rx, b, notify_rx,
664                                           user_attach_call, user_call_ID,
665                                           gfp);
666 }
667 EXPORT_SYMBOL(rxrpc_kernel_charge_accept);