Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

svc_rdma: use local_dma_lkey

We now alwasy have a per-PD local_dma_lkey available. Make use of that
fact in svc_rdma and stop registering our own MR.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Sagi Grimberg <sagig@mellanox.com>
Reviewed-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Reviewed-by: Chuck Lever <chuck.lever@oracle.com>
Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Acked-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>

authored by

Christoph Hellwig and committed by
Doug Ledford
5fe1043d 5d252f90

+10 -40
-2
include/linux/sunrpc/svc_rdma.h
··· 156 156 struct ib_qp *sc_qp; 157 157 struct ib_cq *sc_rq_cq; 158 158 struct ib_cq *sc_sq_cq; 159 - struct ib_mr *sc_phys_mr; /* MR for server memory */ 160 159 int (*sc_reader)(struct svcxprt_rdma *, 161 160 struct svc_rqst *, 162 161 struct svc_rdma_op_ctxt *, 163 162 int *, u32 *, u32, u32, u64, bool); 164 163 u32 sc_dev_caps; /* distilled device caps */ 165 - u32 sc_dma_lkey; /* local dma key */ 166 164 unsigned int sc_frmr_pg_list_len; 167 165 struct list_head sc_frmr_q; 168 166 spinlock_t sc_frmr_q_lock;
+1 -1
net/sunrpc/xprtrdma/svc_rdma_backchannel.c
··· 128 128 129 129 ctxt->wr_op = IB_WR_SEND; 130 130 ctxt->direction = DMA_TO_DEVICE; 131 - ctxt->sge[0].lkey = rdma->sc_dma_lkey; 131 + ctxt->sge[0].lkey = rdma->sc_pd->local_dma_lkey; 132 132 ctxt->sge[0].length = sndbuf->len; 133 133 ctxt->sge[0].addr = 134 134 ib_dma_map_page(rdma->sc_cm_id->device, ctxt->pages[0], 0,
+2 -2
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
··· 144 144 145 145 head->arg.pages[pg_no] = rqstp->rq_arg.pages[pg_no]; 146 146 head->arg.page_len += len; 147 + 147 148 head->arg.len += len; 148 149 if (!pg_off) 149 150 head->count++; ··· 161 160 goto err; 162 161 atomic_inc(&xprt->sc_dma_used); 163 162 164 - /* The lkey here is either a local dma lkey or a dma_mr lkey */ 165 - ctxt->sge[pno].lkey = xprt->sc_dma_lkey; 163 + ctxt->sge[pno].lkey = xprt->sc_pd->local_dma_lkey; 166 164 ctxt->sge[pno].length = len; 167 165 ctxt->count++; 168 166
+3 -3
net/sunrpc/xprtrdma/svc_rdma_sendto.c
··· 265 265 sge[sge_no].addr)) 266 266 goto err; 267 267 atomic_inc(&xprt->sc_dma_used); 268 - sge[sge_no].lkey = xprt->sc_dma_lkey; 268 + sge[sge_no].lkey = xprt->sc_pd->local_dma_lkey; 269 269 ctxt->count++; 270 270 sge_off = 0; 271 271 sge_no++; ··· 480 480 ctxt->count = 1; 481 481 482 482 /* Prepare the SGE for the RPCRDMA Header */ 483 - ctxt->sge[0].lkey = rdma->sc_dma_lkey; 483 + ctxt->sge[0].lkey = rdma->sc_pd->local_dma_lkey; 484 484 ctxt->sge[0].length = svc_rdma_xdr_get_reply_hdr_len(rdma_resp); 485 485 ctxt->sge[0].addr = 486 486 ib_dma_map_page(rdma->sc_cm_id->device, page, 0, ··· 504 504 ctxt->sge[sge_no].addr)) 505 505 goto err; 506 506 atomic_inc(&rdma->sc_dma_used); 507 - ctxt->sge[sge_no].lkey = rdma->sc_dma_lkey; 507 + ctxt->sge[sge_no].lkey = rdma->sc_pd->local_dma_lkey; 508 508 ctxt->sge[sge_no].length = sge_bytes; 509 509 } 510 510 if (byte_count != 0) {
+4 -32
net/sunrpc/xprtrdma/svc_rdma_transport.c
··· 232 232 for (i = 0; i < ctxt->count && ctxt->sge[i].length; i++) { 233 233 /* 234 234 * Unmap the DMA addr in the SGE if the lkey matches 235 - * the sc_dma_lkey, otherwise, ignore it since it is 235 + * the local_dma_lkey, otherwise, ignore it since it is 236 236 * an FRMR lkey and will be unmapped later when the 237 237 * last WR that uses it completes. 238 238 */ 239 - if (ctxt->sge[i].lkey == xprt->sc_dma_lkey) { 239 + if (ctxt->sge[i].lkey == xprt->sc_pd->local_dma_lkey) { 240 240 atomic_dec(&xprt->sc_dma_used); 241 241 ib_dma_unmap_page(xprt->sc_cm_id->device, 242 242 ctxt->sge[i].addr, ··· 698 698 atomic_inc(&xprt->sc_dma_used); 699 699 ctxt->sge[sge_no].addr = pa; 700 700 ctxt->sge[sge_no].length = PAGE_SIZE; 701 - ctxt->sge[sge_no].lkey = xprt->sc_dma_lkey; 701 + ctxt->sge[sge_no].lkey = xprt->sc_pd->local_dma_lkey; 702 702 ctxt->count = sge_no + 1; 703 703 buflen += PAGE_SIZE; 704 704 } ··· 1014 1014 struct ib_cq_init_attr cq_attr = {}; 1015 1015 struct ib_qp_init_attr qp_attr; 1016 1016 struct ib_device *dev; 1017 - int uninitialized_var(dma_mr_acc); 1018 - int need_dma_mr = 0; 1019 1017 unsigned int i; 1020 1018 int ret = 0; 1021 1019 ··· 1158 1160 !rdma_ib_or_roce(dev, newxprt->sc_cm_id->port_num)) 1159 1161 goto errout; 1160 1162 1161 - if (!(newxprt->sc_dev_caps & SVCRDMA_DEVCAP_FAST_REG) || 1162 - !(dev->attrs.device_cap_flags & IB_DEVICE_LOCAL_DMA_LKEY)) { 1163 - need_dma_mr = 1; 1164 - dma_mr_acc = IB_ACCESS_LOCAL_WRITE; 1165 - if (rdma_protocol_iwarp(dev, newxprt->sc_cm_id->port_num) && 1166 - !(newxprt->sc_dev_caps & SVCRDMA_DEVCAP_FAST_REG)) 1167 - dma_mr_acc |= IB_ACCESS_REMOTE_WRITE; 1168 - } 1169 - 1170 1163 if (rdma_protocol_iwarp(dev, newxprt->sc_cm_id->port_num)) 1171 1164 newxprt->sc_dev_caps |= SVCRDMA_DEVCAP_READ_W_INV; 1172 - 1173 - /* Create the DMA MR if needed, otherwise, use the DMA LKEY */ 1174 - if (need_dma_mr) { 1175 - /* Register all of physical memory */ 1176 - newxprt->sc_phys_mr = 1177 - ib_get_dma_mr(newxprt->sc_pd, dma_mr_acc); 1178 - if (IS_ERR(newxprt->sc_phys_mr)) { 1179 - dprintk("svcrdma: Failed to create DMA MR ret=%d\n", 1180 - ret); 1181 - goto errout; 1182 - } 1183 - newxprt->sc_dma_lkey = newxprt->sc_phys_mr->lkey; 1184 - } else 1185 - newxprt->sc_dma_lkey = dev->local_dma_lkey; 1186 1165 1187 1166 /* Post receive buffers */ 1188 1167 for (i = 0; i < newxprt->sc_rq_depth; i++) { ··· 1324 1349 if (rdma->sc_rq_cq && !IS_ERR(rdma->sc_rq_cq)) 1325 1350 ib_destroy_cq(rdma->sc_rq_cq); 1326 1351 1327 - if (rdma->sc_phys_mr && !IS_ERR(rdma->sc_phys_mr)) 1328 - ib_dereg_mr(rdma->sc_phys_mr); 1329 - 1330 1352 if (rdma->sc_pd && !IS_ERR(rdma->sc_pd)) 1331 1353 ib_dealloc_pd(rdma->sc_pd); 1332 1354 ··· 1451 1479 return; 1452 1480 } 1453 1481 atomic_inc(&xprt->sc_dma_used); 1454 - ctxt->sge[0].lkey = xprt->sc_dma_lkey; 1482 + ctxt->sge[0].lkey = xprt->sc_pd->local_dma_lkey; 1455 1483 ctxt->sge[0].length = length; 1456 1484 1457 1485 /* Prepare SEND WR */