aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gunthorpe <jgg@mellanox.com>2019-01-11 21:31:24 -0500
committerJason Gunthorpe <jgg@mellanox.com>2019-01-21 16:39:29 -0500
commit951d01b96f174ded6180e7e4e14929ef22e7da7e (patch)
tree209d4714e9a384d70d72255283ba2a96384705ad
parentd79af7242bb237d00e40092810e6828fbb929d2d (diff)
IB/mlx5: Fix how advise_mr() launches async work
Work must hold a kref on the ib_device otherwise the dev pointer can become free before the work runs. This can happen because the work is being pushed onto the system work queue which is not flushed during driver unregister. Remove the bogus use of 'reg_state': - While in uverbs the reg_state is guaranteed to always be REGISTERED - Testing reg_state with no locking is bogus. Use ib_device_try_get() to get back into a region that prevents unregistration. For now continue with a flow that is similar to the existing code. Fixes: 813e90b1aeaa ("IB/mlx5: Add advise_mr() support") Signed-off-by: Jason Gunthorpe <jgg@mellanox.com> Reviewed-by: Moni Shoua <monis@mellanox.com>
-rw-r--r--drivers/infiniband/hw/mlx5/odp.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/drivers/infiniband/hw/mlx5/odp.c b/drivers/infiniband/hw/mlx5/odp.c
index 01e0f6200631..4ee32964e1dd 100644
--- a/drivers/infiniband/hw/mlx5/odp.c
+++ b/drivers/infiniband/hw/mlx5/odp.c
@@ -1595,10 +1595,12 @@ static void mlx5_ib_prefetch_mr_work(struct work_struct *work)
1595 struct prefetch_mr_work *w = 1595 struct prefetch_mr_work *w =
1596 container_of(work, struct prefetch_mr_work, work); 1596 container_of(work, struct prefetch_mr_work, work);
1597 1597
1598 if (w->dev->ib_dev.reg_state == IB_DEV_REGISTERED) 1598 if (ib_device_try_get(&w->dev->ib_dev)) {
1599 mlx5_ib_prefetch_sg_list(w->dev, w->pf_flags, w->sg_list, 1599 mlx5_ib_prefetch_sg_list(w->dev, w->pf_flags, w->sg_list,
1600 w->num_sge); 1600 w->num_sge);
1601 1601 ib_device_put(&w->dev->ib_dev);
1602 }
1603 put_device(&w->dev->ib_dev.dev);
1602 kfree(w); 1604 kfree(w);
1603} 1605}
1604 1606
@@ -1617,15 +1619,13 @@ int mlx5_ib_advise_mr_prefetch(struct ib_pd *pd,
1617 return mlx5_ib_prefetch_sg_list(dev, pf_flags, sg_list, 1619 return mlx5_ib_prefetch_sg_list(dev, pf_flags, sg_list,
1618 num_sge); 1620 num_sge);
1619 1621
1620 if (dev->ib_dev.reg_state != IB_DEV_REGISTERED)
1621 return -ENODEV;
1622
1623 work = kvzalloc(struct_size(work, sg_list, num_sge), GFP_KERNEL); 1622 work = kvzalloc(struct_size(work, sg_list, num_sge), GFP_KERNEL);
1624 if (!work) 1623 if (!work)
1625 return -ENOMEM; 1624 return -ENOMEM;
1626 1625
1627 memcpy(work->sg_list, sg_list, num_sge * sizeof(struct ib_sge)); 1626 memcpy(work->sg_list, sg_list, num_sge * sizeof(struct ib_sge));
1628 1627
1628 get_device(&dev->ib_dev.dev);
1629 work->dev = dev; 1629 work->dev = dev;
1630 work->pf_flags = pf_flags; 1630 work->pf_flags = pf_flags;
1631 work->num_sge = num_sge; 1631 work->num_sge = num_sge;