call_event.c 32.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/* Management of Tx window, Tx resend, ACKs and out-of-sequence reception
 *
 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
 * Written by David Howells (dhowells@redhat.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */

12 13
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

14 15 16 17
#include <linux/module.h>
#include <linux/circ_buf.h>
#include <linux/net.h>
#include <linux/skbuff.h>
18
#include <linux/slab.h>
19 20 21 22 23 24 25 26
#include <linux/udp.h>
#include <net/sock.h>
#include <net/af_rxrpc.h>
#include "ar-internal.h"

/*
 * propose an ACK be sent
 */
27
void __rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason,
28
			 u16 skew, u32 serial, bool immediate)
29 30 31 32 33 34 35
{
	unsigned long expiry;
	s8 prior = rxrpc_ack_priority[ack_reason];

	ASSERTCMP(prior, >, 0);

	_enter("{%d},%s,%%%x,%u",
36
	       call->debug_id, rxrpc_acks(ack_reason), serial, immediate);
37 38 39 40 41 42 43 44 45 46

	if (prior < rxrpc_ack_priority[call->ackr_reason]) {
		if (immediate)
			goto cancel_timer;
		return;
	}

	/* update DELAY, IDLE, REQUESTED and PING_RESPONSE ACK serial
	 * numbers */
	if (prior == rxrpc_ack_priority[call->ackr_reason]) {
47 48
		if (prior <= 4) {
			call->ackr_skew = skew;
49
			call->ackr_serial = serial;
50
		}
51 52 53 54 55 56 57 58 59 60 61
		if (immediate)
			goto cancel_timer;
		return;
	}

	call->ackr_reason = ack_reason;
	call->ackr_serial = serial;

	switch (ack_reason) {
	case RXRPC_ACK_DELAY:
		_debug("run delay timer");
62 63
		expiry = rxrpc_soft_ack_delay;
		goto run_timer;
64 65 66 67

	case RXRPC_ACK_IDLE:
		if (!immediate) {
			_debug("run defer timer");
68
			expiry = rxrpc_idle_ack_delay;
69 70 71 72 73
			goto run_timer;
		}
		goto cancel_timer;

	case RXRPC_ACK_REQUESTED:
74 75
		expiry = rxrpc_requested_ack_delay;
		if (!expiry)
76
			goto cancel_timer;
77
		if (!immediate || serial == 1) {
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
			_debug("run defer timer");
			goto run_timer;
		}

	default:
		_debug("immediate ACK");
		goto cancel_timer;
	}

run_timer:
	expiry += jiffies;
	if (!timer_pending(&call->ack_timer) ||
	    time_after(call->ack_timer.expires, expiry))
		mod_timer(&call->ack_timer, expiry);
	return;

cancel_timer:
95
	_debug("cancel timer %%%u", serial);
96 97
	try_to_del_timer_sync(&call->ack_timer);
	read_lock_bh(&call->state_lock);
98
	if (call->state < RXRPC_CALL_COMPLETE &&
99
	    !test_and_set_bit(RXRPC_CALL_EV_ACK, &call->events))
100
		rxrpc_queue_call(call);
101 102 103 104 105 106
	read_unlock_bh(&call->state_lock);
}

/*
 * propose an ACK be sent, locking the call structure
 */
107
void rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason,
108
		       u16 skew, u32 serial, bool immediate)
109 110 111 112 113
{
	s8 prior = rxrpc_ack_priority[ack_reason];

	if (prior > rxrpc_ack_priority[call->ackr_reason]) {
		spin_lock_bh(&call->lock);
114
		__rxrpc_propose_ACK(call, ack_reason, skew, serial, immediate);
115 116 117 118 119 120 121 122 123 124 125
		spin_unlock_bh(&call->lock);
	}
}

/*
 * set the resend timer
 */
static void rxrpc_set_resend(struct rxrpc_call *call, u8 resend,
			     unsigned long resend_at)
{
	read_lock_bh(&call->state_lock);
126
	if (call->state == RXRPC_CALL_COMPLETE)
127 128 129 130
		resend = 0;

	if (resend & 1) {
		_debug("SET RESEND");
131
		set_bit(RXRPC_CALL_EV_RESEND, &call->events);
132 133 134 135 136 137 138 139 140
	}

	if (resend & 2) {
		_debug("MODIFY RESEND TIMER");
		set_bit(RXRPC_CALL_RUN_RTIMER, &call->flags);
		mod_timer(&call->resend_timer, resend_at);
	} else {
		_debug("KILL RESEND TIMER");
		del_timer_sync(&call->resend_timer);
141
		clear_bit(RXRPC_CALL_EV_RESEND_TIMER, &call->events);
142 143 144 145 146 147 148 149 150 151
		clear_bit(RXRPC_CALL_RUN_RTIMER, &call->flags);
	}
	read_unlock_bh(&call->state_lock);
}

/*
 * resend packets
 */
static void rxrpc_resend(struct rxrpc_call *call)
{
152
	struct rxrpc_wire_header *whdr;
153 154 155
	struct rxrpc_skb_priv *sp;
	struct sk_buff *txb;
	unsigned long *p_txb, resend_at;
156 157
	bool stop;
	int loop;
158 159 160 161 162 163 164
	u8 resend;

	_enter("{%d,%d,%d,%d},",
	       call->acks_hard, call->acks_unacked,
	       atomic_read(&call->sequence),
	       CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));

