Commit 95ed644f authored by Ingo Molnar's avatar Ingo Molnar Committed by Roland Dreier

IB: convert from semaphores to mutexes

semaphore to mutex conversion by Ingo and Arjan's script.
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
[ Sanity-checked on real IB hardware ]
Signed-off-by: default avatarRoland Dreier <rolandd@cisco.com>
parent 9eacee2a
...@@ -38,8 +38,7 @@ ...@@ -38,8 +38,7 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/mutex.h>
#include <asm/semaphore.h>
#include "core_priv.h" #include "core_priv.h"
...@@ -57,13 +56,13 @@ static LIST_HEAD(device_list); ...@@ -57,13 +56,13 @@ static LIST_HEAD(device_list);
static LIST_HEAD(client_list); static LIST_HEAD(client_list);
/* /*
* device_sem protects access to both device_list and client_list. * device_mutex protects access to both device_list and client_list.
* There's no real point to using multiple locks or something fancier * There's no real point to using multiple locks or something fancier
* like an rwsem: we always access both lists, and we're always * like an rwsem: we always access both lists, and we're always
* modifying one list or the other list. In any case this is not a * modifying one list or the other list. In any case this is not a
* hot path so there's no point in trying to optimize. * hot path so there's no point in trying to optimize.
*/ */
static DECLARE_MUTEX(device_sem); static DEFINE_MUTEX(device_mutex);
static int ib_device_check_mandatory(struct ib_device *device) static int ib_device_check_mandatory(struct ib_device *device)
{ {
...@@ -221,7 +220,7 @@ int ib_register_device(struct ib_device *device) ...@@ -221,7 +220,7 @@ int ib_register_device(struct ib_device *device)
{ {
int ret; int ret;
down(&device_sem); mutex_lock(&device_mutex);
if (strchr(device->name, '%')) { if (strchr(device->name, '%')) {
ret = alloc_name(device->name); ret = alloc_name(device->name);
...@@ -259,7 +258,7 @@ int ib_register_device(struct ib_device *device) ...@@ -259,7 +258,7 @@ int ib_register_device(struct ib_device *device)
} }
out: out:
up(&device_sem); mutex_unlock(&device_mutex);
return ret; return ret;
} }
EXPORT_SYMBOL(ib_register_device); EXPORT_SYMBOL(ib_register_device);
...@@ -276,7 +275,7 @@ void ib_unregister_device(struct ib_device *device) ...@@ -276,7 +275,7 @@ void ib_unregister_device(struct ib_device *device)
struct ib_client_data *context, *tmp; struct ib_client_data *context, *tmp;
unsigned long flags; unsigned long flags;
down(&device_sem); mutex_lock(&device_mutex);
list_for_each_entry_reverse(client, &client_list, list) list_for_each_entry_reverse(client, &client_list, list)
if (client->remove) if (client->remove)
...@@ -284,7 +283,7 @@ void ib_unregister_device(struct ib_device *device) ...@@ -284,7 +283,7 @@ void ib_unregister_device(struct ib_device *device)
list_del(&device->core_list); list_del(&device->core_list);
up(&device_sem); mutex_unlock(&device_mutex);
spin_lock_irqsave(&device->client_data_lock, flags); spin_lock_irqsave(&device->client_data_lock, flags);
list_for_each_entry_safe(context, tmp, &device->client_data_list, list) 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,14 +311,14 @@ int ib_register_client(struct ib_client *client)
{ {
struct ib_device *device; struct ib_device *device;
down(&device_sem); mutex_lock(&device_mutex);
list_add_tail(&client->list, &client_list); list_add_tail(&client->list, &client_list);
list_for_each_entry(device, &device_list, core_list) list_for_each_entry(device, &device_list, core_list)
if (client->add && !add_client_context(device, client)) if (client->add && !add_client_context(device, client))
client->add(device); client->add(device);
up(&device_sem); mutex_unlock(&device_mutex);
return 0; return 0;
} }
...@@ -339,7 +338,7 @@ void ib_unregister_client(struct ib_client *client) ...@@ -339,7 +338,7 @@ void ib_unregister_client(struct ib_client *client)
struct ib_device *device; struct ib_device *device;
unsigned long flags; unsigned long flags;
down(&device_sem); mutex_lock(&device_mutex);
list_for_each_entry(device, &device_list, core_list) { list_for_each_entry(device, &device_list, core_list) {
if (client->remove) if (client->remove)
...@@ -355,7 +354,7 @@ void ib_unregister_client(struct ib_client *client) ...@@ -355,7 +354,7 @@ void ib_unregister_client(struct ib_client *client)
} }
list_del(&client->list); list_del(&client->list);
up(&device_sem); mutex_unlock(&device_mutex);
} }
EXPORT_SYMBOL(ib_unregister_client); EXPORT_SYMBOL(ib_unregister_client);
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <linux/mount.h> #include <linux/mount.h>
#include <linux/cdev.h> #include <linux/cdev.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/mutex.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
...@@ -113,7 +114,7 @@ static struct ib_client ucm_client = { ...@@ -113,7 +114,7 @@ static struct ib_client ucm_client = {
.remove = ib_ucm_remove_one .remove = ib_ucm_remove_one
}; };
static DECLARE_MUTEX(ctx_id_mutex); static DEFINE_MUTEX(ctx_id_mutex);
static DEFINE_IDR(ctx_id_table); static DEFINE_IDR(ctx_id_table);
static DECLARE_BITMAP(dev_map, IB_UCM_MAX_DEVICES); static DECLARE_BITMAP(dev_map, IB_UCM_MAX_DEVICES);
...@@ -121,7 +122,7 @@ static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id) ...@@ -121,7 +122,7 @@ static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id)
{ {
struct ib_ucm_context *ctx; struct ib_ucm_context *ctx;
down(&ctx_id_mutex); mutex_lock(&ctx_id_mutex);
ctx = idr_find(&ctx_id_table, id); ctx = idr_find(&ctx_id_table, id);
if (!ctx) if (!ctx)
ctx = ERR_PTR(-ENOENT); 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,7 +130,7 @@ static struct ib_ucm_context *ib_ucm_ctx_get(struct ib_ucm_file *file, int id)
ctx = ERR_PTR(-EINVAL); ctx = ERR_PTR(-EINVAL);
else else
atomic_inc(&ctx->ref); atomic_inc(&ctx->ref);
up(&ctx_id_mutex); mutex_unlock(&ctx_id_mutex);
return ctx; return ctx;
} }
...@@ -186,9 +187,9 @@ static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file) ...@@ -186,9 +187,9 @@ static struct ib_ucm_context *ib_ucm_ctx_alloc(struct ib_ucm_file *file)
if (!result) if (!result)
goto error; goto error;
down(&ctx_id_mutex); mutex_lock(&ctx_id_mutex);
result = idr_get_new(&ctx_id_table, ctx, &ctx->id); result = idr_get_new(&ctx_id_table, ctx, &ctx->id);
up(&ctx_id_mutex); mutex_unlock(&ctx_id_mutex);
} while (result == -EAGAIN); } while (result == -EAGAIN);
if (result) if (result)
...@@ -550,9 +551,9 @@ static ssize_t ib_ucm_create_id(struct ib_ucm_file *file, ...@@ -550,9 +551,9 @@ static ssize_t ib_ucm_create_id(struct ib_ucm_file *file,
err2: err2:
ib_destroy_cm_id(ctx->cm_id); ib_destroy_cm_id(ctx->cm_id);
err1: err1:
down(&ctx_id_mutex); mutex_lock(&ctx_id_mutex);
idr_remove(&ctx_id_table, ctx->id); idr_remove(&ctx_id_table, ctx->id);
up(&ctx_id_mutex); mutex_unlock(&ctx_id_mutex);
kfree(ctx); kfree(ctx);
return result; return result;
} }
...@@ -572,7 +573,7 @@ static ssize_t ib_ucm_destroy_id(struct ib_ucm_file *file, ...@@ -572,7 +573,7 @@ static ssize_t ib_ucm_destroy_id(struct ib_ucm_file *file,
if (copy_from_user(&cmd, inbuf, sizeof(cmd))) if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
return -EFAULT; return -EFAULT;
down(&ctx_id_mutex); mutex_lock(&ctx_id_mutex);
ctx = idr_find(&ctx_id_table, cmd.id); ctx = idr_find(&ctx_id_table, cmd.id);
if (!ctx) if (!ctx)
ctx = ERR_PTR(-ENOENT); ctx = ERR_PTR(-ENOENT);
...@@ -580,7 +581,7 @@ static ssize_t ib_ucm_destroy_id(struct ib_ucm_file *file, ...@@ -580,7 +581,7 @@ static ssize_t ib_ucm_destroy_id(struct ib_ucm_file *file,
ctx = ERR_PTR(-EINVAL); ctx = ERR_PTR(-EINVAL);
else else
idr_remove(&ctx_id_table, ctx->id); idr_remove(&ctx_id_table, ctx->id);
up(&ctx_id_mutex); mutex_unlock(&ctx_id_mutex);
if (IS_ERR(ctx)) if (IS_ERR(ctx))
return PTR_ERR(ctx); return PTR_ERR(ctx);
...@@ -1280,9 +1281,9 @@ static int ib_ucm_close(struct inode *inode, struct file *filp) ...@@ -1280,9 +1281,9 @@ static int ib_ucm_close(struct inode *inode, struct file *filp)
struct ib_ucm_context, file_list); struct ib_ucm_context, file_list);
up(&file->mutex); up(&file->mutex);
down(&ctx_id_mutex); mutex_lock(&ctx_id_mutex);
idr_remove(&ctx_id_table, ctx->id); idr_remove(&ctx_id_table, ctx->id);
up(&ctx_id_mutex); mutex_unlock(&ctx_id_mutex);
ib_destroy_cm_id(ctx->cm_id); ib_destroy_cm_id(ctx->cm_id);
ib_ucm_cleanup_events(ctx); ib_ucm_cleanup_events(ctx);
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <linux/kref.h> #include <linux/kref.h>
#include <linux/idr.h> #include <linux/idr.h>
#include <linux/mutex.h>
#include <rdma/ib_verbs.h> #include <rdma/ib_verbs.h>
#include <rdma/ib_user_verbs.h> #include <rdma/ib_user_verbs.h>
...@@ -88,7 +89,7 @@ struct ib_uverbs_event_file { ...@@ -88,7 +89,7 @@ struct ib_uverbs_event_file {
struct ib_uverbs_file { struct ib_uverbs_file {
struct kref ref; struct kref ref;
struct semaphore mutex; struct mutex mutex;
struct ib_uverbs_device *device; struct ib_uverbs_device *device;
struct ib_ucontext *ucontext; struct ib_ucontext *ucontext;
struct ib_event_handler event_handler; struct ib_event_handler event_handler;
...@@ -131,7 +132,7 @@ struct ib_ucq_object { ...@@ -131,7 +132,7 @@ struct ib_ucq_object {
u32 async_events_reported; u32 async_events_reported;
}; };
extern struct semaphore ib_uverbs_idr_mutex; extern struct mutex ib_uverbs_idr_mutex;
extern struct idr ib_uverbs_pd_idr; extern struct idr ib_uverbs_pd_idr;
extern struct idr ib_uverbs_mr_idr; extern struct idr ib_uverbs_mr_idr;
extern struct idr ib_uverbs_mw_idr; extern struct idr ib_uverbs_mw_idr;
......
...@@ -67,7 +67,7 @@ ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file, ...@@ -67,7 +67,7 @@ ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
if (copy_from_user(&cmd, buf, sizeof cmd)) if (copy_from_user(&cmd, buf, sizeof cmd))
return -EFAULT; return -EFAULT;
down(&file->mutex); mutex_lock(&file->mutex);
if (file->ucontext) { if (file->ucontext) {
ret = -EINVAL; ret = -EINVAL;
...@@ -119,7 +119,7 @@ ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file, ...@@ -119,7 +119,7 @@ ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
fd_install(resp.async_fd, filp); fd_install(resp.async_fd, filp);
up(&file->mutex); mutex_unlock(&file->mutex);
return in_len; return in_len;
...@@ -131,7 +131,7 @@ ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file, ...@@ -131,7 +131,7 @@ ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
ibdev->dealloc_ucontext(ucontext); ibdev->dealloc_ucontext(ucontext);
err: err:
up(&file->mutex); mutex_unlock(&file->mutex);
return ret; return ret;
} }
...@@ -290,7 +290,7 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file, ...@@ -290,7 +290,7 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file,
pd->uobject = uobj; pd->uobject = uobj;
atomic_set(&pd->usecnt, 0); atomic_set(&pd->usecnt, 0);
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
retry: retry:
if (!idr_pre_get(&ib_uverbs_pd_idr, GFP_KERNEL)) { if (!idr_pre_get(&ib_uverbs_pd_idr, GFP_KERNEL)) {
...@@ -314,11 +314,11 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file, ...@@ -314,11 +314,11 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file,
goto err_idr; goto err_idr;
} }
down(&file->mutex); mutex_lock(&file->mutex);
list_add_tail(&uobj->list, &file->ucontext->pd_list); list_add_tail(&uobj->list, &file->ucontext->pd_list);
up(&file->mutex); mutex_unlock(&file->mutex);
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return in_len; return in_len;
...@@ -326,7 +326,7 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file, ...@@ -326,7 +326,7 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file,
idr_remove(&ib_uverbs_pd_idr, uobj->id); idr_remove(&ib_uverbs_pd_idr, uobj->id);
err_up: err_up:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
ib_dealloc_pd(pd); ib_dealloc_pd(pd);
err: err:
...@@ -346,7 +346,7 @@ ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file, ...@@ -346,7 +346,7 @@ ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file,
if (copy_from_user(&cmd, buf, sizeof cmd)) if (copy_from_user(&cmd, buf, sizeof cmd))
return -EFAULT; return -EFAULT;
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
if (!pd || pd->uobject->context != file->ucontext) if (!pd || pd->uobject->context != file->ucontext)
...@@ -360,14 +360,14 @@ ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file, ...@@ -360,14 +360,14 @@ ssize_t ib_uverbs_dealloc_pd(struct ib_uverbs_file *file,
idr_remove(&ib_uverbs_pd_idr, cmd.pd_handle); idr_remove(&ib_uverbs_pd_idr, cmd.pd_handle);
down(&file->mutex); mutex_lock(&file->mutex);
list_del(&uobj->list); list_del(&uobj->list);
up(&file->mutex); mutex_unlock(&file->mutex);
kfree(uobj); kfree(uobj);
out: out:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return ret ? ret : in_len; return ret ? ret : in_len;
} }
...@@ -426,7 +426,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file, ...@@ -426,7 +426,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
obj->umem.virt_base = cmd.hca_va; obj->umem.virt_base = cmd.hca_va;
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
if (!pd || pd->uobject->context != file->ucontext) { if (!pd || pd->uobject->context != file->ucontext) {
...@@ -476,11 +476,11 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file, ...@@ -476,11 +476,11 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
goto err_idr; goto err_idr;
} }
down(&file->mutex); mutex_lock(&file->mutex);
list_add_tail(&obj->uobject.list, &file->ucontext->mr_list); list_add_tail(&obj->uobject.list, &file->ucontext->mr_list);
up(&file->mutex); mutex_unlock(&file->mutex);
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return in_len; return in_len;
...@@ -492,7 +492,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file, ...@@ -492,7 +492,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
atomic_dec(&pd->usecnt); atomic_dec(&pd->usecnt);
err_up: err_up:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
ib_umem_release(file->device->ib_dev, &obj->umem); ib_umem_release(file->device->ib_dev, &obj->umem);
...@@ -513,7 +513,7 @@ ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file, ...@@ -513,7 +513,7 @@ ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file,
if (copy_from_user(&cmd, buf, sizeof cmd)) if (copy_from_user(&cmd, buf, sizeof cmd))
return -EFAULT; return -EFAULT;
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
mr = idr_find(&ib_uverbs_mr_idr, cmd.mr_handle); mr = idr_find(&ib_uverbs_mr_idr, cmd.mr_handle);
if (!mr || mr->uobject->context != file->ucontext) if (!mr || mr->uobject->context != file->ucontext)
...@@ -527,15 +527,15 @@ ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file, ...@@ -527,15 +527,15 @@ ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file,
idr_remove(&ib_uverbs_mr_idr, cmd.mr_handle); idr_remove(&ib_uverbs_mr_idr, cmd.mr_handle);
down(&file->mutex); mutex_lock(&file->mutex);
list_del(&memobj->uobject.list); list_del(&memobj->uobject.list);
up(&file->mutex); mutex_unlock(&file->mutex);
ib_umem_release(file->device->ib_dev, &memobj->umem); ib_umem_release(file->device->ib_dev, &memobj->umem);
kfree(memobj); kfree(memobj);
out: out:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return ret ? ret : in_len; return ret ? ret : in_len;
} }
...@@ -628,7 +628,7 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file, ...@@ -628,7 +628,7 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
cq->cq_context = ev_file; cq->cq_context = ev_file;
atomic_set(&cq->usecnt, 0); atomic_set(&cq->usecnt, 0);
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
retry: retry:
if (!idr_pre_get(&ib_uverbs_cq_idr, GFP_KERNEL)) { if (!idr_pre_get(&ib_uverbs_cq_idr, GFP_KERNEL)) {
...@@ -653,11 +653,11 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file, ...@@ -653,11 +653,11 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
goto err_idr; goto err_idr;
} }
down(&file->mutex); mutex_lock(&file->mutex);
list_add_tail(&uobj->uobject.list, &file->ucontext->cq_list); list_add_tail(&uobj->uobject.list, &file->ucontext->cq_list);
up(&file->mutex); mutex_unlock(&file->mutex);
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return in_len; return in_len;
...@@ -665,7 +665,7 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file, ...@@ -665,7 +665,7 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file,
idr_remove(&ib_uverbs_cq_idr, uobj->uobject.id); idr_remove(&ib_uverbs_cq_idr, uobj->uobject.id);
err_up: err_up:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
ib_destroy_cq(cq); ib_destroy_cq(cq);
err: err:
...@@ -701,7 +701,7 @@ ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file, ...@@ -701,7 +701,7 @@ ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file,
goto out_wc; goto out_wc;
} }
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle); cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle);
if (!cq || cq->uobject->context != file->ucontext) { if (!cq || cq->uobject->context != file->ucontext) {
ret = -EINVAL; ret = -EINVAL;
...@@ -731,7 +731,7 @@ ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file, ...@@ -731,7 +731,7 @@ ssize_t ib_uverbs_poll_cq(struct ib_uverbs_file *file,
ret = -EFAULT; ret = -EFAULT;
out: out:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
kfree(resp); kfree(resp);
out_wc: out_wc:
...@@ -750,14 +750,14 @@ ssize_t ib_uverbs_req_notify_cq(struct ib_uverbs_file *file, ...@@ -750,14 +750,14 @@ ssize_t ib_uverbs_req_notify_cq(struct ib_uverbs_file *file,
if (copy_from_user(&cmd, buf, sizeof cmd)) if (copy_from_user(&cmd, buf, sizeof cmd))
return -EFAULT; return -EFAULT;
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle); cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle);
if (cq && cq->uobject->context == file->ucontext) { if (cq && cq->uobject->context == file->ucontext) {
ib_req_notify_cq(cq, cmd.solicited_only ? ib_req_notify_cq(cq, cmd.solicited_only ?
IB_CQ_SOLICITED : IB_CQ_NEXT_COMP); IB_CQ_SOLICITED : IB_CQ_NEXT_COMP);
ret = in_len; ret = in_len;
} }
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return ret; return ret;
} }
...@@ -779,7 +779,7 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file, ...@@ -779,7 +779,7 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
memset(&resp, 0, sizeof resp); memset(&resp, 0, sizeof resp);
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle); cq = idr_find(&ib_uverbs_cq_idr, cmd.cq_handle);
if (!cq || cq->uobject->context != file->ucontext) if (!cq || cq->uobject->context != file->ucontext)
...@@ -795,9 +795,9 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file, ...@@ -795,9 +795,9 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
idr_remove(&ib_uverbs_cq_idr, cmd.cq_handle); idr_remove(&ib_uverbs_cq_idr, cmd.cq_handle);
down(&file->mutex); mutex_lock(&file->mutex);
list_del(&uobj->uobject.list); list_del(&uobj->uobject.list);
up(&file->mutex); mutex_unlock(&file->mutex);
ib_uverbs_release_ucq(file, ev_file, uobj); ib_uverbs_release_ucq(file, ev_file, uobj);
...@@ -811,7 +811,7 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file, ...@@ -811,7 +811,7 @@ ssize_t ib_uverbs_destroy_cq(struct ib_uverbs_file *file,
ret = -EFAULT; ret = -EFAULT;
out: out:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return ret ? ret : in_len; return ret ? ret : in_len;
} }
...@@ -845,7 +845,7 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file, ...@@ -845,7 +845,7 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
if (!uobj) if (!uobj)
return -ENOMEM; return -ENOMEM;
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
scq = idr_find(&ib_uverbs_cq_idr, cmd.send_cq_handle); scq = idr_find(&ib_uverbs_cq_idr, cmd.send_cq_handle);
...@@ -930,11 +930,11 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file, ...@@ -930,11 +930,11 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
goto err_idr; goto err_idr;
} }
down(&file->mutex); mutex_lock(&file->mutex);
list_add_tail(&uobj->uevent.uobject.list, &file->ucontext->qp_list); list_add_tail(&uobj->uevent.uobject.list, &file->ucontext->qp_list);
up(&file->mutex); mutex_unlock(&file->mutex);
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return in_len; return in_len;
...@@ -950,7 +950,7 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file, ...@@ -950,7 +950,7 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file,
atomic_dec(&attr.srq->usecnt); atomic_dec(&attr.srq->usecnt);
err_up: err_up:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
kfree(uobj); kfree(uobj);
return ret; return ret;
...@@ -972,7 +972,7 @@ ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file, ...@@ -972,7 +972,7 @@ ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file,
if (!attr) if (!attr)
return -ENOMEM; return -ENOMEM;
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
if (!qp || qp->uobject->context != file->ucontext) { if (!qp || qp->uobject->context != file->ucontext) {
...@@ -1033,7 +1033,7 @@ ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file, ...@@ -1033,7 +1033,7 @@ ssize_t ib_uverbs_modify_qp(struct ib_uverbs_file *file,
ret = in_len; ret = in_len;
out: out:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
kfree(attr); kfree(attr);
return ret; return ret;
...@@ -1054,7 +1054,7 @@ ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file, ...@@ -1054,7 +1054,7 @@ ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file,
memset(&resp, 0, sizeof resp); memset(&resp, 0, sizeof resp);
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
if (!qp || qp->uobject->context != file->ucontext) if (!qp || qp->uobject->context != file->ucontext)
...@@ -1073,9 +1073,9 @@ ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file, ...@@ -1073,9 +1073,9 @@ ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file,
idr_remove(&ib_uverbs_qp_idr, cmd.qp_handle); idr_remove(&ib_uverbs_qp_idr, cmd.qp_handle);
down(&file->mutex); mutex_lock(&file->mutex);
list_del(&uobj->uevent.uobject.list); list_del(&uobj->uevent.uobject.list);
up(&file->mutex); mutex_unlock(&file->mutex);
ib_uverbs_release_uevent(file, &uobj->uevent); ib_uverbs_release_uevent(file, &uobj->uevent);
...@@ -1088,7 +1088,7 @@ ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file, ...@@ -1088,7 +1088,7 @@ ssize_t ib_uverbs_destroy_qp(struct ib_uverbs_file *file,
ret = -EFAULT; ret = -EFAULT;
out: out:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return ret ? ret : in_len; return ret ? ret : in_len;
} }
...@@ -1119,7 +1119,7 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file, ...@@ -1119,7 +1119,7 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
if (!user_wr) if (!user_wr)
return -ENOMEM; return -ENOMEM;
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
if (!qp || qp->uobject->context != file->ucontext) if (!qp || qp->uobject->context != file->ucontext)
...@@ -1224,7 +1224,7 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file, ...@@ -1224,7 +1224,7 @@ ssize_t ib_uverbs_post_send(struct ib_uverbs_file *file,
ret = -EFAULT; ret = -EFAULT;
out: out:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
while (wr) { while (wr) {
next = wr->next; next = wr->next;
...@@ -1341,7 +1341,7 @@ ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file, ...@@ -1341,7 +1341,7 @@ ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file,
if (IS_ERR(wr)) if (IS_ERR(wr))
return PTR_ERR(wr); return PTR_ERR(wr);
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
if (!qp || qp->uobject->context != file->ucontext) if (!qp || qp->uobject->context != file->ucontext)
...@@ -1362,7 +1362,7 @@ ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file, ...@@ -1362,7 +1362,7 @@ ssize_t ib_uverbs_post_recv(struct ib_uverbs_file *file,
ret = -EFAULT; ret = -EFAULT;
out: out:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
while (wr) { while (wr) {
next = wr->next; next = wr->next;
...@@ -1392,7 +1392,7 @@ ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file, ...@@ -1392,7 +1392,7 @@ ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file,
if (IS_ERR(wr)) if (IS_ERR(wr))
return PTR_ERR(wr); return PTR_ERR(wr);
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle); srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle);
if (!srq || srq->uobject->context != file->ucontext) if (!srq || srq->uobject->context != file->ucontext)
...@@ -1413,7 +1413,7 @@ ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file, ...@@ -1413,7 +1413,7 @@ ssize_t ib_uverbs_post_srq_recv(struct ib_uverbs_file *file,
ret = -EFAULT; ret = -EFAULT;
out: out:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
while (wr) { while (wr) {
next = wr->next; next = wr->next;
...@@ -1446,7 +1446,7 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file, ...@@ -1446,7 +1446,7 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file,
if (!uobj) if (!uobj)
return -ENOMEM; return -ENOMEM;
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
if (!pd || pd->uobject->context != file->ucontext) { if (!pd || pd->uobject->context != file->ucontext) {
...@@ -1498,11 +1498,11 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file, ...@@ -1498,11 +1498,11 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file,
goto err_idr; goto err_idr;
} }
down(&file->mutex); mutex_lock(&file->mutex);
list_add_tail(&uobj->list, &file->ucontext->ah_list); list_add_tail(&uobj->list, &file->ucontext->ah_list);
up(&file->mutex); mutex_unlock(&file->mutex);
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return in_len; return in_len;
...@@ -1513,7 +1513,7 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file, ...@@ -1513,7 +1513,7 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file,
ib_destroy_ah(ah); ib_destroy_ah(ah);
err_up: err_up:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
kfree(uobj); kfree(uobj);
return ret; return ret;
...@@ -1530,7 +1530,7 @@ ssize_t ib_uverbs_destroy_ah(struct ib_uverbs_file *file, ...@@ -1530,7 +1530,7 @@ ssize_t ib_uverbs_destroy_ah(struct ib_uverbs_file *file,
if (copy_from_user(&cmd, buf, sizeof cmd)) if (copy_from_user(&cmd, buf, sizeof cmd))
return -EFAULT; return -EFAULT;
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
ah = idr_find(&ib_uverbs_ah_idr, cmd.ah_handle); ah = idr_find(&ib_uverbs_ah_idr, cmd.ah_handle);
if (!ah || ah->uobject->context != file->ucontext) if (!ah || ah->uobject->context != file->ucontext)
...@@ -1544,14 +1544,14 @@ ssize_t ib_uverbs_destroy_ah(struct ib_uverbs_file *file, ...@@ -1544,14 +1544,14 @@ ssize_t ib_uverbs_destroy_ah(struct ib_uverbs_file *file,
idr_remove(&ib_uverbs_ah_idr, cmd.ah_handle); idr_remove(&ib_uverbs_ah_idr, cmd.ah_handle);
down(&file->mutex); mutex_lock(&file->mutex);
list_del(&uobj->list); list_del(&uobj->list);
up(&file->mutex); mutex_unlock(&file->mutex);
kfree(uobj); kfree(uobj);
out: out:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return ret ? ret : in_len; return ret ? ret : in_len;
} }
...@@ -1569,7 +1569,7 @@ ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file, ...@@ -1569,7 +1569,7 @@ ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file,
if (copy_from_user(&cmd, buf, sizeof cmd)) if (copy_from_user(&cmd, buf, sizeof cmd))
return -EFAULT; return -EFAULT;
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
if (!qp || qp->uobject->context != file->ucontext) if (!qp || qp->uobject->context != file->ucontext)
...@@ -1602,7 +1602,7 @@ ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file, ...@@ -1602,7 +1602,7 @@ ssize_t ib_uverbs_attach_mcast(struct ib_uverbs_file *file,
kfree(mcast); kfree(mcast);
out: out:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return ret ? ret : in_len; return ret ? ret : in_len;
} }
...@@ -1620,7 +1620,7 @@ ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file, ...@@ -1620,7 +1620,7 @@ ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file,
if (copy_from_user(&cmd, buf, sizeof cmd)) if (copy_from_user(&cmd, buf, sizeof cmd))
return -EFAULT; return -EFAULT;
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle); qp = idr_find(&ib_uverbs_qp_idr, cmd.qp_handle);
if (!qp || qp->uobject->context != file->ucontext) if (!qp || qp->uobject->context != file->ucontext)
...@@ -1641,7 +1641,7 @@ ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file, ...@@ -1641,7 +1641,7 @@ ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file,
} }
out: out:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return ret ? ret : in_len; return ret ? ret : in_len;
} }
...@@ -1673,7 +1673,7 @@ ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file, ...@@ -1673,7 +1673,7 @@ ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file,
if (!uobj) if (!uobj)
return -ENOMEM; return -ENOMEM;
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle);
...@@ -1730,11 +1730,11 @@ ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file, ...@@ -1730,11 +1730,11 @@ ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file,
goto err_idr; goto err_idr;
} }
down(&file->mutex); mutex_lock(&file->mutex);
list_add_tail(&uobj->uobject.list, &file->ucontext->srq_list); list_add_tail(&uobj->uobject.list, &file->ucontext->srq_list);
up(&file->mutex); mutex_unlock(&file->mutex);
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return in_len; return in_len;
...@@ -1746,7 +1746,7 @@ ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file, ...@@ -1746,7 +1746,7 @@ ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file,
atomic_dec(&pd->usecnt); atomic_dec(&pd->usecnt);
err_up: err_up:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
kfree(uobj); kfree(uobj);
return ret; return ret;
...@@ -1764,7 +1764,7 @@ ssize_t ib_uverbs_modify_srq(struct ib_uverbs_file *file, ...@@ -1764,7 +1764,7 @@ ssize_t ib_uverbs_modify_srq(struct ib_uverbs_file *file,
if (copy_from_user(&cmd, buf, sizeof cmd)) if (copy_from_user(&cmd, buf, sizeof cmd))
return -EFAULT; return -EFAULT;
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle); srq = idr_find(&ib_uverbs_srq_idr, cmd.srq_handle);
if (!srq || srq->uobject->context != file->ucontext) { if (!srq || srq->uobject->context != file->ucontext) {
...@@ -1778,7 +1778,7 @@ ssize_t ib_uverbs_modify_srq(struct ib_uverbs_file *file, ...@@ -1778,7 +1778,7 @@ ssize_t ib_uverbs_modify_srq(struct ib_uverbs_file *file,
ret = ib_modify_srq(srq, &attr, cmd.attr_mask); ret = ib_modify_srq(srq, &attr, cmd.attr_mask);
out: out:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return ret ? ret : in_len; return ret ? ret : in_len;
} }
...@@ -1796,7 +1796,7 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file, ...@@ -1796,7 +1796,7 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
if (copy_from_user(&cmd, buf, sizeof cmd)) if (copy_from_user(&cmd, buf, sizeof cmd))
return -EFAULT; return -EFAULT;
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
memset(&resp, 0, sizeof resp); memset(&resp, 0, sizeof resp);
...@@ -1812,9 +1812,9 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file, ...@@ -1812,9 +1812,9 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
idr_remove(&ib_uverbs_srq_idr, cmd.srq_handle); idr_remove(&ib_uverbs_srq_idr, cmd.srq_handle);
down(&file->mutex); mutex_lock(&file->mutex);
list_del(&uobj->uobject.list); list_del(&uobj->uobject.list);
up(&file->mutex); mutex_unlock(&file->mutex);
ib_uverbs_release_uevent(file, uobj); ib_uverbs_release_uevent(file, uobj);
...@@ -1827,7 +1827,7 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file, ...@@ -1827,7 +1827,7 @@ ssize_t ib_uverbs_destroy_srq(struct ib_uverbs_file *file,
ret = -EFAULT; ret = -EFAULT;
out: out:
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return ret ? ret : in_len; return ret ? ret : in_len;
} }
...@@ -66,7 +66,7 @@ enum { ...@@ -66,7 +66,7 @@ enum {
static struct class *uverbs_class; static struct class *uverbs_class;
DECLARE_MUTEX(ib_uverbs_idr_mutex); DEFINE_MUTEX(ib_uverbs_idr_mutex);
DEFINE_IDR(ib_uverbs_pd_idr); DEFINE_IDR(ib_uverbs_pd_idr);
DEFINE_IDR(ib_uverbs_mr_idr); DEFINE_IDR(ib_uverbs_mr_idr);
DEFINE_IDR(ib_uverbs_mw_idr); DEFINE_IDR(ib_uverbs_mw_idr);
...@@ -180,7 +180,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file, ...@@ -180,7 +180,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
if (!context) if (!context)
return 0; return 0;
down(&ib_uverbs_idr_mutex); mutex_lock(&ib_uverbs_idr_mutex);
list_for_each_entry_safe(uobj, tmp, &context->ah_list, list) { list_for_each_entry_safe(uobj, tmp, &context->ah_list, list) {
struct ib_ah *ah = idr_find(&ib_uverbs_ah_idr, uobj->id); 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,7 +250,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
kfree(uobj); kfree(uobj);
} }
up(&ib_uverbs_idr_mutex); mutex_unlock(&ib_uverbs_idr_mutex);
return context->device->dealloc_ucontext(context); return context->device->dealloc_ucontext(context);
} }
...@@ -653,7 +653,7 @@ static int ib_uverbs_open(struct inode *inode, struct file *filp) ...@@ -653,7 +653,7 @@ static int ib_uverbs_open(struct inode *inode, struct file *filp)
file->ucontext = NULL; file->ucontext = NULL;
file->async_file = NULL; file->async_file = NULL;
kref_init(&file->ref); kref_init(&file->ref);
init_MUTEX(&file->mutex); mutex_init(&file->mutex);
filp->private_data = file; filp->private_data = file;
......
...@@ -45,11 +45,11 @@ ...@@ -45,11 +45,11 @@
#include <linux/config.h> #include <linux/config.h>
#include <linux/kref.h> #include <linux/kref.h>
#include <linux/if_infiniband.h> #include <linux/if_infiniband.h>
#include <linux/mutex.h>
#include <net/neighbour.h> #include <net/neighbour.h>
#include <asm/atomic.h> #include <asm/atomic.h>
#include <asm/semaphore.h>
#include <rdma/ib_verbs.h> #include <rdma/ib_verbs.h>
#include <rdma/ib_pack.h> #include <rdma/ib_pack.h>
...@@ -123,8 +123,8 @@ struct ipoib_dev_priv { ...@@ -123,8 +123,8 @@ struct ipoib_dev_priv {
unsigned long flags; unsigned long flags;
struct semaphore mcast_mutex; struct mutex mcast_mutex;
struct semaphore vlan_mutex; struct mutex vlan_mutex;
struct rb_root path_tree; struct rb_root path_tree;
struct list_head path_list; struct list_head path_list;
......
...@@ -52,7 +52,7 @@ MODULE_PARM_DESC(data_debug_level, ...@@ -52,7 +52,7 @@ MODULE_PARM_DESC(data_debug_level,
#define IPOIB_OP_RECV (1ul << 31) #define IPOIB_OP_RECV (1ul << 31)
static DECLARE_MUTEX(pkey_sem); static DEFINE_MUTEX(pkey_mutex);
struct ipoib_ah *ipoib_create_ah(struct net_device *dev, struct ipoib_ah *ipoib_create_ah(struct net_device *dev,
struct ib_pd *pd, struct ib_ah_attr *attr) struct ib_pd *pd, struct ib_ah_attr *attr)
...@@ -445,10 +445,10 @@ int ipoib_ib_dev_down(struct net_device *dev) ...@@ -445,10 +445,10 @@ int ipoib_ib_dev_down(struct net_device *dev)
/* Shutdown the P_Key thread if still active */ /* Shutdown the P_Key thread if still active */
if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) { if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
down(&pkey_sem); mutex_lock(&pkey_mutex);
set_bit(IPOIB_PKEY_STOP, &priv->flags); set_bit(IPOIB_PKEY_STOP, &priv->flags);
cancel_delayed_work(&priv->pkey_task); cancel_delayed_work(&priv->pkey_task);
up(&pkey_sem); mutex_unlock(&pkey_mutex);
flush_workqueue(ipoib_workqueue); flush_workqueue(ipoib_workqueue);
} }
...@@ -599,13 +599,13 @@ void ipoib_ib_dev_flush(void *_dev) ...@@ -599,13 +599,13 @@ void ipoib_ib_dev_flush(void *_dev)
if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags))
ipoib_ib_dev_up(dev); ipoib_ib_dev_up(dev);
down(&priv->vlan_mutex); mutex_lock(&priv->vlan_mutex);
/* Flush any child interfaces too */ /* Flush any child interfaces too */
list_for_each_entry(cpriv, &priv->child_intfs, list) list_for_each_entry(cpriv, &priv->child_intfs, list)
ipoib_ib_dev_flush(&cpriv->dev); ipoib_ib_dev_flush(&cpriv->dev);
up(&priv->vlan_mutex); mutex_unlock(&priv->vlan_mutex);
} }
void ipoib_ib_dev_cleanup(struct net_device *dev) void ipoib_ib_dev_cleanup(struct net_device *dev)
...@@ -651,12 +651,12 @@ void ipoib_pkey_poll(void *dev_ptr) ...@@ -651,12 +651,12 @@ void ipoib_pkey_poll(void *dev_ptr)
if (test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) if (test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags))
ipoib_open(dev); ipoib_open(dev);
else { else {
down(&pkey_sem); mutex_lock(&pkey_mutex);
if (!test_bit(IPOIB_PKEY_STOP, &priv->flags)) if (!test_bit(IPOIB_PKEY_STOP, &priv->flags))
queue_delayed_work(ipoib_workqueue, queue_delayed_work(ipoib_workqueue,
&priv->pkey_task, &priv->pkey_task,
HZ); HZ);
up(&pkey_sem); mutex_unlock(&pkey_mutex);
} }
} }
...@@ -670,12 +670,12 @@ int ipoib_pkey_dev_delay_open(struct net_device *dev) ...@@ -670,12 +670,12 @@ int ipoib_pkey_dev_delay_open(struct net_device *dev)
/* P_Key value not assigned yet - start polling */ /* P_Key value not assigned yet - start polling */
if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) { if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
down(&pkey_sem); mutex_lock(&pkey_mutex);
clear_bit(IPOIB_PKEY_STOP, &priv->flags); clear_bit(IPOIB_PKEY_STOP, &priv->flags);
queue_delayed_work(ipoib_workqueue, queue_delayed_work(ipoib_workqueue,
&priv->pkey_task, &priv->pkey_task,
HZ); HZ);
up(&pkey_sem); mutex_unlock(&pkey_mutex);
return 1; return 1;
} }
......
...@@ -105,7 +105,7 @@ int ipoib_open(struct net_device *dev) ...@@ -105,7 +105,7 @@ int ipoib_open(struct net_device *dev)
struct ipoib_dev_priv *cpriv; struct ipoib_dev_priv *cpriv;
/* Bring up any child interfaces too */ /* Bring up any child interfaces too */
down(&priv->vlan_mutex); mutex_lock(&priv->vlan_mutex);
list_for_each_entry(cpriv, &priv->child_intfs, list) { list_for_each_entry(cpriv, &priv->child_intfs, list) {
int flags; int flags;
...@@ -115,7 +115,7 @@ int ipoib_open(struct net_device *dev) ...@@ -115,7 +115,7 @@ int ipoib_open(struct net_device *dev)
dev_change_flags(cpriv->dev, flags | IFF_UP); dev_change_flags(cpriv->dev, flags | IFF_UP);
} }
up(&priv->vlan_mutex); mutex_unlock(&priv->vlan_mutex);
} }
netif_start_queue(dev); netif_start_queue(dev);
...@@ -140,7 +140,7 @@ static int ipoib_stop(struct net_device *dev) ...@@ -140,7 +140,7 @@ static int ipoib_stop(struct net_device *dev)
struct ipoib_dev_priv *cpriv; struct ipoib_dev_priv *cpriv;
/* Bring down any child interfaces too */ /* Bring down any child interfaces too */
down(&priv->vlan_mutex); mutex_lock(&priv->vlan_mutex);
list_for_each_entry(cpriv, &priv->child_intfs, list) { list_for_each_entry(cpriv, &priv->child_intfs, list) {
int flags; int flags;
...@@ -150,7 +150,7 @@ static int ipoib_stop(struct net_device *dev) ...@@ -150,7 +150,7 @@ static int ipoib_stop(struct net_device *dev)
dev_change_flags(cpriv->dev, flags & ~IFF_UP); dev_change_flags(cpriv->dev, flags & ~IFF_UP);
} }
up(&priv->vlan_mutex); mutex_unlock(&priv->vlan_mutex);
} }
return 0; return 0;
...@@ -892,8 +892,8 @@ static void ipoib_setup(struct net_device *dev) ...@@ -892,8 +892,8 @@ static void ipoib_setup(struct net_device *dev)
spin_lock_init(&priv->lock); spin_lock_init(&priv->lock);
spin_lock_init(&priv->tx_lock); spin_lock_init(&priv->tx_lock);
init_MUTEX(&priv->mcast_mutex); mutex_init(&priv->mcast_mutex);
init_MUTEX(&priv->vlan_mutex); mutex_init(&priv->vlan_mutex);
INIT_LIST_HEAD(&priv->path_list); INIT_LIST_HEAD(&priv->path_list);
INIT_LIST_HEAD(&priv->child_intfs); INIT_LIST_HEAD(&priv->child_intfs);
......
...@@ -55,7 +55,7 @@ MODULE_PARM_DESC(mcast_debug_level, ...@@ -55,7 +55,7 @@ MODULE_PARM_DESC(mcast_debug_level,
"Enable multicast debug tracing if > 0"); "Enable multicast debug tracing if > 0");
#endif #endif
static DECLARE_MUTEX(mcast_mutex); static DEFINE_MUTEX(mcast_mutex);
/* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */ /* Used for all multicast joins (broadcast, IPv4 mcast and IPv6 mcast) */
struct ipoib_mcast { struct ipoib_mcast {
...@@ -385,10 +385,10 @@ static void ipoib_mcast_join_complete(int status, ...@@ -385,10 +385,10 @@ static void ipoib_mcast_join_complete(int status,
if (!status && !ipoib_mcast_join_finish(mcast, mcmember)) { if (!status && !ipoib_mcast_join_finish(mcast, mcmember)) {
mcast->backoff = 1; mcast->backoff = 1;
down(&mcast_mutex); mutex_lock(&mcast_mutex);
if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
queue_work(ipoib_workqueue, &priv->mcast_task); queue_work(ipoib_workqueue, &priv->mcast_task);
up(&mcast_mutex); mutex_unlock(&mcast_mutex);
complete(&mcast->done); complete(&mcast->done);
return; return;
} }
...@@ -418,7 +418,7 @@ static void ipoib_mcast_join_complete(int status, ...@@ -418,7 +418,7 @@ static void ipoib_mcast_join_complete(int status,
mcast->query = NULL; mcast->query = NULL;
down(&mcast_mutex); mutex_lock(&mcast_mutex);
if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) { if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) {
if (status == -ETIMEDOUT) if (status == -ETIMEDOUT)
queue_work(ipoib_workqueue, &priv->mcast_task); queue_work(ipoib_workqueue, &priv->mcast_task);
...@@ -427,7 +427,7 @@ static void ipoib_mcast_join_complete(int status, ...@@ -427,7 +427,7 @@ static void ipoib_mcast_join_complete(int status,
mcast->backoff * HZ); mcast->backoff * HZ);
} else } else
complete(&mcast->done); complete(&mcast->done);
up(&mcast_mutex); mutex_unlock(&mcast_mutex);
return; return;
} }
...@@ -482,12 +482,12 @@ static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast, ...@@ -482,12 +482,12 @@ static void ipoib_mcast_join(struct net_device *dev, struct ipoib_mcast *mcast,
if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS) if (mcast->backoff > IPOIB_MAX_BACKOFF_SECONDS)
mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS; mcast->backoff = IPOIB_MAX_BACKOFF_SECONDS;
down(&mcast_mutex); mutex_lock(&mcast_mutex);
if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
queue_delayed_work(ipoib_workqueue, queue_delayed_work(ipoib_workqueue,
&priv->mcast_task, &priv->mcast_task,
mcast->backoff * HZ); mcast->backoff * HZ);
up(&mcast_mutex); mutex_unlock(&mcast_mutex);
} else } else
mcast->query_id = ret; mcast->query_id = ret;
} }
...@@ -520,11 +520,11 @@ void ipoib_mcast_join_task(void *dev_ptr) ...@@ -520,11 +520,11 @@ void ipoib_mcast_join_task(void *dev_ptr)
priv->broadcast = ipoib_mcast_alloc(dev, 1); priv->broadcast = ipoib_mcast_alloc(dev, 1);
if (!priv->broadcast) { if (!priv->broadcast) {
ipoib_warn(priv, "failed to allocate broadcast group\n"); ipoib_warn(priv, "failed to allocate broadcast group\n");
down(&mcast_mutex); mutex_lock(&mcast_mutex);
if (test_bit(IPOIB_MCAST_RUN, &priv->flags)) if (test_bit(IPOIB_MCAST_RUN, &priv->flags))
queue_delayed_work(ipoib_workqueue, queue_delayed_work(ipoib_workqueue,
&priv->mcast_task, HZ); &priv->mcast_task, HZ);
up(&mcast_mutex); mutex_unlock(&mcast_mutex);
return; return;
} }
...@@ -580,10 +580,10 @@ int ipoib_mcast_start_thread(struct net_device *dev) ...@@ -580,10 +580,10 @@ int ipoib_mcast_start_thread(struct net_device *dev)
ipoib_dbg_mcast(priv, "starting multicast thread\n"); ipoib_dbg_mcast(priv, "starting multicast thread\n");
down(&mcast_mutex); mutex_lock(&mcast_mutex);
if (!test_and_set_bit(IPOIB_MCAST_RUN, &priv->flags)) if (!test_and_set_bit(IPOIB_MCAST_RUN, &priv->flags))
queue_work(ipoib_workqueue, &priv->mcast_task); queue_work(ipoib_workqueue, &priv->mcast_task);
up(&mcast_mutex); mutex_unlock(&mcast_mutex);
return 0; return 0;
} }
...@@ -595,10 +595,10 @@ int ipoib_mcast_stop_thread(struct net_device *dev, int flush) ...@@ -595,10 +595,10 @@ int ipoib_mcast_stop_thread(struct net_device *dev, int flush)
ipoib_dbg_mcast(priv, "stopping multicast thread\n"); ipoib_dbg_mcast(priv, "stopping multicast thread\n");
down(&mcast_mutex); mutex_lock(&mcast_mutex);
clear_bit(IPOIB_MCAST_RUN, &priv->flags); clear_bit(IPOIB_MCAST_RUN, &priv->flags);
cancel_delayed_work(&priv->mcast_task); cancel_delayed_work(&priv->mcast_task);
up(&mcast_mutex); mutex_unlock(&mcast_mutex);
if (flush) if (flush)
flush_workqueue(ipoib_workqueue); flush_workqueue(ipoib_workqueue);
......
...@@ -65,9 +65,9 @@ int ipoib_mcast_attach(struct net_device *dev, u16 mlid, union ib_gid *mgid) ...@@ -65,9 +65,9 @@ int ipoib_mcast_attach(struct net_device *dev, u16 mlid, union ib_gid *mgid)
} }
/* attach QP to multicast group */ /* attach QP to multicast group */
down(&priv->mcast_mutex); mutex_lock(&priv->mcast_mutex);
ret = ib_attach_mcast(priv->qp, mgid, mlid); ret = ib_attach_mcast(priv->qp, mgid, mlid);
up(&priv->mcast_mutex); mutex_unlock(&priv->mcast_mutex);
if (ret) if (ret)
ipoib_warn(priv, "failed to attach to multicast group, ret = %d\n", ret); ipoib_warn(priv, "failed to attach to multicast group, ret = %d\n", ret);
...@@ -81,9 +81,9 @@ int ipoib_mcast_detach(struct net_device *dev, u16 mlid, union ib_gid *mgid) ...@@ -81,9 +81,9 @@ int ipoib_mcast_detach(struct net_device *dev, u16 mlid, union ib_gid *mgid)
struct ipoib_dev_priv *priv = netdev_priv(dev); struct ipoib_dev_priv *priv = netdev_priv(dev);
int ret; int ret;
down(&priv->mcast_mutex); mutex_lock(&priv->mcast_mutex);
ret = ib_detach_mcast(priv->qp, mgid, mlid); ret = ib_detach_mcast(priv->qp, mgid, mlid);
up(&priv->mcast_mutex); mutex_unlock(&priv->mcast_mutex);
if (ret) if (ret)
ipoib_warn(priv, "ib_detach_mcast failed (result = %d)\n", ret); ipoib_warn(priv, "ib_detach_mcast failed (result = %d)\n", ret);
......
...@@ -63,7 +63,7 @@ int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey) ...@@ -63,7 +63,7 @@ int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey)
ppriv = netdev_priv(pdev); ppriv = netdev_priv(pdev);
down(&ppriv->vlan_mutex); mutex_lock(&ppriv->vlan_mutex);
/* /*
* First ensure this isn't a duplicate. We check the parent device and * 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,7 +124,7 @@ int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey)
list_add_tail(&priv->list, &ppriv->child_intfs); list_add_tail(&priv->list, &ppriv->child_intfs);
up(&ppriv->vlan_mutex); mutex_unlock(&ppriv->vlan_mutex);
return 0; return 0;
...@@ -139,7 +139,7 @@ int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey) ...@@ -139,7 +139,7 @@ int ipoib_vlan_add(struct net_device *pdev, unsigned short pkey)
free_netdev(priv->dev); free_netdev(priv->dev);
err: err:
up(&ppriv->vlan_mutex); mutex_unlock(&ppriv->vlan_mutex);
return result; return result;
} }
...@@ -153,7 +153,7 @@ int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey) ...@@ -153,7 +153,7 @@ int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey)
ppriv = netdev_priv(pdev); ppriv = netdev_priv(pdev);
down(&ppriv->vlan_mutex); mutex_lock(&ppriv->vlan_mutex);
list_for_each_entry_safe(priv, tpriv, &ppriv->child_intfs, list) { list_for_each_entry_safe(priv, tpriv, &ppriv->child_intfs, list) {
if (priv->pkey == pkey) { if (priv->pkey == pkey) {
unregister_netdev(priv->dev); unregister_netdev(priv->dev);
...@@ -167,7 +167,7 @@ int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey) ...@@ -167,7 +167,7 @@ int ipoib_vlan_delete(struct net_device *pdev, unsigned short pkey)
break; break;
} }
} }
up(&ppriv->vlan_mutex); mutex_unlock(&ppriv->vlan_mutex);
return ret; return ret;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment