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