2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2007-04-27 06:48:28 +08:00
|
|
|
/* RxRPC packet transmission
|
|
|
|
*
|
|
|
|
* 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/net.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/gfp.h>
|
2007-04-27 06:48:28 +08:00
|
|
|
#include <linux/skbuff.h>
|
2011-07-15 23:47:34 +08:00
|
|
|
#include <linux/export.h>
|
2007-04-27 06:48:28 +08:00
|
|
|
#include <net/sock.h>
|
|
|
|
#include <net/af_rxrpc.h>
|
2022-03-22 19:07:20 +08:00
|
|
|
#include <net/udp.h>
|
2007-04-27 06:48:28 +08:00
|
|
|
#include "ar-internal.h"
|
|
|
|
|
2022-03-22 19:07:20 +08:00
|
|
|
extern int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len);
|
|
|
|
|
|
|
|
static ssize_t do_udp_sendmsg(struct socket *sk, struct msghdr *msg, size_t len)
|
|
|
|
{
|
|
|
|
#if IS_ENABLED(CONFIG_AF_RXRPC_IPV6)
|
|
|
|
struct sockaddr *sa = msg->msg_name;
|
|
|
|
|
|
|
|
if (sa->sa_family == AF_INET6)
|
|
|
|
return udpv6_sendmsg(sk->sk, msg, len);
|
|
|
|
#endif
|
|
|
|
return udp_sendmsg(sk->sk, msg, len);
|
|
|
|
}
|
|
|
|
|
2016-10-06 15:11:49 +08:00
|
|
|
struct rxrpc_abort_buffer {
|
|
|
|
struct rxrpc_wire_header whdr;
|
|
|
|
__be32 abort_code;
|
|
|
|
};
|
|
|
|
|
2018-03-31 04:04:43 +08:00
|
|
|
static const char rxrpc_keepalive_string[] = "";
|
|
|
|
|
2018-11-01 21:39:53 +08:00
|
|
|
/*
|
|
|
|
* Increase Tx backoff on transmission failure and clear it on success.
|
|
|
|
*/
|
|
|
|
static void rxrpc_tx_backoff(struct rxrpc_call *call, int ret)
|
|
|
|
{
|
|
|
|
if (ret < 0) {
|
|
|
|
u16 tx_backoff = READ_ONCE(call->tx_backoff);
|
|
|
|
|
|
|
|
if (tx_backoff < HZ)
|
|
|
|
WRITE_ONCE(call->tx_backoff, tx_backoff + 1);
|
|
|
|
} else {
|
|
|
|
WRITE_ONCE(call->tx_backoff, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-24 18:18:42 +08:00
|
|
|
/*
|
|
|
|
* Arrange for a keepalive ping a certain time after we last transmitted. This
|
|
|
|
* lets the far side know we're still interested in this call and helps keep
|
|
|
|
* the route through any intervening firewall open.
|
|
|
|
*
|
|
|
|
* Receiving a response to the ping will prevent the ->expect_rx_by timer from
|
|
|
|
* expiring.
|
|
|
|
*/
|
|
|
|
static void rxrpc_set_keepalive(struct rxrpc_call *call)
|
|
|
|
{
|
|
|
|
unsigned long now = jiffies, keepalive_at = call->next_rx_timo / 6;
|
|
|
|
|
|
|
|
keepalive_at += now;
|
|
|
|
WRITE_ONCE(call->keepalive_at, keepalive_at);
|
|
|
|
rxrpc_reduce_call_timer(call, keepalive_at, now,
|
|
|
|
rxrpc_timer_set_for_keepalive);
|
|
|
|
}
|
|
|
|
|
2016-09-07 16:19:31 +08:00
|
|
|
/*
|
|
|
|
* Fill out an ACK packet.
|
|
|
|
*/
|
2017-11-02 23:06:55 +08:00
|
|
|
static size_t rxrpc_fill_out_ack(struct rxrpc_connection *conn,
|
|
|
|
struct rxrpc_call *call,
|
2020-01-31 05:48:13 +08:00
|
|
|
struct rxrpc_txbuf *txb,
|
2016-09-25 01:05:26 +08:00
|
|
|
rxrpc_seq_t *_hard_ack,
|
2020-01-31 05:48:13 +08:00
|
|
|
rxrpc_seq_t *_top)
|
2016-09-07 16:19:31 +08:00
|
|
|
{
|
2020-01-31 05:48:13 +08:00
|
|
|
struct rxrpc_ackinfo ackinfo;
|
2022-05-21 16:03:31 +08:00
|
|
|
unsigned int tmp;
|
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
|
|
|
rxrpc_seq_t hard_ack, top, seq;
|
|
|
|
int ix;
|
2016-09-07 16:19:31 +08:00
|
|
|
u32 mtu, jmax;
|
2020-01-31 05:48:13 +08:00
|
|
|
u8 *ackp = txb->acks;
|
2016-09-07 16:19:31 +08:00
|
|
|
|
2022-05-21 16:03:31 +08:00
|
|
|
tmp = atomic_xchg(&call->ackr_nr_unacked, 0);
|
|
|
|
tmp |= atomic_xchg(&call->ackr_nr_consumed, 0);
|
2020-01-31 05:48:13 +08:00
|
|
|
if (!tmp && (txb->ack.reason == RXRPC_ACK_DELAY ||
|
|
|
|
txb->ack.reason == RXRPC_ACK_IDLE)) {
|
2022-05-11 21:01:25 +08:00
|
|
|
rxrpc_inc_stat(call->rxnet, stat_tx_ack_skip);
|
2022-05-21 16:03:31 +08:00
|
|
|
return 0;
|
2022-05-11 21:01:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rxrpc_inc_stat(call->rxnet, stat_tx_ack_fill);
|
2022-05-21 16:03:31 +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
|
|
|
/* Barrier against rxrpc_input_data(). */
|
|
|
|
hard_ack = READ_ONCE(call->rx_hard_ack);
|
|
|
|
top = smp_load_acquire(&call->rx_top);
|
2016-09-25 01:05:26 +08:00
|
|
|
*_hard_ack = hard_ack;
|
|
|
|
*_top = top;
|
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
|
|
|
|
2020-01-31 05:48:13 +08:00
|
|
|
txb->ack.firstPacket = htonl(hard_ack + 1);
|
|
|
|
txb->ack.previousPacket = htonl(call->ackr_highest_seq);
|
|
|
|
txb->ack.nAcks = top - hard_ack;
|
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
|
|
|
|
2020-01-31 05:48:13 +08:00
|
|
|
if (txb->ack.nAcks) {
|
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
|
|
|
seq = hard_ack + 1;
|
|
|
|
do {
|
|
|
|
ix = seq & RXRPC_RXTX_BUFF_MASK;
|
|
|
|
if (call->rxtx_buffer[ix])
|
|
|
|
*ackp++ = RXRPC_ACK_TYPE_ACK;
|
|
|
|
else
|
|
|
|
*ackp++ = RXRPC_ACK_TYPE_NACK;
|
|
|
|
seq++;
|
|
|
|
} while (before_eq(seq, top));
|
2020-01-31 05:48:14 +08:00
|
|
|
} else if (txb->ack.reason == RXRPC_ACK_DELAY) {
|
|
|
|
txb->ack.reason = RXRPC_ACK_IDLE;
|
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-07 16:19:31 +08:00
|
|
|
|
2017-11-02 23:06:55 +08:00
|
|
|
mtu = conn->params.peer->if_mtu;
|
|
|
|
mtu -= conn->params.peer->hdrsize;
|
2016-09-14 05:36:22 +08:00
|
|
|
jmax = (call->nr_jumbo_bad > 3) ? 1 : rxrpc_rx_jumbo_max;
|
2020-01-31 05:48:13 +08:00
|
|
|
ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
|
|
|
|
ackinfo.maxMTU = htonl(mtu);
|
|
|
|
ackinfo.rwind = htonl(call->rx_winsize);
|
|
|
|
ackinfo.jumbo_max = htonl(jmax);
|
2016-09-07 16:19:31 +08:00
|
|
|
|
|
|
|
*ackp++ = 0;
|
|
|
|
*ackp++ = 0;
|
|
|
|
*ackp++ = 0;
|
2020-01-31 05:48:13 +08:00
|
|
|
memcpy(ackp, &ackinfo, sizeof(ackinfo));
|
|
|
|
return top - hard_ack + 3 + sizeof(ackinfo);
|
2016-09-07 16:19:31 +08:00
|
|
|
}
|
|
|
|
|
rxrpc: Fix loss of RTT samples due to interposed ACK
The Rx protocol has a mechanism to help generate RTT samples that works by
a client transmitting a REQUESTED-type ACK when it receives a DATA packet
that has the REQUEST_ACK flag set.
The peer, however, may interpose other ACKs before transmitting the
REQUESTED-ACK, as can be seen in the following trace excerpt:
rxrpc_tx_data: c=00000044 DATA d0b5ece8:00000001 00000001 q=00000001 fl=07
rxrpc_rx_ack: c=00000044 00000001 PNG r=00000000 f=00000002 p=00000000 n=0
rxrpc_rx_ack: c=00000044 00000002 REQ r=00000001 f=00000002 p=00000001 n=0
...
DATA packet 1 (q=xx) has REQUEST_ACK set (bit 1 of fl=xx). The incoming
ping (labelled PNG) hard-acks the request DATA packet (f=xx exceeds the
sequence number of the DATA packet), causing it to be discarded from the Tx
ring. The ACK that was requested (labelled REQ, r=xx references the serial
of the DATA packet) comes after the ping, but the sk_buff holding the
timestamp has gone and the RTT sample is lost.
This is particularly noticeable on RPC calls used to probe the service
offered by the peer. A lot of peers end up with an unknown RTT because we
only ever sent a single RPC. This confuses the server rotation algorithm.
Fix this by caching the information about the outgoing packet in RTT
calculations in the rxrpc_call struct rather than looking in the Tx ring.
A four-deep buffer is maintained and both REQUEST_ACK-flagged DATA and
PING-ACK transmissions are recorded in there. When the appropriate
response ACK is received, the buffer is checked for a match and, if found,
an RTT sample is recorded.
If a received ACK refers to a packet with a later serial number than an
entry in the cache, that entry is presumed lost and the entry is made
available to record a new transmission.
ACKs types other than REQUESTED-type and PING-type cause any matching
sample to be cancelled as they don't necessarily represent a useful
measurement.
If there's no space in the buffer on ping/data transmission, the sample
base is discarded.
Fixes: 50235c4b5a2f ("rxrpc: Obtain RTT data by requesting ACKs on DATA packets")
Signed-off-by: David Howells <dhowells@redhat.com>
2020-08-20 06:29:16 +08:00
|
|
|
/*
|
|
|
|
* Record the beginning of an RTT probe.
|
|
|
|
*/
|
|
|
|
static int rxrpc_begin_rtt_probe(struct rxrpc_call *call, rxrpc_serial_t serial,
|
|
|
|
enum rxrpc_rtt_tx_trace why)
|
|
|
|
{
|
|
|
|
unsigned long avail = call->rtt_avail;
|
|
|
|
int rtt_slot = 9;
|
|
|
|
|
|
|
|
if (!(avail & RXRPC_CALL_RTT_AVAIL_MASK))
|
|
|
|
goto no_slot;
|
|
|
|
|
|
|
|
rtt_slot = __ffs(avail & RXRPC_CALL_RTT_AVAIL_MASK);
|
|
|
|
if (!test_and_clear_bit(rtt_slot, &call->rtt_avail))
|
|
|
|
goto no_slot;
|
|
|
|
|
|
|
|
call->rtt_serial[rtt_slot] = serial;
|
|
|
|
call->rtt_sent_at[rtt_slot] = ktime_get_real();
|
|
|
|
smp_wmb(); /* Write data before avail bit */
|
|
|
|
set_bit(rtt_slot + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail);
|
|
|
|
|
|
|
|
trace_rxrpc_rtt_tx(call, why, rtt_slot, serial);
|
|
|
|
return rtt_slot;
|
|
|
|
|
|
|
|
no_slot:
|
|
|
|
trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_no_slot, rtt_slot, serial);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cancel an RTT probe.
|
|
|
|
*/
|
|
|
|
static void rxrpc_cancel_rtt_probe(struct rxrpc_call *call,
|
|
|
|
rxrpc_serial_t serial, int rtt_slot)
|
|
|
|
{
|
|
|
|
if (rtt_slot != -1) {
|
|
|
|
clear_bit(rtt_slot + RXRPC_CALL_RTT_PEND_SHIFT, &call->rtt_avail);
|
|
|
|
smp_wmb(); /* Clear pending bit before setting slot */
|
|
|
|
set_bit(rtt_slot, &call->rtt_avail);
|
|
|
|
trace_rxrpc_rtt_tx(call, rxrpc_rtt_tx_cancel, rtt_slot, serial);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-07 16:19:31 +08:00
|
|
|
/*
|
2016-10-06 15:11:49 +08:00
|
|
|
* Send an ACK call packet.
|
2016-09-07 16:19:31 +08:00
|
|
|
*/
|
2020-01-31 05:48:13 +08:00
|
|
|
static int rxrpc_send_ack_packet(struct rxrpc_local *local, struct rxrpc_txbuf *txb)
|
2016-09-07 16:19:31 +08:00
|
|
|
{
|
2020-01-31 05:50:36 +08:00
|
|
|
struct rxrpc_connection *conn;
|
2016-10-06 15:11:49 +08:00
|
|
|
struct rxrpc_ack_buffer *pkt;
|
2020-01-31 05:48:13 +08:00
|
|
|
struct rxrpc_call *call = txb->call;
|
2016-09-07 16:19:31 +08:00
|
|
|
struct msghdr msg;
|
2020-01-31 05:48:13 +08:00
|
|
|
struct kvec iov[1];
|
2016-09-07 16:19:31 +08:00
|
|
|
rxrpc_serial_t serial;
|
2016-09-25 01:05:26 +08:00
|
|
|
rxrpc_seq_t hard_ack, top;
|
2016-09-07 16:19:31 +08:00
|
|
|
size_t len, n;
|
rxrpc: Fix loss of RTT samples due to interposed ACK
The Rx protocol has a mechanism to help generate RTT samples that works by
a client transmitting a REQUESTED-type ACK when it receives a DATA packet
that has the REQUEST_ACK flag set.
The peer, however, may interpose other ACKs before transmitting the
REQUESTED-ACK, as can be seen in the following trace excerpt:
rxrpc_tx_data: c=00000044 DATA d0b5ece8:00000001 00000001 q=00000001 fl=07
rxrpc_rx_ack: c=00000044 00000001 PNG r=00000000 f=00000002 p=00000000 n=0
rxrpc_rx_ack: c=00000044 00000002 REQ r=00000001 f=00000002 p=00000001 n=0
...
DATA packet 1 (q=xx) has REQUEST_ACK set (bit 1 of fl=xx). The incoming
ping (labelled PNG) hard-acks the request DATA packet (f=xx exceeds the
sequence number of the DATA packet), causing it to be discarded from the Tx
ring. The ACK that was requested (labelled REQ, r=xx references the serial
of the DATA packet) comes after the ping, but the sk_buff holding the
timestamp has gone and the RTT sample is lost.
This is particularly noticeable on RPC calls used to probe the service
offered by the peer. A lot of peers end up with an unknown RTT because we
only ever sent a single RPC. This confuses the server rotation algorithm.
Fix this by caching the information about the outgoing packet in RTT
calculations in the rxrpc_call struct rather than looking in the Tx ring.
A four-deep buffer is maintained and both REQUEST_ACK-flagged DATA and
PING-ACK transmissions are recorded in there. When the appropriate
response ACK is received, the buffer is checked for a match and, if found,
an RTT sample is recorded.
If a received ACK refers to a packet with a later serial number than an
entry in the cache, that entry is presumed lost and the entry is made
available to record a new transmission.
ACKs types other than REQUESTED-type and PING-type cause any matching
sample to be cancelled as they don't necessarily represent a useful
measurement.
If there's no space in the buffer on ping/data transmission, the sample
base is discarded.
Fixes: 50235c4b5a2f ("rxrpc: Obtain RTT data by requesting ACKs on DATA packets")
Signed-off-by: David Howells <dhowells@redhat.com>
2020-08-20 06:29:16 +08:00
|
|
|
int ret, rtt_slot = -1;
|
2016-09-07 16:19:31 +08:00
|
|
|
|
2020-01-31 05:50:36 +08:00
|
|
|
if (test_bit(RXRPC_CALL_DISCONNECTED, &call->flags))
|
2016-09-07 16:19:31 +08:00
|
|
|
return -ECONNRESET;
|
|
|
|
|
2020-01-31 05:50:36 +08:00
|
|
|
conn = call->conn;
|
2016-09-07 16:19:31 +08:00
|
|
|
|
|
|
|
msg.msg_name = &call->peer->srx.transport;
|
|
|
|
msg.msg_namelen = call->peer->srx.transport_len;
|
|
|
|
msg.msg_control = NULL;
|
|
|
|
msg.msg_controllen = 0;
|
|
|
|
msg.msg_flags = 0;
|
|
|
|
|
2020-01-31 05:48:13 +08:00
|
|
|
if (txb->ack.reason == RXRPC_ACK_PING)
|
|
|
|
txb->wire.flags |= RXRPC_REQUEST_ACK;
|
2016-09-07 16:19:31 +08:00
|
|
|
|
2020-01-31 05:48:14 +08:00
|
|
|
if (txb->ack.reason == RXRPC_ACK_DELAY)
|
|
|
|
clear_bit(RXRPC_CALL_DELAY_ACK_PENDING, &call->flags);
|
|
|
|
if (txb->ack.reason == RXRPC_ACK_IDLE)
|
|
|
|
clear_bit(RXRPC_CALL_IDLE_ACK_PENDING, &call->flags);
|
|
|
|
|
2016-10-06 15:11:49 +08:00
|
|
|
spin_lock_bh(&call->lock);
|
2020-01-31 05:48:13 +08:00
|
|
|
n = rxrpc_fill_out_ack(conn, call, txb, &hard_ack, &top);
|
2016-10-06 15:11:49 +08:00
|
|
|
spin_unlock_bh(&call->lock);
|
2022-05-21 16:03:31 +08:00
|
|
|
if (n == 0) {
|
|
|
|
kfree(pkt);
|
|
|
|
return 0;
|
|
|
|
}
|
2016-10-06 15:11:49 +08:00
|
|
|
|
2020-01-31 05:48:13 +08:00
|
|
|
iov[0].iov_base = &txb->wire;
|
|
|
|
iov[0].iov_len = sizeof(txb->wire) + sizeof(txb->ack) + n;
|
|
|
|
len = iov[0].iov_len;
|
2016-09-07 16:19:31 +08:00
|
|
|
|
2016-09-23 22:08:48 +08:00
|
|
|
serial = atomic_inc_return(&conn->serial);
|
2020-01-31 05:48:13 +08:00
|
|
|
txb->wire.serial = htonl(serial);
|
2018-07-24 00:18:37 +08:00
|
|
|
trace_rxrpc_tx_ack(call->debug_id, serial,
|
2020-01-31 05:48:13 +08:00
|
|
|
ntohl(txb->ack.firstPacket),
|
|
|
|
ntohl(txb->ack.serial), txb->ack.reason, txb->ack.nAcks);
|
|
|
|
if (txb->ack_why == rxrpc_propose_ack_ping_for_lost_ack)
|
|
|
|
call->acks_lost_ping = serial;
|
2016-09-23 22:08:48 +08:00
|
|
|
|
2020-01-31 05:48:13 +08:00
|
|
|
if (txb->ack.reason == RXRPC_ACK_PING)
|
rxrpc: Fix loss of RTT samples due to interposed ACK
The Rx protocol has a mechanism to help generate RTT samples that works by
a client transmitting a REQUESTED-type ACK when it receives a DATA packet
that has the REQUEST_ACK flag set.
The peer, however, may interpose other ACKs before transmitting the
REQUESTED-ACK, as can be seen in the following trace excerpt:
rxrpc_tx_data: c=00000044 DATA d0b5ece8:00000001 00000001 q=00000001 fl=07
rxrpc_rx_ack: c=00000044 00000001 PNG r=00000000 f=00000002 p=00000000 n=0
rxrpc_rx_ack: c=00000044 00000002 REQ r=00000001 f=00000002 p=00000001 n=0
...
DATA packet 1 (q=xx) has REQUEST_ACK set (bit 1 of fl=xx). The incoming
ping (labelled PNG) hard-acks the request DATA packet (f=xx exceeds the
sequence number of the DATA packet), causing it to be discarded from the Tx
ring. The ACK that was requested (labelled REQ, r=xx references the serial
of the DATA packet) comes after the ping, but the sk_buff holding the
timestamp has gone and the RTT sample is lost.
This is particularly noticeable on RPC calls used to probe the service
offered by the peer. A lot of peers end up with an unknown RTT because we
only ever sent a single RPC. This confuses the server rotation algorithm.
Fix this by caching the information about the outgoing packet in RTT
calculations in the rxrpc_call struct rather than looking in the Tx ring.
A four-deep buffer is maintained and both REQUEST_ACK-flagged DATA and
PING-ACK transmissions are recorded in there. When the appropriate
response ACK is received, the buffer is checked for a match and, if found,
an RTT sample is recorded.
If a received ACK refers to a packet with a later serial number than an
entry in the cache, that entry is presumed lost and the entry is made
available to record a new transmission.
ACKs types other than REQUESTED-type and PING-type cause any matching
sample to be cancelled as they don't necessarily represent a useful
measurement.
If there's no space in the buffer on ping/data transmission, the sample
base is discarded.
Fixes: 50235c4b5a2f ("rxrpc: Obtain RTT data by requesting ACKs on DATA packets")
Signed-off-by: David Howells <dhowells@redhat.com>
2020-08-20 06:29:16 +08:00
|
|
|
rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_ping);
|
2016-10-06 15:11:49 +08:00
|
|
|
|
2022-05-11 21:01:25 +08:00
|
|
|
rxrpc_inc_stat(call->rxnet, stat_tx_ack_send);
|
2022-03-22 19:07:20 +08:00
|
|
|
|
2020-01-31 05:48:13 +08:00
|
|
|
iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, len);
|
2022-03-22 19:07:20 +08:00
|
|
|
ret = do_udp_sendmsg(conn->params.local->socket, &msg, len);
|
|
|
|
call->peer->last_tx_at = ktime_get_seconds();
|
2018-05-11 06:26:01 +08:00
|
|
|
if (ret < 0)
|
|
|
|
trace_rxrpc_tx_fail(call->debug_id, serial, ret,
|
2018-07-24 00:18:37 +08:00
|
|
|
rxrpc_tx_point_call_ack);
|
|
|
|
else
|
2020-01-31 05:48:13 +08:00
|
|
|
trace_rxrpc_tx_packet(call->debug_id, &txb->wire,
|
2018-07-24 00:18:37 +08:00
|
|
|
rxrpc_tx_point_call_ack);
|
2018-11-01 21:39:53 +08:00
|
|
|
rxrpc_tx_backoff(call, ret);
|
2016-09-07 16:19:31 +08:00
|
|
|
|
2016-10-06 15:11:49 +08:00
|
|
|
if (call->state < RXRPC_CALL_COMPLETE) {
|
2020-01-31 05:48:13 +08:00
|
|
|
if (ret < 0)
|
rxrpc: Fix loss of RTT samples due to interposed ACK
The Rx protocol has a mechanism to help generate RTT samples that works by
a client transmitting a REQUESTED-type ACK when it receives a DATA packet
that has the REQUEST_ACK flag set.
The peer, however, may interpose other ACKs before transmitting the
REQUESTED-ACK, as can be seen in the following trace excerpt:
rxrpc_tx_data: c=00000044 DATA d0b5ece8:00000001 00000001 q=00000001 fl=07
rxrpc_rx_ack: c=00000044 00000001 PNG r=00000000 f=00000002 p=00000000 n=0
rxrpc_rx_ack: c=00000044 00000002 REQ r=00000001 f=00000002 p=00000001 n=0
...
DATA packet 1 (q=xx) has REQUEST_ACK set (bit 1 of fl=xx). The incoming
ping (labelled PNG) hard-acks the request DATA packet (f=xx exceeds the
sequence number of the DATA packet), causing it to be discarded from the Tx
ring. The ACK that was requested (labelled REQ, r=xx references the serial
of the DATA packet) comes after the ping, but the sk_buff holding the
timestamp has gone and the RTT sample is lost.
This is particularly noticeable on RPC calls used to probe the service
offered by the peer. A lot of peers end up with an unknown RTT because we
only ever sent a single RPC. This confuses the server rotation algorithm.
Fix this by caching the information about the outgoing packet in RTT
calculations in the rxrpc_call struct rather than looking in the Tx ring.
A four-deep buffer is maintained and both REQUEST_ACK-flagged DATA and
PING-ACK transmissions are recorded in there. When the appropriate
response ACK is received, the buffer is checked for a match and, if found,
an RTT sample is recorded.
If a received ACK refers to a packet with a later serial number than an
entry in the cache, that entry is presumed lost and the entry is made
available to record a new transmission.
ACKs types other than REQUESTED-type and PING-type cause any matching
sample to be cancelled as they don't necessarily represent a useful
measurement.
If there's no space in the buffer on ping/data transmission, the sample
base is discarded.
Fixes: 50235c4b5a2f ("rxrpc: Obtain RTT data by requesting ACKs on DATA packets")
Signed-off-by: David Howells <dhowells@redhat.com>
2020-08-20 06:29:16 +08:00
|
|
|
rxrpc_cancel_rtt_probe(call, serial, rtt_slot);
|
2017-11-24 18:18:42 +08:00
|
|
|
rxrpc_set_keepalive(call);
|
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-07 16:19:31 +08:00
|
|
|
kfree(pkt);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-01-31 05:48:13 +08:00
|
|
|
/*
|
|
|
|
* ACK transmitter for a local endpoint. The UDP socket locks around each
|
|
|
|
* transmission, so we can only transmit one packet at a time, ACK, DATA or
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
void rxrpc_transmit_ack_packets(struct rxrpc_local *local)
|
|
|
|
{
|
|
|
|
LIST_HEAD(queue);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
trace_rxrpc_local(local->debug_id, rxrpc_local_tx_ack,
|
|
|
|
refcount_read(&local->ref), NULL);
|
|
|
|
|
|
|
|
if (list_empty(&local->ack_tx_queue))
|
|
|
|
return;
|
|
|
|
|
|
|
|
spin_lock_bh(&local->ack_tx_lock);
|
|
|
|
list_splice_tail_init(&local->ack_tx_queue, &queue);
|
|
|
|
spin_unlock_bh(&local->ack_tx_lock);
|
|
|
|
|
|
|
|
while (!list_empty(&queue)) {
|
|
|
|
struct rxrpc_txbuf *txb =
|
|
|
|
list_entry(queue.next, struct rxrpc_txbuf, tx_link);
|
|
|
|
|
|
|
|
ret = rxrpc_send_ack_packet(local, txb);
|
|
|
|
if (ret < 0 && ret != -ECONNRESET) {
|
|
|
|
spin_lock_bh(&local->ack_tx_lock);
|
|
|
|
list_splice_init(&queue, &local->ack_tx_queue);
|
|
|
|
spin_unlock_bh(&local->ack_tx_lock);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_del_init(&txb->tx_link);
|
|
|
|
rxrpc_put_call(txb->call, rxrpc_call_put);
|
|
|
|
rxrpc_put_txbuf(txb, rxrpc_txbuf_put_ack_tx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-06 15:11:49 +08:00
|
|
|
/*
|
|
|
|
* Send an ABORT call packet.
|
|
|
|
*/
|
|
|
|
int rxrpc_send_abort_packet(struct rxrpc_call *call)
|
|
|
|
{
|
2020-01-31 05:50:36 +08:00
|
|
|
struct rxrpc_connection *conn;
|
2016-10-06 15:11:49 +08:00
|
|
|
struct rxrpc_abort_buffer pkt;
|
|
|
|
struct msghdr msg;
|
|
|
|
struct kvec iov[1];
|
|
|
|
rxrpc_serial_t serial;
|
|
|
|
int ret;
|
|
|
|
|
2017-11-02 23:06:26 +08:00
|
|
|
/* Don't bother sending aborts for a client call once the server has
|
|
|
|
* hard-ACK'd all of its request data. After that point, we're not
|
|
|
|
* going to stop the operation proceeding, and whilst we might limit
|
|
|
|
* the reply, it's not worth it if we can send a new call on the same
|
|
|
|
* channel instead, thereby closing off this call.
|
|
|
|
*/
|
|
|
|
if (rxrpc_is_client_call(call) &&
|
|
|
|
test_bit(RXRPC_CALL_TX_LAST, &call->flags))
|
|
|
|
return 0;
|
|
|
|
|
2020-01-31 05:50:36 +08:00
|
|
|
if (test_bit(RXRPC_CALL_DISCONNECTED, &call->flags))
|
2016-10-06 15:11:49 +08:00
|
|
|
return -ECONNRESET;
|
|
|
|
|
2020-01-31 05:50:36 +08:00
|
|
|
conn = call->conn;
|
|
|
|
|
2016-10-06 15:11:49 +08:00
|
|
|
msg.msg_name = &call->peer->srx.transport;
|
|
|
|
msg.msg_namelen = call->peer->srx.transport_len;
|
|
|
|
msg.msg_control = NULL;
|
|
|
|
msg.msg_controllen = 0;
|
|
|
|
msg.msg_flags = 0;
|
|
|
|
|
|
|
|
pkt.whdr.epoch = htonl(conn->proto.epoch);
|
|
|
|
pkt.whdr.cid = htonl(call->cid);
|
|
|
|
pkt.whdr.callNumber = htonl(call->call_id);
|
|
|
|
pkt.whdr.seq = 0;
|
|
|
|
pkt.whdr.type = RXRPC_PACKET_TYPE_ABORT;
|
|
|
|
pkt.whdr.flags = conn->out_clientflag;
|
|
|
|
pkt.whdr.userStatus = 0;
|
|
|
|
pkt.whdr.securityIndex = call->security_ix;
|
|
|
|
pkt.whdr._rsvd = 0;
|
|
|
|
pkt.whdr.serviceId = htons(call->service_id);
|
|
|
|
pkt.abort_code = htonl(call->abort_code);
|
|
|
|
|
|
|
|
iov[0].iov_base = &pkt;
|
|
|
|
iov[0].iov_len = sizeof(pkt);
|
|
|
|
|
|
|
|
serial = atomic_inc_return(&conn->serial);
|
|
|
|
pkt.whdr.serial = htonl(serial);
|
|
|
|
|
2022-03-22 19:07:20 +08:00
|
|
|
iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, sizeof(pkt));
|
|
|
|
ret = do_udp_sendmsg(conn->params.local->socket, &msg, sizeof(pkt));
|
2018-08-08 18:30:02 +08:00
|
|
|
conn->params.peer->last_tx_at = ktime_get_seconds();
|
2018-05-11 06:26:01 +08:00
|
|
|
if (ret < 0)
|
|
|
|
trace_rxrpc_tx_fail(call->debug_id, serial, ret,
|
2018-07-24 00:18:37 +08:00
|
|
|
rxrpc_tx_point_call_abort);
|
|
|
|
else
|
|
|
|
trace_rxrpc_tx_packet(call->debug_id, &pkt.whdr,
|
|
|
|
rxrpc_tx_point_call_abort);
|
2018-11-01 21:39:53 +08:00
|
|
|
rxrpc_tx_backoff(call, ret);
|
2016-10-06 15:11:49 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-04-27 06:48:28 +08:00
|
|
|
/*
|
|
|
|
* send a packet through the transport endpoint
|
|
|
|
*/
|
2016-09-30 05:37:15 +08:00
|
|
|
int rxrpc_send_data_packet(struct rxrpc_call *call, struct sk_buff *skb,
|
|
|
|
bool retrans)
|
2007-04-27 06:48:28 +08:00
|
|
|
{
|
2022-04-06 04:48:48 +08:00
|
|
|
enum rxrpc_req_ack_trace why;
|
2016-09-22 07:29:31 +08:00
|
|
|
struct rxrpc_connection *conn = call->conn;
|
|
|
|
struct rxrpc_wire_header whdr;
|
|
|
|
struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
|
2007-04-27 06:48:28 +08:00
|
|
|
struct msghdr msg;
|
2016-09-22 07:29:31 +08:00
|
|
|
struct kvec iov[2];
|
|
|
|
rxrpc_serial_t serial;
|
|
|
|
size_t len;
|
rxrpc: Fix loss of RTT samples due to interposed ACK
The Rx protocol has a mechanism to help generate RTT samples that works by
a client transmitting a REQUESTED-type ACK when it receives a DATA packet
that has the REQUEST_ACK flag set.
The peer, however, may interpose other ACKs before transmitting the
REQUESTED-ACK, as can be seen in the following trace excerpt:
rxrpc_tx_data: c=00000044 DATA d0b5ece8:00000001 00000001 q=00000001 fl=07
rxrpc_rx_ack: c=00000044 00000001 PNG r=00000000 f=00000002 p=00000000 n=0
rxrpc_rx_ack: c=00000044 00000002 REQ r=00000001 f=00000002 p=00000001 n=0
...
DATA packet 1 (q=xx) has REQUEST_ACK set (bit 1 of fl=xx). The incoming
ping (labelled PNG) hard-acks the request DATA packet (f=xx exceeds the
sequence number of the DATA packet), causing it to be discarded from the Tx
ring. The ACK that was requested (labelled REQ, r=xx references the serial
of the DATA packet) comes after the ping, but the sk_buff holding the
timestamp has gone and the RTT sample is lost.
This is particularly noticeable on RPC calls used to probe the service
offered by the peer. A lot of peers end up with an unknown RTT because we
only ever sent a single RPC. This confuses the server rotation algorithm.
Fix this by caching the information about the outgoing packet in RTT
calculations in the rxrpc_call struct rather than looking in the Tx ring.
A four-deep buffer is maintained and both REQUEST_ACK-flagged DATA and
PING-ACK transmissions are recorded in there. When the appropriate
response ACK is received, the buffer is checked for a match and, if found,
an RTT sample is recorded.
If a received ACK refers to a packet with a later serial number than an
entry in the cache, that entry is presumed lost and the entry is made
available to record a new transmission.
ACKs types other than REQUESTED-type and PING-type cause any matching
sample to be cancelled as they don't necessarily represent a useful
measurement.
If there's no space in the buffer on ping/data transmission, the sample
base is discarded.
Fixes: 50235c4b5a2f ("rxrpc: Obtain RTT data by requesting ACKs on DATA packets")
Signed-off-by: David Howells <dhowells@redhat.com>
2020-08-20 06:29:16 +08:00
|
|
|
int ret, rtt_slot = -1;
|
2007-04-27 06:48:28 +08:00
|
|
|
|
|
|
|
_enter(",{%d}", skb->len);
|
|
|
|
|
rxrpc: Rewrite the client connection manager
Rewrite the rxrpc client connection manager so that it can support multiple
connections for a given security key to a peer. The following changes are
made:
(1) For each open socket, the code currently maintains an rbtree with the
connections placed into it, keyed by communications parameters. This
is tricky to maintain as connections can be culled from the tree or
replaced within it. Connections can require replacement for a number
of reasons, e.g. their IDs span too great a range for the IDR data
type to represent efficiently, the call ID numbers on that conn would
overflow or the conn got aborted.
This is changed so that there's now a connection bundle object placed
in the tree, keyed on the same parameters. The bundle, however, does
not need to be replaced.
(2) An rxrpc_bundle object can now manage the available channels for a set
of parallel connections. The lock that manages this is moved there
from the rxrpc_connection struct (channel_lock).
(3) There'a a dummy bundle for all incoming connections to share so that
they have a channel_lock too. It might be better to give each
incoming connection its own bundle. This bundle is not needed to
manage which channels incoming calls are made on because that's the
solely at whim of the client.
(4) The restrictions on how many client connections are around are
removed. Instead, a previous patch limits the number of client calls
that can be allocated. Ordinarily, client connections are reaped
after 2 minutes on the idle queue, but when more than a certain number
of connections are in existence, the reaper starts reaping them after
2s of idleness instead to get the numbers back down.
It could also be made such that new call allocations are forced to
wait until the number of outstanding connections subsides.
Signed-off-by: David Howells <dhowells@redhat.com>
2020-07-01 18:15:32 +08:00
|
|
|
if (hlist_unhashed(&call->error_link)) {
|
|
|
|
spin_lock_bh(&call->peer->lock);
|
|
|
|
hlist_add_head_rcu(&call->error_link, &call->peer->error_targets);
|
|
|
|
spin_unlock_bh(&call->peer->lock);
|
|
|
|
}
|
|
|
|
|
2016-09-22 07:29:31 +08:00
|
|
|
/* Each transmission of a Tx packet needs a new serial number */
|
|
|
|
serial = atomic_inc_return(&conn->serial);
|
2007-04-27 06:48:28 +08:00
|
|
|
|
2016-09-22 07:29:31 +08:00
|
|
|
whdr.epoch = htonl(conn->proto.epoch);
|
|
|
|
whdr.cid = htonl(call->cid);
|
|
|
|
whdr.callNumber = htonl(call->call_id);
|
|
|
|
whdr.seq = htonl(sp->hdr.seq);
|
|
|
|
whdr.serial = htonl(serial);
|
|
|
|
whdr.type = RXRPC_PACKET_TYPE_DATA;
|
|
|
|
whdr.flags = sp->hdr.flags;
|
|
|
|
whdr.userStatus = 0;
|
|
|
|
whdr.securityIndex = call->security_ix;
|
|
|
|
whdr._rsvd = htons(sp->hdr._rsvd);
|
|
|
|
whdr.serviceId = htons(call->service_id);
|
|
|
|
|
2017-06-05 21:30:49 +08:00
|
|
|
if (test_bit(RXRPC_CONN_PROBING_FOR_UPGRADE, &conn->flags) &&
|
|
|
|
sp->hdr.seq == 1)
|
|
|
|
whdr.userStatus = RXRPC_USERSTATUS_SERVICE_UPGRADE;
|
|
|
|
|
2016-09-22 07:29:31 +08:00
|
|
|
iov[0].iov_base = &whdr;
|
|
|
|
iov[0].iov_len = sizeof(whdr);
|
|
|
|
iov[1].iov_base = skb->head;
|
|
|
|
iov[1].iov_len = skb->len;
|
|
|
|
len = iov[0].iov_len + iov[1].iov_len;
|
2022-03-22 19:07:20 +08:00
|
|
|
iov_iter_kvec(&msg.msg_iter, WRITE, iov, 2, len);
|
2016-09-22 07:29:31 +08:00
|
|
|
|
|
|
|
msg.msg_name = &call->peer->srx.transport;
|
|
|
|
msg.msg_namelen = call->peer->srx.transport_len;
|
2007-04-27 06:48:28 +08:00
|
|
|
msg.msg_control = NULL;
|
|
|
|
msg.msg_controllen = 0;
|
|
|
|
msg.msg_flags = 0;
|
|
|
|
|
2016-09-25 01:05:27 +08:00
|
|
|
/* If our RTT cache needs working on, request an ACK. Also request
|
|
|
|
* ACKs if a DATA packet appears to have been lost.
|
2018-09-27 22:13:08 +08:00
|
|
|
*
|
|
|
|
* However, we mustn't request an ACK on the last reply packet of a
|
|
|
|
* service call, lest OpenAFS incorrectly send us an ACK with some
|
|
|
|
* soft-ACKs in it and then never follow up with a proper hard ACK.
|
2016-09-25 01:05:27 +08:00
|
|
|
*/
|
2022-04-06 04:48:48 +08:00
|
|
|
if (whdr.flags & RXRPC_REQUEST_ACK)
|
|
|
|
why = rxrpc_reqack_already_on;
|
|
|
|
else if ((whdr.flags & RXRPC_LAST_PACKET) && rxrpc_to_client(sp))
|
|
|
|
why = rxrpc_reqack_no_srv_last;
|
|
|
|
else if (test_and_clear_bit(RXRPC_CALL_EV_ACK_LOST, &call->events))
|
|
|
|
why = rxrpc_reqack_ack_lost;
|
|
|
|
else if (retrans)
|
|
|
|
why = rxrpc_reqack_retrans;
|
|
|
|
else if (call->cong_mode == RXRPC_CALL_SLOW_START && call->cong_cwnd <= 2)
|
|
|
|
why = rxrpc_reqack_slow_start;
|
|
|
|
else if (call->tx_winsize <= 2)
|
|
|
|
why = rxrpc_reqack_small_txwin;
|
|
|
|
else if (call->peer->rtt_count < 3 && sp->hdr.seq & 1)
|
|
|
|
why = rxrpc_reqack_more_rtt;
|
|
|
|
else if (ktime_before(ktime_add_ms(call->peer->rtt_last_req, 1000), ktime_get_real()))
|
|
|
|
why = rxrpc_reqack_old_rtt;
|
|
|
|
else
|
|
|
|
goto dont_set_request_ack;
|
|
|
|
|
2022-08-18 18:52:36 +08:00
|
|
|
rxrpc_inc_stat(call->rxnet, stat_why_req_ack[why]);
|
2022-04-06 04:48:48 +08:00
|
|
|
trace_rxrpc_req_ack(call->debug_id, sp->hdr.seq, why);
|
|
|
|
if (why != rxrpc_reqack_no_srv_last)
|
2016-09-22 07:29:31 +08:00
|
|
|
whdr.flags |= RXRPC_REQUEST_ACK;
|
2022-04-06 04:48:48 +08:00
|
|
|
dont_set_request_ack:
|
2016-09-22 07:29:31 +08:00
|
|
|
|
2016-09-17 17:49:15 +08:00
|
|
|
if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) {
|
|
|
|
static int lose;
|
|
|
|
if ((lose++ & 7) == 7) {
|
2016-09-30 05:37:15 +08:00
|
|
|
ret = 0;
|
2019-03-22 22:18:43 +08:00
|
|
|
trace_rxrpc_tx_data(call, sp->hdr.seq, serial,
|
|
|
|
whdr.flags, retrans, true);
|
|
|
|
goto done;
|
2016-09-17 17:49:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-22 22:18:43 +08:00
|
|
|
trace_rxrpc_tx_data(call, sp->hdr.seq, serial, whdr.flags, retrans,
|
|
|
|
false);
|
2016-09-22 07:29:31 +08:00
|
|
|
|
2007-04-27 06:48:28 +08:00
|
|
|
/* send the packet with the don't fragment bit set if we currently
|
|
|
|
* think it's small enough */
|
2016-09-22 07:29:31 +08:00
|
|
|
if (iov[1].iov_len >= call->peer->maxdata)
|
|
|
|
goto send_fragmentable;
|
|
|
|
|
|
|
|
down_read(&conn->params.local->defrag_sem);
|
2018-09-27 22:13:08 +08:00
|
|
|
|
|
|
|
sp->hdr.serial = serial;
|
|
|
|
smp_wmb(); /* Set serial before timestamp */
|
|
|
|
skb->tstamp = ktime_get_real();
|
rxrpc: Fix loss of RTT samples due to interposed ACK
The Rx protocol has a mechanism to help generate RTT samples that works by
a client transmitting a REQUESTED-type ACK when it receives a DATA packet
that has the REQUEST_ACK flag set.
The peer, however, may interpose other ACKs before transmitting the
REQUESTED-ACK, as can be seen in the following trace excerpt:
rxrpc_tx_data: c=00000044 DATA d0b5ece8:00000001 00000001 q=00000001 fl=07
rxrpc_rx_ack: c=00000044 00000001 PNG r=00000000 f=00000002 p=00000000 n=0
rxrpc_rx_ack: c=00000044 00000002 REQ r=00000001 f=00000002 p=00000001 n=0
...
DATA packet 1 (q=xx) has REQUEST_ACK set (bit 1 of fl=xx). The incoming
ping (labelled PNG) hard-acks the request DATA packet (f=xx exceeds the
sequence number of the DATA packet), causing it to be discarded from the Tx
ring. The ACK that was requested (labelled REQ, r=xx references the serial
of the DATA packet) comes after the ping, but the sk_buff holding the
timestamp has gone and the RTT sample is lost.
This is particularly noticeable on RPC calls used to probe the service
offered by the peer. A lot of peers end up with an unknown RTT because we
only ever sent a single RPC. This confuses the server rotation algorithm.
Fix this by caching the information about the outgoing packet in RTT
calculations in the rxrpc_call struct rather than looking in the Tx ring.
A four-deep buffer is maintained and both REQUEST_ACK-flagged DATA and
PING-ACK transmissions are recorded in there. When the appropriate
response ACK is received, the buffer is checked for a match and, if found,
an RTT sample is recorded.
If a received ACK refers to a packet with a later serial number than an
entry in the cache, that entry is presumed lost and the entry is made
available to record a new transmission.
ACKs types other than REQUESTED-type and PING-type cause any matching
sample to be cancelled as they don't necessarily represent a useful
measurement.
If there's no space in the buffer on ping/data transmission, the sample
base is discarded.
Fixes: 50235c4b5a2f ("rxrpc: Obtain RTT data by requesting ACKs on DATA packets")
Signed-off-by: David Howells <dhowells@redhat.com>
2020-08-20 06:29:16 +08:00
|
|
|
if (whdr.flags & RXRPC_REQUEST_ACK)
|
|
|
|
rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_data);
|
2018-09-27 22:13:08 +08:00
|
|
|
|
2016-09-22 07:29:31 +08:00
|
|
|
/* send the packet by UDP
|
|
|
|
* - returns -EMSGSIZE if UDP would have to fragment the packet
|
|
|
|
* to go out of the interface
|
|
|
|
* - in which case, we'll have processed the ICMP error
|
|
|
|
* message and update the peer record
|
|
|
|
*/
|
2022-05-11 21:01:25 +08:00
|
|
|
rxrpc_inc_stat(call->rxnet, stat_tx_data_send);
|
2022-03-22 19:07:20 +08:00
|
|
|
ret = do_udp_sendmsg(conn->params.local->socket, &msg, len);
|
2018-08-08 18:30:02 +08:00
|
|
|
conn->params.peer->last_tx_at = ktime_get_seconds();
|
2016-09-22 07:29:31 +08:00
|
|
|
|
|
|
|
up_read(&conn->params.local->defrag_sem);
|
rxrpc: Fix loss of RTT samples due to interposed ACK
The Rx protocol has a mechanism to help generate RTT samples that works by
a client transmitting a REQUESTED-type ACK when it receives a DATA packet
that has the REQUEST_ACK flag set.
The peer, however, may interpose other ACKs before transmitting the
REQUESTED-ACK, as can be seen in the following trace excerpt:
rxrpc_tx_data: c=00000044 DATA d0b5ece8:00000001 00000001 q=00000001 fl=07
rxrpc_rx_ack: c=00000044 00000001 PNG r=00000000 f=00000002 p=00000000 n=0
rxrpc_rx_ack: c=00000044 00000002 REQ r=00000001 f=00000002 p=00000001 n=0
...
DATA packet 1 (q=xx) has REQUEST_ACK set (bit 1 of fl=xx). The incoming
ping (labelled PNG) hard-acks the request DATA packet (f=xx exceeds the
sequence number of the DATA packet), causing it to be discarded from the Tx
ring. The ACK that was requested (labelled REQ, r=xx references the serial
of the DATA packet) comes after the ping, but the sk_buff holding the
timestamp has gone and the RTT sample is lost.
This is particularly noticeable on RPC calls used to probe the service
offered by the peer. A lot of peers end up with an unknown RTT because we
only ever sent a single RPC. This confuses the server rotation algorithm.
Fix this by caching the information about the outgoing packet in RTT
calculations in the rxrpc_call struct rather than looking in the Tx ring.
A four-deep buffer is maintained and both REQUEST_ACK-flagged DATA and
PING-ACK transmissions are recorded in there. When the appropriate
response ACK is received, the buffer is checked for a match and, if found,
an RTT sample is recorded.
If a received ACK refers to a packet with a later serial number than an
entry in the cache, that entry is presumed lost and the entry is made
available to record a new transmission.
ACKs types other than REQUESTED-type and PING-type cause any matching
sample to be cancelled as they don't necessarily represent a useful
measurement.
If there's no space in the buffer on ping/data transmission, the sample
base is discarded.
Fixes: 50235c4b5a2f ("rxrpc: Obtain RTT data by requesting ACKs on DATA packets")
Signed-off-by: David Howells <dhowells@redhat.com>
2020-08-20 06:29:16 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
rxrpc_cancel_rtt_probe(call, serial, rtt_slot);
|
2018-05-11 06:26:01 +08:00
|
|
|
trace_rxrpc_tx_fail(call->debug_id, serial, ret,
|
2018-07-24 00:18:37 +08:00
|
|
|
rxrpc_tx_point_call_data_nofrag);
|
rxrpc: Fix loss of RTT samples due to interposed ACK
The Rx protocol has a mechanism to help generate RTT samples that works by
a client transmitting a REQUESTED-type ACK when it receives a DATA packet
that has the REQUEST_ACK flag set.
The peer, however, may interpose other ACKs before transmitting the
REQUESTED-ACK, as can be seen in the following trace excerpt:
rxrpc_tx_data: c=00000044 DATA d0b5ece8:00000001 00000001 q=00000001 fl=07
rxrpc_rx_ack: c=00000044 00000001 PNG r=00000000 f=00000002 p=00000000 n=0
rxrpc_rx_ack: c=00000044 00000002 REQ r=00000001 f=00000002 p=00000001 n=0
...
DATA packet 1 (q=xx) has REQUEST_ACK set (bit 1 of fl=xx). The incoming
ping (labelled PNG) hard-acks the request DATA packet (f=xx exceeds the
sequence number of the DATA packet), causing it to be discarded from the Tx
ring. The ACK that was requested (labelled REQ, r=xx references the serial
of the DATA packet) comes after the ping, but the sk_buff holding the
timestamp has gone and the RTT sample is lost.
This is particularly noticeable on RPC calls used to probe the service
offered by the peer. A lot of peers end up with an unknown RTT because we
only ever sent a single RPC. This confuses the server rotation algorithm.
Fix this by caching the information about the outgoing packet in RTT
calculations in the rxrpc_call struct rather than looking in the Tx ring.
A four-deep buffer is maintained and both REQUEST_ACK-flagged DATA and
PING-ACK transmissions are recorded in there. When the appropriate
response ACK is received, the buffer is checked for a match and, if found,
an RTT sample is recorded.
If a received ACK refers to a packet with a later serial number than an
entry in the cache, that entry is presumed lost and the entry is made
available to record a new transmission.
ACKs types other than REQUESTED-type and PING-type cause any matching
sample to be cancelled as they don't necessarily represent a useful
measurement.
If there's no space in the buffer on ping/data transmission, the sample
base is discarded.
Fixes: 50235c4b5a2f ("rxrpc: Obtain RTT data by requesting ACKs on DATA packets")
Signed-off-by: David Howells <dhowells@redhat.com>
2020-08-20 06:29:16 +08:00
|
|
|
} else {
|
2018-07-24 00:18:37 +08:00
|
|
|
trace_rxrpc_tx_packet(call->debug_id, &whdr,
|
|
|
|
rxrpc_tx_point_call_data_nofrag);
|
rxrpc: Fix loss of RTT samples due to interposed ACK
The Rx protocol has a mechanism to help generate RTT samples that works by
a client transmitting a REQUESTED-type ACK when it receives a DATA packet
that has the REQUEST_ACK flag set.
The peer, however, may interpose other ACKs before transmitting the
REQUESTED-ACK, as can be seen in the following trace excerpt:
rxrpc_tx_data: c=00000044 DATA d0b5ece8:00000001 00000001 q=00000001 fl=07
rxrpc_rx_ack: c=00000044 00000001 PNG r=00000000 f=00000002 p=00000000 n=0
rxrpc_rx_ack: c=00000044 00000002 REQ r=00000001 f=00000002 p=00000001 n=0
...
DATA packet 1 (q=xx) has REQUEST_ACK set (bit 1 of fl=xx). The incoming
ping (labelled PNG) hard-acks the request DATA packet (f=xx exceeds the
sequence number of the DATA packet), causing it to be discarded from the Tx
ring. The ACK that was requested (labelled REQ, r=xx references the serial
of the DATA packet) comes after the ping, but the sk_buff holding the
timestamp has gone and the RTT sample is lost.
This is particularly noticeable on RPC calls used to probe the service
offered by the peer. A lot of peers end up with an unknown RTT because we
only ever sent a single RPC. This confuses the server rotation algorithm.
Fix this by caching the information about the outgoing packet in RTT
calculations in the rxrpc_call struct rather than looking in the Tx ring.
A four-deep buffer is maintained and both REQUEST_ACK-flagged DATA and
PING-ACK transmissions are recorded in there. When the appropriate
response ACK is received, the buffer is checked for a match and, if found,
an RTT sample is recorded.
If a received ACK refers to a packet with a later serial number than an
entry in the cache, that entry is presumed lost and the entry is made
available to record a new transmission.
ACKs types other than REQUESTED-type and PING-type cause any matching
sample to be cancelled as they don't necessarily represent a useful
measurement.
If there's no space in the buffer on ping/data transmission, the sample
base is discarded.
Fixes: 50235c4b5a2f ("rxrpc: Obtain RTT data by requesting ACKs on DATA packets")
Signed-off-by: David Howells <dhowells@redhat.com>
2020-08-20 06:29:16 +08:00
|
|
|
}
|
|
|
|
|
2018-11-01 21:39:53 +08:00
|
|
|
rxrpc_tx_backoff(call, ret);
|
2016-09-22 07:29:31 +08:00
|
|
|
if (ret == -EMSGSIZE)
|
|
|
|
goto send_fragmentable;
|
|
|
|
|
|
|
|
done:
|
2016-09-22 07:29:31 +08:00
|
|
|
if (ret >= 0) {
|
2016-09-22 07:29:31 +08:00
|
|
|
if (whdr.flags & RXRPC_REQUEST_ACK) {
|
2018-09-27 22:13:08 +08:00
|
|
|
call->peer->rtt_last_req = skb->tstamp;
|
2020-05-11 21:54:34 +08:00
|
|
|
if (call->peer->rtt_count > 1) {
|
2017-11-24 18:18:42 +08:00
|
|
|
unsigned long nowj = jiffies, ack_lost_at;
|
|
|
|
|
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
|
|
|
ack_lost_at = rxrpc_get_rto_backoff(call->peer, false);
|
2017-11-24 18:18:42 +08:00
|
|
|
ack_lost_at += nowj;
|
|
|
|
WRITE_ONCE(call->ack_lost_at, ack_lost_at);
|
|
|
|
rxrpc_reduce_call_timer(call, ack_lost_at, nowj,
|
|
|
|
rxrpc_timer_set_for_lost_ack);
|
|
|
|
}
|
2016-09-22 07:29:31 +08:00
|
|
|
}
|
2018-05-11 06:26:00 +08:00
|
|
|
|
|
|
|
if (sp->hdr.seq == 1 &&
|
|
|
|
!test_and_set_bit(RXRPC_CALL_BEGAN_RX_TIMER,
|
|
|
|
&call->flags)) {
|
|
|
|
unsigned long nowj = jiffies, expect_rx_by;
|
|
|
|
|
|
|
|
expect_rx_by = nowj + call->next_rx_timo;
|
|
|
|
WRITE_ONCE(call->expect_rx_by, expect_rx_by);
|
|
|
|
rxrpc_reduce_call_timer(call, expect_rx_by, nowj,
|
|
|
|
rxrpc_timer_set_for_normal);
|
|
|
|
}
|
2017-11-24 18:18:42 +08:00
|
|
|
|
2018-11-01 21:39:53 +08:00
|
|
|
rxrpc_set_keepalive(call);
|
|
|
|
} else {
|
|
|
|
/* Cancel the call if the initial transmission fails,
|
|
|
|
* particularly if that's due to network routing issues that
|
|
|
|
* aren't going away anytime soon. The layer above can arrange
|
|
|
|
* the retransmission.
|
|
|
|
*/
|
|
|
|
if (!test_and_set_bit(RXRPC_CALL_BEGAN_RX_TIMER, &call->flags))
|
|
|
|
rxrpc_set_call_completion(call, RXRPC_CALL_LOCAL_ERROR,
|
|
|
|
RX_USER_ABORT, ret);
|
|
|
|
}
|
2017-11-24 18:18:42 +08:00
|
|
|
|
2016-09-22 07:29:31 +08:00
|
|
|
_leave(" = %d [%u]", ret, call->peer->maxdata);
|
|
|
|
return ret;
|
2007-04-27 06:48:28 +08:00
|
|
|
|
|
|
|
send_fragmentable:
|
|
|
|
/* attempt to send this message with fragmentation enabled */
|
|
|
|
_debug("send fragment");
|
|
|
|
|
2016-06-17 18:53:37 +08:00
|
|
|
down_write(&conn->params.local->defrag_sem);
|
|
|
|
|
2018-09-27 22:13:08 +08:00
|
|
|
sp->hdr.serial = serial;
|
|
|
|
smp_wmb(); /* Set serial before timestamp */
|
|
|
|
skb->tstamp = ktime_get_real();
|
rxrpc: Fix loss of RTT samples due to interposed ACK
The Rx protocol has a mechanism to help generate RTT samples that works by
a client transmitting a REQUESTED-type ACK when it receives a DATA packet
that has the REQUEST_ACK flag set.
The peer, however, may interpose other ACKs before transmitting the
REQUESTED-ACK, as can be seen in the following trace excerpt:
rxrpc_tx_data: c=00000044 DATA d0b5ece8:00000001 00000001 q=00000001 fl=07
rxrpc_rx_ack: c=00000044 00000001 PNG r=00000000 f=00000002 p=00000000 n=0
rxrpc_rx_ack: c=00000044 00000002 REQ r=00000001 f=00000002 p=00000001 n=0
...
DATA packet 1 (q=xx) has REQUEST_ACK set (bit 1 of fl=xx). The incoming
ping (labelled PNG) hard-acks the request DATA packet (f=xx exceeds the
sequence number of the DATA packet), causing it to be discarded from the Tx
ring. The ACK that was requested (labelled REQ, r=xx references the serial
of the DATA packet) comes after the ping, but the sk_buff holding the
timestamp has gone and the RTT sample is lost.
This is particularly noticeable on RPC calls used to probe the service
offered by the peer. A lot of peers end up with an unknown RTT because we
only ever sent a single RPC. This confuses the server rotation algorithm.
Fix this by caching the information about the outgoing packet in RTT
calculations in the rxrpc_call struct rather than looking in the Tx ring.
A four-deep buffer is maintained and both REQUEST_ACK-flagged DATA and
PING-ACK transmissions are recorded in there. When the appropriate
response ACK is received, the buffer is checked for a match and, if found,
an RTT sample is recorded.
If a received ACK refers to a packet with a later serial number than an
entry in the cache, that entry is presumed lost and the entry is made
available to record a new transmission.
ACKs types other than REQUESTED-type and PING-type cause any matching
sample to be cancelled as they don't necessarily represent a useful
measurement.
If there's no space in the buffer on ping/data transmission, the sample
base is discarded.
Fixes: 50235c4b5a2f ("rxrpc: Obtain RTT data by requesting ACKs on DATA packets")
Signed-off-by: David Howells <dhowells@redhat.com>
2020-08-20 06:29:16 +08:00
|
|
|
if (whdr.flags & RXRPC_REQUEST_ACK)
|
|
|
|
rtt_slot = rxrpc_begin_rtt_probe(call, serial, rxrpc_rtt_tx_data);
|
2018-09-27 22:13:08 +08:00
|
|
|
|
2016-06-17 18:53:37 +08:00
|
|
|
switch (conn->params.local->srx.transport.family) {
|
2020-04-13 20:57:14 +08:00
|
|
|
case AF_INET6:
|
2016-06-17 18:53:37 +08:00
|
|
|
case AF_INET:
|
2020-05-28 13:12:29 +08:00
|
|
|
ip_sock_set_mtu_discover(conn->params.local->socket->sk,
|
|
|
|
IP_PMTUDISC_DONT);
|
2022-05-11 21:01:25 +08:00
|
|
|
rxrpc_inc_stat(call->rxnet, stat_tx_data_send_frag);
|
2022-03-22 19:07:20 +08:00
|
|
|
ret = do_udp_sendmsg(conn->params.local->socket, &msg, len);
|
2020-04-13 20:57:14 +08:00
|
|
|
conn->params.peer->last_tx_at = ktime_get_seconds();
|
|
|
|
|
2020-05-28 13:12:29 +08:00
|
|
|
ip_sock_set_mtu_discover(conn->params.local->socket->sk,
|
|
|
|
IP_PMTUDISC_DO);
|
2016-09-13 15:49:05 +08:00
|
|
|
break;
|
2019-07-02 22:55:28 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
BUG();
|
2007-04-27 06:48:28 +08:00
|
|
|
}
|
|
|
|
|
rxrpc: Fix loss of RTT samples due to interposed ACK
The Rx protocol has a mechanism to help generate RTT samples that works by
a client transmitting a REQUESTED-type ACK when it receives a DATA packet
that has the REQUEST_ACK flag set.
The peer, however, may interpose other ACKs before transmitting the
REQUESTED-ACK, as can be seen in the following trace excerpt:
rxrpc_tx_data: c=00000044 DATA d0b5ece8:00000001 00000001 q=00000001 fl=07
rxrpc_rx_ack: c=00000044 00000001 PNG r=00000000 f=00000002 p=00000000 n=0
rxrpc_rx_ack: c=00000044 00000002 REQ r=00000001 f=00000002 p=00000001 n=0
...
DATA packet 1 (q=xx) has REQUEST_ACK set (bit 1 of fl=xx). The incoming
ping (labelled PNG) hard-acks the request DATA packet (f=xx exceeds the
sequence number of the DATA packet), causing it to be discarded from the Tx
ring. The ACK that was requested (labelled REQ, r=xx references the serial
of the DATA packet) comes after the ping, but the sk_buff holding the
timestamp has gone and the RTT sample is lost.
This is particularly noticeable on RPC calls used to probe the service
offered by the peer. A lot of peers end up with an unknown RTT because we
only ever sent a single RPC. This confuses the server rotation algorithm.
Fix this by caching the information about the outgoing packet in RTT
calculations in the rxrpc_call struct rather than looking in the Tx ring.
A four-deep buffer is maintained and both REQUEST_ACK-flagged DATA and
PING-ACK transmissions are recorded in there. When the appropriate
response ACK is received, the buffer is checked for a match and, if found,
an RTT sample is recorded.
If a received ACK refers to a packet with a later serial number than an
entry in the cache, that entry is presumed lost and the entry is made
available to record a new transmission.
ACKs types other than REQUESTED-type and PING-type cause any matching
sample to be cancelled as they don't necessarily represent a useful
measurement.
If there's no space in the buffer on ping/data transmission, the sample
base is discarded.
Fixes: 50235c4b5a2f ("rxrpc: Obtain RTT data by requesting ACKs on DATA packets")
Signed-off-by: David Howells <dhowells@redhat.com>
2020-08-20 06:29:16 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
rxrpc_cancel_rtt_probe(call, serial, rtt_slot);
|
2018-05-11 06:26:01 +08:00
|
|
|
trace_rxrpc_tx_fail(call->debug_id, serial, ret,
|
2018-07-24 00:18:37 +08:00
|
|
|
rxrpc_tx_point_call_data_frag);
|
rxrpc: Fix loss of RTT samples due to interposed ACK
The Rx protocol has a mechanism to help generate RTT samples that works by
a client transmitting a REQUESTED-type ACK when it receives a DATA packet
that has the REQUEST_ACK flag set.
The peer, however, may interpose other ACKs before transmitting the
REQUESTED-ACK, as can be seen in the following trace excerpt:
rxrpc_tx_data: c=00000044 DATA d0b5ece8:00000001 00000001 q=00000001 fl=07
rxrpc_rx_ack: c=00000044 00000001 PNG r=00000000 f=00000002 p=00000000 n=0
rxrpc_rx_ack: c=00000044 00000002 REQ r=00000001 f=00000002 p=00000001 n=0
...
DATA packet 1 (q=xx) has REQUEST_ACK set (bit 1 of fl=xx). The incoming
ping (labelled PNG) hard-acks the request DATA packet (f=xx exceeds the
sequence number of the DATA packet), causing it to be discarded from the Tx
ring. The ACK that was requested (labelled REQ, r=xx references the serial
of the DATA packet) comes after the ping, but the sk_buff holding the
timestamp has gone and the RTT sample is lost.
This is particularly noticeable on RPC calls used to probe the service
offered by the peer. A lot of peers end up with an unknown RTT because we
only ever sent a single RPC. This confuses the server rotation algorithm.
Fix this by caching the information about the outgoing packet in RTT
calculations in the rxrpc_call struct rather than looking in the Tx ring.
A four-deep buffer is maintained and both REQUEST_ACK-flagged DATA and
PING-ACK transmissions are recorded in there. When the appropriate
response ACK is received, the buffer is checked for a match and, if found,
an RTT sample is recorded.
If a received ACK refers to a packet with a later serial number than an
entry in the cache, that entry is presumed lost and the entry is made
available to record a new transmission.
ACKs types other than REQUESTED-type and PING-type cause any matching
sample to be cancelled as they don't necessarily represent a useful
measurement.
If there's no space in the buffer on ping/data transmission, the sample
base is discarded.
Fixes: 50235c4b5a2f ("rxrpc: Obtain RTT data by requesting ACKs on DATA packets")
Signed-off-by: David Howells <dhowells@redhat.com>
2020-08-20 06:29:16 +08:00
|
|
|
} else {
|
2018-07-24 00:18:37 +08:00
|
|
|
trace_rxrpc_tx_packet(call->debug_id, &whdr,
|
|
|
|
rxrpc_tx_point_call_data_frag);
|
rxrpc: Fix loss of RTT samples due to interposed ACK
The Rx protocol has a mechanism to help generate RTT samples that works by
a client transmitting a REQUESTED-type ACK when it receives a DATA packet
that has the REQUEST_ACK flag set.
The peer, however, may interpose other ACKs before transmitting the
REQUESTED-ACK, as can be seen in the following trace excerpt:
rxrpc_tx_data: c=00000044 DATA d0b5ece8:00000001 00000001 q=00000001 fl=07
rxrpc_rx_ack: c=00000044 00000001 PNG r=00000000 f=00000002 p=00000000 n=0
rxrpc_rx_ack: c=00000044 00000002 REQ r=00000001 f=00000002 p=00000001 n=0
...
DATA packet 1 (q=xx) has REQUEST_ACK set (bit 1 of fl=xx). The incoming
ping (labelled PNG) hard-acks the request DATA packet (f=xx exceeds the
sequence number of the DATA packet), causing it to be discarded from the Tx
ring. The ACK that was requested (labelled REQ, r=xx references the serial
of the DATA packet) comes after the ping, but the sk_buff holding the
timestamp has gone and the RTT sample is lost.
This is particularly noticeable on RPC calls used to probe the service
offered by the peer. A lot of peers end up with an unknown RTT because we
only ever sent a single RPC. This confuses the server rotation algorithm.
Fix this by caching the information about the outgoing packet in RTT
calculations in the rxrpc_call struct rather than looking in the Tx ring.
A four-deep buffer is maintained and both REQUEST_ACK-flagged DATA and
PING-ACK transmissions are recorded in there. When the appropriate
response ACK is received, the buffer is checked for a match and, if found,
an RTT sample is recorded.
If a received ACK refers to a packet with a later serial number than an
entry in the cache, that entry is presumed lost and the entry is made
available to record a new transmission.
ACKs types other than REQUESTED-type and PING-type cause any matching
sample to be cancelled as they don't necessarily represent a useful
measurement.
If there's no space in the buffer on ping/data transmission, the sample
base is discarded.
Fixes: 50235c4b5a2f ("rxrpc: Obtain RTT data by requesting ACKs on DATA packets")
Signed-off-by: David Howells <dhowells@redhat.com>
2020-08-20 06:29:16 +08:00
|
|
|
}
|
2018-11-01 21:39:53 +08:00
|
|
|
rxrpc_tx_backoff(call, ret);
|
2018-05-11 06:26:01 +08:00
|
|
|
|
2016-06-17 18:53:37 +08:00
|
|
|
up_write(&conn->params.local->defrag_sem);
|
2016-09-22 07:29:31 +08:00
|
|
|
goto done;
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* reject packets through the local endpoint
|
|
|
|
*/
|
|
|
|
void rxrpc_reject_packets(struct rxrpc_local *local)
|
|
|
|
{
|
2016-09-13 15:49:05 +08:00
|
|
|
struct sockaddr_rxrpc srx;
|
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
|
|
|
struct rxrpc_skb_priv *sp;
|
|
|
|
struct rxrpc_wire_header whdr;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
struct msghdr msg;
|
|
|
|
struct kvec iov[2];
|
|
|
|
size_t size;
|
|
|
|
__be32 code;
|
rxrpc: Emit BUSY packets when supposed to rather than ABORTs
In the input path, a received sk_buff can be marked for rejection by
setting RXRPC_SKB_MARK_* in skb->mark and, if needed, some auxiliary data
(such as an abort code) in skb->priority. The rejection is handled by
queueing the sk_buff up for dealing with in process context. The output
code reads the mark and priority and, theoretically, generates an
appropriate response packet.
However, if RXRPC_SKB_MARK_BUSY is set, this isn't noticed and an ABORT
message with a random abort code is generated (since skb->priority wasn't
set to anything).
Fix this by outputting the appropriate sort of packet.
Also, whilst we're at it, most of the marks are no longer used, so remove
them and rename the remaining two to something more obvious.
Fixes: 248f219cb8bc ("rxrpc: Rewrite the data and ack handling code")
Signed-off-by: David Howells <dhowells@redhat.com>
2018-09-27 22:13:08 +08:00
|
|
|
int ret, ioc;
|
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", local->debug_id);
|
|
|
|
|
|
|
|
iov[0].iov_base = &whdr;
|
|
|
|
iov[0].iov_len = sizeof(whdr);
|
|
|
|
iov[1].iov_base = &code;
|
|
|
|
iov[1].iov_len = sizeof(code);
|
|
|
|
|
2016-09-13 15:49:05 +08:00
|
|
|
msg.msg_name = &srx.transport;
|
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
|
|
|
msg.msg_control = NULL;
|
|
|
|
msg.msg_controllen = 0;
|
|
|
|
msg.msg_flags = 0;
|
|
|
|
|
|
|
|
memset(&whdr, 0, sizeof(whdr));
|
|
|
|
|
|
|
|
while ((skb = skb_dequeue(&local->reject_queue))) {
|
2019-08-19 16:25:38 +08:00
|
|
|
rxrpc_see_skb(skb, rxrpc_skb_seen);
|
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
|
|
|
sp = rxrpc_skb(skb);
|
2016-09-13 15:49:05 +08:00
|
|
|
|
rxrpc: Emit BUSY packets when supposed to rather than ABORTs
In the input path, a received sk_buff can be marked for rejection by
setting RXRPC_SKB_MARK_* in skb->mark and, if needed, some auxiliary data
(such as an abort code) in skb->priority. The rejection is handled by
queueing the sk_buff up for dealing with in process context. The output
code reads the mark and priority and, theoretically, generates an
appropriate response packet.
However, if RXRPC_SKB_MARK_BUSY is set, this isn't noticed and an ABORT
message with a random abort code is generated (since skb->priority wasn't
set to anything).
Fix this by outputting the appropriate sort of packet.
Also, whilst we're at it, most of the marks are no longer used, so remove
them and rename the remaining two to something more obvious.
Fixes: 248f219cb8bc ("rxrpc: Rewrite the data and ack handling code")
Signed-off-by: David Howells <dhowells@redhat.com>
2018-09-27 22:13:08 +08:00
|
|
|
switch (skb->mark) {
|
|
|
|
case RXRPC_SKB_MARK_REJECT_BUSY:
|
|
|
|
whdr.type = RXRPC_PACKET_TYPE_BUSY;
|
|
|
|
size = sizeof(whdr);
|
|
|
|
ioc = 1;
|
|
|
|
break;
|
|
|
|
case RXRPC_SKB_MARK_REJECT_ABORT:
|
|
|
|
whdr.type = RXRPC_PACKET_TYPE_ABORT;
|
|
|
|
code = htonl(skb->priority);
|
|
|
|
size = sizeof(whdr) + sizeof(code);
|
|
|
|
ioc = 2;
|
|
|
|
break;
|
|
|
|
default:
|
2019-08-19 16:25:38 +08:00
|
|
|
rxrpc_free_skb(skb, rxrpc_skb_freed);
|
rxrpc: Emit BUSY packets when supposed to rather than ABORTs
In the input path, a received sk_buff can be marked for rejection by
setting RXRPC_SKB_MARK_* in skb->mark and, if needed, some auxiliary data
(such as an abort code) in skb->priority. The rejection is handled by
queueing the sk_buff up for dealing with in process context. The output
code reads the mark and priority and, theoretically, generates an
appropriate response packet.
However, if RXRPC_SKB_MARK_BUSY is set, this isn't noticed and an ABORT
message with a random abort code is generated (since skb->priority wasn't
set to anything).
Fix this by outputting the appropriate sort of packet.
Also, whilst we're at it, most of the marks are no longer used, so remove
them and rename the remaining two to something more obvious.
Fixes: 248f219cb8bc ("rxrpc: Rewrite the data and ack handling code")
Signed-off-by: David Howells <dhowells@redhat.com>
2018-09-27 22:13:08 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-10-04 16:32:28 +08:00
|
|
|
if (rxrpc_extract_addr_from_skb(&srx, skb) == 0) {
|
2016-09-13 15:49:05 +08:00
|
|
|
msg.msg_namelen = srx.transport_len;
|
|
|
|
|
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
|
|
|
whdr.epoch = htonl(sp->hdr.epoch);
|
|
|
|
whdr.cid = htonl(sp->hdr.cid);
|
|
|
|
whdr.callNumber = htonl(sp->hdr.callNumber);
|
|
|
|
whdr.serviceId = htons(sp->hdr.serviceId);
|
|
|
|
whdr.flags = sp->hdr.flags;
|
|
|
|
whdr.flags ^= RXRPC_CLIENT_INITIATED;
|
|
|
|
whdr.flags &= RXRPC_CLIENT_INITIATED;
|
|
|
|
|
2022-03-22 19:07:20 +08:00
|
|
|
iov_iter_kvec(&msg.msg_iter, WRITE, iov, ioc, size);
|
|
|
|
ret = do_udp_sendmsg(local->socket, &msg, size);
|
2018-05-11 06:26:01 +08:00
|
|
|
if (ret < 0)
|
|
|
|
trace_rxrpc_tx_fail(local->debug_id, 0, ret,
|
2018-07-24 00:18:37 +08:00
|
|
|
rxrpc_tx_point_reject);
|
|
|
|
else
|
|
|
|
trace_rxrpc_tx_packet(local->debug_id, &whdr,
|
|
|
|
rxrpc_tx_point_reject);
|
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
|
|
|
}
|
|
|
|
|
2019-08-19 16:25:38 +08:00
|
|
|
rxrpc_free_skb(skb, rxrpc_skb_freed);
|
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("");
|
|
|
|
}
|
2018-03-31 04:04:43 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a VERSION reply to a peer as a keepalive.
|
|
|
|
*/
|
|
|
|
void rxrpc_send_keepalive(struct rxrpc_peer *peer)
|
|
|
|
{
|
|
|
|
struct rxrpc_wire_header whdr;
|
|
|
|
struct msghdr msg;
|
|
|
|
struct kvec iov[2];
|
|
|
|
size_t len;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
_enter("");
|
|
|
|
|
|
|
|
msg.msg_name = &peer->srx.transport;
|
|
|
|
msg.msg_namelen = peer->srx.transport_len;
|
|
|
|
msg.msg_control = NULL;
|
|
|
|
msg.msg_controllen = 0;
|
|
|
|
msg.msg_flags = 0;
|
|
|
|
|
|
|
|
whdr.epoch = htonl(peer->local->rxnet->epoch);
|
|
|
|
whdr.cid = 0;
|
|
|
|
whdr.callNumber = 0;
|
|
|
|
whdr.seq = 0;
|
|
|
|
whdr.serial = 0;
|
|
|
|
whdr.type = RXRPC_PACKET_TYPE_VERSION; /* Not client-initiated */
|
|
|
|
whdr.flags = RXRPC_LAST_PACKET;
|
|
|
|
whdr.userStatus = 0;
|
|
|
|
whdr.securityIndex = 0;
|
|
|
|
whdr._rsvd = 0;
|
|
|
|
whdr.serviceId = 0;
|
|
|
|
|
|
|
|
iov[0].iov_base = &whdr;
|
|
|
|
iov[0].iov_len = sizeof(whdr);
|
|
|
|
iov[1].iov_base = (char *)rxrpc_keepalive_string;
|
|
|
|
iov[1].iov_len = sizeof(rxrpc_keepalive_string);
|
|
|
|
|
|
|
|
len = iov[0].iov_len + iov[1].iov_len;
|
|
|
|
|
|
|
|
_proto("Tx VERSION (keepalive)");
|
|
|
|
|
2022-03-22 19:07:20 +08:00
|
|
|
iov_iter_kvec(&msg.msg_iter, WRITE, iov, 2, len);
|
|
|
|
ret = do_udp_sendmsg(peer->local->socket, &msg, len);
|
2018-03-31 04:04:43 +08:00
|
|
|
if (ret < 0)
|
2018-05-11 06:26:01 +08:00
|
|
|
trace_rxrpc_tx_fail(peer->debug_id, 0, ret,
|
2018-07-24 00:18:37 +08:00
|
|
|
rxrpc_tx_point_version_keepalive);
|
|
|
|
else
|
|
|
|
trace_rxrpc_tx_packet(peer->debug_id, &whdr,
|
|
|
|
rxrpc_tx_point_version_keepalive);
|
2018-03-31 04:04:43 +08:00
|
|
|
|
2018-08-08 18:30:02 +08:00
|
|
|
peer->last_tx_at = ktime_get_seconds();
|
2018-03-31 04:04:43 +08:00
|
|
|
_leave("");
|
|
|
|
}
|