RDMA/core: Allow the ioctl layer to abort a fully created uobject
While creating a uobject every create reaches a point where the uobject is fully initialized. For ioctls that go on to copy_to_user this means they need to open code the destruction of a fully created uobject - ie the RDMA_REMOVE_DESTROY sort of flow. Open coding this creates bugs, eg the CQ does not properly flush the events list when it does its error unwind. Provide a uverbs_finalize_uobj_create() function which indicates that the uobject is fully initialized and that abort should call to destroy_hw to destroy the uobj->object and related. Methods can call this function if they go on to have error cases after setting uobj->object. Once done those error cases can simply do return, without an error unwind. Link: https://lore.kernel.org/r/20200519072711.257271-2-leon@kernel.org Signed-off-by: Yishai Hadas <yishaih@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
このコミットが含まれているのは:
@@ -2218,14 +2218,12 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_UMEM_REG)(
|
||||
obj->mdev = dev->mdev;
|
||||
uobj->object = obj;
|
||||
devx_obj_build_destroy_cmd(cmd.in, cmd.out, obj->dinbox, &obj->dinlen, &obj_id);
|
||||
err = uverbs_copy_to(attrs, MLX5_IB_ATTR_DEVX_UMEM_REG_OUT_ID, &obj_id, sizeof(obj_id));
|
||||
if (err)
|
||||
goto err_umem_destroy;
|
||||
uverbs_finalize_uobj_create(attrs, MLX5_IB_ATTR_DEVX_UMEM_REG_HANDLE);
|
||||
|
||||
return 0;
|
||||
err = uverbs_copy_to(attrs, MLX5_IB_ATTR_DEVX_UMEM_REG_OUT_ID, &obj_id,
|
||||
sizeof(obj_id));
|
||||
return err;
|
||||
|
||||
err_umem_destroy:
|
||||
mlx5_cmd_exec(obj->mdev, obj->dinbox, obj->dinlen, cmd.out, sizeof(cmd.out));
|
||||
err_umem_release:
|
||||
ib_umem_release(obj->umem);
|
||||
err_obj_free:
|
||||
|
@@ -6187,26 +6187,20 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_VAR_OBJ_ALLOC)(
|
||||
mmap_offset = mlx5_entry_to_mmap_offset(entry);
|
||||
length = entry->rdma_entry.npages * PAGE_SIZE;
|
||||
uobj->object = entry;
|
||||
uverbs_finalize_uobj_create(attrs, MLX5_IB_ATTR_VAR_OBJ_ALLOC_HANDLE);
|
||||
|
||||
err = uverbs_copy_to(attrs, MLX5_IB_ATTR_VAR_OBJ_ALLOC_MMAP_OFFSET,
|
||||
&mmap_offset, sizeof(mmap_offset));
|
||||
if (err)
|
||||
goto err;
|
||||
return err;
|
||||
|
||||
err = uverbs_copy_to(attrs, MLX5_IB_ATTR_VAR_OBJ_ALLOC_PAGE_ID,
|
||||
&entry->page_idx, sizeof(entry->page_idx));
|
||||
if (err)
|
||||
goto err;
|
||||
return err;
|
||||
|
||||
err = uverbs_copy_to(attrs, MLX5_IB_ATTR_VAR_OBJ_ALLOC_MMAP_LENGTH,
|
||||
&length, sizeof(length));
|
||||
if (err)
|
||||
goto err;
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
rdma_user_mmap_entry_remove(&entry->rdma_entry);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -6320,26 +6314,20 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_UAR_OBJ_ALLOC)(
|
||||
mmap_offset = mlx5_entry_to_mmap_offset(entry);
|
||||
length = entry->rdma_entry.npages * PAGE_SIZE;
|
||||
uobj->object = entry;
|
||||
uverbs_finalize_uobj_create(attrs, MLX5_IB_ATTR_UAR_OBJ_ALLOC_HANDLE);
|
||||
|
||||
err = uverbs_copy_to(attrs, MLX5_IB_ATTR_UAR_OBJ_ALLOC_MMAP_OFFSET,
|
||||
&mmap_offset, sizeof(mmap_offset));
|
||||
if (err)
|
||||
goto err;
|
||||
return err;
|
||||
|
||||
err = uverbs_copy_to(attrs, MLX5_IB_ATTR_UAR_OBJ_ALLOC_PAGE_ID,
|
||||
&entry->page_idx, sizeof(entry->page_idx));
|
||||
if (err)
|
||||
goto err;
|
||||
return err;
|
||||
|
||||
err = uverbs_copy_to(attrs, MLX5_IB_ATTR_UAR_OBJ_ALLOC_MMAP_LENGTH,
|
||||
&length, sizeof(length));
|
||||
if (err)
|
||||
goto err;
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
rdma_user_mmap_entry_remove(&entry->rdma_entry);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@@ -69,17 +69,14 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_PP_OBJ_ALLOC)(
|
||||
if (err)
|
||||
goto err;
|
||||
|
||||
err = uverbs_copy_to(attrs, MLX5_IB_ATTR_PP_OBJ_ALLOC_INDEX,
|
||||
&pp_entry->index, sizeof(pp_entry->index));
|
||||
if (err)
|
||||
goto clean;
|
||||
|
||||
pp_entry->mdev = dev->mdev;
|
||||
uobj->object = pp_entry;
|
||||
return 0;
|
||||
uverbs_finalize_uobj_create(attrs, MLX5_IB_ATTR_PP_OBJ_ALLOC_HANDLE);
|
||||
|
||||
err = uverbs_copy_to(attrs, MLX5_IB_ATTR_PP_OBJ_ALLOC_INDEX,
|
||||
&pp_entry->index, sizeof(pp_entry->index));
|
||||
return err;
|
||||
|
||||
clean:
|
||||
mlx5_rl_remove_rate_raw(dev->mdev, pp_entry->index);
|
||||
err:
|
||||
kfree(pp_entry);
|
||||
return err;
|
||||
|
新しいイシューから参照
ユーザーをブロックする