Skip to content

Commit 5a7a9e0

Browse files
Christoph Hellwigjgunthorpe
authored andcommitted
RDMA/core: remove use of dma_virt_ops
Use the ib_dma_* helpers to skip the DMA translation instead. This removes the last user if dma_virt_ops and keeps the weird layering violation inside the RDMA core instead of burderning the DMA mapping subsystems with it. This also means the software RDMA drivers now don't have to mess with DMA parameters that are not relevant to them at all, and that in the future we can use PCI P2P transfers even for software RDMA, as there is no first fake layer of DMA mapping that the P2P DMA support. Link: https://lore.kernel.org/r/20201106181941.1878556-8-hch@lst.de Signed-off-by: Christoph Hellwig <hch@lst.de> Tested-by: Mike Marciniszyn <mike.marciniszyn@cornelisnetworks.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 42f2611 commit 5a7a9e0

13 files changed

Lines changed: 81 additions & 76 deletions

File tree

‎drivers/infiniband/core/device.c‎

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,25 +1209,6 @@ static int assign_name(struct ib_device *device, const char *name)
12091209
return ret;
12101210
}
12111211

1212-
static void setup_dma_device(struct ib_device *device,
1213-
struct device *dma_device)
1214-
{
1215-
/*
1216-
* If the caller does not provide a DMA capable device then the IB
1217-
* device will be used. In this case the caller should fully setup the
1218-
* ibdev for DMA. This usually means using dma_virt_ops.
1219-
*/
1220-
#ifdef CONFIG_DMA_VIRT_OPS
1221-
if (!dma_device) {
1222-
device->dev.dma_ops = &dma_virt_ops;
1223-
dma_device = &device->dev;
1224-
}
1225-
#endif
1226-
WARN_ON(!dma_device);
1227-
device->dma_device = dma_device;
1228-
WARN_ON(!device->dma_device->dma_parms);
1229-
}
1230-
12311212
/*
12321213
* setup_device() allocates memory and sets up data that requires calling the
12331214
* device ops, this is the only reason these actions are not done during
@@ -1373,7 +1354,14 @@ int ib_register_device(struct ib_device *device, const char *name,
13731354
if (ret)
13741355
return ret;
13751356

1376-
setup_dma_device(device, dma_device);
1357+
/*
1358+
* If the caller does not provide a DMA capable device then the IB core
1359+
* will set up ib_sge and scatterlist structures that stash the kernel
1360+
* virtual address into the address field.
1361+
*/
1362+
WARN_ON(dma_device && !dma_device->dma_parms);
1363+
device->dma_device = dma_device;
1364+
13771365
ret = setup_device(device);
13781366
if (ret)
13791367
return ret;
@@ -2708,6 +2696,21 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
27082696
}
27092697
EXPORT_SYMBOL(ib_set_device_ops);
27102698