165
	stop = false;
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
	resend = 0;
	resend_at = 0;

	for (loop = call->acks_tail;
	     loop != call->acks_head || stop;
	     loop = (loop + 1) &  (call->acks_winsz - 1)
	     ) {
		p_txb = call->acks_window + loop;
		smp_read_barrier_depends();
		if (*p_txb & 1)
			continue;

		txb = (struct sk_buff *) *p_txb;
		sp = rxrpc_skb(txb);

		if (sp->need_resend) {
182
			sp->need_resend = false;
183 184

			/* each Tx packet has a new serial number */
185
			sp->hdr.serial = atomic_inc_return(&call->conn->serial);
186

187 188
			whdr = (struct rxrpc_wire_header *)txb->head;
			whdr->serial = htonl(sp->hdr.serial);
189 190

			_proto("Tx DATA %%%u { #%d }",
191
			       sp->hdr.serial, sp->hdr.seq);
192
			if (rxrpc_send_data_packet(call->conn, txb) < 0) {
193
				stop = true;
194 195
				sp->resend_at = jiffies + 3;
			} else {
196 197
				if (rxrpc_is_client_call(call))
					rxrpc_expose_client_call(call);
198
				sp->resend_at =
199
					jiffies + rxrpc_resend_timeout;
200 201 202 203
			}
		}

		if (time_after_eq(jiffies + 1, sp->resend_at)) {
204
			sp->need_resend = true;
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
			resend |= 1;
		} else if (resend & 2) {
			if (time_before(sp->resend_at, resend_at))
				resend_at = sp->resend_at;
		} else {
			resend_at = sp->resend_at;
			resend |= 2;
		}
	}

	rxrpc_set_resend(call, resend, resend_at);
	_leave("");
}

/*
 * handle resend timer expiry
 */
static void rxrpc_resend_timer(struct rxrpc_call *call)
{
	struct rxrpc_skb_priv *sp;
	struct sk_buff *txb;
	unsigned long *p_txb, resend_at;
	int loop;
	u8 resend;

	_enter("%d,%d,%d",
	       call->acks_tail, call->acks_unacked, call->acks_head);

233
	if (call->state == RXRPC_CALL_COMPLETE)
234 235
		return;

236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
	resend = 0;
	resend_at = 0;

	for (loop = call->acks_unacked;
	     loop != call->acks_head;
	     loop = (loop + 1) &  (call->acks_winsz - 1)
	     ) {
		p_txb = call->acks_window + loop;
		smp_read_barrier_depends();
		txb = (struct sk_buff *) (*p_txb & ~1);
		sp = rxrpc_skb(txb);

		ASSERT(!(*p_txb & 1));

		if (sp->need_resend) {
			;
		} else if (time_after_eq(jiffies + 1, sp->resend_at)) {
253
			sp->need_resend = true;
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
			resend |= 1;
		} else if (resend & 2) {
			if (time_before(sp->resend_at, resend_at))
				resend_at = sp->resend_at;
		} else {
			resend_at = sp->resend_at;
			resend |= 2;
		}
	}

	rxrpc_set_resend(call, resend, resend_at);
	_leave("");
}

/*
 * process soft ACKs of our transmitted packets
 * - these indicate packets the peer has or has not received, but hasn't yet
 *   given to the consumer, and so can still be discarded and re-requested
 */
static int rxrpc_process_soft_ACKs(struct rxrpc_call *call,
				   struct rxrpc_ackpacket *ack,
				   struct sk_buff *skb)
{
	struct rxrpc_skb_priv *sp;
	struct sk_buff *txb;
	unsigned long *p_txb, resend_at;
	int loop;
	u8 sacks[RXRPC_MAXACKS], resend;

	_enter("{%d,%d},{%d},",
	       call->acks_hard,
	       CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz),
	       ack->nAcks);

	if (skb_copy_bits(skb, 0, sacks, ack->nAcks) < 0)
		goto protocol_error;

	resend = 0;
	resend_at = 0;
	for (loop = 0; loop < ack->nAcks; loop++) {
		p_txb = call->acks_window;
		p_txb += (call->acks_tail + loop) & (call->acks_winsz - 1);
		smp_read_barrier_depends();
		txb = (struct sk_buff *) (*p_txb & ~1);
		sp = rxrpc_skb(txb);

		switch (sacks[loop]) {
		case RXRPC_ACK_TYPE_ACK:
302
			sp->need_resend = false;
303 304 305
			*p_txb |= 1;
			break;
		case RXRPC_ACK_TYPE_NACK:
306
			sp->need_resend = true;
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
			*p_txb &= ~1;
			resend = 1;
			break;
		default:
			_debug("Unsupported ACK type %d", sacks[loop]);
			goto protocol_error;
		}
	}

	smp_mb();
	call->acks_unacked = (call->acks_tail + loop) & (call->acks_winsz - 1);

	/* anything not explicitly ACK'd is implicitly NACK'd, but may just not
	 * have been received or processed yet by the far end */
	for (loop = call->acks_unacked;
	     loop != call->acks_head;
	     loop = (loop + 1) &  (call->acks_winsz - 1)
	     ) {
		p_txb = call->acks_window + loop;
		smp_read_barrier_depends();
		txb = (struct sk_buff *) (*p_txb & ~1);
		sp = rxrpc_skb(txb);

		if (*p_txb & 1) {
			/* packet must have been discarded */
332
			sp->need_resend = true;
333 334 335 336 337
			*p_txb &= ~1;
			resend |= 1;
		} else if (sp->need_resend) {
			;
		} else if (time_after_eq(jiffies + 1, sp->resend_at)) {
338
			sp->need_resend = true;
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
			resend |= 1;
		} else if (resend & 2) {
			if (time_before(sp->resend_at, resend_at))
				resend_at = sp->resend_at;
		} else {
			resend_at = sp->resend_at;
			resend |= 2;
		}
	}

	rxrpc_set_resend(call, resend, resend_at);
	_leave(" = 0");
	return 0;

protocol_error:
	_leave(" = -EPROTO");
	return -EPROTO;
}

/*
 * discard hard-ACK'd packets from the Tx window
 */
static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
{
	unsigned long _skb;
	int tail = call->acks_tail, old_tail;
	int win = CIRC_CNT(call->acks_head, tail, call->acks_winsz);

367
	_enter("{%u,%u},%u", call->acks_hard, win, hard);
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382

	ASSERTCMP(hard - call->acks_hard, <=, win);

	while (call->acks_hard < hard) {
		smp_read_barrier_depends();
		_skb = call->acks_window[tail] & ~1;
		rxrpc_free_skb((struct sk_buff *) _skb);
		old_tail = tail;
		tail = (tail + 1) & (call->acks_winsz - 1);
		call->acks_tail = tail;
		if (call->acks_unacked == old_tail)
			call->acks_unacked = tail;
		call->acks_hard++;
	}

383
	wake_up(&call->waitq);
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
}

