Skip to content

Commit e83f0ec

Browse files
committed
IB/uverbs: Do not pass struct ib_device to the ioctl methods
This does the same as the patch before, except for ioctl. The rules are the same, but for the ioctl methods the core code handles setting up the uobject. - Retrieve the ib_dev from the uobject->context->device. This is safe under ioctl as the core has already done rdma_alloc_begin_uobject and so CREATE calls are entirely protected by the rwsem. - Retrieve the ib_dev from uobject->object - Call ib_uverbs_get_ucontext() Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent bbd51e8 commit e83f0ec

File tree

11 files changed

+78
-94
lines changed

11 files changed

+78
-94
lines changed

drivers/infiniband/core/uverbs_ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ static int uverbs_handle_method(struct ib_uverbs_attr __user *uattr_ptr,
354354
goto cleanup;
355355
}
356356

357-
ret = method_spec->handler(ibdev, ufile, attr_bundle);
357+
ret = method_spec->handler(ufile, attr_bundle);
358358

359359
if (destroy_attr) {
360360
uobj_put_destroy(destroy_attr->uobject);

drivers/infiniband/core/uverbs_std_types.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ static int uverbs_hot_unplug_completion_event_file(struct ib_uobject *uobj,
210210
return 0;
211211
};
212212

213-
int uverbs_destroy_def_handler(struct ib_device *ib_dev,
214-
struct ib_uverbs_file *file,
213+
int uverbs_destroy_def_handler(struct ib_uverbs_file *file,
215214
struct uverbs_attr_bundle *attrs)
216215
{
217216
return 0;

drivers/infiniband/core/uverbs_std_types_counters.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ static int uverbs_free_counters(struct ib_uobject *uobject,
4747
return counters->device->destroy_counters(counters);
4848
}
4949

50-
static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_CREATE)(struct ib_device *ib_dev,
51-
struct ib_uverbs_file *file,
52-
struct uverbs_attr_bundle *attrs)
50+
static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_CREATE)(
51+
struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
5352
{
53+
struct ib_uobject *uobj = uverbs_attr_get_uobject(
54+
attrs, UVERBS_ATTR_CREATE_COUNTERS_HANDLE);
55+
struct ib_device *ib_dev = uobj->context->device;
5456
struct ib_counters *counters;
55-
struct ib_uobject *uobj;
5657
int ret;
5758

5859
/*
@@ -63,7 +64,6 @@ static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_CREATE)(struct ib_device *ib_de
6364
if (!ib_dev->create_counters)
6465
return -EOPNOTSUPP;
6566

66-
uobj = uverbs_attr_get_uobject(attrs, UVERBS_ATTR_CREATE_COUNTERS_HANDLE);
6767
counters = ib_dev->create_counters(ib_dev, attrs);
6868
if (IS_ERR(counters)) {
6969
ret = PTR_ERR(counters);
@@ -81,17 +81,16 @@ static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_CREATE)(struct ib_device *ib_de
8181
return ret;
8282
}
8383

84-
static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_READ)(struct ib_device *ib_dev,
85-
struct ib_uverbs_file *file,
86-
struct uverbs_attr_bundle *attrs)
84+
static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_READ)(
85+
struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
8786
{
8887
struct ib_counters_read_attr read_attr = {};
8988
const struct uverbs_attr *uattr;
9089
struct ib_counters *counters =
9190
uverbs_attr_get_obj(attrs, UVERBS_ATTR_READ_COUNTERS_HANDLE);
9291
int ret;
9392

94-
if (!ib_dev->read_counters)
93+
if (!counters->device->read_counters)
9594
return -EOPNOTSUPP;
9695

9796
if (!atomic_read(&counters->usecnt))
@@ -110,9 +109,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_READ)(struct ib_device *ib_dev,
110109
if (!read_attr.counters_buff)
111110
return -ENOMEM;
112111

113-
ret = ib_dev->read_counters(counters,
114-
&read_attr,
115-
attrs);
112+
ret = counters->device->read_counters(counters, &read_attr, attrs);
116113
if (ret)
117114
goto err_read;
118115

drivers/infiniband/core/uverbs_std_types_cq.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ static int uverbs_free_cq(struct ib_uobject *uobject,
5757
return ret;
5858
}
5959

60-
static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(struct ib_device *ib_dev,
61-
struct ib_uverbs_file *file,
62-
struct uverbs_attr_bundle *attrs)
60+
static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(
61+
struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
6362
{
64-
struct ib_ucq_object *obj;
63+
struct ib_ucq_object *obj = container_of(
64+
uverbs_attr_get_uobject(attrs, UVERBS_ATTR_CREATE_CQ_HANDLE),
65+
typeof(*obj), uobject);
66+
struct ib_device *ib_dev = obj->uobject.context->device;
6567
struct ib_udata uhw;
6668
int ret;
6769
u64 user_handle;
@@ -104,9 +106,6 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(struct ib_device *ib_dev,
104106
goto err_event_file;
105107
}
106108

107-
obj = container_of(uverbs_attr_get_uobject(attrs,
108-
UVERBS_ATTR_CREATE_CQ_HANDLE),
109-
typeof(*obj), uobject);
110109
obj->comp_events_reported = 0;
111110
obj->async_events_reported = 0;
112111
INIT_LIST_HEAD(&obj->comp_list);
@@ -173,9 +172,8 @@ DECLARE_UVERBS_NAMED_METHOD(
173172
UA_MANDATORY),
174173
UVERBS_ATTR_UHW());
175174

176-
static int UVERBS_HANDLER(UVERBS_METHOD_CQ_DESTROY)(struct ib_device *ib_dev,
177-
struct ib_uverbs_file *file,
178-
struct uverbs_attr_bundle *attrs)
175+
static int UVERBS_HANDLER(UVERBS_METHOD_CQ_DESTROY)(
176+
struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
179177
{
180178
struct ib_uobject *uobj =
181179
uverbs_attr_get_uobject(attrs, UVERBS_ATTR_DESTROY_CQ_HANDLE);

drivers/infiniband/core/uverbs_std_types_dm.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ static int uverbs_free_dm(struct ib_uobject *uobject,
4646
return dm->device->dealloc_dm(dm);
4747
}
4848

49-
static int UVERBS_HANDLER(UVERBS_METHOD_DM_ALLOC)(struct ib_device *ib_dev,
50-
struct ib_uverbs_file *file,
51-
struct uverbs_attr_bundle *attrs)
49+
static int
50+
UVERBS_HANDLER(UVERBS_METHOD_DM_ALLOC)(struct ib_uverbs_file *file,
51+
struct uverbs_attr_bundle *attrs)
5252
{
5353
struct ib_dm_alloc_attr attr = {};
54-
struct ib_uobject *uobj;
54+
struct ib_uobject *uobj =
55+
uverbs_attr_get(attrs, UVERBS_ATTR_ALLOC_DM_HANDLE)
56+
->obj_attr.uobject;
57+
struct ib_device *ib_dev = uobj->context->device;
5558
struct ib_dm *dm;
5659
int ret;
5760

@@ -68,8 +71,6 @@ static int UVERBS_HANDLER(UVERBS_METHOD_DM_ALLOC)(struct ib_device *ib_dev,
6871
if (ret)
6972
return ret;
7073

71-
uobj = uverbs_attr_get(attrs, UVERBS_ATTR_ALLOC_DM_HANDLE)->obj_attr.uobject;
72-
7374
dm = ib_dev->alloc_dm(ib_dev, uobj->context, &attr, attrs);
7475
if (IS_ERR(dm))
7576
return PTR_ERR(dm);

drivers/infiniband/core/uverbs_std_types_flow_action.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,13 @@ static int parse_flow_action_esp(struct ib_device *ib_dev,
304304
return 0;
305305
}
306306

307-
static int UVERBS_HANDLER(UVERBS_METHOD_FLOW_ACTION_ESP_CREATE)(struct ib_device *ib_dev,
308-
struct ib_uverbs_file *file,
309-
struct uverbs_attr_bundle *attrs)
307+
static int UVERBS_HANDLER(UVERBS_METHOD_FLOW_ACTION_ESP_CREATE)(
308+
struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
310309
{
310+
struct ib_uobject *uobj = uverbs_attr_get_uobject(
311+
attrs, UVERBS_ATTR_CREATE_FLOW_ACTION_ESP_HANDLE);
312+
struct ib_device *ib_dev = uobj->context->device;
311313
int ret;
312-
struct ib_uobject *uobj;
313314
struct ib_flow_action *action;
314315
struct ib_flow_action_esp_attr esp_attr = {};
315316

@@ -321,8 +322,6 @@ static int UVERBS_HANDLER(UVERBS_METHOD_FLOW_ACTION_ESP_CREATE)(struct ib_device
321322
return ret;
322323

323324
/* No need to check as this attribute is marked as MANDATORY */
324-
uobj = uverbs_attr_get_uobject(
325-
attrs, UVERBS_ATTR_CREATE_FLOW_ACTION_ESP_HANDLE);
326325
action = ib_dev->create_flow_action_esp(ib_dev, &esp_attr.hdr, attrs);
327326
if (IS_ERR(action))
328327
return PTR_ERR(action);
@@ -336,32 +335,28 @@ static int UVERBS_HANDLER(UVERBS_METHOD_FLOW_ACTION_ESP_CREATE)(struct ib_device
336335
return 0;
337336
}
338337

339-
static int UVERBS_HANDLER(UVERBS_METHOD_FLOW_ACTION_ESP_MODIFY)(struct ib_device *ib_dev,
340-
struct ib_uverbs_file *file,
341-
struct uverbs_attr_bundle *attrs)
338+
static int UVERBS_HANDLER(UVERBS_METHOD_FLOW_ACTION_ESP_MODIFY)(
339+
struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
342340
{
341+
struct ib_uobject *uobj = uverbs_attr_get_uobject(
342+
attrs, UVERBS_ATTR_MODIFY_FLOW_ACTION_ESP_HANDLE);
343+
struct ib_flow_action *action = uobj->object;
343344
int ret;
344-
struct ib_uobject *uobj;
345-
struct ib_flow_action *action;
346345
struct ib_flow_action_esp_attr esp_attr = {};
347346

348-
if (!ib_dev->modify_flow_action_esp)
347+
if (!action->device->modify_flow_action_esp)
349348
return -EOPNOTSUPP;
350349

351-
ret = parse_flow_action_esp(ib_dev, file, attrs, &esp_attr, true);
350+
ret = parse_flow_action_esp(action->device, file, attrs, &esp_attr,
351+
true);
352352
if (ret)
353353
return ret;
354354

355-
uobj = uverbs_attr_get_uobject(
356-
attrs, UVERBS_ATTR_MODIFY_FLOW_ACTION_ESP_HANDLE);
357-
action = uobj->object;
358-
359355
if (action->type != IB_FLOW_ACTION_ESP)
360356
return -EINVAL;
361357

362-
return ib_dev->modify_flow_action_esp(action,
363-
&esp_attr.hdr,
364-
attrs);
358+
return action->device->modify_flow_action_esp(action, &esp_attr.hdr,
359+
attrs);
365360
}
366361

367362
static const struct uverbs_attr_spec uverbs_flow_action_esp_keymat[] = {

drivers/infiniband/core/uverbs_std_types_mr.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ static int uverbs_free_mr(struct ib_uobject *uobject,
3939
return ib_dereg_mr((struct ib_mr *)uobject->object);
4040
}
4141

42-
static int UVERBS_HANDLER(UVERBS_METHOD_DM_MR_REG)(struct ib_device *ib_dev,
43-
struct ib_uverbs_file *file,
44-
struct uverbs_attr_bundle *attrs)
42+
static int UVERBS_HANDLER(UVERBS_METHOD_DM_MR_REG)(
43+
struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
4544
{
4645
struct ib_dm_mr_attr attr = {};
47-
struct ib_uobject *uobj;
48-
struct ib_dm *dm;
49-
struct ib_pd *pd;
46+
struct ib_uobject *uobj =
47+
uverbs_attr_get_uobject(attrs, UVERBS_ATTR_REG_DM_MR_HANDLE);
48+
struct ib_dm *dm =
49+
uverbs_attr_get_obj(attrs, UVERBS_ATTR_REG_DM_MR_DM_HANDLE);
50+
struct ib_pd *pd =
51+
uverbs_attr_get_obj(attrs, UVERBS_ATTR_REG_DM_MR_PD_HANDLE);
52+
struct ib_device *ib_dev = pd->device;
53+
5054
struct ib_mr *mr;
5155
int ret;
5256

@@ -75,12 +79,6 @@ static int UVERBS_HANDLER(UVERBS_METHOD_DM_MR_REG)(struct ib_device *ib_dev,
7579
if (ret)
7680
return ret;
7781

78-
pd = uverbs_attr_get_obj(attrs, UVERBS_ATTR_REG_DM_MR_PD_HANDLE);
79-
80-
dm = uverbs_attr_get_obj(attrs, UVERBS_ATTR_REG_DM_MR_DM_HANDLE);
81-
82-
uobj = uverbs_attr_get(attrs, UVERBS_ATTR_REG_DM_MR_HANDLE)->obj_attr.uobject;
83-
8482
if (attr.offset > dm->length || attr.length > dm->length ||
8583
attr.length > dm->length - attr.offset)
8684
return -EINVAL;

drivers/infiniband/hw/mlx5/devx.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,11 @@ static bool devx_is_general_cmd(void *in)
409409
}
410410
}
411411

412-
static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_QUERY_EQN)(struct ib_device *ib_dev,
413-
struct ib_uverbs_file *file,
414-
struct uverbs_attr_bundle *attrs)
412+
static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_QUERY_EQN)(
413+
struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
415414
{
416-
struct mlx5_ib_dev *dev = to_mdev(ib_dev);
415+
struct mlx5_ib_ucontext *c;
416+
struct mlx5_ib_dev *dev;
417417
int user_vector;
418418
int dev_eqn;
419419
unsigned int irqn;
@@ -423,6 +423,11 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_QUERY_EQN)(struct ib_device *ib_de
423423
MLX5_IB_ATTR_DEVX_QUERY_EQN_USER_VEC))
424424
return -EFAULT;
425425

426+
c = devx_ufile2uctx(file);
427+
if (IS_ERR(c))
428+
return PTR_ERR(c);
429+
dev = to_mdev(c->ibucontext.device);
430+
426431
err = mlx5_vector2eqn(dev->mdev, user_vector, &dev_eqn, &irqn);
427432
if (err < 0)
428433
return err;
@@ -454,9 +459,8 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_QUERY_EQN)(struct ib_device *ib_de
454459
* of the buggy user for execution (just insert it to the hardware schedule
455460
* queue or arm its CQ for event generation), no further harm is expected.
456461
*/
457-
static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_QUERY_UAR)(struct ib_device *ib_dev,
458-
struct ib_uverbs_file *file,
459-
struct uverbs_attr_bundle *attrs)
462+
static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_QUERY_UAR)(
463+
struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
460464
{
461465
struct mlx5_ib_ucontext *c;
462466
struct mlx5_ib_dev *dev;
@@ -483,9 +487,8 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_QUERY_UAR)(struct ib_device *ib_de
483487
return 0;
484488
}
485489

486-
static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OTHER)(struct ib_device *ib_dev,
487-
struct ib_uverbs_file *file,
488-
struct uverbs_attr_bundle *attrs)
490+
static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OTHER)(
491+
struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
489492
{
490493
struct mlx5_ib_ucontext *c;
491494
struct mlx5_ib_dev *dev;
@@ -712,9 +715,8 @@ static int devx_obj_cleanup(struct ib_uobject *uobject,
712715
return ret;
713716
}
714717

715-
static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_CREATE)(struct ib_device *ib_dev,
716-
struct ib_uverbs_file *file,
717-
struct uverbs_attr_bundle *attrs)
718+
static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_CREATE)(
719+
struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
718720
{
719721
void *cmd_in = uverbs_attr_get_alloced_ptr(attrs, MLX5_IB_ATTR_DEVX_OBJ_CREATE_CMD_IN);
720722
int cmd_out_len = uverbs_attr_get_len(attrs,
@@ -769,9 +771,8 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_CREATE)(struct ib_device *ib_d
769771
return err;
770772
}
771773

772-
static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_MODIFY)(struct ib_device *ib_dev,
773-
struct ib_uverbs_file *file,
774-
struct uverbs_attr_bundle *attrs)
774+
static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_MODIFY)(
775+
struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
775776
{
776777
void *cmd_in = uverbs_attr_get_alloced_ptr(attrs, MLX5_IB_ATTR_DEVX_OBJ_MODIFY_CMD_IN);
777778
int cmd_out_len = uverbs_attr_get_len(attrs,
@@ -811,9 +812,8 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_MODIFY)(struct ib_device *ib_d
811812
return err;
812813
}
813814

814-
static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_QUERY)(struct ib_device *ib_dev,
815-
struct ib_uverbs_file *file,
816-
struct uverbs_attr_bundle *attrs)
815+
static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_OBJ_QUERY)(
816+
struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
817817
{
818818
void *cmd_in = uverbs_attr_get_alloced_ptr(attrs, MLX5_IB_ATTR_DEVX_OBJ_QUERY_CMD_IN);
819819
int cmd_out_len = uverbs_attr_get_len(attrs,
@@ -931,9 +931,8 @@ static void devx_umem_reg_cmd_build(struct mlx5_ib_dev *dev,
931931
MLX5_IB_MTT_READ);
932932
}
933933

934-
static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_UMEM_REG)(struct ib_device *ib_dev,
935-
struct ib_uverbs_file *file,
936-
struct uverbs_attr_bundle *attrs)
934+
static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_UMEM_REG)(
935+
struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
937936
{
938937
struct devx_umem_reg_cmd cmd;
939938
struct devx_umem *obj;

drivers/infiniband/hw/mlx5/flow.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ static const struct uverbs_attr_spec mlx5_ib_flow_type[] = {
3939
};
4040

4141
static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
42-
struct ib_device *ib_dev, struct ib_uverbs_file *file,
43-
struct uverbs_attr_bundle *attrs)
42+
struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
4443
{
4544
struct mlx5_ib_flow_handler *flow_handler;
4645
struct mlx5_ib_flow_matcher *fs_matcher;
@@ -109,7 +108,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_CREATE_FLOW)(
109108
if (IS_ERR(flow_handler))
110109
return PTR_ERR(flow_handler);
111110

112-
ib_set_flow(uobj, &flow_handler->ibflow, qp, ib_dev);
111+
ib_set_flow(uobj, &flow_handler->ibflow, qp, &dev->ib_dev);
113112

114113
return 0;
115114
}
@@ -129,8 +128,7 @@ static int flow_matcher_cleanup(struct ib_uobject *uobject,
129128
}
130129

131130
static int UVERBS_HANDLER(MLX5_IB_METHOD_FLOW_MATCHER_CREATE)(
132-
struct ib_device *ib_dev, struct ib_uverbs_file *file,
133-
struct uverbs_attr_bundle *attrs)
131+
struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
134132
{
135133
struct ib_uobject *uobj = uverbs_attr_get_uobject(
136134
attrs, MLX5_IB_ATTR_FLOW_MATCHER_CREATE_HANDLE);

include/rdma/ib_verbs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4170,7 +4170,6 @@ void rdma_roce_rescan_device(struct ib_device *ibdev);
41704170

41714171
struct ib_ucontext *ib_uverbs_get_ucontext(struct ib_uverbs_file *ufile);
41724172

4173-
int uverbs_destroy_def_handler(struct ib_device *ib_dev,
4174-
struct ib_uverbs_file *file,
4173+
int uverbs_destroy_def_handler(struct ib_uverbs_file *file,
41754174
struct uverbs_attr_bundle *attrs);
41764175
#endif /* IB_VERBS_H */

0 commit comments

Comments
 (0)