Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e83f0ecd authored by Jason Gunthorpe's avatar Jason Gunthorpe
Browse files

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: default avatarJason Gunthorpe <jgg@mellanox.com>
parent bbd51e88
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -354,7 +354,7 @@ static int uverbs_handle_method(struct ib_uverbs_attr __user *uattr_ptr,
			goto cleanup;
	}

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

	if (destroy_attr) {
		uobj_put_destroy(destroy_attr->uobject);
+1 −2
Original line number Diff line number Diff line
@@ -210,8 +210,7 @@ static int uverbs_hot_unplug_completion_event_file(struct ib_uobject *uobj,
	return 0;
};

int uverbs_destroy_def_handler(struct ib_device *ib_dev,
			       struct ib_uverbs_file *file,
int uverbs_destroy_def_handler(struct ib_uverbs_file *file,
			       struct uverbs_attr_bundle *attrs)
{
	return 0;
+9 −12
Original line number Diff line number Diff line
@@ -47,12 +47,13 @@ static int uverbs_free_counters(struct ib_uobject *uobject,
	return counters->device->destroy_counters(counters);
}

static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_CREATE)(struct ib_device *ib_dev,
							 struct ib_uverbs_file *file,
							 struct uverbs_attr_bundle *attrs)
static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_CREATE)(
	struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
{
	struct ib_uobject *uobj = uverbs_attr_get_uobject(
		attrs, UVERBS_ATTR_CREATE_COUNTERS_HANDLE);
	struct ib_device *ib_dev = uobj->context->device;
	struct ib_counters *counters;
	struct ib_uobject *uobj;
	int ret;

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

	uobj = uverbs_attr_get_uobject(attrs, UVERBS_ATTR_CREATE_COUNTERS_HANDLE);
	counters = ib_dev->create_counters(ib_dev, attrs);
	if (IS_ERR(counters)) {
		ret = PTR_ERR(counters);
@@ -81,9 +81,8 @@ static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_CREATE)(struct ib_device *ib_de
	return ret;
}

static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_READ)(struct ib_device *ib_dev,
						       struct ib_uverbs_file *file,
						       struct uverbs_attr_bundle *attrs)
static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_READ)(
	struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
{
	struct ib_counters_read_attr read_attr = {};
	const struct uverbs_attr *uattr;
@@ -91,7 +90,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_COUNTERS_READ)(struct ib_device *ib_dev,
		uverbs_attr_get_obj(attrs, UVERBS_ATTR_READ_COUNTERS_HANDLE);
	int ret;

	if (!ib_dev->read_counters)
	if (!counters->device->read_counters)
		return -EOPNOTSUPP;

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

	ret = ib_dev->read_counters(counters,
				    &read_attr,
				    attrs);
	ret = counters->device->read_counters(counters, &read_attr, attrs);
	if (ret)
		goto err_read;

+8 −10
Original line number Diff line number Diff line
@@ -57,11 +57,13 @@ static int uverbs_free_cq(struct ib_uobject *uobject,
	return ret;
}

static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(struct ib_device *ib_dev,
						   struct ib_uverbs_file *file,
						   struct uverbs_attr_bundle *attrs)
static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(
	struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
{
	struct ib_ucq_object           *obj;
	struct ib_ucq_object *obj = container_of(
		uverbs_attr_get_uobject(attrs, UVERBS_ATTR_CREATE_CQ_HANDLE),
		typeof(*obj), uobject);
	struct ib_device *ib_dev = obj->uobject.context->device;
	struct ib_udata uhw;
	int ret;
	u64 user_handle;
@@ -104,9 +106,6 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(struct ib_device *ib_dev,
		goto err_event_file;
	}

	obj = container_of(uverbs_attr_get_uobject(attrs,
						   UVERBS_ATTR_CREATE_CQ_HANDLE),
			   typeof(*obj), uobject);
	obj->comp_events_reported  = 0;
	obj->async_events_reported = 0;
	INIT_LIST_HEAD(&obj->comp_list);
@@ -173,9 +172,8 @@ DECLARE_UVERBS_NAMED_METHOD(
			    UA_MANDATORY),
	UVERBS_ATTR_UHW());

static int UVERBS_HANDLER(UVERBS_METHOD_CQ_DESTROY)(struct ib_device *ib_dev,
						    struct ib_uverbs_file *file,
						    struct uverbs_attr_bundle *attrs)
static int UVERBS_HANDLER(UVERBS_METHOD_CQ_DESTROY)(
	struct ib_uverbs_file *file, struct uverbs_attr_bundle *attrs)
{
	struct ib_uobject *uobj =
		uverbs_attr_get_uobject(attrs, UVERBS_ATTR_DESTROY_CQ_HANDLE);
+7 −6
Original line number Diff line number Diff line
@@ -46,12 +46,15 @@ static int uverbs_free_dm(struct ib_uobject *uobject,
	return dm->device->dealloc_dm(dm);
}

static int UVERBS_HANDLER(UVERBS_METHOD_DM_ALLOC)(struct ib_device *ib_dev,
						  struct ib_uverbs_file *file,
static int
UVERBS_HANDLER(UVERBS_METHOD_DM_ALLOC)(struct ib_uverbs_file *file,
				       struct uverbs_attr_bundle *attrs)
{
	struct ib_dm_alloc_attr attr = {};
	struct ib_uobject *uobj;
	struct ib_uobject *uobj =
		uverbs_attr_get(attrs, UVERBS_ATTR_ALLOC_DM_HANDLE)
			->obj_attr.uobject;
	struct ib_device *ib_dev = uobj->context->device;
	struct ib_dm *dm;
	int ret;

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

	uobj = uverbs_attr_get(attrs, UVERBS_ATTR_ALLOC_DM_HANDLE)->obj_attr.uobject;

	dm = ib_dev->alloc_dm(ib_dev, uobj->context, &attr, attrs);
	if (IS_ERR(dm))
		return PTR_ERR(dm);
Loading