2009-02-24 23:30:32 +08:00
|
|
|
/*
|
2018-07-24 11:51:23 +08:00
|
|
|
* Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.
|
2009-02-24 23:30:32 +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>
|
2010-04-23 09:59:15 +08:00
|
|
|
#include <linux/rculist.h>
|
2011-08-30 23:21:30 +08:00
|
|
|
#include <linux/llist.h>
|
2009-02-24 23:30:32 +08:00
|
|
|
|
2016-06-14 00:44:26 +08:00
|
|
|
#include "rds_single_path.h"
|
2016-03-02 07:20:46 +08:00
|
|
|
#include "ib_mr.h"
|
2020-01-15 20:43:39 +08:00
|
|
|
#include "rds.h"
|
2016-03-02 07:20:46 +08:00
|
|
|
|
|
|
|
struct workqueue_struct *rds_ib_mr_wq;
|
2020-01-15 20:43:39 +08:00
|
|
|
struct rds_ib_dereg_odp_mr {
|
|
|
|
struct work_struct work;
|
|
|
|
struct ib_mr *mr;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void rds_ib_odp_mr_worker(struct work_struct *work);
|
2009-02-24 23:30:32 +08:00
|
|
|
|
|
|
|
static struct rds_ib_device *rds_ib_get_device(__be32 ipaddr)
|
|
|
|
{
|
|
|
|
struct rds_ib_device *rds_ibdev;
|
|
|
|
struct rds_ib_ipaddr *i_ipaddr;
|
|
|
|
|
2010-07-16 03:34:33 +08:00
|
|
|
rcu_read_lock();
|
|
|
|
list_for_each_entry_rcu(rds_ibdev, &rds_ib_devices, list) {
|
2010-04-23 09:59:15 +08:00
|
|
|
list_for_each_entry_rcu(i_ipaddr, &rds_ibdev->ipaddr_list, list) {
|
2009-02-24 23:30:32 +08:00
|
|
|
if (i_ipaddr->ipaddr == ipaddr) {
|
2017-07-04 20:53:15 +08:00
|
|
|
refcount_inc(&rds_ibdev->refcount);
|
2010-04-23 09:59:15 +08:00
|
|
|
rcu_read_unlock();
|
2009-02-24 23:30:32 +08:00
|
|
|
return rds_ibdev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-07-16 03:34:33 +08:00
|
|
|
rcu_read_unlock();
|
2009-02-24 23:30:32 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rds_ib_add_ipaddr(struct rds_ib_device *rds_ibdev, __be32 ipaddr)
|
|
|
|
{
|
|
|
|
struct rds_ib_ipaddr *i_ipaddr;
|
|
|
|
|
|
|
|
i_ipaddr = kmalloc(sizeof *i_ipaddr, GFP_KERNEL);
|
|
|
|
if (!i_ipaddr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
i_ipaddr->ipaddr = ipaddr;
|
|
|
|
|
|
|
|
spin_lock_irq(&rds_ibdev->spinlock);
|
2010-04-23 09:59:15 +08:00
|
|
|
list_add_tail_rcu(&i_ipaddr->list, &rds_ibdev->ipaddr_list);
|
2009-02-24 23:30:32 +08:00
|
|
|
spin_unlock_irq(&rds_ibdev->spinlock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rds_ib_remove_ipaddr(struct rds_ib_device *rds_ibdev, __be32 ipaddr)
|
|
|
|
{
|
2010-04-24 02:04:21 +08:00
|
|
|
struct rds_ib_ipaddr *i_ipaddr;
|
2010-04-23 09:59:15 +08:00
|
|
|
struct rds_ib_ipaddr *to_free = NULL;
|
|
|
|
|
2009-02-24 23:30:32 +08:00
|
|
|
|
|
|
|
spin_lock_irq(&rds_ibdev->spinlock);
|
2010-04-23 09:59:15 +08:00
|
|
|
list_for_each_entry_rcu(i_ipaddr, &rds_ibdev->ipaddr_list, list) {
|
2009-02-24 23:30:32 +08:00
|
|
|
if (i_ipaddr->ipaddr == ipaddr) {
|
2010-04-23 09:59:15 +08:00
|
|
|
list_del_rcu(&i_ipaddr->list);
|
|
|
|
to_free = i_ipaddr;
|
2009-02-24 23:30:32 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_irq(&rds_ibdev->spinlock);
|
2010-04-23 09:59:15 +08:00
|
|
|
|
2012-02-04 00:09:23 +08:00
|
|
|
if (to_free)
|
|
|
|
kfree_rcu(to_free, rcu);
|
2009-02-24 23:30:32 +08:00
|
|
|
}
|
|
|
|
|
2018-07-24 11:51:21 +08:00
|
|
|
int rds_ib_update_ipaddr(struct rds_ib_device *rds_ibdev,
|
|
|
|
struct in6_addr *ipaddr)
|
2009-02-24 23:30:32 +08:00
|
|
|
{
|
|
|
|
struct rds_ib_device *rds_ibdev_old;
|
|
|
|
|
2018-07-24 11:51:21 +08:00
|
|
|
rds_ibdev_old = rds_ib_get_device(ipaddr->s6_addr32[3]);
|
2015-08-23 06:45:25 +08:00
|
|
|
if (!rds_ibdev_old)
|
2018-07-24 11:51:21 +08:00
|
|
|
return rds_ib_add_ipaddr(rds_ibdev, ipaddr->s6_addr32[3]);
|
2015-08-23 06:45:25 +08:00
|
|
|
|
|
|
|
if (rds_ibdev_old != rds_ibdev) {
|
2018-07-24 11:51:21 +08:00
|
|
|
rds_ib_remove_ipaddr(rds_ibdev_old, ipaddr->s6_addr32[3]);
|
2010-05-19 06:48:51 +08:00
|
|
|
rds_ib_dev_put(rds_ibdev_old);
|
2018-07-24 11:51:21 +08:00
|
|
|
return rds_ib_add_ipaddr(rds_ibdev, ipaddr->s6_addr32[3]);
|
2010-05-19 06:48:51 +08:00
|
|
|
}
|
2015-08-23 06:45:25 +08:00
|
|
|
rds_ib_dev_put(rds_ibdev_old);
|
2009-02-24 23:30:32 +08:00
|
|
|
|
2015-08-23 06:45:25 +08:00
|
|
|
return 0;
|
2009-02-24 23:30:32 +08:00
|
|
|
}
|
|
|
|
|
2009-04-01 16:20:19 +08:00
|
|
|
void rds_ib_add_conn(struct rds_ib_device *rds_ibdev, struct rds_connection *conn)
|
2009-02-24 23:30:32 +08:00
|
|
|
{
|
|
|
|
struct rds_ib_connection *ic = conn->c_transport_data;
|
|
|
|
|
|
|
|
/* conn was previously on the nodev_conns_list */
|
|
|
|
spin_lock_irq(&ib_nodev_conns_lock);
|
|
|
|
BUG_ON(list_empty(&ib_nodev_conns));
|
|
|
|
BUG_ON(list_empty(&ic->ib_node));
|
|
|
|
list_del(&ic->ib_node);
|
|
|
|
|
2010-09-18 21:44:14 +08:00
|
|
|
spin_lock(&rds_ibdev->spinlock);
|
2009-02-24 23:30:32 +08:00
|
|
|
list_add_tail(&ic->ib_node, &rds_ibdev->conn_list);
|
2010-09-18 21:44:14 +08:00
|
|
|
spin_unlock(&rds_ibdev->spinlock);
|
2009-04-01 16:20:19 +08:00
|
|
|
spin_unlock_irq(&ib_nodev_conns_lock);
|
2009-02-24 23:30:32 +08:00
|
|
|
|
|
|
|
ic->rds_ibdev = rds_ibdev;
|
2017-07-04 20:53:15 +08:00
|
|
|
refcount_inc(&rds_ibdev->refcount);
|
2009-02-24 23:30:32 +08:00
|
|
|
}
|
|
|
|
|
2009-04-01 16:20:19 +08:00
|
|
|
void rds_ib_remove_conn(struct rds_ib_device *rds_ibdev, struct rds_connection *conn)
|
2009-02-24 23:30:32 +08:00
|
|
|
{
|
2009-04-01 16:20:19 +08:00
|
|
|
struct rds_ib_connection *ic = conn->c_transport_data;
|
2009-02-24 23:30:32 +08:00
|
|
|
|
2009-04-01 16:20:19 +08:00
|
|
|
/* place conn on nodev_conns_list */
|
|
|
|
spin_lock(&ib_nodev_conns_lock);
|
2009-02-24 23:30:32 +08:00
|
|
|
|
2009-04-01 16:20:19 +08:00
|
|
|
spin_lock_irq(&rds_ibdev->spinlock);
|
|
|
|
BUG_ON(list_empty(&ic->ib_node));
|
|
|
|
list_del(&ic->ib_node);
|
|
|
|
spin_unlock_irq(&rds_ibdev->spinlock);
|
|
|
|
|
|
|
|
list_add_tail(&ic->ib_node, &ib_nodev_conns);
|
|
|
|
|
|
|
|
spin_unlock(&ib_nodev_conns_lock);
|
|
|
|
|
|
|
|
ic->rds_ibdev = NULL;
|
2010-05-19 06:48:51 +08:00
|
|
|
rds_ib_dev_put(rds_ibdev);
|
2009-02-24 23:30:32 +08:00
|
|
|
}
|
|
|
|
|
2010-06-26 05:58:16 +08:00
|
|
|
void rds_ib_destroy_nodev_conns(void)
|
2009-02-24 23:30:32 +08:00
|
|
|
{
|
|
|
|
struct rds_ib_connection *ic, *_ic;
|
|
|
|
LIST_HEAD(tmp_list);
|
|
|
|
|
|
|
|
/* avoid calling conn_destroy with irqs off */
|
2010-06-26 05:58:16 +08:00
|
|
|
spin_lock_irq(&ib_nodev_conns_lock);
|
|
|
|
list_splice(&ib_nodev_conns, &tmp_list);
|
|
|
|
spin_unlock_irq(&ib_nodev_conns_lock);
|
2009-02-24 23:30:32 +08:00
|
|
|
|
2009-10-30 16:51:55 +08:00
|
|
|
list_for_each_entry_safe(ic, _ic, &tmp_list, ib_node)
|
2009-02-24 23:30:32 +08:00
|
|
|
rds_conn_destroy(ic->conn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rds_ib_get_mr_info(struct rds_ib_device *rds_ibdev, struct rds_info_rdma_connection *iinfo)
|
|
|
|
{
|
2015-09-11 12:20:57 +08:00
|
|
|
struct rds_ib_mr_pool *pool_1m = rds_ibdev->mr_1m_pool;
|
2009-02-24 23:30:32 +08:00
|
|
|
|
2015-09-11 12:20:57 +08:00
|
|
|
iinfo->rdma_mr_max = pool_1m->max_items;
|
2020-05-29 03:45:45 +08:00
|
|
|
iinfo->rdma_mr_size = pool_1m->max_pages;
|
2009-02-24 23:30:32 +08:00
|
|
|
}
|
|
|
|
|
2018-07-31 13:48:42 +08:00
|
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
2018-07-24 11:51:23 +08:00
|
|
|
void rds6_ib_get_mr_info(struct rds_ib_device *rds_ibdev,
|
|
|
|
struct rds6_info_rdma_connection *iinfo6)
|
|
|
|
{
|
|
|
|
struct rds_ib_mr_pool *pool_1m = rds_ibdev->mr_1m_pool;
|
|
|
|
|
|
|
|
iinfo6->rdma_mr_max = pool_1m->max_items;
|
2020-05-29 03:45:45 +08:00
|
|
|
iinfo6->rdma_mr_size = pool_1m->max_pages;
|
2018-07-24 11:51:23 +08:00
|
|
|
}
|
2018-07-31 13:48:42 +08:00
|
|
|
#endif
|
2018-07-24 11:51:23 +08:00
|
|
|
|
2016-03-02 07:20:46 +08:00
|
|
|
struct rds_ib_mr *rds_ib_reuse_mr(struct rds_ib_mr_pool *pool)
|
2009-02-24 23:30:32 +08:00
|
|
|
{
|
|
|
|
struct rds_ib_mr *ibmr = NULL;
|
2011-08-30 23:21:30 +08:00
|
|
|
struct llist_node *ret;
|
2019-07-17 06:28:57 +08:00
|
|
|
unsigned long flags;
|
2009-02-24 23:30:32 +08:00
|
|
|
|
2019-07-17 06:28:57 +08:00
|
|
|
spin_lock_irqsave(&pool->clean_lock, flags);
|
2011-08-30 23:21:30 +08:00
|
|
|
ret = llist_del_first(&pool->clean_list);
|
2019-07-17 06:28:57 +08:00
|
|
|
spin_unlock_irqrestore(&pool->clean_lock, flags);
|
2016-03-02 07:20:51 +08:00
|
|
|
if (ret) {
|
2011-08-30 23:21:30 +08:00
|
|
|
ibmr = llist_entry(ret, struct rds_ib_mr, llnode);
|
2016-03-02 07:20:51 +08:00
|
|
|
if (pool->pool_type == RDS_IB_MR_8K_POOL)
|
|
|
|
rds_ib_stats_inc(s_ib_rdma_mr_8k_reused);
|
|
|
|
else
|
|
|
|
rds_ib_stats_inc(s_ib_rdma_mr_1m_reused);
|
|
|
|
}
|
2009-02-24 23:30:32 +08:00
|
|
|
|
|
|
|
return ibmr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rds_ib_sync_mr(void *trans_private, int direction)
|
|
|
|
{
|
|
|
|
struct rds_ib_mr *ibmr = trans_private;
|
|
|
|
struct rds_ib_device *rds_ibdev = ibmr->device;
|
|
|
|
|
2020-01-15 20:43:39 +08:00
|
|
|
if (ibmr->odp)
|
|
|
|
return;
|
|
|
|
|
2009-02-24 23:30:32 +08:00
|
|
|
switch (direction) {
|
|
|
|
case DMA_FROM_DEVICE:
|
|
|
|
ib_dma_sync_sg_for_cpu(rds_ibdev->dev, ibmr->sg,
|
|
|
|
ibmr->sg_dma_len, DMA_BIDIRECTIONAL);
|
|
|
|
break;
|
|
|
|
case DMA_TO_DEVICE:
|
|
|
|
ib_dma_sync_sg_for_device(rds_ibdev->dev, ibmr->sg,
|
|
|
|
ibmr->sg_dma_len, DMA_BIDIRECTIONAL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-02 07:20:46 +08:00
|
|
|
void __rds_ib_teardown_mr(struct rds_ib_mr *ibmr)
|
2009-02-24 23:30:32 +08:00
|
|
|
{
|
|
|
|
struct rds_ib_device *rds_ibdev = ibmr->device;
|
|
|
|
|
|
|
|
if (ibmr->sg_dma_len) {
|
|
|
|
ib_dma_unmap_sg(rds_ibdev->dev,
|
|
|
|
ibmr->sg, ibmr->sg_len,
|
|
|
|
DMA_BIDIRECTIONAL);
|
|
|
|
ibmr->sg_dma_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the s/g list */
|
|
|
|
if (ibmr->sg_len) {
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ibmr->sg_len; ++i) {
|
|
|
|
struct page *page = sg_page(&ibmr->sg[i]);
|
|
|
|
|
|
|
|
/* FIXME we need a way to tell a r/w MR
|
|
|
|
* from a r/o MR */
|
2015-08-23 06:45:31 +08:00
|
|
|
WARN_ON(!page->mapping && irqs_disabled());
|
2009-02-24 23:30:32 +08:00
|
|
|
set_page_dirty(page);
|
|
|
|
put_page(page);
|
|
|
|
}
|
|
|
|
kfree(ibmr->sg);
|
|
|
|
|
|
|
|
ibmr->sg = NULL;
|
|
|
|
ibmr->sg_len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-02 07:20:46 +08:00
|
|
|
void rds_ib_teardown_mr(struct rds_ib_mr *ibmr)
|
2009-02-24 23:30:32 +08:00
|
|
|
{
|
|
|
|
unsigned int pinned = ibmr->sg_len;
|
|
|
|
|
|
|
|
__rds_ib_teardown_mr(ibmr);
|
|
|
|
if (pinned) {
|
2015-09-16 09:20:35 +08:00
|
|
|
struct rds_ib_mr_pool *pool = ibmr->pool;
|
2009-02-24 23:30:32 +08:00
|
|
|
|
|
|
|
atomic_sub(pinned, &pool->free_pinned);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int rds_ib_flush_goal(struct rds_ib_mr_pool *pool, int free_all)
|
|
|
|
{
|
|
|
|
unsigned int item_count;
|
|
|
|
|
|
|
|
item_count = atomic_read(&pool->item_count);
|
|
|
|
if (free_all)
|
|
|
|
return item_count;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-12 02:17:59 +08:00
|
|
|
/*
|
2011-08-30 23:21:30 +08:00
|
|
|
* given an llist of mrs, put them all into the list_head for more processing
|
2010-06-12 02:17:59 +08:00
|
|
|
*/
|
2015-08-26 03:02:00 +08:00
|
|
|
static unsigned int llist_append_to_list(struct llist_head *llist,
|
|
|
|
struct list_head *list)
|
2010-06-12 02:17:59 +08:00
|
|
|
{
|
|
|
|
struct rds_ib_mr *ibmr;
|
2011-08-30 23:21:30 +08:00
|
|
|
struct llist_node *node;
|
|
|
|
struct llist_node *next;
|
2015-08-26 03:02:00 +08:00
|
|
|
unsigned int count = 0;
|
2011-08-30 23:21:30 +08:00
|
|
|
|
|
|
|
node = llist_del_all(llist);
|
|
|
|
while (node) {
|
|
|
|
next = node->next;
|
|
|
|
ibmr = llist_entry(node, struct rds_ib_mr, llnode);
|
2010-06-12 02:17:59 +08:00
|
|
|
list_add_tail(&ibmr->unmap_list, list);
|
2011-08-30 23:21:30 +08:00
|
|
|
node = next;
|
2015-08-26 03:02:00 +08:00
|
|
|
count++;
|
2010-06-12 02:17:59 +08:00
|
|
|
}
|
2015-08-26 03:02:00 +08:00
|
|
|
return count;
|
2010-06-12 02:17:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-08-30 23:21:30 +08:00
|
|
|
* this takes a list head of mrs and turns it into linked llist nodes
|
|
|
|
* of clusters. Each cluster has linked llist nodes of
|
|
|
|
* MR_CLUSTER_SIZE mrs that are ready for reuse.
|
2010-06-12 02:17:59 +08:00
|
|
|
*/
|
2019-07-17 06:28:57 +08:00
|
|
|
static void list_to_llist_nodes(struct list_head *list,
|
2011-08-30 23:21:30 +08:00
|
|
|
struct llist_node **nodes_head,
|
|
|
|
struct llist_node **nodes_tail)
|
2010-06-12 02:17:59 +08:00
|
|
|
{
|
|
|
|
struct rds_ib_mr *ibmr;
|
2011-08-30 23:21:30 +08:00
|
|
|
struct llist_node *cur = NULL;
|
|
|
|
struct llist_node **next = nodes_head;
|
2010-06-12 02:17:59 +08:00
|
|
|
|
|
|
|
list_for_each_entry(ibmr, list, unmap_list) {
|
2011-08-30 23:21:30 +08:00
|
|
|
cur = &ibmr->llnode;
|
|
|
|
*next = cur;
|
|
|
|
next = &cur->next;
|
2010-06-12 02:17:59 +08:00
|
|
|
}
|
2011-08-30 23:21:30 +08:00
|
|
|
*next = NULL;
|
|
|
|
*nodes_tail = cur;
|
2010-06-12 02:17:59 +08:00
|
|
|
}
|
|
|
|
|
2009-02-24 23:30:32 +08:00
|
|
|
/*
|
|
|
|
* Flush our pool of MRs.
|
|
|
|
* At a minimum, all currently unused MRs are unmapped.
|
|
|
|
* If the number of MRs allocated exceeds the limit, we also try
|
|
|
|
* to free as many MRs as needed to get back to this limit.
|
|
|
|
*/
|
2016-03-02 07:20:46 +08:00
|
|
|
int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *pool,
|
|
|
|
int free_all, struct rds_ib_mr **ibmr_ret)
|
2009-02-24 23:30:32 +08:00
|
|
|
{
|
2016-03-02 07:20:48 +08:00
|
|
|
struct rds_ib_mr *ibmr;
|
2011-08-30 23:21:30 +08:00
|
|
|
struct llist_node *clean_nodes;
|
|
|
|
struct llist_node *clean_tail;
|
2009-02-24 23:30:32 +08:00
|
|
|
LIST_HEAD(unmap_list);
|
|
|
|
unsigned long unpinned = 0;
|
2015-08-26 03:02:00 +08:00
|
|
|
unsigned int nfreed = 0, dirty_to_clean = 0, free_goal;
|
2009-02-24 23:30:32 +08:00
|
|
|
|
2015-09-11 12:20:57 +08:00
|
|
|
if (pool->pool_type == RDS_IB_MR_8K_POOL)
|
|
|
|
rds_ib_stats_inc(s_ib_rdma_mr_8k_pool_flush);
|
|
|
|
else
|
|
|
|
rds_ib_stats_inc(s_ib_rdma_mr_1m_pool_flush);
|
2009-02-24 23:30:32 +08:00
|
|
|
|
2010-06-12 02:17:59 +08:00
|
|
|
if (ibmr_ret) {
|
|
|
|
DEFINE_WAIT(wait);
|
2015-09-11 12:20:57 +08:00
|
|
|
while (!mutex_trylock(&pool->flush_lock)) {
|
2016-03-02 07:20:46 +08:00
|
|
|
ibmr = rds_ib_reuse_mr(pool);
|
2010-06-12 02:17:59 +08:00
|
|
|
if (ibmr) {
|
|
|
|
*ibmr_ret = ibmr;
|
|
|
|
finish_wait(&pool->flush_wait, &wait);
|
|
|
|
goto out_nolock;
|
|
|
|
}
|
|
|
|
|
|
|
|
prepare_to_wait(&pool->flush_wait, &wait,
|
|
|
|
TASK_UNINTERRUPTIBLE);
|
2011-08-30 23:21:30 +08:00
|
|
|
if (llist_empty(&pool->clean_list))
|
2010-06-12 02:17:59 +08:00
|
|
|
schedule();
|
|
|
|
|
2016-03-02 07:20:46 +08:00
|
|
|
ibmr = rds_ib_reuse_mr(pool);
|
2010-06-12 02:17:59 +08:00
|
|
|
if (ibmr) {
|
|
|
|
*ibmr_ret = ibmr;
|
|
|
|
finish_wait(&pool->flush_wait, &wait);
|
|
|
|
goto out_nolock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finish_wait(&pool->flush_wait, &wait);
|
|
|
|
} else
|
|
|
|
mutex_lock(&pool->flush_lock);
|
|
|
|
|
|
|
|
if (ibmr_ret) {
|
2016-03-02 07:20:46 +08:00
|
|
|
ibmr = rds_ib_reuse_mr(pool);
|
2010-06-12 02:17:59 +08:00
|
|
|
if (ibmr) {
|
|
|
|
*ibmr_ret = ibmr;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2009-02-24 23:30:32 +08:00
|
|
|
|
|
|
|
/* Get the list of all MRs to be dropped. Ordering matters -
|
2010-06-12 02:17:59 +08:00
|
|
|
* we want to put drop_list ahead of free_list.
|
|
|
|
*/
|
2015-08-26 03:02:00 +08:00
|
|
|
dirty_to_clean = llist_append_to_list(&pool->drop_list, &unmap_list);
|
|
|
|
dirty_to_clean += llist_append_to_list(&pool->free_list, &unmap_list);
|
2019-07-17 06:28:57 +08:00
|
|
|
if (free_all) {
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pool->clean_lock, flags);
|
2011-08-30 23:21:30 +08:00
|
|
|
llist_append_to_list(&pool->clean_list, &unmap_list);
|
2019-07-17 06:28:57 +08:00
|
|
|
spin_unlock_irqrestore(&pool->clean_lock, flags);
|
|
|
|
}
|
2009-02-24 23:30:32 +08:00
|
|
|
|
|
|
|
free_goal = rds_ib_flush_goal(pool, free_all);
|
|
|
|
|
|
|
|
if (list_empty(&unmap_list))
|
|
|
|
goto out;
|
|
|
|
|
2020-05-29 03:45:45 +08:00
|
|
|
rds_ib_unreg_frmr(&unmap_list, &nfreed, &unpinned, free_goal);
|
2009-02-24 23:30:32 +08:00
|
|
|
|
2010-06-12 02:17:59 +08:00
|
|
|
if (!list_empty(&unmap_list)) {
|
2019-07-17 06:28:57 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
list_to_llist_nodes(&unmap_list, &clean_nodes, &clean_tail);
|
net: rds: fix memory leak in rds_ib_flush_mr_pool
When the following tests last for several hours, the problem will occur.
Server:
rds-stress -r 1.1.1.16 -D 1M
Client:
rds-stress -r 1.1.1.14 -s 1.1.1.16 -D 1M -T 30
The following will occur.
"
Starting up....
tsks tx/s rx/s tx+rx K/s mbi K/s mbo K/s tx us/c rtt us cpu
%
1 0 0 0.00 0.00 0.00 0.00 0.00 -1.00
1 0 0 0.00 0.00 0.00 0.00 0.00 -1.00
1 0 0 0.00 0.00 0.00 0.00 0.00 -1.00
1 0 0 0.00 0.00 0.00 0.00 0.00 -1.00
"
>From vmcore, we can find that clean_list is NULL.
>From the source code, rds_mr_flushd calls rds_ib_mr_pool_flush_worker.
Then rds_ib_mr_pool_flush_worker calls
"
rds_ib_flush_mr_pool(pool, 0, NULL);
"
Then in function
"
int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *pool,
int free_all, struct rds_ib_mr **ibmr_ret)
"
ibmr_ret is NULL.
In the source code,
"
...
list_to_llist_nodes(pool, &unmap_list, &clean_nodes, &clean_tail);
if (ibmr_ret)
*ibmr_ret = llist_entry(clean_nodes, struct rds_ib_mr, llnode);
/* more than one entry in llist nodes */
if (clean_nodes->next)
llist_add_batch(clean_nodes->next, clean_tail, &pool->clean_list);
...
"
When ibmr_ret is NULL, llist_entry is not executed. clean_nodes->next
instead of clean_nodes is added in clean_list.
So clean_nodes is discarded. It can not be used again.
The workqueue is executed periodically. So more and more clean_nodes are
discarded. Finally the clean_list is NULL.
Then this problem will occur.
Fixes: 1bc144b62524 ("net, rds, Replace xlist in net/rds/xlist.h with llist")
Signed-off-by: Zhu Yanjun <yanjun.zhu@oracle.com>
Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-06 16:00:03 +08:00
|
|
|
if (ibmr_ret) {
|
2011-08-30 23:21:30 +08:00
|
|
|
*ibmr_ret = llist_entry(clean_nodes, struct rds_ib_mr, llnode);
|
net: rds: fix memory leak in rds_ib_flush_mr_pool
When the following tests last for several hours, the problem will occur.
Server:
rds-stress -r 1.1.1.16 -D 1M
Client:
rds-stress -r 1.1.1.14 -s 1.1.1.16 -D 1M -T 30
The following will occur.
"
Starting up....
tsks tx/s rx/s tx+rx K/s mbi K/s mbo K/s tx us/c rtt us cpu
%
1 0 0 0.00 0.00 0.00 0.00 0.00 -1.00
1 0 0 0.00 0.00 0.00 0.00 0.00 -1.00
1 0 0 0.00 0.00 0.00 0.00 0.00 -1.00
1 0 0 0.00 0.00 0.00 0.00 0.00 -1.00
"
>From vmcore, we can find that clean_list is NULL.
>From the source code, rds_mr_flushd calls rds_ib_mr_pool_flush_worker.
Then rds_ib_mr_pool_flush_worker calls
"
rds_ib_flush_mr_pool(pool, 0, NULL);
"
Then in function
"
int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *pool,
int free_all, struct rds_ib_mr **ibmr_ret)
"
ibmr_ret is NULL.
In the source code,
"
...
list_to_llist_nodes(pool, &unmap_list, &clean_nodes, &clean_tail);
if (ibmr_ret)
*ibmr_ret = llist_entry(clean_nodes, struct rds_ib_mr, llnode);
/* more than one entry in llist nodes */
if (clean_nodes->next)
llist_add_batch(clean_nodes->next, clean_tail, &pool->clean_list);
...
"
When ibmr_ret is NULL, llist_entry is not executed. clean_nodes->next
instead of clean_nodes is added in clean_list.
So clean_nodes is discarded. It can not be used again.
The workqueue is executed periodically. So more and more clean_nodes are
discarded. Finally the clean_list is NULL.
Then this problem will occur.
Fixes: 1bc144b62524 ("net, rds, Replace xlist in net/rds/xlist.h with llist")
Signed-off-by: Zhu Yanjun <yanjun.zhu@oracle.com>
Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-06 16:00:03 +08:00
|
|
|
clean_nodes = clean_nodes->next;
|
|
|
|
}
|
2011-08-30 23:21:30 +08:00
|
|
|
/* more than one entry in llist nodes */
|
2019-07-17 06:28:57 +08:00
|
|
|
if (clean_nodes) {
|
|
|
|
spin_lock_irqsave(&pool->clean_lock, flags);
|
net: rds: fix memory leak in rds_ib_flush_mr_pool
When the following tests last for several hours, the problem will occur.
Server:
rds-stress -r 1.1.1.16 -D 1M
Client:
rds-stress -r 1.1.1.14 -s 1.1.1.16 -D 1M -T 30
The following will occur.
"
Starting up....
tsks tx/s rx/s tx+rx K/s mbi K/s mbo K/s tx us/c rtt us cpu
%
1 0 0 0.00 0.00 0.00 0.00 0.00 -1.00
1 0 0 0.00 0.00 0.00 0.00 0.00 -1.00
1 0 0 0.00 0.00 0.00 0.00 0.00 -1.00
1 0 0 0.00 0.00 0.00 0.00 0.00 -1.00
"
>From vmcore, we can find that clean_list is NULL.
>From the source code, rds_mr_flushd calls rds_ib_mr_pool_flush_worker.
Then rds_ib_mr_pool_flush_worker calls
"
rds_ib_flush_mr_pool(pool, 0, NULL);
"
Then in function
"
int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *pool,
int free_all, struct rds_ib_mr **ibmr_ret)
"
ibmr_ret is NULL.
In the source code,
"
...
list_to_llist_nodes(pool, &unmap_list, &clean_nodes, &clean_tail);
if (ibmr_ret)
*ibmr_ret = llist_entry(clean_nodes, struct rds_ib_mr, llnode);
/* more than one entry in llist nodes */
if (clean_nodes->next)
llist_add_batch(clean_nodes->next, clean_tail, &pool->clean_list);
...
"
When ibmr_ret is NULL, llist_entry is not executed. clean_nodes->next
instead of clean_nodes is added in clean_list.
So clean_nodes is discarded. It can not be used again.
The workqueue is executed periodically. So more and more clean_nodes are
discarded. Finally the clean_list is NULL.
Then this problem will occur.
Fixes: 1bc144b62524 ("net, rds, Replace xlist in net/rds/xlist.h with llist")
Signed-off-by: Zhu Yanjun <yanjun.zhu@oracle.com>
Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-06-06 16:00:03 +08:00
|
|
|
llist_add_batch(clean_nodes, clean_tail,
|
|
|
|
&pool->clean_list);
|
2019-07-17 06:28:57 +08:00
|
|
|
spin_unlock_irqrestore(&pool->clean_lock, flags);
|
|
|
|
}
|
2010-06-12 02:17:59 +08:00
|
|
|
}
|
2009-02-24 23:30:32 +08:00
|
|
|
|
|
|
|
atomic_sub(unpinned, &pool->free_pinned);
|
2015-08-26 03:02:00 +08:00
|
|
|
atomic_sub(dirty_to_clean, &pool->dirty_count);
|
2009-02-24 23:30:32 +08:00
|
|
|
atomic_sub(nfreed, &pool->item_count);
|
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&pool->flush_lock);
|
2010-06-12 02:17:59 +08:00
|
|
|
if (waitqueue_active(&pool->flush_wait))
|
|
|
|
wake_up(&pool->flush_wait);
|
|
|
|
out_nolock:
|
2016-03-02 07:20:48 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct rds_ib_mr *rds_ib_try_reuse_ibmr(struct rds_ib_mr_pool *pool)
|
|
|
|
{
|
|
|
|
struct rds_ib_mr *ibmr = NULL;
|
|
|
|
int iter = 0;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
ibmr = rds_ib_reuse_mr(pool);
|
|
|
|
if (ibmr)
|
|
|
|
return ibmr;
|
|
|
|
|
|
|
|
if (atomic_inc_return(&pool->item_count) <= pool->max_items)
|
|
|
|
break;
|
|
|
|
|
|
|
|
atomic_dec(&pool->item_count);
|
|
|
|
|
|
|
|
if (++iter > 2) {
|
|
|
|
if (pool->pool_type == RDS_IB_MR_8K_POOL)
|
|
|
|
rds_ib_stats_inc(s_ib_rdma_mr_8k_pool_depleted);
|
|
|
|
else
|
|
|
|
rds_ib_stats_inc(s_ib_rdma_mr_1m_pool_depleted);
|
2019-07-17 06:29:07 +08:00
|
|
|
break;
|
2016-03-02 07:20:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We do have some empty MRs. Flush them out. */
|
|
|
|
if (pool->pool_type == RDS_IB_MR_8K_POOL)
|
|
|
|
rds_ib_stats_inc(s_ib_rdma_mr_8k_pool_wait);
|
|
|
|
else
|
|
|
|
rds_ib_stats_inc(s_ib_rdma_mr_1m_pool_wait);
|
|
|
|
|
|
|
|
rds_ib_flush_mr_pool(pool, 0, &ibmr);
|
|
|
|
if (ibmr)
|
|
|
|
return ibmr;
|
|
|
|
}
|
|
|
|
|
2019-07-17 06:29:07 +08:00
|
|
|
return NULL;
|
2009-02-24 23:30:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rds_ib_mr_pool_flush_worker(struct work_struct *work)
|
|
|
|
{
|
2010-06-12 02:26:02 +08:00
|
|
|
struct rds_ib_mr_pool *pool = container_of(work, struct rds_ib_mr_pool, flush_worker.work);
|
2009-02-24 23:30:32 +08:00
|
|
|
|
2010-06-12 02:17:59 +08:00
|
|
|
rds_ib_flush_mr_pool(pool, 0, NULL);
|
2009-02-24 23:30:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rds_ib_free_mr(void *trans_private, int invalidate)
|
|
|
|
{
|
|
|
|
struct rds_ib_mr *ibmr = trans_private;
|
2015-09-16 09:20:35 +08:00
|
|
|
struct rds_ib_mr_pool *pool = ibmr->pool;
|
2009-02-24 23:30:32 +08:00
|
|
|
struct rds_ib_device *rds_ibdev = ibmr->device;
|
|
|
|
|
|
|
|
rdsdebug("RDS/IB: free_mr nents %u\n", ibmr->sg_len);
|
|
|
|
|
2020-01-15 20:43:39 +08:00
|
|
|
if (ibmr->odp) {
|
|
|
|
/* A MR created and marked as use_once. We use delayed work,
|
|
|
|
* because there is a change that we are in interrupt and can't
|
|
|
|
* call to ib_dereg_mr() directly.
|
|
|
|
*/
|
|
|
|
INIT_DELAYED_WORK(&ibmr->work, rds_ib_odp_mr_worker);
|
|
|
|
queue_delayed_work(rds_ib_mr_wq, &ibmr->work, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-24 23:30:32 +08:00
|
|
|
/* Return it to the pool's free list */
|
2020-05-29 03:45:45 +08:00
|
|
|
rds_ib_free_frmr_list(ibmr);
|
2009-02-24 23:30:32 +08:00
|
|
|
|
|
|
|
atomic_add(ibmr->sg_len, &pool->free_pinned);
|
|
|
|
atomic_inc(&pool->dirty_count);
|
|
|
|
|
|
|
|
/* If we've pinned too many pages, request a flush */
|
2009-11-30 08:55:45 +08:00
|
|
|
if (atomic_read(&pool->free_pinned) >= pool->max_free_pinned ||
|
2015-08-26 03:02:02 +08:00
|
|
|
atomic_read(&pool->dirty_count) >= pool->max_items / 5)
|
2016-03-02 07:20:46 +08:00
|
|
|
queue_delayed_work(rds_ib_mr_wq, &pool->flush_worker, 10);
|
2009-02-24 23:30:32 +08:00
|
|
|
|
|
|
|
if (invalidate) {
|
|
|
|
if (likely(!in_interrupt())) {
|
2010-06-12 02:17:59 +08:00
|
|
|
rds_ib_flush_mr_pool(pool, 0, NULL);
|
2009-02-24 23:30:32 +08:00
|
|
|
} else {
|
|
|
|
/* We get here if the user created a MR marked
|
2015-08-26 03:02:01 +08:00
|
|
|
* as use_once and invalidate at the same time.
|
|
|
|
*/
|
2016-03-02 07:20:46 +08:00
|
|
|
queue_delayed_work(rds_ib_mr_wq,
|
2015-08-26 03:02:01 +08:00
|
|
|
&pool->flush_worker, 10);
|
2009-02-24 23:30:32 +08:00
|
|
|
}
|
|
|
|
}
|
2010-05-19 06:48:51 +08:00
|
|
|
|
|
|
|
rds_ib_dev_put(rds_ibdev);
|
2009-02-24 23:30:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rds_ib_flush_mrs(void)
|
|
|
|
{
|
|
|
|
struct rds_ib_device *rds_ibdev;
|
|
|
|
|
2010-07-16 03:34:33 +08:00
|
|
|
down_read(&rds_ib_devices_lock);
|
2009-02-24 23:30:32 +08:00
|
|
|
list_for_each_entry(rds_ibdev, &rds_ib_devices, list) {
|
2015-09-11 12:20:57 +08:00
|
|
|
if (rds_ibdev->mr_8k_pool)
|
|
|
|
rds_ib_flush_mr_pool(rds_ibdev->mr_8k_pool, 0, NULL);
|
2009-02-24 23:30:32 +08:00
|
|
|
|
2015-09-11 12:20:57 +08:00
|
|
|
if (rds_ibdev->mr_1m_pool)
|
|
|
|
rds_ib_flush_mr_pool(rds_ibdev->mr_1m_pool, 0, NULL);
|
2009-02-24 23:30:32 +08:00
|
|
|
}
|
2010-07-16 03:34:33 +08:00
|
|
|
up_read(&rds_ib_devices_lock);
|
2009-02-24 23:30:32 +08:00
|
|
|
}
|
|
|
|
|
2020-01-15 20:43:39 +08:00
|
|
|
u32 rds_ib_get_lkey(void *trans_private)
|
|
|
|
{
|
|
|
|
struct rds_ib_mr *ibmr = trans_private;
|
|
|
|
|
|
|
|
return ibmr->u.mr->lkey;
|
|
|
|
}
|
|
|
|
|
2009-02-24 23:30:32 +08:00
|
|
|
void *rds_ib_get_mr(struct scatterlist *sg, unsigned long nents,
|
2018-07-25 11:31:58 +08:00
|
|
|
struct rds_sock *rs, u32 *key_ret,
|
2020-01-15 20:43:39 +08:00
|
|
|
struct rds_connection *conn,
|
|
|
|
u64 start, u64 length, int need_odp)
|
2009-02-24 23:30:32 +08:00
|
|
|
{
|
|
|
|
struct rds_ib_device *rds_ibdev;
|
|
|
|
struct rds_ib_mr *ibmr = NULL;
|
2018-07-25 11:31:58 +08:00
|
|
|
struct rds_ib_connection *ic = NULL;
|
2009-02-24 23:30:32 +08:00
|
|
|
int ret;
|
|
|
|
|
2018-07-24 11:51:21 +08:00
|
|
|
rds_ibdev = rds_ib_get_device(rs->rs_bound_addr.s6_addr32[3]);
|
2009-02-24 23:30:32 +08:00
|
|
|
if (!rds_ibdev) {
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2020-01-15 20:43:39 +08:00
|
|
|
if (need_odp == ODP_ZEROBASED || need_odp == ODP_VIRTUAL) {
|
|
|
|
u64 virt_addr = need_odp == ODP_ZEROBASED ? 0 : start;
|
|
|
|
int access_flags =
|
|
|
|
(IB_ACCESS_LOCAL_WRITE | IB_ACCESS_REMOTE_READ |
|
|
|
|
IB_ACCESS_REMOTE_WRITE | IB_ACCESS_REMOTE_ATOMIC |
|
|
|
|
IB_ACCESS_ON_DEMAND);
|
2020-01-15 20:43:40 +08:00
|
|
|
struct ib_sge sge = {};
|
2020-01-15 20:43:39 +08:00
|
|
|
struct ib_mr *ib_mr;
|
|
|
|
|
|
|
|
if (!rds_ibdev->odp_capable) {
|
|
|
|
ret = -EOPNOTSUPP;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ib_mr = ib_reg_user_mr(rds_ibdev->pd, start, length, virt_addr,
|
|
|
|
access_flags);
|
|
|
|
|
|
|
|
if (IS_ERR(ib_mr)) {
|
|
|
|
rdsdebug("rds_ib_get_user_mr returned %d\n",
|
|
|
|
IS_ERR(ib_mr));
|
|
|
|
ret = PTR_ERR(ib_mr);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (key_ret)
|
|
|
|
*key_ret = ib_mr->rkey;
|
|
|
|
|
|
|
|
ibmr = kzalloc(sizeof(*ibmr), GFP_KERNEL);
|
|
|
|
if (!ibmr) {
|
|
|
|
ib_dereg_mr(ib_mr);
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
ibmr->u.mr = ib_mr;
|
|
|
|
ibmr->odp = 1;
|
2020-01-15 20:43:40 +08:00
|
|
|
|
|
|
|
sge.addr = virt_addr;
|
|
|
|
sge.length = length;
|
|
|
|
sge.lkey = ib_mr->lkey;
|
|
|
|
|
|
|
|
ib_advise_mr(rds_ibdev->pd,
|
|
|
|
IB_UVERBS_ADVISE_MR_ADVICE_PREFETCH_WRITE,
|
|
|
|
IB_UVERBS_ADVISE_MR_FLAG_FLUSH, &sge, 1);
|
2020-01-15 20:43:39 +08:00
|
|
|
return ibmr;
|
|
|
|
}
|
|
|
|
|
2018-07-25 11:31:58 +08:00
|
|
|
if (conn)
|
|
|
|
ic = conn->c_transport_data;
|
|
|
|
|
2015-09-11 12:20:57 +08:00
|
|
|
if (!rds_ibdev->mr_8k_pool || !rds_ibdev->mr_1m_pool) {
|
2009-02-24 23:30:32 +08:00
|
|
|
ret = -ENODEV;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2020-05-29 03:45:45 +08:00
|
|
|
ibmr = rds_ib_reg_frmr(rds_ibdev, ic, sg, nents, key_ret);
|
2018-07-25 11:31:58 +08:00
|
|
|
if (IS_ERR(ibmr)) {
|
|
|
|
ret = PTR_ERR(ibmr);
|
2016-03-02 07:20:48 +08:00
|
|
|
pr_warn("RDS/IB: rds_ib_get_mr failed (errno=%d)\n", ret);
|
2018-07-25 11:31:58 +08:00
|
|
|
} else {
|
|
|
|
return ibmr;
|
|
|
|
}
|
2016-03-02 07:20:48 +08:00
|
|
|
|
2018-07-25 11:31:58 +08:00
|
|
|
out:
|
2010-05-19 06:48:51 +08:00
|
|
|
if (rds_ibdev)
|
|
|
|
rds_ib_dev_put(rds_ibdev);
|
2016-03-02 07:20:48 +08:00
|
|
|
|
2018-07-25 11:31:58 +08:00
|
|
|
return ERR_PTR(ret);
|
2009-02-24 23:30:32 +08:00
|
|
|
}
|
2010-06-12 02:17:59 +08:00
|
|
|
|
2016-03-02 07:20:46 +08:00
|
|
|
void rds_ib_destroy_mr_pool(struct rds_ib_mr_pool *pool)
|
|
|
|
{
|
|
|
|
cancel_delayed_work_sync(&pool->flush_worker);
|
|
|
|
rds_ib_flush_mr_pool(pool, 1, NULL);
|
|
|
|
WARN_ON(atomic_read(&pool->item_count));
|
|
|
|
WARN_ON(atomic_read(&pool->free_pinned));
|
|
|
|
kfree(pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct rds_ib_mr_pool *rds_ib_create_mr_pool(struct rds_ib_device *rds_ibdev,
|
|
|
|
int pool_type)
|
|
|
|
{
|
|
|
|
struct rds_ib_mr_pool *pool;
|
|
|
|
|
|
|
|
pool = kzalloc(sizeof(*pool), GFP_KERNEL);
|
|
|
|
if (!pool)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
pool->pool_type = pool_type;
|
|
|
|
init_llist_head(&pool->free_list);
|
|
|
|
init_llist_head(&pool->drop_list);
|
|
|
|
init_llist_head(&pool->clean_list);
|
2019-07-17 06:28:57 +08:00
|
|
|
spin_lock_init(&pool->clean_lock);
|
2016-03-02 07:20:46 +08:00
|
|
|
mutex_init(&pool->flush_lock);
|
|
|
|
init_waitqueue_head(&pool->flush_wait);
|
|
|
|
INIT_DELAYED_WORK(&pool->flush_worker, rds_ib_mr_pool_flush_worker);
|
|
|
|
|
|
|
|
if (pool_type == RDS_IB_MR_1M_POOL) {
|
|
|
|
/* +1 allows for unaligned MRs */
|
2020-05-29 03:45:45 +08:00
|
|
|
pool->max_pages = RDS_MR_1M_MSG_SIZE + 1;
|
2017-10-05 03:11:29 +08:00
|
|
|
pool->max_items = rds_ibdev->max_1m_mrs;
|
2016-03-02 07:20:46 +08:00
|
|
|
} else {
|
|
|
|
/* pool_type == RDS_IB_MR_8K_POOL */
|
2020-05-29 03:45:45 +08:00
|
|
|
pool->max_pages = RDS_MR_8K_MSG_SIZE + 1;
|
2017-10-05 03:11:29 +08:00
|
|
|
pool->max_items = rds_ibdev->max_8k_mrs;
|
2016-03-02 07:20:46 +08:00
|
|
|
}
|
|
|
|
|
2020-05-29 03:45:45 +08:00
|
|
|
pool->max_free_pinned = pool->max_items * pool->max_pages / 4;
|
2016-03-02 07:20:46 +08:00
|
|
|
pool->max_items_soft = rds_ibdev->max_mrs * 3 / 4;
|
|
|
|
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rds_ib_mr_init(void)
|
|
|
|
{
|
2016-06-08 03:33:45 +08:00
|
|
|
rds_ib_mr_wq = alloc_workqueue("rds_mr_flushd", WQ_MEM_RECLAIM, 0);
|
2016-03-02 07:20:46 +08:00
|
|
|
if (!rds_ib_mr_wq)
|
|
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* By the time this is called all the IB devices should have been torn down and
|
|
|
|
* had their pools freed. As each pool is freed its work struct is waited on,
|
|
|
|
* so the pool flushing work queue should be idle by the time we get here.
|
|
|
|
*/
|
|
|
|
void rds_ib_mr_exit(void)
|
|
|
|
{
|
|
|
|
destroy_workqueue(rds_ib_mr_wq);
|
|
|
|
}
|
2020-01-15 20:43:39 +08:00
|
|
|
|
|
|
|
static void rds_ib_odp_mr_worker(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct rds_ib_mr *ibmr;
|
|
|
|
|
|
|
|
ibmr = container_of(work, struct rds_ib_mr, work.work);
|
|
|
|
ib_dereg_mr(ibmr->u.mr);
|
|
|
|
kfree(ibmr);
|
|
|
|
}
|