linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ira Weiny <ira.weiny@intel.com>
To: Christoph Hellwig <hch@lst.de>
Cc: dledford@redhat.com, bart.vanassche@sandisk.com,
	swise@opengridcomputing.com, sagi@grimberg.me,
	linux-rdma@vger.kernel.org, target-devel@vger.kernel.org
Subject: Re: [PATCH 06/12] IB/core: add a simple MR pool
Date: Mon, 18 Apr 2016 23:19:10 -0400	[thread overview]
Message-ID: <20160419031909.GD27515@rhel.amr.corp.intel.com> (raw)
In-Reply-To: <1460410360-13104-7-git-send-email-hch@lst.de>

On Mon, Apr 11, 2016 at 02:32:34PM -0700, Christoph Hellwig wrote:
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> Tested-by: Steve Wise <swise@opengridcomputing.com>
> Reviewed-by: Bart Van Assche <bart.vanassche@sandisk.com>
> Reviewed-by: Steve Wise <swise@opengridcomputing.com>

Reviewed-by: Ira Weiny <ira.weiny@intel.com>

> ---
>  drivers/infiniband/core/Makefile  |  2 +-
>  drivers/infiniband/core/mr_pool.c | 86 +++++++++++++++++++++++++++++++++++++++
>  drivers/infiniband/core/verbs.c   |  5 +++
>  include/rdma/ib_verbs.h           |  8 +++-
>  include/rdma/mr_pool.h            | 25 ++++++++++++
>  5 files changed, 124 insertions(+), 2 deletions(-)
>  create mode 100644 drivers/infiniband/core/mr_pool.c
>  create mode 100644 include/rdma/mr_pool.h
> 
> diff --git a/drivers/infiniband/core/Makefile b/drivers/infiniband/core/Makefile
> index f818538..48bd9d8 100644
> --- a/drivers/infiniband/core/Makefile
> +++ b/drivers/infiniband/core/Makefile
> @@ -10,7 +10,7 @@ obj-$(CONFIG_INFINIBAND_USER_ACCESS) +=	ib_uverbs.o ib_ucm.o \
>  
>  ib_core-y :=			packer.o ud_header.o verbs.o cq.o sysfs.o \
>  				device.o fmr_pool.o cache.o netlink.o \
> -				roce_gid_mgmt.o
> +				roce_gid_mgmt.o mr_pool.o
>  ib_core-$(CONFIG_INFINIBAND_USER_MEM) += umem.o
>  ib_core-$(CONFIG_INFINIBAND_ON_DEMAND_PAGING) += umem_odp.o umem_rbtree.o
>  
> diff --git a/drivers/infiniband/core/mr_pool.c b/drivers/infiniband/core/mr_pool.c
> new file mode 100644
> index 0000000..49d478b
> --- /dev/null
> +++ b/drivers/infiniband/core/mr_pool.c
> @@ -0,0 +1,86 @@
> +/*
> + * Copyright (c) 2016 HGST, a Western Digital Company.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + */
> +#include <rdma/ib_verbs.h>
> +#include <rdma/mr_pool.h>
> +
> +struct ib_mr *ib_mr_pool_get(struct ib_qp *qp, struct list_head *list)
> +{
> +	struct ib_mr *mr;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&qp->mr_lock, flags);
> +	mr = list_first_entry_or_null(list, struct ib_mr, qp_entry);
> +	if (mr) {
> +		list_del(&mr->qp_entry);
> +		qp->mrs_used++;
> +	}
> +	spin_unlock_irqrestore(&qp->mr_lock, flags);
> +
> +	return mr;
> +}
> +EXPORT_SYMBOL(ib_mr_pool_get);
> +
> +void ib_mr_pool_put(struct ib_qp *qp, struct list_head *list, struct ib_mr *mr)
> +{
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&qp->mr_lock, flags);
> +	list_add(&mr->qp_entry, list);
> +	qp->mrs_used--;
> +	spin_unlock_irqrestore(&qp->mr_lock, flags);
> +}
> +EXPORT_SYMBOL(ib_mr_pool_put);
> +
> +int ib_mr_pool_init(struct ib_qp *qp, struct list_head *list, int nr,
> +		enum ib_mr_type type, u32 max_num_sg)
> +{
> +	struct ib_mr *mr;
> +	unsigned long flags;
> +	int ret, i;
> +
> +	for (i = 0; i < nr; i++) {
> +		mr = ib_alloc_mr(qp->pd, type, max_num_sg);
> +		if (IS_ERR(mr)) {
> +			ret = PTR_ERR(mr);
> +			goto out;
> +		}
> +
> +		spin_lock_irqsave(&qp->mr_lock, flags);
> +		list_add_tail(&mr->qp_entry, list);
> +		spin_unlock_irqrestore(&qp->mr_lock, flags);
> +	}
> +
> +	return 0;
> +out:
> +	ib_mr_pool_destroy(qp, list);
> +	return ret;
> +}
> +EXPORT_SYMBOL(ib_mr_pool_init);
> +
> +void ib_mr_pool_destroy(struct ib_qp *qp, struct list_head *list)
> +{
> +	struct ib_mr *mr;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&qp->mr_lock, flags);
> +	while (!list_empty(list)) {
> +		mr = list_first_entry(list, struct ib_mr, qp_entry);
> +		list_del(&mr->qp_entry);
> +
> +		spin_unlock_irqrestore(&qp->mr_lock, flags);
> +		ib_dereg_mr(mr);
> +		spin_lock_irqsave(&qp->mr_lock, flags);
> +	}
> +	spin_unlock_irqrestore(&qp->mr_lock, flags);
> +}
> +EXPORT_SYMBOL(ib_mr_pool_destroy);
> diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
> index d0ed260..d9ea2fb 100644
> --- a/drivers/infiniband/core/verbs.c
> +++ b/drivers/infiniband/core/verbs.c
> @@ -762,6 +762,9 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd,
>  	qp->qp_type    = qp_init_attr->qp_type;
>  
>  	atomic_set(&qp->usecnt, 0);
> +	qp->mrs_used = 0;
> +	spin_lock_init(&qp->mr_lock);
> +
>  	if (qp_init_attr->qp_type == IB_QPT_XRC_TGT)
>  		return ib_create_xrc_qp(qp, qp_init_attr);
>  
> @@ -1255,6 +1258,8 @@ int ib_destroy_qp(struct ib_qp *qp)
>  	struct ib_srq *srq;
>  	int ret;
>  
> +	WARN_ON_ONCE(qp->mrs_used > 0);
> +
>  	if (atomic_read(&qp->usecnt))
>  		return -EBUSY;
>  
> diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
> index 9e8616a..400a8a0 100644
> --- a/include/rdma/ib_verbs.h
> +++ b/include/rdma/ib_verbs.h
> @@ -1421,9 +1421,12 @@ struct ib_qp {
>  	struct ib_pd	       *pd;
>  	struct ib_cq	       *send_cq;
>  	struct ib_cq	       *recv_cq;
> +	spinlock_t		mr_lock;
> +	int			mrs_used;
>  	struct ib_srq	       *srq;
>  	struct ib_xrcd	       *xrcd; /* XRC TGT QPs only */
>  	struct list_head	xrcd_list;
> +
>  	/* count times opened, mcast attaches, flow attaches */
>  	atomic_t		usecnt;
>  	struct list_head	open_list;
> @@ -1438,12 +1441,15 @@ struct ib_qp {
>  struct ib_mr {
>  	struct ib_device  *device;
>  	struct ib_pd	  *pd;
> -	struct ib_uobject *uobject;
>  	u32		   lkey;
>  	u32		   rkey;
>  	u64		   iova;
>  	u32		   length;
>  	unsigned int	   page_size;
> +	union {
> +		struct ib_uobject	*uobject;	/* user */
> +		struct list_head	qp_entry;	/* FR */
> +	};
>  };
>  
>  struct ib_mw {
> diff --git a/include/rdma/mr_pool.h b/include/rdma/mr_pool.h
> new file mode 100644
> index 0000000..986010b
> --- /dev/null
> +++ b/include/rdma/mr_pool.h
> @@ -0,0 +1,25 @@
> +/*
> + * Copyright (c) 2016 HGST, a Western Digital Company.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + */
> +#ifndef _RDMA_MR_POOL_H
> +#define _RDMA_MR_POOL_H 1
> +
> +#include <rdma/ib_verbs.h>
> +
> +struct ib_mr *ib_mr_pool_get(struct ib_qp *qp, struct list_head *list);
> +void ib_mr_pool_put(struct ib_qp *qp, struct list_head *list, struct ib_mr *mr);
> +
> +int ib_mr_pool_init(struct ib_qp *qp, struct list_head *list, int nr,
> +		enum ib_mr_type type, u32 max_num_sg);
> +void ib_mr_pool_destroy(struct ib_qp *qp, struct list_head *list);
> +
> +#endif /* _RDMA_MR_POOL_H */
> -- 
> 2.1.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2016-04-19  3:19 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-11 21:32 generic RDMA READ/WRITE API V6 Christoph Hellwig
     [not found] ` <1460410360-13104-1-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2016-04-11 21:32   ` [PATCH 01/12] IB/mlx5: Expose correct max_sge_rd limit Christoph Hellwig
     [not found]     ` <1460410360-13104-2-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2016-04-17 13:53       ` Leon Romanovsky
     [not found]         ` <20160417135341.GC6349-2ukJVAZIZ/Y@public.gmane.org>
2016-04-17 18:06           ` Christoph Hellwig
2016-04-11 21:32   ` [PATCH 06/12] IB/core: add a simple MR pool Christoph Hellwig
2016-04-17 20:01     ` Sagi Grimberg
2016-04-19  3:19     ` Ira Weiny [this message]
2016-04-11 21:32   ` [PATCH 09/12] target: enhance and export target_alloc_sgl/target_free_sgl Christoph Hellwig
2016-04-11 21:32 ` [PATCH 02/12] IB/cma: pass the port number to ib_create_qp Christoph Hellwig
     [not found]   ` <1460410360-13104-3-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2016-04-15 17:55     ` Sagi Grimberg
2016-04-19  3:14   ` Ira Weiny
2016-04-19 17:30     ` Jason Gunthorpe
2016-04-19 18:38       ` Christoph Hellwig
     [not found]         ` <20160419183830.GB1211-jcswGhMUV9g@public.gmane.org>
2016-04-28 21:05           ` Doug Ledford
     [not found]       ` <20160419173032.GD20844-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-04-19 18:49         ` Sagi Grimberg
2016-04-19 19:24           ` Jason Gunthorpe
     [not found]             ` <20160419192430.GB27028-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-04-19 19:41               ` Steve Wise
2016-04-19 20:05                 ` 'Christoph Hellwig'
2016-04-19 20:21                   ` Jason Gunthorpe
     [not found]                   ` <20160419200555.GA2561-jcswGhMUV9g@public.gmane.org>
2016-04-19 20:26                     ` Steve Wise
2016-04-21  3:11                       ` ira.weiny
2016-04-28 19:43               ` Hefty, Sean
2016-04-28 20:07                 ` Jason Gunthorpe
2016-04-28 21:53                   ` Hefty, Sean
2016-04-28 22:09                     ` Jason Gunthorpe
2016-04-28 23:23                       ` Hefty, Sean
2016-04-28 23:49                         ` Jason Gunthorpe
2016-04-28 23:25                       ` Weiny, Ira
     [not found]                         ` <2807E5FD2F6FDA4886F6618EAC48510E22EC858F-8k97q/ur5Z2krb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2016-04-29  0:01                           ` Jason Gunthorpe
2016-04-11 21:32 ` [PATCH 03/12] IB/core: allow passing mapping an offset into the SG in ib_map_mr_sg Christoph Hellwig
     [not found]   ` <1460410360-13104-4-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2016-04-15 17:56     ` Sagi Grimberg
2016-04-11 21:32 ` [PATCH 04/12] IB/core: add a helper to check for READ WITH INVALIDATE support Christoph Hellwig
     [not found]   ` <1460410360-13104-5-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2016-04-15 17:56     ` Sagi Grimberg
2016-04-19  3:15   ` Ira Weiny
2016-04-11 21:32 ` [PATCH 05/12] IB/core: refactor ib_create_qp Christoph Hellwig
2016-04-17 20:00   ` Sagi Grimberg
     [not found]   ` <1460410360-13104-6-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2016-04-19  3:08     ` Ira Weiny
2016-04-11 21:32 ` [PATCH 07/12] IB/core: add a need_inval flag to struct ib_mr Christoph Hellwig
     [not found]   ` <1460410360-13104-8-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2016-04-17 20:01     ` Sagi Grimberg
2016-04-19  3:20   ` Ira Weiny
2016-04-11 21:32 ` [PATCH 08/12] IB/core: generic RDMA READ/WRITE API Christoph Hellwig
     [not found]   ` <1460410360-13104-9-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2016-04-12 23:52     ` Bart Van Assche
     [not found]       ` <570D8A42.9040107-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2016-04-13 13:50         ` Christoph Hellwig
2016-04-11 21:32 ` [PATCH 10/12] IB/srpt: convert to the " Christoph Hellwig
2016-04-13 18:57   ` Bart Van Assche
2016-04-14 13:32     ` Christoph Hellwig
2016-04-28 21:02       ` Doug Ledford
     [not found]         ` <57227A6D.4000802-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-04-29  6:34           ` Christoph Hellwig
     [not found]             ` <20160429063443.GA18893-jcswGhMUV9g@public.gmane.org>
2016-04-29 14:44               ` Doug Ledford
2016-04-11 21:32 ` [PATCH 11/12] IB/core: add RW API support for signature MRs Christoph Hellwig
     [not found]   ` <1460410360-13104-12-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2016-04-22 21:53     ` Bart Van Assche
2016-04-11 21:32 ` [PATCH 12/12] IB/isert: convert to the generic RDMA READ/WRITE API Christoph Hellwig
     [not found]   ` <1460410360-13104-13-git-send-email-hch-jcswGhMUV9g@public.gmane.org>
2016-04-28 21:04     ` Doug Ledford
2016-04-29 11:46       ` Sagi Grimberg
     [not found]         ` <572349AA.2070407-NQWnxTmZq1alnMjI0IkVqw@public.gmane.org>
2016-04-29 14:45           ` Doug Ledford
     [not found]             ` <e7959da7-79ca-0422-fbc9-9b3814516e1b-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-04-29 16:42               ` Leon Romanovsky
2016-04-12 18:31 ` generic RDMA READ/WRITE API V6 Steve Wise
2016-04-22 22:29 ` Bart Van Assche
     [not found]   ` <571AA5C8.4080502-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2016-05-02 15:15     ` Christoph Hellwig
     [not found]       ` <20160502151535.GA520-jcswGhMUV9g@public.gmane.org>
2016-05-02 19:08         ` Bart Van Assche
2016-05-02 22:14           ` Bart Van Assche
2016-05-03  8:40             ` Christoph Hellwig
2016-05-03 16:10               ` Bart Van Assche
     [not found]           ` <5727A5C7.1090009-XdAiOPVOjttBDgjK7y7TUQ@public.gmane.org>
2016-05-03 14:31             ` Christoph Hellwig
     [not found]               ` <20160503143104.GA30342-jcswGhMUV9g@public.gmane.org>
2016-05-03 21:23                 ` Bart Van Assche
  -- strict thread matches above, loose matches on Subject: below --
2016-04-18 20:14 generic RDMA READ/WRITE API V7 Christoph Hellwig
2016-04-18 20:14 ` [PATCH 06/12] IB/core: add a simple MR pool Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160419031909.GD27515@rhel.amr.corp.intel.com \
    --to=ira.weiny@intel.com \
    --cc=bart.vanassche@sandisk.com \
    --cc=dledford@redhat.com \
    --cc=hch@lst.de \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sagi@grimberg.me \
    --cc=swise@opengridcomputing.com \
    --cc=target-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).