Skip to content

Commit 50b7d22

Browse files
lsgunthbjorn-helgaas
authored andcommitted
IB/core: Ensure we map P2P memory correctly in rdma_rw_ctx_[init|destroy]()
In order to use PCI P2P memory the pci_p2pmem_map_sg() function must be called to map the correct PCI bus address. To do this, check the first page in the scatter list to see if it is P2P memory or not. At the moment, scatter lists that contain P2P memory must be homogeneous so if the first page is P2P the entire SGL should be P2P. Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
1 parent 49d92c0 commit 50b7d22

File tree

1 file changed

+9
-2
lines changed
  • drivers/infiniband/core

1 file changed

+9
-2
lines changed

drivers/infiniband/core/rw.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
#include <linux/moduleparam.h>
1414
#include <linux/slab.h>
15+
#include <linux/pci-p2pdma.h>
1516
#include <rdma/mr_pool.h>
1617
#include <rdma/rw.h>
1718

@@ -280,7 +281,11 @@ int rdma_rw_ctx_init(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u8 port_num,
280281
struct ib_device *dev = qp->pd->device;
281282
int ret;
282283

283-
ret = ib_dma_map_sg(dev, sg, sg_cnt, dir);
284+
if (is_pci_p2pdma_page(sg_page(sg)))
285+
ret = pci_p2pdma_map_sg(dev->dma_device, sg, sg_cnt, dir);
286+
else
287+
ret = ib_dma_map_sg(dev, sg, sg_cnt, dir);
288+
284289
if (!ret)
285290
return -ENOMEM;
286291
sg_cnt = ret;
@@ -602,7 +607,9 @@ void rdma_rw_ctx_destroy(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u8 port_num,
602607
break;
603608
}
604609

605-
ib_dma_unmap_sg(qp->pd->device, sg, sg_cnt, dir);
610+
/* P2PDMA contexts do not need to be unmapped */
611+
if (!is_pci_p2pdma_page(sg_page(sg)))
612+
ib_dma_unmap_sg(qp->pd->device, sg, sg_cnt, dir);
606613
}
607614
EXPORT_SYMBOL(rdma_rw_ctx_destroy);
608615

0 commit comments

Comments
 (0)