Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'rxrpc-rewrite-20160923' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs

David Howells says:

====================
rxrpc: Bug fixes and tracepoints

Here are a bunch of bug fixes:

(1) Need to set the timestamp on a Tx packet before queueing it to avoid
trouble with the retransmission function.

(2) Don't send an ACK at the end of the service reply transmission; it's
the responsibility of the client to send an ACK to close the call.
The service can resend the last DATA packet or send a PING ACK.

(3) Wake sendmsg() on abnormal call termination.

(4) Use ktime_add_ms() not ktime_add_ns() to add millisecond offsets.

(5) Use before_eq() & co. to compare serial numbers (which may wrap).

(6) Start the resend timer on DATA packet transmission.

(7) Don't accidentally cancel a retransmission upon receiving a NACK.

(8) Fix the call timer setting function to deal with timeouts that are now
or past.

(9) Don't use a flag to communicate the presence of the last packet in the
Tx buffer from sendmsg to the input routines where ACK and DATA
reception is handled. The problem is that there's a window between
queueing the last packet for transmission and setting the flag in
which ACKs or reply DATA packets can arrive, causing apparent state
machine violation issues.

Instead use the annotation buffer to mark the last packet and pick up
and set the flag in the input routines.

(10) Don't call the tx_ack tracepoint and don't allocate a serial number if
someone else nicked the ACK we were about to transmit.

There are also new tracepoints and one altered tracepoint used to track
down the above bugs:

(11) Call timer tracepoint.

(12) Data Tx tracepoint (and adjustments to ACK tracepoint).

(13) Injected Rx packet loss tracepoint.

(14) Ack proposal tracepoint.