/*
 * clear the Tx window in the event of a failure
 */
static void rxrpc_clear_tx_window(struct rxrpc_call *call)
{
	rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
}

/*
 * drain the out of sequence received packet queue into the packet Rx queue
 */
static int rxrpc_drain_rx_oos_queue(struct rxrpc_call *call)
{
	struct rxrpc_skb_priv *sp;
	struct sk_buff *skb;
	bool terminal;
	int ret;

	_enter("{%d,%d}", call->rx_data_post, call->rx_first_oos);

	spin_lock_bh(&call->lock);

	ret = -ECONNRESET;
	if (test_bit(RXRPC_CALL_RELEASED, &call->flags))
		goto socket_unavailable;

	skb = skb_dequeue(&call->rx_oos_queue);
	if (skb) {
414
		rxrpc_see_skb(skb);
415 416 417
		sp = rxrpc_skb(skb);

		_debug("drain OOS packet %d [%d]",
418
		       sp->hdr.seq, call->rx_first_oos);
419

420
		if (sp->hdr.seq != call->rx_first_oos) {
421
			skb_queue_head(&call->rx_oos_queue, skb);
422
			call->rx_first_oos = rxrpc_skb(skb)->hdr.seq;
423 424 425 426 427 428 429 430 431 432 433 434
			_debug("requeue %p {%u}", skb, call->rx_first_oos);
		} else {
			skb->mark = RXRPC_SKB_MARK_DATA;
			terminal = ((sp->hdr.flags & RXRPC_LAST_PACKET) &&
				!(sp->hdr.flags & RXRPC_CLIENT_INITIATED));
			ret = rxrpc_queue_rcv_skb(call, skb, true, terminal);
			BUG_ON(ret < 0);
			_debug("drain #%u", call->rx_data_post);
			call->rx_data_post++;

			/* find out what the next packet is */
			skb = skb_peek(&call->rx_oos_queue);
435
			rxrpc_see_skb(skb);
436
			if (skb)
437
				call->rx_first_oos = rxrpc_skb(skb)->hdr.seq;
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
			else
				call->rx_first_oos = 0;
			_debug("peek %p {%u}", skb, call->rx_first_oos);
		}
	}

	ret = 0;
socket_unavailable:
	spin_unlock_bh(&call->lock);
	_leave(" = %d", ret);
	return ret;
}

/*
 * insert an out of sequence packet into the buffer
 */
static void rxrpc_insert_oos_packet(struct rxrpc_call *call,
				    struct sk_buff *skb)
{
	struct rxrpc_skb_priv *sp, *psp;
	struct sk_buff *p;
	u32 seq;

	sp = rxrpc_skb(skb);
462
	seq = sp->hdr.seq;
463 464 465 466 467
	_enter(",,{%u}", seq);

	skb->destructor = rxrpc_packet_destructor;
	ASSERTCMP(sp->call, ==, NULL);
	sp->call = call;
D
David Howells 已提交
468
	rxrpc_get_call_for_skb(call, skb);
469 470 471 472 473 474

	/* insert into the buffer in sequence order */
	spin_lock_bh(&call->lock);

	skb_queue_walk(&call->rx_oos_queue, p) {
		psp = rxrpc_skb(p);
475 476
		if (psp->hdr.seq > seq) {
			_debug("insert oos #%u before #%u", seq, psp->hdr.seq);
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
			skb_insert(p, skb, &call->rx_oos_queue);
			goto inserted;
		}
	}

	_debug("append oos #%u", seq);
	skb_queue_tail(&call->rx_oos_queue, skb);
inserted:

	/* we might now have a new front to the queue */
	if (call->rx_first_oos == 0 || seq < call->rx_first_oos)
		call->rx_first_oos = seq;

	read_lock(&call->state_lock);
	if (call->state < RXRPC_CALL_COMPLETE &&
	    call->rx_data_post == call->rx_first_oos) {
		_debug("drain rx oos now");
494
		set_bit(RXRPC_CALL_EV_DRAIN_RX_OOS, &call->events);
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
	}
	read_unlock(&call->state_lock);

	spin_unlock_bh(&call->lock);
	_leave(" [stored #%u]", call->rx_first_oos);
}

/*
 * clear the Tx window on final ACK reception
 */
static void rxrpc_zap_tx_window(struct rxrpc_call *call)
{
	struct rxrpc_skb_priv *sp;
	struct sk_buff *skb;
	unsigned long _skb, *acks_window;
510
	u8 winsz = call->acks_winsz;
511 512 513 514 515 516 517 518 519 520 521 522 523 524
	int tail;

	acks_window = call->acks_window;
	call->acks_window = NULL;

	while (CIRC_CNT(call->acks_head, call->acks_tail, winsz) > 0) {
		tail = call->acks_tail;
		smp_read_barrier_depends();
		_skb = acks_window[tail] & ~1;
		smp_mb();
		call->acks_tail = (call->acks_tail + 1) & (winsz - 1);

		skb = (struct sk_buff *) _skb;
		sp = rxrpc_skb(skb);
525
		_debug("+++ clear Tx %u", sp->hdr.seq);
526 527 528 529 530 531
		rxrpc_free_skb(skb);
	}

	kfree(acks_window);
}

532 533 534 535
/*
 * process the extra information that may be appended to an ACK packet
 */
static void rxrpc_extract_ackinfo(struct rxrpc_call *call, struct sk_buff *skb,
536
				  unsigned int latest, int nAcks)
