aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2006-01-13 17:51:39 -0500
committerRoland Dreier <rolandd@cisco.com>2006-01-13 17:51:39 -0500
commit95ed644fd12f53c6fc778f3f246974e5fe3a9468 (patch)
treeedf9f57192ad95f9165b3be5dbf1e8e745249ed1
parent9eacee2ac624bfa9740d49355dbe6ee88d0cba0a (diff)
IB: convert from semaphores to mutexes
semaphore to mutex conversion by Ingo and Arjan's script. Signed-off-by: Ingo Molnar <mingo@elte.hu> [ Sanity-checked on real IB hardware ] Signed-off-by: Roland Dreier <rolandd@cisco.com>
-rw-r--r--drivers/infiniband/core/device.c23
-rw-r--r--drivers/infiniband/core/ucm.c23
-rw-r--r--drivers/infiniband/core/uverbs.h5
-rw-r--r--drivers/infiniband/core/uverbs_cmd.c150
-rw-r--r--drivers/infiniband/core/uverbs_main.c8
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib.h6
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_ib.c18
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c12
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_multicast.c26
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_verbs.c8
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_vlan.c10
11 files changed, 145 insertions, 144 deletions
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index e169e798354b..b2f3cb91d9bc 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -38,8 +38,7 @@
38#include <linux/errno.h> 38#include <linux/errno.h>
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/init.h> 40#include <linux/init.h>
41 41#include <linux/mutex.h>
42#include <asm/semaphore.h>
43 42
44#include "core_priv.h" 43#include "core_priv.h"
45 44
@@ -57,13 +56,13 @@ static LIST_HEAD(device_list);
57static LIST_HEAD(client_list); 56static LIST_HEAD(client_list);
58 57
59/* 58/*
60 * device_sem protects access to both device_list and client_list. 59 * device_mutex protects access to both device_list and client_list.
61 * There's no real point to using multiple locks or something fancier 60 * There's no real point to using multiple locks or something fancier
62 * like an rwsem: we always access both lists, and we're always 61 * like an rwsem: we always access both lists, and we're always
63 * modifying one list or the other list. In any case this is not a 62 * modifying one list or the other list. In any case this is not a
64 * hot path so there's no point in trying to optimize. 63 * hot path so there's no point in trying to optimize.
65 */ 64 */
66static DECLARE_MUTEX(device_sem); 65static DEFINE_MUTEX(device_mutex);
67 66
68static int ib_device_check_mandatory(struct ib_device *device) 67static int ib_device_check_mandatory(struct ib_device *device)
69{ 68{
@@ -221,7 +220,7 @@ int ib_register_device(struct ib_device *device)
221{ 220{
222 int ret; 221 int ret;
223 222
224 down(&device_sem); 223 mutex_lock(&device_mutex);
225 224
226 if (strchr(device->name, '%')) { 225 if (strchr(device->name, '%')) {
227 ret = alloc_name(device->name); 226 ret = alloc_name(device->name);
@@ -259,7 +258,7 @@ int ib_register_device(struct ib_device *device)
259 } 258 }
260 259
261 out: 260 out:
262 up(&device_sem); 261 mutex_unlock(&device_mutex);
263 return ret; 262 return ret;
264} 263}
265EXPORT_SYMBOL(ib_register_device); 264EXPORT_SYMBOL(ib_register_device);
@@ -276,7 +275,7 @@ void ib_unregister_device(struct ib_device *device)
276 struct ib_client_data *context, *tmp; 275 struct ib_client_data *context, *tmp;
277 unsigned long flags; 276 unsigned long flags;
278 277
279 down(&device_sem); 278 mutex_lock(&device_mutex);
280 279
281 list_for_each_entry_reverse(client, &client_list, list) 280 list_for_each_entry_reverse(client, &client_list, list)
282 if (client->remove) 281 if (client->remove)
@@ -284,7 +283,7 @@ void ib_unregister_device(struct ib_device *device)
284 283
285 list_del(&device->core_list); 284 list_del(&device->core_list);
286 285
287 up(&device_sem); 286 mutex_unlock(&device_mutex);
288 287
289 spin_lock_irqsave(&device->client_data_lock, flags); 288 spin_lock_irqsave(&device->client_data_lock, flags);
290 list_for_each_entry_safe(context, tmp, &device->client_data_list, list) 289 list_for_each_entry_safe(context, tmp, &device->client_data_list, list)
@@ -312,14 +311,14 @@ int ib_register_client(struct ib_client *client)
312{ 311{
313 struct ib_device *device; 312 struct ib_device *device;
314 313
315 down(&device_sem); 314 mutex_lock(&device_mutex);
316 315
317 list_add_tail(&client->list, &client_list); 316 list_add_tail(&client->list, &client_list);
318 list_for_each_entry(device, &device_list, core_list) 317 list_for_each_entry(device, &device_list, core_list)
319 if (client->add && !add_client_context(device, client)) 318 if (client->add && !add_client_context(device, client))
320 client->add(device); 319 client->add(device);
321 320
322 up(&device_sem); 321 mutex_unlock(&device_mutex);
323 322
324 return 0; 323 return 0;
325} 324}
@@ -339,7 +338,7 @@ void ib_unregister_client(struct ib_client *client)
339 struct ib_device *device; 338 struct ib_device *device;
340 unsigned long flags; 339 unsigned long flags;
341 340
342 down(&device_sem); 341 mutex_lock(&device_mutex);
343 342
344 list_for_each_entry(device, &device_list, core_list) { 343 list_for_each_entry(device, &device_list, core_list) {
345 if (client->remove) 344 if (client->remove)
@@ -355,7 +354,7 @@ void ib_unregister_client(struct ib_client *client)
355 } 354 }
356 list_del(&client->list); 355 list_del(&client->list);
357 356
358 up(&device_sem); 357 mutex_unlock(&device_mutex);
359} 358}
360EXPORT_SYMBOL(ib_unregister_client); 359EXPORT_SYMBOL(ib_unregister_client);
361 360
diff --git a/drivers/infiniband/core/ucm.c b/drivers/infiniband/core/ucm.c
index 6e15787d1de1..e95c4293a496 100644
--- a/drivers/infiniband/core/ucm.c
+++ b/drivers/infiniband/core/ucm.c
@@ -42,6 +42,7 @@
42#include <linux/mount.h> 42#include <linux/mount.h>
43#include <linux/cdev.h> 43#include <linux/cdev.h>
44#include <linux/idr.h> 44#include <linux/idr.h>
45#include <linux/mutex.h>
45 46
46#include <asm/uaccess.h> 47#include <asm/uaccess.h>
47 48
@@ -113,7 +114,7 @@ static struct ib_client ucm_client = {
113 .remove = ib_ucm_remove_one 114 .remove = ib_ucm_remove_one
114}; 115};
115 116
116static DECLARE_MUTEX(ctx_id_mutex); 117static DEFINE_MUTEX(ctx_id_mutex);
117static DEFINE_IDR(ctx_id_table); 118static DEFINE_IDR(ctx_id_table);
118static DECLARE_BITMAP(dev_map, IB_UCM_MAX_DEVICES); 119static DECLARE_BITMAP(dev_map, IB_UCM_MAX_DEVICES);
119 120
@@ -121,7 +122,7 @@ static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id)
121{ 122{
122 struct ib_ucm_context *ctx; 123 struct ib_ucm_context *ctx;
123 124
124 down(&ctx_id_mutex); 125 mutex_lock(&ctx_id_mutex);
125 ctx = idr_find(&ctx_id_table, id); 126 ctx = idr_find(&ctx_id_table, id);
126 if (!ctx) 127 if (!ctx)
127 ctx = ERR_PTR(-ENOENT); 128 ctx = ERR_PTR(-ENOENT);
@@ -129,7 +130,7 @@ static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id)
129 ctx = ERR_PTR(-EINVAL); 130 ctx = ERR_PTR(-EINVAL);
130 else 131 else
131 atomic_inc(&ctx->ref); 132 atomic_inc(&ctx->ref);
132 up(&ctx_id_mutex); 133 mutex_unlock(&ctx_id_mutex);
133 134
134 return ctx; 135 return ctx;
135} 136}
@@ -186,9 +187,9 @@ static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file)
186 if (!result) 187 if (!result)
187 goto error; 188 goto error;
188 189
189 down(&ctx_id_mutex); 190 mutex_lock(&ctx_id_mutex);
190 result = idr_get_new(&ctx_id_table, ctx, &ctx->id); 191 result = idr_get_new(&ctx_id_table, ctx, &ctx->id);
191 up(&ctx_id_mutex); 192 mutex_unlock(&ctx_id_mutex);
192 } while (result == -EAGAIN); 193 } while (result == -EAGAIN);
193 194
194 if (result) 195 if (result)
@@ -550,9 +551,9 @@ static ssize_t ib_ucm_create_id(struct ib_ucm_file *file,
550err2: 551err2:
551 ib_destroy_cm_id(ctx->cm_id); 552 ib_destroy_cm_id(ctx->cm_id);
552err1: 553err1:
553 down(&ctx_id_mutex); 554 mutex_lock(&ctx_id_mutex);
554 idr_remove(&ctx_id_table, ctx->id); 555 idr_remove(&ctx_id_table, ctx->id);
555 up(&ctx_id_mutex); 556 mutex_unlock(&ctx_id_mutex);
556 kfree(ctx); 557 kfree(ctx);
557 return result; 558 return result;
558} 559}
@@ -572,7 +573,7 @@ static ssize_t ib_ucm_destroy_id(struct ib_ucm_file *file,
572 if (copy_from_user(&cmd, inbuf, sizeof(cmd))) 573 if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
573 return -EFAULT; 574 return -EFAULT;
574 575
575 down(&ctx_id_mutex); 576 mutex_lock(&ctx_id_mutex);
576 ctx = idr_find(&ctx_id_table, cmd.id); 577 ctx = idr_find(&ctx_id_table, cmd.id);
577 if (!ctx) 578 if (!ctx)
578 ctx = ERR_PTR(-ENOENT); 579 ctx = ERR_PTR(-ENOENT);
@@ -580,7 +581,7 @@ static ssize_t ib_ucm_destroy_id(struct ib_ucm_file *file,
580 ctx = ERR_PTR(-EINVAL); 581 ctx = ERR_PTR(-EINVAL);
581 else 582 else
582 idr_remove(&ctx_id_table, ctx->id); 583 idr_remove(&ctx_id_table, ctx->id);
583 up(&ctx_id_mutex); 584 mutex_unlock(&ctx_id_mutex);
584 585
585 if (IS_ERR(ctx)) 586 if (IS_ERR(ctx))
586 return PTR_ERR(ctx); 587 return PTR_ERR(ctx);
@@ -1280,9 +1281,9 @@ static int ib_ucm_close(struct inode *inode, struct file *filp)
1280 struct ib_ucm_context, file_list); 1281 struct ib_ucm_context, file_list);
1281 up(&file->mutex); 1282 up(&file->mutex);
1282 1283
1283 down(&ctx_id_mutex); 1284 mutex_lock(&ctx_id_mutex);
1284 idr_remove(&ctx_id_table, ctx->id); 1285 idr_remove(&ctx_id_table, ctx->id);
1285 up(&ctx_id_mutex); 1286 mutex_unlock(&ctx_id_mutex);
1286 1287
1287 ib_destroy_cm_id(ctx->cm_id); 1288 ib_destroy_cm_id(ctx->cm_id);
1288 ib_ucm_cleanup_events(ctx); 1289 ib_ucm_cleanup_events(ctx);
diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h
index 7114e3fbab00..f7eecbc6af6c 100644
--- a/drivers/infiniband/core/uverbs.h
+++ b/drivers/infiniband/core/uverbs.h
@@ -41,6 +41,7 @@
41 41
42#include <linux/kref.h> 42#include <linux/kref.h>
43#include <linux/idr.h> 43#include <linux/idr.h>
44#include <linux/mutex.h>
44 45
45#include <rdma/ib_verbs.h> 46#include <rdma/ib_verbs.h>
46#include <rdma/ib_user_verbs.h> 47#include <rdma/ib_user_verbs.h>
@@ -88,7 +89,7 @@ struct ib_uverbs_event_file {
88 89
89struct ib_uverbs_file { 90struct ib_uverbs_file {
90 struct kref ref; 91 struct kref ref;
91 struct semaphore mutex; 92 struct mutex mutex;
92 struct ib_uverbs_device *device; 93 struct ib_uverbs_device *device;
93 struct ib_ucontext *ucontext; 94 struct ib_ucontext *ucontext;
94 struct ib_event_handler event_handler; 95 struct ib_event_handler event_handler;
@@ -131,7 +132,7 @@ struct ib_ucq_object {
131 u32 async_events_reported; 132 u32 async_events_reported;
132}; 133};
133 134
134extern struct semaphore ib_uverbs_idr_mutex; 135extern struct mutex ib_uverbs_idr_mutex;
135extern struct idr ib_uverbs_pd_idr; 136extern struct idr ib_uverbs_pd_idr;
136extern struct idr ib_uverbs_mr_idr; 137extern struct idr ib_uverbs_mr_idr;
137extern struct idr ib_uverbs_mw_idr; 138extern struct idr ib_uverbs_mw_idr;
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index 554c2057b7c1..407b6284d7d5 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -67,7 +67,7 @@ ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
67 if (copy_from_user(&cmd, buf, sizeof cmd)) 67 if (copy_from_user(&cmd, buf, sizeof cmd))
68 return -EFAULT; 68 return -EFAULT;
69 69
70 down(&file->mutex); 70 mutex_lock(&file->mutex);
71 71
72 if (file->ucontext) { 72 if (file->ucontext) {
73 ret = -EINVAL; 73 ret = -EINVAL;
@@ -119,7 +119,7 @@ ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
119 119
120 fd_install(resp.async_fd, filp); 120 fd_install(resp.async_fd, filp);
121 121
122 up(&file->mutex); 122 mutex_unlock(&file->mutex);
123 123
124 return in_len; 124 return in_len;
125 125
@@ -131,7 +131,7 @@ err_free:
131 ibdev->dealloc_ucontext(ucontext); 131 ibdev->dealloc_ucontext(ucontext);
132 132
133err: 133err:
134 up(&file->mutex); 134 mutex_unlock(&file->mutex);
135 return ret; 135 return ret;
136} 136}
137 137
@@ -290,7 +290,7 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file,
290 pd->uobject = uobj; 290 pd->uobject = uobj;
291 atomic_set(&pd->usecnt, 0); 291 atomic_set(&pd->usecnt, 0);
292 292
293 down(&ib_uverbs_idr_mutex); 293 mutex_lock(&ib_uverbs_idr_mutex);
294 294
295retry: 295retry:
296 if (!idr_pre_get(&ib_uverbs_pd_idr, GFP_KERNEL)) { 296 if (!idr_pre_get(&ib_uverbs_pd_idr, GFP_KERNEL)) {
@@ -314,11 +314,11 @@ retry:
314 goto err_idr; 314 goto err_idr;
315 } 315 }
316 316
317 down(&file->mutex); 317 mutex_lock(&file->mutex);
318 list_add_tail(&uobj->list, &file->ucontext->pd_list); 318 list_add_tail(&uobj->list, &file->ucontext->pd_list);
319 up(&file->mutex); 319 mutex_unlock(&file->mutex);
320 320
321 up(&ib_uverbs_idr_mutex); 321 mutex_unlock(&ib_uverbs_idr_mutex);
322 322
323 return in_len; 323 return in_len;
324 324
@@ -326,7 +326,7 @@ err_idr:
326 idr_remove(&ib_uverbs_pd_idr, uobj->id); 326 idr_remove(&ib_uverbs_pd_idr, uobj->id);
327 327
328err_up: 328err_up:
329 up(&ib_uverbs_idr_mutex); 329 mutex_unlock(&ib_uverbs_idr_mutex);
330 ib_dealloc_pd(pd); 330 ib_dealloc_pd(pd);
331 331
332err: 332err:
@@ -346,7 +346,7 @@ ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file,
346 if (copy_from_user(&cmd, buf, sizeof cmd)) 346 if (copy_from_user(&cmd, buf, sizeof cmd))
347 return -EFAULT; 347 return -EFAULT;
348 348
349 down(&ib_uverbs_idr_mutex); 349 mutex_lock(&ib_uverbs_idr_mutex);
350 350
351 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); 351 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
352 if (!pd || pd->uobject->context != file->ucontext) 352 if (!pd || pd->uobject->context != file->ucontext)
@@ -360,14 +360,14 @@ ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file,
360 360
361 idr_remove(&ib_uverbs_pd_idr, cmd.pd_handle); 361 idr_remove(&ib_uverbs_pd_idr, cmd.pd_handle);
362 362
363 down(&file->mutex); 363 mutex_lock(&file->mutex);
364 list_del(&uobj->list); 364 list_del(&uobj->list);
365 up(&file->mutex); 365 mutex_unlock(&file->mutex);
366 366
367 kfree(uobj); 367 kfree(uobj);
368 368
369out: 369out:
370 up(&ib_uverbs_idr_mutex); 370 mutex_unlock(&ib_uverbs_idr_mutex);
371 371
372 return ret ? ret : in_len; 372 return ret ? ret : in_len;
373} 373}
@@ -426,7 +426,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
426 426
427 obj->umem.virt_base = cmd.hca_va; 427 obj->umem.virt_base = cmd.hca_va;
428 428
429 down(&ib_uverbs_idr_mutex); 429 mutex_lock(&ib_uverbs_idr_mutex);
430 430
431 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); 431 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
432 if (!pd || pd->uobject->context != file->ucontext) { 432 if (!pd || pd->uobject->context != file->ucontext) {
@@ -476,11 +476,11 @@ retry:
476 goto err_idr; 476 goto err_idr;
477 } 477 }
478 478
479 down(&file->mutex); 479 mutex_lock(&file->mutex);
480 list_add_tail(&obj->uobject.list, &file->ucontext->mr_list); 480 list_add_tail(&obj->uobject.list, &file->ucontext->mr_list);
481 up(&file->mutex); 481 mutex_unlock(&file->mutex);
482 482
483 up(&ib_uverbs_idr_mutex); 483 mutex_unlock(&ib_uverbs_idr_mutex);
484 484
485 return in_len; 485 return in_len;
486 486
@@ -492,7 +492,7 @@ err_unreg:
492 atomic_dec(&pd->usecnt); 492 atomic_dec(&pd->usecnt);
493 493
494err_up: 494err_up:
495 up(&ib_uverbs_idr_mutex); 495 mutex_unlock(&ib_uverbs_idr_mutex);
496 496
497 ib_umem_release(file->device->ib_dev, &obj->umem); 497 ib_umem_release(file->device->ib_dev, &obj->umem);
498 498
@@ -513,7 +513,7 @@ ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file,
513 if (copy_from_user(&cmd, buf, sizeof cmd)) 513 if (copy_from_user(&cmd, buf, sizeof cmd))
514 return -EFAULT; 514 return -EFAULT;
515 515
516 down(&ib_uverbs_idr_mutex); 516 mutex_lock(&ib_uverbs_idr_mutex);
517 517
518 mr = idr_find(&ib_uverbs_mr_idr, cmd.mr_handle); 518 mr = idr_find(&ib_uverbs_mr_idr, cmd.mr_handle);
519 if (!mr || mr->uobject->context != file->ucontext) 519 if (!mr || mr->uobject->context != file->ucontext)
@@ -527,15 +527,15 @@ ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file,
527 527
528 idr_remove(&ib_uverbs_mr_idr, cmd.mr_handle); 528 idr_remove(&ib_uverbs_mr_idr, cmd.mr_handle);
529 529
530 down(&file->mutex); 530 mutex_lock(&file->mutex);
531 list_del(&memobj->uobject.list); 531 list_del(&memobj->uobject.list);
532 up(&file->mutex); 532 mutex_unlock(&file->mutex);
533 533
534 ib_umem_release(file->device->ib_dev, &memobj->umem); 534 ib_umem_release(file->device->ib_dev, &memobj->umem);
535 kfree(memobj); 535 kfree(memobj);
536 536
537out: 537out:
538 up(&ib_uverbs_idr_mutex); 538 mutex_unlock(&ib_uverbs_idr_mutex);
539 539
540 return ret ? ret : in_len; 540 return ret ? ret : in_len;
541} 541}
@@ -628,7 +628,7 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
628 cq->cq_context = ev_file; 628 cq->cq_context = ev_file;
629 atomic_set(&cq->usecnt, 0); 629 atomic_set(&cq->usecnt, 0);
630 630
631 down(&ib_uverbs_idr_mutex); 631 mutex_lock(&ib_uverbs_idr_mutex);
632 632
633retry: 633retry:
634 if (!idr_pre_get(&ib_uverbs_cq_idr, GFP_KERNEL)) { 634 if (!idr_pre_get(&ib_uverbs_cq_idr, GFP_KERNEL)) {
@@ -653,11 +653,11 @@ retry:
653 goto err_idr; 653 goto err_idr;
654 } 654 }
655 655
656 down(&file->mutex); 656 mutex_lock(&file->mutex);
657 list_add_tail(&uobj->uobject.list, &file->ucontext->cq_list); 657 list_add_tail(&uobj->uobject.list, &file->ucontext->cq_list);
658 up(&file->mutex); 658 mutex_unlock(&file->mutex);
659 659
660 up(&ib_uverbs_idr_mutex); 660 mutex_unlock(&ib_uverbs_idr_mutex);
661 661
662 return in_len; 662 return in_len;
663 663
@@ -665,7 +665,7 @@ err_idr:
665 idr_remove(&ib_uverbs_cq_idr, uobj->uobject.id); 665 idr_remove(&ib_uverbs_cq_idr, uobj->uobject.id);
666 666
667err_up: 667err_up:
668 up(&ib_uverbs_idr_mutex); 668 mutex_unlock(&ib_uverbs_idr_mutex);
669 ib_destroy_cq(cq); 669 ib_destroy_cq(cq);
670 670
671err: 671err:
@@ -701,7 +701,7 @@ ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file,
701 goto out_wc; 701 goto out_wc;
702 } 702 }
703 703
704 down(&ib_uverbs_idr_mutex); 704 mutex_lock(&ib_uverbs_idr_mutex);
705 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle); 705 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle);
706 if (!cq || cq->uobject->context != file->ucontext) { 706 if (!cq || cq->uobject->context != file->ucontext) {
707 ret = -EINVAL; 707 ret = -EINVAL;
@@ -731,7 +731,7 @@ ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file,
731 ret = -EFAULT; 731 ret = -EFAULT;
732 732
733out: 733out:
734 up(&ib_uverbs_idr_mutex); 734 mutex_unlock(&ib_uverbs_idr_mutex);
735 kfree(resp); 735 kfree(resp);
736 736
737out_wc: 737out_wc:
@@ -750,14 +750,14 @@ ssize_t ib_uverbs_req_notify_cq(struct ib_uverbs_file *file,
750 if (copy_from_user(&cmd, buf, sizeof cmd)) 750 if (copy_from_user(&cmd, buf, sizeof cmd))
751 return -EFAULT; 751 return -EFAULT;
752 752
753 down(&ib_uverbs_idr_mutex); 753 mutex_lock(&ib_uverbs_idr_mutex);
754 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle); 754 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle);
755 if (cq && cq->uobject->context == file->ucontext) { 755 if (cq && cq->uobject->context == file->ucontext) {
756 ib_req_notify_cq(cq, cmd.solicited_only ? 756 ib_req_notify_cq(cq, cmd.solicited_only ?
757 IB_CQ_SOLICITED : IB_CQ_NEXT_COMP); 757 IB_CQ_SOLICITED : IB_CQ_NEXT_COMP);
758 ret = in_len; 758 ret = in_len;
759 } 759 }
760 up(&ib_uverbs_idr_mutex); 760 mutex_unlock(&ib_uverbs_idr_mutex);
761 761
762 return ret; 762 return ret;
763} 763}
@@ -779,7 +779,7 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
779 779
780 memset(&resp, 0, sizeof resp); 780 memset(&resp, 0, sizeof resp);
781 781
782 down(&ib_uverbs_idr_mutex); 782 mutex_lock(&ib_uverbs_idr_mutex);
783 783
784 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle); 784 cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle);
785 if (!cq || cq->uobject->context != file->ucontext) 785 if (!cq || cq->uobject->context != file->ucontext)
@@ -795,9 +795,9 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
795 795
796 idr_remove(&ib_uverbs_cq_idr, cmd.cq_handle); 796 idr_remove(&ib_uverbs_cq_idr, cmd.cq_handle);
797 797
798 down(&file->mutex); 798 mutex_lock(&file->mutex);
799 list_del(&uobj->uobject.list); 799 list_del(&uobj->uobject.list);
800 up(&file->mutex); 800 mutex_unlock(&file->mutex);
801 801
802 ib_uverbs_release_ucq(file, ev_file, uobj); 802 ib_uverbs_release_ucq(file, ev_file, uobj);
803 803
@@ -811,7 +811,7 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
811 ret = -EFAULT; 811 ret = -EFAULT;
812 812
813out: 813out:
814 up(&ib_uverbs_idr_mutex); 814 mutex_unlock(&ib_uverbs_idr_mutex);
815 815
816 return ret ? ret : in_len; 816 return ret ? ret : in_len;
817} 817}
@@ -845,7 +845,7 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
845 if (!uobj) 845 if (!uobj)
846 return -ENOMEM; 846 return -ENOMEM;
847 847
848 down(&ib_uverbs_idr_mutex); 848 mutex_lock(&ib_uverbs_idr_mutex);
849 849
850 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); 850 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
851 scq = idr_find(&ib_uverbs_cq_idr, cmd.send_cq_handle); 851 scq = idr_find(&ib_uverbs_cq_idr, cmd.send_cq_handle);
@@ -930,11 +930,11 @@ retry:
930 goto err_idr; 930 goto err_idr;
931 } 931 }
932 932
933 down(&file->mutex); 933 mutex_lock(&file->mutex);
934 list_add_tail(&uobj->uevent.uobject.list, &file->ucontext->qp_list); 934 list_add_tail(&uobj->uevent.uobject.list, &file->ucontext->qp_list);
935 up(&file->mutex); 935 mutex_unlock(&file->mutex);
936 936
937 up(&ib_uverbs_idr_mutex); 937 mutex_unlock(&ib_uverbs_idr_mutex);
938 938
939 return in_len; 939 return in_len;
940 940
@@ -950,7 +950,7 @@ err_destroy:
950 atomic_dec(&attr.srq->usecnt); 950 atomic_dec(&attr.srq->usecnt);
951 951
952err_up: 952err_up:
953 up(&ib_uverbs_idr_mutex); 953 mutex_unlock(&ib_uverbs_idr_mutex);
954 954
955 kfree(uobj); 955 kfree(uobj);
956 return ret; 956 return ret;
@@ -972,7 +972,7 @@ ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file,
972 if (!attr) 972 if (!attr)
973 return -ENOMEM; 973 return -ENOMEM;
974 974
975 down(&ib_uverbs_idr_mutex); 975 mutex_lock(&ib_uverbs_idr_mutex);
976 976
977 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); 977 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
978 if (!qp || qp->uobject->context != file->ucontext) { 978 if (!qp || qp->uobject->context != file->ucontext) {
@@ -1033,7 +1033,7 @@ ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file,
1033 ret = in_len; 1033 ret = in_len;
1034 1034
1035out: 1035out:
1036 up(&ib_uverbs_idr_mutex); 1036 mutex_unlock(&ib_uverbs_idr_mutex);
1037 kfree(attr); 1037 kfree(attr);
1038 1038
1039 return ret; 1039 return ret;
@@ -1054,7 +1054,7 @@ ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file,
1054 1054
1055 memset(&resp, 0, sizeof resp); 1055 memset(&resp, 0, sizeof resp);
1056 1056
1057 down(&ib_uverbs_idr_mutex); 1057 mutex_lock(&ib_uverbs_idr_mutex);
1058 1058
1059 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); 1059 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
1060 if (!qp || qp->uobject->context != file->ucontext) 1060 if (!qp || qp->uobject->context != file->ucontext)
@@ -1073,9 +1073,9 @@ ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file,
1073 1073
1074 idr_remove(&ib_uverbs_qp_idr, cmd.qp_handle); 1074 idr_remove(&ib_uverbs_qp_idr, cmd.qp_handle);
1075 1075
1076 down(&file->mutex); 1076 mutex_lock(&file->mutex);
1077 list_del(&uobj->uevent.uobject.list); 1077 list_del(&uobj->uevent.uobject.list);
1078 up(&file->mutex); 1078 mutex_unlock(&file->mutex);
1079 1079
1080 ib_uverbs_release_uevent(file, &uobj->uevent); 1080 ib_uverbs_release_uevent(file, &uobj->uevent);
1081 1081
@@ -1088,7 +1088,7 @@ ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file,
1088 ret = -EFAULT; 1088 ret = -EFAULT;
1089 1089
1090out: 1090out:
1091 up(&ib_uverbs_idr_mutex); 1091 mutex_unlock(&ib_uverbs_idr_mutex);
1092 1092
1093 return ret ? ret : in_len; 1093 return ret ? ret : in_len;
1094} 1094}
@@ -1119,7 +1119,7 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
1119 if (!user_wr) 1119 if (!user_wr)
1120 return -ENOMEM; 1120 return -ENOMEM;
1121 1121
1122 down(&ib_uverbs_idr_mutex); 1122 mutex_lock(&ib_uverbs_idr_mutex);
1123 1123
1124 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); 1124 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
1125 if (!qp || qp->uobject->context != file->ucontext) 1125 if (!qp || qp->uobject->context != file->ucontext)
@@ -1224,7 +1224,7 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
1224 ret = -EFAULT; 1224 ret = -EFAULT;
1225 1225
1226out: 1226out:
1227 up(&ib_uverbs_idr_mutex); 1227 mutex_unlock(&ib_uverbs_idr_mutex);
1228 1228
1229 while (wr) { 1229 while (wr) {
1230 next = wr->next; 1230 next = wr->next;
@@ -1341,7 +1341,7 @@ ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file,
1341 if (IS_ERR(wr)) 1341 if (IS_ERR(wr))
1342 return PTR_ERR(wr); 1342 return PTR_ERR(wr);
1343 1343
1344 down(&ib_uverbs_idr_mutex); 1344 mutex_lock(&ib_uverbs_idr_mutex);
1345 1345
1346 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); 1346 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
1347 if (!qp || qp->uobject->context != file->ucontext) 1347 if (!qp || qp->uobject->context != file->ucontext)
@@ -1362,7 +1362,7 @@ ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file,
1362 ret = -EFAULT; 1362 ret = -EFAULT;
1363 1363
1364out: 1364out:
1365 up(&ib_uverbs_idr_mutex); 1365 mutex_unlock(&ib_uverbs_idr_mutex);
1366 1366
1367 while (wr) { 1367 while (wr) {
1368 next = wr->next; 1368 next = wr->next;
@@ -1392,7 +1392,7 @@ ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file,
1392 if (IS_ERR(wr)) 1392 if (IS_ERR(wr))
1393 return PTR_ERR(wr); 1393 return PTR_ERR(wr);
1394 1394
1395 down(&ib_uverbs_idr_mutex); 1395 mutex_lock(&ib_uverbs_idr_mutex);
1396 1396
1397 srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle); 1397 srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle);
1398 if (!srq || srq->uobject->context != file->ucontext) 1398 if (!srq || srq->uobject->context != file->ucontext)
@@ -1413,7 +1413,7 @@ ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file,
1413 ret = -EFAULT; 1413 ret = -EFAULT;
1414 1414
1415out: 1415out:
1416 up(&ib_uverbs_idr_mutex); 1416 mutex_unlock(&ib_uverbs_idr_mutex);
1417 1417
1418 while (wr) { 1418 while (wr) {
1419 next = wr->next; 1419 next = wr->next;
@@ -1446,7 +1446,7 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file,
1446 if (!uobj) 1446 if (!uobj)
1447 return -ENOMEM; 1447 return -ENOMEM;
1448 1448
1449 down(&ib_uverbs_idr_mutex); 1449 mutex_lock(&ib_uverbs_idr_mutex);
1450 1450
1451 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); 1451 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
1452 if (!pd || pd->uobject->context != file->ucontext) { 1452 if (!pd || pd->uobject->context != file->ucontext) {
@@ -1498,11 +1498,11 @@ retry:
1498 goto err_idr; 1498 goto err_idr;
1499 } 1499 }
1500 1500
1501 down(&file->mutex); 1501 mutex_lock(&file->mutex);
1502 list_add_tail(&uobj->list, &file->ucontext->ah_list); 1502 list_add_tail(&uobj->list, &file->ucontext->ah_list);
1503 up(&file->mutex); 1503 mutex_unlock(&file->mutex);
1504 1504
1505 up(&ib_uverbs_idr_mutex); 1505 mutex_unlock(&ib_uverbs_idr_mutex);
1506 1506
1507 return in_len; 1507 return in_len;
1508 1508
@@ -1513,7 +1513,7 @@ err_destroy:
1513 ib_destroy_ah(ah); 1513 ib_destroy_ah(ah);
1514 1514
1515err_up: 1515err_up:
1516 up(&ib_uverbs_idr_mutex); 1516 mutex_unlock(&ib_uverbs_idr_mutex);
1517 1517
1518 kfree(uobj); 1518 kfree(uobj);
1519 return ret; 1519 return ret;
@@ -1530,7 +1530,7 @@ ssize_t ib_uverbs_destroy_ah(struct ib_uverbs_file *file,
1530 if (copy_from_user(&cmd, buf, sizeof cmd)) 1530 if (copy_from_user(&cmd, buf, sizeof cmd))
1531 return -EFAULT; 1531 return -EFAULT;
1532 1532
1533 down(&ib_uverbs_idr_mutex); 1533 mutex_lock(&ib_uverbs_idr_mutex);
1534 1534
1535 ah = idr_find(&ib_uverbs_ah_idr, cmd.ah_handle); 1535 ah = idr_find(&ib_uverbs_ah_idr, cmd.ah_handle);
1536 if (!ah || ah->uobject->context != file->ucontext) 1536 if (!ah || ah->uobject->context != file->ucontext)
@@ -1544,14 +1544,14 @@ ssize_t ib_uverbs_destroy_ah(struct ib_uverbs_file *file,
1544 1544
1545 idr_remove(&ib_uverbs_ah_idr, cmd.ah_handle); 1545 idr_remove(&ib_uverbs_ah_idr, cmd.ah_handle);
1546 1546
1547 down(&file->mutex); 1547 mutex_lock(&file->mutex);
1548 list_del(&uobj->list); 1548 list_del(&uobj->list);
1549 up(&file->mutex); 1549 mutex_unlock(&file->mutex);
1550 1550
1551 kfree(uobj); 1551 kfree(uobj);
1552 1552
1553out: 1553out:
1554 up(&ib_uverbs_idr_mutex); 1554 mutex_unlock(&ib_uverbs_idr_mutex);
1555 1555
1556 return ret ? ret : in_len; 1556 return ret ? ret : in_len;
1557} 1557}
@@ -1569,7 +1569,7 @@ ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file,
1569 if (copy_from_user(&cmd, buf, sizeof cmd)) 1569 if (copy_from_user(&cmd, buf, sizeof cmd))
1570 return -EFAULT; 1570 return -EFAULT;
1571 1571
1572 down(&ib_uverbs_idr_mutex); 1572 mutex_lock(&ib_uverbs_idr_mutex);
1573 1573
1574 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); 1574 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
1575 if (!qp || qp->uobject->context != file->ucontext) 1575 if (!qp || qp->uobject->context != file->ucontext)
@@ -1602,7 +1602,7 @@ ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file,
1602 kfree(mcast); 1602 kfree(mcast);
1603 1603
1604out: 1604out:
1605 up(&ib_uverbs_idr_mutex); 1605 mutex_unlock(&ib_uverbs_idr_mutex);
1606 1606
1607 return ret ? ret : in_len; 1607 return ret ? ret : in_len;
1608} 1608}
@@ -1620,7 +1620,7 @@ ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file,
1620 if (copy_from_user(&cmd, buf, sizeof cmd)) 1620 if (copy_from_user(&cmd, buf, sizeof cmd))
1621 return -EFAULT; 1621 return -EFAULT;
1622 1622
1623 down(&ib_uverbs_idr_mutex); 1623 mutex_lock(&ib_uverbs_idr_mutex);
1624 1624
1625 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); 1625 qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
1626 if (!qp || qp->uobject->context != file->ucontext) 1626 if (!qp || qp->uobject->context != file->ucontext)
@@ -1641,7 +1641,7 @@ ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file,
1641 } 1641 }
1642 1642
1643out: 1643out:
1644 up(&ib_uverbs_idr_mutex); 1644 mutex_unlock(&ib_uverbs_idr_mutex);
1645 1645
1646 return ret ? ret : in_len; 1646 return ret ? ret : in_len;
1647} 1647}
@@ -1673,7 +1673,7 @@ ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file,
1673 if (!uobj) 1673 if (!uobj)
1674 return -ENOMEM; 1674 return -ENOMEM;
1675 1675
1676 down(&ib_uverbs_idr_mutex); 1676 mutex_lock(&ib_uverbs_idr_mutex);
1677 1677
1678 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); 1678 pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
1679 1679
@@ -1730,11 +1730,11 @@ retry:
1730 goto err_idr; 1730 goto err_idr;
1731 } 1731 }
1732 1732
1733 down(&file->mutex); 1733 mutex_lock(&file->mutex);
1734 list_add_tail(&uobj->uobject.list, &file->ucontext->srq_list); 1734 list_add_tail(&uobj->uobject.list, &file->ucontext->srq_list);
1735 up(&file->mutex); 1735 mutex_unlock(&file->mutex);
1736 1736
1737 up(&ib_uverbs_idr_mutex); 1737 mutex_unlock(&ib_uverbs_idr_mutex);
1738 1738
1739 return in_len; 1739 return in_len;
1740 1740
@@ -1746,7 +1746,7 @@ err_destroy:
1746 atomic_dec(&pd->usecnt); 1746 atomic_dec(&pd->usecnt);
1747 1747
1748err_up: 1748err_up:
1749 up(&ib_uverbs_idr_mutex); 1749 mutex_unlock(&ib_uverbs_idr_mutex);
1750 1750
1751 kfree(uobj); 1751 kfree(uobj);
1752 return ret; 1752 return ret;
@@ -1764,7 +1764,7 @@ ssize_t ib_uverbs_modify_srq(struct ib_uverbs_file *file,
1764 if (copy_from_user(&cmd, buf, sizeof cmd)) 1764 if (copy_from_user(&cmd, buf, sizeof cmd))
1765 return -EFAULT; 1765 return -EFAULT;
1766 1766
1767 down(&ib_uverbs_idr_mutex); 1767 mutex_lock(&ib_uverbs_idr_mutex);
1768 1768
1769 srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle); 1769 srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle);
1770 if (!srq || srq->uobject->context != file->ucontext) { 1770 if (!srq || srq->uobject->context != file->ucontext) {
@@ -1778,7 +1778,7 @@ ssize_t ib_uverbs_modify_srq(struct ib_uverbs_file *file,
1778 ret = ib_modify_srq(srq, &attr, cmd.attr_mask); 1778 ret = ib_modify_srq(srq, &attr, cmd.attr_mask);
1779 1779
1780out: 1780out:
1781 up(&ib_uverbs_idr_mutex); 1781 mutex_unlock(&ib_uverbs_idr_mutex);
1782 1782
1783 return ret ? ret : in_len; 1783 return ret ? ret : in_len;
1784} 1784}
@@ -1796,7 +1796,7 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
1796 if (copy_from_user(&cmd, buf, sizeof cmd)) 1796 if (copy_from_user(&cmd, buf, sizeof cmd))
1797 return -EFAULT; 1797 return -EFAULT;
1798 1798
1799 down(&ib_uverbs_idr_mutex); 1799 mutex_lock(&ib_uverbs_idr_mutex);
1800 1800
1801 memset(&resp, 0, sizeof resp); 1801 memset(&resp, 0, sizeof resp);
1802 1802
@@ -1812,9 +1812,9 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
1812 1812
1813 idr_remove(&ib_uverbs_srq_idr, cmd.srq_handle); 1813 idr_remove(&ib_uverbs_srq_idr, cmd.srq_handle);
1814 1814
1815 down(&file->mutex); 1815 mutex_lock(&file->mutex);
1816 list_del(&uobj->uobject.list); 1816 list_del(&uobj->uobject.list);
1817 up(&file->mutex); 1817 mutex_unlock(&file->mutex);
1818 1818
1819 ib_uverbs_release_uevent(file, uobj); 1819 ib_uverbs_release_uevent(file, uobj);
1820 1820
@@ -1827,7 +1827,7 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
1827 ret = -EFAULT; 1827 ret = -EFAULT;
1828 1828
1829out: 1829out:
1830 up(&ib_uverbs_idr_mutex); 1830 mutex_unlock(&ib_uverbs_idr_mutex);
1831 1831
1832 return ret ? ret : in_len; 1832 return ret ? ret : in_len;
1833} 1833}
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index 81737bd6faea..96ea79b63df7 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -66,7 +66,7 @@ enum {
66 66
67static struct class *uverbs_class; 67static struct class *uverbs_class;
68 68
69DECLARE_MUTEX(ib_uverbs_idr_mutex); 69DEFINE_MUTEX(ib_uverbs_idr_mutex);
70DEFINE_IDR(ib_uverbs_pd_idr); 70DEFINE_IDR(ib_uverbs_pd_idr);
71DEFINE_IDR(ib_uverbs_mr_idr); 71DEFINE_IDR(ib_uverbs_mr_idr);
72DEFINE_IDR(ib_uverbs_mw_idr); 72DEFINE_IDR(ib_uverbs_mw_idr);
@@ -180,7 +180,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
180 if (!context) 180 if (!context)
181 return 0; 181 return 0;
182 182
183 down(&ib_uverbs_idr_mutex); 183 mutex_lock(&ib_uverbs_idr_mutex);
184 184
185 list_for_each_entry_safe(uobj, tmp, &context->ah_list, list) { 185 list_for_each_entry_safe(uobj, tmp, &context->ah_list, list) {
186 struct ib_ah *ah = idr_find(&ib_uverbs_ah_idr, uobj->id); 186 struct ib_ah *ah = idr_find(&ib_uverbs_ah_idr, uobj->id);
@@ -250,7 +250,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
250 kfree(uobj); 250 kfree(uobj);
251 } 251 }
252 252
253 up(&ib_uverbs_idr_mutex); 253 mutex_unlock(&ib_uverbs_idr_mutex);
254 254
255 return context->device->dealloc_ucontext(context); 255 return context->device->dealloc_ucontext(context);
256} 256}
@@ -653,7 +653,7 @@ static int ib_uverbs_open(struct inode *inode, struct file *filp)
653 file->ucontext = NULL; 653 file->ucontext = NULL;
654 file->async_file = NULL; 654 file->async_file = NULL;
655 kref_init(&file->ref); 655 kref_init(&file->ref);
656 init_MUTEX(&file->mutex); 656 mutex_init(&file->mutex);
657 657
658 filp->private_data = file; 658 filp->private_data = file;
659 659
diff --git a/drivers/infiniband/ulp/ipoib/ipoib.h b/drivers/infiniband/ulp/ipoib/ipoib.h
index 9923a15a9996..e0a5412b7e68 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib.h
+++ b/drivers/infiniband/ulp/ipoib/ipoib.h
@@ -45,11 +45,11 @@
45#include <linux/config.h> 45#include <linux/config.h>
46#include <linux/kref.h> 46#include <linux/kref.h>
47#include <linux/if_infiniband.h> 47#include <linux/if_infiniband.h>
48#include <linux/mutex.h>
48 49
49#include <net/neighbour.h> 50#include <net/neighbour.h>
50 51
51#include <asm/atomic.h> 52#include <asm/atomic.h>
52#include <asm/semaphore.h>
53 53
54#include <rdma/ib_verbs.h> 54#include <rdma/ib_verbs.h>
55#include <rdma/ib_pack.h> 55#include <rdma/ib_pack.h>
@@ -123,8 +123,8 @@ struct ipoib_dev_priv {
123 123
124 unsigned long flags; 124 unsigned long flags;
125 125
126 struct semaphore mcast_mutex; 126 struct mutex mcast_mutex;
127 struct semaphore vlan_mutex; 127 struct mutex vlan_mutex;
128 128
129 struct rb_root path_tree; 129 struct rb_root path_tree;
130 struct list_head path_list; 130 struct list_head path_list;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ib.c b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
index f7e848970794..86bcdd72a107 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
@@ -52,7 +52,7 @@ MODULE_PARM_DESC(data_debug_level,
52 52
53#define IPOIB_OP_RECV (1ul << 31) 53#define IPOIB_OP_RECV (1ul << 31)
54 54
55static DECLARE_MUTEX(pkey_sem); 55static DEFINE_MUTEX(pkey_mutex);
56 56
57struct ipoib_ah *ipoib_create_ah(struct net_device *dev, 57struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
58 struct ib_pd *pd, struct ib_ah_attr *attr) 58 struct ib_pd *pd, struct ib_ah_attr *attr)
@@ -445,10 +445,10 @@ int ipoib_ib_dev_down(struct net_device *dev)
445 445
446 /* Shutdown the P_Key thread if still active */ 446 /* Shutdown the P_Key thread if still active */
447 if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) { 447 if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
448 down(&pkey_sem); 448 mutex_lock(&pkey_mutex);
449 set_bit(IPOIB_PKEY_STOP, &priv->flags); 449 set_bit(IPOIB_PKEY_STOP, &priv->flags);
450 cancel_delayed_work(&priv->pkey_task); 450 cancel_delayed_work(&priv->pkey_task);
451 up(&pkey_sem); 451 mutex_unlock(&pkey_mutex);
452 flush_workqueue(ipoib_workqueue); 452 flush_workqueue(ipoib_workqueue);
453 } 453 }
454 454
@@ -599,13 +599,13 @@ void ipoib_ib_dev_flush(void *_dev)
599 if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) 599 if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
600 ipoib_ib_dev_up(dev); 600 ipoib_ib_dev_up(dev);
601 601
602 down(&priv->vlan_mutex); 602 mutex_lock(&priv->vlan_mutex);
603 603
604 /* Flush any child interfaces too */ 604 /* Flush any child interfaces too */
605 list_for_each_entry(cpriv, &priv->child_intfs, list) 605 list_for_each_entry(cpriv, &priv->child_intfs, list)
606 ipoib_ib_dev_flush(&cpriv->dev); 606 ipoib_ib_dev_flush(&cpriv->dev);
607 607
608 up(&priv->vlan_mutex); 608 mutex_unlock(&priv->vlan_mutex);
609} 609}
610 610
611void ipoib_ib_dev_cleanup(struct net_device *dev) 611void ipoib_ib_dev_cleanup(struct net_device *dev)
@@ -651,12 +651,12 @@ void ipoib_pkey_poll(void *dev_ptr)
651 if (test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) 651 if (test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags))
652 ipoib_open(dev); 652 ipoib_open(dev);
653 else { 653 else {
654 down(&pkey_sem); 654 mutex_lock(&pkey_mutex);
655 if (!test_bit(IPOIB_PKEY_STOP, &priv->flags)) 655 if (!test_bit(IPOIB_PKEY_STOP, &priv->flags))
656 queue_delayed_work(ipoib_workqueue, 656 queue_delayed_work(ipoib_workqueue,
657 &priv->pkey_task, 657 &priv->pkey_task,
658 HZ); 658 HZ);
659 up(&pkey_sem); 659 mutex_unlock(&pkey_mutex);
660 } 660 }
661} 661}
662 662
@@ -670,12 +670,12 @@ int ipoib_pkey_dev_delay_open(struct net_device *dev)
670 670
671 /* P_Key value not assigned yet - start polling */ 671 /* P_Key value not assigned yet - start polling */
672 if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) { 672 if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
673 down(&pkey_sem); 673 mutex_lock(&pkey_mutex);
674 clear_bit(IPOIB_PKEY_STOP, &priv->flags); 674 clear_bit(IPOIB_PKEY_STOP, &priv->flags);
675 queue_delayed_work(ipoib_workqueue, 675 queue_delayed_work(ipoib_workqueue,
676 &priv->pkey_task, 676 &priv->pkey_task,
677 HZ); 677 HZ);
678 up(&pkey_sem); 678 mutex_unlock(&pkey_mutex);
679 return 1; 679 return 1;
680 } 680 }
681 681
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 780009c7eaa6..fd3f5c862a5d 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -105,7 +105,7 @@ int ipoib_open(struct net_device *dev)
105 struct ipoib_dev_priv *cpriv; 105 struct ipoib_dev_priv *cpriv;
106 106
107 /* Bring up any child interfaces too */ 107 /* Bring up any child interfaces too */
108 down(&priv->vlan_mutex); 108 mutex_lock(&priv->vlan_mutex);
109 list_for_each_entry(cpriv, &priv->child_intfs, list) { 109 list_for_each_entry(cpriv, &priv->child_intfs, list) {
110 int flags; 110 int flags;
111 111
@@ -115,7 +115,7 @@ int ipoib_open(struct net_device *dev)
115 115
116 dev_change_flags(cpriv->dev, flags | IFF_UP); 116 dev_change_flags(cpriv->dev, flags | IFF_UP);
117 } 117 }
118 up(&priv->vlan_mutex); 118 mutex_unlock(&priv->vlan_mutex);
119 } 119 }
120 120
121 netif_start_queue(dev); 121 netif_start_queue(dev);
@@ -140,7 +140,7 @@ static int ipoib_stop(struct net_device *dev)
140 struct ipoib_dev_priv *cpriv; 140 struct ipoib_dev_priv *cpriv;
141 141
142 /* Bring down any child interfaces too */ 142 /* Bring down any child interfaces too */
143 down(&priv->vlan_mutex); 143 mutex_lock(&priv->vlan_mutex);
144 list_for_each_entry(cpriv, &priv->child_intfs, list) { 144 list_for_each_entry(cpriv, &priv->child_intfs, list) {
145 int flags; 145 int flags;
146 146
@@ -150,7 +150,7 @@ static int ipoib_stop(struct net_device *dev)
150 150
151 dev_change_flags(cpriv->dev, flags & ~IFF_UP); 151 dev_change_flags(cpriv->dev, flags & ~IFF_UP);
152 } 152 }
153 up(&priv->vlan_mutex); 153 mutex_unlock(&priv->vlan_mutex);
154 } 154 }
155 155
156 return 0; 156 return 0;
@@ -892,8 +892,8 @@ static void ipoib_setup(struct net_device *dev)
892 spin_lock_init(&priv->lock); 892 spin_lock_init(&priv->lock);
893 spin_lock_init(&priv->tx_lock); 893 spin_lock_init(&priv->tx_lock);
894 894
895 init_MUTEX(&priv->mcast_mutex); 895 mutex_init(&priv->mcast_mutex);
896 init_MUTEX(&priv->vlan_mutex); 896 mutex_init(&priv->vlan_mutex);
897 897
898 INIT_LIST_HEAD(&priv->path_list); 898 INIT_LIST_HEAD(&priv->path_list);
899 INIT_LIST_HEAD(&priv->child_intfs); 899 INIT_LIST_HEAD(&priv->child_intfs);
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
index 7403bac1977b..98039da0caf0 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
@@ -55,7 +55,7 @@ MODULE_PARM_DESC(mcast_debug_level,
55 "Enable multicast debug tracing if > 0"); 55 "Enable multicast debug tracing if > 0");
56#endif 56#endif
57 57
58static DECLARE_MUTEX(mcast_mutex); 58static DEFINE_MUTEX(mcast_mutex);
59 59
60/* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */ 60/* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */
61struct ipoib_mcast { 61struct ipoib_mcast {
@@ -385,10 +385,10 @@ static void ipoib_mcast_join_complete(int status,
385 385
386 if (!status && !ipoib_mcast_join_finish(mcast, mcmember)) { 386 if (!status && !ipoib_mcast_join_finish(mcast, mcmember)) {
387 mcast->backoff = 1; 387 mcast->backoff = 1;
388 down(&mcast_mutex); 388 mutex_lock(&mcast_mutex);
389 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) 389 if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
390 queue_work(ipoib_workqueue, &priv->mcast_task); 390 queue_work(ipoib_workqueue, &priv->mcast_task);
391 up(&mcast_mutex); 391 mutex_unlock(&mcast_mutex);
392 complete(&mcast->done); 392 complete(&mcast->done);
393 return; 393 return;
394 } 394 }
@@ -418,7 +418,7 @@ static void ipoib_mcast_join_complete(int status,
418 418
419 mcast->query = NULL; 419 mcast->query = NULL;
420 420
421 down(&mcast_mutex); 421 mutex_lock(&mcast_mutex);
422 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) { 422 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) {
423 if (status == -ETIMEDOUT) 423 if (status == -ETIMEDOUT)
424 queue_work(ipoib_workqueue, &priv->mcast_task); 424 queue_work(ipoib_workqueue, &priv->mcast_task);
@@ -427,7 +427,7 @@ static void ipoib_mcast_join_complete(int status,
427 mcast->backoff * HZ); 427 mcast->backoff * HZ);
428 } else 428 } else
429 complete(&mcast->done); 429 complete(&mcast->done);
430 up(&mcast_mutex); 430 mutex_unlock(&mcast_mutex);
431 431
432 return; 432 return;
433} 433}
@@ -482,12 +482,12 @@ static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast,
482 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS) 482 if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS)
483 mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS; 483 mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS;
484 484
485 down(&mcast_mutex); 485 mutex_lock(&mcast_mutex);
486 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) 486 if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
487 queue_delayed_work(ipoib_workqueue, 487 queue_delayed_work(ipoib_workqueue,
488 &priv->mcast_task, 488 &priv->mcast_task,
489 mcast->backoff * HZ); 489 mcast->backoff * HZ);
490 up(&mcast_mutex); 490 mutex_unlock(&mcast_mutex);
491 } else 491 } else
492 mcast->query_id = ret; 492 mcast->query_id = ret;
493} 493}
@@ -520,11 +520,11 @@ void ipoib_mcast_join_task(void *dev_ptr)
520 priv->broadcast = ipoib_mcast_alloc(dev, 1); 520 priv->broadcast = ipoib_mcast_alloc(dev, 1);
521 if (!priv->broadcast) { 521 if (!priv->broadcast) {
522 ipoib_warn(priv, "failed to allocate broadcast group\n"); 522 ipoib_warn(priv, "failed to allocate broadcast group\n");
523 down(&mcast_mutex); 523 mutex_lock(&mcast_mutex);
524 if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) 524 if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
525 queue_delayed_work(ipoib_workqueue, 525 queue_delayed_work(ipoib_workqueue,
526 &priv->mcast_task, HZ); 526 &priv->mcast_task, HZ);
527 up(&mcast_mutex); 527 mutex_unlock(&mcast_mutex);
528 return; 528 return;
529 } 529 }
530 530
@@ -580,10 +580,10 @@ int ipoib_mcast_start_thread(struct net_device *dev)
580 580
581 ipoib_dbg_mcast(priv, "starting multicast thread\n"); 581 ipoib_dbg_mcast(priv, "starting multicast thread\n");
582 582
583 down(&mcast_mutex); 583 mutex_lock(&mcast_mutex);
584 if (!test_and_set_bit(IPOIB_MCAST_RUN, &priv->flags)) 584 if (!test_and_set_bit(IPOIB_MCAST_RUN, &priv->flags))
585 queue_work(ipoib_workqueue, &priv->mcast_task); 585 queue_work(ipoib_workqueue, &priv->mcast_task);
586 up(&mcast_mutex); 586 mutex_unlock(&mcast_mutex);
587 587
588 return 0; 588 return 0;
589} 589}
@@ -595,10 +595,10 @@ int ipoib_mcast_stop_thread(struct net_device *dev, int flush)
595 595
596 ipoib_dbg_mcast(priv, "stopping multicast thread\n"); 596 ipoib_dbg_mcast(priv, "stopping multicast thread\n");
597 597
598 down(&mcast_mutex); 598 mutex_lock(&mcast_mutex);
599 clear_bit(IPOIB_MCAST_RUN, &priv->flags); 599 clear_bit(IPOIB_MCAST_RUN, &priv->flags);
600 cancel_delayed_work(&priv->mcast_task); 600 cancel_delayed_work(&priv->mcast_task);
601 up(&mcast_mutex); 601 mutex_unlock(&mcast_mutex);
602 602
603 if (flush) 603 if (flush)
604 flush_workqueue(ipoib_workqueue); 604 flush_workqueue(ipoib_workqueue);
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
index e829e10400e3..faaf10e5fc7b 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
@@ -65,9 +65,9 @@ int ipoib_mcast_attach(struct net_device *dev, u16 mlid, union ib_gid *mgid)
65 } 65 }
66 66
67 /* attach QP to multicast group */ 67 /* attach QP to multicast group */
68 down(&priv->mcast_mutex); 68 mutex_lock(&priv->mcast_mutex);
69 ret = ib_attach_mcast(priv->qp, mgid, mlid); 69 ret = ib_attach_mcast(priv->qp, mgid, mlid);
70 up(&priv->mcast_mutex); 70 mutex_unlock(&priv->mcast_mutex);
71 if (ret) 71 if (ret)
72 ipoib_warn(priv, "failed to attach to multicast group, ret = %d\n", ret); 72 ipoib_warn(priv, "failed to attach to multicast group, ret = %d\n", ret);
73 73
@@ -81,9 +81,9 @@ int ipoib_mcast_detach(struct net_device *dev, u16 mlid, union ib_gid *mgid)
81 struct ipoib_dev_priv *priv = netdev_priv(dev); 81 struct ipoib_dev_priv *priv = netdev_priv(dev);
82 int ret; 82 int ret;
83 83
84 down(&priv->mcast_mutex); 84 mutex_lock(&priv->mcast_mutex);
85 ret = ib_detach_mcast(priv->qp, mgid, mlid); 85 ret = ib_detach_mcast(priv->qp, mgid, mlid);
86 up(&priv->mcast_mutex); 86 mutex_unlock(&priv->mcast_mutex);
87 if (ret) 87 if (ret)
88 ipoib_warn(priv, "ib_detach_mcast failed (result = %d)\n", ret); 88 ipoib_warn(priv, "ib_detach_mcast failed (result = %d)\n", ret);
89 89
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_vlan.c b/drivers/infiniband/ulp/ipoib/ipoib_vlan.c
index d280b341a37f..4ca175553f9f 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_vlan.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_vlan.c
@@ -63,7 +63,7 @@ int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey)
63 63
64 ppriv = netdev_priv(pdev); 64 ppriv = netdev_priv(pdev);
65 65
66 down(&ppriv->vlan_mutex); 66 mutex_lock(&ppriv->vlan_mutex);
67 67
68 /* 68 /*
69 * First ensure this isn't a duplicate. We check the parent device and 69 * First ensure this isn't a duplicate. We check the parent device and
@@ -124,7 +124,7 @@ int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey)
124 124
125 list_add_tail(&priv->list, &ppriv->child_intfs); 125 list_add_tail(&priv->list, &ppriv->child_intfs);
126 126
127 up(&ppriv->vlan_mutex); 127 mutex_unlock(&ppriv->vlan_mutex);
128 128
129 return 0; 129 return 0;
130 130
@@ -139,7 +139,7 @@ device_init_failed:
139 free_netdev(priv->dev); 139 free_netdev(priv->dev);
140 140
141err: 141err:
142 up(&ppriv->vlan_mutex); 142 mutex_unlock(&ppriv->vlan_mutex);
143 return result; 143 return result;
144} 144}
145 145
@@ -153,7 +153,7 @@ int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey)
153 153
154 ppriv = netdev_priv(pdev); 154 ppriv = netdev_priv(pdev);
155 155
156 down(&ppriv->vlan_mutex); 156 mutex_lock(&ppriv->vlan_mutex);
157 list_for_each_entry_safe(priv, tpriv, &ppriv->child_intfs, list) { 157 list_for_each_entry_safe(priv, tpriv, &ppriv->child_intfs, list) {
158 if (priv->pkey == pkey) { 158 if (priv->pkey == pkey) {
159 unregister_netdev(priv->dev); 159 unregister_netdev(priv->dev);
@@ -167,7 +167,7 @@ int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey)
167 break; 167 break;
168 } 168 }
169 } 169 }
170 up(&ppriv->vlan_mutex); 170 mutex_unlock(&ppriv->vlan_mutex);
171 171
172 return ret; 172 return ret;
173} 173}