Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Roland Dreier <rolandd@cisco.com>

+21 -11
+21 -11
drivers/infiniband/core/uverbs_cmd.c
··· 42 42 43 43 #include "uverbs.h" 44 44 45 + static struct lock_class_key pd_lock_key; 46 + static struct lock_class_key mr_lock_key; 47 + static struct lock_class_key cq_lock_key; 48 + static struct lock_class_key qp_lock_key; 49 + static struct lock_class_key ah_lock_key; 50 + static struct lock_class_key srq_lock_key; 51 + 45 52 #define INIT_UDATA(udata, ibuf, obuf, ilen, olen) \ 46 53 do { \ 47 54 (udata)->inbuf = (void __user *) (ibuf); \ ··· 83 76 */ 84 77 85 78 static void init_uobj(struct ib_uobject *uobj, u64 user_handle, 86 - struct ib_ucontext *context) 79 + struct ib_ucontext *context, struct lock_class_key *key) 87 80 { 88 81 uobj->user_handle = user_handle; 89 82 uobj->context = context; 90 83 kref_init(&uobj->ref); 91 84 init_rwsem(&uobj->mutex); 85 + lockdep_set_class(&uobj->mutex, key); 92 86 uobj->live = 0; 93 87 } 94 88 ··· 478 470 if (!uobj) 479 471 return -ENOMEM; 480 472 481 - init_uobj(uobj, 0, file->ucontext); 473 + init_uobj(uobj, 0, file->ucontext, &pd_lock_key); 482 474 down_write(&uobj->mutex); 483 475 484 476 pd = file->device->ib_dev->alloc_pd(file->device->ib_dev, ··· 599 591 if (!obj) 600 592 return -ENOMEM; 601 593 602 - init_uobj(&obj->uobject, 0, file->ucontext); 594 + init_uobj(&obj->uobject, 0, file->ucontext, &mr_lock_key); 603 595 down_write(&obj->uobject.mutex); 604 596 605 597 /* ··· 778 770 if (!obj) 779 771 return -ENOMEM; 780 772 781 - init_uobj(&obj->uobject, cmd.user_handle, file->ucontext); 773 + init_uobj(&obj->uobject, cmd.user_handle, file->ucontext, &cq_lock_key); 782 774 down_write(&obj->uobject.mutex); 783 775 784 776 if (cmd.comp_channel >= 0) { ··· 1059 1051 if (!obj) 1060 1052 return -ENOMEM; 1061 1053 1062 - init_uobj(&obj->uevent.uobject, cmd.user_handle, file->ucontext); 1054 + init_uobj(&obj->uevent.uobject, cmd.user_handle, file->ucontext, &qp_lock_key); 1063 1055 down_write(&obj->uevent.uobject.mutex); 1064 1056 1057 + srq = cmd.is_srq ? idr_read_srq(cmd.srq_handle, file->ucontext) : NULL; 1065 1058 pd = idr_read_pd(cmd.pd_handle, file->ucontext); 1066 1059 scq = idr_read_cq(cmd.send_cq_handle, file->ucontext); 1067 - rcq = idr_read_cq(cmd.recv_cq_handle, file->ucontext); 1068 - srq = cmd.is_srq ? idr_read_srq(cmd.srq_handle, file->ucontext) : NULL; 1060 + rcq = cmd.recv_cq_handle == cmd.send_cq_handle ? 1061 + scq : idr_read_cq(cmd.recv_cq_handle, file->ucontext); 1069 1062 1070 1063 if (!pd || !scq || !rcq || (cmd.is_srq && !srq)) { 1071 1064 ret = -EINVAL; ··· 1134 1125 1135 1126 put_pd_read(pd); 1136 1127 put_cq_read(scq); 1137 - put_cq_read(rcq); 1128 + if (rcq != scq) 1129 + put_cq_read(rcq); 1138 1130 if (srq) 1139 1131 put_srq_read(srq); 1140 1132 ··· 1160 1150 put_pd_read(pd); 1161 1151 if (scq) 1162 1152 put_cq_read(scq); 1163 - if (rcq) 1153 + if (rcq && rcq != scq) 1164 1154 put_cq_read(rcq); 1165 1155 if (srq) 1166 1156 put_srq_read(srq); ··· 1761 1751 if (!uobj) 1762 1752 return -ENOMEM; 1763 1753 1764 - init_uobj(uobj, cmd.user_handle, file->ucontext); 1754 + init_uobj(uobj, cmd.user_handle, file->ucontext, &ah_lock_key); 1765 1755 down_write(&uobj->mutex); 1766 1756 1767 1757 pd = idr_read_pd(cmd.pd_handle, file->ucontext); ··· 1976 1966 if (!obj) 1977 1967 return -ENOMEM; 1978 1968 1979 - init_uobj(&obj->uobject, cmd.user_handle, file->ucontext); 1969 + init_uobj(&obj->uobject, cmd.user_handle, file->ucontext, &srq_lock_key); 1980 1970 down_write(&obj->uobject.mutex); 1981 1971 1982 1972 pd = idr_read_pd(cmd.pd_handle, file->ucontext);