Commit 310ca1a7 authored by Jason Gunthorpe's avatar Jason Gunthorpe

RDMA/ucma: Narrow file->mut in ucma_event_handler()

Since the backlog is now an atomic the file->mut is now only protecting
the event_list and ctx_list. Narrow its scope to make it clear

Link: https://lore.kernel.org/r/20200818120526.702120-13-leon@kernel.orgSigned-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 26c15dec
...@@ -283,7 +283,6 @@ static void ucma_set_event_context(struct ucma_context *ctx, ...@@ -283,7 +283,6 @@ static void ucma_set_event_context(struct ucma_context *ctx,
} }
} }
/* Called with file->mut locked for the relevant context. */
static void ucma_removal_event_handler(struct rdma_cm_id *cm_id) static void ucma_removal_event_handler(struct rdma_cm_id *cm_id)
{ {
struct ucma_context *ctx = cm_id->context; struct ucma_context *ctx = cm_id->context;
...@@ -307,6 +306,7 @@ static void ucma_removal_event_handler(struct rdma_cm_id *cm_id) ...@@ -307,6 +306,7 @@ static void ucma_removal_event_handler(struct rdma_cm_id *cm_id)
return; return;
} }
mutex_lock(&ctx->file->mut);
list_for_each_entry(con_req_eve, &ctx->file->event_list, list) { list_for_each_entry(con_req_eve, &ctx->file->event_list, list) {
if (con_req_eve->cm_id == cm_id && if (con_req_eve->cm_id == cm_id &&
con_req_eve->resp.event == RDMA_CM_EVENT_CONNECT_REQUEST) { con_req_eve->resp.event == RDMA_CM_EVENT_CONNECT_REQUEST) {
...@@ -317,6 +317,7 @@ static void ucma_removal_event_handler(struct rdma_cm_id *cm_id) ...@@ -317,6 +317,7 @@ static void ucma_removal_event_handler(struct rdma_cm_id *cm_id)
break; break;
} }
} }
mutex_unlock(&ctx->file->mut);
if (!event_found) if (!event_found)
pr_err("ucma_removal_event_handler: warning: connect request event wasn't found\n"); pr_err("ucma_removal_event_handler: warning: connect request event wasn't found\n");
} }
...@@ -326,13 +327,11 @@ static int ucma_event_handler(struct rdma_cm_id *cm_id, ...@@ -326,13 +327,11 @@ static int ucma_event_handler(struct rdma_cm_id *cm_id,
{ {
struct ucma_event *uevent; struct ucma_event *uevent;
struct ucma_context *ctx = cm_id->context; struct ucma_context *ctx = cm_id->context;
int ret = 0;
uevent = kzalloc(sizeof(*uevent), GFP_KERNEL); uevent = kzalloc(sizeof(*uevent), GFP_KERNEL);
if (!uevent) if (!uevent)
return event->event == RDMA_CM_EVENT_CONNECT_REQUEST; return event->event == RDMA_CM_EVENT_CONNECT_REQUEST;
mutex_lock(&ctx->file->mut);
uevent->cm_id = cm_id; uevent->cm_id = cm_id;
ucma_set_event_context(ctx, event, uevent); ucma_set_event_context(ctx, event, uevent);
uevent->resp.event = event->event; uevent->resp.event = event->event;
...@@ -349,9 +348,8 @@ static int ucma_event_handler(struct rdma_cm_id *cm_id, ...@@ -349,9 +348,8 @@ static int ucma_event_handler(struct rdma_cm_id *cm_id,
if (event->event == RDMA_CM_EVENT_CONNECT_REQUEST) { if (event->event == RDMA_CM_EVENT_CONNECT_REQUEST) {
if (!atomic_add_unless(&ctx->backlog, -1, 0)) { if (!atomic_add_unless(&ctx->backlog, -1, 0)) {
ret = -ENOMEM;
kfree(uevent); kfree(uevent);
goto out; return -ENOMEM;
} }
} else if (!ctx->uid || ctx->cm_id != cm_id) { } else if (!ctx->uid || ctx->cm_id != cm_id) {
/* /*
...@@ -366,16 +364,16 @@ static int ucma_event_handler(struct rdma_cm_id *cm_id, ...@@ -366,16 +364,16 @@ static int ucma_event_handler(struct rdma_cm_id *cm_id,
ucma_removal_event_handler(cm_id); ucma_removal_event_handler(cm_id);
kfree(uevent); kfree(uevent);
goto out; return 0;
} }
mutex_lock(&ctx->file->mut);
list_add_tail(&uevent->list, &ctx->file->event_list); list_add_tail(&uevent->list, &ctx->file->event_list);
mutex_unlock(&ctx->file->mut);
wake_up_interruptible(&ctx->file->poll_wait); wake_up_interruptible(&ctx->file->poll_wait);
if (event->event == RDMA_CM_EVENT_DEVICE_REMOVAL) if (event->event == RDMA_CM_EVENT_DEVICE_REMOVAL)
ucma_removal_event_handler(cm_id); ucma_removal_event_handler(cm_id);
out: return 0;
mutex_unlock(&ctx->file->mut);
return ret;
} }
static ssize_t ucma_get_event(struct ucma_file *file, const char __user *inbuf, static ssize_t ucma_get_event(struct ucma_file *file, const char __user *inbuf,
......
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