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

Commit 43db2bc0 authored by Roland Dreier's avatar Roland Dreier
Browse files

IB/uverbs: Fix lockdep warnings



Lockdep warns because uverbs is trying to take uobj->mutex when it
already holds that lock.  This is because there are really multiple
types of uobjs even though all of their locks are initialized in
common code.

Signed-off-by: default avatarRoland Dreier <rolandd@cisco.com>
parent ec924b47
Loading
Loading
Loading
Loading
+21 −11
Original line number Diff line number Diff line
@@ -42,6 +42,13 @@

#include "uverbs.h"

static struct lock_class_key pd_lock_key;
static struct lock_class_key mr_lock_key;
static struct lock_class_key cq_lock_key;
static struct lock_class_key qp_lock_key;
static struct lock_class_key ah_lock_key;
static struct lock_class_key srq_lock_key;

#define INIT_UDATA(udata, ibuf, obuf, ilen, olen)			\
	do {								\
		(udata)->inbuf  = (void __user *) (ibuf);		\
@@ -76,12 +83,13 @@
 */

static void init_uobj(struct ib_uobject *uobj, u64 user_handle,
		      struct ib_ucontext *context)
		      struct ib_ucontext *context, struct lock_class_key *key)
{
	uobj->user_handle = user_handle;
	uobj->context     = context;
	kref_init(&uobj->ref);
	init_rwsem(&uobj->mutex);
	lockdep_set_class(&uobj->mutex, key);
	uobj->live        = 0;
}

@@ -470,7 +478,7 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file,
	if (!uobj)
		return -ENOMEM;

	init_uobj(uobj, 0, file->ucontext);
	init_uobj(uobj, 0, file->ucontext, &pd_lock_key);
	down_write(&uobj->mutex);

	pd = file->device->ib_dev->alloc_pd(file->device->ib_dev,
@@ -591,7 +599,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
	if (!obj)
		return -ENOMEM;

	init_uobj(&obj->uobject, 0, file->ucontext);
	init_uobj(&obj->uobject, 0, file->ucontext, &mr_lock_key);
	down_write(&obj->uobject.mutex);

	/*
@@ -770,7 +778,7 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
	if (!obj)
		return -ENOMEM;

	init_uobj(&obj->uobject, cmd.user_handle, file->ucontext);
	init_uobj(&obj->uobject, cmd.user_handle, file->ucontext, &cq_lock_key);
	down_write(&obj->uobject.mutex);

	if (cmd.comp_channel >= 0) {
@@ -1051,13 +1059,14 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
	if (!obj)
		return -ENOMEM;

	init_uobj(&obj->uevent.uobject, cmd.user_handle, file->ucontext);
	init_uobj(&obj->uevent.uobject, cmd.user_handle, file->ucontext, &qp_lock_key);
	down_write(&obj->uevent.uobject.mutex);

	srq = cmd.is_srq ? idr_read_srq(cmd.srq_handle, file->ucontext) : NULL;
	pd  = idr_read_pd(cmd.pd_handle, file->ucontext);
	scq = idr_read_cq(cmd.send_cq_handle, file->ucontext);
	rcq = idr_read_cq(cmd.recv_cq_handle, file->ucontext);
	srq = cmd.is_srq ? idr_read_srq(cmd.srq_handle, file->ucontext) : NULL;
	rcq = cmd.recv_cq_handle == cmd.send_cq_handle ?
		scq : idr_read_cq(cmd.recv_cq_handle, file->ucontext);

	if (!pd || !scq || !rcq || (cmd.is_srq && !srq)) {
		ret = -EINVAL;
@@ -1125,6 +1134,7 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,

	put_pd_read(pd);
	put_cq_read(scq);
	if (rcq != scq)
		put_cq_read(rcq);
	if (srq)
		put_srq_read(srq);
@@ -1150,7 +1160,7 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
		put_pd_read(pd);
	if (scq)
		put_cq_read(scq);
	if (rcq)
	if (rcq && rcq != scq)
		put_cq_read(rcq);
	if (srq)
		put_srq_read(srq);
@@ -1751,7 +1761,7 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file,
	if (!uobj)
		return -ENOMEM;

	init_uobj(uobj, cmd.user_handle, file->ucontext);
	init_uobj(uobj, cmd.user_handle, file->ucontext, &ah_lock_key);
	down_write(&uobj->mutex);

	pd = idr_read_pd(cmd.pd_handle, file->ucontext);
@@ -1966,7 +1976,7 @@ ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file,
	if (!obj)
		return -ENOMEM;

	init_uobj(&obj->uobject, cmd.user_handle, file->ucontext);
	init_uobj(&obj->uobject, cmd.user_handle, file->ucontext, &srq_lock_key);
	down_write(&obj->uobject.mutex);

	pd  = idr_read_pd(cmd.pd_handle, file->ucontext);