io_uring: rename ->resize_lock
authorPavel Begunkov <asml.silence@gmail.com>
Fri, 29 Nov 2024 13:34:22 +0000 (13:34 +0000)
committerJens Axboe <axboe@kernel.dk>
Mon, 23 Dec 2024 15:17:15 +0000 (08:17 -0700)
->resize_lock is used for resizing rings, but it's a good idea to reuse
it in other cases as well. Rename it into mmap_lock as it's protects
from races with mmap.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Link: https://lore.kernel.org/r/68f705306f3ac4d2fb999eb80ea1615015ce9f7f.1732886067.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/linux/io_uring_types.h
io_uring/io_uring.c
io_uring/memmap.c
io_uring/register.c

index fd4cdb0860a28abbf3f698feea49d6e4090b90bf..fafc1d779eb14b2d04ae50f9ce5fb4fb6a229552 100644 (file)
@@ -424,7 +424,7 @@ struct io_ring_ctx {
         * side will need to grab this lock, to prevent either side from
         * being run concurrently with the other.
         */
-       struct mutex                    resize_lock;
+       struct mutex                    mmap_lock;
 
        /*
         * If IORING_SETUP_NO_MMAP is used, then the below holds
index d3403c8216db822d0acd5bdf9201edde58b7ffe8..539fecde024436fba445ceb47811294fa2f71e40 100644 (file)
@@ -350,7 +350,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(struct io_uring_params *p)
        INIT_WQ_LIST(&ctx->submit_state.compl_reqs);
        INIT_HLIST_HEAD(&ctx->cancelable_uring_cmd);
        io_napi_init(ctx);
-       mutex_init(&ctx->resize_lock);
+       mutex_init(&ctx->mmap_lock);
 
        return ctx;
 
index 57de9bccbf508b8820fd3120d3a8d08b5437527f..a0d4151d11af3ebca5a014b3f51572825ae6dc17 100644 (file)
@@ -329,7 +329,7 @@ __cold int io_uring_mmap(struct file *file, struct vm_area_struct *vma)
        unsigned int npages;
        void *ptr;
 
-       guard(mutex)(&ctx->resize_lock);
+       guard(mutex)(&ctx->mmap_lock);
 
        ptr = io_uring_validate_mmap_request(file, vma->vm_pgoff, sz);
        if (IS_ERR(ptr))
@@ -365,7 +365,7 @@ unsigned long io_uring_get_unmapped_area(struct file *filp, unsigned long addr,
        if (addr)
                return -EINVAL;
 
-       guard(mutex)(&ctx->resize_lock);
+       guard(mutex)(&ctx->mmap_lock);
 
        ptr = io_uring_validate_mmap_request(filp, pgoff, len);
        if (IS_ERR(ptr))
@@ -415,7 +415,7 @@ unsigned long io_uring_get_unmapped_area(struct file *file, unsigned long addr,
        struct io_ring_ctx *ctx = file->private_data;
        void *ptr;
 
-       guard(mutex)(&ctx->resize_lock);
+       guard(mutex)(&ctx->mmap_lock);
 
        ptr = io_uring_validate_mmap_request(file, pgoff, len);
        if (IS_ERR(ptr))
index fdd44914c39c7c7457b1775f03bdb5bb1ed86b0a..77743e3f67518468bce8360eb4460a93d0bf1e01 100644 (file)
@@ -489,15 +489,15 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
        }
 
        /*
-        * We'll do the swap. Grab the ctx->resize_lock, which will exclude
+        * We'll do the swap. Grab the ctx->mmap_lock, which will exclude
         * any new mmap's on the ring fd. Clear out existing mappings to prevent
         * mmap from seeing them, as we'll unmap them. Any attempt to mmap
         * existing rings beyond this point will fail. Not that it could proceed
         * at this point anyway, as the io_uring mmap side needs go grab the
-        * ctx->resize_lock as well. Likewise, hold the completion lock over the
+        * ctx->mmap_lock as well. Likewise, hold the completion lock over the
         * duration of the actual swap.
         */
-       mutex_lock(&ctx->resize_lock);
+       mutex_lock(&ctx->mmap_lock);
        spin_lock(&ctx->completion_lock);
        o.rings = ctx->rings;
        ctx->rings = NULL;
@@ -564,7 +564,7 @@ overflow:
        ret = 0;
 out:
        spin_unlock(&ctx->completion_lock);
-       mutex_unlock(&ctx->resize_lock);
+       mutex_unlock(&ctx->mmap_lock);
        io_register_free_rings(&p, to_free);
 
        if (ctx->sq_data)