2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2007-04-27 06:48:28 +08:00
|
|
|
/* 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)
|
|
|
|
*/
|
|
|
|
|
2016-06-03 03:08:52 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2007-04-27 06:48:28 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/circ_buf.h>
|
|
|
|
#include <linux/net.h>
|
|
|
|
#include <linux/skbuff.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2007-04-27 06:48:28 +08:00
|
|
|
#include <linux/udp.h>
|
|
|
|
#include <net/sock.h>
|
|
|
|
#include <net/af_rxrpc.h>
|
|
|
|
#include "ar-internal.h"
|
|
|
|
|
2016-10-06 15:11:49 +08:00
|
|
|
/*
|
|
|
|
* Propose a PING ACK be sent.
|
|
|
|
*/
|
2020-01-31 05:48:13 +08:00
|
|
|
void rxrpc_propose_ping(struct rxrpc_call *call, u32 serial,
|
|
|
|
enum rxrpc_propose_ack_trace why)
|
2016-10-06 15:11:49 +08:00
|
|
|
{
|
2020-01-31 05:48:13 +08:00
|
|
|
unsigned long now = jiffies;
|
|
|
|
unsigned long ping_at = now + rxrpc_idle_ack_delay;
|
2016-10-06 15:11:49 +08:00
|
|
|
|
2020-01-31 05:48:13 +08:00
|
|
|
if (time_before(ping_at, call->ping_at)) {
|
|
|
|
WRITE_ONCE(call->ping_at, ping_at);
|
|
|
|
rxrpc_reduce_call_timer(call, ping_at, now,
|
|
|
|
rxrpc_timer_set_for_ping);
|
2020-01-31 05:48:14 +08:00
|
|
|
trace_rxrpc_propose_ack(call, why, RXRPC_ACK_PING, serial);
|
2016-10-06 15:11:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-27 06:48:28 +08:00
|
|
|
/*
|
2020-01-31 05:48:14 +08:00
|
|
|
* Propose a DELAY ACK be sent in the future.
|
2007-04-27 06:48:28 +08:00
|
|
|
*/
|
2022-05-06 23:13:13 +08:00
|
|
|
void rxrpc_propose_delay_ACK(struct rxrpc_call *call, rxrpc_serial_t serial,
|
|
|
|
enum rxrpc_propose_ack_trace why)
|
2007-04-27 06:48:28 +08:00
|
|
|
{
|
2017-11-24 18:18:41 +08:00
|
|
|
unsigned long expiry = rxrpc_soft_ack_delay;
|
2020-01-31 05:48:13 +08:00
|
|
|
unsigned long now = jiffies, ack_at;
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2020-01-31 05:48:14 +08:00
|
|
|
call->ackr_serial = serial;
|
2020-01-31 05:48:13 +08:00
|
|
|
|
2020-01-31 05:48:14 +08:00
|
|
|
if (rxrpc_soft_ack_delay < expiry)
|
|
|
|
expiry = rxrpc_soft_ack_delay;
|
2020-01-31 05:48:13 +08:00
|
|
|
if (call->peer->srtt_us != 0)
|
|
|
|
ack_at = usecs_to_jiffies(call->peer->srtt_us >> 3);
|
|
|
|
else
|
|
|
|
ack_at = expiry;
|
|
|
|
|
|
|
|
ack_at += READ_ONCE(call->tx_backoff);
|
|
|
|
ack_at += now;
|
2020-01-31 05:48:14 +08:00
|
|
|
if (time_before(ack_at, call->delay_ack_at)) {
|
|
|
|
WRITE_ONCE(call->delay_ack_at, ack_at);
|
2020-01-31 05:48:13 +08:00
|
|
|
rxrpc_reduce_call_timer(call, ack_at, now,
|
|
|
|
rxrpc_timer_set_for_ack);
|
2007-04-27 06:48:28 +08:00
|
|
|
}
|
2016-09-23 20:50:40 +08:00
|
|
|
|
2020-01-31 05:48:14 +08:00
|
|
|
trace_rxrpc_propose_ack(call, why, RXRPC_ACK_DELAY, serial);
|
2007-04-27 06:48:28 +08:00
|
|
|
}
|
|
|
|
|
2020-01-31 05:48:13 +08:00
|
|
|
/*
|
|
|
|
* Queue an ACK for immediate transmission.
|
|
|
|
*/
|
|
|
|
void rxrpc_send_ACK(struct rxrpc_call *call, u8 ack_reason,
|
|
|
|
rxrpc_serial_t serial, enum rxrpc_propose_ack_trace why)
|
|
|
|
{
|
|
|
|
struct rxrpc_txbuf *txb;
|
|
|
|
|
|
|
|
if (test_bit(RXRPC_CALL_DISCONNECTED, &call->flags))
|
|
|
|
return;
|
|
|
|
|
|
|
|
rxrpc_inc_stat(call->rxnet, stat_tx_acks[ack_reason]);
|
|
|
|
|
|
|
|
txb = rxrpc_alloc_txbuf(call, RXRPC_PACKET_TYPE_ACK,
|
2022-10-10 17:55:24 +08:00
|
|
|
rcu_read_lock_held() ? GFP_ATOMIC | __GFP_NOWARN : GFP_NOFS);
|
2020-01-31 05:48:13 +08:00
|
|
|
if (!txb) {
|
|
|
|
kleave(" = -ENOMEM");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
txb->ack_why = why;
|
|
|
|
txb->wire.seq = 0;
|
|
|
|
txb->wire.type = RXRPC_PACKET_TYPE_ACK;
|
|
|
|
txb->wire.flags |= RXRPC_SLOW_START_OK;
|
|
|
|
txb->ack.bufferSpace = 0;
|
|
|
|
txb->ack.maxSkew = 0;
|
|
|
|
txb->ack.firstPacket = 0;
|
|
|
|
txb->ack.previousPacket = 0;
|
|
|
|
txb->ack.serial = htonl(serial);
|
|
|
|
txb->ack.reason = ack_reason;
|
|
|
|
txb->ack.nAcks = 0;
|
|
|
|
|
|
|
|
trace_rxrpc_send_ack(call, why, ack_reason, serial);
|
2020-01-31 05:48:13 +08:00
|
|
|
rxrpc_send_ack_packet(call, txb);
|
|
|
|
rxrpc_put_txbuf(txb, rxrpc_txbuf_put_ack_tx);
|
2020-01-31 05:48:13 +08:00
|
|
|
}
|
|
|
|
|
2016-09-25 01:05:27 +08:00
|
|
|
/*
|
|
|
|
* Handle congestion being detected by the retransmit timeout.
|
|
|
|
*/
|
|
|
|
static void rxrpc_congestion_timeout(struct rxrpc_call *call)
|
|
|
|
{
|
|
|
|
set_bit(RXRPC_CALL_RETRANS_TIMEOUT, &call->flags);
|
|
|
|
}
|
|
|
|
|
2007-04-27 06:48:28 +08:00
|
|
|
/*
|
rxrpc: Rewrite the data and ack handling code
Rewrite the data and ack handling code such that:
(1) Parsing of received ACK and ABORT packets and the distribution and the
filing of DATA packets happens entirely within the data_ready context
called from the UDP socket. This allows us to process and discard ACK
and ABORT packets much more quickly (they're no longer stashed on a
queue for a background thread to process).
(2) We avoid calling skb_clone(), pskb_pull() and pskb_trim(). We instead
keep track of the offset and length of the content of each packet in
the sk_buff metadata. This means we don't do any allocation in the
receive path.
(3) Jumbo DATA packet parsing is now done in data_ready context. Rather
than cloning the packet once for each subpacket and pulling/trimming
it, we file the packet multiple times with an annotation for each
indicating which subpacket is there. From that we can directly
calculate the offset and length.
(4) A call's receive queue can be accessed without taking locks (memory
barriers do have to be used, though).
(5) Incoming calls are set up from preallocated resources and immediately
made live. They can than have packets queued upon them and ACKs
generated. If insufficient resources exist, DATA packet #1 is given a
BUSY reply and other DATA packets are discarded).
(6) sk_buffs no longer take a ref on their parent call.
To make this work, the following changes are made:
(1) Each call's receive buffer is now a circular buffer of sk_buff
pointers (rxtx_buffer) rather than a number of sk_buff_heads spread
between the call and the socket. This permits each sk_buff to be in
the buffer multiple times. The receive buffer is reused for the
transmit buffer.
(2) A circular buffer of annotations (rxtx_annotations) is kept parallel
to the data buffer. Transmission phase annotations indicate whether a
buffered packet has been ACK'd or not and whether it needs
retransmission.
Receive phase annotations indicate whether a slot holds a whole packet
or a jumbo subpacket and, if the latter, which subpacket. They also
note whether the packet has been decrypted in place.
(3) DATA packet window tracking is much simplified. Each phase has just
two numbers representing the window (rx_hard_ack/rx_top and
tx_hard_ack/tx_top).
The hard_ack number is the sequence number before base of the window,
representing the last packet the other side says it has consumed.
hard_ack starts from 0 and the first packet is sequence number 1.
The top number is the sequence number of the highest-numbered packet
residing in the buffer. Packets between hard_ack+1 and top are
soft-ACK'd to indicate they've been received, but not yet consumed.
Four macros, before(), before_eq(), after() and after_eq() are added
to compare sequence numbers within the window. This allows for the
top of the window to wrap when the hard-ack sequence number gets close
to the limit.
Two flags, RXRPC_CALL_RX_LAST and RXRPC_CALL_TX_LAST, are added also
to indicate when rx_top and tx_top point at the packets with the
LAST_PACKET bit set, indicating the end of the phase.
(4) Calls are queued on the socket 'receive queue' rather than packets.
This means that we don't need have to invent dummy packets to queue to
indicate abnormal/terminal states and we don't have to keep metadata
packets (such as ABORTs) around
(5) The offset and length of a (sub)packet's content are now passed to
the verify_packet security op. This is currently expected to decrypt
the packet in place and validate it.
However, there's now nowhere to store the revised offset and length of
the actual data within the decrypted blob (there may be a header and
padding to skip) because an sk_buff may represent multiple packets, so
a locate_data security op is added to retrieve these details from the
sk_buff content when needed.
(6) recvmsg() now has to handle jumbo subpackets, where each subpacket is
individually secured and needs to be individually decrypted. The code
to do this is broken out into rxrpc_recvmsg_data() and shared with the
kernel API. It now iterates over the call's receive buffer rather
than walking the socket receive queue.
Additional changes:
(1) The timers are condensed to a single timer that is set for the soonest
of three timeouts (delayed ACK generation, DATA retransmission and
call lifespan).
(2) Transmission of ACK and ABORT packets is effected immediately from
process-context socket ops/kernel API calls that cause them instead of
them being punted off to a background work item. The data_ready
handler still has to defer to the background, though.
(3) A shutdown op is added to the AF_RXRPC socket so that the AFS
filesystem can shut down the socket and flush its own work items
before closing the socket to deal with any in-progress service calls.
Future additional changes that will need to be considered:
(1) Make sure that a call doesn't hog the front of the queue by receiving
data from the network as fast as userspace is consuming it to the
exclusion of other calls.
(2) Transmit delayed ACKs from within recvmsg() when we've consumed
sufficiently more packets to avoid the background work item needing to
run.
Signed-off-by: David Howells <dhowells@redhat.com>
2016-09-08 18:10:12 +08:00
|
|
|
* Perform retransmission of NAK'd and unack'd packets.
|
2007-04-27 06:48:28 +08:00
|
|
|
*/
|
2020-01-23 21:13:41 +08:00
|
|
|
void rxrpc_resend(struct rxrpc_call *call, struct sk_buff *ack_skb)
|
2007-04-27 06:48:28 +08:00
|
|
|
{
|
2022-05-07 17:06:13 +08:00
|
|
|
struct rxrpc_ackpacket *ack = NULL;
|
2022-04-01 06:55:08 +08:00
|
|
|
struct rxrpc_txbuf *txb;
|
rxrpc: Adjust retransmission backoff
Improve retransmission backoff by only backing off when we retransmit data
packets rather than when we set the lost ack timer.
To this end:
(1) In rxrpc_resend(), use rxrpc_get_rto_backoff() when setting the
retransmission timer and only tell it that we are retransmitting if we
actually have things to retransmit.
Note that it's possible for the retransmission algorithm to race with
the processing of a received ACK, so we may see no packets needing
retransmission.
(2) In rxrpc_send_data_packet(), don't bump the backoff when setting the
ack_lost_at timer, as it may then get bumped twice.
With this, when looking at one particular packet, the retransmission
intervals were seen to be 1.5ms, 2ms, 3ms, 5ms, 9ms, 17ms, 33ms, 71ms,
136ms, 264ms, 544ms, 1.088s, 2.1s, 4.2s and 8.3s.
Fixes: c410bf01933e ("rxrpc: Fix the excessive initial retransmission timeout")
Suggested-by: Marc Dionne <marc.dionne@auristor.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Marc Dionne <marc.dionne@auristor.com>
Tested-by: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
Link: https://lore.kernel.org/r/164138117069.2023386.17446904856843997127.stgit@warthog.procyon.org.uk/
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-01-22 07:12:58 +08:00
|
|
|
unsigned long resend_at;
|
2022-04-01 06:55:08 +08:00
|
|
|
rxrpc_seq_t transmitted = READ_ONCE(call->tx_transmitted);
|
2020-05-11 21:54:34 +08:00
|
|
|
ktime_t now, max_age, oldest, ack_ts;
|
2022-04-01 06:55:08 +08:00
|
|
|
bool unacked = false;
|
2022-05-07 17:06:13 +08:00
|
|
|
unsigned int i;
|
2022-04-01 06:55:08 +08:00
|
|
|
LIST_HEAD(retrans_queue);
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2022-04-01 06:55:08 +08:00
|
|
|
_enter("{%d,%d}", call->acks_hard_ack, call->tx_top);
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2017-11-24 18:18:41 +08:00
|
|
|
now = ktime_get_real();
|
2022-04-05 20:34:09 +08:00
|
|
|
max_age = ktime_sub_us(now, jiffies_to_usecs(call->peer->rto_j));
|
2022-05-07 17:06:13 +08:00
|
|
|
oldest = now;
|
|
|
|
|
|
|
|
if (list_empty(&call->tx_buffer))
|
|
|
|
goto no_resend;
|
2016-09-22 07:29:31 +08:00
|
|
|
|
2022-05-07 17:06:13 +08:00
|
|
|
if (list_empty(&call->tx_buffer))
|
|
|
|
goto no_further_resend;
|
|
|
|
|
2020-01-23 21:13:41 +08:00
|
|
|
trace_rxrpc_resend(call, ack_skb);
|
2022-05-07 17:06:13 +08:00
|
|
|
txb = list_first_entry(&call->tx_buffer, struct rxrpc_txbuf, call_link);
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2022-05-07 17:06:13 +08:00
|
|
|
/* Scan the soft ACK table without dropping the lock and resend any
|
|
|
|
* explicitly NAK'd packets.
|
|
|
|
*/
|
2020-01-23 21:13:41 +08:00
|
|
|
if (ack_skb) {
|
|
|
|
ack = (void *)ack_skb->data + sizeof(struct rxrpc_wire_header);
|
|
|
|
|
2022-05-07 17:06:13 +08:00
|
|
|
for (i = 0; i < ack->nAcks; i++) {
|
|
|
|
rxrpc_seq_t seq;
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2022-05-07 17:06:13 +08:00
|
|
|
if (ack->acks[i] & 1)
|
rxrpc: Rewrite the data and ack handling code
Rewrite the data and ack handling code such that:
(1) Parsing of received ACK and ABORT packets and the distribution and the
filing of DATA packets happens entirely within the data_ready context
called from the UDP socket. This allows us to process and discard ACK
and ABORT packets much more quickly (they're no longer stashed on a
queue for a background thread to process).
(2) We avoid calling skb_clone(), pskb_pull() and pskb_trim(). We instead
keep track of the offset and length of the content of each packet in
the sk_buff metadata. This means we don't do any allocation in the
receive path.
(3) Jumbo DATA packet parsing is now done in data_ready context. Rather
than cloning the packet once for each subpacket and pulling/trimming
it, we file the packet multiple times with an annotation for each
indicating which subpacket is there. From that we can directly
calculate the offset and length.
(4) A call's receive queue can be accessed without taking locks (memory
barriers do have to be used, though).
(5) Incoming calls are set up from preallocated resources and immediately
made live. They can than have packets queued upon them and ACKs
generated. If insufficient resources exist, DATA packet #1 is given a
BUSY reply and other DATA packets are discarded).
(6) sk_buffs no longer take a ref on their parent call.
To make this work, the following changes are made:
(1) Each call's receive buffer is now a circular buffer of sk_buff
pointers (rxtx_buffer) rather than a number of sk_buff_heads spread
between the call and the socket. This permits each sk_buff to be in
the buffer multiple times. The receive buffer is reused for the
transmit buffer.
(2) A circular buffer of annotations (rxtx_annotations) is kept parallel
to the data buffer. Transmission phase annotations indicate whether a
buffered packet has been ACK'd or not and whether it needs
retransmission.
Receive phase annotations indicate whether a slot holds a whole packet
or a jumbo subpacket and, if the latter, which subpacket. They also
note whether the packet has been decrypted in place.
(3) DATA packet window tracking is much simplified. Each phase has just
two numbers representing the window (rx_hard_ack/rx_top and
tx_hard_ack/tx_top).
The hard_ack number is the sequence number before base of the window,
representing the last packet the other side says it has consumed.
hard_ack starts from 0 and the first packet is sequence number 1.
The top number is the sequence number of the highest-numbered packet
residing in the buffer. Packets between hard_ack+1 and top are
soft-ACK'd to indicate they've been received, but not yet consumed.
Four macros, before(), before_eq(), after() and after_eq() are added
to compare sequence numbers within the window. This allows for the
top of the window to wrap when the hard-ack sequence number gets close
to the limit.
Two flags, RXRPC_CALL_RX_LAST and RXRPC_CALL_TX_LAST, are added also
to indicate when rx_top and tx_top point at the packets with the
LAST_PACKET bit set, indicating the end of the phase.
(4) Calls are queued on the socket 'receive queue' rather than packets.
This means that we don't need have to invent dummy packets to queue to
indicate abnormal/terminal states and we don't have to keep metadata
packets (such as ABORTs) around
(5) The offset and length of a (sub)packet's content are now passed to
the verify_packet security op. This is currently expected to decrypt
the packet in place and validate it.
However, there's now nowhere to store the revised offset and length of
the actual data within the decrypted blob (there may be a header and
padding to skip) because an sk_buff may represent multiple packets, so
a locate_data security op is added to retrieve these details from the
sk_buff content when needed.
(6) recvmsg() now has to handle jumbo subpackets, where each subpacket is
individually secured and needs to be individually decrypted. The code
to do this is broken out into rxrpc_recvmsg_data() and shared with the
kernel API. It now iterates over the call's receive buffer rather
than walking the socket receive queue.
Additional changes:
(1) The timers are condensed to a single timer that is set for the soonest
of three timeouts (delayed ACK generation, DATA retransmission and
call lifespan).
(2) Transmission of ACK and ABORT packets is effected immediately from
process-context socket ops/kernel API calls that cause them instead of
them being punted off to a background work item. The data_ready
handler still has to defer to the background, though.
(3) A shutdown op is added to the AF_RXRPC socket so that the AFS
filesystem can shut down the socket and flush its own work items
before closing the socket to deal with any in-progress service calls.
Future additional changes that will need to be considered:
(1) Make sure that a call doesn't hog the front of the queue by receiving
data from the network as fast as userspace is consuming it to the
exclusion of other calls.
(2) Transmit delayed ACKs from within recvmsg() when we've consumed
sufficiently more packets to avoid the background work item needing to
run.
Signed-off-by: David Howells <dhowells@redhat.com>
2016-09-08 18:10:12 +08:00
|
|
|
continue;
|
2022-05-07 17:06:13 +08:00
|
|
|
seq = ntohl(ack->firstPacket) + i;
|
|
|
|
if (after(txb->seq, transmitted))
|
|
|
|
break;
|
|
|
|
if (after(txb->seq, seq))
|
|
|
|
continue; /* A new hard ACK probably came in */
|
|
|
|
list_for_each_entry_from(txb, &call->tx_buffer, call_link) {
|
|
|
|
if (txb->seq == seq)
|
|
|
|
goto found_txb;
|
|
|
|
}
|
|
|
|
goto no_further_resend;
|
|
|
|
|
|
|
|
found_txb:
|
|
|
|
if (after(ntohl(txb->wire.serial), call->acks_highest_serial))
|
|
|
|
continue; /* Ack point not yet reached */
|
|
|
|
|
|
|
|
rxrpc_see_txbuf(txb, rxrpc_txbuf_see_unacked);
|
|
|
|
|
|
|
|
if (list_empty(&txb->tx_link)) {
|
|
|
|
list_add_tail(&txb->tx_link, &retrans_queue);
|
|
|
|
set_bit(RXRPC_TXBUF_RESENT, &txb->flags);
|
2015-11-24 22:41:59 +08:00
|
|
|
}
|
2022-05-07 17:06:13 +08:00
|
|
|
|
|
|
|
trace_rxrpc_retransmit(call, txb->seq,
|
|
|
|
ktime_to_ns(ktime_sub(txb->last_sent,
|
|
|
|
max_age)));
|
|
|
|
|
|
|
|
if (list_is_last(&txb->call_link, &call->tx_buffer))
|
|
|
|
goto no_further_resend;
|
|
|
|
txb = list_next_entry(txb, call_link);
|
2007-04-27 06:48:28 +08:00
|
|
|
}
|
2022-05-07 17:06:13 +08:00
|
|
|
}
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2022-05-07 17:06:13 +08:00
|
|
|
/* Fast-forward through the Tx queue to the point the peer says it has
|
|
|
|
* seen. Anything between the soft-ACK table and that point will get
|
|
|
|
* ACK'd or NACK'd in due course, so don't worry about it here; here we
|
|
|
|
* need to consider retransmitting anything beyond that point.
|
|
|
|
*
|
|
|
|
* Note that ACK for a packet can beat the update of tx_transmitted.
|
|
|
|
*/
|
|
|
|
if (after_eq(READ_ONCE(call->acks_prev_seq), READ_ONCE(call->tx_transmitted)))
|
|
|
|
goto no_further_resend;
|
|
|
|
|
|
|
|
list_for_each_entry_from(txb, &call->tx_buffer, call_link) {
|
|
|
|
if (before_eq(txb->seq, READ_ONCE(call->acks_prev_seq)))
|
|
|
|
continue;
|
|
|
|
if (after(txb->seq, READ_ONCE(call->tx_transmitted)))
|
|
|
|
break; /* Not transmitted yet */
|
|
|
|
|
|
|
|
if (ack && ack->reason == RXRPC_ACK_PING_RESPONSE &&
|
|
|
|
before(ntohl(txb->wire.serial), ntohl(ack->serial)))
|
|
|
|
goto do_resend; /* Wasn't accounted for by a more recent ping. */
|
|
|
|
|
|
|
|
if (ktime_after(txb->last_sent, max_age)) {
|
|
|
|
if (ktime_before(txb->last_sent, oldest))
|
|
|
|
oldest = txb->last_sent;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_resend:
|
|
|
|
unacked = true;
|
|
|
|
if (list_empty(&txb->tx_link)) {
|
|
|
|
list_add_tail(&txb->tx_link, &retrans_queue);
|
|
|
|
set_bit(RXRPC_TXBUF_RESENT, &txb->flags);
|
|
|
|
rxrpc_inc_stat(call->rxnet, stat_tx_data_retrans);
|
|
|
|
}
|
2016-09-17 17:49:12 +08:00
|
|
|
}
|
rxrpc: Rewrite the data and ack handling code
Rewrite the data and ack handling code such that:
(1) Parsing of received ACK and ABORT packets and the distribution and the
filing of DATA packets happens entirely within the data_ready context
called from the UDP socket. This allows us to process and discard ACK
and ABORT packets much more quickly (they're no longer stashed on a
queue for a background thread to process).
(2) We avoid calling skb_clone(), pskb_pull() and pskb_trim(). We instead
keep track of the offset and length of the content of each packet in
the sk_buff metadata. This means we don't do any allocation in the
receive path.
(3) Jumbo DATA packet parsing is now done in data_ready context. Rather
than cloning the packet once for each subpacket and pulling/trimming
it, we file the packet multiple times with an annotation for each
indicating which subpacket is there. From that we can directly
calculate the offset and length.
(4) A call's receive queue can be accessed without taking locks (memory
barriers do have to be used, though).
(5) Incoming calls are set up from preallocated resources and immediately
made live. They can than have packets queued upon them and ACKs
generated. If insufficient resources exist, DATA packet #1 is given a
BUSY reply and other DATA packets are discarded).
(6) sk_buffs no longer take a ref on their parent call.
To make this work, the following changes are made:
(1) Each call's receive buffer is now a circular buffer of sk_buff
pointers (rxtx_buffer) rather than a number of sk_buff_heads spread
between the call and the socket. This permits each sk_buff to be in
the buffer multiple times. The receive buffer is reused for the
transmit buffer.
(2) A circular buffer of annotations (rxtx_annotations) is kept parallel
to the data buffer. Transmission phase annotations indicate whether a
buffered packet has been ACK'd or not and whether it needs
retransmission.
Receive phase annotations indicate whether a slot holds a whole packet
or a jumbo subpacket and, if the latter, which subpacket. They also
note whether the packet has been decrypted in place.
(3) DATA packet window tracking is much simplified. Each phase has just
two numbers representing the window (rx_hard_ack/rx_top and
tx_hard_ack/tx_top).
The hard_ack number is the sequence number before base of the window,
representing the last packet the other side says it has consumed.
hard_ack starts from 0 and the first packet is sequence number 1.
The top number is the sequence number of the highest-numbered packet
residing in the buffer. Packets between hard_ack+1 and top are
soft-ACK'd to indicate they've been received, but not yet consumed.
Four macros, before(), before_eq(), after() and after_eq() are added
to compare sequence numbers within the window. This allows for the
top of the window to wrap when the hard-ack sequence number gets close
to the limit.
Two flags, RXRPC_CALL_RX_LAST and RXRPC_CALL_TX_LAST, are added also
to indicate when rx_top and tx_top point at the packets with the
LAST_PACKET bit set, indicating the end of the phase.
(4) Calls are queued on the socket 'receive queue' rather than packets.
This means that we don't need have to invent dummy packets to queue to
indicate abnormal/terminal states and we don't have to keep metadata
packets (such as ABORTs) around
(5) The offset and length of a (sub)packet's content are now passed to
the verify_packet security op. This is currently expected to decrypt
the packet in place and validate it.
However, there's now nowhere to store the revised offset and length of
the actual data within the decrypted blob (there may be a header and
padding to skip) because an sk_buff may represent multiple packets, so
a locate_data security op is added to retrieve these details from the
sk_buff content when needed.
(6) recvmsg() now has to handle jumbo subpackets, where each subpacket is
individually secured and needs to be individually decrypted. The code
to do this is broken out into rxrpc_recvmsg_data() and shared with the
kernel API. It now iterates over the call's receive buffer rather
than walking the socket receive queue.
Additional changes:
(1) The timers are condensed to a single timer that is set for the soonest
of three timeouts (delayed ACK generation, DATA retransmission and
call lifespan).
(2) Transmission of ACK and ABORT packets is effected immediately from
process-context socket ops/kernel API calls that cause them instead of
them being punted off to a background work item. The data_ready
handler still has to defer to the background, though.
(3) A shutdown op is added to the AF_RXRPC socket so that the AFS
filesystem can shut down the socket and flush its own work items
before closing the socket to deal with any in-progress service calls.
Future additional changes that will need to be considered:
(1) Make sure that a call doesn't hog the front of the queue by receiving
data from the network as fast as userspace is consuming it to the
exclusion of other calls.
(2) Transmit delayed ACKs from within recvmsg() when we've consumed
sufficiently more packets to avoid the background work item needing to
run.
Signed-off-by: David Howells <dhowells@redhat.com>
2016-09-08 18:10:12 +08:00
|
|
|
|
2022-05-07 17:06:13 +08:00
|
|
|
no_further_resend:
|
|
|
|
no_resend:
|
2018-03-31 04:04:44 +08:00
|
|
|
resend_at = nsecs_to_jiffies(ktime_to_ns(ktime_sub(now, oldest)));
|
2022-04-01 06:55:08 +08:00
|
|
|
resend_at += jiffies + rxrpc_get_rto_backoff(call->peer,
|
|
|
|
!list_empty(&retrans_queue));
|
2017-11-24 18:18:41 +08:00
|
|
|
WRITE_ONCE(call->resend_at, resend_at);
|
rxrpc: Rewrite the data and ack handling code
Rewrite the data and ack handling code such that:
(1) Parsing of received ACK and ABORT packets and the distribution and the
filing of DATA packets happens entirely within the data_ready context
called from the UDP socket. This allows us to process and discard ACK
and ABORT packets much more quickly (they're no longer stashed on a
queue for a background thread to process).
(2) We avoid calling skb_clone(), pskb_pull() and pskb_trim(). We instead
keep track of the offset and length of the content of each packet in
the sk_buff metadata. This means we don't do any allocation in the
receive path.
(3) Jumbo DATA packet parsing is now done in data_ready context. Rather
than cloning the packet once for each subpacket and pulling/trimming
it, we file the packet multiple times with an annotation for each
indicating which subpacket is there. From that we can directly
calculate the offset and length.
(4) A call's receive queue can be accessed without taking locks (memory
barriers do have to be used, though).
(5) Incoming calls are set up from preallocated resources and immediately
made live. They can than have packets queued upon them and ACKs
generated. If insufficient resources exist, DATA packet #1 is given a
BUSY reply and other DATA packets are discarded).
(6) sk_buffs no longer take a ref on their parent call.
To make this work, the following changes are made:
(1) Each call's receive buffer is now a circular buffer of sk_buff
pointers (rxtx_buffer) rather than a number of sk_buff_heads spread
between the call and the socket. This permits each sk_buff to be in
the buffer multiple times. The receive buffer is reused for the
transmit buffer.
(2) A circular buffer of annotations (rxtx_annotations) is kept parallel
to the data buffer. Transmission phase annotations indicate whether a
buffered packet has been ACK'd or not and whether it needs
retransmission.
Receive phase annotations indicate whether a slot holds a whole packet
or a jumbo subpacket and, if the latter, which subpacket. They also
note whether the packet has been decrypted in place.
(3) DATA packet window tracking is much simplified. Each phase has just
two numbers representing the window (rx_hard_ack/rx_top and
tx_hard_ack/tx_top).
The hard_ack number is the sequence number before base of the window,
representing the last packet the other side says it has consumed.
hard_ack starts from 0 and the first packet is sequence number 1.
The top number is the sequence number of the highest-numbered packet
residing in the buffer. Packets between hard_ack+1 and top are
soft-ACK'd to indicate they've been received, but not yet consumed.
Four macros, before(), before_eq(), after() and after_eq() are added
to compare sequence numbers within the window. This allows for the
top of the window to wrap when the hard-ack sequence number gets close
to the limit.
Two flags, RXRPC_CALL_RX_LAST and RXRPC_CALL_TX_LAST, are added also
to indicate when rx_top and tx_top point at the packets with the
LAST_PACKET bit set, indicating the end of the phase.
(4) Calls are queued on the socket 'receive queue' rather than packets.
This means that we don't need have to invent dummy packets to queue to
indicate abnormal/terminal states and we don't have to keep metadata
packets (such as ABORTs) around
(5) The offset and length of a (sub)packet's content are now passed to
the verify_packet security op. This is currently expected to decrypt
the packet in place and validate it.
However, there's now nowhere to store the revised offset and length of
the actual data within the decrypted blob (there may be a header and
padding to skip) because an sk_buff may represent multiple packets, so
a locate_data security op is added to retrieve these details from the
sk_buff content when needed.
(6) recvmsg() now has to handle jumbo subpackets, where each subpacket is
individually secured and needs to be individually decrypted. The code
to do this is broken out into rxrpc_recvmsg_data() and shared with the
kernel API. It now iterates over the call's receive buffer rather
than walking the socket receive queue.
Additional changes:
(1) The timers are condensed to a single timer that is set for the soonest
of three timeouts (delayed ACK generation, DATA retransmission and
call lifespan).
(2) Transmission of ACK and ABORT packets is effected immediately from
process-context socket ops/kernel API calls that cause them instead of
them being punted off to a background work item. The data_ready
handler still has to defer to the background, though.
(3) A shutdown op is added to the AF_RXRPC socket so that the AFS
filesystem can shut down the socket and flush its own work items
before closing the socket to deal with any in-progress service calls.
Future additional changes that will need to be considered:
(1) Make sure that a call doesn't hog the front of the queue by receiving
data from the network as fast as userspace is consuming it to the
exclusion of other calls.
(2) Transmit delayed ACKs from within recvmsg() when we've consumed
sufficiently more packets to avoid the background work item needing to
run.
Signed-off-by: David Howells <dhowells@redhat.com>
2016-09-08 18:10:12 +08:00
|
|
|
|
2016-09-25 01:05:27 +08:00
|
|
|
if (unacked)
|
|
|
|
rxrpc_congestion_timeout(call);
|
|
|
|
|
|
|
|
/* If there was nothing that needed retransmission then it's likely
|
|
|
|
* that an ACK got lost somewhere. Send a ping to find out instead of
|
|
|
|
* retransmitting data.
|
|
|
|
*/
|
2022-04-01 06:55:08 +08:00
|
|
|
if (list_empty(&retrans_queue)) {
|
2020-01-23 21:13:41 +08:00
|
|
|
rxrpc_reduce_call_timer(call, resend_at, jiffies,
|
2017-11-24 18:18:41 +08:00
|
|
|
rxrpc_timer_set_for_resend);
|
2016-09-25 01:05:27 +08:00
|
|
|
ack_ts = ktime_sub(now, call->acks_latest_ts);
|
2020-05-11 21:54:34 +08:00
|
|
|
if (ktime_to_us(ack_ts) < (call->peer->srtt_us >> 3))
|
2016-09-25 01:05:27 +08:00
|
|
|
goto out;
|
2020-01-31 05:48:13 +08:00
|
|
|
rxrpc_send_ACK(call, RXRPC_ACK_PING, 0,
|
|
|
|
rxrpc_propose_ack_ping_for_lost_ack);
|
2016-09-25 01:05:27 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2020-01-23 21:13:41 +08:00
|
|
|
/* Retransmit the queue */
|
2022-04-01 06:55:08 +08:00
|
|
|
while ((txb = list_first_entry_or_null(&retrans_queue,
|
|
|
|
struct rxrpc_txbuf, tx_link))) {
|
|
|
|
list_del_init(&txb->tx_link);
|
2020-01-23 21:13:41 +08:00
|
|
|
rxrpc_transmit_one(call, txb);
|
2016-09-17 17:49:12 +08:00
|
|
|
}
|
rxrpc: Rewrite the data and ack handling code
Rewrite the data and ack handling code such that:
(1) Parsing of received ACK and ABORT packets and the distribution and the
filing of DATA packets happens entirely within the data_ready context
called from the UDP socket. This allows us to process and discard ACK
and ABORT packets much more quickly (they're no longer stashed on a
queue for a background thread to process).
(2) We avoid calling skb_clone(), pskb_pull() and pskb_trim(). We instead
keep track of the offset and length of the content of each packet in
the sk_buff metadata. This means we don't do any allocation in the
receive path.
(3) Jumbo DATA packet parsing is now done in data_ready context. Rather
than cloning the packet once for each subpacket and pulling/trimming
it, we file the packet multiple times with an annotation for each
indicating which subpacket is there. From that we can directly
calculate the offset and length.
(4) A call's receive queue can be accessed without taking locks (memory
barriers do have to be used, though).
(5) Incoming calls are set up from preallocated resources and immediately
made live. They can than have packets queued upon them and ACKs
generated. If insufficient resources exist, DATA packet #1 is given a
BUSY reply and other DATA packets are discarded).
(6) sk_buffs no longer take a ref on their parent call.
To make this work, the following changes are made:
(1) Each call's receive buffer is now a circular buffer of sk_buff
pointers (rxtx_buffer) rather than a number of sk_buff_heads spread
between the call and the socket. This permits each sk_buff to be in
the buffer multiple times. The receive buffer is reused for the
transmit buffer.
(2) A circular buffer of annotations (rxtx_annotations) is kept parallel
to the data buffer. Transmission phase annotations indicate whether a
buffered packet has been ACK'd or not and whether it needs
retransmission.
Receive phase annotations indicate whether a slot holds a whole packet
or a jumbo subpacket and, if the latter, which subpacket. They also
note whether the packet has been decrypted in place.
(3) DATA packet window tracking is much simplified. Each phase has just
two numbers representing the window (rx_hard_ack/rx_top and
tx_hard_ack/tx_top).
The hard_ack number is the sequence number before base of the window,
representing the last packet the other side says it has consumed.
hard_ack starts from 0 and the first packet is sequence number 1.
The top number is the sequence number of the highest-numbered packet
residing in the buffer. Packets between hard_ack+1 and top are
soft-ACK'd to indicate they've been received, but not yet consumed.
Four macros, before(), before_eq(), after() and after_eq() are added
to compare sequence numbers within the window. This allows for the
top of the window to wrap when the hard-ack sequence number gets close
to the limit.
Two flags, RXRPC_CALL_RX_LAST and RXRPC_CALL_TX_LAST, are added also
to indicate when rx_top and tx_top point at the packets with the
LAST_PACKET bit set, indicating the end of the phase.
(4) Calls are queued on the socket 'receive queue' rather than packets.
This means that we don't need have to invent dummy packets to queue to
indicate abnormal/terminal states and we don't have to keep metadata
packets (such as ABORTs) around
(5) The offset and length of a (sub)packet's content are now passed to
the verify_packet security op. This is currently expected to decrypt
the packet in place and validate it.
However, there's now nowhere to store the revised offset and length of
the actual data within the decrypted blob (there may be a header and
padding to skip) because an sk_buff may represent multiple packets, so
a locate_data security op is added to retrieve these details from the
sk_buff content when needed.
(6) recvmsg() now has to handle jumbo subpackets, where each subpacket is
individually secured and needs to be individually decrypted. The code
to do this is broken out into rxrpc_recvmsg_data() and shared with the
kernel API. It now iterates over the call's receive buffer rather
than walking the socket receive queue.
Additional changes:
(1) The timers are condensed to a single timer that is set for the soonest
of three timeouts (delayed ACK generation, DATA retransmission and
call lifespan).
(2) Transmission of ACK and ABORT packets is effected immediately from
process-context socket ops/kernel API calls that cause them instead of
them being punted off to a background work item. The data_ready
handler still has to defer to the background, though.
(3) A shutdown op is added to the AF_RXRPC socket so that the AFS
filesystem can shut down the socket and flush its own work items
before closing the socket to deal with any in-progress service calls.
Future additional changes that will need to be considered:
(1) Make sure that a call doesn't hog the front of the queue by receiving
data from the network as fast as userspace is consuming it to the
exclusion of other calls.
(2) Transmit delayed ACKs from within recvmsg() when we've consumed
sufficiently more packets to avoid the background work item needing to
run.
Signed-off-by: David Howells <dhowells@redhat.com>
2016-09-08 18:10:12 +08:00
|
|
|
|
2016-09-25 01:05:27 +08:00
|
|
|
out:
|
rxrpc: Rewrite the data and ack handling code
Rewrite the data and ack handling code such that:
(1) Parsing of received ACK and ABORT packets and the distribution and the
filing of DATA packets happens entirely within the data_ready context
called from the UDP socket. This allows us to process and discard ACK
and ABORT packets much more quickly (they're no longer stashed on a
queue for a background thread to process).
(2) We avoid calling skb_clone(), pskb_pull() and pskb_trim(). We instead
keep track of the offset and length of the content of each packet in
the sk_buff metadata. This means we don't do any allocation in the
receive path.
(3) Jumbo DATA packet parsing is now done in data_ready context. Rather
than cloning the packet once for each subpacket and pulling/trimming
it, we file the packet multiple times with an annotation for each
indicating which subpacket is there. From that we can directly
calculate the offset and length.
(4) A call's receive queue can be accessed without taking locks (memory
barriers do have to be used, though).
(5) Incoming calls are set up from preallocated resources and immediately
made live. They can than have packets queued upon them and ACKs
generated. If insufficient resources exist, DATA packet #1 is given a
BUSY reply and other DATA packets are discarded).
(6) sk_buffs no longer take a ref on their parent call.
To make this work, the following changes are made:
(1) Each call's receive buffer is now a circular buffer of sk_buff
pointers (rxtx_buffer) rather than a number of sk_buff_heads spread
between the call and the socket. This permits each sk_buff to be in
the buffer multiple times. The receive buffer is reused for the
transmit buffer.
(2) A circular buffer of annotations (rxtx_annotations) is kept parallel
to the data buffer. Transmission phase annotations indicate whether a
buffered packet has been ACK'd or not and whether it needs
retransmission.
Receive phase annotations indicate whether a slot holds a whole packet
or a jumbo subpacket and, if the latter, which subpacket. They also
note whether the packet has been decrypted in place.
(3) DATA packet window tracking is much simplified. Each phase has just
two numbers representing the window (rx_hard_ack/rx_top and
tx_hard_ack/tx_top).
The hard_ack number is the sequence number before base of the window,
representing the last packet the other side says it has consumed.
hard_ack starts from 0 and the first packet is sequence number 1.
The top number is the sequence number of the highest-numbered packet
residing in the buffer. Packets between hard_ack+1 and top are
soft-ACK'd to indicate they've been received, but not yet consumed.
Four macros, before(), before_eq(), after() and after_eq() are added
to compare sequence numbers within the window. This allows for the
top of the window to wrap when the hard-ack sequence number gets close
to the limit.
Two flags, RXRPC_CALL_RX_LAST and RXRPC_CALL_TX_LAST, are added also
to indicate when rx_top and tx_top point at the packets with the
LAST_PACKET bit set, indicating the end of the phase.
(4) Calls are queued on the socket 'receive queue' rather than packets.
This means that we don't need have to invent dummy packets to queue to
indicate abnormal/terminal states and we don't have to keep metadata
packets (such as ABORTs) around
(5) The offset and length of a (sub)packet's content are now passed to
the verify_packet security op. This is currently expected to decrypt
the packet in place and validate it.
However, there's now nowhere to store the revised offset and length of
the actual data within the decrypted blob (there may be a header and
padding to skip) because an sk_buff may represent multiple packets, so
a locate_data security op is added to retrieve these details from the
sk_buff content when needed.
(6) recvmsg() now has to handle jumbo subpackets, where each subpacket is
individually secured and needs to be individually decrypted. The code
to do this is broken out into rxrpc_recvmsg_data() and shared with the
kernel API. It now iterates over the call's receive buffer rather
than walking the socket receive queue.
Additional changes:
(1) The timers are condensed to a single timer that is set for the soonest
of three timeouts (delayed ACK generation, DATA retransmission and
call lifespan).
(2) Transmission of ACK and ABORT packets is effected immediately from
process-context socket ops/kernel API calls that cause them instead of
them being punted off to a background work item. The data_ready
handler still has to defer to the background, though.
(3) A shutdown op is added to the AF_RXRPC socket so that the AFS
filesystem can shut down the socket and flush its own work items
before closing the socket to deal with any in-progress service calls.
Future additional changes that will need to be considered:
(1) Make sure that a call doesn't hog the front of the queue by receiving
data from the network as fast as userspace is consuming it to the
exclusion of other calls.
(2) Transmit delayed ACKs from within recvmsg() when we've consumed
sufficiently more packets to avoid the background work item needing to
run.
Signed-off-by: David Howells <dhowells@redhat.com>
2016-09-08 18:10:12 +08:00
|
|
|
_leave("");
|
2007-04-27 06:48:28 +08:00
|
|
|
}
|
|
|
|
|
2022-11-11 16:35:36 +08:00
|
|
|
/*
|
|
|
|
* Start transmitting the reply to a service. This cancels the need to ACK the
|
|
|
|
* request if we haven't yet done so.
|
|
|
|
*/
|
|
|
|
static void rxrpc_begin_service_reply(struct rxrpc_call *call)
|
|
|
|
{
|
2022-10-27 18:25:55 +08:00
|
|
|
unsigned long now = jiffies;
|
2022-11-11 16:35:36 +08:00
|
|
|
|
2022-10-27 18:25:55 +08:00
|
|
|
rxrpc_set_call_state(call, RXRPC_CALL_SERVER_SEND_REPLY);
|
|
|
|
WRITE_ONCE(call->delay_ack_at, now + MAX_JIFFY_OFFSET);
|
|
|
|
if (call->ackr_reason == RXRPC_ACK_DELAY)
|
|
|
|
call->ackr_reason = 0;
|
|
|
|
trace_rxrpc_timer(call, rxrpc_timer_init_for_send_reply, now);
|
2022-11-11 16:35:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close the transmission phase. After this point there is no more data to be
|
|
|
|
* transmitted in the call.
|
|
|
|
*/
|
|
|
|
static void rxrpc_close_tx_phase(struct rxrpc_call *call)
|
|
|
|
{
|
|
|
|
_debug("________awaiting reply/ACK__________");
|
|
|
|
|
2022-10-27 18:25:55 +08:00
|
|
|
switch (__rxrpc_call_state(call)) {
|
2022-11-11 16:35:36 +08:00
|
|
|
case RXRPC_CALL_CLIENT_SEND_REQUEST:
|
2022-10-27 18:25:55 +08:00
|
|
|
rxrpc_set_call_state(call, RXRPC_CALL_CLIENT_AWAIT_REPLY);
|
2022-11-11 16:35:36 +08:00
|
|
|
break;
|
|
|
|
case RXRPC_CALL_SERVER_SEND_REPLY:
|
2022-10-27 18:25:55 +08:00
|
|
|
rxrpc_set_call_state(call, RXRPC_CALL_SERVER_AWAIT_ACK);
|
2022-11-11 16:35:36 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-01 06:55:08 +08:00
|
|
|
static bool rxrpc_tx_window_has_space(struct rxrpc_call *call)
|
|
|
|
{
|
|
|
|
unsigned int winsize = min_t(unsigned int, call->tx_winsize,
|
|
|
|
call->cong_cwnd + call->cong_extra);
|
|
|
|
rxrpc_seq_t window = call->acks_hard_ack, wtop = window + winsize;
|
|
|
|
rxrpc_seq_t tx_top = call->tx_top;
|
|
|
|
int space;
|
|
|
|
|
|
|
|
space = wtop - tx_top;
|
|
|
|
return space > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decant some if the sendmsg prepared queue into the transmission buffer.
|
|
|
|
*/
|
|
|
|
static void rxrpc_decant_prepared_tx(struct rxrpc_call *call)
|
|
|
|
{
|
|
|
|
struct rxrpc_txbuf *txb;
|
|
|
|
|
2022-10-13 05:17:56 +08:00
|
|
|
if (!test_bit(RXRPC_CALL_EXPOSED, &call->flags)) {
|
|
|
|
if (list_empty(&call->tx_sendmsg))
|
|
|
|
return;
|
2022-04-01 06:55:08 +08:00
|
|
|
rxrpc_expose_client_call(call);
|
2022-10-13 05:17:56 +08:00
|
|
|
}
|
2022-04-01 06:55:08 +08:00
|
|
|
|
|
|
|
while ((txb = list_first_entry_or_null(&call->tx_sendmsg,
|
|
|
|
struct rxrpc_txbuf, call_link))) {
|
|
|
|
spin_lock(&call->tx_lock);
|
|
|
|
list_del(&txb->call_link);
|
|
|
|
spin_unlock(&call->tx_lock);
|
|
|
|
|
|
|
|
call->tx_top = txb->seq;
|
|
|
|
list_add_tail(&txb->call_link, &call->tx_buffer);
|
|
|
|
|
2022-11-11 16:35:36 +08:00
|
|
|
if (txb->wire.flags & RXRPC_LAST_PACKET)
|
|
|
|
rxrpc_close_tx_phase(call);
|
|
|
|
|
2022-04-01 06:55:08 +08:00
|
|
|
rxrpc_transmit_one(call, txb);
|
|
|
|
|
|
|
|
if (!rxrpc_tx_window_has_space(call))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rxrpc_transmit_some_data(struct rxrpc_call *call)
|
|
|
|
{
|
2022-10-27 18:25:55 +08:00
|
|
|
switch (__rxrpc_call_state(call)) {
|
2022-04-01 06:55:08 +08:00
|
|
|
case RXRPC_CALL_SERVER_ACK_REQUEST:
|
|
|
|
if (list_empty(&call->tx_sendmsg))
|
|
|
|
return;
|
2022-11-11 16:35:36 +08:00
|
|
|
rxrpc_begin_service_reply(call);
|
2022-04-01 06:55:08 +08:00
|
|
|
fallthrough;
|
|
|
|
|
|
|
|
case RXRPC_CALL_SERVER_SEND_REPLY:
|
|
|
|
case RXRPC_CALL_CLIENT_SEND_REQUEST:
|
|
|
|
if (!rxrpc_tx_window_has_space(call))
|
|
|
|
return;
|
2022-11-11 21:47:35 +08:00
|
|
|
if (list_empty(&call->tx_sendmsg)) {
|
|
|
|
rxrpc_inc_stat(call->rxnet, stat_tx_data_underflow);
|
2022-04-01 06:55:08 +08:00
|
|
|
return;
|
2022-11-11 21:47:35 +08:00
|
|
|
}
|
2022-04-01 06:55:08 +08:00
|
|
|
rxrpc_decant_prepared_tx(call);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-23 21:13:41 +08:00
|
|
|
/*
|
|
|
|
* Ping the other end to fill our RTT cache and to retrieve the rwind
|
|
|
|
* and MTU parameters.
|
|
|
|
*/
|
|
|
|
static void rxrpc_send_initial_ping(struct rxrpc_call *call)
|
|
|
|
{
|
|
|
|
if (call->peer->rtt_count < 3 ||
|
|
|
|
ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000),
|
|
|
|
ktime_get_real()))
|
|
|
|
rxrpc_send_ACK(call, RXRPC_ACK_PING, 0,
|
|
|
|
rxrpc_propose_ack_ping_for_params);
|
|
|
|
}
|
|
|
|
|
2007-04-27 06:48:28 +08:00
|
|
|
/*
|
rxrpc: Rewrite the data and ack handling code
Rewrite the data and ack handling code such that:
(1) Parsing of received ACK and ABORT packets and the distribution and the
filing of DATA packets happens entirely within the data_ready context
called from the UDP socket. This allows us to process and discard ACK
and ABORT packets much more quickly (they're no longer stashed on a
queue for a background thread to process).
(2) We avoid calling skb_clone(), pskb_pull() and pskb_trim(). We instead
keep track of the offset and length of the content of each packet in
the sk_buff metadata. This means we don't do any allocation in the
receive path.
(3) Jumbo DATA packet parsing is now done in data_ready context. Rather
than cloning the packet once for each subpacket and pulling/trimming
it, we file the packet multiple times with an annotation for each
indicating which subpacket is there. From that we can directly
calculate the offset and length.
(4) A call's receive queue can be accessed without taking locks (memory
barriers do have to be used, though).
(5) Incoming calls are set up from preallocated resources and immediately
made live. They can than have packets queued upon them and ACKs
generated. If insufficient resources exist, DATA packet #1 is given a
BUSY reply and other DATA packets are discarded).
(6) sk_buffs no longer take a ref on their parent call.
To make this work, the following changes are made:
(1) Each call's receive buffer is now a circular buffer of sk_buff
pointers (rxtx_buffer) rather than a number of sk_buff_heads spread
between the call and the socket. This permits each sk_buff to be in
the buffer multiple times. The receive buffer is reused for the
transmit buffer.
(2) A circular buffer of annotations (rxtx_annotations) is kept parallel
to the data buffer. Transmission phase annotations indicate whether a
buffered packet has been ACK'd or not and whether it needs
retransmission.
Receive phase annotations indicate whether a slot holds a whole packet
or a jumbo subpacket and, if the latter, which subpacket. They also
note whether the packet has been decrypted in place.
(3) DATA packet window tracking is much simplified. Each phase has just
two numbers representing the window (rx_hard_ack/rx_top and
tx_hard_ack/tx_top).
The hard_ack number is the sequence number before base of the window,
representing the last packet the other side says it has consumed.
hard_ack starts from 0 and the first packet is sequence number 1.
The top number is the sequence number of the highest-numbered packet
residing in the buffer. Packets between hard_ack+1 and top are
soft-ACK'd to indicate they've been received, but not yet consumed.
Four macros, before(), before_eq(), after() and after_eq() are added
to compare sequence numbers within the window. This allows for the
top of the window to wrap when the hard-ack sequence number gets close
to the limit.
Two flags, RXRPC_CALL_RX_LAST and RXRPC_CALL_TX_LAST, are added also
to indicate when rx_top and tx_top point at the packets with the
LAST_PACKET bit set, indicating the end of the phase.
(4) Calls are queued on the socket 'receive queue' rather than packets.
This means that we don't need have to invent dummy packets to queue to
indicate abnormal/terminal states and we don't have to keep metadata
packets (such as ABORTs) around
(5) The offset and length of a (sub)packet's content are now passed to
the verify_packet security op. This is currently expected to decrypt
the packet in place and validate it.
However, there's now nowhere to store the revised offset and length of
the actual data within the decrypted blob (there may be a header and
padding to skip) because an sk_buff may represent multiple packets, so
a locate_data security op is added to retrieve these details from the
sk_buff content when needed.
(6) recvmsg() now has to handle jumbo subpackets, where each subpacket is
individually secured and needs to be individually decrypted. The code
to do this is broken out into rxrpc_recvmsg_data() and shared with the
kernel API. It now iterates over the call's receive buffer rather
than walking the socket receive queue.
Additional changes:
(1) The timers are condensed to a single timer that is set for the soonest
of three timeouts (delayed ACK generation, DATA retransmission and
call lifespan).
(2) Transmission of ACK and ABORT packets is effected immediately from
process-context socket ops/kernel API calls that cause them instead of
them being punted off to a background work item. The data_ready
handler still has to defer to the background, though.
(3) A shutdown op is added to the AF_RXRPC socket so that the AFS
filesystem can shut down the socket and flush its own work items
before closing the socket to deal with any in-progress service calls.
Future additional changes that will need to be considered:
(1) Make sure that a call doesn't hog the front of the queue by receiving
data from the network as fast as userspace is consuming it to the
exclusion of other calls.
(2) Transmit delayed ACKs from within recvmsg() when we've consumed
sufficiently more packets to avoid the background work item needing to
run.
Signed-off-by: David Howells <dhowells@redhat.com>
2016-09-08 18:10:12 +08:00
|
|
|
* Handle retransmission and deferred ACK/abort generation.
|
2007-04-27 06:48:28 +08:00
|
|
|
*/
|
2022-10-07 04:45:42 +08:00
|
|
|
bool rxrpc_input_call_event(struct rxrpc_call *call, struct sk_buff *skb)
|
2007-04-27 06:48:28 +08:00
|
|
|
{
|
2017-11-24 18:18:41 +08:00
|
|
|
unsigned long now, next, t;
|
2020-01-31 05:48:13 +08:00
|
|
|
rxrpc_serial_t ackr_serial;
|
2020-01-23 21:13:41 +08:00
|
|
|
bool resend = false, expired = false;
|
2022-10-13 05:17:56 +08:00
|
|
|
s32 abort_code;
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2022-10-21 21:39:26 +08:00
|
|
|
rxrpc_see_call(call, rxrpc_call_see_input);
|
2016-08-30 16:49:29 +08:00
|
|
|
|
2007-04-27 06:48:28 +08:00
|
|
|
//printk("\n--------------------\n");
|
rxrpc: Rewrite the data and ack handling code
Rewrite the data and ack handling code such that:
(1) Parsing of received ACK and ABORT packets and the distribution and the
filing of DATA packets happens entirely within the data_ready context
called from the UDP socket. This allows us to process and discard ACK
and ABORT packets much more quickly (they're no longer stashed on a
queue for a background thread to process).
(2) We avoid calling skb_clone(), pskb_pull() and pskb_trim(). We instead
keep track of the offset and length of the content of each packet in
the sk_buff metadata. This means we don't do any allocation in the
receive path.
(3) Jumbo DATA packet parsing is now done in data_ready context. Rather
than cloning the packet once for each subpacket and pulling/trimming
it, we file the packet multiple times with an annotation for each
indicating which subpacket is there. From that we can directly
calculate the offset and length.
(4) A call's receive queue can be accessed without taking locks (memory
barriers do have to be used, though).
(5) Incoming calls are set up from preallocated resources and immediately
made live. They can than have packets queued upon them and ACKs
generated. If insufficient resources exist, DATA packet #1 is given a
BUSY reply and other DATA packets are discarded).
(6) sk_buffs no longer take a ref on their parent call.
To make this work, the following changes are made:
(1) Each call's receive buffer is now a circular buffer of sk_buff
pointers (rxtx_buffer) rather than a number of sk_buff_heads spread
between the call and the socket. This permits each sk_buff to be in
the buffer multiple times. The receive buffer is reused for the
transmit buffer.
(2) A circular buffer of annotations (rxtx_annotations) is kept parallel
to the data buffer. Transmission phase annotations indicate whether a
buffered packet has been ACK'd or not and whether it needs
retransmission.
Receive phase annotations indicate whether a slot holds a whole packet
or a jumbo subpacket and, if the latter, which subpacket. They also
note whether the packet has been decrypted in place.
(3) DATA packet window tracking is much simplified. Each phase has just
two numbers representing the window (rx_hard_ack/rx_top and
tx_hard_ack/tx_top).
The hard_ack number is the sequence number before base of the window,
representing the last packet the other side says it has consumed.
hard_ack starts from 0 and the first packet is sequence number 1.
The top number is the sequence number of the highest-numbered packet
residing in the buffer. Packets between hard_ack+1 and top are
soft-ACK'd to indicate they've been received, but not yet consumed.
Four macros, before(), before_eq(), after() and after_eq() are added
to compare sequence numbers within the window. This allows for the
top of the window to wrap when the hard-ack sequence number gets close
to the limit.
Two flags, RXRPC_CALL_RX_LAST and RXRPC_CALL_TX_LAST, are added also
to indicate when rx_top and tx_top point at the packets with the
LAST_PACKET bit set, indicating the end of the phase.
(4) Calls are queued on the socket 'receive queue' rather than packets.
This means that we don't need have to invent dummy packets to queue to
indicate abnormal/terminal states and we don't have to keep metadata
packets (such as ABORTs) around
(5) The offset and length of a (sub)packet's content are now passed to
the verify_packet security op. This is currently expected to decrypt
the packet in place and validate it.
However, there's now nowhere to store the revised offset and length of
the actual data within the decrypted blob (there may be a header and
padding to skip) because an sk_buff may represent multiple packets, so
a locate_data security op is added to retrieve these details from the
sk_buff content when needed.
(6) recvmsg() now has to handle jumbo subpackets, where each subpacket is
individually secured and needs to be individually decrypted. The code
to do this is broken out into rxrpc_recvmsg_data() and shared with the
kernel API. It now iterates over the call's receive buffer rather
than walking the socket receive queue.
Additional changes:
(1) The timers are condensed to a single timer that is set for the soonest
of three timeouts (delayed ACK generation, DATA retransmission and
call lifespan).
(2) Transmission of ACK and ABORT packets is effected immediately from
process-context socket ops/kernel API calls that cause them instead of
them being punted off to a background work item. The data_ready
handler still has to defer to the background, though.
(3) A shutdown op is added to the AF_RXRPC socket so that the AFS
filesystem can shut down the socket and flush its own work items
before closing the socket to deal with any in-progress service calls.
Future additional changes that will need to be considered:
(1) Make sure that a call doesn't hog the front of the queue by receiving
data from the network as fast as userspace is consuming it to the
exclusion of other calls.
(2) Transmit delayed ACKs from within recvmsg() when we've consumed
sufficiently more packets to avoid the background work item needing to
run.
Signed-off-by: David Howells <dhowells@redhat.com>
2016-09-08 18:10:12 +08:00
|
|
|
_enter("{%d,%s,%lx}",
|
2022-10-27 18:25:55 +08:00
|
|
|
call->debug_id, rxrpc_call_states[__rxrpc_call_state(call)],
|
|
|
|
call->events);
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2022-10-27 18:25:55 +08:00
|
|
|
if (__rxrpc_call_is_complete(call))
|
2020-01-23 21:13:41 +08:00
|
|
|
goto out;
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2022-10-13 05:17:56 +08:00
|
|
|
/* Handle abort request locklessly, vs rxrpc_propose_abort(). */
|
|
|
|
abort_code = smp_load_acquire(&call->send_abort);
|
|
|
|
if (abort_code) {
|
2022-10-07 04:45:42 +08:00
|
|
|
rxrpc_abort_call(call, 0, call->send_abort, call->send_abort_err,
|
|
|
|
call->send_abort_why);
|
2022-10-13 05:17:56 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2020-01-23 21:13:41 +08:00
|
|
|
if (skb && skb->mark == RXRPC_SKB_MARK_ERROR)
|
2022-11-25 17:00:55 +08:00
|
|
|
goto out;
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2020-01-23 21:13:41 +08:00
|
|
|
/* If we see our async-event poke, check for timeout trippage. */
|
2017-11-24 18:18:41 +08:00
|
|
|
now = jiffies;
|
|
|
|
t = READ_ONCE(call->expect_rx_by);
|
|
|
|
if (time_after_eq(now, t)) {
|
|
|
|
trace_rxrpc_timer(call, rxrpc_timer_exp_normal, now);
|
2020-01-23 21:13:41 +08:00
|
|
|
expired = true;
|
2017-11-24 18:18:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
t = READ_ONCE(call->expect_req_by);
|
2022-10-27 18:25:55 +08:00
|
|
|
if (__rxrpc_call_state(call) == RXRPC_CALL_SERVER_RECV_REQUEST &&
|
2017-11-24 18:18:41 +08:00
|
|
|
time_after_eq(now, t)) {
|
|
|
|
trace_rxrpc_timer(call, rxrpc_timer_exp_idle, now);
|
2020-01-23 21:13:41 +08:00
|
|
|
expired = true;
|
2017-11-24 18:18:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
t = READ_ONCE(call->expect_term_by);
|
|
|
|
if (time_after_eq(now, t)) {
|
|
|
|
trace_rxrpc_timer(call, rxrpc_timer_exp_hard, now);
|
2020-01-23 21:13:41 +08:00
|
|
|
expired = true;
|
2017-11-24 18:18:41 +08:00
|
|
|
}
|
|
|
|
|
2020-01-31 05:48:14 +08:00
|
|
|
t = READ_ONCE(call->delay_ack_at);
|
2017-11-24 18:18:41 +08:00
|
|
|
if (time_after_eq(now, t)) {
|
|
|
|
trace_rxrpc_timer(call, rxrpc_timer_exp_ack, now);
|
2020-01-31 05:48:14 +08:00
|
|
|
cmpxchg(&call->delay_ack_at, t, now + MAX_JIFFY_OFFSET);
|
|
|
|
ackr_serial = xchg(&call->ackr_serial, 0);
|
|
|
|
rxrpc_send_ACK(call, RXRPC_ACK_DELAY, ackr_serial,
|
|
|
|
rxrpc_propose_ack_ping_for_lost_ack);
|
2017-11-24 18:18:41 +08:00
|
|
|
}
|
|
|
|
|
2017-11-24 18:18:42 +08:00
|
|
|
t = READ_ONCE(call->ack_lost_at);
|
|
|
|
if (time_after_eq(now, t)) {
|
|
|
|
trace_rxrpc_timer(call, rxrpc_timer_exp_lost_ack, now);
|
|
|
|
cmpxchg(&call->ack_lost_at, t, now + MAX_JIFFY_OFFSET);
|
|
|
|
set_bit(RXRPC_CALL_EV_ACK_LOST, &call->events);
|
|
|
|
}
|
|
|
|
|
2017-11-24 18:18:42 +08:00
|
|
|
t = READ_ONCE(call->keepalive_at);
|
|
|
|
if (time_after_eq(now, t)) {
|
|
|
|
trace_rxrpc_timer(call, rxrpc_timer_exp_keepalive, now);
|
|
|
|
cmpxchg(&call->keepalive_at, t, now + MAX_JIFFY_OFFSET);
|
2020-01-31 05:48:13 +08:00
|
|
|
rxrpc_send_ACK(call, RXRPC_ACK_PING, 0,
|
|
|
|
rxrpc_propose_ack_ping_for_keepalive);
|
2017-11-24 18:18:42 +08:00
|
|
|
}
|
|
|
|
|
2017-11-24 18:18:41 +08:00
|
|
|
t = READ_ONCE(call->ping_at);
|
|
|
|
if (time_after_eq(now, t)) {
|
|
|
|
trace_rxrpc_timer(call, rxrpc_timer_exp_ping, now);
|
|
|
|
cmpxchg(&call->ping_at, t, now + MAX_JIFFY_OFFSET);
|
2020-01-31 05:48:13 +08:00
|
|
|
rxrpc_send_ACK(call, RXRPC_ACK_PING, 0,
|
|
|
|
rxrpc_propose_ack_ping_for_keepalive);
|
2017-11-24 18:18:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
t = READ_ONCE(call->resend_at);
|
|
|
|
if (time_after_eq(now, t)) {
|
|
|
|
trace_rxrpc_timer(call, rxrpc_timer_exp_resend, now);
|
|
|
|
cmpxchg(&call->resend_at, t, now + MAX_JIFFY_OFFSET);
|
2020-01-23 21:13:41 +08:00
|
|
|
resend = true;
|
2017-11-24 18:18:41 +08:00
|
|
|
}
|
|
|
|
|
2020-01-23 21:13:41 +08:00
|
|
|
if (skb)
|
|
|
|
rxrpc_input_call_packet(call, skb);
|
|
|
|
|
2022-04-01 06:55:08 +08:00
|
|
|
rxrpc_transmit_some_data(call);
|
|
|
|
|
2022-11-11 21:47:35 +08:00
|
|
|
if (skb) {
|
|
|
|
struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
|
|
|
|
|
|
|
|
if (sp->hdr.type == RXRPC_PACKET_TYPE_ACK)
|
|
|
|
rxrpc_congestion_degrade(call);
|
|
|
|
}
|
|
|
|
|
2020-01-23 21:13:41 +08:00
|
|
|
if (test_and_clear_bit(RXRPC_CALL_EV_INITIAL_PING, &call->events))
|
|
|
|
rxrpc_send_initial_ping(call);
|
|
|
|
|
2017-11-24 18:18:41 +08:00
|
|
|
/* Process events */
|
2020-01-23 21:13:41 +08:00
|
|
|
if (expired) {
|
rxrpc: Fix handling of call quietly cancelled out on server
Sometimes an in-progress call will stop responding on the fileserver when
the fileserver quietly cancels the call with an internally marked abort
(RX_CALL_DEAD), without sending an ABORT to the client.
This causes the client's call to eventually expire from lack of incoming
packets directed its way, which currently leads to it being cancelled
locally with ETIME. Note that it's not currently clear as to why this
happens as it's really hard to reproduce.
The rotation policy implement by kAFS, however, doesn't differentiate
between ETIME meaning we didn't get any response from the server and ETIME
meaning the call got cancelled mid-flow. The latter leads to an oops when
fetching data as the rotation partially resets the afs_read descriptor,
which can result in a cleared page pointer being dereferenced because that
page has already been filled.
Handle this by the following means:
(1) Set a flag on a call when we receive a packet for it.
(2) Store the highest packet serial number so far received for a call
(bearing in mind this may wrap).
(3) If, when the "not received anything recently" timeout expires on a
call, we've received at least one packet for a call and the connection
as a whole has received packets more recently than that call, then
cancel the call locally with ECONNRESET rather than ETIME.
This indicates that the call was definitely in progress on the server.
(4) In kAFS, if the rotation algorithm sees ECONNRESET rather than ETIME,
don't try the next server, but rather abort the call.
This avoids the oops as we don't try to reuse the afs_read struct.
Rather, as-yet ungotten pages will be reread at a later data.
Also:
(5) Add an rxrpc tracepoint to log detection of the call being reset.
Without this, I occasionally see an oops like the following:
general protection fault: 0000 [#1] SMP PTI
...
RIP: 0010:_copy_to_iter+0x204/0x310
RSP: 0018:ffff8800cae0f828 EFLAGS: 00010206
RAX: 0000000000000560 RBX: 0000000000000560 RCX: 0000000000000560
RDX: ffff8800cae0f968 RSI: ffff8800d58b3312 RDI: 0005080000000000
RBP: ffff8800cae0f968 R08: 0000000000000560 R09: ffff8800ca00f400
R10: ffff8800c36f28d4 R11: 00000000000008c4 R12: ffff8800cae0f958
R13: 0000000000000560 R14: ffff8800d58b3312 R15: 0000000000000560
FS: 00007fdaef108080(0000) GS:ffff8800ca680000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fb28a8fa000 CR3: 00000000d2a76002 CR4: 00000000001606e0
Call Trace:
skb_copy_datagram_iter+0x14e/0x289
rxrpc_recvmsg_data.isra.0+0x6f3/0xf68
? trace_buffer_unlock_commit_regs+0x4f/0x89
rxrpc_kernel_recv_data+0x149/0x421
afs_extract_data+0x1e0/0x798
? afs_wait_for_call_to_complete+0xc9/0x52e
afs_deliver_fs_fetch_data+0x33a/0x5ab
afs_deliver_to_call+0x1ee/0x5e0
? afs_wait_for_call_to_complete+0xc9/0x52e
afs_wait_for_call_to_complete+0x12b/0x52e
? wake_up_q+0x54/0x54
afs_make_call+0x287/0x462
? afs_fs_fetch_data+0x3e6/0x3ed
? rcu_read_lock_sched_held+0x5d/0x63
afs_fs_fetch_data+0x3e6/0x3ed
afs_fetch_data+0xbb/0x14a
afs_readpages+0x317/0x40d
__do_page_cache_readahead+0x203/0x2ba
? ondemand_readahead+0x3a7/0x3c1
ondemand_readahead+0x3a7/0x3c1
generic_file_buffered_read+0x18b/0x62f
__vfs_read+0xdb/0xfe
vfs_read+0xb2/0x137
ksys_read+0x50/0x8c
do_syscall_64+0x7d/0x1a0
entry_SYSCALL_64_after_hwframe+0x49/0xbe
Note the weird value in RDI which is a result of trying to kmap() a NULL
page pointer.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-06-03 09:17:39 +08:00
|
|
|
if (test_bit(RXRPC_CALL_RX_HEARD, &call->flags) &&
|
|
|
|
(int)call->conn->hi_serial - (int)call->rx_serial > 0) {
|
|
|
|
trace_rxrpc_call_reset(call);
|
2022-10-07 04:45:42 +08:00
|
|
|
rxrpc_abort_call(call, 0, RX_CALL_DEAD, -ECONNRESET,
|
|
|
|
rxrpc_abort_call_reset);
|
rxrpc: Fix handling of call quietly cancelled out on server
Sometimes an in-progress call will stop responding on the fileserver when
the fileserver quietly cancels the call with an internally marked abort
(RX_CALL_DEAD), without sending an ABORT to the client.
This causes the client's call to eventually expire from lack of incoming
packets directed its way, which currently leads to it being cancelled
locally with ETIME. Note that it's not currently clear as to why this
happens as it's really hard to reproduce.
The rotation policy implement by kAFS, however, doesn't differentiate
between ETIME meaning we didn't get any response from the server and ETIME
meaning the call got cancelled mid-flow. The latter leads to an oops when
fetching data as the rotation partially resets the afs_read descriptor,
which can result in a cleared page pointer being dereferenced because that
page has already been filled.
Handle this by the following means:
(1) Set a flag on a call when we receive a packet for it.
(2) Store the highest packet serial number so far received for a call
(bearing in mind this may wrap).
(3) If, when the "not received anything recently" timeout expires on a
call, we've received at least one packet for a call and the connection
as a whole has received packets more recently than that call, then
cancel the call locally with ECONNRESET rather than ETIME.
This indicates that the call was definitely in progress on the server.
(4) In kAFS, if the rotation algorithm sees ECONNRESET rather than ETIME,
don't try the next server, but rather abort the call.
This avoids the oops as we don't try to reuse the afs_read struct.
Rather, as-yet ungotten pages will be reread at a later data.
Also:
(5) Add an rxrpc tracepoint to log detection of the call being reset.
Without this, I occasionally see an oops like the following:
general protection fault: 0000 [#1] SMP PTI
...
RIP: 0010:_copy_to_iter+0x204/0x310
RSP: 0018:ffff8800cae0f828 EFLAGS: 00010206
RAX: 0000000000000560 RBX: 0000000000000560 RCX: 0000000000000560
RDX: ffff8800cae0f968 RSI: ffff8800d58b3312 RDI: 0005080000000000
RBP: ffff8800cae0f968 R08: 0000000000000560 R09: ffff8800ca00f400
R10: ffff8800c36f28d4 R11: 00000000000008c4 R12: ffff8800cae0f958
R13: 0000000000000560 R14: ffff8800d58b3312 R15: 0000000000000560
FS: 00007fdaef108080(0000) GS:ffff8800ca680000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fb28a8fa000 CR3: 00000000d2a76002 CR4: 00000000001606e0
Call Trace:
skb_copy_datagram_iter+0x14e/0x289
rxrpc_recvmsg_data.isra.0+0x6f3/0xf68
? trace_buffer_unlock_commit_regs+0x4f/0x89
rxrpc_kernel_recv_data+0x149/0x421
afs_extract_data+0x1e0/0x798
? afs_wait_for_call_to_complete+0xc9/0x52e
afs_deliver_fs_fetch_data+0x33a/0x5ab
afs_deliver_to_call+0x1ee/0x5e0
? afs_wait_for_call_to_complete+0xc9/0x52e
afs_wait_for_call_to_complete+0x12b/0x52e
? wake_up_q+0x54/0x54
afs_make_call+0x287/0x462
? afs_fs_fetch_data+0x3e6/0x3ed
? rcu_read_lock_sched_held+0x5d/0x63
afs_fs_fetch_data+0x3e6/0x3ed
afs_fetch_data+0xbb/0x14a
afs_readpages+0x317/0x40d
__do_page_cache_readahead+0x203/0x2ba
? ondemand_readahead+0x3a7/0x3c1
ondemand_readahead+0x3a7/0x3c1
generic_file_buffered_read+0x18b/0x62f
__vfs_read+0xdb/0xfe
vfs_read+0xb2/0x137
ksys_read+0x50/0x8c
do_syscall_64+0x7d/0x1a0
entry_SYSCALL_64_after_hwframe+0x49/0xbe
Note the weird value in RDI which is a result of trying to kmap() a NULL
page pointer.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-06-03 09:17:39 +08:00
|
|
|
} else {
|
2022-10-07 04:45:42 +08:00
|
|
|
rxrpc_abort_call(call, 0, RX_CALL_TIMEOUT, -ETIME,
|
|
|
|
rxrpc_abort_call_timeout);
|
rxrpc: Fix handling of call quietly cancelled out on server
Sometimes an in-progress call will stop responding on the fileserver when
the fileserver quietly cancels the call with an internally marked abort
(RX_CALL_DEAD), without sending an ABORT to the client.
This causes the client's call to eventually expire from lack of incoming
packets directed its way, which currently leads to it being cancelled
locally with ETIME. Note that it's not currently clear as to why this
happens as it's really hard to reproduce.
The rotation policy implement by kAFS, however, doesn't differentiate
between ETIME meaning we didn't get any response from the server and ETIME
meaning the call got cancelled mid-flow. The latter leads to an oops when
fetching data as the rotation partially resets the afs_read descriptor,
which can result in a cleared page pointer being dereferenced because that
page has already been filled.
Handle this by the following means:
(1) Set a flag on a call when we receive a packet for it.
(2) Store the highest packet serial number so far received for a call
(bearing in mind this may wrap).
(3) If, when the "not received anything recently" timeout expires on a
call, we've received at least one packet for a call and the connection
as a whole has received packets more recently than that call, then
cancel the call locally with ECONNRESET rather than ETIME.
This indicates that the call was definitely in progress on the server.
(4) In kAFS, if the rotation algorithm sees ECONNRESET rather than ETIME,
don't try the next server, but rather abort the call.
This avoids the oops as we don't try to reuse the afs_read struct.
Rather, as-yet ungotten pages will be reread at a later data.
Also:
(5) Add an rxrpc tracepoint to log detection of the call being reset.
Without this, I occasionally see an oops like the following:
general protection fault: 0000 [#1] SMP PTI
...
RIP: 0010:_copy_to_iter+0x204/0x310
RSP: 0018:ffff8800cae0f828 EFLAGS: 00010206
RAX: 0000000000000560 RBX: 0000000000000560 RCX: 0000000000000560
RDX: ffff8800cae0f968 RSI: ffff8800d58b3312 RDI: 0005080000000000
RBP: ffff8800cae0f968 R08: 0000000000000560 R09: ffff8800ca00f400
R10: ffff8800c36f28d4 R11: 00000000000008c4 R12: ffff8800cae0f958
R13: 0000000000000560 R14: ffff8800d58b3312 R15: 0000000000000560
FS: 00007fdaef108080(0000) GS:ffff8800ca680000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fb28a8fa000 CR3: 00000000d2a76002 CR4: 00000000001606e0
Call Trace:
skb_copy_datagram_iter+0x14e/0x289
rxrpc_recvmsg_data.isra.0+0x6f3/0xf68
? trace_buffer_unlock_commit_regs+0x4f/0x89
rxrpc_kernel_recv_data+0x149/0x421
afs_extract_data+0x1e0/0x798
? afs_wait_for_call_to_complete+0xc9/0x52e
afs_deliver_fs_fetch_data+0x33a/0x5ab
afs_deliver_to_call+0x1ee/0x5e0
? afs_wait_for_call_to_complete+0xc9/0x52e
afs_wait_for_call_to_complete+0x12b/0x52e
? wake_up_q+0x54/0x54
afs_make_call+0x287/0x462
? afs_fs_fetch_data+0x3e6/0x3ed
? rcu_read_lock_sched_held+0x5d/0x63
afs_fs_fetch_data+0x3e6/0x3ed
afs_fetch_data+0xbb/0x14a
afs_readpages+0x317/0x40d
__do_page_cache_readahead+0x203/0x2ba
? ondemand_readahead+0x3a7/0x3c1
ondemand_readahead+0x3a7/0x3c1
generic_file_buffered_read+0x18b/0x62f
__vfs_read+0xdb/0xfe
vfs_read+0xb2/0x137
ksys_read+0x50/0x8c
do_syscall_64+0x7d/0x1a0
entry_SYSCALL_64_after_hwframe+0x49/0xbe
Note the weird value in RDI which is a result of trying to kmap() a NULL
page pointer.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-06-03 09:17:39 +08:00
|
|
|
}
|
2020-01-23 21:13:41 +08:00
|
|
|
goto out;
|
2007-04-27 06:48:28 +08:00
|
|
|
}
|
|
|
|
|
2020-01-23 21:13:41 +08:00
|
|
|
if (test_and_clear_bit(RXRPC_CALL_EV_ACK_LOST, &call->events))
|
2020-01-31 05:48:13 +08:00
|
|
|
rxrpc_send_ACK(call, RXRPC_ACK_PING, 0,
|
|
|
|
rxrpc_propose_ack_ping_for_lost_ack);
|
2016-10-06 15:11:49 +08:00
|
|
|
|
2022-10-27 18:25:55 +08:00
|
|
|
if (resend && __rxrpc_call_state(call) != RXRPC_CALL_CLIENT_RECV_REPLY)
|
2020-01-23 21:13:41 +08:00
|
|
|
rxrpc_resend(call, NULL);
|
|
|
|
|
|
|
|
if (test_and_clear_bit(RXRPC_CALL_RX_IS_IDLE, &call->flags))
|
|
|
|
rxrpc_send_ACK(call, RXRPC_ACK_IDLE, 0,
|
|
|
|
rxrpc_propose_ack_rx_idle);
|
|
|
|
|
2022-10-17 18:44:22 +08:00
|
|
|
if (call->ackr_nr_unacked > 2) {
|
2022-10-17 17:55:41 +08:00
|
|
|
if (call->peer->rtt_count < 3)
|
|
|
|
rxrpc_send_ACK(call, RXRPC_ACK_PING, 0,
|
|
|
|
rxrpc_propose_ack_ping_for_rtt);
|
|
|
|
else if (ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000),
|
|
|
|
ktime_get_real()))
|
|
|
|
rxrpc_send_ACK(call, RXRPC_ACK_PING, 0,
|
|
|
|
rxrpc_propose_ack_ping_for_old_rtt);
|
|
|
|
else
|
|
|
|
rxrpc_send_ACK(call, RXRPC_ACK_IDLE, 0,
|
|
|
|
rxrpc_propose_ack_input_data);
|
|
|
|
}
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2017-11-24 18:18:41 +08:00
|
|
|
/* Make sure the timer is restarted */
|
2022-10-27 18:25:55 +08:00
|
|
|
if (!__rxrpc_call_is_complete(call)) {
|
2020-01-23 21:13:41 +08:00
|
|
|
next = call->expect_rx_by;
|
2017-11-24 18:18:41 +08:00
|
|
|
|
|
|
|
#define set(T) { t = READ_ONCE(T); if (time_before(t, next)) next = t; }
|
2017-11-29 22:25:50 +08:00
|
|
|
|
2020-01-23 21:13:41 +08:00
|
|
|
set(call->expect_req_by);
|
|
|
|
set(call->expect_term_by);
|
|
|
|
set(call->delay_ack_at);
|
|
|
|
set(call->ack_lost_at);
|
|
|
|
set(call->resend_at);
|
|
|
|
set(call->keepalive_at);
|
|
|
|
set(call->ping_at);
|
2017-11-24 18:18:41 +08:00
|
|
|
|
2020-01-23 21:13:41 +08:00
|
|
|
now = jiffies;
|
|
|
|
if (time_after_eq(now, next))
|
|
|
|
rxrpc_poke_call(call, rxrpc_call_poke_timer_now);
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2020-01-23 21:13:41 +08:00
|
|
|
rxrpc_reduce_call_timer(call, next, now, rxrpc_timer_restart);
|
|
|
|
}
|
2007-04-27 06:48:28 +08:00
|
|
|
|
rxrpc: Rewrite the data and ack handling code
Rewrite the data and ack handling code such that:
(1) Parsing of received ACK and ABORT packets and the distribution and the
filing of DATA packets happens entirely within the data_ready context
called from the UDP socket. This allows us to process and discard ACK
and ABORT packets much more quickly (they're no longer stashed on a
queue for a background thread to process).
(2) We avoid calling skb_clone(), pskb_pull() and pskb_trim(). We instead
keep track of the offset and length of the content of each packet in
the sk_buff metadata. This means we don't do any allocation in the
receive path.
(3) Jumbo DATA packet parsing is now done in data_ready context. Rather
than cloning the packet once for each subpacket and pulling/trimming
it, we file the packet multiple times with an annotation for each
indicating which subpacket is there. From that we can directly
calculate the offset and length.
(4) A call's receive queue can be accessed without taking locks (memory
barriers do have to be used, though).
(5) Incoming calls are set up from preallocated resources and immediately
made live. They can than have packets queued upon them and ACKs
generated. If insufficient resources exist, DATA packet #1 is given a
BUSY reply and other DATA packets are discarded).
(6) sk_buffs no longer take a ref on their parent call.
To make this work, the following changes are made:
(1) Each call's receive buffer is now a circular buffer of sk_buff
pointers (rxtx_buffer) rather than a number of sk_buff_heads spread
between the call and the socket. This permits each sk_buff to be in
the buffer multiple times. The receive buffer is reused for the
transmit buffer.
(2) A circular buffer of annotations (rxtx_annotations) is kept parallel
to the data buffer. Transmission phase annotations indicate whether a
buffered packet has been ACK'd or not and whether it needs
retransmission.
Receive phase annotations indicate whether a slot holds a whole packet
or a jumbo subpacket and, if the latter, which subpacket. They also
note whether the packet has been decrypted in place.
(3) DATA packet window tracking is much simplified. Each phase has just
two numbers representing the window (rx_hard_ack/rx_top and
tx_hard_ack/tx_top).
The hard_ack number is the sequence number before base of the window,
representing the last packet the other side says it has consumed.
hard_ack starts from 0 and the first packet is sequence number 1.
The top number is the sequence number of the highest-numbered packet
residing in the buffer. Packets between hard_ack+1 and top are
soft-ACK'd to indicate they've been received, but not yet consumed.
Four macros, before(), before_eq(), after() and after_eq() are added
to compare sequence numbers within the window. This allows for the
top of the window to wrap when the hard-ack sequence number gets close
to the limit.
Two flags, RXRPC_CALL_RX_LAST and RXRPC_CALL_TX_LAST, are added also
to indicate when rx_top and tx_top point at the packets with the
LAST_PACKET bit set, indicating the end of the phase.
(4) Calls are queued on the socket 'receive queue' rather than packets.
This means that we don't need have to invent dummy packets to queue to
indicate abnormal/terminal states and we don't have to keep metadata
packets (such as ABORTs) around
(5) The offset and length of a (sub)packet's content are now passed to
the verify_packet security op. This is currently expected to decrypt
the packet in place and validate it.
However, there's now nowhere to store the revised offset and length of
the actual data within the decrypted blob (there may be a header and
padding to skip) because an sk_buff may represent multiple packets, so
a locate_data security op is added to retrieve these details from the
sk_buff content when needed.
(6) recvmsg() now has to handle jumbo subpackets, where each subpacket is
individually secured and needs to be individually decrypted. The code
to do this is broken out into rxrpc_recvmsg_data() and shared with the
kernel API. It now iterates over the call's receive buffer rather
than walking the socket receive queue.
Additional changes:
(1) The timers are condensed to a single timer that is set for the soonest
of three timeouts (delayed ACK generation, DATA retransmission and
call lifespan).
(2) Transmission of ACK and ABORT packets is effected immediately from
process-context socket ops/kernel API calls that cause them instead of
them being punted off to a background work item. The data_ready
handler still has to defer to the background, though.
(3) A shutdown op is added to the AF_RXRPC socket so that the AFS
filesystem can shut down the socket and flush its own work items
before closing the socket to deal with any in-progress service calls.
Future additional changes that will need to be considered:
(1) Make sure that a call doesn't hog the front of the queue by receiving
data from the network as fast as userspace is consuming it to the
exclusion of other calls.
(2) Transmit delayed ACKs from within recvmsg() when we've consumed
sufficiently more packets to avoid the background work item needing to
run.
Signed-off-by: David Howells <dhowells@redhat.com>
2016-09-08 18:10:12 +08:00
|
|
|
out:
|
2022-10-27 18:25:55 +08:00
|
|
|
if (__rxrpc_call_is_complete(call)) {
|
2020-01-23 21:13:41 +08:00
|
|
|
del_timer_sync(&call->timer);
|
2022-10-13 00:01:25 +08:00
|
|
|
if (!test_bit(RXRPC_CALL_DISCONNECTED, &call->flags))
|
|
|
|
rxrpc_disconnect_call(call);
|
|
|
|
if (call->security)
|
|
|
|
call->security->free_call_crypto(call);
|
|
|
|
}
|
2020-01-23 21:13:41 +08:00
|
|
|
if (call->acks_hard_ack != call->tx_bottom)
|
|
|
|
rxrpc_shrink_call_tx_buffer(call);
|
2007-04-27 06:48:28 +08:00
|
|
|
_leave("");
|
2022-10-07 04:45:42 +08:00
|
|
|
return true;
|
2007-04-27 06:48:28 +08:00
|
|
|
}
|