2019-05-27 06:55:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2007-04-26 22:48:28 +00:00
|
|
|
/* RxRPC packet transmission
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
|
|
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
|
|
*/
|
|
|
|
|
2016-06-02 19:08:52 +00:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2007-04-26 22:48:28 +00: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 08:04:11 +00:00
|
|
|
#include <linux/gfp.h>
|
2007-04-26 22:48:28 +00:00
|
|
|
#include <linux/skbuff.h>
|
2011-07-15 15:47:34 +00:00
|
|
|
#include <linux/export.h>
|
2007-04-26 22:48:28 +00:00
|
|
|
#include <net/sock.h>
|
|
|
|
#include <net/af_rxrpc.h>
|
2022-03-22 11:07:20 +00:00
|
|
|
#include <net/udp.h>
|
2007-04-26 22:48:28 +00:00
|
|
|
#include "ar-internal.h"
|
|
|
|
|
2022-03-22 11:07:20 +00:00
|
|
|
extern int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len);
|
|
|
|
|
2022-11-11 16:00:21 +00:00
|
|
|
static ssize_t do_udp_sendmsg(struct socket *socket, struct msghdr *msg, size_t len)
|
2022-03-22 11:07:20 +00:00
|
|
|
{
|
|
|
|
struct sockaddr *sa = msg->msg_name;
|
2022-11-11 16:00:21 +00:00
|
|
|
struct sock *sk = socket->sk;
|
2022-03-22 11:07:20 +00:00
|
|
|
|
2022-11-11 16:00:21 +00:00
|
|
|
if (IS_ENABLED(CONFIG_AF_RXRPC_IPV6)) {
|
|
|
|
if (sa->sa_family == AF_INET6) {
|
|
|
|
if (sk->sk_family != AF_INET6) {
|
|
|
|
pr_warn("AF_INET6 address on AF_INET socket\n");
|
|
|
|
return -ENOPROTOOPT;
|
|
|
|
}
|
|
|
|
return udpv6_sendmsg(sk, msg, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return udp_sendmsg(sk, msg, len);
|
2022-03-22 11:07:20 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 07:11:49 +00:00
|
|
|
struct rxrpc_abort_buffer {
|
|
|
|
struct rxrpc_wire_header whdr;
|
|
|
|
__be32 abort_code;
|
|
|
|
};
|
|
|
|
|
2018-03-30 20:04:43 +00:00
|
|
|
static const char rxrpc_keepalive_string[] = "";
|
|
|
|
|
2018-11-01 13:39:53 +00: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 10:18:42 +00: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)
|
|
|
|
{
|
2024-01-30 16:39:15 +00:00
|
|
|
unsigned long now = jiffies;
|
2017-11-24 10:18:42 +00:00
|
|
|
|
2024-01-30 16:39:15 +00:00
|
|
|
call->keepalive_at = now + call->next_rx_timo / 6;
|
|
|
|
rxrpc_reduce_call_timer(call, call->keepalive_at, now,
|
2017-11-24 10:18:42 +00:00
|
|
|
rxrpc_timer_set_for_keepalive);
|
|
|
|
}
|
|
|
|
|
2016-09-07 08:19:31 +00:00
|
|
|
/*
|
|
|
|
* Fill out an ACK packet.
|
|
|
|
*/
|
2017-11-02 15:06:55 +00:00
|
|
|
static size_t rxrpc_fill_out_ack(struct rxrpc_connection *conn,
|
|
|
|
struct rxrpc_call *call,
|
2023-01-31 15:31:49 +00:00
|
|
|
struct rxrpc_txbuf *txb,
|
|
|
|
u16 *_rwind)
|
2016-09-07 08:19:31 +00:00
|
|
|
{
|
2024-01-26 16:17:03 +00:00
|
|
|
struct rxrpc_acktrailer trailer;
|
2022-10-16 07:01:32 +00:00
|
|
|
unsigned int qsize, sack, wrap, to;
|
|
|
|
rxrpc_seq_t window, wtop;
|
2022-08-27 13:27:56 +00:00
|
|
|
int rsize;
|
2016-09-07 08:19:31 +00:00
|
|
|
u32 mtu, jmax;
|
2020-01-30 21:48:13 +00:00
|
|
|
u8 *ackp = txb->acks;
|
2016-09-07 08:19:31 +00:00
|
|
|
|
2022-10-17 10:44:22 +00:00
|
|
|
call->ackr_nr_unacked = 0;
|
2022-08-27 13:27:56 +00:00
|
|
|
atomic_set(&call->ackr_nr_consumed, 0);
|
2022-05-11 13:01:25 +00:00
|
|
|
rxrpc_inc_stat(call->rxnet, stat_tx_ack_fill);
|
2022-10-16 07:01:32 +00:00
|
|
|
clear_bit(RXRPC_CALL_RX_IS_IDLE, &call->flags);
|
2022-05-21 08:03:31 +00:00
|
|
|
|
2022-10-17 10:44:22 +00:00
|
|
|
window = call->ackr_window;
|
|
|
|
wtop = call->ackr_wtop;
|
2022-10-16 07:01:32 +00:00
|
|
|
sack = call->ackr_sack_base % RXRPC_SACK_SIZE;
|
2022-08-27 13:27:56 +00:00
|
|
|
txb->ack.firstPacket = htonl(window);
|
2022-10-16 07:01:32 +00:00
|
|
|
txb->ack.nAcks = wtop - window;
|
2022-08-27 13:27:56 +00:00
|
|
|
|
|
|
|
if (after(wtop, window)) {
|
2022-10-16 07:01:32 +00:00
|
|
|
wrap = RXRPC_SACK_SIZE - sack;
|
|
|
|
to = min_t(unsigned int, txb->ack.nAcks, RXRPC_SACK_SIZE);
|
2022-08-27 13:27:56 +00:00
|
|
|
|
2022-10-16 07:01:32 +00:00
|
|
|
if (sack + txb->ack.nAcks <= RXRPC_SACK_SIZE) {
|
|
|
|
memcpy(txb->acks, call->ackr_sack_table + sack, txb->ack.nAcks);
|
2022-08-27 13:27:56 +00:00
|
|
|
} else {
|
2022-10-16 07:01:32 +00:00
|
|
|
memcpy(txb->acks, call->ackr_sack_table + sack, wrap);
|
|
|
|
memcpy(txb->acks + wrap, call->ackr_sack_table,
|
|
|
|
to - wrap);
|
2022-08-27 13:27:56 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 07:01:32 +00:00
|
|
|
ackp += to;
|
2022-08-27 13:27:56 +00:00
|
|
|
} else if (before(wtop, window)) {
|
|
|
|
pr_warn("ack window backward %x %x", window, wtop);
|
2020-01-30 21:48:14 +00: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 10:10:12 +00:00
|
|
|
}
|
2016-09-07 08:19:31 +00:00
|
|
|
|
2022-10-19 12:49:02 +00:00
|
|
|
mtu = conn->peer->if_mtu;
|
|
|
|
mtu -= conn->peer->hdrsize;
|
2022-10-07 16:44:39 +00:00
|
|
|
jmax = rxrpc_rx_jumbo_max;
|
2022-08-27 13:27:56 +00:00
|
|
|
qsize = (window - 1) - call->rx_consumed;
|
|
|
|
rsize = max_t(int, call->rx_winsize - qsize, 0);
|
2023-01-31 15:31:49 +00:00
|
|
|
*_rwind = rsize;
|
2024-01-26 16:17:03 +00:00
|
|
|
trailer.maxMTU = htonl(rxrpc_rx_mtu);
|
|
|
|
trailer.ifMTU = htonl(mtu);
|
|
|
|
trailer.rwind = htonl(rsize);
|
|
|
|
trailer.jumbo_max = htonl(jmax);
|
2016-09-07 08:19:31 +00:00
|
|
|
|
|
|
|
*ackp++ = 0;
|
|
|
|
*ackp++ = 0;
|
|
|
|
*ackp++ = 0;
|
2024-01-26 16:17:03 +00:00
|
|
|
memcpy(ackp, &trailer, sizeof(trailer));
|
|
|
|
return txb->ack.nAcks + 3 + sizeof(trailer);
|
2016-09-07 08:19:31 +00: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-19 22:29:16 +00: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 08:19:31 +00:00
|
|
|
/*
|
2020-01-30 21:48:13 +00:00
|
|
|
* Transmit an ACK packet.
|
2016-09-07 08:19:31 +00:00
|
|
|
*/
|
2020-01-30 21:48:13 +00:00
|
|
|
int rxrpc_send_ack_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb)
|
2016-09-07 08:19:31 +00:00
|
|
|
{
|
2020-01-30 21:50:36 +00:00
|
|
|
struct rxrpc_connection *conn;
|
2016-09-07 08:19:31 +00:00
|
|
|
struct msghdr msg;
|
2020-01-30 21:48:13 +00:00
|
|
|
struct kvec iov[1];
|
2016-09-07 08:19:31 +00: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-19 22:29:16 +00:00
|
|
|
int ret, rtt_slot = -1;
|
2023-01-31 15:31:49 +00:00
|
|
|
u16 rwind;
|
2016-09-07 08:19:31 +00:00
|
|
|
|
2020-01-30 21:50:36 +00:00
|
|
|
if (test_bit(RXRPC_CALL_DISCONNECTED, &call->flags))
|
2016-09-07 08:19:31 +00:00
|
|
|
return -ECONNRESET;
|
|
|
|
|
2020-01-30 21:50:36 +00:00
|
|
|
conn = call->conn;
|
2016-09-07 08:19:31 +00: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-30 21:48:13 +00:00
|
|
|
if (txb->ack.reason == RXRPC_ACK_PING)
|
2024-01-29 15:01:10 +00:00
|
|
|
txb->flags |= RXRPC_REQUEST_ACK;
|
|
|
|
txb->wire.flags = txb->flags & RXRPC_TXBUF_WIRE_FLAGS;
|
2016-09-07 08:19:31 +00:00
|
|
|
|
2023-01-31 15:31:49 +00:00
|
|
|
n = rxrpc_fill_out_ack(conn, call, txb, &rwind);
|
2022-05-06 15:13:13 +00:00
|
|
|
if (n == 0)
|
2022-05-21 08:03:31 +00:00
|
|
|
return 0;
|
2016-10-06 07:11:49 +00:00
|
|
|
|
2020-01-30 21:48:13 +00: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 08:19:31 +00:00
|
|
|
|
2024-01-29 13:51:30 +00:00
|
|
|
txb->serial = rxrpc_get_next_serial(conn);
|
|
|
|
txb->wire.serial = htonl(txb->serial);
|
|
|
|
trace_rxrpc_tx_ack(call->debug_id, txb->serial,
|
2020-01-30 21:48:13 +00:00
|
|
|
ntohl(txb->ack.firstPacket),
|
2023-01-31 15:31:49 +00:00
|
|
|
ntohl(txb->ack.serial), txb->ack.reason, txb->ack.nAcks,
|
|
|
|
rwind);
|
2016-09-23 14:08:48 +00:00
|
|
|
|
2020-01-30 21:48:13 +00:00
|
|
|
if (txb->ack.reason == RXRPC_ACK_PING)
|
2024-01-29 13:51:30 +00:00
|
|
|
rtt_slot = rxrpc_begin_rtt_probe(call, txb->serial, rxrpc_rtt_tx_ping);
|
2016-10-06 07:11:49 +00:00
|
|
|
|
2022-05-11 13:01:25 +00:00
|
|
|
rxrpc_inc_stat(call->rxnet, stat_tx_ack_send);
|
2022-03-22 11:07:20 +00:00
|
|
|
|
2022-08-27 13:27:56 +00:00
|
|
|
/* Grab the highest received seq as late as possible */
|
|
|
|
txb->ack.previousPacket = htonl(call->rx_highest_seq);
|
|
|
|
|
2020-01-30 21:48:13 +00:00
|
|
|
iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, len);
|
2024-01-29 22:38:31 +00:00
|
|
|
rxrpc_local_dont_fragment(conn->local, false);
|
2022-10-19 12:49:02 +00:00
|
|
|
ret = do_udp_sendmsg(conn->local->socket, &msg, len);
|
2022-03-22 11:07:20 +00:00
|
|
|
call->peer->last_tx_at = ktime_get_seconds();
|
2022-10-17 09:55:41 +00:00
|
|
|
if (ret < 0) {
|
2024-01-29 13:51:30 +00:00
|
|
|
trace_rxrpc_tx_fail(call->debug_id, txb->serial, ret,
|
2018-07-23 16:18:37 +00:00
|
|
|
rxrpc_tx_point_call_ack);
|
2022-10-17 09:55:41 +00:00
|
|
|
} else {
|
2020-01-30 21:48:13 +00:00
|
|
|
trace_rxrpc_tx_packet(call->debug_id, &txb->wire,
|
2018-07-23 16:18:37 +00:00
|
|
|
rxrpc_tx_point_call_ack);
|
2024-01-29 15:01:10 +00:00
|
|
|
if (txb->flags & RXRPC_REQUEST_ACK)
|
2022-10-17 09:55:41 +00:00
|
|
|
call->peer->rtt_last_req = ktime_get_real();
|
|
|
|
}
|
2018-11-01 13:39:53 +00:00
|
|
|
rxrpc_tx_backoff(call, ret);
|
2016-09-07 08:19:31 +00:00
|
|
|
|
2022-10-27 10:25:55 +00:00
|
|
|
if (!__rxrpc_call_is_complete(call)) {
|
2020-01-30 21:48:13 +00:00
|
|
|
if (ret < 0)
|
2024-01-29 13:51:30 +00:00
|
|
|
rxrpc_cancel_rtt_probe(call, txb->serial, rtt_slot);
|
2017-11-24 10:18:42 +00: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 10:10:12 +00:00
|
|
|
}
|
|
|
|
|
2016-09-07 08:19:31 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-10-06 07:11:49 +00:00
|
|
|
/*
|
|
|
|
* Send an ABORT call packet.
|
|
|
|
*/
|
|
|
|
int rxrpc_send_abort_packet(struct rxrpc_call *call)
|
|
|
|
{
|
2020-01-30 21:50:36 +00:00
|
|
|
struct rxrpc_connection *conn;
|
2016-10-06 07:11:49 +00:00
|
|
|
struct rxrpc_abort_buffer pkt;
|
|
|
|
struct msghdr msg;
|
|
|
|
struct kvec iov[1];
|
|
|
|
rxrpc_serial_t serial;
|
|
|
|
int ret;
|
|
|
|
|
2017-11-02 15:06:26 +00: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) &&
|
2022-03-31 22:55:08 +00:00
|
|
|
test_bit(RXRPC_CALL_TX_ALL_ACKED, &call->flags))
|
2017-11-02 15:06:26 +00:00
|
|
|
return 0;
|
|
|
|
|
2020-01-30 21:50:36 +00:00
|
|
|
if (test_bit(RXRPC_CALL_DISCONNECTED, &call->flags))
|
2016-10-06 07:11:49 +00:00
|
|
|
return -ECONNRESET;
|
|
|
|
|
2020-01-30 21:50:36 +00:00
|
|
|
conn = call->conn;
|
|
|
|
|
2016-10-06 07:11:49 +00: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;
|
2022-10-20 20:58:36 +00:00
|
|
|
pkt.whdr.serviceId = htons(call->dest_srx.srx_service);
|
2016-10-06 07:11:49 +00:00
|
|
|
pkt.abort_code = htonl(call->abort_code);
|
|
|
|
|
|
|
|
iov[0].iov_base = &pkt;
|
|
|
|
iov[0].iov_len = sizeof(pkt);
|
|
|
|
|
2024-02-02 15:19:13 +00:00
|
|
|
serial = rxrpc_get_next_serial(conn);
|
2016-10-06 07:11:49 +00:00
|
|
|
pkt.whdr.serial = htonl(serial);
|
|
|
|
|
2022-03-22 11:07:20 +00:00
|
|
|
iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, sizeof(pkt));
|
2022-10-19 12:49:02 +00:00
|
|
|
ret = do_udp_sendmsg(conn->local->socket, &msg, sizeof(pkt));
|
|
|
|
conn->peer->last_tx_at = ktime_get_seconds();
|
2018-05-10 22:26:01 +00:00
|
|
|
if (ret < 0)
|
|
|
|
trace_rxrpc_tx_fail(call->debug_id, serial, ret,
|
2018-07-23 16:18:37 +00:00
|
|
|
rxrpc_tx_point_call_abort);
|
|
|
|
else
|
|
|
|
trace_rxrpc_tx_packet(call->debug_id, &pkt.whdr,
|
|
|
|
rxrpc_tx_point_call_abort);
|
2018-11-01 13:39:53 +00:00
|
|
|
rxrpc_tx_backoff(call, ret);
|
2016-10-06 07:11:49 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-04-26 22:48:28 +00:00
|
|
|
/*
|
|
|
|
* send a packet through the transport endpoint
|
|
|
|
*/
|
2022-03-31 22:55:08 +00:00
|
|
|
int rxrpc_send_data_packet(struct rxrpc_call *call, struct rxrpc_txbuf *txb)
|
2007-04-26 22:48:28 +00:00
|
|
|
{
|
2022-04-05 20:48:48 +00:00
|
|
|
enum rxrpc_req_ack_trace why;
|
2016-09-21 23:29:31 +00:00
|
|
|
struct rxrpc_connection *conn = call->conn;
|
2007-04-26 22:48:28 +00:00
|
|
|
struct msghdr msg;
|
2022-03-31 22:55:08 +00:00
|
|
|
struct kvec iov[1];
|
2016-09-21 23:29:31 +00:00
|
|
|
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-19 22:29:16 +00:00
|
|
|
int ret, rtt_slot = -1;
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2022-03-31 22:55:08 +00:00
|
|
|
_enter("%x,{%d}", txb->seq, txb->len);
|
2007-04-26 22:48:28 +00:00
|
|
|
|
2024-01-29 13:51:30 +00:00
|
|
|
/* Each transmission of a Tx packet+ needs a new serial number */
|
|
|
|
txb->serial = rxrpc_get_next_serial(conn);
|
|
|
|
txb->wire.serial = htonl(txb->serial);
|
2024-01-29 14:37:52 +00:00
|
|
|
txb->wire.cksum = txb->cksum;
|
2016-09-21 23:29:31 +00:00
|
|
|
|
2017-06-05 13:30:49 +00:00
|
|
|
if (test_bit(RXRPC_CONN_PROBING_FOR_UPGRADE, &conn->flags) &&
|
2022-03-31 22:55:08 +00:00
|
|
|
txb->seq == 1)
|
|
|
|
txb->wire.userStatus = RXRPC_USERSTATUS_SERVICE_UPGRADE;
|
2017-06-05 13:30:49 +00:00
|
|
|
|
2022-03-31 22:55:08 +00:00
|
|
|
iov[0].iov_base = &txb->wire;
|
|
|
|
iov[0].iov_len = sizeof(txb->wire) + txb->len;
|
|
|
|
len = iov[0].iov_len;
|
|
|
|
iov_iter_kvec(&msg.msg_iter, WRITE, iov, 1, len);
|
2016-09-21 23:29:31 +00:00
|
|
|
|
|
|
|
msg.msg_name = &call->peer->srx.transport;
|
|
|
|
msg.msg_namelen = call->peer->srx.transport_len;
|
2007-04-26 22:48:28 +00:00
|
|
|
msg.msg_control = NULL;
|
|
|
|
msg.msg_controllen = 0;
|
|
|
|
msg.msg_flags = 0;
|
|
|
|
|
2016-09-24 17:05:27 +00: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 14:13:08 +00: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-24 17:05:27 +00:00
|
|
|
*/
|
2024-01-29 15:01:10 +00:00
|
|
|
if (txb->flags & RXRPC_REQUEST_ACK)
|
2022-04-05 20:48:48 +00:00
|
|
|
why = rxrpc_reqack_already_on;
|
2024-01-29 15:01:10 +00:00
|
|
|
else if ((txb->flags & RXRPC_LAST_PACKET) && rxrpc_sending_to_client(txb))
|
2022-04-05 20:48:48 +00:00
|
|
|
why = rxrpc_reqack_no_srv_last;
|
|
|
|
else if (test_and_clear_bit(RXRPC_CALL_EV_ACK_LOST, &call->events))
|
|
|
|
why = rxrpc_reqack_ack_lost;
|
2024-01-29 15:01:10 +00:00
|
|
|
else if (txb->flags & RXRPC_TXBUF_RESENT)
|
2022-04-05 20:48:48 +00:00
|
|
|
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;
|
2022-03-31 22:55:08 +00:00
|
|
|
else if (call->peer->rtt_count < 3 && txb->seq & 1)
|
2022-04-05 20:48:48 +00:00
|
|
|
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 10:52:36 +00:00
|
|
|
rxrpc_inc_stat(call->rxnet, stat_why_req_ack[why]);
|
2022-03-31 22:55:08 +00:00
|
|
|
trace_rxrpc_req_ack(call->debug_id, txb->seq, why);
|
2022-04-05 20:48:48 +00:00
|
|
|
if (why != rxrpc_reqack_no_srv_last)
|
2024-01-29 15:01:10 +00:00
|
|
|
txb->flags |= RXRPC_REQUEST_ACK;
|
2022-04-05 20:48:48 +00:00
|
|
|
dont_set_request_ack:
|
2016-09-21 23:29:31 +00:00
|
|
|
|
2016-09-17 09:49:15 +00:00
|
|
|
if (IS_ENABLED(CONFIG_AF_RXRPC_INJECT_LOSS)) {
|
|
|
|
static int lose;
|
|
|
|
if ((lose++ & 7) == 7) {
|
2016-09-29 21:37:15 +00:00
|
|
|
ret = 0;
|
2024-01-29 13:51:30 +00:00
|
|
|
trace_rxrpc_tx_data(call, txb->seq, txb->serial,
|
2024-01-29 15:01:10 +00:00
|
|
|
txb->flags, true);
|
2019-03-22 14:18:43 +00:00
|
|
|
goto done;
|
2016-09-17 09:49:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-29 15:01:10 +00:00
|
|
|
trace_rxrpc_tx_data(call, txb->seq, txb->serial, txb->flags, false);
|
2022-03-31 22:55:08 +00:00
|
|
|
|
|
|
|
/* Track what we've attempted to transmit at least once so that the
|
|
|
|
* retransmission algorithm doesn't try to resend what we haven't sent
|
2024-01-29 22:29:58 +00:00
|
|
|
* yet.
|
2022-03-31 22:55:08 +00:00
|
|
|
*/
|
2024-01-29 22:29:58 +00:00
|
|
|
if (txb->seq == call->tx_transmitted + 1)
|
|
|
|
call->tx_transmitted = txb->seq;
|
2016-09-21 23:29:31 +00:00
|
|
|
|
2007-04-26 22:48:28 +00:00
|
|
|
/* send the packet with the don't fragment bit set if we currently
|
|
|
|
* think it's small enough */
|
2022-03-31 22:55:08 +00:00
|
|
|
if (txb->len >= call->peer->maxdata)
|
2016-09-21 23:29:31 +00:00
|
|
|
goto send_fragmentable;
|
2024-01-29 22:38:31 +00:00
|
|
|
rxrpc_local_dont_fragment(conn->local, true);
|
2016-09-21 23:29:31 +00:00
|
|
|
|
2024-01-29 15:01:10 +00:00
|
|
|
txb->wire.flags = txb->flags & RXRPC_TXBUF_WIRE_FLAGS;
|
2022-03-31 22:55:08 +00:00
|
|
|
txb->last_sent = ktime_get_real();
|
2024-01-29 15:01:10 +00:00
|
|
|
if (txb->flags & RXRPC_REQUEST_ACK)
|
2024-01-29 13:51:30 +00:00
|
|
|
rtt_slot = rxrpc_begin_rtt_probe(call, txb->serial, rxrpc_rtt_tx_data);
|
2018-09-27 14:13:08 +00:00
|
|
|
|
2016-09-21 23:29:31 +00: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 13:01:25 +00:00
|
|
|
rxrpc_inc_stat(call->rxnet, stat_tx_data_send);
|
2022-10-19 12:49:02 +00:00
|
|
|
ret = do_udp_sendmsg(conn->local->socket, &msg, len);
|
|
|
|
conn->peer->last_tx_at = ktime_get_seconds();
|
2016-09-21 23:29:31 +00: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-19 22:29:16 +00:00
|
|
|
if (ret < 0) {
|
2022-11-11 13:47:35 +00:00
|
|
|
rxrpc_inc_stat(call->rxnet, stat_tx_data_send_fail);
|
2024-01-29 13:51:30 +00:00
|
|
|
rxrpc_cancel_rtt_probe(call, txb->serial, rtt_slot);
|
|
|
|
trace_rxrpc_tx_fail(call->debug_id, txb->serial, ret,
|
2018-07-23 16:18:37 +00: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-19 22:29:16 +00:00
|
|
|
} else {
|
2022-03-31 22:55:08 +00:00
|
|
|
trace_rxrpc_tx_packet(call->debug_id, &txb->wire,
|
2018-07-23 16:18:37 +00: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-19 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 13:39:53 +00:00
|
|
|
rxrpc_tx_backoff(call, ret);
|
2016-09-21 23:29:31 +00:00
|
|
|
if (ret == -EMSGSIZE)
|
|
|
|
goto send_fragmentable;
|
|
|
|
|
|
|
|
done:
|
2016-09-21 23:29:31 +00:00
|
|
|
if (ret >= 0) {
|
2022-10-03 17:49:11 +00:00
|
|
|
call->tx_last_sent = txb->last_sent;
|
2024-01-29 15:01:10 +00:00
|
|
|
if (txb->flags & RXRPC_REQUEST_ACK) {
|
2022-03-31 22:55:08 +00:00
|
|
|
call->peer->rtt_last_req = txb->last_sent;
|
2020-05-11 13:54:34 +00:00
|
|
|
if (call->peer->rtt_count > 1) {
|
2017-11-24 10:18:42 +00: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-21 23:12:58 +00:00
|
|
|
ack_lost_at = rxrpc_get_rto_backoff(call->peer, false);
|
2017-11-24 10:18:42 +00:00
|
|
|
ack_lost_at += nowj;
|
2024-01-30 16:39:15 +00:00
|
|
|
call->ack_lost_at = ack_lost_at;
|
2017-11-24 10:18:42 +00:00
|
|
|
rxrpc_reduce_call_timer(call, ack_lost_at, nowj,
|
|
|
|
rxrpc_timer_set_for_lost_ack);
|
|
|
|
}
|
2016-09-21 23:29:31 +00:00
|
|
|
}
|
2018-05-10 22:26:00 +00:00
|
|
|
|
2022-03-31 22:55:08 +00:00
|
|
|
if (txb->seq == 1 &&
|
2018-05-10 22:26:00 +00:00
|
|
|
!test_and_set_bit(RXRPC_CALL_BEGAN_RX_TIMER,
|
|
|
|
&call->flags)) {
|
2024-01-30 16:39:15 +00:00
|
|
|
unsigned long nowj = jiffies;
|
2018-05-10 22:26:00 +00:00
|
|
|
|
2024-01-30 16:39:15 +00:00
|
|
|
call->expect_rx_by = nowj + call->next_rx_timo;
|
|
|
|
rxrpc_reduce_call_timer(call, call->expect_rx_by, nowj,
|
2018-05-10 22:26:00 +00:00
|
|
|
rxrpc_timer_set_for_normal);
|
|
|
|
}
|
2017-11-24 10:18:42 +00:00
|
|
|
|
2018-11-01 13:39:53 +00: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 10:18:42 +00:00
|
|
|
|
2016-09-21 23:29:31 +00:00
|
|
|
_leave(" = %d [%u]", ret, call->peer->maxdata);
|
|
|
|
return ret;
|
2007-04-26 22:48:28 +00:00
|
|
|
|
|
|
|
send_fragmentable:
|
|
|
|
/* attempt to send this message with fragmentation enabled */
|
|
|
|
_debug("send fragment");
|
|
|
|
|
2022-03-31 22:55:08 +00:00
|
|
|
txb->last_sent = ktime_get_real();
|
2024-01-29 15:01:10 +00:00
|
|
|
if (txb->flags & RXRPC_REQUEST_ACK)
|
2024-01-29 13:51:30 +00:00
|
|
|
rtt_slot = rxrpc_begin_rtt_probe(call, txb->serial, rxrpc_rtt_tx_data);
|
2018-09-27 14:13:08 +00:00
|
|
|
|
2022-10-19 12:49:02 +00:00
|
|
|
switch (conn->local->srx.transport.family) {
|
2020-04-13 12:57:14 +00:00
|
|
|
case AF_INET6:
|
2016-06-17 10:53:37 +00:00
|
|
|
case AF_INET:
|
2024-01-09 15:10:48 +00:00
|
|
|
rxrpc_local_dont_fragment(conn->local, false);
|
2022-05-11 13:01:25 +00:00
|
|
|
rxrpc_inc_stat(call->rxnet, stat_tx_data_send_frag);
|
2022-10-19 12:49:02 +00:00
|
|
|
ret = do_udp_sendmsg(conn->local->socket, &msg, len);
|
|
|
|
conn->peer->last_tx_at = ktime_get_seconds();
|
2016-09-13 07:49:05 +00:00
|
|
|
break;
|
2019-07-02 14:55:28 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
BUG();
|
2007-04-26 22:48:28 +00: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-19 22:29:16 +00:00
|
|
|
if (ret < 0) {
|
2022-11-11 13:47:35 +00:00
|
|
|
rxrpc_inc_stat(call->rxnet, stat_tx_data_send_fail);
|
2024-01-29 13:51:30 +00:00
|
|
|
rxrpc_cancel_rtt_probe(call, txb->serial, rtt_slot);
|
|
|
|
trace_rxrpc_tx_fail(call->debug_id, txb->serial, ret,
|
2018-07-23 16:18:37 +00: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-19 22:29:16 +00:00
|
|
|
} else {
|
2022-03-31 22:55:08 +00:00
|
|
|
trace_rxrpc_tx_packet(call->debug_id, &txb->wire,
|
2018-07-23 16:18:37 +00: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-19 22:29:16 +00:00
|
|
|
}
|
2018-11-01 13:39:53 +00:00
|
|
|
rxrpc_tx_backoff(call, ret);
|
2016-09-21 23:29:31 +00:00
|
|
|
goto done;
|
2007-04-26 22:48:28 +00: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 10:10:12 +00:00
|
|
|
|
2022-10-20 08:56:36 +00:00
|
|
|
/*
|
|
|
|
* Transmit a connection-level abort.
|
|
|
|
*/
|
|
|
|
void rxrpc_send_conn_abort(struct rxrpc_connection *conn)
|
|
|
|
{
|
|
|
|
struct rxrpc_wire_header whdr;
|
|
|
|
struct msghdr msg;
|
|
|
|
struct kvec iov[2];
|
|
|
|
__be32 word;
|
|
|
|
size_t len;
|
|
|
|
u32 serial;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
msg.msg_name = &conn->peer->srx.transport;
|
|
|
|
msg.msg_namelen = conn->peer->srx.transport_len;
|
|
|
|
msg.msg_control = NULL;
|
|
|
|
msg.msg_controllen = 0;
|
|
|
|
msg.msg_flags = 0;
|
|
|
|
|
|
|
|
whdr.epoch = htonl(conn->proto.epoch);
|
|
|
|
whdr.cid = htonl(conn->proto.cid);
|
|
|
|
whdr.callNumber = 0;
|
|
|
|
whdr.seq = 0;
|
|
|
|
whdr.type = RXRPC_PACKET_TYPE_ABORT;
|
|
|
|
whdr.flags = conn->out_clientflag;
|
|
|
|
whdr.userStatus = 0;
|
|
|
|
whdr.securityIndex = conn->security_ix;
|
|
|
|
whdr._rsvd = 0;
|
|
|
|
whdr.serviceId = htons(conn->service_id);
|
|
|
|
|
|
|
|
word = htonl(conn->abort_code);
|
|
|
|
|
|
|
|
iov[0].iov_base = &whdr;
|
|
|
|
iov[0].iov_len = sizeof(whdr);
|
|
|
|
iov[1].iov_base = &word;
|
|
|
|
iov[1].iov_len = sizeof(word);
|
|
|
|
|
|
|
|
len = iov[0].iov_len + iov[1].iov_len;
|
|
|
|
|
2024-02-02 15:19:13 +00:00
|
|
|
serial = rxrpc_get_next_serial(conn);
|
2022-10-20 08:56:36 +00:00
|
|
|
whdr.serial = htonl(serial);
|
|
|
|
|
|
|
|
iov_iter_kvec(&msg.msg_iter, WRITE, iov, 2, len);
|
|
|
|
ret = do_udp_sendmsg(conn->local->socket, &msg, len);
|
|
|
|
if (ret < 0) {
|
|
|
|
trace_rxrpc_tx_fail(conn->debug_id, serial, ret,
|
|
|
|
rxrpc_tx_point_conn_abort);
|
|
|
|
_debug("sendmsg failed: %d", ret);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
trace_rxrpc_tx_packet(conn->debug_id, &whdr, rxrpc_tx_point_conn_abort);
|
|
|
|
|
|
|
|
conn->peer->last_tx_at = ktime_get_seconds();
|
|
|
|
}
|
|
|
|
|
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 10:10:12 +00:00
|
|
|
/*
|
2020-01-23 13:13:41 +00:00
|
|
|
* Reject a packet through the local endpoint.
|
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 10:10:12 +00:00
|
|
|
*/
|
2020-01-23 13:13:41 +00:00
|
|
|
void rxrpc_reject_packet(struct rxrpc_local *local, struct sk_buff *skb)
|
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 10:10:12 +00:00
|
|
|
{
|
|
|
|
struct rxrpc_wire_header whdr;
|
2020-01-23 13:13:41 +00:00
|
|
|
struct sockaddr_rxrpc srx;
|
|
|
|
struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
|
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 10:10:12 +00:00
|
|
|
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 14:13:08 +00: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 10:10:12 +00:00
|
|
|
|
2020-01-23 13:13:41 +00:00
|
|
|
rxrpc_see_skb(skb, rxrpc_skb_see_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 10:10:12 +00:00
|
|
|
|
|
|
|
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 07:49:05 +00: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 10:10:12 +00:00
|
|
|
msg.msg_control = NULL;
|
|
|
|
msg.msg_controllen = 0;
|
|
|
|
msg.msg_flags = 0;
|
|
|
|
|
|
|
|
memset(&whdr, 0, sizeof(whdr));
|
|
|
|
|
2020-01-23 13:13:41 +00: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:
|
|
|
|
return;
|
|
|
|
}
|
2016-09-13 07:49:05 +00:00
|
|
|
|
2020-01-23 13:13:41 +00:00
|
|
|
if (rxrpc_extract_addr_from_skb(&srx, skb) == 0) {
|
|
|
|
msg.msg_namelen = srx.transport_len;
|
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 14:13:08 +00:00
|
|
|
|
2020-01-23 13:13:41 +00: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;
|
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 10:10:12 +00:00
|
|
|
|
2020-01-23 13:13:41 +00:00
|
|
|
iov_iter_kvec(&msg.msg_iter, WRITE, iov, ioc, size);
|
|
|
|
ret = do_udp_sendmsg(local->socket, &msg, size);
|
|
|
|
if (ret < 0)
|
|
|
|
trace_rxrpc_tx_fail(local->debug_id, 0, ret,
|
|
|
|
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 10:10:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-30 20:04:43 +00: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;
|
|
|
|
|
2022-03-22 11:07:20 +00:00
|
|
|
iov_iter_kvec(&msg.msg_iter, WRITE, iov, 2, len);
|
|
|
|
ret = do_udp_sendmsg(peer->local->socket, &msg, len);
|
2018-03-30 20:04:43 +00:00
|
|
|
if (ret < 0)
|
2018-05-10 22:26:01 +00:00
|
|
|
trace_rxrpc_tx_fail(peer->debug_id, 0, ret,
|
2018-07-23 16:18:37 +00:00
|
|
|
rxrpc_tx_point_version_keepalive);
|
|
|
|
else
|
|
|
|
trace_rxrpc_tx_packet(peer->debug_id, &whdr,
|
|
|
|
rxrpc_tx_point_version_keepalive);
|
2018-03-30 20:04:43 +00:00
|
|
|
|
2018-08-08 10:30:02 +00:00
|
|
|
peer->last_tx_at = ktime_get_seconds();
|
2018-03-30 20:04:43 +00:00
|
|
|
_leave("");
|
|
|
|
}
|
2022-03-31 22:55:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Schedule an instant Tx resend.
|
|
|
|
*/
|
|
|
|
static inline void rxrpc_instant_resend(struct rxrpc_call *call,
|
|
|
|
struct rxrpc_txbuf *txb)
|
|
|
|
{
|
2022-10-27 10:25:55 +00:00
|
|
|
if (!__rxrpc_call_is_complete(call))
|
2022-03-31 22:55:08 +00:00
|
|
|
kdebug("resend");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transmit one packet.
|
|
|
|
*/
|
|
|
|
void rxrpc_transmit_one(struct rxrpc_call *call, struct rxrpc_txbuf *txb)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = rxrpc_send_data_packet(call, txb);
|
|
|
|
if (ret < 0) {
|
|
|
|
switch (ret) {
|
|
|
|
case -ENETUNREACH:
|
|
|
|
case -EHOSTUNREACH:
|
|
|
|
case -ECONNREFUSED:
|
|
|
|
rxrpc_set_call_completion(call, RXRPC_CALL_LOCAL_ERROR,
|
|
|
|
0, ret);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_debug("need instant resend %d", ret);
|
|
|
|
rxrpc_instant_resend(call, txb);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unsigned long now = jiffies;
|
|
|
|
unsigned long resend_at = now + call->peer->rto_j;
|
|
|
|
|
2024-01-30 16:39:15 +00:00
|
|
|
call->resend_at = resend_at;
|
2022-03-31 22:55:08 +00:00
|
|
|
rxrpc_reduce_call_timer(call, resend_at, now,
|
|
|
|
rxrpc_timer_set_for_send);
|
|
|
|
}
|
|
|
|
}
|