io_uring: mutex locked poll hashing
[linux-2.6-microblaze.git] / io_uring / io_uring.c
index 0b3851a..eeda167 100644 (file)
@@ -275,6 +275,8 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
        hash_bits = clamp(hash_bits, 1, 8);
        if (io_alloc_hash_table(&ctx->cancel_table, hash_bits))
                goto err;
+       if (io_alloc_hash_table(&ctx->cancel_table_locked, hash_bits))
+               goto err;
 
        ctx->dummy_ubuf = kzalloc(sizeof(*ctx->dummy_ubuf), GFP_KERNEL);
        if (!ctx->dummy_ubuf)
@@ -317,6 +319,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
 err:
        kfree(ctx->dummy_ubuf);
        kfree(ctx->cancel_table.hbs);
+       kfree(ctx->cancel_table_locked.hbs);
        kfree(ctx->io_bl);
        xa_destroy(&ctx->io_bl_xa);
        kfree(ctx);
@@ -2493,6 +2496,7 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
        if (ctx->hash_map)
                io_wq_put_hash(ctx->hash_map);
        kfree(ctx->cancel_table.hbs);
+       kfree(ctx->cancel_table_locked.hbs);
        kfree(ctx->dummy_ubuf);
        kfree(ctx->io_bl);
        xa_destroy(&ctx->io_bl_xa);
@@ -2654,12 +2658,13 @@ static __cold void io_ring_ctx_wait_and_kill(struct io_ring_ctx *ctx)
                __io_cqring_overflow_flush(ctx, true);
        xa_for_each(&ctx->personalities, index, creds)
                io_unregister_personality(ctx, index);
+       if (ctx->rings)
+               io_poll_remove_all(ctx, NULL, true);
        mutex_unlock(&ctx->uring_lock);
 
        /* failed during ring init, it couldn't have issued any requests */
        if (ctx->rings) {
                io_kill_timeouts(ctx, NULL, true);
-               io_poll_remove_all(ctx, NULL, true);
                /* if we failed setting up the ctx, we might not have any rings */
                io_iopoll_try_reap_events(ctx);
        }
@@ -2784,7 +2789,9 @@ static __cold void io_uring_try_cancel_requests(struct io_ring_ctx *ctx,
                }
 
                ret |= io_cancel_defer_files(ctx, task, cancel_all);
+               mutex_lock(&ctx->uring_lock);
                ret |= io_poll_remove_all(ctx, task, cancel_all);
+               mutex_unlock(&ctx->uring_lock);
                ret |= io_kill_timeouts(ctx, task, cancel_all);
                if (task)
                        ret |= io_run_task_work();