537 538 539
{
	struct rxrpc_ackinfo ackinfo;
	struct rxrpc_peer *peer;
540
	unsigned int mtu;
541 542 543 544 545 546 547 548 549 550 551 552 553

	if (skb_copy_bits(skb, nAcks + 3, &ackinfo, sizeof(ackinfo)) < 0) {
		_leave(" [no ackinfo]");
		return;
	}

	_proto("Rx ACK %%%u Info { rx=%u max=%u rwin=%u jm=%u }",
	       latest,
	       ntohl(ackinfo.rxMTU), ntohl(ackinfo.maxMTU),
	       ntohl(ackinfo.rwind), ntohl(ackinfo.jumbo_max));

	mtu = min(ntohl(ackinfo.rxMTU), ntohl(ackinfo.maxMTU));

554
	peer = call->conn->params.peer;
555 556 557 558 559 560 561 562 563
	if (mtu < peer->maxdata) {
		spin_lock_bh(&peer->lock);
		peer->maxdata = mtu;
		peer->mtu = mtu + peer->hdrsize;
		spin_unlock_bh(&peer->lock);
		_net("Net MTU %u (maxdata %u)", peer->mtu, peer->maxdata);
	}
}

564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
/*
 * process packets in the reception queue
 */
static int rxrpc_process_rx_queue(struct rxrpc_call *call,
				  u32 *_abort_code)
{
	struct rxrpc_ackpacket ack;
	struct rxrpc_skb_priv *sp;
	struct sk_buff *skb;
	bool post_ACK;
	int latest;
	u32 hard, tx;

	_enter("");

process_further:
	skb = skb_dequeue(&call->rx_queue);
	if (!skb)
		return -EAGAIN;

584
	rxrpc_see_skb(skb);
585 586 587 588 589 590 591 592 593 594 595 596
	_net("deferred skb %p", skb);

	sp = rxrpc_skb(skb);

	_debug("process %s [st %d]", rxrpc_pkts[sp->hdr.type], call->state);

	post_ACK = false;

	switch (sp->hdr.type) {
		/* data packets that wind up here have been received out of
		 * order, need security processing or are jumbo packets */
	case RXRPC_PACKET_TYPE_DATA:
597
		_proto("OOSQ DATA %%%u { #%u }", sp->hdr.serial, sp->hdr.seq);
598 599

		/* secured packets must be verified and possibly decrypted */
600 601
		if (call->conn->security->verify_packet(call, skb,
							_abort_code) < 0)
602 603 604 605 606 607 608 609 610 611 612 613 614 615
			goto protocol_error;

		rxrpc_insert_oos_packet(call, skb);
		goto process_further;

		/* partial ACK to process */
	case RXRPC_PACKET_TYPE_ACK:
		if (skb_copy_bits(skb, 0, &ack, sizeof(ack)) < 0) {
			_debug("extraction failure");
			goto protocol_error;
		}
		if (!skb_pull(skb, sizeof(ack)))
			BUG();

616
		latest = sp->hdr.serial;
617 618 619 620 621 622 623 624 625
		hard = ntohl(ack.firstPacket);
		tx = atomic_read(&call->sequence);

		_proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
		       latest,
		       ntohs(ack.maxSkew),
		       hard,
		       ntohl(ack.previousPacket),
		       ntohl(ack.serial),
626
		       rxrpc_acks(ack.reason),
627 628
		       ack.nAcks);

629 630
		rxrpc_extract_ackinfo(call, skb, latest, ack.nAcks);

631 632 633
		if (ack.reason == RXRPC_ACK_PING) {
			_proto("Rx ACK %%%u PING Request", latest);
			rxrpc_propose_ACK(call, RXRPC_ACK_PING_RESPONSE,
634
					  skb->priority, sp->hdr.serial, true);
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
		}

		/* discard any out-of-order or duplicate ACKs */
		if (latest - call->acks_latest <= 0) {
			_debug("discard ACK %d <= %d",
			       latest, call->acks_latest);
			goto discard;
		}
		call->acks_latest = latest;

		if (call->state != RXRPC_CALL_CLIENT_SEND_REQUEST &&
		    call->state != RXRPC_CALL_CLIENT_AWAIT_REPLY &&
		    call->state != RXRPC_CALL_SERVER_SEND_REPLY &&
		    call->state != RXRPC_CALL_SERVER_AWAIT_ACK)
			goto discard;

		_debug("Tx=%d H=%u S=%d", tx, call->acks_hard, call->state);

		if (hard > 0) {
			if (hard - 1 > tx) {
				_debug("hard-ACK'd packet %d not transmitted"
				       " (%d top)",
				       hard - 1, tx);
				goto protocol_error;
			}

			if ((call->state == RXRPC_CALL_CLIENT_AWAIT_REPLY ||
			     call->state == RXRPC_CALL_SERVER_AWAIT_ACK) &&
663 664
			    hard > tx) {
				call->acks_hard = tx;
665
				goto all_acked;
666
			}
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712

			smp_rmb();
			rxrpc_rotate_tx_window(call, hard - 1);
		}

		if (ack.nAcks > 0) {
			if (hard - 1 + ack.nAcks > tx) {
				_debug("soft-ACK'd packet %d+%d not"
				       " transmitted (%d top)",
				       hard - 1, ack.nAcks, tx);
				goto protocol_error;
			}

			if (rxrpc_process_soft_ACKs(call, &ack, skb) < 0)
				goto protocol_error;
		}
		goto discard;

		/* complete ACK to process */
	case RXRPC_PACKET_TYPE_ACKALL:
		goto all_acked;

		/* abort and busy are handled elsewhere */
	case RXRPC_PACKET_TYPE_BUSY:
	case RXRPC_PACKET_TYPE_ABORT:
		BUG();

		/* connection level events - also handled elsewhere */
	case RXRPC_PACKET_TYPE_CHALLENGE:
	case RXRPC_PACKET_TYPE_RESPONSE:
	case RXRPC_PACKET_TYPE_DEBUG:
		BUG();
	}

	/* if we've had a hard ACK that covers all the packets we've sent, then
	 * that ends that phase of the operation */
