[PATCH] RDMA: Fix software RDMA drivers for dma mapping error

From: Parav Pandit
Date: Tue Oct 27 2020 - 08:20:07 EST


A cited commit in fixes tag avoided setting dma_mask of the ib_device.
Commit [1] made dma_mask as mandetory field to be setup even for
dma_virt_ops based dma devices.

Fix it by setting empty DMA MASK for software based RDMA devices.

[1] commit: f959dcd6ddfd2 ("dma-direct: Fix potential NULL pointer derefere=
nce")

Reported-by: syzbot+34dc2fea3478e659af01@xxxxxxxxxxxxxxxxxxxxxxxxx
Fixes: e0477b34d9d1 ("RDMA: Explicitly pass in the dma_device to ib_registe=
r_device")
Signed-off-by: Parav Pandit <parav@xxxxxxxxxx>
---
drivers/infiniband/sw/rdmavt/vt.c | 5 +++--
drivers/infiniband/sw/rxe/rxe_verbs.c | 4 +++-
drivers/infiniband/sw/siw/siw_main.c | 5 +++--
3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/infiniband/sw/rdmavt/vt.c b/drivers/infiniband/sw/rdma=
vt/vt.c
index 52218684ad4a..1b456f4d4fcf 100644
--- a/drivers/infiniband/sw/rdmavt/vt.c
+++ b/drivers/infiniband/sw/rdmavt/vt.c
@@ -580,8 +580,9 @@ int rvt_register_device(struct rvt_dev_info *rdi)
=20
/* DMA Operations */
rdi->ibdev.dev.dma_parms =3D rdi->ibdev.dev.parent->dma_parms;
- dma_set_coherent_mask(&rdi->ibdev.dev,
- rdi->ibdev.dev.parent->coherent_dma_mask);
+ ret =3D dma_coerce_mask_and_coherent(&rdi->ibdev.dev, DMA_MASK_NONE);
+ if (ret)
+ goto bail_wss;
=20
/* Protection Domain */
spin_lock_init(&rdi->n_pds_lock);
diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/=
rxe/rxe_verbs.c
index 1fc022362fbe..357787688293 100644
--- a/drivers/infiniband/sw/rxe/rxe_verbs.c
+++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
@@ -1130,7 +1130,9 @@ int rxe_register_device(struct rxe_dev *rxe, const ch=
ar *ibdev_name)
rxe->ndev->dev_addr);
dev->dev.dma_parms =3D &rxe->dma_parms;
dma_set_max_seg_size(&dev->dev, UINT_MAX);
- dma_set_coherent_mask(&dev->dev, dma_get_required_mask(&dev->dev));
+ err =3D dma_coerce_mask_and_coherent(&dev->dev, DMA_MASK_NONE);
+ if (err)
+ return err;
=20
dev->uverbs_cmd_mask =3D BIT_ULL(IB_USER_VERBS_CMD_GET_CONTEXT)
| BIT_ULL(IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL)
diff --git a/drivers/infiniband/sw/siw/siw_main.c b/drivers/infiniband/sw/s=
iw/siw_main.c
index ca8bc7296867..d3dc50a42dab 100644
--- a/drivers/infiniband/sw/siw/siw_main.c
+++ b/drivers/infiniband/sw/siw/siw_main.c
@@ -384,8 +384,9 @@ static struct siw_device *siw_device_create(struct net_=
device *netdev)
base_dev->dev.parent =3D parent;
base_dev->dev.dma_parms =3D &sdev->dma_parms;
dma_set_max_seg_size(&base_dev->dev, UINT_MAX);
- dma_set_coherent_mask(&base_dev->dev,
- dma_get_required_mask(&base_dev->dev));
+ if (dma_coerce_mask_and_coherent(&base_dev->dev, DMA_MASK_NONE))
+ goto error;
+
base_dev->num_comp_vectors =3D num_possible_cpus();
=20
xa_init_flags(&sdev->qp_xa, XA_FLAGS_ALLOC1);
--=20
2.26.2