RDMA/core: Make invalidate_range a device operation
authorMoni Shoua <monis@mellanox.com>
Mon, 19 Aug 2019 11:17:08 +0000 (14:17 +0300)
committerJason Gunthorpe <jgg@mellanox.com>
Wed, 21 Aug 2019 17:08:43 +0000 (14:08 -0300)
The callback function 'invalidate_range' is implemented in a driver so the
place for it is in the ib_device_ops structure and not in ib_ucontext.

Signed-off-by: Moni Shoua <monis@mellanox.com>
Reviewed-by: Guy Levi <guyle@mellanox.com>
Reviewed-by: Jason Gunthorpe <jgg@mellanox.com>
Link: https://lore.kernel.org/r/20190819111710.18440-11-leon@kernel.org
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/core/device.c
drivers/infiniband/core/umem_odp.c
drivers/infiniband/core/uverbs_cmd.c
drivers/infiniband/hw/mlx5/main.c
drivers/infiniband/hw/mlx5/odp.c
include/rdma/ib_verbs.h

index ea8661a00651bba68f496a7bd2a398b9289f9a68..b5631b8a03971da6ed8862d035168b87e3f350f3 100644 (file)
@@ -2562,6 +2562,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
        SET_DEVICE_OP(dev_ops, get_vf_config);
        SET_DEVICE_OP(dev_ops, get_vf_stats);
        SET_DEVICE_OP(dev_ops, init_port);
+       SET_DEVICE_OP(dev_ops, invalidate_range);
        SET_DEVICE_OP(dev_ops, iw_accept);
        SET_DEVICE_OP(dev_ops, iw_add_ref);
        SET_DEVICE_OP(dev_ops, iw_connect);
index 72765b110f4b44ff1c3c748545c8ede246d50327..32fb0b579dec552c2ce5733534a7213dc147ec76 100644 (file)
@@ -96,7 +96,7 @@ static void ib_umem_notifier_release(struct mmu_notifier *mn,
                 */
                ib_umem_notifier_start_account(umem_odp);
                complete_all(&umem_odp->notifier_completion);
-               umem_odp->umem.context->invalidate_range(
+               umem_odp->umem.context->device->ops.invalidate_range(
                        umem_odp, ib_umem_start(umem_odp),
                        ib_umem_end(umem_odp));
        }
@@ -109,7 +109,7 @@ static int invalidate_range_start_trampoline(struct ib_umem_odp *item,
                                             u64 start, u64 end, void *cookie)
 {
        ib_umem_notifier_start_account(item);
-       item->umem.context->invalidate_range(item, start, end);
+       item->umem.context->device->ops.invalidate_range(item, start, end);
        return 0;
 }
 
@@ -385,7 +385,7 @@ struct ib_umem_odp *ib_umem_odp_alloc_implicit(struct ib_udata *udata,
 
        if (!context)
                return ERR_PTR(-EIO);
-       if (WARN_ON_ONCE(!context->invalidate_range))
+       if (WARN_ON_ONCE(!context->device->ops.invalidate_range))
                return ERR_PTR(-EINVAL);
 
        umem_odp = kzalloc(sizeof(*umem_odp), GFP_KERNEL);
@@ -479,7 +479,7 @@ struct ib_umem_odp *ib_umem_odp_get(struct ib_udata *udata, unsigned long addr,
                return ERR_PTR(-EIO);
 
        if (WARN_ON_ONCE(!(access & IB_ACCESS_ON_DEMAND)) ||
-           WARN_ON_ONCE(!context->invalidate_range))
+           WARN_ON_ONCE(!context->device->ops.invalidate_range))
                return ERR_PTR(-EINVAL);
 
        umem_odp = kzalloc(sizeof(struct ib_umem_odp), GFP_KERNEL);
@@ -607,7 +607,7 @@ out:
 
        if (remove_existing_mapping) {
                ib_umem_notifier_start_account(umem_odp);
-               context->invalidate_range(
+               dev->ops.invalidate_range(
                        umem_odp,
                        ib_umem_start(umem_odp) +
                                (page_index << umem_odp->page_shift),
index 7ddd0e5bc6b3419f79217a59030037c7b5f5b14c..8f4fd4fac1593afa89496d881657d1682412b706 100644 (file)
@@ -275,8 +275,6 @@ static int ib_uverbs_get_context(struct uverbs_attr_bundle *attrs)
        ret = ib_dev->ops.alloc_ucontext(ucontext, &attrs->driver_udata);
        if (ret)
                goto err_file;
-       if (!(ib_dev->attrs.device_cap_flags & IB_DEVICE_ON_DEMAND_PAGING))
-               ucontext->invalidate_range = NULL;
 
        rdma_restrack_uadd(&ucontext->res);
 
index e12a4404096b6da2ec45f27104b49f6fd5ec4bf6..7d5c2763b691cd501ac6f300fc45b57ec572dd6b 100644 (file)
@@ -1867,10 +1867,6 @@ static int mlx5_ib_alloc_ucontext(struct ib_ucontext *uctx,
        if (err)
                goto out_sys_pages;
 
-       if (ibdev->attrs.device_cap_flags & IB_DEVICE_ON_DEMAND_PAGING)
-               context->ibucontext.invalidate_range =
-                       &mlx5_ib_invalidate_range;
-
        if (req.flags & MLX5_IB_ALLOC_UCTX_DEVX) {
                err = mlx5_ib_devx_create(dev, true);
                if (err < 0)
index a660dc2b21f43d1c5aca87515bc8e91d532fde67..6d940d8f5247cf7cbd0f9f572c5bc6233e926f1b 100644 (file)
@@ -1612,6 +1612,7 @@ void mlx5_odp_init_mr_cache_entry(struct mlx5_cache_ent *ent)
 
 static const struct ib_device_ops mlx5_ib_dev_odp_ops = {
        .advise_mr = mlx5_ib_advise_mr,
+       .invalidate_range = mlx5_ib_invalidate_range,
 };
 
 int mlx5_ib_odp_init_one(struct mlx5_ib_dev *dev)
index 4f225175cb91ef6e43a75b29e9b51084b31db413..c2b39dda44cc6fc0c07492ef8d28b674c95d825b 100644 (file)
@@ -1417,8 +1417,6 @@ struct ib_ucontext {
 
        bool cleanup_retryable;
 
-       void (*invalidate_range)(struct ib_umem_odp *umem_odp,
-                                unsigned long start, unsigned long end);
        struct mutex per_mm_list_lock;
        struct list_head per_mm_list;
 
@@ -2378,6 +2376,8 @@ struct ib_device_ops {
                            u64 iova);
        int (*unmap_fmr)(struct list_head *fmr_list);
        int (*dealloc_fmr)(struct ib_fmr *fmr);
+       void (*invalidate_range)(struct ib_umem_odp *umem_odp,
+                                unsigned long start, unsigned long end);
        int (*attach_mcast)(struct ib_qp *qp, union ib_gid *gid, u16 lid);
        int (*detach_mcast)(struct ib_qp *qp, union ib_gid *gid, u16 lid);
        struct ib_xrcd *(*alloc_xrcd)(struct ib_device *device,