all_acked:
	write_lock_bh(&call->state_lock);
	_debug("ack all %d", call->state);

	switch (call->state) {
	case RXRPC_CALL_CLIENT_AWAIT_REPLY:
		call->state = RXRPC_CALL_CLIENT_RECV_REPLY;
		break;
	case RXRPC_CALL_SERVER_AWAIT_ACK:
		_debug("srv complete");
713
		__rxrpc_call_completed(call);
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732
		post_ACK = true;
		break;
	case RXRPC_CALL_CLIENT_SEND_REQUEST:
	case RXRPC_CALL_SERVER_RECV_REQUEST:
		goto protocol_error_unlock; /* can't occur yet */
	default:
		write_unlock_bh(&call->state_lock);
		goto discard; /* assume packet left over from earlier phase */
	}

	write_unlock_bh(&call->state_lock);

	/* if all the packets we sent are hard-ACK'd, then we can discard
	 * whatever we've got left */
	_debug("clear Tx %d",
	       CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));

	del_timer_sync(&call->resend_timer);
	clear_bit(RXRPC_CALL_RUN_RTIMER, &call->flags);
733
	clear_bit(RXRPC_CALL_EV_RESEND_TIMER, &call->events);
734 735 736 737 738 739 740 741 742

	if (call->acks_window)
		rxrpc_zap_tx_window(call);

	if (post_ACK) {
		/* post the final ACK message for userspace to pick up */
		_debug("post ACK");
		skb->mark = RXRPC_SKB_MARK_FINAL_ACK;
		sp->call = call;
D
David Howells 已提交
743
		rxrpc_get_call_for_skb(call, skb);
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801
		spin_lock_bh(&call->lock);
		if (rxrpc_queue_rcv_skb(call, skb, true, true) < 0)
			BUG();
		spin_unlock_bh(&call->lock);
		goto process_further;
	}

discard:
	rxrpc_free_skb(skb);
	goto process_further;

protocol_error_unlock:
	write_unlock_bh(&call->state_lock);
protocol_error:
	rxrpc_free_skb(skb);
	_leave(" = -EPROTO");
	return -EPROTO;
}

/*
 * post a message to the socket Rx queue for recvmsg() to pick up
 */
static int rxrpc_post_message(struct rxrpc_call *call, u32 mark, u32 error,
			      bool fatal)
{
	struct rxrpc_skb_priv *sp;
	struct sk_buff *skb;
	int ret;

	_enter("{%d,%lx},%u,%u,%d",
	       call->debug_id, call->flags, mark, error, fatal);

	/* remove timers and things for fatal messages */
	if (fatal) {
		del_timer_sync(&call->resend_timer);
		del_timer_sync(&call->ack_timer);
		clear_bit(RXRPC_CALL_RUN_RTIMER, &call->flags);
	}

	if (mark != RXRPC_SKB_MARK_NEW_CALL &&
	    !test_bit(RXRPC_CALL_HAS_USERID, &call->flags)) {
		_leave("[no userid]");
		return 0;
	}

	if (!test_bit(RXRPC_CALL_TERMINAL_MSG, &call->flags)) {
		skb = alloc_skb(0, GFP_NOFS);
		if (!skb)
			return -ENOMEM;

		rxrpc_new_skb(skb);

		skb->mark = mark;

		sp = rxrpc_skb(skb);
		memset(sp, 0, sizeof(*sp));
		sp->error = error;
		sp->call = call;
D
David Howells 已提交
802
		rxrpc_get_call_for_skb(call, skb);
803 804 805 806

		spin_lock_bh(&call->lock);
		ret = rxrpc_queue_rcv_skb(call, skb, true, fatal);
		spin_unlock_bh(&call->lock);
J
Julia Lawall 已提交
807
		BUG_ON(ret < 0);
808 809 810 811 812 813 814 815 816 817 818 819 820
	}

	return 0;
}

/*
 * handle background processing of incoming call packets and ACK / abort
 * generation
 */
