move unsafe global rkey handling to the RDMA core V2
Subsystems (15)
This fairly simply series adds support to ib_alloc_pd to create the unsafe global rkey in the IB core, and then switches over all ULPs to use that functionality instead of using ib_get_dma_mr directly, and consequently removes ib_get_dma_mr now that all global registrations are done in the core code.
The advantage is that abuses of ib_get_dma_mr are more easily prevented, and use of the global unsafe rkey is more visible and auditable.
I'm also pondering removing the get_dma_mr methods and moving the global registrations into the ->alloc_pd methods, but I'll need to investigate how that will work out first.
Changes since V1:
- keep a pointer to the pd in the srp_target_port strucure
- fix a typo in a patch description
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 1473072981-2035-1-git-send-email-hch-jcswGhMUV9g@public.gmane.org
PATCH 1/6 IB/core: rename pd->local_mr to pd->__internal_mr
This has two reasons: a) to clearly mark that drivers don't have any business using it, and b) because we're going to use it for the (dangerous) global rkey soon, so that drivers don't create on themselves.
--- drivers/infiniband/core/uverbs_cmd.c | 2 +- drivers/infiniband/core/verbs.c | 12 ++++++------ include/rdma/ib_verbs.h | 6 +++++- 3 files changed, 12 insertions(+), 8 deletions(-)
drivers/infiniband/core/uverbs_cmd.c +1 -1
@@ -571,7 +571,7 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file, pd->device = ib_dev; pd->uobject = uobj; - pd->local_mr =NULL ; + pd->__internal_mr =NULL ;atomic_set (&pd->usecnt,0 ); uobj->object = pd;
drivers/infiniband/core/verbs.c +6 -6
@@ -237,7 +237,7 @@ struct ib_pd *ib_alloc_pd(struct ib_device *device) pd->device = device; pd->uobject =NULL ; - pd->local_mr =NULL ; + pd->__internal_mr =NULL ;atomic_set (&pd->usecnt,0 );if (device->attrs.device_cap_flags &IB_DEVICE_LOCAL_DMA_LKEY )
@@ -251,8 +251,8 @@ struct ib_pd *ib_alloc_pd(struct ib_device *device)return (struct ib_pd *)mr; } - pd->local_mr = mr; - pd->local_dma_lkey = pd->local_mr->lkey; + pd->__internal_mr = mr; + pd->local_dma_lkey = pd->__internal_mr->lkey; }return pd; }
@@ -270,10 +270,10 @@ void ib_dealloc_pd(struct ib_pd *pd) {int ret; -if (pd->local_mr) { - ret =ib_dereg_mr (pd->local_mr); +if (pd->__internal_mr) { + ret =ib_dereg_mr (pd->__internal_mr);WARN_ON (ret); - pd->local_mr =NULL ; + pd->__internal_mr =NULL ; }/* uverbs manipulates usecnt with proper locking, while the kabi
include/rdma/ib_verbs.h +5 -1
@@ -1373,7 +1373,11 @@ struct ib_pd {struct ib_device *device;struct ib_uobject *uobject;atomic_t usecnt;/* count all resources */ -struct ib_mr *local_mr; + +/* +* Implementation details of the RDMA core, don't use in drivers: +*/ +struct ib_mr *__internal_mr; };struct ib_xrcd {
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/6 IB/core: add support to create a unsafe global rkey to ib_create_pd
In reply to a message not in the archiveInstead of exposing ib_get_dma_mr to ULPs and letting them use it more or less unchecked, this moves the capability of creating a global rkey into the RDMA core, where it can be easily audited. It also prints a warning everytime this feature is used as well.
--- drivers/infiniband/core/mad.c | 2 +- drivers/infiniband/core/verbs.c | 27 ++++++++++++++++++---- drivers/infiniband/hw/mlx4/mad.c | 2 +- drivers/infiniband/hw/mlx4/main.c | 2 +- drivers/infiniband/hw/mlx5/main.c | 2 +- drivers/infiniband/ulp/ipoib/ipoib_verbs.c | 2 +- drivers/infiniband/ulp/iser/iser_verbs.c | 2 +- drivers/infiniband/ulp/isert/ib_isert.c | 2 +- drivers/infiniband/ulp/srp/ib_srp.c | 2 +- drivers/infiniband/ulp/srpt/ib_srpt.c | 2 +- drivers/nvme/host/rdma.c | 2 +- drivers/nvme/target/rdma.c | 2 +- .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 2 +- include/rdma/ib_verbs.h | 20 +++++++++++++++- net/9p/trans_rdma.c | 2 +- net/rds/ib.c | 2 +- net/sunrpc/xprtrdma/svc_rdma_transport.c | 2 +- net/sunrpc/xprtrdma/verbs.c | 2 +- 18 files changed, 57 insertions(+), 22 deletions(-)
drivers/infiniband/core/mad.c +1 -1
@@ -3160,7 +3160,7 @@ static int ib_mad_port_open(struct ib_device *device, goto error3; } - port_priv->pd =ib_alloc_pd (device); + port_priv->pd =ib_alloc_pd (device,0 );if (IS_ERR (port_priv->pd)) {dev_err (&device->dev,"Couldn't create ib_mad PD\n" ); ret =PTR_ERR (port_priv->pd);
drivers/infiniband/core/verbs.c +22 -5
@@ -227,9 +227,11 @@ EXPORT_SYMBOL(rdma_port_get_link_layer);* Every PD has a local_dma_lkey which can be used as the lkey value for local * memory operations. */ -struct ib_pd *ib_alloc_pd (struct ib_device *device) +struct ib_pd *__ib_alloc_pd (struct ib_device *device,unsigned int flags, +const char *caller) {struct ib_pd *pd; +int mr_access_flags =0 ; pd = device->alloc_pd (device,NULL ,NULL );if (IS_ERR (pd))
@@ -239,24 +241,39 @@ struct ib_pd *ib_alloc_pd(struct ib_device *device) pd->uobject =NULL ; pd->__internal_mr =NULL ;atomic_set (&pd->usecnt,0 ); + pd->flags = flags;if (device->attrs.device_cap_flags &IB_DEVICE_LOCAL_DMA_LKEY ) pd->local_dma_lkey = device->local_dma_lkey; -else { +else + mr_access_flags |=IB_ACCESS_LOCAL_WRITE ; + +if (flags &IB_PD_UNSAFE_GLOBAL_RKEY ) { +pr_warn ("%s: enabling unsafe global rkey\n" , caller); + mr_access_flags |=IB_ACCESS_REMOTE_READ |IB_ACCESS_REMOTE_WRITE ; + } + +if (mr_access_flags) {struct ib_mr *mr; - mr =ib_get_dma_mr (pd,IB_ACCESS_LOCAL_WRITE ); + mr =ib_get_dma_mr (pd, mr_access_flags);if (IS_ERR (mr)) {ib_dealloc_pd (pd);return (struct ib_pd *)mr; } pd->__internal_mr = mr; - pd->local_dma_lkey = pd->__internal_mr->lkey; + +if (!(device->attrs.device_cap_flags &IB_DEVICE_LOCAL_DMA_LKEY )) + pd->local_dma_lkey = pd->__internal_mr->lkey; + +if (flags &IB_PD_UNSAFE_GLOBAL_RKEY ) + pd->unsafe_global_rkey = pd->__internal_mr->rkey; } +return pd; } -EXPORT_SYMBOL (ib_alloc_pd); +EXPORT_SYMBOL (__ib_alloc_pd);/** * ib_dealloc_pd - Deallocates a protection domain.
drivers/infiniband/hw/mlx4/mad.c +1 -1
@@ -1897,7 +1897,7 @@ static int create_pv_resources(struct ib_device *ibdev, int slave, int port, goto err_buf; } - ctx->pd =ib_alloc_pd (ctx->ib_dev); + ctx->pd =ib_alloc_pd (ctx->ib_dev,0 );if (IS_ERR (ctx->pd)) { ret =PTR_ERR (ctx->pd);pr_err ("Couldn't create tunnel PD (%d)\n" , ret);
drivers/infiniband/hw/mlx4/main.c +1 -1
@@ -1259,7 +1259,7 @@ static struct ib_xrcd *mlx4_ib_alloc_xrcd(struct ib_device *ibdev,if (err) goto err1; - xrcd->pd =ib_alloc_pd (ibdev); + xrcd->pd =ib_alloc_pd (ibdev,0 );if (IS_ERR (xrcd->pd)) { err =PTR_ERR (xrcd->pd); goto err2;
drivers/infiniband/hw/mlx5/main.c +1 -1
@@ -2223,7 +2223,7 @@ static int create_umr_res(struct mlx5_ib_dev *dev) goto error_0; } - pd =ib_alloc_pd (&dev->ib_dev); + pd =ib_alloc_pd (&dev->ib_dev,0 );if (IS_ERR (pd)) {mlx5_ib_dbg (dev,"Couldn't create PD for sync UMR QP\n" ); ret =PTR_ERR (pd);
drivers/infiniband/ulp/ipoib/ipoib_verbs.c +1 -1
@@ -147,7 +147,7 @@ int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca)int ret, size;int i; - priv->pd =ib_alloc_pd (priv->ca); + priv->pd =ib_alloc_pd (priv->ca,0 );if (IS_ERR (priv->pd)) {printk (KERN_WARNING "%s: failed to allocate PD\n" , ca->name);return -ENODEV ;
drivers/infiniband/ulp/iser/iser_verbs.c +1 -1
@@ -88,7 +88,7 @@ static int iser_create_device_ib_res(struct iser_device *device) device->comps_used, ib_dev->name, ib_dev->num_comp_vectors, max_cqe); - device->pd =ib_alloc_pd (ib_dev); + device->pd =ib_alloc_pd (ib_dev,0 );if (IS_ERR (device->pd)) goto pd_err;
drivers/infiniband/ulp/isert/ib_isert.c +1 -1
@@ -309,7 +309,7 @@ isert_create_device_ib_res(struct isert_device *device)if (ret) goto out; - device->pd =ib_alloc_pd (ib_dev); + device->pd =ib_alloc_pd (ib_dev,0 );if (IS_ERR (device->pd)) { ret =PTR_ERR (device->pd); isert_err("failed to allocate pd, device %p, ret=%d\n",
drivers/infiniband/ulp/srp/ib_srp.c +1 -1
@@ -3573,7 +3573,7 @@ static void srp_add_one(struct ib_device *device)INIT_LIST_HEAD (&srp_dev->dev_list); srp_dev->dev = device; - srp_dev->pd =ib_alloc_pd (device); + srp_dev->pd =ib_alloc_pd (device,0 );if (IS_ERR (srp_dev->pd)) goto free_dev;
drivers/infiniband/ulp/srpt/ib_srpt.c +1 -1
@@ -2475,7 +2475,7 @@ static void srpt_add_one(struct ib_device *device)init_waitqueue_head (&sdev->ch_releaseQ);mutex_init (&sdev->mutex); - sdev->pd =ib_alloc_pd (device); + sdev->pd =ib_alloc_pd (device,0 );if (IS_ERR (sdev->pd)) goto free_dev;
drivers/nvme/host/rdma.c +1 -1
@@ -446,7 +446,7 @@ nvme_rdma_find_get_device(struct rdma_cm_id *cm_id) ndev->dev = cm_id->device;kref_init (&ndev->ref); - ndev->pd =ib_alloc_pd (ndev->dev); + ndev->pd =ib_alloc_pd (ndev->dev,0 );if (IS_ERR (ndev->pd)) goto out_free_dev;
drivers/nvme/target/rdma.c +1 -1
@@ -848,7 +848,7 @@ nvmet_rdma_find_get_device(struct rdma_cm_id *cm_id) ndev->device = cm_id->device;kref_init (&ndev->ref); - ndev->pd =ib_alloc_pd (ndev->device); + ndev->pd =ib_alloc_pd (ndev->device,0 );if (IS_ERR (ndev->pd)) goto out_free_dev;
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +1 -1
@@ -2465,7 +2465,7 @@ int kiblnd_dev_failover(struct kib_dev *dev) hdev->ibh_cmid = cmid; hdev->ibh_ibdev = cmid->device; - pd =ib_alloc_pd (cmid->device); + pd =ib_alloc_pd (cmid->device,0 );if (IS_ERR (pd)) { rc =PTR_ERR (pd);CERROR ("Can't allocate PD: %d\n" , rc);
include/rdma/ib_verbs.h +19 -1
@@ -1370,10 +1370,13 @@ struct ib_udata {struct ib_pd {u32 local_dma_lkey; +u32 flags;struct ib_device *device;struct ib_uobject *uobject;atomic_t usecnt;/* count all resources */ +u32 unsafe_global_rkey; +/* * Implementation details of the RDMA core, don't use in drivers: */
@@ -2506,8 +2509,23 @@ int ib_find_gid(struct ib_device *device, union ib_gid *gid,int ib_find_pkey (struct ib_device *device,u8 port_num,u16 pkey,u16 *index); -struct ib_pd *ib_alloc_pd (struct ib_device *device); +enum ib_pd_flags { +/* +* Create a memory registration for all memory in the system and place +* the rkey for it into pd->unsafe_global_rkey. This can be used by +* ULPs to avoid the overhead of dynamic MRs. +* +* This flag is generally considered unsafe and must only be used in +* extremly trusted environments. Every use of it will log a warning +* in the kernel log. +*/ +IB_PD_UNSAFE_GLOBAL_RKEY =0x01 , +}; +struct ib_pd *__ib_alloc_pd (struct ib_device *device,unsigned int flags, +const char *caller); +#define ib_alloc_pd (device, flags) \ + __ib_alloc_pd((device), (flags), __func__)void ib_dealloc_pd (struct ib_pd *pd);/**
net/9p/trans_rdma.c +1 -1
@@ -680,7 +680,7 @@ rdma_create_trans(struct p9_client *client, const char *addr, char *args) goto error;/* Create the Protection Domain */ - rdma->pd =ib_alloc_pd (rdma->cm_id->device); + rdma->pd =ib_alloc_pd (rdma->cm_id->device,0 );if (IS_ERR (rdma->pd)) goto error;
net/rds/ib.c +1 -1
@@ -160,7 +160,7 @@ static void rds_ib_add_one(struct ib_device *device) rds_ibdev->max_responder_resources = device->attrs.max_qp_rd_atom; rds_ibdev->dev = device; - rds_ibdev->pd =ib_alloc_pd (device); + rds_ibdev->pd =ib_alloc_pd (device,0 );if (IS_ERR (rds_ibdev->pd)) { rds_ibdev->pd =NULL ; goto put_dev;
net/sunrpc/xprtrdma/svc_rdma_transport.c +1 -1
@@ -993,7 +993,7 @@ static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt) newxprt->sc_ord =min_t (size_t, dev->attrs.max_qp_rd_atom, newxprt->sc_ord); newxprt->sc_ord =min_t (size_t, svcrdma_ord, newxprt->sc_ord); - newxprt->sc_pd =ib_alloc_pd (dev); + newxprt->sc_pd =ib_alloc_pd (dev,0 );if (IS_ERR (newxprt->sc_pd)) {dprintk ("svcrdma: error creating PD for connect request\n" ); goto errout;
net/sunrpc/xprtrdma/verbs.c +1 -1
@@ -386,7 +386,7 @@ rpcrdma_ia_open(struct rpcrdma_xprt *xprt, struct sockaddr *addr, int memreg) } ia->ri_device = ia->ri_id->device; - ia->ri_pd =ib_alloc_pd (ia->ri_device); + ia->ri_pd =ib_alloc_pd (ia->ri_device,0 );if (IS_ERR (ia->ri_pd)) { rc =PTR_ERR (ia->ri_pd);pr_err ("rpcrdma: ib_alloc_pd() returned %d\n" , rc);
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/6 IB/iser: use IB_PD_UNSAFE_GLOBAL_RKEY
In reply to a message not in the archive--- drivers/infiniband/ulp/iser/iscsi_iser.h | 1 - drivers/infiniband/ulp/iser/iser_memory.c | 6 +++++- drivers/infiniband/ulp/iser/iser_verbs.c | 22 +++------------------- 3 files changed, 8 insertions(+), 21 deletions(-)
drivers/infiniband/ulp/iser/iscsi_iser.h +0 -1
@@ -374,7 +374,6 @@ struct iser_reg_ops {struct iser_device {struct ib_device *ib_device;struct ib_pd *pd; -struct ib_mr *mr;struct ib_event_handler event_handler;struct list_head ig_list;int refcount;
drivers/infiniband/ulp/iser/iser_memory.c +5 -1
@@ -199,7 +199,11 @@ iser_reg_dma(struct iser_device *device, struct iser_data_buf *mem,* FIXME: rework the registration code path to differentiate * rkey/lkey use cases */ - reg->rkey = device->mr ? device->mr->rkey :0 ; + +if (device->pd->flags &IB_PD_UNSAFE_GLOBAL_RKEY ) + reg->rkey = device->pd->unsafe_global_rkey; +else + reg->rkey =0 ; reg->sge.addr =ib_sg_dma_address (device->ib_device, &sg[0 ]); reg->sge.length =ib_sg_dma_len (device->ib_device, &sg[0 ]);
drivers/infiniband/ulp/iser/iser_verbs.c +3 -19
@@ -88,7 +88,8 @@ static int iser_create_device_ib_res(struct iser_device *device) device->comps_used, ib_dev->name, ib_dev->num_comp_vectors, max_cqe); - device->pd =ib_alloc_pd (ib_dev,0 ); + device->pd =ib_alloc_pd (ib_dev, + iser_always_reg ?0 :IB_PD_UNSAFE_GLOBAL_RKEY );if (IS_ERR (device->pd)) goto pd_err;
@@ -103,26 +104,13 @@ static int iser_create_device_ib_res(struct iser_device *device) } } -if (!iser_always_reg) { -int access =IB_ACCESS_LOCAL_WRITE | -IB_ACCESS_REMOTE_WRITE | -IB_ACCESS_REMOTE_READ ; - - device->mr =ib_get_dma_mr (device->pd, access); -if (IS_ERR (device->mr)) - goto cq_err; - } -INIT_IB_EVENT_HANDLER (&device->event_handler, ib_dev, iser_event_handler);if (ib_register_event_handler (&device->event_handler)) - goto handler_err; + goto cq_err;return 0 ; -handler_err: -if (device->mr) -ib_dereg_mr (device->mr); cq_err:for (i =0 ; i < device->comps_used; i++) {struct iser_comp *comp = &device->comps[i];
@@ -154,14 +142,10 @@ static void iser_free_device_ib_res(struct iser_device *device) } (void )ib_unregister_event_handler (&device->event_handler); -if (device->mr) - (void )ib_dereg_mr (device->mr);ib_dealloc_pd (device->pd);kfree (device->comps); device->comps =NULL ; - - device->mr =NULL ; device->pd =NULL ; }
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 4/6 IB/srp: use IB_PD_UNSAFE_GLOBAL_RKEY
In reply to a message not in the archive--- drivers/infiniband/ulp/srp/ib_srp.c | 44 ++++++++++++++++--------------------- drivers/infiniband/ulp/srp/ib_srp.h | 3 +-- 2 files changed, 20 insertions(+), 27 deletions(-)
drivers/infiniband/ulp/srp/ib_srp.c +19 -25
@@ -1262,6 +1262,7 @@ static int srp_map_finish_fmr(struct srp_map_state *state, {struct srp_target_port *target = ch->target;struct srp_device *dev = target->srp_host->srp_dev; +struct ib_pd *pd = target->pd;struct ib_pool_fmr *fmr;u64 io_addr =0 ;
@@ -1273,9 +1274,9 @@ static int srp_map_finish_fmr(struct srp_map_state *state,if (state->npages ==0 )return 0 ; -if (state->npages ==1 && target->global_mr) { +if (state->npages ==1 && (pd->flags &IB_PD_UNSAFE_GLOBAL_RKEY )) {srp_map_desc (state, state->base_dma_addr, state->dma_len, - target->global_mr->rkey); + pd->unsafe_global_rkey); goto reset_state; }
@@ -1315,6 +1316,7 @@ static int srp_map_finish_fr(struct srp_map_state *state, {struct srp_target_port *target = ch->target;struct srp_device *dev = target->srp_host->srp_dev; +struct ib_pd *pd = target->pd;struct ib_send_wr *bad_wr;struct ib_reg_wr wr;struct srp_fr_desc *desc;
@@ -1326,12 +1328,12 @@ static int srp_map_finish_fr(struct srp_map_state *state,WARN_ON_ONCE (!dev->use_fast_reg); -if (sg_nents ==1 && target->global_mr) { +if (sg_nents ==1 && (pd->flags &IB_PD_UNSAFE_GLOBAL_RKEY )) {unsigned int sg_offset = sg_offset_p ? *sg_offset_p :0 ;srp_map_desc (state,sg_dma_address (state->sg) + sg_offset,sg_dma_len (state->sg) - sg_offset, - target->global_mr->rkey); + pd->unsafe_global_rkey);if (sg_offset_p) *sg_offset_p =0 ;return 1 ;
@@ -1491,7 +1493,7 @@ static int srp_map_sg_dma(struct srp_map_state *state, struct srp_rdma_ch *ch,for_each_sg (scat, sg, count, i) {srp_map_desc (state,ib_sg_dma_address (dev->dev, sg),ib_sg_dma_len (dev->dev, sg), - target->global_mr->rkey); + target->pd->unsafe_global_rkey); }return 0 ;
@@ -1591,6 +1593,7 @@ static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_rdma_ch *ch, struct srp_request *req) {struct srp_target_port *target = ch->target; +struct ib_pd *pd = target->pd;struct scatterlist *scat;struct srp_cmd *cmd = req->cmd->buf;int len, nents, count, ret;
@@ -1626,7 +1629,7 @@ static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_rdma_ch *ch, fmt =SRP_DATA_DESC_DIRECT ; len =sizeof (struct srp_cmd ) +sizeof (struct srp_direct_buf ); -if (count ==1 && target->global_mr) { +if (count ==1 && (pd->flags &IB_PD_UNSAFE_GLOBAL_RKEY )) {/* * The midlayer only generated a single gather/scatter * entry, or DMA mapping coalesced everything to a
@@ -1636,7 +1639,7 @@ static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_rdma_ch *ch,struct srp_direct_buf *buf = (void *) cmd->add_data; buf->va =cpu_to_be64 (ib_sg_dma_address (ibdev, scat)); - buf->key =cpu_to_be32 (target->global_mr->rkey); + buf->key =cpu_to_be32 (pd->unsafe_global_rkey); buf->len =cpu_to_be32 (ib_sg_dma_len (ibdev, scat)); req->nmdesc =0 ;
@@ -1709,14 +1712,14 @@ static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_rdma_ch *ch,memcpy (indirect_hdr->desc_list, req->indirect_desc, count *sizeof (struct srp_direct_buf )); -if (!target->global_mr) { +if (!(pd->flags &IB_PD_UNSAFE_GLOBAL_RKEY )) { ret =srp_map_idb (ch, req, state.gen.next, state.gen.end, idb_len, &idb_rkey);if (ret <0 ) goto unmap; req->nmdesc++; }else { - idb_rkey =cpu_to_be32 (target->global_mr->rkey); + idb_rkey =cpu_to_be32 (pd->unsafe_global_rkey); } indirect_hdr->table_desc.va =cpu_to_be64 (req->indirect_dma_addr);
@@ -3268,8 +3271,8 @@ static ssize_t srp_create_target(struct device *dev, target->io_class =SRP_REV16A_IB_IO_CLASS ; target->scsi_host = target_host; target->srp_host = host; + target->pd = host->srp_dev->pd; target->lkey = host->srp_dev->pd->local_dma_lkey; - target->global_mr = host->srp_dev->global_mr; target->cmd_sg_cnt = cmd_sg_entries; target->sg_tablesize = indirect_sg_entries ? : cmd_sg_entries; target->allow_ext_sg = allow_ext_sg;
@@ -3524,6 +3527,7 @@ static void srp_add_one(struct ib_device *device)struct srp_host *host;int mr_page_shift, p;u64 max_pages_per_mr; +unsigned int flags =0 ; srp_dev =kzalloc (sizeof (*srp_dev),GFP_KERNEL );if (!srp_dev)
@@ -3558,6 +3562,10 @@ static void srp_add_one(struct ib_device *device) srp_dev->use_fmr = !srp_dev->use_fast_reg && srp_dev->has_fmr; } +if (never_register || !register_always || + (!srp_dev->has_fmr && !srp_dev->has_fr)) + flags |=IB_PD_UNSAFE_GLOBAL_RKEY ; +if (srp_dev->use_fast_reg) { srp_dev->max_pages_per_mr = min_t(u32, srp_dev->max_pages_per_mr,
@@ -3573,19 +3581,10 @@ static void srp_add_one(struct ib_device *device)INIT_LIST_HEAD (&srp_dev->dev_list); srp_dev->dev = device; - srp_dev->pd =ib_alloc_pd (device,0 ); + srp_dev->pd =ib_alloc_pd (device, flags);if (IS_ERR (srp_dev->pd)) goto free_dev; -if (never_register || !register_always || - (!srp_dev->has_fmr && !srp_dev->has_fr)) { - srp_dev->global_mr =ib_get_dma_mr (srp_dev->pd, -IB_ACCESS_LOCAL_WRITE | -IB_ACCESS_REMOTE_READ | -IB_ACCESS_REMOTE_WRITE ); -if (IS_ERR (srp_dev->global_mr)) - goto err_pd; - }for (p =rdma_start_port (device); p <=rdma_end_port (device); ++p) { host =srp_add_port (srp_dev, p);
@@ -3596,9 +3595,6 @@ static void srp_add_one(struct ib_device *device)ib_set_client_data (device, &srp_client, srp_dev);return ; -err_pd: -ib_dealloc_pd (srp_dev->pd); - free_dev:kfree (srp_dev); }
@@ -3638,8 +3634,6 @@ static void srp_remove_one(struct ib_device *device, void *client_data)kfree (host); } -if (srp_dev->global_mr) -ib_dereg_mr (srp_dev->global_mr);ib_dealloc_pd (srp_dev->pd);kfree (srp_dev);
drivers/infiniband/ulp/srp/ib_srp.h +1 -2
@@ -90,7 +90,6 @@ struct srp_device {struct list_head dev_list;struct ib_device *dev;struct ib_pd *pd; -struct ib_mr *global_mr;u64 mr_page_mask;int mr_page_size;int mr_max_size;
@@ -179,7 +178,7 @@ struct srp_target_port {spinlock_t lock;/* read only in the hot path */ -struct ib_mr *global_mr; +struct ib_pd *pd;struct srp_rdma_ch *ch;u32 ch_count;u32 lkey;
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 1473072981-2035-5-git-send-email-hch-jcswGhMUV9g@public.gmane.org
Max Gurtovoy
Reviewed-byRe: [PATCH 4/6] IB/srp: use IB_PD_UNSAFE_GLOBAL_RKEY
Quoted 32 lines
drivers/infiniband/ulp/srp/ib_srp.c +6
-1indirect_hdr->table_desc.va =cpu_to_be64 (req->indirect_dma_addr);@@ -3268,8 +3271,8 @@ static ssize_t srp_create_target(struct device *dev, target->io_class =SRP_REV16A_IB_IO_CLASS ; target->scsi_host = target_host; target->srp_host = host; + target->pd = host->srp_dev->pd; target->lkey = host->srp_dev->pd->local_dma_lkey; - target->global_mr = host->srp_dev->global_mr; target->cmd_sg_cnt = cmd_sg_entries; target->sg_tablesize = indirect_sg_entries ? : cmd_sg_entries; target->allow_ext_sg = allow_ext_sg;@@ -3524,6 +3527,7 @@ static void srp_add_one(struct ib_device *device)struct srp_host *host;int mr_page_shift, p;u64 max_pages_per_mr; +unsigned int flags =0 ; srp_dev =kzalloc (sizeof (*srp_dev),GFP_KERNEL );if (!srp_dev)@@ -3558,6 +3562,10 @@ static void srp_add_one(struct ib_device *device) srp_dev->use_fmr = !srp_dev->use_fast_reg && srp_dev->has_fmr; } +if (never_register || !register_always || + (!srp_dev->has_fmr && !srp_dev->has_fr)) + flags |=IB_PD_UNSAFE_GLOBAL_RKEY ; +if (srp_dev->use_fast_reg) { srp_dev->max_pages_per_mr = min_t(u32, srp_dev->max_pages_per_mr,
drivers/infiniband/ulp/srp/ib_srp.c static void srp_add_one(struct ib_device *device) · line 3586
Quoted 7 lines
drivers/infiniband/ulp/srp/ib_srp.c +1
-1@@ -3573,19 +3581,10 @@ static void srp_add_one(struct ib_device *device)INIT_LIST_HEAD (&srp_dev->dev_list); srp_dev->dev = device; - srp_dev->pd =ib_alloc_pd (device,0 ); + srp_dev->pd =ib_alloc_pd (device, flags);if (IS_ERR (srp_dev->pd)) goto free_dev;
Looks good,
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 5/6 nvme-rdma: use IB_PD_UNSAFE_GLOBAL_RKEY
In reply to a message not in the archive--- drivers/nvme/host/rdma.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-)
drivers/nvme/host/rdma.c +5 -20
@@ -58,7 +58,6 @@struct nvme_rdma_device {struct ib_device *dev;struct ib_pd *pd; -struct ib_mr *mr;struct kref ref;struct list_head entry; };
@@ -410,10 +409,7 @@ static void nvme_rdma_free_dev(struct kref *ref)list_del (&ndev->entry);mutex_unlock (&device_list_mutex); -if (!register_always) -ib_dereg_mr (ndev->mr);ib_dealloc_pd (ndev->pd); -kfree (ndev); }
@@ -446,24 +442,16 @@ nvme_rdma_find_get_device(struct rdma_cm_id *cm_id) ndev->dev = cm_id->device;kref_init (&ndev->ref); - ndev->pd =ib_alloc_pd (ndev->dev,0 ); + ndev->pd =ib_alloc_pd (ndev->dev, + register_always ?0 :IB_PD_UNSAFE_GLOBAL_RKEY );if (IS_ERR (ndev->pd)) goto out_free_dev; -if (!register_always) { - ndev->mr =ib_get_dma_mr (ndev->pd, -IB_ACCESS_LOCAL_WRITE | -IB_ACCESS_REMOTE_READ | -IB_ACCESS_REMOTE_WRITE ); -if (IS_ERR (ndev->mr)) - goto out_free_pd; - } -if (!(ndev->dev->attrs.device_cap_flags &IB_DEVICE_MEM_MGT_EXTENSIONS )) {dev_err (&ndev->dev->dev,"Memory registrations not supported.\n" ); - goto out_free_mr; + goto out_free_pd; }list_add (&ndev->entry, &device_list);
@@ -471,9 +459,6 @@ out_unlock:mutex_unlock (&device_list_mutex);return ndev; -out_free_mr: -if (!register_always) -ib_dereg_mr (ndev->mr); out_free_pd:ib_dealloc_pd (ndev->pd); out_free_dev:
@@ -903,7 +888,7 @@ static int nvme_rdma_map_sg_single(struct nvme_rdma_queue *queue, sg->addr =cpu_to_le64 (sg_dma_address (req->sg_table.sgl));put_unaligned_le24 (sg_dma_len (req->sg_table.sgl), sg->length); -put_unaligned_le32 (queue->device->mr->rkey, sg->key); +put_unaligned_le32 (queue->device->pd->unsafe_global_rkey, sg->key); sg->type =NVME_KEY_SGL_FMT_DATA_DESC <<4 ;return 0 ; }
@@ -988,7 +973,7 @@ static int nvme_rdma_map_data(struct nvme_rdma_queue *queue, nvme_rdma_queue_idx(queue))return nvme_rdma_map_sg_inline (queue, req, c); -if (!register_always) +if (dev->pd->flags &IB_PD_UNSAFE_GLOBAL_RKEY )return nvme_rdma_map_sg_single (queue, req, c); }
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 6/6 IB/core: remove ib_get_dma_mr
In reply to a message not in the archiveWe now only use it from ib_alloc_pd to create a local DMA lkey if the device doesn't provide one, or a global rkey if the ULP requests it.
This patch removes ib_get_dma_mr and open codes the functionality in ib_alloc_pd so that we can simplify the code and prevent abuse of the functionality. As a side effect we can also simplify things by removing the valid access bit check, and the PD refcounting.
In the future I hope to also remove the per-PD global MR entirely by shifting this work into the HW drivers, as one step towards avoiding the struct ib_mr overload for various different use cases.
--- drivers/infiniband/core/verbs.c | 34 ++++++++-------------------------- include/rdma/ib_verbs.h | 12 ------------ 2 files changed, 8 insertions(+), 38 deletions(-)
drivers/infiniband/core/verbs.c +8 -26
@@ -256,12 +256,17 @@ struct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags,if (mr_access_flags) {struct ib_mr *mr; - mr =ib_get_dma_mr (pd, mr_access_flags); + mr = pd->device->get_dma_mr (pd, mr_access_flags);if (IS_ERR (mr)) {ib_dealloc_pd (pd); -return (struct ib_pd *)mr; +return ERR_CAST (mr); } + mr->device = pd->device; + mr->pd = pd; + mr->uobject =NULL ; + mr->need_inval = false; + pd->__internal_mr = mr;if (!(device->attrs.device_cap_flags &IB_DEVICE_LOCAL_DMA_LKEY ))
@@ -288,7 +293,7 @@ void ib_dealloc_pd(struct ib_pd *pd)int ret;if (pd->__internal_mr) { - ret =ib_dereg_mr (pd->__internal_mr); + ret = pd->device->dereg_mr (pd->__internal_mr);WARN_ON (ret); pd->__internal_mr =NULL ; }
@@ -1408,29 +1413,6 @@ EXPORT_SYMBOL(ib_resize_cq);/* Memory regions */ -struct ib_mr *ib_get_dma_mr (struct ib_pd *pd,int mr_access_flags) -{ -struct ib_mr *mr; -int err; - - err =ib_check_mr_access (mr_access_flags); -if (err) -return ERR_PTR (err); - - mr = pd->device->get_dma_mr (pd, mr_access_flags); - -if (!IS_ERR (mr)) { - mr->device = pd->device; - mr->pd = pd; - mr->uobject =NULL ; -atomic_inc (&pd->usecnt); - mr->need_inval = false; - } - -return mr; -} -EXPORT_SYMBOL (ib_get_dma_mr); -int ib_dereg_mr (struct ib_mr *mr) {struct ib_pd *pd = mr->pd;
include/rdma/ib_verbs.h +0 -12
@@ -2879,18 +2879,6 @@ static inline int ib_req_ncomp_notif(struct ib_cq *cq, int wc_cnt) }/** -* ib_get_dma_mr - Returns a memory region for system memory that is -* usable for DMA. -* @pd: The protection domain associated with the memory region. -* @mr_access_flags: Specifies the memory access rights. -* -* Note that the ib_dma_*() functions defined below must be used -* to create/destroy addresses used with the Lkey or Rkey returned -* by ib_get_dma_mr(). -*/ -struct ib_mr *ib_get_dma_mr (struct ib_pd *pd,int mr_access_flags); - -/** * ib_dma_mapping_error - check a DMA addr for error * @dev: The device for which the dma_addr was created * @dma_addr: The DMA address to check
Signature · 6 lines
2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Doug, any comments on this series? I'd really like to get it in for this merge window.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 3 lines · Christoph Hellwig
Doug, any comments on this series? I'd really like to get it in for this merge window.
Series applied, thanks.
Signature · 2 lines
Doug Ledford <[email protected]> GPG Key ID: 0E572FDD