Commit 26c15dec authored by Jason Gunthorpe's avatar Jason Gunthorpe

RDMA/ucma: Change backlog into an atomic

There is no reason to grab the file->mut just to do this inc/dec work. Use
an atomic.

Link: https://lore.kernel.org/r/20200818120526.702120-12-leon@kernel.orgSigned-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 38e03d09
...@@ -88,7 +88,7 @@ struct ucma_context { ...@@ -88,7 +88,7 @@ struct ucma_context {
struct completion comp; struct completion comp;
refcount_t ref; refcount_t ref;
int events_reported; int events_reported;
int backlog; atomic_t backlog;
struct ucma_file *file; struct ucma_file *file;
struct rdma_cm_id *cm_id; struct rdma_cm_id *cm_id;
...@@ -348,12 +348,11 @@ static int ucma_event_handler(struct rdma_cm_id *cm_id, ...@@ -348,12 +348,11 @@ static int ucma_event_handler(struct rdma_cm_id *cm_id,
uevent->resp.ece.attr_mod = event->ece.attr_mod; uevent->resp.ece.attr_mod = event->ece.attr_mod;
if (event->event == RDMA_CM_EVENT_CONNECT_REQUEST) { if (event->event == RDMA_CM_EVENT_CONNECT_REQUEST) {
if (!ctx->backlog) { if (!atomic_add_unless(&ctx->backlog, -1, 0)) {
ret = -ENOMEM; ret = -ENOMEM;
kfree(uevent); kfree(uevent);
goto out; goto out;
} }
ctx->backlog--;
} else if (!ctx->uid || ctx->cm_id != cm_id) { } else if (!ctx->uid || ctx->cm_id != cm_id) {
/* /*
* We ignore events for new connections until userspace has set * We ignore events for new connections until userspace has set
...@@ -432,7 +431,7 @@ static ssize_t ucma_get_event(struct ucma_file *file, const char __user *inbuf, ...@@ -432,7 +431,7 @@ static ssize_t ucma_get_event(struct ucma_file *file, const char __user *inbuf,
} }
if (ctx) { if (ctx) {
uevent->ctx->backlog++; atomic_inc(&uevent->ctx->backlog);
uevent->cm_id->context = ctx; uevent->cm_id->context = ctx;
ucma_finish_ctx(ctx); ucma_finish_ctx(ctx);
} }
...@@ -1136,10 +1135,12 @@ static ssize_t ucma_listen(struct ucma_file *file, const char __user *inbuf, ...@@ -1136,10 +1135,12 @@ static ssize_t ucma_listen(struct ucma_file *file, const char __user *inbuf,
if (IS_ERR(ctx)) if (IS_ERR(ctx))
return PTR_ERR(ctx); return PTR_ERR(ctx);
ctx->backlog = cmd.backlog > 0 && cmd.backlog < max_backlog ? if (cmd.backlog <= 0 || cmd.backlog > max_backlog)
cmd.backlog : max_backlog; cmd.backlog = max_backlog;
atomic_set(&ctx->backlog, cmd.backlog);
mutex_lock(&ctx->mutex); mutex_lock(&ctx->mutex);
ret = rdma_listen(ctx->cm_id, ctx->backlog); ret = rdma_listen(ctx->cm_id, cmd.backlog);
mutex_unlock(&ctx->mutex); mutex_unlock(&ctx->mutex);
ucma_put_ctx(ctx); ucma_put_ctx(ctx);
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