Skip to content

Commit 6affca1

Browse files
Max Gurtovoyjgunthorpe
authored andcommitted
RDMA/rw: Fix error flow during RDMA context initialization
In case the SGL was mapped for P2P DMA operation, we must unmap it using pci_p2pdma_unmap_sg during the error unwind of rdma_rw_ctx_init() Fixes: 7f73eac ("PCI/P2PDMA: Introduce pci_p2pdma_unmap_sg()") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Max Gurtovoy <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Reviewed-by: Logan Gunthorpe <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 4ca501d commit 6affca1

File tree

1 file changed

+20
-11
lines changed
  • drivers/infiniband/core

1 file changed

+20
-11
lines changed

drivers/infiniband/core/rw.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,23 @@ static int rdma_rw_init_single_wr(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
273273
return 1;
274274
}
275275

276+
static void rdma_rw_unmap_sg(struct ib_device *dev, struct scatterlist *sg,
277+
u32 sg_cnt, enum dma_data_direction dir)
278+
{
279+
if (is_pci_p2pdma_page(sg_page(sg)))
280+
pci_p2pdma_unmap_sg(dev->dma_device, sg, sg_cnt, dir);
281+
else
282+
ib_dma_unmap_sg(dev, sg, sg_cnt, dir);
283+
}
284+
285+
static int rdma_rw_map_sg(struct ib_device *dev, struct scatterlist *sg,
286+
u32 sg_cnt, enum dma_data_direction dir)
287+
{
288+
if (is_pci_p2pdma_page(sg_page(sg)))
289+
return pci_p2pdma_map_sg(dev->dma_device, sg, sg_cnt, dir);
290+
return ib_dma_map_sg(dev, sg, sg_cnt, dir);
291+
}
292+
276293
/**
277294
* rdma_rw_ctx_init - initialize a RDMA READ/WRITE context
278295
* @ctx: context to initialize
@@ -295,11 +312,7 @@ int rdma_rw_ctx_init(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u8 port_num,
295312
struct ib_device *dev = qp->pd->device;
296313
int ret;
297314

298-
if (is_pci_p2pdma_page(sg_page(sg)))
299-
ret = pci_p2pdma_map_sg(dev->dma_device, sg, sg_cnt, dir);
300-
else
301-
ret = ib_dma_map_sg(dev, sg, sg_cnt, dir);
302-
315+
ret = rdma_rw_map_sg(dev, sg, sg_cnt, dir);
303316
if (!ret)
304317
return -ENOMEM;
305318
sg_cnt = ret;
@@ -338,7 +351,7 @@ int rdma_rw_ctx_init(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u8 port_num,
338351
return ret;
339352

340353
out_unmap_sg:
341-
ib_dma_unmap_sg(dev, sg, sg_cnt, dir);
354+
rdma_rw_unmap_sg(dev, sg, sg_cnt, dir);
342355
return ret;
343356
}
344357
EXPORT_SYMBOL(rdma_rw_ctx_init);
@@ -588,11 +601,7 @@ void rdma_rw_ctx_destroy(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u8 port_num,
588601
break;
589602
}
590603

591-
if (is_pci_p2pdma_page(sg_page(sg)))
592-
pci_p2pdma_unmap_sg(qp->pd->device->dma_device, sg,
593-
sg_cnt, dir);
594-
else
595-
ib_dma_unmap_sg(qp->pd->device, sg, sg_cnt, dir);
604+
rdma_rw_unmap_sg(qp->pd->device, sg, sg_cnt, dir);
596605
}
597606
EXPORT_SYMBOL(rdma_rw_ctx_destroy);
598607

0 commit comments

Comments
 (0)