2009-02-24 18:30:28 +03:00
|
|
|
/*
|
2019-08-26 12:39:12 +03:00
|
|
|
* Copyright (c) 2006, 2019 Oracle and/or its affiliates. All rights reserved.
|
2009-02-24 18:30:28 +03:00
|
|
|
*
|
|
|
|
* This software is available to you under a choice of one of two
|
|
|
|
* licenses. You may choose to be licensed under the terms of the GNU
|
|
|
|
* General Public License (GPL) Version 2, available from the file
|
|
|
|
* COPYING in the main directory of this source tree, or the
|
|
|
|
* OpenIB.org BSD license below:
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or
|
|
|
|
* without modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials
|
|
|
|
* provided with the distribution.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.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 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2009-02-24 18:30:28 +03:00
|
|
|
#include <net/sock.h>
|
|
|
|
#include <linux/in.h>
|
2011-07-15 19:47:34 +04:00
|
|
|
#include <linux/export.h>
|
2016-03-02 02:20:43 +03:00
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/rds.h>
|
2009-02-24 18:30:28 +03:00
|
|
|
|
|
|
|
#include "rds.h"
|
|
|
|
|
|
|
|
void rds_inc_init(struct rds_incoming *inc, struct rds_connection *conn,
|
2018-07-24 06:51:21 +03:00
|
|
|
struct in6_addr *saddr)
|
2009-02-24 18:30:28 +03:00
|
|
|
{
|
2017-07-04 15:53:16 +03:00
|
|
|
refcount_set(&inc->i_refcount, 1);
|
2009-02-24 18:30:28 +03:00
|
|
|
INIT_LIST_HEAD(&inc->i_item);
|
|
|
|
inc->i_conn = conn;
|
2018-07-24 06:51:21 +03:00
|
|
|
inc->i_saddr = *saddr;
|
2019-08-23 17:03:18 +03:00
|
|
|
inc->i_usercopy.rdma_cookie = 0;
|
|
|
|
inc->i_usercopy.rx_tstamp = ktime_set(0, 0);
|
2016-07-05 08:35:15 +03:00
|
|
|
|
2018-09-17 05:49:30 +03:00
|
|
|
memset(inc->i_rx_lat_trace, 0, sizeof(inc->i_rx_lat_trace));
|
2009-02-24 18:30:28 +03:00
|
|
|
}
|
2009-08-21 16:28:32 +04:00
|
|
|
EXPORT_SYMBOL_GPL(rds_inc_init);
|
2009-02-24 18:30:28 +03:00
|
|
|
|
2016-06-13 19:44:29 +03:00
|
|
|
void rds_inc_path_init(struct rds_incoming *inc, struct rds_conn_path *cp,
|
2018-07-24 06:51:21 +03:00
|
|
|
struct in6_addr *saddr)
|
2016-06-13 19:44:29 +03:00
|
|
|
{
|
2017-07-04 15:53:16 +03:00
|
|
|
refcount_set(&inc->i_refcount, 1);
|
2016-06-13 19:44:29 +03:00
|
|
|
INIT_LIST_HEAD(&inc->i_item);
|
|
|
|
inc->i_conn = cp->cp_conn;
|
|
|
|
inc->i_conn_path = cp;
|
2018-07-24 06:51:21 +03:00
|
|
|
inc->i_saddr = *saddr;
|
2019-08-23 17:03:18 +03:00
|
|
|
inc->i_usercopy.rdma_cookie = 0;
|
|
|
|
inc->i_usercopy.rx_tstamp = ktime_set(0, 0);
|
2016-06-13 19:44:29 +03:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(rds_inc_path_init);
|
|
|
|
|
2010-10-19 12:08:33 +04:00
|
|
|
static void rds_inc_addref(struct rds_incoming *inc)
|
2009-02-24 18:30:28 +03:00
|
|
|
{
|
2017-07-04 15:53:16 +03:00
|
|
|
rdsdebug("addref inc %p ref %d\n", inc, refcount_read(&inc->i_refcount));
|
|
|
|
refcount_inc(&inc->i_refcount);
|
2009-02-24 18:30:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void rds_inc_put(struct rds_incoming *inc)
|
|
|
|
{
|
2017-07-04 15:53:16 +03:00
|
|
|
rdsdebug("put inc %p ref %d\n", inc, refcount_read(&inc->i_refcount));
|
|
|
|
if (refcount_dec_and_test(&inc->i_refcount)) {
|
2009-02-24 18:30:28 +03:00
|
|
|
BUG_ON(!list_empty(&inc->i_item));
|
|
|
|
|
|
|
|
inc->i_conn->c_trans->inc_free(inc);
|
|
|
|
}
|
|
|
|
}
|
2009-08-21 16:28:32 +04:00
|
|
|
EXPORT_SYMBOL_GPL(rds_inc_put);
|
2009-02-24 18:30:28 +03:00
|
|
|
|
|
|
|
static void rds_recv_rcvbuf_delta(struct rds_sock *rs, struct sock *sk,
|
|
|
|
struct rds_cong_map *map,
|
|
|
|
int delta, __be16 port)
|
|
|
|
{
|
|
|
|
int now_congested;
|
|
|
|
|
|
|
|
if (delta == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
rs->rs_rcv_bytes += delta;
|
2016-07-10 03:36:20 +03:00
|
|
|
if (delta > 0)
|
|
|
|
rds_stats_add(s_recv_bytes_added_to_socket, delta);
|
|
|
|
else
|
|
|
|
rds_stats_add(s_recv_bytes_removed_from_socket, -delta);
|
2018-06-14 21:52:34 +03:00
|
|
|
|
|
|
|
/* loop transport doesn't send/recv congestion updates */
|
|
|
|
if (rs->rs_transport->t_type == RDS_TRANS_LOOP)
|
|
|
|
return;
|
|
|
|
|
2009-02-24 18:30:28 +03:00
|
|
|
now_congested = rs->rs_rcv_bytes > rds_sk_rcvbuf(rs);
|
|
|
|
|
2018-07-24 06:51:21 +03:00
|
|
|
rdsdebug("rs %p (%pI6c:%u) recv bytes %d buf %d "
|
2009-02-24 18:30:28 +03:00
|
|
|
"now_cong %d delta %d\n",
|
|
|
|
rs, &rs->rs_bound_addr,
|
|
|
|
ntohs(rs->rs_bound_port), rs->rs_rcv_bytes,
|
|
|
|
rds_sk_rcvbuf(rs), now_congested, delta);
|
|
|
|
|
|
|
|
/* wasn't -> am congested */
|
|
|
|
if (!rs->rs_congested && now_congested) {
|
|
|
|
rs->rs_congested = 1;
|
|
|
|
rds_cong_set_bit(map, port);
|
|
|
|
rds_cong_queue_updates(map);
|
|
|
|
}
|
|
|
|
/* was -> aren't congested */
|
|
|
|
/* Require more free space before reporting uncongested to prevent
|
|
|
|
bouncing cong/uncong state too often */
|
|
|
|
else if (rs->rs_congested && (rs->rs_rcv_bytes < (rds_sk_rcvbuf(rs)/2))) {
|
|
|
|
rs->rs_congested = 0;
|
|
|
|
rds_cong_clear_bit(map, port);
|
|
|
|
rds_cong_queue_updates(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do nothing if no change in cong state */
|
|
|
|
}
|
|
|
|
|
2016-11-17 00:29:49 +03:00
|
|
|
static void rds_conn_peer_gen_update(struct rds_connection *conn,
|
|
|
|
u32 peer_gen_num)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct rds_message *rm, *tmp;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
WARN_ON(conn->c_trans->t_type != RDS_TRANS_TCP);
|
|
|
|
if (peer_gen_num != 0) {
|
|
|
|
if (conn->c_peer_gen_num != 0 &&
|
|
|
|
peer_gen_num != conn->c_peer_gen_num) {
|
|
|
|
for (i = 0; i < RDS_MPATH_WORKERS; i++) {
|
|
|
|
struct rds_conn_path *cp;
|
|
|
|
|
|
|
|
cp = &conn->c_path[i];
|
|
|
|
spin_lock_irqsave(&cp->cp_lock, flags);
|
|
|
|
cp->cp_next_tx_seq = 1;
|
|
|
|
cp->cp_next_rx_seq = 0;
|
|
|
|
list_for_each_entry_safe(rm, tmp,
|
|
|
|
&cp->cp_retrans,
|
|
|
|
m_conn_item) {
|
|
|
|
set_bit(RDS_MSG_FLUSH, &rm->m_flags);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&cp->cp_lock, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
conn->c_peer_gen_num = peer_gen_num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-24 18:30:28 +03:00
|
|
|
/*
|
|
|
|
* Process all extension headers that come with this message.
|
|
|
|
*/
|
|
|
|
static void rds_recv_incoming_exthdrs(struct rds_incoming *inc, struct rds_sock *rs)
|
|
|
|
{
|
|
|
|
struct rds_header *hdr = &inc->i_hdr;
|
|
|
|
unsigned int pos = 0, type, len;
|
|
|
|
union {
|
|
|
|
struct rds_ext_header_version version;
|
|
|
|
struct rds_ext_header_rdma rdma;
|
|
|
|
struct rds_ext_header_rdma_dest rdma_dest;
|
|
|
|
} buffer;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
len = sizeof(buffer);
|
|
|
|
type = rds_message_next_extension(hdr, &pos, &buffer, &len);
|
|
|
|
if (type == RDS_EXTHDR_NONE)
|
|
|
|
break;
|
|
|
|
/* Process extension header here */
|
|
|
|
switch (type) {
|
|
|
|
case RDS_EXTHDR_RDMA:
|
|
|
|
rds_rdma_unuse(rs, be32_to_cpu(buffer.rdma.h_rdma_rkey), 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RDS_EXTHDR_RDMA_DEST:
|
|
|
|
/* We ignore the size for now. We could stash it
|
|
|
|
* somewhere and use it for error checking. */
|
2019-08-23 17:03:18 +03:00
|
|
|
inc->i_usercopy.rdma_cookie = rds_rdma_make_cookie(
|
2009-02-24 18:30:28 +03:00
|
|
|
be32_to_cpu(buffer.rdma_dest.h_rdma_rkey),
|
|
|
|
be32_to_cpu(buffer.rdma_dest.h_rdma_offset));
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-14 13:51:03 +03:00
|
|
|
static void rds_recv_hs_exthdrs(struct rds_header *hdr,
|
|
|
|
struct rds_connection *conn)
|
|
|
|
{
|
|
|
|
unsigned int pos = 0, type, len;
|
|
|
|
union {
|
|
|
|
struct rds_ext_header_version version;
|
|
|
|
u16 rds_npaths;
|
2016-11-17 00:29:49 +03:00
|
|
|
u32 rds_gen_num;
|
2016-07-14 13:51:03 +03:00
|
|
|
} buffer;
|
2016-11-17 00:29:49 +03:00
|
|
|
u32 new_peer_gen_num = 0;
|
2016-07-14 13:51:03 +03:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
len = sizeof(buffer);
|
|
|
|
type = rds_message_next_extension(hdr, &pos, &buffer, &len);
|
|
|
|
if (type == RDS_EXTHDR_NONE)
|
|
|
|
break;
|
|
|
|
/* Process extension header here */
|
|
|
|
switch (type) {
|
|
|
|
case RDS_EXTHDR_NPATHS:
|
|
|
|
conn->c_npaths = min_t(int, RDS_MPATH_WORKERS,
|
2017-06-15 21:28:54 +03:00
|
|
|
be16_to_cpu(buffer.rds_npaths));
|
2016-07-14 13:51:03 +03:00
|
|
|
break;
|
2016-11-17 00:29:49 +03:00
|
|
|
case RDS_EXTHDR_GEN_NUM:
|
2017-06-15 21:28:54 +03:00
|
|
|
new_peer_gen_num = be32_to_cpu(buffer.rds_gen_num);
|
2016-11-17 00:29:49 +03:00
|
|
|
break;
|
2016-07-14 13:51:03 +03:00
|
|
|
default:
|
|
|
|
pr_warn_ratelimited("ignoring unknown exthdr type "
|
|
|
|
"0x%x\n", type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* if RDS_EXTHDR_NPATHS was not found, default to a single-path */
|
|
|
|
conn->c_npaths = max_t(int, conn->c_npaths, 1);
|
2017-06-21 23:40:12 +03:00
|
|
|
conn->c_ping_triggered = 0;
|
2016-11-17 00:29:49 +03:00
|
|
|
rds_conn_peer_gen_update(conn, new_peer_gen_num);
|
2016-07-14 13:51:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* rds_start_mprds() will synchronously start multiple paths when appropriate.
|
|
|
|
* The scheme is based on the following rules:
|
|
|
|
*
|
|
|
|
* 1. rds_sendmsg on first connect attempt sends the probe ping, with the
|
|
|
|
* sender's npaths (s_npaths)
|
|
|
|
* 2. rcvr of probe-ping knows the mprds_paths = min(s_npaths, r_npaths). It
|
|
|
|
* sends back a probe-pong with r_npaths. After that, if rcvr is the
|
|
|
|
* smaller ip addr, it starts rds_conn_path_connect_if_down on all
|
|
|
|
* mprds_paths.
|
|
|
|
* 3. sender gets woken up, and can move to rds_conn_path_connect_if_down.
|
|
|
|
* If it is the smaller ipaddr, rds_conn_path_connect_if_down can be
|
|
|
|
* called after reception of the probe-pong on all mprds_paths.
|
|
|
|
* Otherwise (sender of probe-ping is not the smaller ip addr): just call
|
|
|
|
* rds_conn_path_connect_if_down on the hashed path. (see rule 4)
|
2017-06-21 23:40:12 +03:00
|
|
|
* 4. rds_connect_worker must only trigger a connection if laddr < faddr.
|
2016-07-14 13:51:03 +03:00
|
|
|
* 5. sender may end up queuing the packet on the cp. will get sent out later.
|
|
|
|
* when connection is completed.
|
|
|
|
*/
|
|
|
|
static void rds_start_mprds(struct rds_connection *conn)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct rds_conn_path *cp;
|
|
|
|
|
2017-06-15 21:28:54 +03:00
|
|
|
if (conn->c_npaths > 1 &&
|
2018-07-24 06:51:21 +03:00
|
|
|
rds_addr_cmp(&conn->c_laddr, &conn->c_faddr) < 0) {
|
2017-06-21 23:40:12 +03:00
|
|
|
for (i = 0; i < conn->c_npaths; i++) {
|
2016-07-14 13:51:03 +03:00
|
|
|
cp = &conn->c_path[i];
|
|
|
|
rds_conn_path_connect_if_down(cp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-24 18:30:28 +03:00
|
|
|
/*
|
|
|
|
* The transport must make sure that this is serialized against other
|
|
|
|
* rx and conn reset on this specific conn.
|
|
|
|
*
|
|
|
|
* We currently assert that only one fragmented message will be sent
|
|
|
|
* down a connection at a time. This lets us reassemble in the conn
|
|
|
|
* instead of per-flow which means that we don't have to go digging through
|
|
|
|
* flows to tear down partial reassembly progress on conn failure and
|
|
|
|
* we save flow lookup and locking for each frag arrival. It does mean
|
|
|
|
* that small messages will wait behind large ones. Fragmenting at all
|
|
|
|
* is only to reduce the memory consumption of pre-posted buffers.
|
|
|
|
*
|
|
|
|
* The caller passes in saddr and daddr instead of us getting it from the
|
|
|
|
* conn. This lets loopback, who only has one conn for both directions,
|
|
|
|
* tell us which roles the addrs in the conn are playing for this message.
|
|
|
|
*/
|
2018-07-24 06:51:21 +03:00
|
|
|
void rds_recv_incoming(struct rds_connection *conn, struct in6_addr *saddr,
|
|
|
|
struct in6_addr *daddr,
|
2011-11-25 19:14:40 +04:00
|
|
|
struct rds_incoming *inc, gfp_t gfp)
|
2009-02-24 18:30:28 +03:00
|
|
|
{
|
|
|
|
struct rds_sock *rs = NULL;
|
|
|
|
struct sock *sk;
|
|
|
|
unsigned long flags;
|
2016-06-13 19:44:28 +03:00
|
|
|
struct rds_conn_path *cp;
|
2009-02-24 18:30:28 +03:00
|
|
|
|
|
|
|
inc->i_conn = conn;
|
|
|
|
inc->i_rx_jiffies = jiffies;
|
2016-06-13 19:44:28 +03:00
|
|
|
if (conn->c_trans->t_mp_capable)
|
|
|
|
cp = inc->i_conn_path;
|
|
|
|
else
|
|
|
|
cp = &conn->c_path[0];
|
2009-02-24 18:30:28 +03:00
|
|
|
|
|
|
|
rdsdebug("conn %p next %llu inc %p seq %llu len %u sport %u dport %u "
|
|
|
|
"flags 0x%x rx_jiffies %lu\n", conn,
|
2016-06-13 19:44:28 +03:00
|
|
|
(unsigned long long)cp->cp_next_rx_seq,
|
2009-02-24 18:30:28 +03:00
|
|
|
inc,
|
|
|
|
(unsigned long long)be64_to_cpu(inc->i_hdr.h_sequence),
|
|
|
|
be32_to_cpu(inc->i_hdr.h_len),
|
|
|
|
be16_to_cpu(inc->i_hdr.h_sport),
|
|
|
|
be16_to_cpu(inc->i_hdr.h_dport),
|
|
|
|
inc->i_hdr.h_flags,
|
|
|
|
inc->i_rx_jiffies);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sequence numbers should only increase. Messages get their
|
|
|
|
* sequence number as they're queued in a sending conn. They
|
|
|
|
* can be dropped, though, if the sending socket is closed before
|
|
|
|
* they hit the wire. So sequence numbers can skip forward
|
|
|
|
* under normal operation. They can also drop back in the conn
|
|
|
|
* failover case as previously sent messages are resent down the
|
|
|
|
* new instance of a conn. We drop those, otherwise we have
|
|
|
|
* to assume that the next valid seq does not come after a
|
|
|
|
* hole in the fragment stream.
|
|
|
|
*
|
|
|
|
* The headers don't give us a way to realize if fragments of
|
|
|
|
* a message have been dropped. We assume that frags that arrive
|
|
|
|
* to a flow are part of the current message on the flow that is
|
|
|
|
* being reassembled. This means that senders can't drop messages
|
|
|
|
* from the sending conn until all their frags are sent.
|
|
|
|
*
|
|
|
|
* XXX we could spend more on the wire to get more robust failure
|
|
|
|
* detection, arguably worth it to avoid data corruption.
|
|
|
|
*/
|
2016-06-13 19:44:28 +03:00
|
|
|
if (be64_to_cpu(inc->i_hdr.h_sequence) < cp->cp_next_rx_seq &&
|
2009-11-30 03:55:45 +03:00
|
|
|
(inc->i_hdr.h_flags & RDS_FLAG_RETRANSMITTED)) {
|
2009-02-24 18:30:28 +03:00
|
|
|
rds_stats_inc(s_recv_drop_old_seq);
|
|
|
|
goto out;
|
|
|
|
}
|
2016-06-13 19:44:28 +03:00
|
|
|
cp->cp_next_rx_seq = be64_to_cpu(inc->i_hdr.h_sequence) + 1;
|
2009-02-24 18:30:28 +03:00
|
|
|
|
|
|
|
if (rds_sysctl_ping_enable && inc->i_hdr.h_dport == 0) {
|
2016-07-01 02:11:18 +03:00
|
|
|
if (inc->i_hdr.h_sport == 0) {
|
2018-07-24 06:51:21 +03:00
|
|
|
rdsdebug("ignore ping with 0 sport from %pI6c\n",
|
|
|
|
saddr);
|
2016-07-01 02:11:18 +03:00
|
|
|
goto out;
|
|
|
|
}
|
2009-02-24 18:30:28 +03:00
|
|
|
rds_stats_inc(s_recv_ping);
|
2016-06-13 19:44:36 +03:00
|
|
|
rds_send_pong(cp, inc->i_hdr.h_sport);
|
2016-07-14 13:51:03 +03:00
|
|
|
/* if this is a handshake ping, start multipath if necessary */
|
2017-06-15 21:28:54 +03:00
|
|
|
if (RDS_HS_PROBE(be16_to_cpu(inc->i_hdr.h_sport),
|
|
|
|
be16_to_cpu(inc->i_hdr.h_dport))) {
|
2016-07-14 13:51:03 +03:00
|
|
|
rds_recv_hs_exthdrs(&inc->i_hdr, cp->cp_conn);
|
|
|
|
rds_start_mprds(cp->cp_conn);
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-06-15 21:28:54 +03:00
|
|
|
if (be16_to_cpu(inc->i_hdr.h_dport) == RDS_FLAG_PROBE_PORT &&
|
2016-07-14 13:51:03 +03:00
|
|
|
inc->i_hdr.h_sport == 0) {
|
|
|
|
rds_recv_hs_exthdrs(&inc->i_hdr, cp->cp_conn);
|
|
|
|
/* if this is a handshake pong, start multipath if necessary */
|
|
|
|
rds_start_mprds(cp->cp_conn);
|
|
|
|
wake_up(&cp->cp_conn->c_hs_waitq);
|
2009-02-24 18:30:28 +03:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-07-24 06:51:22 +03:00
|
|
|
rs = rds_find_bound(daddr, inc->i_hdr.h_dport, conn->c_bound_if);
|
2010-01-12 22:56:44 +03:00
|
|
|
if (!rs) {
|
2009-02-24 18:30:28 +03:00
|
|
|
rds_stats_inc(s_recv_drop_no_sock);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process extension headers */
|
|
|
|
rds_recv_incoming_exthdrs(inc, rs);
|
|
|
|
|
|
|
|
/* We can be racing with rds_release() which marks the socket dead. */
|
|
|
|
sk = rds_rs_to_sk(rs);
|
|
|
|
|
|
|
|
/* serialize with rds_release -> sock_orphan */
|
|
|
|
write_lock_irqsave(&rs->rs_recv_lock, flags);
|
|
|
|
if (!sock_flag(sk, SOCK_DEAD)) {
|
|
|
|
rdsdebug("adding inc %p to rs %p's recv queue\n", inc, rs);
|
|
|
|
rds_stats_inc(s_recv_queued);
|
|
|
|
rds_recv_rcvbuf_delta(rs, sk, inc->i_conn->c_lcong,
|
|
|
|
be32_to_cpu(inc->i_hdr.h_len),
|
|
|
|
inc->i_hdr.h_dport);
|
2016-03-02 02:20:43 +03:00
|
|
|
if (sock_flag(sk, SOCK_RCVTSTAMP))
|
2019-08-23 17:03:18 +03:00
|
|
|
inc->i_usercopy.rx_tstamp = ktime_get_real();
|
2009-02-24 18:30:28 +03:00
|
|
|
rds_inc_addref(inc);
|
2016-07-05 08:35:15 +03:00
|
|
|
inc->i_rx_lat_trace[RDS_MSG_RX_END] = local_clock();
|
2009-02-24 18:30:28 +03:00
|
|
|
list_add_tail(&inc->i_item, &rs->rs_recv_queue);
|
|
|
|
__rds_wake_sk_sleep(sk);
|
|
|
|
} else {
|
|
|
|
rds_stats_inc(s_recv_drop_dead_sock);
|
|
|
|
}
|
|
|
|
write_unlock_irqrestore(&rs->rs_recv_lock, flags);
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (rs)
|
|
|
|
rds_sock_put(rs);
|
|
|
|
}
|
2009-08-21 16:28:32 +04:00
|
|
|
EXPORT_SYMBOL_GPL(rds_recv_incoming);
|
2009-02-24 18:30:28 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* be very careful here. This is being called as the condition in
|
|
|
|
* wait_event_*() needs to cope with being called many times.
|
|
|
|
*/
|
|
|
|
static int rds_next_incoming(struct rds_sock *rs, struct rds_incoming **inc)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2010-01-12 22:56:44 +03:00
|
|
|
if (!*inc) {
|
2009-02-24 18:30:28 +03:00
|
|
|
read_lock_irqsave(&rs->rs_recv_lock, flags);
|
|
|
|
if (!list_empty(&rs->rs_recv_queue)) {
|
|
|
|
*inc = list_entry(rs->rs_recv_queue.next,
|
|
|
|
struct rds_incoming,
|
|
|
|
i_item);
|
|
|
|
rds_inc_addref(*inc);
|
|
|
|
}
|
|
|
|
read_unlock_irqrestore(&rs->rs_recv_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *inc != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rds_still_queued(struct rds_sock *rs, struct rds_incoming *inc,
|
|
|
|
int drop)
|
|
|
|
{
|
|
|
|
struct sock *sk = rds_rs_to_sk(rs);
|
|
|
|
int ret = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
write_lock_irqsave(&rs->rs_recv_lock, flags);
|
|
|
|
if (!list_empty(&inc->i_item)) {
|
|
|
|
ret = 1;
|
|
|
|
if (drop) {
|
|
|
|
/* XXX make sure this i_conn is reliable */
|
|
|
|
rds_recv_rcvbuf_delta(rs, sk, inc->i_conn->c_lcong,
|
|
|
|
-be32_to_cpu(inc->i_hdr.h_len),
|
|
|
|
inc->i_hdr.h_dport);
|
|
|
|
list_del_init(&inc->i_item);
|
|
|
|
rds_inc_put(inc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
write_unlock_irqrestore(&rs->rs_recv_lock, flags);
|
|
|
|
|
|
|
|
rdsdebug("inc %p rs %p still %d dropped %d\n", inc, rs, ret, drop);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pull errors off the error queue.
|
|
|
|
* If msghdr is NULL, we will just purge the error queue.
|
|
|
|
*/
|
|
|
|
int rds_notify_queue_get(struct rds_sock *rs, struct msghdr *msghdr)
|
|
|
|
{
|
|
|
|
struct rds_notifier *notifier;
|
2010-08-16 07:25:00 +04:00
|
|
|
struct rds_rdma_notify cmsg = { 0 }; /* fill holes with zero */
|
2009-02-24 18:30:28 +03:00
|
|
|
unsigned int count = 0, max_messages = ~0U;
|
|
|
|
unsigned long flags;
|
|
|
|
LIST_HEAD(copy);
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* put_cmsg copies to user space and thus may sleep. We can't do this
|
|
|
|
* with rs_lock held, so first grab as many notifications as we can stuff
|
|
|
|
* in the user provided cmsg buffer. We don't try to copy more, to avoid
|
|
|
|
* losing notifications - except when the buffer is so small that it wouldn't
|
|
|
|
* even hold a single notification. Then we give him as much of this single
|
|
|
|
* msg as we can squeeze in, and set MSG_CTRUNC.
|
|
|
|
*/
|
|
|
|
if (msghdr) {
|
|
|
|
max_messages = msghdr->msg_controllen / CMSG_SPACE(sizeof(cmsg));
|
|
|
|
if (!max_messages)
|
|
|
|
max_messages = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&rs->rs_lock, flags);
|
|
|
|
while (!list_empty(&rs->rs_notify_queue) && count < max_messages) {
|
|
|
|
notifier = list_entry(rs->rs_notify_queue.next,
|
|
|
|
struct rds_notifier, n_list);
|
|
|
|
list_move(¬ifier->n_list, ©);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&rs->rs_lock, flags);
|
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (!list_empty(©)) {
|
|
|
|
notifier = list_entry(copy.next, struct rds_notifier, n_list);
|
|
|
|
|
|
|
|
if (msghdr) {
|
|
|
|
cmsg.user_token = notifier->n_user_token;
|
2010-01-12 21:53:05 +03:00
|
|
|
cmsg.status = notifier->n_status;
|
2009-02-24 18:30:28 +03:00
|
|
|
|
|
|
|
err = put_cmsg(msghdr, SOL_RDS, RDS_CMSG_RDMA_STATUS,
|
2010-01-12 21:53:05 +03:00
|
|
|
sizeof(cmsg), &cmsg);
|
2009-02-24 18:30:28 +03:00
|
|
|
if (err)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_del_init(¬ifier->n_list);
|
|
|
|
kfree(notifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we bailed out because of an error in put_cmsg,
|
|
|
|
* we may be left with one or more notifications that we
|
|
|
|
* didn't process. Return them to the head of the list. */
|
|
|
|
if (!list_empty(©)) {
|
|
|
|
spin_lock_irqsave(&rs->rs_lock, flags);
|
|
|
|
list_splice(©, &rs->rs_notify_queue);
|
|
|
|
spin_unlock_irqrestore(&rs->rs_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Queue a congestion notification
|
|
|
|
*/
|
|
|
|
static int rds_notify_cong(struct rds_sock *rs, struct msghdr *msghdr)
|
|
|
|
{
|
|
|
|
uint64_t notify = rs->rs_cong_notify;
|
|
|
|
unsigned long flags;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = put_cmsg(msghdr, SOL_RDS, RDS_CMSG_CONG_UPDATE,
|
|
|
|
sizeof(notify), ¬ify);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&rs->rs_lock, flags);
|
|
|
|
rs->rs_cong_notify &= ~notify;
|
|
|
|
spin_unlock_irqrestore(&rs->rs_lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive any control messages.
|
|
|
|
*/
|
2016-03-02 02:20:43 +03:00
|
|
|
static int rds_cmsg_recv(struct rds_incoming *inc, struct msghdr *msg,
|
|
|
|
struct rds_sock *rs)
|
2009-02-24 18:30:28 +03:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2019-08-23 17:03:18 +03:00
|
|
|
if (inc->i_usercopy.rdma_cookie) {
|
2009-02-24 18:30:28 +03:00
|
|
|
ret = put_cmsg(msg, SOL_RDS, RDS_CMSG_RDMA_DEST,
|
2019-08-23 17:03:18 +03:00
|
|
|
sizeof(inc->i_usercopy.rdma_cookie),
|
|
|
|
&inc->i_usercopy.rdma_cookie);
|
2009-02-24 18:30:28 +03:00
|
|
|
if (ret)
|
2016-07-05 08:35:15 +03:00
|
|
|
goto out;
|
2009-02-24 18:30:28 +03:00
|
|
|
}
|
|
|
|
|
2019-08-23 17:03:18 +03:00
|
|
|
if ((inc->i_usercopy.rx_tstamp != 0) &&
|
2016-03-02 02:20:43 +03:00
|
|
|
sock_flag(rds_rs_to_sk(rs), SOCK_RCVTSTAMP)) {
|
2019-08-23 17:03:18 +03:00
|
|
|
struct __kernel_old_timeval tv =
|
|
|
|
ns_to_kernel_old_timeval(inc->i_usercopy.rx_tstamp);
|
2019-02-02 18:34:50 +03:00
|
|
|
|
|
|
|
if (!sock_flag(rds_rs_to_sk(rs), SOCK_TSTAMP_NEW)) {
|
|
|
|
ret = put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP_OLD,
|
|
|
|
sizeof(tv), &tv);
|
|
|
|
} else {
|
|
|
|
struct __kernel_sock_timeval sk_tv;
|
|
|
|
|
|
|
|
sk_tv.tv_sec = tv.tv_sec;
|
|
|
|
sk_tv.tv_usec = tv.tv_usec;
|
|
|
|
|
|
|
|
ret = put_cmsg(msg, SOL_SOCKET, SO_TIMESTAMP_NEW,
|
|
|
|
sizeof(sk_tv), &sk_tv);
|
|
|
|
}
|
|
|
|
|
2016-03-02 02:20:43 +03:00
|
|
|
if (ret)
|
2016-07-05 08:35:15 +03:00
|
|
|
goto out;
|
2016-03-02 02:20:43 +03:00
|
|
|
}
|
|
|
|
|
2016-07-05 08:35:15 +03:00
|
|
|
if (rs->rs_rx_traces) {
|
|
|
|
struct rds_cmsg_rx_trace t;
|
|
|
|
int i, j;
|
|
|
|
|
2018-05-03 00:53:39 +03:00
|
|
|
memset(&t, 0, sizeof(t));
|
2016-07-05 08:35:15 +03:00
|
|
|
inc->i_rx_lat_trace[RDS_MSG_RX_CMSG] = local_clock();
|
|
|
|
t.rx_traces = rs->rs_rx_traces;
|
|
|
|
for (i = 0; i < rs->rs_rx_traces; i++) {
|
|
|
|
j = rs->rs_rx_trace[i];
|
|
|
|
t.rx_trace_pos[i] = j;
|
|
|
|
t.rx_trace[i] = inc->i_rx_lat_trace[j + 1] -
|
|
|
|
inc->i_rx_lat_trace[j];
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = put_cmsg(msg, SOL_RDS, RDS_CMSG_RXPATH_LATENCY,
|
|
|
|
sizeof(t), &t);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
2009-02-24 18:30:28 +03:00
|
|
|
}
|
|
|
|
|
2018-02-27 20:52:43 +03:00
|
|
|
static bool rds_recvmsg_zcookie(struct rds_sock *rs, struct msghdr *msg)
|
|
|
|
{
|
2018-03-06 18:22:34 +03:00
|
|
|
struct rds_msg_zcopy_queue *q = &rs->rs_zcookie_queue;
|
|
|
|
struct rds_msg_zcopy_info *info = NULL;
|
2018-02-27 20:52:43 +03:00
|
|
|
struct rds_zcopy_cookies *done;
|
2018-03-06 18:22:34 +03:00
|
|
|
unsigned long flags;
|
2018-02-27 20:52:43 +03:00
|
|
|
|
|
|
|
if (!msg->msg_control)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!sock_flag(rds_rs_to_sk(rs), SOCK_ZEROCOPY) ||
|
|
|
|
msg->msg_controllen < CMSG_SPACE(sizeof(*done)))
|
|
|
|
return false;
|
|
|
|
|
2018-03-06 18:22:34 +03:00
|
|
|
spin_lock_irqsave(&q->lock, flags);
|
|
|
|
if (!list_empty(&q->zcookie_head)) {
|
|
|
|
info = list_entry(q->zcookie_head.next,
|
|
|
|
struct rds_msg_zcopy_info, rs_zcookie_next);
|
|
|
|
list_del(&info->rs_zcookie_next);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&q->lock, flags);
|
|
|
|
if (!info)
|
2018-02-27 20:52:43 +03:00
|
|
|
return false;
|
2018-03-06 18:22:34 +03:00
|
|
|
done = &info->zcookies;
|
2018-02-27 20:52:43 +03:00
|
|
|
if (put_cmsg(msg, SOL_RDS, RDS_CMSG_ZCOPY_COMPLETION, sizeof(*done),
|
|
|
|
done)) {
|
2018-03-06 18:22:34 +03:00
|
|
|
spin_lock_irqsave(&q->lock, flags);
|
|
|
|
list_add(&info->rs_zcookie_next, &q->zcookie_head);
|
|
|
|
spin_unlock_irqrestore(&q->lock, flags);
|
2018-02-27 20:52:43 +03:00
|
|
|
return false;
|
|
|
|
}
|
2018-03-06 18:22:34 +03:00
|
|
|
kfree(info);
|
2018-02-27 20:52:43 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-02 10:37:48 +03:00
|
|
|
int rds_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
|
|
|
|
int msg_flags)
|
2009-02-24 18:30:28 +03:00
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
struct rds_sock *rs = rds_sk_to_rs(sk);
|
|
|
|
long timeo;
|
|
|
|
int ret = 0, nonblock = msg_flags & MSG_DONTWAIT;
|
2018-07-24 06:51:21 +03:00
|
|
|
DECLARE_SOCKADDR(struct sockaddr_in6 *, sin6, msg->msg_name);
|
2014-01-18 01:53:15 +04:00
|
|
|
DECLARE_SOCKADDR(struct sockaddr_in *, sin, msg->msg_name);
|
2009-02-24 18:30:28 +03:00
|
|
|
struct rds_incoming *inc = NULL;
|
|
|
|
|
|
|
|
/* udp_recvmsg()->sock_recvtimeo() gets away without locking too.. */
|
|
|
|
timeo = sock_rcvtimeo(sk, nonblock);
|
|
|
|
|
|
|
|
rdsdebug("size %zu flags 0x%x timeo %ld\n", size, msg_flags, timeo);
|
|
|
|
|
|
|
|
if (msg_flags & MSG_OOB)
|
|
|
|
goto out;
|
2018-02-15 21:49:35 +03:00
|
|
|
if (msg_flags & MSG_ERRQUEUE)
|
|
|
|
return sock_recv_errqueue(sk, msg, size, SOL_IP, IP_RECVERR);
|
2009-02-24 18:30:28 +03:00
|
|
|
|
2009-07-17 17:13:32 +04:00
|
|
|
while (1) {
|
|
|
|
/* If there are pending notifications, do those - and nothing else */
|
|
|
|
if (!list_empty(&rs->rs_notify_queue)) {
|
|
|
|
ret = rds_notify_queue_get(rs, msg);
|
|
|
|
break;
|
|
|
|
}
|
2009-02-24 18:30:28 +03:00
|
|
|
|
2009-07-17 17:13:32 +04:00
|
|
|
if (rs->rs_cong_notify) {
|
|
|
|
ret = rds_notify_cong(rs, msg);
|
|
|
|
break;
|
|
|
|
}
|
2009-02-24 18:30:28 +03:00
|
|
|
|
|
|
|
if (!rds_next_incoming(rs, &inc)) {
|
|
|
|
if (nonblock) {
|
2018-02-27 20:52:43 +03:00
|
|
|
bool reaped = rds_recvmsg_zcookie(rs, msg);
|
|
|
|
|
|
|
|
ret = reaped ? 0 : -EAGAIN;
|
2009-02-24 18:30:28 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-20 17:03:51 +04:00
|
|
|
timeo = wait_event_interruptible_timeout(*sk_sleep(sk),
|
2009-11-30 03:55:45 +03:00
|
|
|
(!list_empty(&rs->rs_notify_queue) ||
|
|
|
|
rs->rs_cong_notify ||
|
|
|
|
rds_next_incoming(rs, &inc)), timeo);
|
2009-02-24 18:30:28 +03:00
|
|
|
rdsdebug("recvmsg woke inc %p timeo %ld\n", inc,
|
|
|
|
timeo);
|
|
|
|
if (timeo > 0 || timeo == MAX_SCHEDULE_TIMEOUT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ret = timeo;
|
|
|
|
if (ret == 0)
|
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-07-24 06:51:21 +03:00
|
|
|
rdsdebug("copying inc %p from %pI6c:%u to user\n", inc,
|
2009-02-24 18:30:28 +03:00
|
|
|
&inc->i_conn->c_faddr,
|
|
|
|
ntohs(inc->i_hdr.h_sport));
|
2014-11-24 18:42:55 +03:00
|
|
|
ret = inc->i_conn->c_trans->inc_copy_to_user(inc, &msg->msg_iter);
|
2009-02-24 18:30:28 +03:00
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if the message we just copied isn't at the head of the
|
|
|
|
* recv queue then someone else raced us to return it, try
|
|
|
|
* to get the next message.
|
|
|
|
*/
|
|
|
|
if (!rds_still_queued(rs, inc, !(msg_flags & MSG_PEEK))) {
|
|
|
|
rds_inc_put(inc);
|
|
|
|
inc = NULL;
|
|
|
|
rds_stats_inc(s_recv_deliver_raced);
|
2017-04-13 06:09:32 +03:00
|
|
|
iov_iter_revert(&msg->msg_iter, ret);
|
2009-02-24 18:30:28 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < be32_to_cpu(inc->i_hdr.h_len)) {
|
|
|
|
if (msg_flags & MSG_TRUNC)
|
|
|
|
ret = be32_to_cpu(inc->i_hdr.h_len);
|
|
|
|
msg->msg_flags |= MSG_TRUNC;
|
|
|
|
}
|
|
|
|
|
2016-03-02 02:20:43 +03:00
|
|
|
if (rds_cmsg_recv(inc, msg, rs)) {
|
2009-02-24 18:30:28 +03:00
|
|
|
ret = -EFAULT;
|
|
|
|
goto out;
|
|
|
|
}
|
2018-02-27 20:52:43 +03:00
|
|
|
rds_recvmsg_zcookie(rs, msg);
|
2009-02-24 18:30:28 +03:00
|
|
|
|
|
|
|
rds_stats_inc(s_recv_delivered);
|
|
|
|
|
2018-07-24 06:51:21 +03:00
|
|
|
if (msg->msg_name) {
|
|
|
|
if (ipv6_addr_v4mapped(&inc->i_saddr)) {
|
|
|
|
sin = (struct sockaddr_in *)msg->msg_name;
|
|
|
|
|
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
sin->sin_port = inc->i_hdr.h_sport;
|
|
|
|
sin->sin_addr.s_addr =
|
|
|
|
inc->i_saddr.s6_addr32[3];
|
|
|
|
memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
|
|
|
|
msg->msg_namelen = sizeof(*sin);
|
|
|
|
} else {
|
|
|
|
sin6 = (struct sockaddr_in6 *)msg->msg_name;
|
|
|
|
|
|
|
|
sin6->sin6_family = AF_INET6;
|
|
|
|
sin6->sin6_port = inc->i_hdr.h_sport;
|
|
|
|
sin6->sin6_addr = inc->i_saddr;
|
|
|
|
sin6->sin6_flowinfo = 0;
|
|
|
|
sin6->sin6_scope_id = rs->rs_bound_scope_id;
|
|
|
|
msg->msg_namelen = sizeof(*sin6);
|
|
|
|
}
|
2009-02-24 18:30:28 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inc)
|
|
|
|
rds_inc_put(inc);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The socket is being shut down and we're asked to drop messages that were
|
|
|
|
* queued for recvmsg. The caller has unbound the socket so the receive path
|
|
|
|
* won't queue any more incoming fragments or messages on the socket.
|
|
|
|
*/
|
|
|
|
void rds_clear_recv_queue(struct rds_sock *rs)
|
|
|
|
{
|
|
|
|
struct sock *sk = rds_rs_to_sk(rs);
|
|
|
|
struct rds_incoming *inc, *tmp;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
write_lock_irqsave(&rs->rs_recv_lock, flags);
|
|
|
|
list_for_each_entry_safe(inc, tmp, &rs->rs_recv_queue, i_item) {
|
|
|
|
rds_recv_rcvbuf_delta(rs, sk, inc->i_conn->c_lcong,
|
|
|
|
-be32_to_cpu(inc->i_hdr.h_len),
|
|
|
|
inc->i_hdr.h_dport);
|
|
|
|
list_del_init(&inc->i_item);
|
|
|
|
rds_inc_put(inc);
|
|
|
|
}
|
|
|
|
write_unlock_irqrestore(&rs->rs_recv_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* inc->i_saddr isn't used here because it is only set in the receive
|
|
|
|
* path.
|
|
|
|
*/
|
|
|
|
void rds_inc_info_copy(struct rds_incoming *inc,
|
|
|
|
struct rds_info_iterator *iter,
|
|
|
|
__be32 saddr, __be32 daddr, int flip)
|
|
|
|
{
|
|
|
|
struct rds_info_message minfo;
|
|
|
|
|
|
|
|
minfo.seq = be64_to_cpu(inc->i_hdr.h_sequence);
|
|
|
|
minfo.len = be32_to_cpu(inc->i_hdr.h_len);
|
2018-10-24 06:21:14 +03:00
|
|
|
minfo.tos = inc->i_conn->c_tos;
|
2009-02-24 18:30:28 +03:00
|
|
|
|
|
|
|
if (flip) {
|
|
|
|
minfo.laddr = daddr;
|
|
|
|
minfo.faddr = saddr;
|
|
|
|
minfo.lport = inc->i_hdr.h_dport;
|
|
|
|
minfo.fport = inc->i_hdr.h_sport;
|
|
|
|
} else {
|
|
|
|
minfo.laddr = saddr;
|
|
|
|
minfo.faddr = daddr;
|
|
|
|
minfo.lport = inc->i_hdr.h_sport;
|
|
|
|
minfo.fport = inc->i_hdr.h_dport;
|
|
|
|
}
|
|
|
|
|
2016-06-02 11:11:20 +03:00
|
|
|
minfo.flags = 0;
|
|
|
|
|
2009-02-24 18:30:28 +03:00
|
|
|
rds_info_copy(iter, &minfo, sizeof(minfo));
|
|
|
|
}
|
2018-07-24 06:51:23 +03:00
|
|
|
|
2018-07-31 08:48:42 +03:00
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
2018-07-24 06:51:23 +03:00
|
|
|
void rds6_inc_info_copy(struct rds_incoming *inc,
|
|
|
|
struct rds_info_iterator *iter,
|
|
|
|
struct in6_addr *saddr, struct in6_addr *daddr,
|
|
|
|
int flip)
|
|
|
|
{
|
|
|
|
struct rds6_info_message minfo6;
|
|
|
|
|
|
|
|
minfo6.seq = be64_to_cpu(inc->i_hdr.h_sequence);
|
|
|
|
minfo6.len = be32_to_cpu(inc->i_hdr.h_len);
|
2019-08-26 12:39:12 +03:00
|
|
|
minfo6.tos = inc->i_conn->c_tos;
|
2018-07-24 06:51:23 +03:00
|
|
|
|
|
|
|
if (flip) {
|
|
|
|
minfo6.laddr = *daddr;
|
|
|
|
minfo6.faddr = *saddr;
|
|
|
|
minfo6.lport = inc->i_hdr.h_dport;
|
|
|
|
minfo6.fport = inc->i_hdr.h_sport;
|
|
|
|
} else {
|
|
|
|
minfo6.laddr = *saddr;
|
|
|
|
minfo6.faddr = *daddr;
|
|
|
|
minfo6.lport = inc->i_hdr.h_sport;
|
|
|
|
minfo6.fport = inc->i_hdr.h_dport;
|
|
|
|
}
|
|
|
|
|
2019-08-26 12:39:12 +03:00
|
|
|
minfo6.flags = 0;
|
|
|
|
|
2018-07-24 06:51:23 +03:00
|
|
|
rds_info_copy(iter, &minfo6, sizeof(minfo6));
|
|
|
|
}
|
2018-07-31 08:48:42 +03:00
|
|
|
#endif
|