void rxrpc_process_call(struct work_struct *work)
{
	struct rxrpc_call *call =
		container_of(work, struct rxrpc_call, processor);
821
	struct rxrpc_wire_header whdr;
822 823 824 825
	struct rxrpc_ackpacket ack;
	struct rxrpc_ackinfo ackinfo;
	struct msghdr msg;
	struct kvec iov[5];
826
	enum rxrpc_call_event genbit;
827
	unsigned long bits;
828
	__be32 data, pad;
829
	size_t len;
830
	int loop, nbit, ioc, ret, mtu;
831
	u32 serial, abort_code = RX_PROTOCOL_ERROR;
832 833
	u8 *acks = NULL;

D
David Howells 已提交
834 835
	rxrpc_see_call(call);

836 837 838 839 840
	//printk("\n--------------------\n");
	_enter("{%d,%s,%lx} [%lu]",
	       call->debug_id, rxrpc_call_states[call->state], call->events,
	       (jiffies - call->creation_jif) / (HZ / 10));

841 842 843
	if (!call->conn)
		goto skip_msg_init;

844 845
	/* there's a good chance we're going to have to send a message, so set
	 * one up in advance */
846 847
	msg.msg_name	= &call->conn->params.peer->srx.transport;
	msg.msg_namelen	= call->conn->params.peer->srx.transport_len;
848 849 850 851
	msg.msg_control	= NULL;
	msg.msg_controllen = 0;
	msg.msg_flags	= 0;

852
	whdr.epoch	= htonl(call->conn->proto.epoch);
853 854 855 856 857 858 859 860 861
	whdr.cid	= htonl(call->cid);
	whdr.callNumber	= htonl(call->call_id);
	whdr.seq	= 0;
	whdr.type	= RXRPC_PACKET_TYPE_ACK;
	whdr.flags	= call->conn->out_clientflag;
	whdr.userStatus	= 0;
	whdr.securityIndex = call->conn->security_ix;
	whdr._rsvd	= 0;
	whdr.serviceId	= htons(call->service_id);
862 863

	memset(iov, 0, sizeof(iov));
864 865
	iov[0].iov_base	= &whdr;
	iov[0].iov_len	= sizeof(whdr);
866
skip_msg_init:
867 868

	/* deal with events of a final nature */
869
	if (test_bit(RXRPC_CALL_EV_RCVD_ERROR, &call->events)) {
870
		enum rxrpc_skb_mark mark;
871 872
		int error;

873 874 875
		clear_bit(RXRPC_CALL_EV_CONN_ABORT, &call->events);
		clear_bit(RXRPC_CALL_EV_REJECT_BUSY, &call->events);
		clear_bit(RXRPC_CALL_EV_ABORT, &call->events);
876

877
		if (call->completion == RXRPC_CALL_NETWORK_ERROR) {
878 879 880 881 882 883
			mark = RXRPC_SKB_MARK_NET_ERROR;
			_debug("post net error %d", error);
		} else {
			mark = RXRPC_SKB_MARK_LOCAL_ERROR;
			_debug("post net local error %d", error);
		}
884

885
		if (rxrpc_post_message(call, mark, call->error, true) < 0)
886
			goto no_mem;
887
		clear_bit(RXRPC_CALL_EV_RCVD_ERROR, &call->events);
888 889 890
		goto kill_ACKs;
	}

891
	if (test_bit(RXRPC_CALL_EV_CONN_ABORT, &call->events)) {
892
		ASSERTCMP(call->state, ==, RXRPC_CALL_COMPLETE);
893

894 895
		clear_bit(RXRPC_CALL_EV_REJECT_BUSY, &call->events);
		clear_bit(RXRPC_CALL_EV_ABORT, &call->events);
896 897 898 899

		_debug("post conn abort");

		if (rxrpc_post_message(call, RXRPC_SKB_MARK_LOCAL_ERROR,
900
				       call->error, true) < 0)
901
			goto no_mem;
902
		clear_bit(RXRPC_CALL_EV_CONN_ABORT, &call->events);
903 904 905
		goto kill_ACKs;
	}

906
	if (test_bit(RXRPC_CALL_EV_REJECT_BUSY, &call->events)) {
907
		whdr.type = RXRPC_PACKET_TYPE_BUSY;
908
		genbit = RXRPC_CALL_EV_REJECT_BUSY;
909 910 911
		goto send_message;
	}

912
	if (test_bit(RXRPC_CALL_EV_ABORT, &call->events)) {
913
		ASSERTCMP(call->state, ==, RXRPC_CALL_COMPLETE);
914 915

		if (rxrpc_post_message(call, RXRPC_SKB_MARK_LOCAL_ERROR,
916
				       call->error, true) < 0)
917
			goto no_mem;
918
		whdr.type = RXRPC_PACKET_TYPE_ABORT;
919
		data = htonl(call->abort_code);
920 921
		iov[1].iov_base = &data;
		iov[1].iov_len = sizeof(data);
922
		genbit = RXRPC_CALL_EV_ABORT;
923 924 925
		goto send_message;
	}

926 927
	if (test_bit(RXRPC_CALL_EV_ACK_FINAL, &call->events)) {
		genbit = RXRPC_CALL_EV_ACK_FINAL;
928 929 930 931 932 933 934 935 936

		ack.bufferSpace	= htons(8);
		ack.maxSkew	= 0;
		ack.serial	= 0;
		ack.reason	= RXRPC_ACK_IDLE;
		ack.nAcks	= 0;
		call->ackr_reason = 0;

		spin_lock_bh(&call->lock);
937 938 939
		ack.serial	= htonl(call->ackr_serial);
		ack.previousPacket = htonl(call->ackr_prev_seq);
		ack.firstPacket	= htonl(call->rx_data_eaten + 1);
940 941 942 943 944 945 946 947 948 949 950
		spin_unlock_bh(&call->lock);

		pad = 0;

		iov[1].iov_base = &ack;
		iov[1].iov_len	= sizeof(ack);
		iov[2].iov_base = &pad;
		iov[2].iov_len	= 3;
		iov[3].iov_base = &ackinfo;
		iov[3].iov_len	= sizeof(ackinfo);
		goto send_ACK;
951 952
	}

953 954
	if (call->events & ((1 << RXRPC_CALL_EV_RCVD_BUSY) |
			    (1 << RXRPC_CALL_EV_RCVD_ABORT))
955 956 957
	    ) {
		u32 mark;

958
		if (test_bit(RXRPC_CALL_EV_RCVD_ABORT, &call->events))
959 960 961 962 963 964 965 966 967
			mark = RXRPC_SKB_MARK_REMOTE_ABORT;
		else
			mark = RXRPC_SKB_MARK_BUSY;

		_debug("post abort/busy");
		rxrpc_clear_tx_window(call);
		if (rxrpc_post_message(call, mark, ECONNABORTED, true) < 0)
			goto no_mem;

968 969
		clear_bit(RXRPC_CALL_EV_RCVD_BUSY, &call->events);
		clear_bit(RXRPC_CALL_EV_RCVD_ABORT, &call->events);
970 971 972
		goto kill_ACKs;
	}

973
	if (test_and_clear_bit(RXRPC_CALL_EV_RCVD_ACKALL, &call->events)) {
974 975 976 977
		_debug("do implicit ackall");
		rxrpc_clear_tx_window(call);
	}

978
	if (test_bit(RXRPC_CALL_EV_LIFE_TIMER, &call->events)) {
979
		rxrpc_abort_call(call, RX_CALL_TIMEOUT, ETIME);
980 981 982 983 984 985

		_debug("post timeout");
		if (rxrpc_post_message(call, RXRPC_SKB_MARK_LOCAL_ERROR,
				       ETIME, true) < 0)
			goto no_mem;

986
		clear_bit(RXRPC_CALL_EV_LIFE_TIMER, &call->events);
987 988 989 990 991
		goto kill_ACKs;
	}

	/* deal with assorted inbound messages */
	if (!skb_queue_empty(&call->rx_queue)) {
992 993
		ret = rxrpc_process_rx_queue(call, &abort_code);
		switch (ret) {
994 995 996 997 998 999 1000 1001
		case 0:
		case -EAGAIN:
			break;
		case -ENOMEM:
			goto no_mem;
		case -EKEYEXPIRED:
		case -EKEYREJECTED:
		case -EPROTO:
1002
			rxrpc_abort_call(call, abort_code, -ret);
1003 1004 1005 1006 1007
			goto kill_ACKs;
		}
	}

	/* handle resending */
1008
	if (test_and_clear_bit(RXRPC_CALL_EV_RESEND_TIMER, &call->events))
1009
		rxrpc_resend_timer(call);
1010
	if (test_and_clear_bit(RXRPC_CALL_EV_RESEND, &call->events))
1011 1012 1013
		rxrpc_resend(call);

	/* consider sending an ordinary ACK */
1014
	if (test_bit(RXRPC_CALL_EV_ACK, &call->events)) {
1015 1016 1017 1018 1019 1020 1021
		_debug("send ACK: window: %d - %d { %lx }",
		       call->rx_data_eaten, call->ackr_win_top,
		       call->ackr_window[0]);

		if (call->state > RXRPC_CALL_SERVER_ACK_REQUEST &&
		    call->ackr_reason != RXRPC_ACK_PING_RESPONSE) {
			/* ACK by sending reply DATA packet in this state */
1022
			clear_bit(RXRPC_CALL_EV_ACK, &call->events);
1023 1024 1025
			goto maybe_reschedule;
		}

1026
		genbit = RXRPC_CALL_EV_ACK;
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037

		acks = kzalloc(call->ackr_win_top - call->rx_data_eaten,
			       GFP_NOFS);
		if (!acks)
			goto no_mem;

		//hdr.flags	= RXRPC_SLOW_START_OK;
		ack.bufferSpace	= htons(8);
		ack.maxSkew	= 0;

		spin_lock_bh(&call->lock);
1038 1039 1040
		ack.reason	= call->ackr_reason;
		ack.serial	= htonl(call->ackr_serial);
		ack.previousPacket = htonl(call->ackr_prev_seq);
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
		ack.firstPacket = htonl(call->rx_data_eaten + 1);

		ack.nAcks = 0;
		for (loop = 0; loop < RXRPC_ACKR_WINDOW_ASZ; loop++) {
			nbit = loop * BITS_PER_LONG;
			for (bits = call->ackr_window[loop]; bits; bits >>= 1
			     ) {
				_debug("- l=%d n=%d b=%lx", loop, nbit, bits);
				if (bits & 1) {
					acks[nbit] = RXRPC_ACK_TYPE_ACK;
					ack.nAcks = nbit + 1;
				}
				nbit++;
			}
		}
		call->ackr_reason = 0;
		spin_unlock_bh(&call->lock);

		pad = 0;

		iov[1].iov_base = &ack;
		iov[1].iov_len	= sizeof(ack);
		iov[2].iov_base = acks;
		iov[2].iov_len	= ack.nAcks;
		iov[3].iov_base = &pad;
		iov[3].iov_len	= 3;
		iov[4].iov_base = &ackinfo;
		iov[4].iov_len	= sizeof(ackinfo);

		switch (ack.reason) {
		case RXRPC_ACK_REQUESTED:
		case RXRPC_ACK_DUPLICATE:
		case RXRPC_ACK_OUT_OF_SEQUENCE:
		case RXRPC_ACK_EXCEEDS_WINDOW:
		case RXRPC_ACK_NOSPACE:
		case RXRPC_ACK_PING:
		case RXRPC_ACK_PING_RESPONSE:
			goto send_ACK_with_skew;
		case RXRPC_ACK_DELAY:
		case RXRPC_ACK_IDLE:
			goto send_ACK;
		}
	}

	/* handle completion of security negotiations on an incoming
	 * connection */
1087
	if (test_and_clear_bit(RXRPC_CALL_EV_SECURED, &call->events)) {
1088 1089 1090 1091 1092
		_debug("secured");
		spin_lock_bh(&call->lock);

		if (call->state == RXRPC_CALL_SERVER_SECURING) {
			_debug("securing");
1093
			write_lock(&call->socket->call_lock);
1094
			if (!test_bit(RXRPC_CALL_RELEASED, &call->flags) &&
1095
			    !test_bit(RXRPC_CALL_EV_RELEASE, &call->events)) {
1096 1097 1098 1099 1100
				_debug("not released");
				call->state = RXRPC_CALL_SERVER_ACCEPTING;
				list_move_tail(&call->accept_link,
					       &call->socket->acceptq);
			}
1101
			write_unlock(&call->socket->call_lock);
1102 1103
			read_lock(&call->state_lock);
			if (call->state < RXRPC_CALL_COMPLETE)
1104
				set_bit(RXRPC_CALL_EV_POST_ACCEPT, &call->events);
1105 1106 1107 1108
			read_unlock(&call->state_lock);
		}

		spin_unlock_bh(&call->lock);
1109
		if (!test_bit(RXRPC_CALL_EV_POST_ACCEPT, &call->events))
1110 1111 1112 1113
			goto maybe_reschedule;
	}

	/* post a notification of an acceptable connection to the app */
1114
	if (test_bit(RXRPC_CALL_EV_POST_ACCEPT, &call->events)) {
1115 1116 1117 1118
		_debug("post accept");
		if (rxrpc_post_message(call, RXRPC_SKB_MARK_NEW_CALL,
				       0, false) < 0)
			goto no_mem;
1119
		clear_bit(RXRPC_CALL_EV_POST_ACCEPT, &call->events);
1120 1121 1122 1123
		goto maybe_reschedule;
	}

	/* handle incoming call acceptance */
1124
	if (test_and_clear_bit(RXRPC_CALL_EV_ACCEPTED, &call->events)) {
1125 1126 1127 1128 1129
		_debug("accepted");
		ASSERTCMP(call->rx_data_post, ==, 0);
		call->rx_data_post = 1;
		read_lock_bh(&call->state_lock);
		if (call->state < RXRPC_CALL_COMPLETE)
1130
			set_bit(RXRPC_CALL_EV_DRAIN_RX_OOS, &call->events);
1131 1132 1133 1134 1135
		read_unlock_bh(&call->state_lock);
	}

	/* drain the out of sequence received packet queue into the packet Rx
	 * queue */
1136
	if (test_and_clear_bit(RXRPC_CALL_EV_DRAIN_RX_OOS, &call->events)) {
1137 1138 1139 1140 1141 1142
		while (call->rx_data_post == call->rx_first_oos)
			if (rxrpc_drain_rx_oos_queue(call) < 0)
				break;
		goto maybe_reschedule;
	}

1143 1144 1145 1146 1147
	if (test_bit(RXRPC_CALL_EV_RELEASE, &call->events)) {
		rxrpc_release_call(call);
		clear_bit(RXRPC_CALL_EV_RELEASE, &call->events);
	}

1148 1149 1150 1151
	/* other events may have been raised since we started checking */
	goto maybe_reschedule;

send_ACK_with_skew:
1152
	ack.maxSkew = htons(call->ackr_skew);
1153
send_ACK:
1154 1155
	mtu = call->conn->params.peer->if_mtu;
	mtu -= call->conn->params.peer->hdrsize;
1156
	ackinfo.maxMTU	= htonl(mtu);
1157
	ackinfo.rwind	= htonl(rxrpc_rx_window_size);
1158 1159

	/* permit the peer to send us jumbo packets if it wants to */
1160 1161
	ackinfo.rxMTU	= htonl(rxrpc_rx_mtu);
	ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
1162

1163 1164
	serial = atomic_inc_return(&call->conn->serial);
	whdr.serial = htonl(serial);
1165
	_proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
1166
	       serial,
1167 1168 1169 1170
	       ntohs(ack.maxSkew),
	       ntohl(ack.firstPacket),
	       ntohl(ack.previousPacket),
	       ntohl(ack.serial),
1171
	       rxrpc_acks(ack.reason),
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181
	       ack.nAcks);

	del_timer_sync(&call->ack_timer);
	if (ack.nAcks > 0)
		set_bit(RXRPC_CALL_TX_SOFT_ACK, &call->flags);
	goto send_message_2;