2699+
#ifdef CONFIG_INFINIBAND_VIRT_DMA
2700+
int ib_dma_virt_map_sg(struct ib_device *dev, struct scatterlist *sg, int nents)
2701+
{
2702+
struct scatterlist *s;
2703+
int i;
2704+
2705+
for_each_sg(sg, s, nents, i) {
2706+
sg_dma_address(s) = (uintptr_t)sg_virt(s);
2707+
sg_dma_len(s) = s->length;
2708+
}
2709+
return nents;
2710+
}
2711+
EXPORT_SYMBOL(ib_dma_virt_map_sg);
2712+
#endif /* CONFIG_INFINIBAND_VIRT_DMA */
2713+
27112714
static const struct rdma_nl_cbs ibnl_ls_cb_table[RDMA_NL_LS_NUM_OPS] = {
27122715
[RDMA_NL_LS_OP_RESOLVE] = {
27132716
.doit = ib_nl_handle_resolve_resp,

‎drivers/infiniband/core/rw.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,11 @@ static void rdma_rw_unmap_sg(struct ib_device *dev, struct scatterlist *sg,
285285
static int rdma_rw_map_sg(struct ib_device *dev, struct scatterlist *sg,
286286
u32 sg_cnt, enum dma_data_direction dir)
287287
{
288-
if (is_pci_p2pdma_page(sg_page(sg)))
288+
if (is_pci_p2pdma_page(sg_page(sg))) {
289+
if (WARN_ON_ONCE(ib_uses_virt_dma(dev)))
290+
return 0;
289291
return pci_p2pdma_map_sg(dev->dma_device, sg, sg_cnt, dir);
292+
}
290293
return ib_dma_map_sg(dev, sg, sg_cnt, dir);
291294
}
292295

‎drivers/infiniband/sw/rdmavt/Kconfig‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ config INFINIBAND_RDMAVT
44
depends on INFINIBAND_VIRT_DMA
55
depends on X86_64
66
depends on PCI
7-
select DMA_VIRT_OPS
87
help
98
This is a common software verbs provider for RDMA networks.

‎drivers/infiniband/sw/rdmavt/mr.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,6 @@ static void __rvt_free_mr(struct rvt_mr *mr)
324324
* @acc: access flags
325325
*
326326
* Return: the memory region on success, otherwise returns an errno.
327-
* Note that all DMA addresses should be created via the functions in
328-
* struct dma_virt_ops.
329327
*/
330328
struct ib_mr *rvt_get_dma_mr(struct ib_pd *pd, int acc)
331329
{
@@ -766,7 +764,7 @@ int rvt_lkey_ok(struct rvt_lkey_table *rkt, struct rvt_pd *pd,
766764

767765
/*
768766
* We use LKEY == zero for kernel virtual addresses
769-
* (see rvt_get_dma_mr() and dma_virt_ops).
767+
* (see rvt_get_dma_mr()).
770768
*/
771769
if (sge->lkey == 0) {
772770
struct rvt_dev_info *dev = ib_to_rvt(pd->ibpd.device);
@@ -877,7 +875,7 @@ int rvt_rkey_ok(struct rvt_qp *qp, struct rvt_sge *sge,
877875

878876
/*
879877
* We use RKEY == zero for kernel virtual addresses
880-
* (see rvt_get_dma_mr() and dma_virt_ops).
878+
* (see rvt_get_dma_mr()).
881879
*/
882880
rcu_read_lock();
883881
if (rkey == 0) {

‎drivers/infiniband/sw/rdmavt/vt.c‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ static noinline int check_support(struct rvt_dev_info *rdi, int verb)
525525
int rvt_register_device(struct rvt_dev_info *rdi)
526526
{
527527
int ret = 0, i;
528-
u64 dma_mask;
529528

530529
if (!rdi)
531530
return -EINVAL;
@@ -580,13 +579,6 @@ int rvt_register_device(struct rvt_dev_info *rdi)
580579
/* Completion queues */
581580
spin_lock_init(&rdi->n_cqs_lock);
582581

583-
/* DMA Operations */
584-
rdi->ibdev.dev.dma_parms = rdi->ibdev.dev.parent->dma_parms;
585-
dma_mask = IS_ENABLED(CONFIG_64BIT) ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32);
586-
ret = dma_coerce_mask_and_coherent(&rdi->ibdev.dev, dma_mask);
587-
if (ret)
588-
goto bail_wss;
589-
590582
/* Protection Domain */
591583
spin_lock_init(&rdi->n_pds_lock);
592584
rdi->n_pds_allocated = 0;

‎drivers/infiniband/sw/rxe/Kconfig‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ config RDMA_RXE
55
depends on INFINIBAND_VIRT_DMA
66
select NET_UDP_TUNNEL
77
select CRYPTO_CRC32
8-
select DMA_VIRT_OPS
98
help
109
This driver implements the InfiniBand RDMA transport over
1110
the Linux network stack. It enables a system with a

‎drivers/infiniband/sw/rxe/rxe_verbs.c‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,6 @@ int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name)
11281128
int err;
11291129
struct ib_device *dev = &rxe->ib_dev;
11301130
struct crypto_shash *tfm;
1131-
u64 dma_mask;
11321131

11331132
strlcpy(dev->node_desc, "rxe", sizeof(dev->node_desc));
11341133

@@ -1139,12 +1138,6 @@ int rxe_register_device(struct rxe_dev *rxe, const char *ibdev_name)
11391138
dev->local_dma_lkey = 0;
11401139
addrconf_addr_eui48((unsigned char *)&dev->node_guid,
11411140
rxe->ndev->dev_addr);
1142-
dev->dev.dma_parms = &rxe->dma_parms;
1143-
dma_set_max_seg_size(&dev->dev, UINT_MAX);
1144-
dma_mask = IS_ENABLED(CONFIG_64BIT) ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32);
1145-
err = dma_coerce_mask_and_coherent(&dev->dev, dma_mask);
1146-
if (err)
1147-
return err;
11481141

11491142
dev->uverbs_cmd_mask |= BIT_ULL(IB_USER_VERBS_CMD_POST_SEND) |
11501143
BIT_ULL(IB_USER_VERBS_CMD_REQ_NOTIFY_CQ);

‎drivers/infiniband/sw/rxe/rxe_verbs.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ struct rxe_port {
351351
struct rxe_dev {
352352
struct ib_device ib_dev;
353353
struct ib_device_attr attr;
354-
struct device_dma_parameters dma_parms;
355354
int max_ucontext;
356355
int max_inline_data;
357356
struct mutex usdev_lock;

‎drivers/infiniband/sw/siw/Kconfig‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ config RDMA_SIW
22
tristate "Software RDMA over TCP/IP (iWARP) driver"
33
depends on INET && INFINIBAND && LIBCRC32C
44
depends on INFINIBAND_VIRT_DMA
5-
select DMA_VIRT_OPS
65
help
76
This driver implements the iWARP RDMA transport over
87
the Linux TCP/IP network stack. It enables a system with a

‎drivers/infiniband/sw/siw/siw.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ struct siw_pd {
6969

7070
struct siw_device {
7171
struct ib_device base_dev;
72-
struct device_dma_parameters dma_parms;
7372
struct net_device *netdev;
7473
struct siw_dev_cap attrs;
7574

0 commit comments

Comments
 (0)