(15) Retransmission selection tracepoint.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+407 -129
+1
include/rxrpc/packet.h
··· 123 123 #define RXRPC_ACK_PING_RESPONSE 7 /* response to RXRPC_ACK_PING */ 124 124 #define RXRPC_ACK_DELAY 8 /* nothing happened since received packet */ 125 125 #define RXRPC_ACK_IDLE 9 /* ACK due to fully received ACK window */ 126 + #define RXRPC_ACK__INVALID 10 /* Representation of invalid ACK reason */ 126 127 127 128 uint8_t nAcks; /* number of ACKs */ 128 129 #define RXRPC_MAXACKS 255
+166 -10
include/trace/events/rxrpc.h
··· 251 251 252 252 TP_printk("c=%p %s f=%08x n=%u", 253 253 __entry->call, 254 - rxrpc_acks(__entry->reason), 254 + rxrpc_ack_names[__entry->reason], 255 255 __entry->first, 256 256 __entry->n_acks) 257 257 ); 258 258 259 - TRACE_EVENT(rxrpc_tx_ack, 260 - TP_PROTO(struct rxrpc_call *call, rxrpc_seq_t first, 261 - rxrpc_serial_t serial, u8 reason, u8 n_acks), 259 + TRACE_EVENT(rxrpc_tx_data, 260 + TP_PROTO(struct rxrpc_call *call, rxrpc_seq_t seq, 261 + rxrpc_serial_t serial, u8 flags, bool lose), 262 262 263 - TP_ARGS(call, first, serial, reason, n_acks), 263 + TP_ARGS(call, seq, serial, flags, lose), 264 264 265 265 TP_STRUCT__entry( 266 266 __field(struct rxrpc_call *, call ) 267 - __field(rxrpc_seq_t, first ) 267 + __field(rxrpc_seq_t, seq ) 268 268 __field(rxrpc_serial_t, serial ) 269 + __field(u8, flags ) 270 + __field(bool, lose ) 271 + ), 272 + 273 + TP_fast_assign( 274 + __entry->call = call; 275 + __entry->seq = seq; 276 + __entry->serial = serial; 277 + __entry->flags = flags; 278 + __entry->lose = lose; 279 + ), 280 + 281 + TP_printk("c=%p DATA %08x q=%08x fl=%02x%s", 282 + __entry->call, 283 + __entry->serial, 284 + __entry->seq, 285 + __entry->flags, 286 + __entry->lose ? " *LOSE*" : "") 287 + ); 288 + 289 + TRACE_EVENT(rxrpc_tx_ack, 290 + TP_PROTO(struct rxrpc_call *call, rxrpc_serial_t serial, 291 + rxrpc_seq_t ack_first, rxrpc_serial_t ack_serial, 292 + u8 reason, u8 n_acks), 293 + 294 + TP_ARGS(call, serial, ack_first, ack_serial, reason, n_acks), 295 + 296 + TP_STRUCT__entry( 297 + __field(struct rxrpc_call *, call ) 298 + __field(rxrpc_serial_t, serial ) 299 + __field(rxrpc_seq_t, ack_first ) 300 + __field(rxrpc_serial_t, ack_serial ) 269 301 __field(u8, reason ) 270 302 __field(u8, n_acks ) 271 303 ), 272 304 273 305 TP_fast_assign( 274 306 __entry->call = call; 275 - __entry->first = first; 276 307 __entry->serial = serial; 308 + __entry->ack_first = ack_first; 309 + __entry->ack_serial = ack_serial; 277 310 __entry->reason = reason; 278 311 __entry->n_acks = n_acks; 279 312 ), 280 313 281 - TP_printk("c=%p %s f=%08x r=%08x n=%u", 314 + TP_printk(" c=%p ACK %08x %s f=%08x r=%08x n=%u", 282 315 __entry->call, 283 - rxrpc_acks(__entry->reason), 284 - __entry->first, 285 316 __entry->serial, 317 + rxrpc_ack_names[__entry->reason], 318 + __entry->ack_first, 319 + __entry->ack_serial, 286 320 __entry->n_acks) 287 321 ); 288 322 ··· 446 412 __entry->rtt, 447 413 __entry->nr, 448 414 __entry->avg) 415 + ); 416 + 417 + TRACE_EVENT(rxrpc_timer, 418 + TP_PROTO(struct rxrpc_call *call, enum rxrpc_timer_trace why, 419 + unsigned long now), 420 + 421 + TP_ARGS(call, why, now), 422 + 423 + TP_STRUCT__entry( 424 + __field(struct rxrpc_call *, call ) 425 + __field(enum rxrpc_timer_trace, why ) 426 + __field(unsigned long, now ) 427 + __field(unsigned long, expire_at ) 428 + __field(unsigned long, ack_at ) 429 + __field(unsigned long, resend_at ) 430 + __field(unsigned long, timer ) 431 + ), 432 + 433 + TP_fast_assign( 434 + __entry->call = call; 435 + __entry->why = why; 436 + __entry->now = now; 437 + __entry->expire_at = call->expire_at; 438 + __entry->ack_at = call->ack_at; 439 + __entry->resend_at = call->resend_at; 440 + __entry->timer = call->timer.expires; 441 + ), 442 + 443 + TP_printk("c=%p %s now=%lx x=%ld a=%ld r=%ld t=%ld", 444 + __entry->call, 445 + rxrpc_timer_traces[__entry->why], 446 + __entry->now, 447 + __entry->expire_at - __entry->now, 448 + __entry->ack_at - __entry->now, 449 + __entry->resend_at - __entry->now, 450 + __entry->timer - __entry->now) 451 + ); 452 + 453 + TRACE_EVENT(rxrpc_rx_lose, 454 + TP_PROTO(struct rxrpc_skb_priv *sp), 455 + 456 + TP_ARGS(sp), 457 + 458 + TP_STRUCT__entry( 459 + __field_struct(struct rxrpc_host_header, hdr ) 460 + ), 461 + 462 + TP_fast_assign( 463 + memcpy(&__entry->hdr, &sp->hdr, sizeof(__entry->hdr)); 464 + ), 465 + 466 + TP_printk("%08x:%08x:%08x:%04x %08x %08x %02x %02x %s *LOSE*", 467 + __entry->hdr.epoch, __entry->hdr.cid, 468 + __entry->hdr.callNumber, __entry->hdr.serviceId, 469 + __entry->hdr.serial, __entry->hdr.seq, 470 + __entry->hdr.type, __entry->hdr.flags, 471 + __entry->hdr.type <= 15 ? rxrpc_pkts[__entry->hdr.type] : "?UNK") 472 + ); 473 + 474 + TRACE_EVENT(rxrpc_propose_ack, 475 + TP_PROTO(struct rxrpc_call *call, enum rxrpc_propose_ack_trace why, 476 + u8 ack_reason, rxrpc_serial_t serial, bool immediate, 477 + bool background, enum rxrpc_propose_ack_outcome outcome), 478 + 479 + TP_ARGS(call, why, ack_reason, serial, immediate, background, 480 + outcome), 481 + 482 + TP_STRUCT__entry( 483 + __field(struct rxrpc_call *, call ) 484 + __field(enum rxrpc_propose_ack_trace, why ) 485 + __field(rxrpc_serial_t, serial ) 486 + __field(u8, ack_reason ) 487 + __field(bool, immediate ) 488 + __field(bool, background ) 489 + __field(enum rxrpc_propose_ack_outcome, outcome ) 490 + ), 491 + 492 + TP_fast_assign( 493 + __entry->call = call; 494 + __entry->why = why; 495 + __entry->serial = serial; 496 + __entry->ack_reason = ack_reason; 497 + __entry->immediate = immediate; 498 + __entry->background = background; 499 + __entry->outcome = outcome; 500 + ), 501 + 502 + TP_printk("c=%p %s %s r=%08x i=%u b=%u%s", 503 + __entry->call, 504 + rxrpc_propose_ack_traces[__entry->why], 505 + rxrpc_ack_names[__entry->ack_reason], 506 + __entry->serial, 507 + __entry->immediate, 508 + __entry->background, 509 + rxrpc_propose_ack_outcomes[__entry->outcome]) 510 + ); 511 + 512 + TRACE_EVENT(rxrpc_retransmit, 513 + TP_PROTO(struct rxrpc_call *call, rxrpc_seq_t seq, u8 annotation, 514 + s64 expiry), 515 + 516 + TP_ARGS(call, seq, annotation, expiry), 517 + 518 + TP_STRUCT__entry( 519 + __field(struct rxrpc_call *, call ) 520 + __field(rxrpc_seq_t, seq ) 521 + __field(u8, annotation ) 522 + __field(s64, expiry ) 523 + ), 524 + 525 + TP_fast_assign( 526 + __entry->call = call; 527 + __entry->seq = seq; 528 + __entry->annotation = annotation; 529 + __entry->expiry = expiry; 530 + ), 531 + 532 + TP_printk("c=%p q=%x a=%02x xp=%lld", 533 + __entry->call, 534 + __entry->seq, 535 + __entry->annotation, 536 + __entry->expiry) 449 537 ); 450 538 451 539 #endif /* _TRACE_RXRPC_H */
+41 -4
net/rxrpc/ar-internal.h
··· 508 508 #define RXRPC_TX_ANNO_NAK 2 509 509 #define RXRPC_TX_ANNO_RETRANS 3 510 510 #define RXRPC_TX_ANNO_MASK 0x03 511 - #define RXRPC_TX_ANNO_RESENT 0x04 511 + #define RXRPC_TX_ANNO_LAST 0x04 512 + #define RXRPC_TX_ANNO_RESENT 0x08 513 + 512 514 #define RXRPC_RX_ANNO_JUMBO 0x3f /* Jumbo subpacket number + 1 if not zero */ 513 515 #define RXRPC_RX_ANNO_JLAST 0x40 /* Set if last element of a jumbo packet */ 514 516 #define RXRPC_RX_ANNO_VERIFIED 0x80 /* Set if verified and decrypted */ ··· 623 621 enum rxrpc_transmit_trace { 624 622 rxrpc_transmit_wait, 625 623 rxrpc_transmit_queue, 626 - rxrpc_transmit_queue_reqack, 627 624 rxrpc_transmit_queue_last, 628 625 rxrpc_transmit_rotate, 626 + rxrpc_transmit_rotate_last, 627 + rxrpc_transmit_await_reply, 629 628 rxrpc_transmit_end, 630 629 rxrpc_transmit__nr_trace 631 630 }; ··· 678 675 679 676 extern const char rxrpc_rtt_rx_traces[rxrpc_rtt_rx__nr_trace][5]; 680 677 678 + enum rxrpc_timer_trace { 679 + rxrpc_timer_begin, 680 + rxrpc_timer_expired, 681 + rxrpc_timer_set_for_ack, 682 + rxrpc_timer_set_for_resend, 683 + rxrpc_timer_set_for_send, 684 + rxrpc_timer__nr_trace 685 + }; 686 + 687 + extern const char rxrpc_timer_traces[rxrpc_timer__nr_trace][8]; 688 + 689 + enum rxrpc_propose_ack_trace { 690 + rxrpc_propose_ack_input_data, 691 + rxrpc_propose_ack_ping_for_params, 692 + rxrpc_propose_ack_respond_to_ack, 693 + rxrpc_propose_ack_respond_to_ping, 694 + rxrpc_propose_ack_retry_tx, 695 + rxrpc_propose_ack_terminal_ack, 696 + rxrpc_propose_ack__nr_trace 697 + }; 698 + 699 + enum rxrpc_propose_ack_outcome { 700 + rxrpc_propose_ack_use, 701 + rxrpc_propose_ack_update, 702 + rxrpc_propose_ack_subsume, 703 + rxrpc_propose_ack__nr_outcomes 704 + }; 705 + 706 + extern const char rxrpc_propose_ack_traces[rxrpc_propose_ack__nr_trace][8]; 707 + extern const char *const rxrpc_propose_ack_outcomes[rxrpc_propose_ack__nr_outcomes]; 708 + 681 709 extern const char *const rxrpc_pkts[]; 682 - extern const char *rxrpc_acks(u8 reason); 710 + extern const char const rxrpc_ack_names[RXRPC_ACK__INVALID + 1][4]; 683 711 684 712 #include <trace/events/rxrpc.h> 685 713 ··· 738 704 /* 739 705 * call_event.c 740 706 */ 741 - void rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool, bool); 707 + void rxrpc_set_timer(struct rxrpc_call *, enum rxrpc_timer_trace); 708 + void rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool, bool, 709 + enum rxrpc_propose_ack_trace); 742 710 void rxrpc_process_call(struct work_struct *); 743 711 744 712 /* ··· 794 758 call->error = error; 795 759 call->completion = compl, 796 760 call->state = RXRPC_CALL_COMPLETE; 761 + wake_up(&call->waitq); 797 762 return true; 798 763 } 799 764 return false;
+35 -22
net/rxrpc/call_event.c
··· 24 24 /* 25 25 * Set the timer 26 26 */ 27 - static void rxrpc_set_timer(struct rxrpc_call *call) 27 + void rxrpc_set_timer(struct rxrpc_call *call, enum rxrpc_timer_trace why) 28 28 { 29 29 unsigned long t, now = jiffies; 30 - 31 - _enter("{%ld,%ld,%ld:%ld}", 32 - call->ack_at - now, call->resend_at - now, call->expire_at - now, 33 - call->timer.expires - now); 34 30 35 31 read_lock_bh(&call->state_lock); 36 32 37 33 if (call->state < RXRPC_CALL_COMPLETE) { 38 - t = call->ack_at; 39 - if (time_before(call->resend_at, t)) 34 + t = call->expire_at; 35 + if (time_before_eq(t, now)) 36 + goto out; 37 + 38 + if (time_after(call->resend_at, now) && 39 + time_before(call->resend_at, t)) 40 40 t = call->resend_at; 41 - if (time_before(call->expire_at, t)) 42 - t = call->expire_at; 43 - if (!timer_pending(&call->timer) || 44 - time_before(t, call->timer.expires)) { 45 - _debug("set timer %ld", t - now); 41 + 42 + if (time_after(call->ack_at, now) && 43 + time_before(call->ack_at, t)) 44 + t = call->ack_at; 45 + 46 + if (call->timer.expires != t || !timer_pending(&call->timer)) { 46 47 mod_timer(&call->timer, t); 48 + trace_rxrpc_timer(call, why, now); 47 49 } 48 50 } 51 + 52 + out: 49 53 read_unlock_bh(&call->state_lock); 50 54 } 51 55 ··· 58 54 */ 59 55 static void __rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason, 60 56 u16 skew, u32 serial, bool immediate, 61 - bool background) 57 + bool background, 58 + enum rxrpc_propose_ack_trace why) 62 59 { 60 + enum rxrpc_propose_ack_outcome outcome = rxrpc_propose_ack_use; 63 61 unsigned long now, ack_at, expiry = rxrpc_soft_ack_delay; 64 62 s8 prior = rxrpc_ack_priority[ack_reason]; 65 - 66 - _enter("{%d},%s,%%%x,%u", 67 - call->debug_id, rxrpc_acks(ack_reason), serial, immediate); 68 63 69 64 /* Update DELAY, IDLE, REQUESTED and PING_RESPONSE ACK serial 70 65 * numbers, but we don't alter the timeout. ··· 73 70 call->ackr_reason, rxrpc_ack_priority[call->ackr_reason]); 74 71 if (ack_reason == call->ackr_reason) { 75 72 if (RXRPC_ACK_UPDATEABLE & (1 << ack_reason)) { 73 + outcome = rxrpc_propose_ack_update; 76 74 call->ackr_serial = serial; 77 75 call->ackr_skew = skew; 78 76 } 79 77 if (!immediate) 80 - return; 78 + goto trace; 81 79 } else if (prior > rxrpc_ack_priority[call->ackr_reason]) { 82 80 call->ackr_reason = ack_reason; 83 81 call->ackr_serial = serial; 84 82 call->ackr_skew = skew; 83 + } else { 84 + outcome = rxrpc_propose_ack_subsume; 85 85 } 86 86 87 87 switch (ack_reason) { ··· 123 117 _debug("deferred ACK %ld < %ld", expiry, call->ack_at - now); 124 118 if (time_before(ack_at, call->ack_at)) { 125 119 call->ack_at = ack_at; 126 - rxrpc_set_timer(call); 120 + rxrpc_set_timer(call, rxrpc_timer_set_for_ack); 127 121 } 128 122 } 123 + 124 + trace: 125 + trace_rxrpc_propose_ack(call, why, ack_reason, serial, immediate, 126 + background, outcome); 129 127 } 130 128 131 129 /* 132 130 * propose an ACK be sent, locking the call structure 133 131 */ 134 132 void rxrpc_propose_ACK(struct rxrpc_call *call, u8 ack_reason, 135 - u16 skew, u32 serial, bool immediate, bool background) 133 + u16 skew, u32 serial, bool immediate, bool background, 134 + enum rxrpc_propose_ack_trace why) 136 135 { 137 136 spin_lock_bh(&call->lock); 138 137 __rxrpc_propose_ACK(call, ack_reason, skew, serial, 139 - immediate, background); 138 + immediate, background, why); 140 139 spin_unlock_bh(&call->lock); 141 140 } 142 141 ··· 196 185 197 186 /* Okay, we need to retransmit a packet. */ 198 187 call->rxtx_annotations[ix] = RXRPC_TX_ANNO_RETRANS | annotation; 188 + trace_rxrpc_retransmit(call, seq, annotation | anno_type, 189 + ktime_to_ns(ktime_sub(skb->tstamp, max_age))); 199 190 } 200 191 201 - resend_at = ktime_sub(ktime_add_ns(oldest, rxrpc_resend_timeout), now); 192 + resend_at = ktime_sub(ktime_add_ms(oldest, rxrpc_resend_timeout), now); 202 193 call->resend_at = jiffies + nsecs_to_jiffies(ktime_to_ns(resend_at)); 203 194 204 195 /* Now go through the Tx window and perform the retransmissions. We ··· 303 290 goto recheck_state; 304 291 } 305 292 306 - rxrpc_set_timer(call); 293 + rxrpc_set_timer(call, rxrpc_timer_set_for_resend); 307 294 308 295 /* other events may have been raised since we started checking */ 309 296 if (call->events && call->state < RXRPC_CALL_COMPLETE) {
+5 -3
net/rxrpc/call_object.c
··· 76 76 77 77 _enter("%d", call->debug_id); 78 78 79 - if (call->state < RXRPC_CALL_COMPLETE) 79 + if (call->state < RXRPC_CALL_COMPLETE) { 80 + trace_rxrpc_timer(call, rxrpc_timer_expired, jiffies); 80 81 rxrpc_queue_call(call); 82 + } 81 83 } 82 84 83 85 /* ··· 201 199 call->expire_at = expire_at; 202 200 call->ack_at = expire_at; 203 201 call->resend_at = expire_at; 204 - call->timer.expires = expire_at; 205 - add_timer(&call->timer); 202 + call->timer.expires = expire_at + 1; 203 + rxrpc_set_timer(call, rxrpc_timer_begin); 206 204 } 207 205 208 206 /*
+2 -3
net/rxrpc/conn_event.c
··· 98 98 pkt.info.rwind = htonl(rxrpc_rx_window_size); 99 99 pkt.info.jumbo_max = htonl(rxrpc_rx_jumbo_max); 100 100 len += sizeof(pkt.ack) + sizeof(pkt.info); 101 - 102 - trace_rxrpc_tx_ack(NULL, chan->last_seq, 0, 103 - RXRPC_ACK_DUPLICATE, 0); 104 101 break; 105 102 } 106 103 ··· 119 122 _proto("Tx ABORT %%%u { %d } [re]", serial, conn->local_abort); 120 123 break; 121 124 case RXRPC_PACKET_TYPE_ACK: 125 + trace_rxrpc_tx_ack(NULL, serial, chan->last_seq, 0, 126 + RXRPC_ACK_DUPLICATE, 0); 122 127 _proto("Tx ACK %%%u [re]", serial); 123 128 break; 124 129 }
+89 -49
net/rxrpc/input.c
··· 49 49 if (call->peer->rtt_usage < 3 || 50 50 ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000), now)) 51 51 rxrpc_propose_ACK(call, RXRPC_ACK_PING, skew, sp->hdr.serial, 52 - true, true); 52 + true, true, 53 + rxrpc_propose_ack_ping_for_params); 53 54 } 54 55 55 56 /* ··· 60 59 { 61 60 struct sk_buff *skb, *list = NULL; 62 61 int ix; 62 + u8 annotation; 63 63 64 64 spin_lock(&call->lock); 65 65 ··· 68 66 call->tx_hard_ack++; 69 67 ix = call->tx_hard_ack & RXRPC_RXTX_BUFF_MASK; 70 68 skb = call->rxtx_buffer[ix]; 69 + annotation = call->rxtx_annotations[ix]; 71 70 rxrpc_see_skb(skb, rxrpc_skb_tx_rotated); 72 71 call->rxtx_buffer[ix] = NULL; 73 72 call->rxtx_annotations[ix] = 0; 74 73 skb->next = list; 75 74 list = skb; 75 + 76 + if (annotation & RXRPC_TX_ANNO_LAST) 77 + set_bit(RXRPC_CALL_TX_LAST, &call->flags); 76 78 } 77 79 78 80 spin_unlock(&call->lock); 79 81 80 - trace_rxrpc_transmit(call, rxrpc_transmit_rotate); 82 + trace_rxrpc_transmit(call, (test_bit(RXRPC_CALL_TX_LAST, &call->flags) ? 83 + rxrpc_transmit_rotate_last : 84 + rxrpc_transmit_rotate)); 81 85 wake_up(&call->waitq); 82 86 83 87 while (list) { ··· 100 92 * This occurs when we get an ACKALL packet, the first DATA packet of a reply, 101 93 * or a final ACK packet. 102 94 */ 103 - static bool rxrpc_end_tx_phase(struct rxrpc_call *call, const char *abort_why) 95 + static bool rxrpc_end_tx_phase(struct rxrpc_call *call, bool reply_begun, 96 + const char *abort_why) 104 97 { 105 - _enter(""); 106 98 107 - switch (call->state) { 108 - case RXRPC_CALL_CLIENT_RECV_REPLY: 109 - return true; 110 - case RXRPC_CALL_CLIENT_AWAIT_REPLY: 111 - case RXRPC_CALL_SERVER_AWAIT_ACK: 112 - break; 113 - default: 114 - rxrpc_proto_abort(abort_why, call, call->tx_top); 115 - return false; 116 - } 117 - 118 - rxrpc_rotate_tx_window(call, call->tx_top); 99 + ASSERT(test_bit(RXRPC_CALL_TX_LAST, &call->flags)); 119 100 120 101 write_lock(&call->state_lock); 121 102 122 103 switch (call->state) { 123 - default: 124 - break; 104 + case RXRPC_CALL_CLIENT_SEND_REQUEST: 125 105 case RXRPC_CALL_CLIENT_AWAIT_REPLY: 126 - call->tx_phase = false; 127 - call->state = RXRPC_CALL_CLIENT_RECV_REPLY; 106 + if (reply_begun) 107 + call->state = RXRPC_CALL_CLIENT_RECV_REPLY; 108 + else 109 + call->state = RXRPC_CALL_CLIENT_AWAIT_REPLY; 128 110 break; 111 + 129 112 case RXRPC_CALL_SERVER_AWAIT_ACK: 130 113 __rxrpc_call_completed(call); 131 114 rxrpc_notify_socket(call); 132 115 break; 116 + 117 + default: 118 + goto bad_state; 133 119 } 134 120 135 121 write_unlock(&call->state_lock); 136 - trace_rxrpc_transmit(call, rxrpc_transmit_end); 122 + if (call->state == RXRPC_CALL_CLIENT_AWAIT_REPLY) { 123 + trace_rxrpc_transmit(call, rxrpc_transmit_await_reply); 124 + } else { 125 + trace_rxrpc_transmit(call, rxrpc_transmit_end); 126 + } 137 127 _leave(" = ok"); 128 + return true; 129 + 130 + bad_state: 131 + write_unlock(&call->state_lock); 132 + kdebug("end_tx %s", rxrpc_call_states[call->state]); 133 + rxrpc_proto_abort(abort_why, call, call->tx_top); 134 + return false; 135 + } 136 + 137 + /* 138 + * Begin the reply reception phase of a call. 139 + */ 140 + static bool rxrpc_receiving_reply(struct rxrpc_call *call) 141 + { 142 + rxrpc_seq_t top = READ_ONCE(call->tx_top); 143 + 144 + if (!test_bit(RXRPC_CALL_TX_LAST, &call->flags)) 145 + rxrpc_rotate_tx_window(call, top); 146 + if (!test_bit(RXRPC_CALL_TX_LAST, &call->flags)) { 147 + rxrpc_proto_abort("TXL", call, top); 148 + return false; 149 + } 150 + if (!rxrpc_end_tx_phase(call, true, "ETD")) 151 + return false; 152 + call->tx_phase = false; 138 153 return true; 139 154 } 140 155 ··· 257 226 /* Received data implicitly ACKs all of the request packets we sent 258 227 * when we're acting as a client. 259 228 */ 260 - if (call->state == RXRPC_CALL_CLIENT_AWAIT_REPLY && 261 - !rxrpc_end_tx_phase(call, "ETD")) 229 + if ((call->state == RXRPC_CALL_CLIENT_SEND_REQUEST || 230 + call->state == RXRPC_CALL_CLIENT_AWAIT_REPLY) && 231 + !rxrpc_receiving_reply(call)) 262 232 return; 263 233 264 234 call->ackr_prev_seq = seq; ··· 383 351 ack: 384 352 if (ack) 385 353 rxrpc_propose_ACK(call, ack, skew, ack_serial, 386 - immediate_ack, true); 354 + immediate_ack, true, 355 + rxrpc_propose_ack_input_data); 387 356 388 357 if (sp->hdr.seq == READ_ONCE(call->rx_hard_ack) + 1) 389 358 rxrpc_notify_socket(call); ··· 512 479 case RXRPC_ACK_TYPE_NACK: 513 480 if (anno_type == RXRPC_TX_ANNO_NAK) 514 481 continue; 482 + if (anno_type == RXRPC_TX_ANNO_RETRANS) 483 + continue; 515 484 call->rxtx_annotations[ix] = 516 485 RXRPC_TX_ANNO_NAK | annotation; 517 486 resend = true; ··· 541 506 static void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb, 542 507 u16 skew) 543 508 { 509 + u8 ack_reason; 544 510 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 545 511 union { 546 512 struct rxrpc_ackpacket ack; ··· 564 528 first_soft_ack = ntohl(buf.ack.firstPacket); 565 529 hard_ack = first_soft_ack - 1; 566 530 nr_acks = buf.ack.nAcks; 531 + ack_reason = (buf.ack.reason < RXRPC_ACK__INVALID ? 532 + buf.ack.reason : RXRPC_ACK__INVALID); 567 533 568 - trace_rxrpc_rx_ack(call, first_soft_ack, buf.ack.reason, nr_acks); 534 + trace_rxrpc_rx_ack(call, first_soft_ack, ack_reason, nr_acks); 569 535 570 536 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }", 571 537 sp->hdr.serial, ··· 575 537 first_soft_ack, 576 538 ntohl(buf.ack.previousPacket), 577 539 acked_serial, 578 - rxrpc_acks(buf.ack.reason), 540 + rxrpc_ack_names[ack_reason], 579 541 buf.ack.nAcks); 580 542 581 543 if (buf.ack.reason == RXRPC_ACK_PING_RESPONSE) ··· 588 550 if (buf.ack.reason == RXRPC_ACK_PING) { 589 551 _proto("Rx ACK %%%u PING Request", sp->hdr.serial); 590 552 rxrpc_propose_ACK(call, RXRPC_ACK_PING_RESPONSE, 591 - skew, sp->hdr.serial, true, true); 553 + skew, sp->hdr.serial, true, true, 554 + rxrpc_propose_ack_respond_to_ping); 592 555 } else if (sp->hdr.flags & RXRPC_REQUEST_ACK) { 593 556 rxrpc_propose_ACK(call, RXRPC_ACK_REQUESTED, 594 - skew, sp->hdr.serial, true, true); 557 + skew, sp->hdr.serial, true, true, 558 + rxrpc_propose_ack_respond_to_ack); 595 559 } 596 560 597 561 offset = sp->offset + nr_acks + 3; ··· 618 578 } 619 579 620 580 /* Discard any out-of-order or duplicate ACKs. */ 621 - if ((int)sp->hdr.serial - (int)call->acks_latest <= 0) { 581 + if (before_eq(sp->hdr.serial, call->acks_latest)) { 622 582 _debug("discard ACK %d <= %d", 623 583 sp->hdr.serial, call->acks_latest); 624 584 return; 625 585 } 626 586 call->acks_latest = sp->hdr.serial; 627 587 628 - if (test_bit(RXRPC_CALL_TX_LAST, &call->flags) && 629 - hard_ack == call->tx_top) { 630 - rxrpc_end_tx_phase(call, "ETA"); 631 - return; 632 - } 633 - 634 588 if (before(hard_ack, call->tx_hard_ack) || 635 589 after(hard_ack, call->tx_top)) 636 590 return rxrpc_proto_abort("AKW", call, 0); 591 + if (nr_acks > call->tx_top - hard_ack) 592 + return rxrpc_proto_abort("AKN", call, 0); 637 593 638 594 if (after(hard_ack, call->tx_hard_ack)) 639 595 rxrpc_rotate_tx_window(call, hard_ack); 640 596 641 - if (after(first_soft_ack, call->tx_top)) 642 - return; 597 + if (nr_acks > 0) { 598 + if (skb_copy_bits(skb, sp->offset, buf.acks, nr_acks) < 0) 599 + return rxrpc_proto_abort("XSA", call, 0); 600 + rxrpc_input_soft_acks(call, buf.acks, first_soft_ack, nr_acks); 601 + } 643 602 644 - if (nr_acks > call->tx_top - first_soft_ack + 1) 645 - nr_acks = first_soft_ack - call->tx_top + 1; 646 - if (skb_copy_bits(skb, sp->offset, buf.acks, nr_acks) < 0) 647 - return rxrpc_proto_abort("XSA", call, 0); 648 - rxrpc_input_soft_acks(call, buf.acks, first_soft_ack, nr_acks); 603 + if (test_bit(RXRPC_CALL_TX_LAST, &call->flags)) { 604 + rxrpc_end_tx_phase(call, false, "ETA"); 605 + return; 606 + } 607 + 649 608 } 650 609 651 610 /* ··· 656 617 657 618 _proto("Rx ACKALL %%%u", sp->hdr.serial); 658 619 659 - rxrpc_end_tx_phase(call, "ETL"); 620 + rxrpc_rotate_tx_window(call, call->tx_top); 621 + if (test_bit(RXRPC_CALL_TX_LAST, &call->flags)) 622 + rxrpc_end_tx_phase(call, false, "ETL"); 660 623 } 661 624 662 625 /* ··· 844 803 skb_orphan(skb); 845 804 sp = rxrpc_skb(skb); 846 805 806 + /* dig out the RxRPC connection details */ 807 + if (rxrpc_extract_header(sp, skb) < 0) 808 + goto bad_message; 809 + 847 810 if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) { 848 811 static int lose; 849 812 if ((lose++ & 7) == 7) { 813 + trace_rxrpc_rx_lose(sp); 850 814 rxrpc_lose_skb(skb, rxrpc_skb_rx_lost); 851 815 return; 852 816 } 853 817 } 854 818 855 - _net("Rx UDP packet from %08x:%04hu", 856 - ntohl(ip_hdr(skb)->saddr), ntohs(udp_hdr(skb)->source)); 857 - 858 - /* dig out the RxRPC connection details */ 859 - if (rxrpc_extract_header(sp, skb) < 0) 860 - goto bad_message; 861 819 trace_rxrpc_rx_packet(sp); 862 820 863 821 _net("Rx RxRPC %s ep=%x call=%x:%x",
+29 -12
net/rxrpc/misc.c
··· 91 91 [RXRPC_ACK_PING] = 9, 92 92 }; 93 93 94 - const char *rxrpc_acks(u8 reason) 95 - { 96 - static const char *const str[] = { 97 - "---", "REQ", "DUP", "OOS", "WIN", "MEM", "PNG", "PNR", "DLY", 98 - "IDL", "-?-" 99 - }; 100 - 101 - if (reason >= ARRAY_SIZE(str)) 102 - reason = ARRAY_SIZE(str) - 1; 103 - return str[reason]; 104 - } 94 + const char const rxrpc_ack_names[RXRPC_ACK__INVALID + 1][4] = { 95 + "---", "REQ", "DUP", "OOS", "WIN", "MEM", "PNG", "PNR", "DLY", 96 + "IDL", "-?-" 97 + }; 105 98 106 99 const char rxrpc_skb_traces[rxrpc_skb__nr_trace][7] = { 107 100 [rxrpc_skb_rx_cleaned] = "Rx CLN", ··· 148 155 const char rxrpc_transmit_traces[rxrpc_transmit__nr_trace][4] = { 149 156 [rxrpc_transmit_wait] = "WAI", 150 157 [rxrpc_transmit_queue] = "QUE", 151 - [rxrpc_transmit_queue_reqack] = "QRA", 152 158 [rxrpc_transmit_queue_last] = "QLS", 153 159 [rxrpc_transmit_rotate] = "ROT", 160 + [rxrpc_transmit_rotate_last] = "RLS", 161 + [rxrpc_transmit_await_reply] = "AWR", 154 162 [rxrpc_transmit_end] = "END", 155 163 }; 156 164 ··· 186 192 const char rxrpc_rtt_rx_traces[rxrpc_rtt_rx__nr_trace][5] = { 187 193 [rxrpc_rtt_rx_ping_response] = "PONG", 188 194 [rxrpc_rtt_rx_requested_ack] = "RACK", 195 + }; 196 + 197 + const char rxrpc_timer_traces[rxrpc_timer__nr_trace][8] = { 198 + [rxrpc_timer_begin] = "Begin ", 199 + [rxrpc_timer_expired] = "*EXPR*", 200 + [rxrpc_timer_set_for_ack] = "SetAck", 201 + [rxrpc_timer_set_for_send] = "SetTx ", 202 + [rxrpc_timer_set_for_resend] = "SetRTx", 203 + }; 204 + 205 + const char rxrpc_propose_ack_traces[rxrpc_propose_ack__nr_trace][8] = { 206 + [rxrpc_propose_ack_input_data] = "DataIn ", 207 + [rxrpc_propose_ack_ping_for_params] = "Params ", 208 + [rxrpc_propose_ack_respond_to_ack] = "Rsp2Ack", 209 + [rxrpc_propose_ack_respond_to_ping] = "Rsp2Png", 210 + [rxrpc_propose_ack_retry_tx] = "RetryTx", 211 + [rxrpc_propose_ack_terminal_ack] = "ClTerm ", 212 + }; 213 + 214 + const char *const rxrpc_propose_ack_outcomes[rxrpc_propose_ack__nr_outcomes] = { 215 + [rxrpc_propose_ack_use] = "", 216 + [rxrpc_propose_ack_update] = " Update", 217 + [rxrpc_propose_ack_subsume] = " Subsume", 189 218 };
+16 -16
net/rxrpc/output.c
··· 80 80 pkt->ackinfo.rwind = htonl(call->rx_winsize); 81 81 pkt->ackinfo.jumbo_max = htonl(jmax); 82 82 83 - trace_rxrpc_tx_ack(call, hard_ack + 1, serial, call->ackr_reason, 84 - top - hard_ack); 85 - 86 83 *ackp++ = 0; 87 84 *ackp++ = 0; 88 85 *ackp++ = 0; ··· 116 119 return -ENOMEM; 117 120 } 118 121 119 - serial = atomic_inc_return(&conn->serial); 120 - 121 122 msg.msg_name = &call->peer->srx.transport; 122 123 msg.msg_namelen = call->peer->srx.transport_len; 123 124 msg.msg_control = NULL; ··· 126 131 pkt->whdr.cid = htonl(call->cid); 127 132 pkt->whdr.callNumber = htonl(call->call_id); 128 133 pkt->whdr.seq = 0; 129 - pkt->whdr.serial = htonl(serial); 130 134 pkt->whdr.type = type; 131 135 pkt->whdr.flags = conn->out_clientflag; 132 136 pkt->whdr.userStatus = 0; ··· 151 157 152 158 spin_unlock_bh(&call->lock); 153 159 154 - _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }", 155 - serial, 156 - ntohs(pkt->ack.maxSkew), 157 - ntohl(pkt->ack.firstPacket), 158 - ntohl(pkt->ack.previousPacket), 159 - ntohl(pkt->ack.serial), 160 - rxrpc_acks(pkt->ack.reason), 161 - pkt->ack.nAcks); 162 160 163 161 iov[0].iov_len += sizeof(pkt->ack) + n; 164 162 iov[1].iov_base = &pkt->ackinfo; ··· 162 176 case RXRPC_PACKET_TYPE_ABORT: 163 177 abort_code = call->abort_code; 164 178 pkt->abort_code = htonl(abort_code); 165 - _proto("Tx ABORT %%%u { %d }", serial, abort_code); 166 179 iov[0].iov_len += sizeof(pkt->abort_code); 167 180 len += sizeof(pkt->abort_code); 168 181 ioc = 1; ··· 171 186 BUG(); 172 187 ret = -ENOANO; 173 188 goto out; 189 + } 190 + 191 + serial = atomic_inc_return(&conn->serial); 192 + pkt->whdr.serial = htonl(serial); 193 + switch (type) { 194 + case RXRPC_PACKET_TYPE_ACK: 195 + trace_rxrpc_tx_ack(call, serial, 196 + ntohl(pkt->ack.firstPacket), 197 + ntohl(pkt->ack.serial), 198 + pkt->ack.reason, pkt->ack.nAcks); 199 + break; 174 200 } 175 201 176 202 if (ping) { ··· 210 214 rxrpc_propose_ACK(call, pkt->ack.reason, 211 215 ntohs(pkt->ack.maxSkew), 212 216 ntohl(pkt->ack.serial), 213 - true, true); 217 + true, true, 218 + rxrpc_propose_ack_retry_tx); 214 219 break; 215 220 case RXRPC_PACKET_TYPE_ABORT: 216 221 break; ··· 276 279 if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) { 277 280 static int lose; 278 281 if ((lose++ & 7) == 7) { 282 + trace_rxrpc_tx_data(call, sp->hdr.seq, serial, 283 + whdr.flags, true); 279 284 rxrpc_lose_skb(skb, rxrpc_skb_tx_lost); 280 285 _leave(" = 0 [lose]"); 281 286 return 0; ··· 305 306 goto send_fragmentable; 306 307 307 308 done: 309 + trace_rxrpc_tx_data(call, sp->hdr.seq, serial, whdr.flags, false); 308 310 if (ret >= 0) { 309 311 ktime_t now = ktime_get_real(); 310 312 skb->tstamp = now;
+2 -3
net/rxrpc/recvmsg.c
··· 141 141 ASSERTCMP(call->rx_hard_ack, ==, call->rx_top); 142 142 143 143 if (call->state == RXRPC_CALL_CLIENT_RECV_REPLY) { 144 - rxrpc_propose_ACK(call, RXRPC_ACK_IDLE, 0, 0, true, false); 144 + rxrpc_propose_ACK(call, RXRPC_ACK_IDLE, 0, 0, true, false, 145 + rxrpc_propose_ack_terminal_ack); 145 146 rxrpc_send_call_packet(call, RXRPC_PACKET_TYPE_ACK); 146 - } else { 147 - rxrpc_propose_ACK(call, RXRPC_ACK_IDLE, 0, 0, false, false); 148 147 } 149 148 150 149 write_lock_bh(&call->state_lock);
+21 -7
net/rxrpc/sendmsg.c
··· 94 94 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 95 95 rxrpc_seq_t seq = sp->hdr.seq; 96 96 int ret, ix; 97 + u8 annotation = RXRPC_TX_ANNO_UNACK; 97 98 98 99 _net("queue skb %p [%d]", skb, seq); 99 100 100 101 ASSERTCMP(seq, ==, call->tx_top + 1); 101 102 103 + if (last) 104 + annotation |= RXRPC_TX_ANNO_LAST; 105 + 106 + /* We have to set the timestamp before queueing as the retransmit 107 + * algorithm can see the packet as soon as we queue it. 108 + */ 109 + skb->tstamp = ktime_get_real(); 110 + 102 111 ix = seq & RXRPC_RXTX_BUFF_MASK; 103 112 rxrpc_get_skb(skb, rxrpc_skb_tx_got); 104 - call->rxtx_annotations[ix] = RXRPC_TX_ANNO_UNACK; 113 + call->rxtx_annotations[ix] = annotation; 105 114 smp_wmb(); 106 115 call->rxtx_buffer[ix] = skb; 107 116 call->tx_top = seq; 108 - if (last) { 109 - set_bit(RXRPC_CALL_TX_LAST, &call->flags); 117 + if (last) 110 118 trace_rxrpc_transmit(call, rxrpc_transmit_queue_last); 111 - } else if (sp->hdr.flags & RXRPC_REQUEST_ACK) { 112 - trace_rxrpc_transmit(call, rxrpc_transmit_queue_reqack); 113 - } else { 119 + else 114 120 trace_rxrpc_transmit(call, rxrpc_transmit_queue); 115 - } 116 121 117 122 if (last || call->state == RXRPC_CALL_SERVER_ACK_REQUEST) { 118 123 _debug("________awaiting reply/ACK__________"); ··· 146 141 if (ret < 0) { 147 142 _debug("need instant resend %d", ret); 148 143 rxrpc_instant_resend(call, ix); 144 + } else { 145 + unsigned long resend_at; 146 + 147 + resend_at = jiffies + msecs_to_jiffies(rxrpc_resend_timeout); 148 + 149 + if (time_before(resend_at, call->resend_at)) { 150 + call->resend_at = resend_at; 151 + rxrpc_set_timer(call, rxrpc_timer_set_for_send); 152 + } 149 153 } 150 154 151 155 rxrpc_free_skb(skb, rxrpc_skb_tx_freed);