send_message:
	_debug("send message");

1182 1183 1184
	serial = atomic_inc_return(&call->conn->serial);
	whdr.serial = htonl(serial);
	_proto("Tx %s %%%u", rxrpc_pkts[whdr.type], serial);
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
send_message_2:

	len = iov[0].iov_len;
	ioc = 1;
	if (iov[4].iov_len) {
		ioc = 5;
		len += iov[4].iov_len;
		len += iov[3].iov_len;
		len += iov[2].iov_len;
		len += iov[1].iov_len;
	} else if (iov[3].iov_len) {
		ioc = 4;
		len += iov[3].iov_len;
		len += iov[2].iov_len;
		len += iov[1].iov_len;
	} else if (iov[2].iov_len) {
		ioc = 3;
		len += iov[2].iov_len;
		len += iov[1].iov_len;
	} else if (iov[1].iov_len) {
		ioc = 2;
		len += iov[1].iov_len;
	}

1209
	ret = kernel_sendmsg(call->conn->params.local->socket,
1210 1211 1212 1213 1214
			     &msg, iov, ioc, len);
	if (ret < 0) {
		_debug("sendmsg failed: %d", ret);
		read_lock_bh(&call->state_lock);
		if (call->state < RXRPC_CALL_DEAD)
1215
			rxrpc_queue_call(call);
1216 1217 1218 1219 1220
		read_unlock_bh(&call->state_lock);
		goto error;
	}

	switch (genbit) {
1221
	case RXRPC_CALL_EV_ABORT:
1222
		clear_bit(genbit, &call->events);
1223
		clear_bit(RXRPC_CALL_EV_RCVD_ABORT, &call->events);
1224 1225
		goto kill_ACKs;

1226
	case RXRPC_CALL_EV_ACK_FINAL:
1227
		rxrpc_call_completed(call);
1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238
		goto kill_ACKs;

	default:
		clear_bit(genbit, &call->events);
		switch (call->state) {
		case RXRPC_CALL_CLIENT_AWAIT_REPLY:
		case RXRPC_CALL_CLIENT_RECV_REPLY:
		case RXRPC_CALL_SERVER_RECV_REQUEST:
		case RXRPC_CALL_SERVER_ACK_REQUEST:
			_debug("start ACK timer");
			rxrpc_propose_ACK(call, RXRPC_ACK_DELAY,
1239 1240
					  call->ackr_skew, call->ackr_serial,
					  false);
1241 1242 1243 1244 1245 1246 1247 1248
		default:
			break;
		}
		goto maybe_reschedule;
	}

