ar-ack.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  1. /* Management of Tx window, Tx resend, ACKs and out-of-sequence reception
  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. #include <linux/module.h>
  12. #include <linux/circ_buf.h>
  13. #include <linux/net.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/udp.h>
  16. #include <net/sock.h>
  17. #include <net/af_rxrpc.h>
  18. #include "ar-internal.h"
  19. static unsigned rxrpc_ack_defer = 1;
  20. static const char *rxrpc_acks[] = {
  21. "---", "REQ", "DUP", "OOS", "WIN", "MEM", "PNG", "PNR", "DLY", "IDL",
  22. "-?-"
  23. };
  24. static const s8 rxrpc_ack_priority[] = {
  25. [0] = 0,
  26. [RXRPC_ACK_DELAY] = 1,
  27. [RXRPC_ACK_REQUESTED] = 2,
  28. [RXRPC_ACK_IDLE] = 3,
  29. [RXRPC_ACK_PING_RESPONSE] = 4,
  30. [RXRPC_ACK_DUPLICATE] = 5,
  31. [RXRPC_ACK_OUT_OF_SEQUENCE] = 6,
  32. [RXRPC_ACK_EXCEEDS_WINDOW] = 7,
  33. [RXRPC_ACK_NOSPACE] = 8,
  34. };
  35. /*
  36. * propose an ACK be sent
  37. */
  38. void __rxrpc_propose_ACK(struct rxrpc_call *call, uint8_t ack_reason,
  39. __be32 serial, bool immediate)
  40. {
  41. unsigned long expiry;
  42. s8 prior = rxrpc_ack_priority[ack_reason];
  43. ASSERTCMP(prior, >, 0);
  44. _enter("{%d},%s,%%%x,%u",
  45. call->debug_id, rxrpc_acks[ack_reason], ntohl(serial),
  46. immediate);
  47. if (prior < rxrpc_ack_priority[call->ackr_reason]) {
  48. if (immediate)
  49. goto cancel_timer;
  50. return;
  51. }
  52. /* update DELAY, IDLE, REQUESTED and PING_RESPONSE ACK serial
  53. * numbers */
  54. if (prior == rxrpc_ack_priority[call->ackr_reason]) {
  55. if (prior <= 4)
  56. call->ackr_serial = serial;
  57. if (immediate)
  58. goto cancel_timer;
  59. return;
  60. }
  61. call->ackr_reason = ack_reason;
  62. call->ackr_serial = serial;
  63. switch (ack_reason) {
  64. case RXRPC_ACK_DELAY:
  65. _debug("run delay timer");
  66. call->ack_timer.expires = jiffies + rxrpc_ack_timeout * HZ;
  67. add_timer(&call->ack_timer);
  68. return;
  69. case RXRPC_ACK_IDLE:
  70. if (!immediate) {
  71. _debug("run defer timer");
  72. expiry = 1;
  73. goto run_timer;
  74. }
  75. goto cancel_timer;
  76. case RXRPC_ACK_REQUESTED:
  77. if (!rxrpc_ack_defer)
  78. goto cancel_timer;
  79. if (!immediate || serial == cpu_to_be32(1)) {
  80. _debug("run defer timer");
  81. expiry = rxrpc_ack_defer;
  82. goto run_timer;
  83. }
  84. default:
  85. _debug("immediate ACK");
  86. goto cancel_timer;
  87. }
  88. run_timer:
  89. expiry += jiffies;
  90. if (!timer_pending(&call->ack_timer) ||
  91. time_after(call->ack_timer.expires, expiry))
  92. mod_timer(&call->ack_timer, expiry);
  93. return;
  94. cancel_timer:
  95. _debug("cancel timer %%%u", ntohl(serial));
  96. try_to_del_timer_sync(&call->ack_timer);
  97. read_lock_bh(&call->state_lock);
  98. if (call->state <= RXRPC_CALL_COMPLETE &&
  99. !test_and_set_bit(RXRPC_CALL_ACK, &call->events))
  100. rxrpc_queue_call(call);
  101. read_unlock_bh(&call->state_lock);
  102. }
  103. /*
  104. * propose an ACK be sent, locking the call structure
  105. */
  106. void rxrpc_propose_ACK(struct rxrpc_call *call, uint8_t ack_reason,
  107. __be32 serial, bool immediate)
  108. {
  109. s8 prior = rxrpc_ack_priority[ack_reason];
  110. if (prior > rxrpc_ack_priority[call->ackr_reason]) {
  111. spin_lock_bh(&call->lock);
  112. __rxrpc_propose_ACK(call, ack_reason, serial, immediate);
  113. spin_unlock_bh(&call->lock);
  114. }
  115. }
  116. /*
  117. * set the resend timer
  118. */
  119. static void rxrpc_set_resend(struct rxrpc_call *call, u8 resend,
  120. unsigned long resend_at)
  121. {
  122. read_lock_bh(&call->state_lock);
  123. if (call->state >= RXRPC_CALL_COMPLETE)
  124. resend = 0;
  125. if (resend & 1) {
  126. _debug("SET RESEND");
  127. set_bit(RXRPC_CALL_RESEND, &call->events);
  128. }
  129. if (resend & 2) {
  130. _debug("MODIFY RESEND TIMER");
  131. set_bit(RXRPC_CALL_RUN_RTIMER, &call->flags);
  132. mod_timer(&call->resend_timer, resend_at);
  133. } else {
  134. _debug("KILL RESEND TIMER");
  135. del_timer_sync(&call->resend_timer);
  136. clear_bit(RXRPC_CALL_RESEND_TIMER, &call->events);
  137. clear_bit(RXRPC_CALL_RUN_RTIMER, &call->flags);
  138. }
  139. read_unlock_bh(&call->state_lock);
  140. }
  141. /*
  142. * resend packets
  143. */
  144. static void rxrpc_resend(struct rxrpc_call *call)
  145. {
  146. struct rxrpc_skb_priv *sp;
  147. struct rxrpc_header *hdr;
  148. struct sk_buff *txb;
  149. unsigned long *p_txb, resend_at;
  150. int loop, stop;
  151. u8 resend;
  152. _enter("{%d,%d,%d,%d},",
  153. call->acks_hard, call->acks_unacked,
  154. atomic_read(&call->sequence),
  155. CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
  156. stop = 0;
  157. resend = 0;
  158. resend_at = 0;
  159. for (loop = call->acks_tail;
  160. loop != call->acks_head || stop;
  161. loop = (loop + 1) & (call->acks_winsz - 1)
  162. ) {
  163. p_txb = call->acks_window + loop;
  164. smp_read_barrier_depends();
  165. if (*p_txb & 1)
  166. continue;
  167. txb = (struct sk_buff *) *p_txb;
  168. sp = rxrpc_skb(txb);
  169. if (sp->need_resend) {
  170. sp->need_resend = 0;
  171. /* each Tx packet has a new serial number */
  172. sp->hdr.serial =
  173. htonl(atomic_inc_return(&call->conn->serial));
  174. hdr = (struct rxrpc_header *) txb->head;
  175. hdr->serial = sp->hdr.serial;
  176. _proto("Tx DATA %%%u { #%d }",
  177. ntohl(sp->hdr.serial), ntohl(sp->hdr.seq));
  178. if (rxrpc_send_packet(call->conn->trans, txb) < 0) {
  179. stop = 0;
  180. sp->resend_at = jiffies + 3;
  181. } else {
  182. sp->resend_at =
  183. jiffies + rxrpc_resend_timeout * HZ;
  184. }
  185. }
  186. if (time_after_eq(jiffies + 1, sp->resend_at)) {
  187. sp->need_resend = 1;
  188. resend |= 1;
  189. } else if (resend & 2) {
  190. if (time_before(sp->resend_at, resend_at))
  191. resend_at = sp->resend_at;
  192. } else {
  193. resend_at = sp->resend_at;
  194. resend |= 2;
  195. }
  196. }
  197. rxrpc_set_resend(call, resend, resend_at);
  198. _leave("");
  199. }
  200. /*
  201. * handle resend timer expiry
  202. */
  203. static void rxrpc_resend_timer(struct rxrpc_call *call)
  204. {
  205. struct rxrpc_skb_priv *sp;
  206. struct sk_buff *txb;
  207. unsigned long *p_txb, resend_at;
  208. int loop;
  209. u8 resend;
  210. _enter("%d,%d,%d",
  211. call->acks_tail, call->acks_unacked, call->acks_head);
  212. resend = 0;
  213. resend_at = 0;
  214. for (loop = call->acks_unacked;
  215. loop != call->acks_head;
  216. loop = (loop + 1) & (call->acks_winsz - 1)
  217. ) {
  218. p_txb = call->acks_window + loop;
  219. smp_read_barrier_depends();
  220. txb = (struct sk_buff *) (*p_txb & ~1);
  221. sp = rxrpc_skb(txb);
  222. ASSERT(!(*p_txb & 1));
  223. if (sp->need_resend) {
  224. ;
  225. } else if (time_after_eq(jiffies + 1, sp->resend_at)) {
  226. sp->need_resend = 1;
  227. resend |= 1;
  228. } else if (resend & 2) {
  229. if (time_before(sp->resend_at, resend_at))
  230. resend_at = sp->resend_at;
  231. } else {
  232. resend_at = sp->resend_at;
  233. resend |= 2;
  234. }
  235. }
  236. rxrpc_set_resend(call, resend, resend_at);
  237. _leave("");
  238. }
  239. /*
  240. * process soft ACKs of our transmitted packets
  241. * - these indicate packets the peer has or has not received, but hasn't yet
  242. * given to the consumer, and so can still be discarded and re-requested
  243. */
  244. static int rxrpc_process_soft_ACKs(struct rxrpc_call *call,
  245. struct rxrpc_ackpacket *ack,
  246. struct sk_buff *skb)
  247. {
  248. struct rxrpc_skb_priv *sp;
  249. struct sk_buff *txb;
  250. unsigned long *p_txb, resend_at;
  251. int loop;
  252. u8 sacks[RXRPC_MAXACKS], resend;
  253. _enter("{%d,%d},{%d},",
  254. call->acks_hard,
  255. CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz),
  256. ack->nAcks);
  257. if (skb_copy_bits(skb, 0, sacks, ack->nAcks) < 0)
  258. goto protocol_error;
  259. resend = 0;
  260. resend_at = 0;
  261. for (loop = 0; loop < ack->nAcks; loop++) {
  262. p_txb = call->acks_window;
  263. p_txb += (call->acks_tail + loop) & (call->acks_winsz - 1);
  264. smp_read_barrier_depends();
  265. txb = (struct sk_buff *) (*p_txb & ~1);
  266. sp = rxrpc_skb(txb);
  267. switch (sacks[loop]) {
  268. case RXRPC_ACK_TYPE_ACK:
  269. sp->need_resend = 0;
  270. *p_txb |= 1;
  271. break;
  272. case RXRPC_ACK_TYPE_NACK:
  273. sp->need_resend = 1;
  274. *p_txb &= ~1;
  275. resend = 1;
  276. break;
  277. default:
  278. _debug("Unsupported ACK type %d", sacks[loop]);
  279. goto protocol_error;
  280. }
  281. }
  282. smp_mb();
  283. call->acks_unacked = (call->acks_tail + loop) & (call->acks_winsz - 1);
  284. /* anything not explicitly ACK'd is implicitly NACK'd, but may just not
  285. * have been received or processed yet by the far end */
  286. for (loop = call->acks_unacked;
  287. loop != call->acks_head;
  288. loop = (loop + 1) & (call->acks_winsz - 1)
  289. ) {
  290. p_txb = call->acks_window + loop;
  291. smp_read_barrier_depends();
  292. txb = (struct sk_buff *) (*p_txb & ~1);
  293. sp = rxrpc_skb(txb);
  294. if (*p_txb & 1) {
  295. /* packet must have been discarded */
  296. sp->need_resend = 1;
  297. *p_txb &= ~1;
  298. resend |= 1;
  299. } else if (sp->need_resend) {
  300. ;
  301. } else if (time_after_eq(jiffies + 1, sp->resend_at)) {
  302. sp->need_resend = 1;
  303. resend |= 1;
  304. } else if (resend & 2) {
  305. if (time_before(sp->resend_at, resend_at))
  306. resend_at = sp->resend_at;
  307. } else {
  308. resend_at = sp->resend_at;
  309. resend |= 2;
  310. }
  311. }
  312. rxrpc_set_resend(call, resend, resend_at);
  313. _leave(" = 0");
  314. return 0;
  315. protocol_error:
  316. _leave(" = -EPROTO");
  317. return -EPROTO;
  318. }
  319. /*
  320. * discard hard-ACK'd packets from the Tx window
  321. */
  322. static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
  323. {
  324. struct rxrpc_skb_priv *sp;
  325. unsigned long _skb;
  326. int tail = call->acks_tail, old_tail;
  327. int win = CIRC_CNT(call->acks_head, tail, call->acks_winsz);
  328. _enter("{%u,%u},%u", call->acks_hard, win, hard);
  329. ASSERTCMP(hard - call->acks_hard, <=, win);
  330. while (call->acks_hard < hard) {
  331. smp_read_barrier_depends();
  332. _skb = call->acks_window[tail] & ~1;
  333. sp = rxrpc_skb((struct sk_buff *) _skb);
  334. rxrpc_free_skb((struct sk_buff *) _skb);
  335. old_tail = tail;
  336. tail = (tail + 1) & (call->acks_winsz - 1);
  337. call->acks_tail = tail;
  338. if (call->acks_unacked == old_tail)
  339. call->acks_unacked = tail;
  340. call->acks_hard++;
  341. }
  342. wake_up(&call->tx_waitq);
  343. }
  344. /*
  345. * clear the Tx window in the event of a failure
  346. */
  347. static void rxrpc_clear_tx_window(struct rxrpc_call *call)
  348. {
  349. rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
  350. }
  351. /*
  352. * drain the out of sequence received packet queue into the packet Rx queue
  353. */
  354. static int rxrpc_drain_rx_oos_queue(struct rxrpc_call *call)
  355. {
  356. struct rxrpc_skb_priv *sp;
  357. struct sk_buff *skb;
  358. bool terminal;
  359. int ret;
  360. _enter("{%d,%d}", call->rx_data_post, call->rx_first_oos);
  361. spin_lock_bh(&call->lock);
  362. ret = -ECONNRESET;
  363. if (test_bit(RXRPC_CALL_RELEASED, &call->flags))
  364. goto socket_unavailable;
  365. skb = skb_dequeue(&call->rx_oos_queue);
  366. if (skb) {
  367. sp = rxrpc_skb(skb);
  368. _debug("drain OOS packet %d [%d]",
  369. ntohl(sp->hdr.seq), call->rx_first_oos);
  370. if (ntohl(sp->hdr.seq) != call->rx_first_oos) {
  371. skb_queue_head(&call->rx_oos_queue, skb);
  372. call->rx_first_oos = ntohl(rxrpc_skb(skb)->hdr.seq);
  373. _debug("requeue %p {%u}", skb, call->rx_first_oos);
  374. } else {
  375. skb->mark = RXRPC_SKB_MARK_DATA;
  376. terminal = ((sp->hdr.flags & RXRPC_LAST_PACKET) &&
  377. !(sp->hdr.flags & RXRPC_CLIENT_INITIATED));
  378. ret = rxrpc_queue_rcv_skb(call, skb, true, terminal);
  379. BUG_ON(ret < 0);
  380. _debug("drain #%u", call->rx_data_post);
  381. call->rx_data_post++;
  382. /* find out what the next packet is */
  383. skb = skb_peek(&call->rx_oos_queue);
  384. if (skb)
  385. call->rx_first_oos =
  386. ntohl(rxrpc_skb(skb)->hdr.seq);
  387. else
  388. call->rx_first_oos = 0;
  389. _debug("peek %p {%u}", skb, call->rx_first_oos);
  390. }
  391. }
  392. ret = 0;
  393. socket_unavailable:
  394. spin_unlock_bh(&call->lock);
  395. _leave(" = %d", ret);
  396. return ret;
  397. }
  398. /*
  399. * insert an out of sequence packet into the buffer
  400. */
  401. static void rxrpc_insert_oos_packet(struct rxrpc_call *call,
  402. struct sk_buff *skb)
  403. {
  404. struct rxrpc_skb_priv *sp, *psp;
  405. struct sk_buff *p;
  406. u32 seq;
  407. sp = rxrpc_skb(skb);
  408. seq = ntohl(sp->hdr.seq);
  409. _enter(",,{%u}", seq);
  410. skb->destructor = rxrpc_packet_destructor;
  411. ASSERTCMP(sp->call, ==, NULL);
  412. sp->call = call;
  413. rxrpc_get_call(call);
  414. /* insert into the buffer in sequence order */
  415. spin_lock_bh(&call->lock);
  416. skb_queue_walk(&call->rx_oos_queue, p) {
  417. psp = rxrpc_skb(p);
  418. if (ntohl(psp->hdr.seq) > seq) {
  419. _debug("insert oos #%u before #%u",
  420. seq, ntohl(psp->hdr.seq));
  421. skb_insert(p, skb, &call->rx_oos_queue);
  422. goto inserted;
  423. }
  424. }
  425. _debug("append oos #%u", seq);
  426. skb_queue_tail(&call->rx_oos_queue, skb);
  427. inserted:
  428. /* we might now have a new front to the queue */
  429. if (call->rx_first_oos == 0 || seq < call->rx_first_oos)
  430. call->rx_first_oos = seq;
  431. read_lock(&call->state_lock);
  432. if (call->state < RXRPC_CALL_COMPLETE &&
  433. call->rx_data_post == call->rx_first_oos) {
  434. _debug("drain rx oos now");
  435. set_bit(RXRPC_CALL_DRAIN_RX_OOS, &call->events);
  436. }
  437. read_unlock(&call->state_lock);
  438. spin_unlock_bh(&call->lock);
  439. _leave(" [stored #%u]", call->rx_first_oos);
  440. }
  441. /*
  442. * clear the Tx window on final ACK reception
  443. */
  444. static void rxrpc_zap_tx_window(struct rxrpc_call *call)
  445. {
  446. struct rxrpc_skb_priv *sp;
  447. struct sk_buff *skb;
  448. unsigned long _skb, *acks_window;
  449. uint8_t winsz = call->acks_winsz;
  450. int tail;
  451. acks_window = call->acks_window;
  452. call->acks_window = NULL;
  453. while (CIRC_CNT(call->acks_head, call->acks_tail, winsz) > 0) {
  454. tail = call->acks_tail;
  455. smp_read_barrier_depends();
  456. _skb = acks_window[tail] & ~1;
  457. smp_mb();
  458. call->acks_tail = (call->acks_tail + 1) & (winsz - 1);
  459. skb = (struct sk_buff *) _skb;
  460. sp = rxrpc_skb(skb);
  461. _debug("+++ clear Tx %u", ntohl(sp->hdr.seq));
  462. rxrpc_free_skb(skb);
  463. }
  464. kfree(acks_window);
  465. }
  466. /*
  467. * process packets in the reception queue
  468. */
  469. static int rxrpc_process_rx_queue(struct rxrpc_call *call,
  470. u32 *_abort_code)
  471. {
  472. struct rxrpc_ackpacket ack;
  473. struct rxrpc_skb_priv *sp;
  474. struct sk_buff *skb;
  475. bool post_ACK;
  476. int latest;
  477. u32 hard, tx;
  478. _enter("");
  479. process_further:
  480. skb = skb_dequeue(&call->rx_queue);
  481. if (!skb)
  482. return -EAGAIN;
  483. _net("deferred skb %p", skb);
  484. sp = rxrpc_skb(skb);
  485. _debug("process %s [st %d]", rxrpc_pkts[sp->hdr.type], call->state);
  486. post_ACK = false;
  487. switch (sp->hdr.type) {
  488. /* data packets that wind up here have been received out of
  489. * order, need security processing or are jumbo packets */
  490. case RXRPC_PACKET_TYPE_DATA:
  491. _proto("OOSQ DATA %%%u { #%u }",
  492. ntohl(sp->hdr.serial), ntohl(sp->hdr.seq));
  493. /* secured packets must be verified and possibly decrypted */
  494. if (rxrpc_verify_packet(call, skb, _abort_code) < 0)
  495. goto protocol_error;
  496. rxrpc_insert_oos_packet(call, skb);
  497. goto process_further;
  498. /* partial ACK to process */
  499. case RXRPC_PACKET_TYPE_ACK:
  500. if (skb_copy_bits(skb, 0, &ack, sizeof(ack)) < 0) {
  501. _debug("extraction failure");
  502. goto protocol_error;
  503. }
  504. if (!skb_pull(skb, sizeof(ack)))
  505. BUG();
  506. latest = ntohl(sp->hdr.serial);
  507. hard = ntohl(ack.firstPacket);
  508. tx = atomic_read(&call->sequence);
  509. _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
  510. latest,
  511. ntohs(ack.maxSkew),
  512. hard,
  513. ntohl(ack.previousPacket),
  514. ntohl(ack.serial),
  515. rxrpc_acks[ack.reason],
  516. ack.nAcks);
  517. if (ack.reason == RXRPC_ACK_PING) {
  518. _proto("Rx ACK %%%u PING Request", latest);
  519. rxrpc_propose_ACK(call, RXRPC_ACK_PING_RESPONSE,
  520. sp->hdr.serial, true);
  521. }
  522. /* discard any out-of-order or duplicate ACKs */
  523. if (latest - call->acks_latest <= 0) {
  524. _debug("discard ACK %d <= %d",
  525. latest, call->acks_latest);
  526. goto discard;
  527. }
  528. call->acks_latest = latest;
  529. if (call->state != RXRPC_CALL_CLIENT_SEND_REQUEST &&
  530. call->state != RXRPC_CALL_CLIENT_AWAIT_REPLY &&
  531. call->state != RXRPC_CALL_SERVER_SEND_REPLY &&
  532. call->state != RXRPC_CALL_SERVER_AWAIT_ACK)
  533. goto discard;
  534. _debug("Tx=%d H=%u S=%d", tx, call->acks_hard, call->state);
  535. if (hard > 0) {
  536. if (hard - 1 > tx) {
  537. _debug("hard-ACK'd packet %d not transmitted"
  538. " (%d top)",
  539. hard - 1, tx);
  540. goto protocol_error;
  541. }
  542. if ((call->state == RXRPC_CALL_CLIENT_AWAIT_REPLY ||
  543. call->state == RXRPC_CALL_SERVER_AWAIT_ACK) &&
  544. hard > tx)
  545. goto all_acked;
  546. smp_rmb();
  547. rxrpc_rotate_tx_window(call, hard - 1);
  548. }
  549. if (ack.nAcks > 0) {
  550. if (hard - 1 + ack.nAcks > tx) {
  551. _debug("soft-ACK'd packet %d+%d not"
  552. " transmitted (%d top)",
  553. hard - 1, ack.nAcks, tx);
  554. goto protocol_error;
  555. }
  556. if (rxrpc_process_soft_ACKs(call, &ack, skb) < 0)
  557. goto protocol_error;
  558. }
  559. goto discard;
  560. /* complete ACK to process */
  561. case RXRPC_PACKET_TYPE_ACKALL:
  562. goto all_acked;
  563. /* abort and busy are handled elsewhere */
  564. case RXRPC_PACKET_TYPE_BUSY:
  565. case RXRPC_PACKET_TYPE_ABORT:
  566. BUG();
  567. /* connection level events - also handled elsewhere */
  568. case RXRPC_PACKET_TYPE_CHALLENGE:
  569. case RXRPC_PACKET_TYPE_RESPONSE:
  570. case RXRPC_PACKET_TYPE_DEBUG:
  571. BUG();
  572. }
  573. /* if we've had a hard ACK that covers all the packets we've sent, then
  574. * that ends that phase of the operation */
  575. all_acked:
  576. write_lock_bh(&call->state_lock);
  577. _debug("ack all %d", call->state);
  578. switch (call->state) {
  579. case RXRPC_CALL_CLIENT_AWAIT_REPLY:
  580. call->state = RXRPC_CALL_CLIENT_RECV_REPLY;
  581. break;
  582. case RXRPC_CALL_SERVER_AWAIT_ACK:
  583. _debug("srv complete");
  584. call->state = RXRPC_CALL_COMPLETE;
  585. post_ACK = true;
  586. break;
  587. case RXRPC_CALL_CLIENT_SEND_REQUEST:
  588. case RXRPC_CALL_SERVER_RECV_REQUEST:
  589. goto protocol_error_unlock; /* can't occur yet */
  590. default:
  591. write_unlock_bh(&call->state_lock);
  592. goto discard; /* assume packet left over from earlier phase */
  593. }
  594. write_unlock_bh(&call->state_lock);
  595. /* if all the packets we sent are hard-ACK'd, then we can discard
  596. * whatever we've got left */
  597. _debug("clear Tx %d",
  598. CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
  599. del_timer_sync(&call->resend_timer);
  600. clear_bit(RXRPC_CALL_RUN_RTIMER, &call->flags);
  601. clear_bit(RXRPC_CALL_RESEND_TIMER, &call->events);
  602. if (call->acks_window)
  603. rxrpc_zap_tx_window(call);
  604. if (post_ACK) {
  605. /* post the final ACK message for userspace to pick up */
  606. _debug("post ACK");
  607. skb->mark = RXRPC_SKB_MARK_FINAL_ACK;
  608. sp->call = call;
  609. rxrpc_get_call(call);
  610. spin_lock_bh(&call->lock);
  611. if (rxrpc_queue_rcv_skb(call, skb, true, true) < 0)
  612. BUG();
  613. spin_unlock_bh(&call->lock);
  614. goto process_further;
  615. }
  616. discard:
  617. rxrpc_free_skb(skb);
  618. goto process_further;
  619. protocol_error_unlock:
  620. write_unlock_bh(&call->state_lock);
  621. protocol_error:
  622. rxrpc_free_skb(skb);
  623. _leave(" = -EPROTO");
  624. return -EPROTO;
  625. }
  626. /*
  627. * post a message to the socket Rx queue for recvmsg() to pick up
  628. */
  629. static int rxrpc_post_message(struct rxrpc_call *call, u32 mark, u32 error,
  630. bool fatal)
  631. {
  632. struct rxrpc_skb_priv *sp;
  633. struct sk_buff *skb;
  634. int ret;
  635. _enter("{%d,%lx},%u,%u,%d",
  636. call->debug_id, call->flags, mark, error, fatal);
  637. /* remove timers and things for fatal messages */
  638. if (fatal) {
  639. del_timer_sync(&call->resend_timer);
  640. del_timer_sync(&call->ack_timer);
  641. clear_bit(RXRPC_CALL_RUN_RTIMER, &call->flags);
  642. }
  643. if (mark != RXRPC_SKB_MARK_NEW_CALL &&
  644. !test_bit(RXRPC_CALL_HAS_USERID, &call->flags)) {
  645. _leave("[no userid]");
  646. return 0;
  647. }
  648. if (!test_bit(RXRPC_CALL_TERMINAL_MSG, &call->flags)) {
  649. skb = alloc_skb(0, GFP_NOFS);
  650. if (!skb)
  651. return -ENOMEM;
  652. rxrpc_new_skb(skb);
  653. skb->mark = mark;
  654. sp = rxrpc_skb(skb);
  655. memset(sp, 0, sizeof(*sp));
  656. sp->error = error;
  657. sp->call = call;
  658. rxrpc_get_call(call);
  659. spin_lock_bh(&call->lock);
  660. ret = rxrpc_queue_rcv_skb(call, skb, true, fatal);
  661. spin_unlock_bh(&call->lock);
  662. if (ret < 0)
  663. BUG();
  664. }
  665. return 0;
  666. }
  667. /*
  668. * handle background processing of incoming call packets and ACK / abort
  669. * generation
  670. */
  671. void rxrpc_process_call(struct work_struct *work)
  672. {
  673. struct rxrpc_call *call =
  674. container_of(work, struct rxrpc_call, processor);
  675. struct rxrpc_ackpacket ack;
  676. struct rxrpc_ackinfo ackinfo;
  677. struct rxrpc_header hdr;
  678. struct msghdr msg;
  679. struct kvec iov[5];
  680. unsigned long bits;
  681. __be32 data;
  682. size_t len;
  683. int genbit, loop, nbit, ioc, ret;
  684. u32 abort_code = RX_PROTOCOL_ERROR;
  685. u8 *acks = NULL;
  686. //printk("\n--------------------\n");
  687. _enter("{%d,%s,%lx} [%lu]",
  688. call->debug_id, rxrpc_call_states[call->state], call->events,
  689. (jiffies - call->creation_jif) / (HZ / 10));
  690. if (test_and_set_bit(RXRPC_CALL_PROC_BUSY, &call->flags)) {
  691. _debug("XXXXXXXXXXXXX RUNNING ON MULTIPLE CPUS XXXXXXXXXXXXX");
  692. return;
  693. }
  694. /* there's a good chance we're going to have to send a message, so set
  695. * one up in advance */
  696. msg.msg_name = &call->conn->trans->peer->srx.transport.sin;
  697. msg.msg_namelen = sizeof(call->conn->trans->peer->srx.transport.sin);
  698. msg.msg_control = NULL;
  699. msg.msg_controllen = 0;
  700. msg.msg_flags = 0;
  701. hdr.epoch = call->conn->epoch;
  702. hdr.cid = call->cid;
  703. hdr.callNumber = call->call_id;
  704. hdr.seq = 0;
  705. hdr.type = RXRPC_PACKET_TYPE_ACK;
  706. hdr.flags = call->conn->out_clientflag;
  707. hdr.userStatus = 0;
  708. hdr.securityIndex = call->conn->security_ix;
  709. hdr._rsvd = 0;
  710. hdr.serviceId = call->conn->service_id;
  711. memset(iov, 0, sizeof(iov));
  712. iov[0].iov_base = &hdr;
  713. iov[0].iov_len = sizeof(hdr);
  714. /* deal with events of a final nature */
  715. if (test_bit(RXRPC_CALL_RELEASE, &call->events)) {
  716. rxrpc_release_call(call);
  717. clear_bit(RXRPC_CALL_RELEASE, &call->events);
  718. }
  719. if (test_bit(RXRPC_CALL_RCVD_ERROR, &call->events)) {
  720. int error;
  721. clear_bit(RXRPC_CALL_CONN_ABORT, &call->events);
  722. clear_bit(RXRPC_CALL_REJECT_BUSY, &call->events);
  723. clear_bit(RXRPC_CALL_ABORT, &call->events);
  724. error = call->conn->trans->peer->net_error;
  725. _debug("post net error %d", error);
  726. if (rxrpc_post_message(call, RXRPC_SKB_MARK_NET_ERROR,
  727. error, true) < 0)
  728. goto no_mem;
  729. clear_bit(RXRPC_CALL_RCVD_ERROR, &call->events);
  730. goto kill_ACKs;
  731. }
  732. if (test_bit(RXRPC_CALL_CONN_ABORT, &call->events)) {
  733. ASSERTCMP(call->state, >, RXRPC_CALL_COMPLETE);
  734. clear_bit(RXRPC_CALL_REJECT_BUSY, &call->events);
  735. clear_bit(RXRPC_CALL_ABORT, &call->events);
  736. _debug("post conn abort");
  737. if (rxrpc_post_message(call, RXRPC_SKB_MARK_LOCAL_ERROR,
  738. call->conn->error, true) < 0)
  739. goto no_mem;
  740. clear_bit(RXRPC_CALL_CONN_ABORT, &call->events);
  741. goto kill_ACKs;
  742. }
  743. if (test_bit(RXRPC_CALL_REJECT_BUSY, &call->events)) {
  744. hdr.type = RXRPC_PACKET_TYPE_BUSY;
  745. genbit = RXRPC_CALL_REJECT_BUSY;
  746. goto send_message;
  747. }
  748. if (test_bit(RXRPC_CALL_ABORT, &call->events)) {
  749. ASSERTCMP(call->state, >, RXRPC_CALL_COMPLETE);
  750. if (rxrpc_post_message(call, RXRPC_SKB_MARK_LOCAL_ERROR,
  751. ECONNABORTED, true) < 0)
  752. goto no_mem;
  753. hdr.type = RXRPC_PACKET_TYPE_ABORT;
  754. data = htonl(call->abort_code);
  755. iov[1].iov_base = &data;
  756. iov[1].iov_len = sizeof(data);
  757. genbit = RXRPC_CALL_ABORT;
  758. goto send_message;
  759. }
  760. if (test_bit(RXRPC_CALL_ACK_FINAL, &call->events)) {
  761. hdr.type = RXRPC_PACKET_TYPE_ACKALL;
  762. genbit = RXRPC_CALL_ACK_FINAL;
  763. goto send_message;
  764. }
  765. if (call->events & ((1 << RXRPC_CALL_RCVD_BUSY) |
  766. (1 << RXRPC_CALL_RCVD_ABORT))
  767. ) {
  768. u32 mark;
  769. if (test_bit(RXRPC_CALL_RCVD_ABORT, &call->events))
  770. mark = RXRPC_SKB_MARK_REMOTE_ABORT;
  771. else
  772. mark = RXRPC_SKB_MARK_BUSY;
  773. _debug("post abort/busy");
  774. rxrpc_clear_tx_window(call);
  775. if (rxrpc_post_message(call, mark, ECONNABORTED, true) < 0)
  776. goto no_mem;
  777. clear_bit(RXRPC_CALL_RCVD_BUSY, &call->events);
  778. clear_bit(RXRPC_CALL_RCVD_ABORT, &call->events);
  779. goto kill_ACKs;
  780. }
  781. if (test_and_clear_bit(RXRPC_CALL_RCVD_ACKALL, &call->events)) {
  782. _debug("do implicit ackall");
  783. rxrpc_clear_tx_window(call);
  784. }
  785. if (test_bit(RXRPC_CALL_LIFE_TIMER, &call->events)) {
  786. write_lock_bh(&call->state_lock);
  787. if (call->state <= RXRPC_CALL_COMPLETE) {
  788. call->state = RXRPC_CALL_LOCALLY_ABORTED;
  789. call->abort_code = RX_CALL_TIMEOUT;
  790. set_bit(RXRPC_CALL_ABORT, &call->events);
  791. }
  792. write_unlock_bh(&call->state_lock);
  793. _debug("post timeout");
  794. if (rxrpc_post_message(call, RXRPC_SKB_MARK_LOCAL_ERROR,
  795. ETIME, true) < 0)
  796. goto no_mem;
  797. clear_bit(RXRPC_CALL_LIFE_TIMER, &call->events);
  798. goto kill_ACKs;
  799. }
  800. /* deal with assorted inbound messages */
  801. if (!skb_queue_empty(&call->rx_queue)) {
  802. switch (rxrpc_process_rx_queue(call, &abort_code)) {
  803. case 0:
  804. case -EAGAIN:
  805. break;
  806. case -ENOMEM:
  807. goto no_mem;
  808. case -EKEYEXPIRED:
  809. case -EKEYREJECTED:
  810. case -EPROTO:
  811. rxrpc_abort_call(call, abort_code);
  812. goto kill_ACKs;
  813. }
  814. }
  815. /* handle resending */
  816. if (test_and_clear_bit(RXRPC_CALL_RESEND_TIMER, &call->events))
  817. rxrpc_resend_timer(call);
  818. if (test_and_clear_bit(RXRPC_CALL_RESEND, &call->events))
  819. rxrpc_resend(call);
  820. /* consider sending an ordinary ACK */
  821. if (test_bit(RXRPC_CALL_ACK, &call->events)) {
  822. __be32 pad;
  823. _debug("send ACK: window: %d - %d { %lx }",
  824. call->rx_data_eaten, call->ackr_win_top,
  825. call->ackr_window[0]);
  826. if (call->state > RXRPC_CALL_SERVER_ACK_REQUEST &&
  827. call->ackr_reason != RXRPC_ACK_PING_RESPONSE) {
  828. /* ACK by sending reply DATA packet in this state */
  829. clear_bit(RXRPC_CALL_ACK, &call->events);
  830. goto maybe_reschedule;
  831. }
  832. genbit = RXRPC_CALL_ACK;
  833. acks = kzalloc(call->ackr_win_top - call->rx_data_eaten,
  834. GFP_NOFS);
  835. if (!acks)
  836. goto no_mem;
  837. //hdr.flags = RXRPC_SLOW_START_OK;
  838. ack.bufferSpace = htons(8);
  839. ack.maxSkew = 0;
  840. ack.serial = 0;
  841. ack.reason = 0;
  842. ackinfo.rxMTU = htonl(5692);
  843. // ackinfo.rxMTU = htonl(call->conn->trans->peer->maxdata);
  844. ackinfo.maxMTU = htonl(call->conn->trans->peer->maxdata);
  845. ackinfo.rwind = htonl(32);
  846. ackinfo.jumbo_max = htonl(4);
  847. spin_lock_bh(&call->lock);
  848. ack.reason = call->ackr_reason;
  849. ack.serial = call->ackr_serial;
  850. ack.previousPacket = call->ackr_prev_seq;
  851. ack.firstPacket = htonl(call->rx_data_eaten + 1);
  852. ack.nAcks = 0;
  853. for (loop = 0; loop < RXRPC_ACKR_WINDOW_ASZ; loop++) {
  854. nbit = loop * BITS_PER_LONG;
  855. for (bits = call->ackr_window[loop]; bits; bits >>= 1
  856. ) {
  857. _debug("- l=%d n=%d b=%lx", loop, nbit, bits);
  858. if (bits & 1) {
  859. acks[nbit] = RXRPC_ACK_TYPE_ACK;
  860. ack.nAcks = nbit + 1;
  861. }
  862. nbit++;
  863. }
  864. }
  865. call->ackr_reason = 0;
  866. spin_unlock_bh(&call->lock);
  867. pad = 0;
  868. iov[1].iov_base = &ack;
  869. iov[1].iov_len = sizeof(ack);
  870. iov[2].iov_base = acks;
  871. iov[2].iov_len = ack.nAcks;
  872. iov[3].iov_base = &pad;
  873. iov[3].iov_len = 3;
  874. iov[4].iov_base = &ackinfo;
  875. iov[4].iov_len = sizeof(ackinfo);
  876. switch (ack.reason) {
  877. case RXRPC_ACK_REQUESTED:
  878. case RXRPC_ACK_DUPLICATE:
  879. case RXRPC_ACK_OUT_OF_SEQUENCE:
  880. case RXRPC_ACK_EXCEEDS_WINDOW:
  881. case RXRPC_ACK_NOSPACE:
  882. case RXRPC_ACK_PING:
  883. case RXRPC_ACK_PING_RESPONSE:
  884. goto send_ACK_with_skew;
  885. case RXRPC_ACK_DELAY:
  886. case RXRPC_ACK_IDLE:
  887. goto send_ACK;
  888. }
  889. }
  890. /* handle completion of security negotiations on an incoming
  891. * connection */
  892. if (test_and_clear_bit(RXRPC_CALL_SECURED, &call->events)) {
  893. _debug("secured");
  894. spin_lock_bh(&call->lock);
  895. if (call->state == RXRPC_CALL_SERVER_SECURING) {
  896. _debug("securing");
  897. write_lock(&call->conn->lock);
  898. if (!test_bit(RXRPC_CALL_RELEASED, &call->flags) &&
  899. !test_bit(RXRPC_CALL_RELEASE, &call->events)) {
  900. _debug("not released");
  901. call->state = RXRPC_CALL_SERVER_ACCEPTING;
  902. list_move_tail(&call->accept_link,
  903. &call->socket->acceptq);
  904. }
  905. write_unlock(&call->conn->lock);
  906. read_lock(&call->state_lock);
  907. if (call->state < RXRPC_CALL_COMPLETE)
  908. set_bit(RXRPC_CALL_POST_ACCEPT, &call->events);
  909. read_unlock(&call->state_lock);
  910. }
  911. spin_unlock_bh(&call->lock);
  912. if (!test_bit(RXRPC_CALL_POST_ACCEPT, &call->events))
  913. goto maybe_reschedule;
  914. }
  915. /* post a notification of an acceptable connection to the app */
  916. if (test_bit(RXRPC_CALL_POST_ACCEPT, &call->events)) {
  917. _debug("post accept");
  918. if (rxrpc_post_message(call, RXRPC_SKB_MARK_NEW_CALL,
  919. 0, false) < 0)
  920. goto no_mem;
  921. clear_bit(RXRPC_CALL_POST_ACCEPT, &call->events);
  922. goto maybe_reschedule;
  923. }
  924. /* handle incoming call acceptance */
  925. if (test_and_clear_bit(RXRPC_CALL_ACCEPTED, &call->events)) {
  926. _debug("accepted");
  927. ASSERTCMP(call->rx_data_post, ==, 0);
  928. call->rx_data_post = 1;
  929. read_lock_bh(&call->state_lock);
  930. if (call->state < RXRPC_CALL_COMPLETE)
  931. set_bit(RXRPC_CALL_DRAIN_RX_OOS, &call->events);
  932. read_unlock_bh(&call->state_lock);
  933. }
  934. /* drain the out of sequence received packet queue into the packet Rx
  935. * queue */
  936. if (test_and_clear_bit(RXRPC_CALL_DRAIN_RX_OOS, &call->events)) {
  937. while (call->rx_data_post == call->rx_first_oos)
  938. if (rxrpc_drain_rx_oos_queue(call) < 0)
  939. break;
  940. goto maybe_reschedule;
  941. }
  942. /* other events may have been raised since we started checking */
  943. goto maybe_reschedule;
  944. send_ACK_with_skew:
  945. ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
  946. ntohl(ack.serial));
  947. send_ACK:
  948. hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
  949. _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
  950. ntohl(hdr.serial),
  951. ntohs(ack.maxSkew),
  952. ntohl(ack.firstPacket),
  953. ntohl(ack.previousPacket),
  954. ntohl(ack.serial),
  955. rxrpc_acks[ack.reason],
  956. ack.nAcks);
  957. del_timer_sync(&call->ack_timer);
  958. if (ack.nAcks > 0)
  959. set_bit(RXRPC_CALL_TX_SOFT_ACK, &call->flags);
  960. goto send_message_2;
  961. send_message:
  962. _debug("send message");
  963. hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
  964. _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
  965. send_message_2:
  966. len = iov[0].iov_len;
  967. ioc = 1;
  968. if (iov[4].iov_len) {
  969. ioc = 5;
  970. len += iov[4].iov_len;
  971. len += iov[3].iov_len;
  972. len += iov[2].iov_len;
  973. len += iov[1].iov_len;
  974. } else if (iov[3].iov_len) {
  975. ioc = 4;
  976. len += iov[3].iov_len;
  977. len += iov[2].iov_len;
  978. len += iov[1].iov_len;
  979. } else if (iov[2].iov_len) {
  980. ioc = 3;
  981. len += iov[2].iov_len;
  982. len += iov[1].iov_len;
  983. } else if (iov[1].iov_len) {
  984. ioc = 2;
  985. len += iov[1].iov_len;
  986. }
  987. ret = kernel_sendmsg(call->conn->trans->local->socket,
  988. &msg, iov, ioc, len);
  989. if (ret < 0) {
  990. _debug("sendmsg failed: %d", ret);
  991. read_lock_bh(&call->state_lock);
  992. if (call->state < RXRPC_CALL_DEAD)
  993. rxrpc_queue_call(call);
  994. read_unlock_bh(&call->state_lock);
  995. goto error;
  996. }
  997. switch (genbit) {
  998. case RXRPC_CALL_ABORT:
  999. clear_bit(genbit, &call->events);
  1000. clear_bit(RXRPC_CALL_RCVD_ABORT, &call->events);
  1001. goto kill_ACKs;
  1002. case RXRPC_CALL_ACK_FINAL:
  1003. write_lock_bh(&call->state_lock);
  1004. if (call->state == RXRPC_CALL_CLIENT_FINAL_ACK)
  1005. call->state = RXRPC_CALL_COMPLETE;
  1006. write_unlock_bh(&call->state_lock);
  1007. goto kill_ACKs;
  1008. default:
  1009. clear_bit(genbit, &call->events);
  1010. switch (call->state) {
  1011. case RXRPC_CALL_CLIENT_AWAIT_REPLY:
  1012. case RXRPC_CALL_CLIENT_RECV_REPLY:
  1013. case RXRPC_CALL_SERVER_RECV_REQUEST:
  1014. case RXRPC_CALL_SERVER_ACK_REQUEST:
  1015. _debug("start ACK timer");
  1016. rxrpc_propose_ACK(call, RXRPC_ACK_DELAY,
  1017. call->ackr_serial, false);
  1018. default:
  1019. break;
  1020. }
  1021. goto maybe_reschedule;
  1022. }
  1023. kill_ACKs:
  1024. del_timer_sync(&call->ack_timer);
  1025. if (test_and_clear_bit(RXRPC_CALL_ACK_FINAL, &call->events))
  1026. rxrpc_put_call(call);
  1027. clear_bit(RXRPC_CALL_ACK, &call->events);
  1028. maybe_reschedule:
  1029. if (call->events || !skb_queue_empty(&call->rx_queue)) {
  1030. read_lock_bh(&call->state_lock);
  1031. if (call->state < RXRPC_CALL_DEAD)
  1032. rxrpc_queue_call(call);
  1033. read_unlock_bh(&call->state_lock);
  1034. }
  1035. /* don't leave aborted connections on the accept queue */
  1036. if (call->state >= RXRPC_CALL_COMPLETE &&
  1037. !list_empty(&call->accept_link)) {
  1038. _debug("X unlinking once-pending call %p { e=%lx f=%lx c=%x }",
  1039. call, call->events, call->flags,
  1040. ntohl(call->conn->cid));
  1041. read_lock_bh(&call->state_lock);
  1042. if (!test_bit(RXRPC_CALL_RELEASED, &call->flags) &&
  1043. !test_and_set_bit(RXRPC_CALL_RELEASE, &call->events))
  1044. rxrpc_queue_call(call);
  1045. read_unlock_bh(&call->state_lock);
  1046. }
  1047. error:
  1048. clear_bit(RXRPC_CALL_PROC_BUSY, &call->flags);
  1049. kfree(acks);
  1050. /* because we don't want two CPUs both processing the work item for one
  1051. * call at the same time, we use a flag to note when it's busy; however
  1052. * this means there's a race between clearing the flag and setting the
  1053. * work pending bit and the work item being processed again */
  1054. if (call->events && !work_pending(&call->processor)) {
  1055. _debug("jumpstart %x", ntohl(call->conn->cid));
  1056. rxrpc_queue_call(call);
  1057. }
  1058. _leave("");
  1059. return;
  1060. no_mem:
  1061. _debug("out of memory");
  1062. goto maybe_reschedule;
  1063. }