2009-02-24 23:30:34 +08:00
|
|
|
/*
|
2019-10-03 12:11:08 +08:00
|
|
|
* Copyright (c) 2006, 2019 Oracle and/or its affiliates. All rights reserved.
|
2009-02-24 23:30:34 +08: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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-02-24 23:30:34 +08:00
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <rdma/rdma_cm.h>
|
|
|
|
|
2016-06-14 00:44:26 +08:00
|
|
|
#include "rds_single_path.h"
|
2009-02-24 23:30:34 +08:00
|
|
|
#include "rds.h"
|
|
|
|
#include "ib.h"
|
|
|
|
|
|
|
|
static struct kmem_cache *rds_ib_incoming_slab;
|
|
|
|
static struct kmem_cache *rds_ib_frag_slab;
|
|
|
|
static atomic_t rds_ib_allocation = ATOMIC_INIT(0);
|
|
|
|
|
|
|
|
void rds_ib_recv_init_ring(struct rds_ib_connection *ic)
|
|
|
|
{
|
|
|
|
struct rds_ib_recv_work *recv;
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
for (i = 0, recv = ic->i_recvs; i < ic->i_recv_ring.w_nr; i++, recv++) {
|
|
|
|
struct ib_sge *sge;
|
|
|
|
|
|
|
|
recv->r_ibinc = NULL;
|
|
|
|
recv->r_frag = NULL;
|
|
|
|
|
|
|
|
recv->r_wr.next = NULL;
|
|
|
|
recv->r_wr.wr_id = i;
|
|
|
|
recv->r_wr.sg_list = recv->r_sge;
|
|
|
|
recv->r_wr.num_sge = RDS_IB_RECV_SGE;
|
|
|
|
|
2010-01-14 08:32:24 +08:00
|
|
|
sge = &recv->r_sge[0];
|
2019-10-03 12:11:08 +08:00
|
|
|
sge->addr = ic->i_recv_hdrs_dma[i];
|
2009-02-24 23:30:34 +08:00
|
|
|
sge->length = sizeof(struct rds_header);
|
2015-07-31 07:22:26 +08:00
|
|
|
sge->lkey = ic->i_pd->local_dma_lkey;
|
2010-01-14 08:32:24 +08:00
|
|
|
|
|
|
|
sge = &recv->r_sge[1];
|
|
|
|
sge->addr = 0;
|
|
|
|
sge->length = RDS_FRAG_SIZE;
|
2015-07-31 07:22:26 +08:00
|
|
|
sge->lkey = ic->i_pd->local_dma_lkey;
|
2009-02-24 23:30:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-27 13:05:37 +08:00
|
|
|
/*
|
|
|
|
* The entire 'from' list, including the from element itself, is put on
|
|
|
|
* to the tail of the 'to' list.
|
|
|
|
*/
|
|
|
|
static void list_splice_entire_tail(struct list_head *from,
|
|
|
|
struct list_head *to)
|
|
|
|
{
|
|
|
|
struct list_head *from_last = from->prev;
|
|
|
|
|
|
|
|
list_splice_tail(from_last, to);
|
|
|
|
list_add_tail(from_last, to);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rds_ib_cache_xfer_to_ready(struct rds_ib_refill_cache *cache)
|
|
|
|
{
|
|
|
|
struct list_head *tmp;
|
|
|
|
|
|
|
|
tmp = xchg(&cache->xfer, NULL);
|
|
|
|
if (tmp) {
|
|
|
|
if (cache->ready)
|
|
|
|
list_splice_entire_tail(tmp, cache->ready);
|
|
|
|
else
|
|
|
|
cache->ready = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-31 13:48:41 +08:00
|
|
|
static int rds_ib_recv_alloc_cache(struct rds_ib_refill_cache *cache, gfp_t gfp)
|
2010-05-27 13:05:37 +08:00
|
|
|
{
|
|
|
|
struct rds_ib_cache_head *head;
|
|
|
|
int cpu;
|
|
|
|
|
2018-07-31 13:48:41 +08:00
|
|
|
cache->percpu = alloc_percpu_gfp(struct rds_ib_cache_head, gfp);
|
2010-05-27 13:05:37 +08:00
|
|
|
if (!cache->percpu)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
|
|
head = per_cpu_ptr(cache->percpu, cpu);
|
|
|
|
head->first = NULL;
|
|
|
|
head->count = 0;
|
|
|
|
}
|
|
|
|
cache->xfer = NULL;
|
|
|
|
cache->ready = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-31 13:48:41 +08:00
|
|
|
int rds_ib_recv_alloc_caches(struct rds_ib_connection *ic, gfp_t gfp)
|
2010-05-27 13:05:37 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2018-07-31 13:48:41 +08:00
|
|
|
ret = rds_ib_recv_alloc_cache(&ic->i_cache_incs, gfp);
|
2010-05-27 13:05:37 +08:00
|
|
|
if (!ret) {
|
2018-07-31 13:48:41 +08:00
|
|
|
ret = rds_ib_recv_alloc_cache(&ic->i_cache_frags, gfp);
|
2010-05-27 13:05:37 +08:00
|
|
|
if (ret)
|
|
|
|
free_percpu(ic->i_cache_incs.percpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rds_ib_cache_splice_all_lists(struct rds_ib_refill_cache *cache,
|
|
|
|
struct list_head *caller_list)
|
|
|
|
{
|
|
|
|
struct rds_ib_cache_head *head;
|
|
|
|
int cpu;
|
|
|
|
|
|
|
|
for_each_possible_cpu(cpu) {
|
|
|
|
head = per_cpu_ptr(cache->percpu, cpu);
|
|
|
|
if (head->first) {
|
|
|
|
list_splice_entire_tail(head->first, caller_list);
|
|
|
|
head->first = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cache->ready) {
|
|
|
|
list_splice_entire_tail(cache->ready, caller_list);
|
|
|
|
cache->ready = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void rds_ib_recv_free_caches(struct rds_ib_connection *ic)
|
|
|
|
{
|
|
|
|
struct rds_ib_incoming *inc;
|
|
|
|
struct rds_ib_incoming *inc_tmp;
|
|
|
|
struct rds_page_frag *frag;
|
|
|
|
struct rds_page_frag *frag_tmp;
|
|
|
|
LIST_HEAD(list);
|
|
|
|
|
|
|
|
rds_ib_cache_xfer_to_ready(&ic->i_cache_incs);
|
|
|
|
rds_ib_cache_splice_all_lists(&ic->i_cache_incs, &list);
|
|
|
|
free_percpu(ic->i_cache_incs.percpu);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(inc, inc_tmp, &list, ii_cache_entry) {
|
|
|
|
list_del(&inc->ii_cache_entry);
|
|
|
|
WARN_ON(!list_empty(&inc->ii_frags));
|
|
|
|
kmem_cache_free(rds_ib_incoming_slab, inc);
|
net: rds: fix memory leak when unload rds_rdma
When KASAN is enabled, after several rds connections are
created, then "rmmod rds_rdma" is run. The following will
appear.
"
BUG rds_ib_incoming (Not tainted): Objects remaining
in rds_ib_incoming on __kmem_cache_shutdown()
Call Trace:
dump_stack+0x71/0xab
slab_err+0xad/0xd0
__kmem_cache_shutdown+0x17d/0x370
shutdown_cache+0x17/0x130
kmem_cache_destroy+0x1df/0x210
rds_ib_recv_exit+0x11/0x20 [rds_rdma]
rds_ib_exit+0x7a/0x90 [rds_rdma]
__x64_sys_delete_module+0x224/0x2c0
? __ia32_sys_delete_module+0x2c0/0x2c0
do_syscall_64+0x73/0x190
entry_SYSCALL_64_after_hwframe+0x44/0xa9
"
This is rds connection memory leak. The root cause is:
When "rmmod rds_rdma" is run, rds_ib_remove_one will call
rds_ib_dev_shutdown to drop the rds connections.
rds_ib_dev_shutdown will call rds_conn_drop to drop rds
connections as below.
"
rds_conn_path_drop(&conn->c_path[0], false);
"
In the above, destroy is set to false.
void rds_conn_path_drop(struct rds_conn_path *cp, bool destroy)
{
atomic_set(&cp->cp_state, RDS_CONN_ERROR);
rcu_read_lock();
if (!destroy && rds_destroy_pending(cp->cp_conn)) {
rcu_read_unlock();
return;
}
queue_work(rds_wq, &cp->cp_down_w);
rcu_read_unlock();
}
In the above function, destroy is set to false. rds_destroy_pending
is called. This does not move rds connections to ib_nodev_conns.
So destroy is set to true to move rds connections to ib_nodev_conns.
In rds_ib_unregister_client, flush_workqueue is called to make rds_wq
finsh shutdown rds connections. The function rds_ib_destroy_nodev_conns
is called to shutdown rds connections finally.
Then rds_ib_recv_exit is called to destroy slab.
void rds_ib_recv_exit(void)
{
kmem_cache_destroy(rds_ib_incoming_slab);
kmem_cache_destroy(rds_ib_frag_slab);
}
The above slab memory leak will not occur again.
>From tests,
256 rds connections
[root@ca-dev14 ~]# time rmmod rds_rdma
real 0m16.522s
user 0m0.000s
sys 0m8.152s
512 rds connections
[root@ca-dev14 ~]# time rmmod rds_rdma
real 0m32.054s
user 0m0.000s
sys 0m15.568s
To rmmod rds_rdma with 256 rds connections, about 16 seconds are needed.
And with 512 rds connections, about 32 seconds are needed.
>From ftrace, when one rds connection is destroyed,
"
19) | rds_conn_destroy [rds]() {
19) 7.782 us | rds_conn_path_drop [rds]();
15) | rds_shutdown_worker [rds]() {
15) | rds_conn_shutdown [rds]() {
15) 1.651 us | rds_send_path_reset [rds]();
15) 7.195 us | }
15) + 11.434 us | }
19) 2.285 us | rds_cong_remove_conn [rds]();
19) * 24062.76 us | }
"
So if many rds connections will be destroyed, this function
rds_ib_destroy_nodev_conns uses most of time.
Suggested-by: Håkon Bugge <haakon.bugge@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun.zhu@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-03 20:48:19 +08:00
|
|
|
atomic_dec(&rds_ib_allocation);
|
2010-05-27 13:05:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rds_ib_cache_xfer_to_ready(&ic->i_cache_frags);
|
|
|
|
rds_ib_cache_splice_all_lists(&ic->i_cache_frags, &list);
|
|
|
|
free_percpu(ic->i_cache_frags.percpu);
|
|
|
|
|
|
|
|
list_for_each_entry_safe(frag, frag_tmp, &list, f_cache_entry) {
|
|
|
|
list_del(&frag->f_cache_entry);
|
|
|
|
WARN_ON(!list_empty(&frag->f_item));
|
|
|
|
kmem_cache_free(rds_ib_frag_slab, frag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fwd decl */
|
|
|
|
static void rds_ib_recv_cache_put(struct list_head *new_item,
|
|
|
|
struct rds_ib_refill_cache *cache);
|
|
|
|
static struct list_head *rds_ib_recv_cache_get(struct rds_ib_refill_cache *cache);
|
|
|
|
|
|
|
|
|
|
|
|
/* Recycle frag and attached recv buffer f_sg */
|
|
|
|
static void rds_ib_frag_free(struct rds_ib_connection *ic,
|
|
|
|
struct rds_page_frag *frag)
|
|
|
|
{
|
|
|
|
rdsdebug("frag %p page %p\n", frag, sg_page(&frag->f_sg));
|
|
|
|
|
|
|
|
rds_ib_recv_cache_put(&frag->f_cache_entry, &ic->i_cache_frags);
|
2016-07-10 08:14:02 +08:00
|
|
|
atomic_add(RDS_FRAG_SIZE / SZ_1K, &ic->i_cache_allocs);
|
|
|
|
rds_ib_stats_add(s_ib_recv_added_to_cache, RDS_FRAG_SIZE);
|
2010-05-27 13:05:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Recycle inc after freeing attached frags */
|
|
|
|
void rds_ib_inc_free(struct rds_incoming *inc)
|
|
|
|
{
|
|
|
|
struct rds_ib_incoming *ibinc;
|
|
|
|
struct rds_page_frag *frag;
|
|
|
|
struct rds_page_frag *pos;
|
|
|
|
struct rds_ib_connection *ic = inc->i_conn->c_transport_data;
|
|
|
|
|
|
|
|
ibinc = container_of(inc, struct rds_ib_incoming, ii_inc);
|
|
|
|
|
|
|
|
/* Free attached frags */
|
|
|
|
list_for_each_entry_safe(frag, pos, &ibinc->ii_frags, f_item) {
|
|
|
|
list_del_init(&frag->f_item);
|
|
|
|
rds_ib_frag_free(ic, frag);
|
|
|
|
}
|
|
|
|
BUG_ON(!list_empty(&ibinc->ii_frags));
|
|
|
|
|
|
|
|
rdsdebug("freeing ibinc %p inc %p\n", ibinc, inc);
|
|
|
|
rds_ib_recv_cache_put(&ibinc->ii_cache_entry, &ic->i_cache_incs);
|
|
|
|
}
|
|
|
|
|
2009-02-24 23:30:34 +08:00
|
|
|
static void rds_ib_recv_clear_one(struct rds_ib_connection *ic,
|
|
|
|
struct rds_ib_recv_work *recv)
|
|
|
|
{
|
|
|
|
if (recv->r_ibinc) {
|
|
|
|
rds_inc_put(&recv->r_ibinc->ii_inc);
|
|
|
|
recv->r_ibinc = NULL;
|
|
|
|
}
|
|
|
|
if (recv->r_frag) {
|
2010-05-26 02:20:09 +08:00
|
|
|
ib_dma_unmap_sg(ic->i_cm_id->device, &recv->r_frag->f_sg, 1, DMA_FROM_DEVICE);
|
2010-05-27 13:05:37 +08:00
|
|
|
rds_ib_frag_free(ic, recv->r_frag);
|
2009-02-24 23:30:34 +08:00
|
|
|
recv->r_frag = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void rds_ib_recv_clear_ring(struct rds_ib_connection *ic)
|
|
|
|
{
|
|
|
|
u32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < ic->i_recv_ring.w_nr; i++)
|
|
|
|
rds_ib_recv_clear_one(ic, &ic->i_recvs[i]);
|
|
|
|
}
|
|
|
|
|
2010-05-27 12:45:06 +08:00
|
|
|
static struct rds_ib_incoming *rds_ib_refill_one_inc(struct rds_ib_connection *ic,
|
|
|
|
gfp_t slab_mask)
|
2010-05-27 13:05:37 +08:00
|
|
|
{
|
|
|
|
struct rds_ib_incoming *ibinc;
|
|
|
|
struct list_head *cache_item;
|
|
|
|
int avail_allocs;
|
|
|
|
|
|
|
|
cache_item = rds_ib_recv_cache_get(&ic->i_cache_incs);
|
|
|
|
if (cache_item) {
|
|
|
|
ibinc = container_of(cache_item, struct rds_ib_incoming, ii_cache_entry);
|
|
|
|
} else {
|
|
|
|
avail_allocs = atomic_add_unless(&rds_ib_allocation,
|
|
|
|
1, rds_ib_sysctl_max_recv_allocation);
|
|
|
|
if (!avail_allocs) {
|
|
|
|
rds_ib_stats_inc(s_ib_rx_alloc_limit);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-05-27 12:45:06 +08:00
|
|
|
ibinc = kmem_cache_alloc(rds_ib_incoming_slab, slab_mask);
|
2010-05-27 13:05:37 +08:00
|
|
|
if (!ibinc) {
|
|
|
|
atomic_dec(&rds_ib_allocation);
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-07-10 08:14:02 +08:00
|
|
|
rds_ib_stats_inc(s_ib_rx_total_incs);
|
2010-05-27 13:05:37 +08:00
|
|
|
}
|
|
|
|
INIT_LIST_HEAD(&ibinc->ii_frags);
|
2018-07-24 11:51:21 +08:00
|
|
|
rds_inc_init(&ibinc->ii_inc, ic->conn, &ic->conn->c_faddr);
|
2010-05-27 13:05:37 +08:00
|
|
|
|
|
|
|
return ibinc;
|
|
|
|
}
|
|
|
|
|
2010-05-27 12:45:06 +08:00
|
|
|
static struct rds_page_frag *rds_ib_refill_one_frag(struct rds_ib_connection *ic,
|
|
|
|
gfp_t slab_mask, gfp_t page_mask)
|
2010-05-27 13:05:37 +08:00
|
|
|
{
|
|
|
|
struct rds_page_frag *frag;
|
|
|
|
struct list_head *cache_item;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
cache_item = rds_ib_recv_cache_get(&ic->i_cache_frags);
|
|
|
|
if (cache_item) {
|
|
|
|
frag = container_of(cache_item, struct rds_page_frag, f_cache_entry);
|
2016-07-10 08:14:02 +08:00
|
|
|
atomic_sub(RDS_FRAG_SIZE / SZ_1K, &ic->i_cache_allocs);
|
|
|
|
rds_ib_stats_add(s_ib_recv_added_to_cache, RDS_FRAG_SIZE);
|
2010-05-27 13:05:37 +08:00
|
|
|
} else {
|
2010-05-27 12:45:06 +08:00
|
|
|
frag = kmem_cache_alloc(rds_ib_frag_slab, slab_mask);
|
2010-05-27 13:05:37 +08:00
|
|
|
if (!frag)
|
|
|
|
return NULL;
|
|
|
|
|
2010-07-20 08:02:41 +08:00
|
|
|
sg_init_table(&frag->f_sg, 1);
|
2010-05-27 13:05:37 +08:00
|
|
|
ret = rds_page_remainder_alloc(&frag->f_sg,
|
2010-05-27 12:45:06 +08:00
|
|
|
RDS_FRAG_SIZE, page_mask);
|
2010-05-27 13:05:37 +08:00
|
|
|
if (ret) {
|
|
|
|
kmem_cache_free(rds_ib_frag_slab, frag);
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-07-10 08:14:02 +08:00
|
|
|
rds_ib_stats_inc(s_ib_rx_total_frags);
|
2010-05-27 13:05:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&frag->f_item);
|
|
|
|
|
|
|
|
return frag;
|
|
|
|
}
|
|
|
|
|
2009-02-24 23:30:34 +08:00
|
|
|
static int rds_ib_recv_refill_one(struct rds_connection *conn,
|
2015-08-23 06:45:26 +08:00
|
|
|
struct rds_ib_recv_work *recv, gfp_t gfp)
|
2009-02-24 23:30:34 +08:00
|
|
|
{
|
|
|
|
struct rds_ib_connection *ic = conn->c_transport_data;
|
|
|
|
struct ib_sge *sge;
|
|
|
|
int ret = -ENOMEM;
|
2020-10-07 05:31:37 +08:00
|
|
|
gfp_t slab_mask = gfp;
|
|
|
|
gfp_t page_mask = gfp;
|
2010-05-27 12:45:06 +08:00
|
|
|
|
2015-11-07 08:28:21 +08:00
|
|
|
if (gfp & __GFP_DIRECT_RECLAIM) {
|
2010-05-27 12:45:06 +08:00
|
|
|
slab_mask = GFP_KERNEL;
|
|
|
|
page_mask = GFP_HIGHUSER;
|
|
|
|
}
|
2009-02-24 23:30:34 +08:00
|
|
|
|
2010-05-27 13:05:37 +08:00
|
|
|
if (!ic->i_cache_incs.ready)
|
|
|
|
rds_ib_cache_xfer_to_ready(&ic->i_cache_incs);
|
|
|
|
if (!ic->i_cache_frags.ready)
|
|
|
|
rds_ib_cache_xfer_to_ready(&ic->i_cache_frags);
|
|
|
|
|
2010-05-25 11:28:49 +08:00
|
|
|
/*
|
|
|
|
* ibinc was taken from recv if recv contained the start of a message.
|
|
|
|
* recvs that were continuations will still have this allocated.
|
|
|
|
*/
|
2010-01-13 03:56:44 +08:00
|
|
|
if (!recv->r_ibinc) {
|
2010-05-27 12:45:06 +08:00
|
|
|
recv->r_ibinc = rds_ib_refill_one_inc(ic, slab_mask);
|
2010-05-27 13:05:37 +08:00
|
|
|
if (!recv->r_ibinc)
|
2009-02-24 23:30:34 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-05-25 11:28:49 +08:00
|
|
|
WARN_ON(recv->r_frag); /* leak! */
|
2010-05-27 12:45:06 +08:00
|
|
|
recv->r_frag = rds_ib_refill_one_frag(ic, slab_mask, page_mask);
|
2010-05-25 11:28:49 +08:00
|
|
|
if (!recv->r_frag)
|
|
|
|
goto out;
|
2009-02-24 23:30:34 +08:00
|
|
|
|
2010-05-25 11:12:41 +08:00
|
|
|
ret = ib_dma_map_sg(ic->i_cm_id->device, &recv->r_frag->f_sg,
|
|
|
|
1, DMA_FROM_DEVICE);
|
|
|
|
WARN_ON(ret != 1);
|
2009-02-24 23:30:34 +08:00
|
|
|
|
2010-01-14 08:32:24 +08:00
|
|
|
sge = &recv->r_sge[0];
|
2019-10-03 12:11:08 +08:00
|
|
|
sge->addr = ic->i_recv_hdrs_dma[recv - ic->i_recvs];
|
2009-02-24 23:30:34 +08:00
|
|
|
sge->length = sizeof(struct rds_header);
|
|
|
|
|
2010-01-14 08:32:24 +08:00
|
|
|
sge = &recv->r_sge[1];
|
2019-02-01 00:30:34 +08:00
|
|
|
sge->addr = sg_dma_address(&recv->r_frag->f_sg);
|
|
|
|
sge->length = sg_dma_len(&recv->r_frag->f_sg);
|
2009-02-24 23:30:34 +08:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-23 06:45:26 +08:00
|
|
|
static int acquire_refill(struct rds_connection *conn)
|
|
|
|
{
|
|
|
|
return test_and_set_bit(RDS_RECV_REFILL, &conn->c_flags) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release_refill(struct rds_connection *conn)
|
|
|
|
{
|
|
|
|
clear_bit(RDS_RECV_REFILL, &conn->c_flags);
|
|
|
|
|
|
|
|
/* We don't use wait_on_bit()/wake_up_bit() because our waking is in a
|
|
|
|
* hot path and finding waiters is very rare. We don't want to walk
|
|
|
|
* the system-wide hashed waitqueue buckets in the fast path only to
|
|
|
|
* almost never find waiters.
|
|
|
|
*/
|
|
|
|
if (waitqueue_active(&conn->c_waitq))
|
|
|
|
wake_up_all(&conn->c_waitq);
|
|
|
|
}
|
|
|
|
|
2009-02-24 23:30:34 +08:00
|
|
|
/*
|
|
|
|
* This tries to allocate and post unused work requests after making sure that
|
|
|
|
* they have all the allocations they need to queue received fragments into
|
2010-05-27 13:05:37 +08:00
|
|
|
* sockets.
|
2009-02-24 23:30:34 +08:00
|
|
|
*/
|
2015-08-23 06:45:26 +08:00
|
|
|
void rds_ib_recv_refill(struct rds_connection *conn, int prefill, gfp_t gfp)
|
2009-02-24 23:30:34 +08:00
|
|
|
{
|
|
|
|
struct rds_ib_connection *ic = conn->c_transport_data;
|
|
|
|
struct rds_ib_recv_work *recv;
|
|
|
|
unsigned int posted = 0;
|
|
|
|
int ret = 0;
|
2015-11-07 08:28:21 +08:00
|
|
|
bool can_wait = !!(gfp & __GFP_DIRECT_RECLAIM);
|
2012-02-04 00:07:54 +08:00
|
|
|
bool must_wake = false;
|
2009-02-24 23:30:34 +08:00
|
|
|
u32 pos;
|
|
|
|
|
2015-08-23 06:45:26 +08:00
|
|
|
/* the goal here is to just make sure that someone, somewhere
|
|
|
|
* is posting buffers. If we can't get the refill lock,
|
|
|
|
* let them do their thing
|
|
|
|
*/
|
|
|
|
if (!acquire_refill(conn))
|
|
|
|
return;
|
|
|
|
|
2009-11-30 08:55:45 +08:00
|
|
|
while ((prefill || rds_conn_up(conn)) &&
|
|
|
|
rds_ib_ring_alloc(&ic->i_recv_ring, 1, &pos)) {
|
2009-02-24 23:30:34 +08:00
|
|
|
if (pos >= ic->i_recv_ring.w_nr) {
|
|
|
|
printk(KERN_NOTICE "Argh - ring alloc returned pos=%u\n",
|
|
|
|
pos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
recv = &ic->i_recvs[pos];
|
2015-08-23 06:45:26 +08:00
|
|
|
ret = rds_ib_recv_refill_one(conn, recv, gfp);
|
2009-02-24 23:30:34 +08:00
|
|
|
if (ret) {
|
2012-02-04 00:07:54 +08:00
|
|
|
must_wake = true;
|
2009-02-24 23:30:34 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
rds: ib: Fix NULL pointer dereference in debug code
rds_ib_recv_refill() is a function that refills an IB receive
queue. It can be called from both the CQE handler (tasklet) and a
worker thread.
Just after the call to ib_post_recv(), a debug message is printed with
rdsdebug():
ret = ib_post_recv(ic->i_cm_id->qp, &recv->r_wr, &failed_wr);
rdsdebug("recv %p ibinc %p page %p addr %lu ret %d\n", recv,
recv->r_ibinc, sg_page(&recv->r_frag->f_sg),
(long) ib_sg_dma_address(
ic->i_cm_id->device,
&recv->r_frag->f_sg),
ret);
Now consider an invocation of rds_ib_recv_refill() from the worker
thread, which is preemptible. Further, assume that the worker thread
is preempted between the ib_post_recv() and rdsdebug() statements.
Then, if the preemption is due to a receive CQE event, the
rds_ib_recv_cqe_handler() will be invoked. This function processes
receive completions, including freeing up data structures, such as the
recv->r_frag.
In this scenario, rds_ib_recv_cqe_handler() will process the receive
WR posted above. That implies, that the recv->r_frag has been freed
before the above rdsdebug() statement has been executed. When it is
later executed, we will have a NULL pointer dereference:
[ 4088.068008] BUG: unable to handle kernel NULL pointer dereference at 0000000000000020
[ 4088.076754] IP: rds_ib_recv_refill+0x87/0x620 [rds_rdma]
[ 4088.082686] PGD 0 P4D 0
[ 4088.085515] Oops: 0000 [#1] SMP
[ 4088.089015] Modules linked in: rds_rdma(OE) rds(OE) rpcsec_gss_krb5(E) nfsv4(E) dns_resolver(E) nfs(E) fscache(E) mlx4_ib(E) ib_ipoib(E) rdma_ucm(E) ib_ucm(E) ib_uverbs(E) ib_umad(E) rdma_cm(E) ib_cm(E) iw_cm(E) ib_core(E) binfmt_misc(E) sb_edac(E) intel_powerclamp(E) coretemp(E) kvm_intel(E) kvm(E) irqbypass(E) crct10dif_pclmul(E) crc32_pclmul(E) ghash_clmulni_intel(E) pcbc(E) aesni_intel(E) crypto_simd(E) iTCO_wdt(E) glue_helper(E) iTCO_vendor_support(E) sg(E) cryptd(E) pcspkr(E) ipmi_si(E) ipmi_devintf(E) ipmi_msghandler(E) shpchp(E) ioatdma(E) i2c_i801(E) wmi(E) lpc_ich(E) mei_me(E) mei(E) mfd_core(E) nfsd(E) auth_rpcgss(E) nfs_acl(E) lockd(E) grace(E) sunrpc(E) ip_tables(E) ext4(E) mbcache(E) jbd2(E) fscrypto(E) mgag200(E) i2c_algo_bit(E) drm_kms_helper(E) syscopyarea(E) sysfillrect(E) sysimgblt(E)
[ 4088.168486] fb_sys_fops(E) ahci(E) ixgbe(E) libahci(E) ttm(E) mdio(E) ptp(E) pps_core(E) drm(E) sd_mod(E) libata(E) crc32c_intel(E) mlx4_core(E) i2c_core(E) dca(E) megaraid_sas(E) dm_mirror(E) dm_region_hash(E) dm_log(E) dm_mod(E) [last unloaded: rds]
[ 4088.193442] CPU: 20 PID: 1244 Comm: kworker/20:2 Tainted: G OE 4.14.0-rc7.master.20171105.ol7.x86_64 #1
[ 4088.205097] Hardware name: Oracle Corporation ORACLE SERVER X5-2L/ASM,MOBO TRAY,2U, BIOS 31110000 03/03/2017
[ 4088.216074] Workqueue: ib_cm cm_work_handler [ib_cm]
[ 4088.221614] task: ffff885fa11d0000 task.stack: ffffc9000e598000
[ 4088.228224] RIP: 0010:rds_ib_recv_refill+0x87/0x620 [rds_rdma]
[ 4088.234736] RSP: 0018:ffffc9000e59bb68 EFLAGS: 00010286
[ 4088.240568] RAX: 0000000000000000 RBX: ffffc9002115d050 RCX: ffffc9002115d050
[ 4088.248535] RDX: ffffffffa0521380 RSI: ffffffffa0522158 RDI: ffffffffa0525580
[ 4088.256498] RBP: ffffc9000e59bbf8 R08: 0000000000000005 R09: 0000000000000000
[ 4088.264465] R10: 0000000000000339 R11: 0000000000000001 R12: 0000000000000000
[ 4088.272433] R13: ffff885f8c9d8000 R14: ffffffff81a0a060 R15: ffff884676268000
[ 4088.280397] FS: 0000000000000000(0000) GS:ffff885fbec80000(0000) knlGS:0000000000000000
[ 4088.289434] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 4088.295846] CR2: 0000000000000020 CR3: 0000000001e09005 CR4: 00000000001606e0
[ 4088.303816] Call Trace:
[ 4088.306557] rds_ib_cm_connect_complete+0xe0/0x220 [rds_rdma]
[ 4088.312982] ? __dynamic_pr_debug+0x8c/0xb0
[ 4088.317664] ? __queue_work+0x142/0x3c0
[ 4088.321944] rds_rdma_cm_event_handler+0x19e/0x250 [rds_rdma]
[ 4088.328370] cma_ib_handler+0xcd/0x280 [rdma_cm]
[ 4088.333522] cm_process_work+0x25/0x120 [ib_cm]
[ 4088.338580] cm_work_handler+0xd6b/0x17aa [ib_cm]
[ 4088.343832] process_one_work+0x149/0x360
[ 4088.348307] worker_thread+0x4d/0x3e0
[ 4088.352397] kthread+0x109/0x140
[ 4088.355996] ? rescuer_thread+0x380/0x380
[ 4088.360467] ? kthread_park+0x60/0x60
[ 4088.364563] ret_from_fork+0x25/0x30
[ 4088.368548] Code: 48 89 45 90 48 89 45 98 eb 4d 0f 1f 44 00 00 48 8b 43 08 48 89 d9 48 c7 c2 80 13 52 a0 48 c7 c6 58 21 52 a0 48 c7 c7 80 55 52 a0 <4c> 8b 48 20 44 89 64 24 08 48 8b 40 30 49 83 e1 fc 48 89 04 24
[ 4088.389612] RIP: rds_ib_recv_refill+0x87/0x620 [rds_rdma] RSP: ffffc9000e59bb68
[ 4088.397772] CR2: 0000000000000020
[ 4088.401505] ---[ end trace fe922e6ccf004431 ]---
This bug was provoked by compiling rds out-of-tree with
EXTRA_CFLAGS="-DRDS_DEBUG -DDEBUG" and inserting an artificial delay
between the rdsdebug() and ib_ib_port_recv() statements:
/* XXX when can this fail? */
ret = ib_post_recv(ic->i_cm_id->qp, &recv->r_wr, &failed_wr);
+ if (can_wait)
+ usleep_range(1000, 5000);
rdsdebug("recv %p ibinc %p page %p addr %lu ret %d\n", recv,
recv->r_ibinc, sg_page(&recv->r_frag->f_sg),
(long) ib_sg_dma_address(
The fix is simply to move the rdsdebug() statement up before the
ib_post_recv() and remove the printing of ret, which is taken care of
anyway by the non-debug code.
Signed-off-by: Håkon Bugge <haakon.bugge@oracle.com>
Reviewed-by: Knut Omang <knut.omang@oracle.com>
Reviewed-by: Wei Lin Guay <wei.lin.guay@oracle.com>
Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-11-07 23:33:34 +08:00
|
|
|
rdsdebug("recv %p ibinc %p page %p addr %lu\n", recv,
|
2010-05-25 11:12:41 +08:00
|
|
|
recv->r_ibinc, sg_page(&recv->r_frag->f_sg),
|
2019-02-01 00:30:34 +08:00
|
|
|
(long)sg_dma_address(&recv->r_frag->f_sg));
|
rds: ib: Fix NULL pointer dereference in debug code
rds_ib_recv_refill() is a function that refills an IB receive
queue. It can be called from both the CQE handler (tasklet) and a
worker thread.
Just after the call to ib_post_recv(), a debug message is printed with
rdsdebug():
ret = ib_post_recv(ic->i_cm_id->qp, &recv->r_wr, &failed_wr);
rdsdebug("recv %p ibinc %p page %p addr %lu ret %d\n", recv,
recv->r_ibinc, sg_page(&recv->r_frag->f_sg),
(long) ib_sg_dma_address(
ic->i_cm_id->device,
&recv->r_frag->f_sg),
ret);
Now consider an invocation of rds_ib_recv_refill() from the worker
thread, which is preemptible. Further, assume that the worker thread
is preempted between the ib_post_recv() and rdsdebug() statements.
Then, if the preemption is due to a receive CQE event, the
rds_ib_recv_cqe_handler() will be invoked. This function processes
receive completions, including freeing up data structures, such as the
recv->r_frag.
In this scenario, rds_ib_recv_cqe_handler() will process the receive
WR posted above. That implies, that the recv->r_frag has been freed
before the above rdsdebug() statement has been executed. When it is
later executed, we will have a NULL pointer dereference:
[ 4088.068008] BUG: unable to handle kernel NULL pointer dereference at 0000000000000020
[ 4088.076754] IP: rds_ib_recv_refill+0x87/0x620 [rds_rdma]
[ 4088.082686] PGD 0 P4D 0
[ 4088.085515] Oops: 0000 [#1] SMP
[ 4088.089015] Modules linked in: rds_rdma(OE) rds(OE) rpcsec_gss_krb5(E) nfsv4(E) dns_resolver(E) nfs(E) fscache(E) mlx4_ib(E) ib_ipoib(E) rdma_ucm(E) ib_ucm(E) ib_uverbs(E) ib_umad(E) rdma_cm(E) ib_cm(E) iw_cm(E) ib_core(E) binfmt_misc(E) sb_edac(E) intel_powerclamp(E) coretemp(E) kvm_intel(E) kvm(E) irqbypass(E) crct10dif_pclmul(E) crc32_pclmul(E) ghash_clmulni_intel(E) pcbc(E) aesni_intel(E) crypto_simd(E) iTCO_wdt(E) glue_helper(E) iTCO_vendor_support(E) sg(E) cryptd(E) pcspkr(E) ipmi_si(E) ipmi_devintf(E) ipmi_msghandler(E) shpchp(E) ioatdma(E) i2c_i801(E) wmi(E) lpc_ich(E) mei_me(E) mei(E) mfd_core(E) nfsd(E) auth_rpcgss(E) nfs_acl(E) lockd(E) grace(E) sunrpc(E) ip_tables(E) ext4(E) mbcache(E) jbd2(E) fscrypto(E) mgag200(E) i2c_algo_bit(E) drm_kms_helper(E) syscopyarea(E) sysfillrect(E) sysimgblt(E)
[ 4088.168486] fb_sys_fops(E) ahci(E) ixgbe(E) libahci(E) ttm(E) mdio(E) ptp(E) pps_core(E) drm(E) sd_mod(E) libata(E) crc32c_intel(E) mlx4_core(E) i2c_core(E) dca(E) megaraid_sas(E) dm_mirror(E) dm_region_hash(E) dm_log(E) dm_mod(E) [last unloaded: rds]
[ 4088.193442] CPU: 20 PID: 1244 Comm: kworker/20:2 Tainted: G OE 4.14.0-rc7.master.20171105.ol7.x86_64 #1
[ 4088.205097] Hardware name: Oracle Corporation ORACLE SERVER X5-2L/ASM,MOBO TRAY,2U, BIOS 31110000 03/03/2017
[ 4088.216074] Workqueue: ib_cm cm_work_handler [ib_cm]
[ 4088.221614] task: ffff885fa11d0000 task.stack: ffffc9000e598000
[ 4088.228224] RIP: 0010:rds_ib_recv_refill+0x87/0x620 [rds_rdma]
[ 4088.234736] RSP: 0018:ffffc9000e59bb68 EFLAGS: 00010286
[ 4088.240568] RAX: 0000000000000000 RBX: ffffc9002115d050 RCX: ffffc9002115d050
[ 4088.248535] RDX: ffffffffa0521380 RSI: ffffffffa0522158 RDI: ffffffffa0525580
[ 4088.256498] RBP: ffffc9000e59bbf8 R08: 0000000000000005 R09: 0000000000000000
[ 4088.264465] R10: 0000000000000339 R11: 0000000000000001 R12: 0000000000000000
[ 4088.272433] R13: ffff885f8c9d8000 R14: ffffffff81a0a060 R15: ffff884676268000
[ 4088.280397] FS: 0000000000000000(0000) GS:ffff885fbec80000(0000) knlGS:0000000000000000
[ 4088.289434] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 4088.295846] CR2: 0000000000000020 CR3: 0000000001e09005 CR4: 00000000001606e0
[ 4088.303816] Call Trace:
[ 4088.306557] rds_ib_cm_connect_complete+0xe0/0x220 [rds_rdma]
[ 4088.312982] ? __dynamic_pr_debug+0x8c/0xb0
[ 4088.317664] ? __queue_work+0x142/0x3c0
[ 4088.321944] rds_rdma_cm_event_handler+0x19e/0x250 [rds_rdma]
[ 4088.328370] cma_ib_handler+0xcd/0x280 [rdma_cm]
[ 4088.333522] cm_process_work+0x25/0x120 [ib_cm]
[ 4088.338580] cm_work_handler+0xd6b/0x17aa [ib_cm]
[ 4088.343832] process_one_work+0x149/0x360
[ 4088.348307] worker_thread+0x4d/0x3e0
[ 4088.352397] kthread+0x109/0x140
[ 4088.355996] ? rescuer_thread+0x380/0x380
[ 4088.360467] ? kthread_park+0x60/0x60
[ 4088.364563] ret_from_fork+0x25/0x30
[ 4088.368548] Code: 48 89 45 90 48 89 45 98 eb 4d 0f 1f 44 00 00 48 8b 43 08 48 89 d9 48 c7 c2 80 13 52 a0 48 c7 c6 58 21 52 a0 48 c7 c7 80 55 52 a0 <4c> 8b 48 20 44 89 64 24 08 48 8b 40 30 49 83 e1 fc 48 89 04 24
[ 4088.389612] RIP: rds_ib_recv_refill+0x87/0x620 [rds_rdma] RSP: ffffc9000e59bb68
[ 4088.397772] CR2: 0000000000000020
[ 4088.401505] ---[ end trace fe922e6ccf004431 ]---
This bug was provoked by compiling rds out-of-tree with
EXTRA_CFLAGS="-DRDS_DEBUG -DDEBUG" and inserting an artificial delay
between the rdsdebug() and ib_ib_port_recv() statements:
/* XXX when can this fail? */
ret = ib_post_recv(ic->i_cm_id->qp, &recv->r_wr, &failed_wr);
+ if (can_wait)
+ usleep_range(1000, 5000);
rdsdebug("recv %p ibinc %p page %p addr %lu ret %d\n", recv,
recv->r_ibinc, sg_page(&recv->r_frag->f_sg),
(long) ib_sg_dma_address(
The fix is simply to move the rdsdebug() statement up before the
ib_post_recv() and remove the printing of ret, which is taken care of
anyway by the non-debug code.
Signed-off-by: Håkon Bugge <haakon.bugge@oracle.com>
Reviewed-by: Knut Omang <knut.omang@oracle.com>
Reviewed-by: Wei Lin Guay <wei.lin.guay@oracle.com>
Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-11-07 23:33:34 +08:00
|
|
|
|
|
|
|
/* XXX when can this fail? */
|
2018-07-19 00:25:28 +08:00
|
|
|
ret = ib_post_recv(ic->i_cm_id->qp, &recv->r_wr, NULL);
|
2009-02-24 23:30:34 +08:00
|
|
|
if (ret) {
|
|
|
|
rds_ib_conn_error(conn, "recv post on "
|
2018-07-24 11:51:21 +08:00
|
|
|
"%pI6c returned %d, disconnecting and "
|
2009-02-24 23:30:34 +08:00
|
|
|
"reconnecting\n", &conn->c_faddr,
|
|
|
|
ret);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
posted++;
|
2012-02-04 00:07:54 +08:00
|
|
|
|
|
|
|
if ((posted > 128 && need_resched()) || posted > 8192) {
|
|
|
|
must_wake = true;
|
|
|
|
break;
|
|
|
|
}
|
2009-02-24 23:30:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We're doing flow control - update the window. */
|
|
|
|
if (ic->i_flowctl && posted)
|
|
|
|
rds_ib_advertise_credits(conn, posted);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
rds_ib_ring_unalloc(&ic->i_recv_ring, 1);
|
2015-08-23 06:45:26 +08:00
|
|
|
|
|
|
|
release_refill(conn);
|
|
|
|
|
|
|
|
/* if we're called from the softirq handler, we'll be GFP_NOWAIT.
|
|
|
|
* in this case the ring being low is going to lead to more interrupts
|
|
|
|
* and we can safely let the softirq code take care of it unless the
|
|
|
|
* ring is completely empty.
|
|
|
|
*
|
|
|
|
* if we're called from krdsd, we'll be GFP_KERNEL. In this case
|
|
|
|
* we might have raced with the softirq code while we had the refill
|
|
|
|
* lock held. Use rds_ib_ring_low() instead of ring_empty to decide
|
|
|
|
* if we should requeue.
|
|
|
|
*/
|
|
|
|
if (rds_conn_up(conn) &&
|
2012-02-04 00:07:54 +08:00
|
|
|
(must_wake ||
|
|
|
|
(can_wait && rds_ib_ring_low(&ic->i_recv_ring)) ||
|
2015-08-23 06:45:26 +08:00
|
|
|
rds_ib_ring_empty(&ic->i_recv_ring))) {
|
|
|
|
queue_delayed_work(rds_wq, &conn->c_recv_w, 1);
|
|
|
|
}
|
2012-02-04 00:07:54 +08:00
|
|
|
if (can_wait)
|
|
|
|
cond_resched();
|
2009-02-24 23:30:34 +08:00
|
|
|
}
|
|
|
|
|
2010-05-27 13:05:37 +08:00
|
|
|
/*
|
|
|
|
* We want to recycle several types of recv allocations, like incs and frags.
|
|
|
|
* To use this, the *_free() function passes in the ptr to a list_head within
|
|
|
|
* the recyclee, as well as the cache to put it on.
|
|
|
|
*
|
|
|
|
* First, we put the memory on a percpu list. When this reaches a certain size,
|
|
|
|
* We move it to an intermediate non-percpu list in a lockless manner, with some
|
|
|
|
* xchg/compxchg wizardry.
|
|
|
|
*
|
|
|
|
* N.B. Instead of a list_head as the anchor, we use a single pointer, which can
|
|
|
|
* be NULL and xchg'd. The list is actually empty when the pointer is NULL, and
|
|
|
|
* list_empty() will return true with one element is actually present.
|
|
|
|
*/
|
|
|
|
static void rds_ib_recv_cache_put(struct list_head *new_item,
|
|
|
|
struct rds_ib_refill_cache *cache)
|
2009-02-24 23:30:34 +08:00
|
|
|
{
|
2010-05-27 13:05:37 +08:00
|
|
|
unsigned long flags;
|
2014-01-16 23:54:48 +08:00
|
|
|
struct list_head *old, *chpfirst;
|
2009-02-24 23:30:34 +08:00
|
|
|
|
2010-05-27 13:05:37 +08:00
|
|
|
local_irq_save(flags);
|
2009-02-24 23:30:34 +08:00
|
|
|
|
2012-11-12 23:52:01 +08:00
|
|
|
chpfirst = __this_cpu_read(cache->percpu->first);
|
|
|
|
if (!chpfirst)
|
2010-05-27 13:05:37 +08:00
|
|
|
INIT_LIST_HEAD(new_item);
|
|
|
|
else /* put on front */
|
2012-11-12 23:52:01 +08:00
|
|
|
list_add_tail(new_item, chpfirst);
|
2010-05-27 13:05:37 +08:00
|
|
|
|
2014-01-16 23:54:48 +08:00
|
|
|
__this_cpu_write(cache->percpu->first, new_item);
|
2012-11-12 23:52:01 +08:00
|
|
|
__this_cpu_inc(cache->percpu->count);
|
|
|
|
|
|
|
|
if (__this_cpu_read(cache->percpu->count) < RDS_IB_RECYCLE_BATCH_COUNT)
|
2010-05-27 13:05:37 +08:00
|
|
|
goto end;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return our per-cpu first list to the cache's xfer by atomically
|
|
|
|
* grabbing the current xfer list, appending it to our per-cpu list,
|
|
|
|
* and then atomically returning that entire list back to the
|
|
|
|
* cache's xfer list as long as it's still empty.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
old = xchg(&cache->xfer, NULL);
|
|
|
|
if (old)
|
2012-11-12 23:52:01 +08:00
|
|
|
list_splice_entire_tail(old, chpfirst);
|
|
|
|
old = cmpxchg(&cache->xfer, NULL, chpfirst);
|
2010-05-27 13:05:37 +08:00
|
|
|
} while (old);
|
|
|
|
|
2012-11-12 23:52:01 +08:00
|
|
|
|
2014-01-16 23:54:48 +08:00
|
|
|
__this_cpu_write(cache->percpu->first, NULL);
|
2012-11-12 23:52:01 +08:00
|
|
|
__this_cpu_write(cache->percpu->count, 0);
|
2010-05-27 13:05:37 +08:00
|
|
|
end:
|
|
|
|
local_irq_restore(flags);
|
2009-02-24 23:30:34 +08:00
|
|
|
}
|
|
|
|
|
2010-05-27 13:05:37 +08:00
|
|
|
static struct list_head *rds_ib_recv_cache_get(struct rds_ib_refill_cache *cache)
|
2009-02-24 23:30:34 +08:00
|
|
|
{
|
2010-05-27 13:05:37 +08:00
|
|
|
struct list_head *head = cache->ready;
|
|
|
|
|
|
|
|
if (head) {
|
|
|
|
if (!list_empty(head)) {
|
|
|
|
cache->ready = head->next;
|
|
|
|
list_del_init(head);
|
|
|
|
} else
|
|
|
|
cache->ready = NULL;
|
|
|
|
}
|
2009-02-24 23:30:34 +08:00
|
|
|
|
2010-05-27 13:05:37 +08:00
|
|
|
return head;
|
2009-02-24 23:30:34 +08:00
|
|
|
}
|
|
|
|
|
2014-11-20 22:21:14 +08:00
|
|
|
int rds_ib_inc_copy_to_user(struct rds_incoming *inc, struct iov_iter *to)
|
2009-02-24 23:30:34 +08:00
|
|
|
{
|
|
|
|
struct rds_ib_incoming *ibinc;
|
|
|
|
struct rds_page_frag *frag;
|
|
|
|
unsigned long to_copy;
|
|
|
|
unsigned long frag_off = 0;
|
|
|
|
int copied = 0;
|
|
|
|
int ret;
|
|
|
|
u32 len;
|
|
|
|
|
|
|
|
ibinc = container_of(inc, struct rds_ib_incoming, ii_inc);
|
|
|
|
frag = list_entry(ibinc->ii_frags.next, struct rds_page_frag, f_item);
|
|
|
|
len = be32_to_cpu(inc->i_hdr.h_len);
|
|
|
|
|
2014-11-20 22:21:14 +08:00
|
|
|
while (iov_iter_count(to) && copied < len) {
|
2009-02-24 23:30:34 +08:00
|
|
|
if (frag_off == RDS_FRAG_SIZE) {
|
|
|
|
frag = list_entry(frag->f_item.next,
|
|
|
|
struct rds_page_frag, f_item);
|
|
|
|
frag_off = 0;
|
|
|
|
}
|
2014-11-20 22:21:14 +08:00
|
|
|
to_copy = min_t(unsigned long, iov_iter_count(to),
|
|
|
|
RDS_FRAG_SIZE - frag_off);
|
2009-02-24 23:30:34 +08:00
|
|
|
to_copy = min_t(unsigned long, to_copy, len - copied);
|
|
|
|
|
|
|
|
/* XXX needs + offset for multiple recvs per page */
|
2014-11-20 22:21:14 +08:00
|
|
|
rds_stats_add(s_copy_to_user, to_copy);
|
|
|
|
ret = copy_page_to_iter(sg_page(&frag->f_sg),
|
|
|
|
frag->f_sg.offset + frag_off,
|
|
|
|
to_copy,
|
|
|
|
to);
|
|
|
|
if (ret != to_copy)
|
|
|
|
return -EFAULT;
|
2009-02-24 23:30:34 +08:00
|
|
|
|
|
|
|
frag_off += to_copy;
|
|
|
|
copied += to_copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
return copied;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ic starts out kzalloc()ed */
|
|
|
|
void rds_ib_recv_init_ack(struct rds_ib_connection *ic)
|
|
|
|
{
|
|
|
|
struct ib_send_wr *wr = &ic->i_ack_wr;
|
|
|
|
struct ib_sge *sge = &ic->i_ack_sge;
|
|
|
|
|
|
|
|
sge->addr = ic->i_ack_dma;
|
|
|
|
sge->length = sizeof(struct rds_header);
|
2015-07-31 07:22:26 +08:00
|
|
|
sge->lkey = ic->i_pd->local_dma_lkey;
|
2009-02-24 23:30:34 +08:00
|
|
|
|
|
|
|
wr->sg_list = sge;
|
|
|
|
wr->num_sge = 1;
|
|
|
|
wr->opcode = IB_WR_SEND;
|
|
|
|
wr->wr_id = RDS_IB_ACK_WR_ID;
|
|
|
|
wr->send_flags = IB_SEND_SIGNALED | IB_SEND_SOLICITED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* You'd think that with reliable IB connections you wouldn't need to ack
|
|
|
|
* messages that have been received. The problem is that IB hardware generates
|
|
|
|
* an ack message before it has DMAed the message into memory. This creates a
|
|
|
|
* potential message loss if the HCA is disabled for any reason between when it
|
|
|
|
* sends the ack and before the message is DMAed and processed. This is only a
|
|
|
|
* potential issue if another HCA is available for fail-over.
|
|
|
|
*
|
|
|
|
* When the remote host receives our ack they'll free the sent message from
|
|
|
|
* their send queue. To decrease the latency of this we always send an ack
|
|
|
|
* immediately after we've received messages.
|
|
|
|
*
|
|
|
|
* For simplicity, we only have one ack in flight at a time. This puts
|
|
|
|
* pressure on senders to have deep enough send queues to absorb the latency of
|
|
|
|
* a single ack frame being in flight. This might not be good enough.
|
|
|
|
*
|
|
|
|
* This is implemented by have a long-lived send_wr and sge which point to a
|
|
|
|
* statically allocated ack frame. This ack wr does not fall under the ring
|
|
|
|
* accounting that the tx and rx wrs do. The QP attribute specifically makes
|
|
|
|
* room for it beyond the ring size. Send completion notices its special
|
|
|
|
* wr_id and avoids working with the ring in that case.
|
|
|
|
*/
|
2009-04-01 16:20:20 +08:00
|
|
|
#ifndef KERNEL_HAS_ATOMIC64
|
2015-09-06 14:18:51 +08:00
|
|
|
void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq, int ack_required)
|
2009-02-24 23:30:34 +08:00
|
|
|
{
|
2009-04-01 16:20:20 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ic->i_ack_lock, flags);
|
|
|
|
ic->i_ack_next = seq;
|
|
|
|
if (ack_required)
|
|
|
|
set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
|
|
|
|
spin_unlock_irqrestore(&ic->i_ack_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
u64 seq;
|
|
|
|
|
|
|
|
clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ic->i_ack_lock, flags);
|
|
|
|
seq = ic->i_ack_next;
|
|
|
|
spin_unlock_irqrestore(&ic->i_ack_lock, flags);
|
|
|
|
|
|
|
|
return seq;
|
|
|
|
}
|
|
|
|
#else
|
2015-09-06 14:18:51 +08:00
|
|
|
void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq, int ack_required)
|
2009-04-01 16:20:20 +08:00
|
|
|
{
|
|
|
|
atomic64_set(&ic->i_ack_next, seq);
|
2009-02-24 23:30:34 +08:00
|
|
|
if (ack_required) {
|
2014-03-18 01:06:10 +08:00
|
|
|
smp_mb__before_atomic();
|
2009-02-24 23:30:34 +08:00
|
|
|
set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
|
|
|
|
{
|
|
|
|
clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
|
2014-03-18 01:06:10 +08:00
|
|
|
smp_mb__after_atomic();
|
2009-02-24 23:30:34 +08:00
|
|
|
|
2009-04-01 16:20:20 +08:00
|
|
|
return atomic64_read(&ic->i_ack_next);
|
2009-02-24 23:30:34 +08:00
|
|
|
}
|
2009-04-01 16:20:20 +08:00
|
|
|
#endif
|
|
|
|
|
2009-02-24 23:30:34 +08:00
|
|
|
|
|
|
|
static void rds_ib_send_ack(struct rds_ib_connection *ic, unsigned int adv_credits)
|
|
|
|
{
|
|
|
|
struct rds_header *hdr = ic->i_ack;
|
|
|
|
u64 seq;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
seq = rds_ib_get_ack(ic);
|
|
|
|
|
|
|
|
rdsdebug("send_ack: ic %p ack %llu\n", ic, (unsigned long long) seq);
|
2020-11-07 02:19:36 +08:00
|
|
|
|
|
|
|
ib_dma_sync_single_for_cpu(ic->rds_ibdev->dev, ic->i_ack_dma,
|
|
|
|
sizeof(*hdr), DMA_TO_DEVICE);
|
2009-02-24 23:30:34 +08:00
|
|
|
rds_message_populate_header(hdr, 0, 0, 0);
|
|
|
|
hdr->h_ack = cpu_to_be64(seq);
|
|
|
|
hdr->h_credit = adv_credits;
|
|
|
|
rds_message_make_checksum(hdr);
|
2020-11-07 02:19:36 +08:00
|
|
|
ib_dma_sync_single_for_device(ic->rds_ibdev->dev, ic->i_ack_dma,
|
|
|
|
sizeof(*hdr), DMA_TO_DEVICE);
|
|
|
|
|
2009-02-24 23:30:34 +08:00
|
|
|
ic->i_ack_queued = jiffies;
|
|
|
|
|
2018-07-19 00:25:28 +08:00
|
|
|
ret = ib_post_send(ic->i_cm_id->qp, &ic->i_ack_wr, NULL);
|
2009-02-24 23:30:34 +08:00
|
|
|
if (unlikely(ret)) {
|
|
|
|
/* Failed to send. Release the WR, and
|
|
|
|
* force another ACK.
|
|
|
|
*/
|
|
|
|
clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
|
|
|
|
set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
|
|
|
|
|
|
|
|
rds_ib_stats_inc(s_ib_ack_send_failure);
|
2010-03-11 21:49:55 +08:00
|
|
|
|
|
|
|
rds_ib_conn_error(ic->conn, "sending ack failed\n");
|
2009-02-24 23:30:34 +08:00
|
|
|
} else
|
|
|
|
rds_ib_stats_inc(s_ib_ack_sent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There are 3 ways of getting acknowledgements to the peer:
|
|
|
|
* 1. We call rds_ib_attempt_ack from the recv completion handler
|
|
|
|
* to send an ACK-only frame.
|
|
|
|
* However, there can be only one such frame in the send queue
|
|
|
|
* at any time, so we may have to postpone it.
|
|
|
|
* 2. When another (data) packet is transmitted while there's
|
|
|
|
* an ACK in the queue, we piggyback the ACK sequence number
|
|
|
|
* on the data packet.
|
|
|
|
* 3. If the ACK WR is done sending, we get called from the
|
|
|
|
* send queue completion handler, and check whether there's
|
|
|
|
* another ACK pending (postponed because the WR was on the
|
|
|
|
* queue). If so, we transmit it.
|
|
|
|
*
|
|
|
|
* We maintain 2 variables:
|
|
|
|
* - i_ack_flags, which keeps track of whether the ACK WR
|
|
|
|
* is currently in the send queue or not (IB_ACK_IN_FLIGHT)
|
|
|
|
* - i_ack_next, which is the last sequence number we received
|
|
|
|
*
|
|
|
|
* Potentially, send queue and receive queue handlers can run concurrently.
|
2009-04-01 16:20:20 +08:00
|
|
|
* It would be nice to not have to use a spinlock to synchronize things,
|
|
|
|
* but the one problem that rules this out is that 64bit updates are
|
|
|
|
* not atomic on all platforms. Things would be a lot simpler if
|
|
|
|
* we had atomic64 or maybe cmpxchg64 everywhere.
|
2009-02-24 23:30:34 +08:00
|
|
|
*
|
|
|
|
* Reconnecting complicates this picture just slightly. When we
|
|
|
|
* reconnect, we may be seeing duplicate packets. The peer
|
|
|
|
* is retransmitting them, because it hasn't seen an ACK for
|
|
|
|
* them. It is important that we ACK these.
|
|
|
|
*
|
|
|
|
* ACK mitigation adds a header flag "ACK_REQUIRED"; any packet with
|
|
|
|
* this flag set *MUST* be acknowledged immediately.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When we get here, we're called from the recv queue handler.
|
|
|
|
* Check whether we ought to transmit an ACK.
|
|
|
|
*/
|
|
|
|
void rds_ib_attempt_ack(struct rds_ib_connection *ic)
|
|
|
|
{
|
|
|
|
unsigned int adv_credits;
|
|
|
|
|
|
|
|
if (!test_bit(IB_ACK_REQUESTED, &ic->i_ack_flags))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (test_and_set_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags)) {
|
|
|
|
rds_ib_stats_inc(s_ib_ack_send_delayed);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Can we get a send credit? */
|
2009-04-09 22:09:39 +08:00
|
|
|
if (!rds_ib_send_grab_credits(ic, 1, &adv_credits, 0, RDS_MAX_ADV_CREDIT)) {
|
2009-02-24 23:30:34 +08:00
|
|
|
rds_ib_stats_inc(s_ib_tx_throttle);
|
|
|
|
clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
|
|
|
|
rds_ib_send_ack(ic, adv_credits);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We get here from the send completion handler, when the
|
|
|
|
* adapter tells us the ACK frame was sent.
|
|
|
|
*/
|
|
|
|
void rds_ib_ack_send_complete(struct rds_ib_connection *ic)
|
|
|
|
{
|
|
|
|
clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
|
|
|
|
rds_ib_attempt_ack(ic);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called by the regular xmit code when it wants to piggyback
|
|
|
|
* an ACK on an outgoing frame.
|
|
|
|
*/
|
|
|
|
u64 rds_ib_piggyb_ack(struct rds_ib_connection *ic)
|
|
|
|
{
|
|
|
|
if (test_and_clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags))
|
|
|
|
rds_ib_stats_inc(s_ib_ack_send_piggybacked);
|
|
|
|
return rds_ib_get_ack(ic);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It's kind of lame that we're copying from the posted receive pages into
|
|
|
|
* long-lived bitmaps. We could have posted the bitmaps and rdma written into
|
|
|
|
* them. But receiving new congestion bitmaps should be a *rare* event, so
|
|
|
|
* hopefully we won't need to invest that complexity in making it more
|
|
|
|
* efficient. By copying we can share a simpler core with TCP which has to
|
|
|
|
* copy.
|
|
|
|
*/
|
|
|
|
static void rds_ib_cong_recv(struct rds_connection *conn,
|
|
|
|
struct rds_ib_incoming *ibinc)
|
|
|
|
{
|
|
|
|
struct rds_cong_map *map;
|
|
|
|
unsigned int map_off;
|
|
|
|
unsigned int map_page;
|
|
|
|
struct rds_page_frag *frag;
|
|
|
|
unsigned long frag_off;
|
|
|
|
unsigned long to_copy;
|
|
|
|
unsigned long copied;
|
2019-04-30 11:12:57 +08:00
|
|
|
__le64 uncongested = 0;
|
2009-02-24 23:30:34 +08:00
|
|
|
void *addr;
|
|
|
|
|
|
|
|
/* catch completely corrupt packets */
|
|
|
|
if (be32_to_cpu(ibinc->ii_inc.i_hdr.h_len) != RDS_CONG_MAP_BYTES)
|
|
|
|
return;
|
|
|
|
|
|
|
|
map = conn->c_fcong;
|
|
|
|
map_page = 0;
|
|
|
|
map_off = 0;
|
|
|
|
|
|
|
|
frag = list_entry(ibinc->ii_frags.next, struct rds_page_frag, f_item);
|
|
|
|
frag_off = 0;
|
|
|
|
|
|
|
|
copied = 0;
|
|
|
|
|
|
|
|
while (copied < RDS_CONG_MAP_BYTES) {
|
2019-04-30 11:12:57 +08:00
|
|
|
__le64 *src, *dst;
|
2009-02-24 23:30:34 +08:00
|
|
|
unsigned int k;
|
|
|
|
|
|
|
|
to_copy = min(RDS_FRAG_SIZE - frag_off, PAGE_SIZE - map_off);
|
|
|
|
BUG_ON(to_copy & 7); /* Must be 64bit aligned. */
|
|
|
|
|
2011-11-25 23:14:40 +08:00
|
|
|
addr = kmap_atomic(sg_page(&frag->f_sg));
|
2009-02-24 23:30:34 +08:00
|
|
|
|
2016-04-07 19:57:36 +08:00
|
|
|
src = addr + frag->f_sg.offset + frag_off;
|
2009-02-24 23:30:34 +08:00
|
|
|
dst = (void *)map->m_page_addrs[map_page] + map_off;
|
|
|
|
for (k = 0; k < to_copy; k += 8) {
|
|
|
|
/* Record ports that became uncongested, ie
|
|
|
|
* bits that changed from 0 to 1. */
|
|
|
|
uncongested |= ~(*src) & *dst;
|
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
2011-11-25 23:14:40 +08:00
|
|
|
kunmap_atomic(addr);
|
2009-02-24 23:30:34 +08:00
|
|
|
|
|
|
|
copied += to_copy;
|
|
|
|
|
|
|
|
map_off += to_copy;
|
|
|
|
if (map_off == PAGE_SIZE) {
|
|
|
|
map_off = 0;
|
|
|
|
map_page++;
|
|
|
|
}
|
|
|
|
|
|
|
|
frag_off += to_copy;
|
|
|
|
if (frag_off == RDS_FRAG_SIZE) {
|
|
|
|
frag = list_entry(frag->f_item.next,
|
|
|
|
struct rds_page_frag, f_item);
|
|
|
|
frag_off = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the congestion map is in little endian order */
|
2019-04-30 11:12:57 +08:00
|
|
|
rds_cong_map_updated(map, le64_to_cpu(uncongested));
|
2009-02-24 23:30:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rds_ib_process_recv(struct rds_connection *conn,
|
2009-07-17 21:13:27 +08:00
|
|
|
struct rds_ib_recv_work *recv, u32 data_len,
|
2009-02-24 23:30:34 +08:00
|
|
|
struct rds_ib_ack_state *state)
|
|
|
|
{
|
|
|
|
struct rds_ib_connection *ic = conn->c_transport_data;
|
|
|
|
struct rds_ib_incoming *ibinc = ic->i_ibinc;
|
|
|
|
struct rds_header *ihdr, *hdr;
|
2020-11-07 02:19:36 +08:00
|
|
|
dma_addr_t dma_addr = ic->i_recv_hdrs_dma[recv - ic->i_recvs];
|
2009-02-24 23:30:34 +08:00
|
|
|
|
|
|
|
/* XXX shut down the connection if port 0,0 are seen? */
|
|
|
|
|
|
|
|
rdsdebug("ic %p ibinc %p recv %p byte len %u\n", ic, ibinc, recv,
|
2009-07-17 21:13:27 +08:00
|
|
|
data_len);
|
2009-02-24 23:30:34 +08:00
|
|
|
|
2009-07-17 21:13:27 +08:00
|
|
|
if (data_len < sizeof(struct rds_header)) {
|
2009-02-24 23:30:34 +08:00
|
|
|
rds_ib_conn_error(conn, "incoming message "
|
2018-07-24 11:51:21 +08:00
|
|
|
"from %pI6c didn't include a "
|
2009-02-24 23:30:34 +08:00
|
|
|
"header, disconnecting and "
|
|
|
|
"reconnecting\n",
|
|
|
|
&conn->c_faddr);
|
|
|
|
return;
|
|
|
|
}
|
2009-07-17 21:13:27 +08:00
|
|
|
data_len -= sizeof(struct rds_header);
|
2009-02-24 23:30:34 +08:00
|
|
|
|
2019-10-03 12:11:08 +08:00
|
|
|
ihdr = ic->i_recv_hdrs[recv - ic->i_recvs];
|
2009-02-24 23:30:34 +08:00
|
|
|
|
2020-11-07 02:19:36 +08:00
|
|
|
ib_dma_sync_single_for_cpu(ic->rds_ibdev->dev, dma_addr,
|
|
|
|
sizeof(*ihdr), DMA_FROM_DEVICE);
|
2009-02-24 23:30:34 +08:00
|
|
|
/* Validate the checksum. */
|
|
|
|
if (!rds_message_verify_checksum(ihdr)) {
|
|
|
|
rds_ib_conn_error(conn, "incoming message "
|
2018-07-24 11:51:21 +08:00
|
|
|
"from %pI6c has corrupted header - "
|
2009-02-24 23:30:34 +08:00
|
|
|
"forcing a reconnect\n",
|
|
|
|
&conn->c_faddr);
|
|
|
|
rds_stats_inc(s_recv_drop_bad_checksum);
|
2020-11-07 02:19:36 +08:00
|
|
|
goto done;
|
2009-02-24 23:30:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process the ACK sequence which comes with every packet */
|
|
|
|
state->ack_recv = be64_to_cpu(ihdr->h_ack);
|
|
|
|
state->ack_recv_valid = 1;
|
|
|
|
|
|
|
|
/* Process the credits update if there was one */
|
|
|
|
if (ihdr->h_credit)
|
|
|
|
rds_ib_send_add_credits(conn, ihdr->h_credit);
|
|
|
|
|
2009-07-17 21:13:27 +08:00
|
|
|
if (ihdr->h_sport == 0 && ihdr->h_dport == 0 && data_len == 0) {
|
2009-02-24 23:30:34 +08:00
|
|
|
/* This is an ACK-only packet. The fact that it gets
|
|
|
|
* special treatment here is that historically, ACKs
|
|
|
|
* were rather special beasts.
|
|
|
|
*/
|
|
|
|
rds_ib_stats_inc(s_ib_ack_received);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Usually the frags make their way on to incs and are then freed as
|
|
|
|
* the inc is freed. We don't go that route, so we have to drop the
|
|
|
|
* page ref ourselves. We can't just leave the page on the recv
|
|
|
|
* because that confuses the dma mapping of pages and each recv's use
|
2010-05-25 11:12:41 +08:00
|
|
|
* of a partial page.
|
2009-02-24 23:30:34 +08:00
|
|
|
*
|
|
|
|
* FIXME: Fold this into the code path below.
|
|
|
|
*/
|
2010-05-27 13:05:37 +08:00
|
|
|
rds_ib_frag_free(ic, recv->r_frag);
|
2010-05-25 11:12:41 +08:00
|
|
|
recv->r_frag = NULL;
|
2020-11-07 02:19:36 +08:00
|
|
|
goto done;
|
2009-02-24 23:30:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we don't already have an inc on the connection then this
|
|
|
|
* fragment has a header and starts a message.. copy its header
|
|
|
|
* into the inc and save the inc so we can hang upcoming fragments
|
|
|
|
* off its list.
|
|
|
|
*/
|
2010-01-13 03:56:44 +08:00
|
|
|
if (!ibinc) {
|
2009-02-24 23:30:34 +08:00
|
|
|
ibinc = recv->r_ibinc;
|
|
|
|
recv->r_ibinc = NULL;
|
|
|
|
ic->i_ibinc = ibinc;
|
|
|
|
|
|
|
|
hdr = &ibinc->ii_inc.i_hdr;
|
2016-07-05 13:35:15 +08:00
|
|
|
ibinc->ii_inc.i_rx_lat_trace[RDS_MSG_RX_HDR] =
|
|
|
|
local_clock();
|
2009-02-24 23:30:34 +08:00
|
|
|
memcpy(hdr, ihdr, sizeof(*hdr));
|
|
|
|
ic->i_recv_data_rem = be32_to_cpu(hdr->h_len);
|
2016-07-05 13:35:15 +08:00
|
|
|
ibinc->ii_inc.i_rx_lat_trace[RDS_MSG_RX_START] =
|
|
|
|
local_clock();
|
2009-02-24 23:30:34 +08:00
|
|
|
|
|
|
|
rdsdebug("ic %p ibinc %p rem %u flag 0x%x\n", ic, ibinc,
|
|
|
|
ic->i_recv_data_rem, hdr->h_flags);
|
|
|
|
} else {
|
|
|
|
hdr = &ibinc->ii_inc.i_hdr;
|
|
|
|
/* We can't just use memcmp here; fragments of a
|
|
|
|
* single message may carry different ACKs */
|
2009-11-30 08:55:45 +08:00
|
|
|
if (hdr->h_sequence != ihdr->h_sequence ||
|
|
|
|
hdr->h_len != ihdr->h_len ||
|
|
|
|
hdr->h_sport != ihdr->h_sport ||
|
|
|
|
hdr->h_dport != ihdr->h_dport) {
|
2009-02-24 23:30:34 +08:00
|
|
|
rds_ib_conn_error(conn,
|
|
|
|
"fragment header mismatch; forcing reconnect\n");
|
2020-11-07 02:19:36 +08:00
|
|
|
goto done;
|
2009-02-24 23:30:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add_tail(&recv->r_frag->f_item, &ibinc->ii_frags);
|
|
|
|
recv->r_frag = NULL;
|
|
|
|
|
|
|
|
if (ic->i_recv_data_rem > RDS_FRAG_SIZE)
|
|
|
|
ic->i_recv_data_rem -= RDS_FRAG_SIZE;
|
|
|
|
else {
|
|
|
|
ic->i_recv_data_rem = 0;
|
|
|
|
ic->i_ibinc = NULL;
|
|
|
|
|
2018-07-24 11:51:21 +08:00
|
|
|
if (ibinc->ii_inc.i_hdr.h_flags == RDS_FLAG_CONG_BITMAP) {
|
2009-02-24 23:30:34 +08:00
|
|
|
rds_ib_cong_recv(conn, ibinc);
|
2018-07-24 11:51:21 +08:00
|
|
|
} else {
|
|
|
|
rds_recv_incoming(conn, &conn->c_faddr, &conn->c_laddr,
|
2011-11-25 23:14:40 +08:00
|
|
|
&ibinc->ii_inc, GFP_ATOMIC);
|
2009-02-24 23:30:34 +08:00
|
|
|
state->ack_next = be64_to_cpu(hdr->h_sequence);
|
|
|
|
state->ack_next_valid = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Evaluate the ACK_REQUIRED flag *after* we received
|
|
|
|
* the complete frame, and after bumping the next_rx
|
|
|
|
* sequence. */
|
|
|
|
if (hdr->h_flags & RDS_FLAG_ACK_REQUIRED) {
|
|
|
|
rds_stats_inc(s_recv_ack_required);
|
|
|
|
state->ack_required = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rds_inc_put(&ibinc->ii_inc);
|
|
|
|
}
|
2020-11-07 02:19:36 +08:00
|
|
|
done:
|
|
|
|
ib_dma_sync_single_for_device(ic->rds_ibdev->dev, dma_addr,
|
|
|
|
sizeof(*ihdr), DMA_FROM_DEVICE);
|
2009-02-24 23:30:34 +08:00
|
|
|
}
|
|
|
|
|
2015-09-06 14:18:51 +08:00
|
|
|
void rds_ib_recv_cqe_handler(struct rds_ib_connection *ic,
|
|
|
|
struct ib_wc *wc,
|
|
|
|
struct rds_ib_ack_state *state)
|
2009-10-30 16:51:57 +08:00
|
|
|
{
|
|
|
|
struct rds_connection *conn = ic->conn;
|
|
|
|
struct rds_ib_recv_work *recv;
|
|
|
|
|
2015-09-06 14:18:51 +08:00
|
|
|
rdsdebug("wc wr_id 0x%llx status %u (%s) byte_len %u imm_data %u\n",
|
|
|
|
(unsigned long long)wc->wr_id, wc->status,
|
|
|
|
ib_wc_status_msg(wc->status), wc->byte_len,
|
|
|
|
be32_to_cpu(wc->ex.imm_data));
|
2009-02-24 23:30:34 +08:00
|
|
|
|
2015-09-06 14:18:51 +08:00
|
|
|
rds_ib_stats_inc(s_ib_rx_cq_event);
|
|
|
|
recv = &ic->i_recvs[rds_ib_ring_oldest(&ic->i_recv_ring)];
|
|
|
|
ib_dma_unmap_sg(ic->i_cm_id->device, &recv->r_frag->f_sg, 1,
|
|
|
|
DMA_FROM_DEVICE);
|
2009-02-24 23:30:34 +08:00
|
|
|
|
2015-09-06 14:18:51 +08:00
|
|
|
/* Also process recvs in connecting state because it is possible
|
|
|
|
* to get a recv completion _before_ the rdmacm ESTABLISHED
|
|
|
|
* event is processed.
|
|
|
|
*/
|
|
|
|
if (wc->status == IB_WC_SUCCESS) {
|
|
|
|
rds_ib_process_recv(conn, recv, wc->byte_len, state);
|
|
|
|
} else {
|
|
|
|
/* We expect errors as the qp is drained during shutdown */
|
|
|
|
if (rds_conn_up(conn) || rds_conn_connecting(conn))
|
2019-10-02 07:33:14 +08:00
|
|
|
rds_ib_conn_error(conn, "recv completion on <%pI6c,%pI6c, %d> had status %u (%s), vendor err 0x%x, disconnecting and reconnecting\n",
|
2016-03-14 22:43:55 +08:00
|
|
|
&conn->c_laddr, &conn->c_faddr,
|
2018-10-13 22:13:23 +08:00
|
|
|
conn->c_tos, wc->status,
|
2019-10-02 07:33:14 +08:00
|
|
|
ib_wc_status_msg(wc->status),
|
|
|
|
wc->vendor_err);
|
2009-02-24 23:30:34 +08:00
|
|
|
}
|
2009-10-30 16:51:57 +08:00
|
|
|
|
2015-09-06 14:18:51 +08:00
|
|
|
/* rds_ib_process_recv() doesn't always consume the frag, and
|
|
|
|
* we might not have called it at all if the wc didn't indicate
|
|
|
|
* success. We already unmapped the frag's pages, though, and
|
|
|
|
* the following rds_ib_ring_free() call tells the refill path
|
|
|
|
* that it will not find an allocated frag here. Make sure we
|
|
|
|
* keep that promise by freeing a frag that's still on the ring.
|
|
|
|
*/
|
|
|
|
if (recv->r_frag) {
|
|
|
|
rds_ib_frag_free(ic, recv->r_frag);
|
|
|
|
recv->r_frag = NULL;
|
2009-02-24 23:30:34 +08:00
|
|
|
}
|
2015-09-06 14:18:51 +08:00
|
|
|
rds_ib_ring_free(&ic->i_recv_ring, 1);
|
2009-02-24 23:30:34 +08:00
|
|
|
|
|
|
|
/* If we ever end up with a really empty receive ring, we're
|
|
|
|
* in deep trouble, as the sender will definitely see RNR
|
|
|
|
* timeouts. */
|
|
|
|
if (rds_ib_ring_empty(&ic->i_recv_ring))
|
|
|
|
rds_ib_stats_inc(s_ib_rx_ring_empty);
|
|
|
|
|
2017-08-08 17:13:32 +08:00
|
|
|
if (rds_ib_ring_low(&ic->i_recv_ring)) {
|
2020-10-07 05:31:37 +08:00
|
|
|
rds_ib_recv_refill(conn, 0, GFP_NOWAIT | __GFP_NOWARN);
|
2017-08-08 17:13:32 +08:00
|
|
|
rds_ib_stats_inc(s_ib_rx_refill_from_cq);
|
|
|
|
}
|
2009-02-24 23:30:34 +08:00
|
|
|
}
|
|
|
|
|
2016-07-01 07:11:15 +08:00
|
|
|
int rds_ib_recv_path(struct rds_conn_path *cp)
|
2009-02-24 23:30:34 +08:00
|
|
|
{
|
2016-07-01 07:11:15 +08:00
|
|
|
struct rds_connection *conn = cp->cp_conn;
|
2009-02-24 23:30:34 +08:00
|
|
|
struct rds_ib_connection *ic = conn->c_transport_data;
|
|
|
|
|
|
|
|
rdsdebug("conn %p\n", conn);
|
2015-08-23 06:45:26 +08:00
|
|
|
if (rds_conn_up(conn)) {
|
2009-02-24 23:30:34 +08:00
|
|
|
rds_ib_attempt_ack(ic);
|
2015-08-23 06:45:26 +08:00
|
|
|
rds_ib_recv_refill(conn, 0, GFP_KERNEL);
|
2017-08-08 17:13:32 +08:00
|
|
|
rds_ib_stats_inc(s_ib_rx_refill_from_thread);
|
2015-08-23 06:45:26 +08:00
|
|
|
}
|
2009-02-24 23:30:34 +08:00
|
|
|
|
2018-07-16 21:06:39 +08:00
|
|
|
return 0;
|
2009-02-24 23:30:34 +08:00
|
|
|
}
|
|
|
|
|
2010-07-10 03:26:20 +08:00
|
|
|
int rds_ib_recv_init(void)
|
2009-02-24 23:30:34 +08:00
|
|
|
{
|
|
|
|
struct sysinfo si;
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
|
|
|
|
/* Default to 30% of all available RAM for recv memory */
|
|
|
|
si_meminfo(&si);
|
|
|
|
rds_ib_sysctl_max_recv_allocation = si.totalram / 3 * PAGE_SIZE / RDS_FRAG_SIZE;
|
|
|
|
|
2019-08-23 22:03:18 +08:00
|
|
|
rds_ib_incoming_slab =
|
|
|
|
kmem_cache_create_usercopy("rds_ib_incoming",
|
|
|
|
sizeof(struct rds_ib_incoming),
|
|
|
|
0, SLAB_HWCACHE_ALIGN,
|
|
|
|
offsetof(struct rds_ib_incoming,
|
|
|
|
ii_inc.i_usercopy),
|
|
|
|
sizeof(struct rds_inc_usercopy),
|
|
|
|
NULL);
|
2010-01-13 03:56:44 +08:00
|
|
|
if (!rds_ib_incoming_slab)
|
2009-02-24 23:30:34 +08:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
rds_ib_frag_slab = kmem_cache_create("rds_ib_frag",
|
|
|
|
sizeof(struct rds_page_frag),
|
2010-07-08 07:46:26 +08:00
|
|
|
0, SLAB_HWCACHE_ALIGN, NULL);
|
2015-08-26 03:01:58 +08:00
|
|
|
if (!rds_ib_frag_slab) {
|
2009-02-24 23:30:34 +08:00
|
|
|
kmem_cache_destroy(rds_ib_incoming_slab);
|
2015-08-26 03:01:58 +08:00
|
|
|
rds_ib_incoming_slab = NULL;
|
|
|
|
} else
|
2009-02-24 23:30:34 +08:00
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rds_ib_recv_exit(void)
|
|
|
|
{
|
net: rds: fix memory leak when unload rds_rdma
When KASAN is enabled, after several rds connections are
created, then "rmmod rds_rdma" is run. The following will
appear.
"
BUG rds_ib_incoming (Not tainted): Objects remaining
in rds_ib_incoming on __kmem_cache_shutdown()
Call Trace:
dump_stack+0x71/0xab
slab_err+0xad/0xd0
__kmem_cache_shutdown+0x17d/0x370
shutdown_cache+0x17/0x130
kmem_cache_destroy+0x1df/0x210
rds_ib_recv_exit+0x11/0x20 [rds_rdma]
rds_ib_exit+0x7a/0x90 [rds_rdma]
__x64_sys_delete_module+0x224/0x2c0
? __ia32_sys_delete_module+0x2c0/0x2c0
do_syscall_64+0x73/0x190
entry_SYSCALL_64_after_hwframe+0x44/0xa9
"
This is rds connection memory leak. The root cause is:
When "rmmod rds_rdma" is run, rds_ib_remove_one will call
rds_ib_dev_shutdown to drop the rds connections.
rds_ib_dev_shutdown will call rds_conn_drop to drop rds
connections as below.
"
rds_conn_path_drop(&conn->c_path[0], false);
"
In the above, destroy is set to false.
void rds_conn_path_drop(struct rds_conn_path *cp, bool destroy)
{
atomic_set(&cp->cp_state, RDS_CONN_ERROR);
rcu_read_lock();
if (!destroy && rds_destroy_pending(cp->cp_conn)) {
rcu_read_unlock();
return;
}
queue_work(rds_wq, &cp->cp_down_w);
rcu_read_unlock();
}
In the above function, destroy is set to false. rds_destroy_pending
is called. This does not move rds connections to ib_nodev_conns.
So destroy is set to true to move rds connections to ib_nodev_conns.
In rds_ib_unregister_client, flush_workqueue is called to make rds_wq
finsh shutdown rds connections. The function rds_ib_destroy_nodev_conns
is called to shutdown rds connections finally.
Then rds_ib_recv_exit is called to destroy slab.
void rds_ib_recv_exit(void)
{
kmem_cache_destroy(rds_ib_incoming_slab);
kmem_cache_destroy(rds_ib_frag_slab);
}
The above slab memory leak will not occur again.
>From tests,
256 rds connections
[root@ca-dev14 ~]# time rmmod rds_rdma
real 0m16.522s
user 0m0.000s
sys 0m8.152s
512 rds connections
[root@ca-dev14 ~]# time rmmod rds_rdma
real 0m32.054s
user 0m0.000s
sys 0m15.568s
To rmmod rds_rdma with 256 rds connections, about 16 seconds are needed.
And with 512 rds connections, about 32 seconds are needed.
>From ftrace, when one rds connection is destroyed,
"
19) | rds_conn_destroy [rds]() {
19) 7.782 us | rds_conn_path_drop [rds]();
15) | rds_shutdown_worker [rds]() {
15) | rds_conn_shutdown [rds]() {
15) 1.651 us | rds_send_path_reset [rds]();
15) 7.195 us | }
15) + 11.434 us | }
19) 2.285 us | rds_cong_remove_conn [rds]();
19) * 24062.76 us | }
"
So if many rds connections will be destroyed, this function
rds_ib_destroy_nodev_conns uses most of time.
Suggested-by: Håkon Bugge <haakon.bugge@oracle.com>
Signed-off-by: Zhu Yanjun <yanjun.zhu@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-03 20:48:19 +08:00
|
|
|
WARN_ON(atomic_read(&rds_ib_allocation));
|
|
|
|
|
2009-02-24 23:30:34 +08:00
|
|
|
kmem_cache_destroy(rds_ib_incoming_slab);
|
|
|
|
kmem_cache_destroy(rds_ib_frag_slab);
|
|
|
|
}
|