kill_ACKs:
	del_timer_sync(&call->ack_timer);
1249
	if (test_and_clear_bit(RXRPC_CALL_EV_ACK_FINAL, &call->events))
1250
		rxrpc_put_call(call);
1251
	clear_bit(RXRPC_CALL_EV_ACK, &call->events);
1252 1253 1254 1255 1256

maybe_reschedule:
	if (call->events || !skb_queue_empty(&call->rx_queue)) {
		read_lock_bh(&call->state_lock);
		if (call->state < RXRPC_CALL_DEAD)
1257
			rxrpc_queue_call(call);
1258 1259 1260 1261 1262 1263 1264
		read_unlock_bh(&call->state_lock);
	}

	/* don't leave aborted connections on the accept queue */
	if (call->state >= RXRPC_CALL_COMPLETE &&
	    !list_empty(&call->accept_link)) {
		_debug("X unlinking once-pending call %p { e=%lx f=%lx c=%x }",
1265
		       call, call->events, call->flags, call->conn->proto.cid);
1266 1267 1268

		read_lock_bh(&call->state_lock);
		if (!test_bit(RXRPC_CALL_RELEASED, &call->flags) &&
1269
		    !test_and_set_bit(RXRPC_CALL_EV_RELEASE, &call->events))
1270
			rxrpc_queue_call(call);
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
		read_unlock_bh(&call->state_lock);
	}

error:
	kfree(acks);

	/* because we don't want two CPUs both processing the work item for one
	 * call at the same time, we use a flag to note when it's busy; however
	 * this means there's a race between clearing the flag and setting the
	 * work pending bit and the work item being processed again */
	if (call->events && !work_pending(&call->processor)) {
1282
		_debug("jumpstart %x", call->conn->proto.cid);
1283
		rxrpc_queue_call(call);
1284 1285 1286 1287 1288 1289 1290 1291 1292
	}

	_leave("");
	return;

no_mem:
	_debug("out of memory");
	goto maybe_reschedule;
}