]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
io_uring/rsrc: refactor io_{un}account_mem() to take {user,mm}_struct param
authorDavid Wei <dw@davidwei.uk>
Tue, 4 Nov 2025 22:44:54 +0000 (14:44 -0800)
committerJens Axboe <axboe@kernel.dk>
Thu, 6 Nov 2025 23:23:21 +0000 (16:23 -0700)
Refactor io_{un}account_mem() to take user_struct and mm_struct
directly, instead of accessing it from the ring ctx.

Signed-off-by: David Wei <dw@davidwei.uk>
Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/rsrc.c
io_uring/rsrc.h
io_uring/zcrx.c

index 4cc38eb56758ab6c5fb3d8b348520b46d87d3b64..4053d104bf4c3f2a7ec89ea091b6c21f68c6a6fd 100644 (file)
@@ -56,27 +56,29 @@ int __io_account_mem(struct user_struct *user, unsigned long nr_pages)
        return 0;
 }
 
-void io_unaccount_mem(struct io_ring_ctx *ctx, unsigned long nr_pages)
+void io_unaccount_mem(struct user_struct *user, struct mm_struct *mm_account,
+                     unsigned long nr_pages)
 {
-       if (ctx->user)
-               __io_unaccount_mem(ctx->user, nr_pages);
+       if (user)
+               __io_unaccount_mem(user, nr_pages);
 
-       if (ctx->mm_account)
-               atomic64_sub(nr_pages, &ctx->mm_account->pinned_vm);
+       if (mm_account)
+               atomic64_sub(nr_pages, &mm_account->pinned_vm);
 }
 
-int io_account_mem(struct io_ring_ctx *ctx, unsigned long nr_pages)
+int io_account_mem(struct user_struct *user, struct mm_struct *mm_account,
+                  unsigned long nr_pages)
 {
        int ret;
 
-       if (ctx->user) {
-               ret = __io_account_mem(ctx->user, nr_pages);
+       if (user) {
+               ret = __io_account_mem(user, nr_pages);
                if (ret)
                        return ret;
        }
 
-       if (ctx->mm_account)
-               atomic64_add(nr_pages, &ctx->mm_account->pinned_vm);
+       if (mm_account)
+               atomic64_add(nr_pages, &mm_account->pinned_vm);
 
        return 0;
 }
@@ -145,7 +147,7 @@ static void io_buffer_unmap(struct io_ring_ctx *ctx, struct io_mapped_ubuf *imu)
        }
 
        if (imu->acct_pages)
-               io_unaccount_mem(ctx, imu->acct_pages);
+               io_unaccount_mem(ctx->user, ctx->mm_account, imu->acct_pages);
        imu->release(imu->priv);
        io_free_imu(ctx, imu);
 }
@@ -684,7 +686,7 @@ static int io_buffer_account_pin(struct io_ring_ctx *ctx, struct page **pages,
        if (!imu->acct_pages)
                return 0;
 
-       ret = io_account_mem(ctx, imu->acct_pages);
+       ret = io_account_mem(ctx->user, ctx->mm_account, imu->acct_pages);
        if (ret)
                imu->acct_pages = 0;
        return ret;
index a3ca6ba66596fb3759836b046009ba9448901526..d603f6a47f5e221d6465d1c49e526b4f80d5bb8a 100644 (file)
@@ -120,8 +120,10 @@ int io_files_update(struct io_kiocb *req, unsigned int issue_flags);
 int io_files_update_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
 
 int __io_account_mem(struct user_struct *user, unsigned long nr_pages);
-int io_account_mem(struct io_ring_ctx *ctx, unsigned long nr_pages);
-void io_unaccount_mem(struct io_ring_ctx *ctx, unsigned long nr_pages);
+int io_account_mem(struct user_struct *user, struct mm_struct *mm_account,
+                  unsigned long nr_pages);
+void io_unaccount_mem(struct user_struct *user, struct mm_struct *mm_account,
+                     unsigned long nr_pages);
 
 static inline void __io_unaccount_mem(struct user_struct *user,
                                      unsigned long nr_pages)
index d1545388400495d595157d478f8510ba5449a792..30d3a7b3c407cae6f06eaa1d39028c78018eb03b 100644 (file)
@@ -200,7 +200,7 @@ static int io_import_umem(struct io_zcrx_ifq *ifq,
        }
 
        mem->account_pages = io_count_account_pages(pages, nr_pages);
-       ret = io_account_mem(ifq->ctx, mem->account_pages);
+       ret = io_account_mem(ifq->ctx->user, ifq->ctx->mm_account, mem->account_pages);
        if (ret < 0)
                mem->account_pages = 0;
 
@@ -389,7 +389,8 @@ static void io_zcrx_free_area(struct io_zcrx_area *area)
        io_release_area_mem(&area->mem);
 
        if (area->mem.account_pages)
-               io_unaccount_mem(area->ifq->ctx, area->mem.account_pages);
+               io_unaccount_mem(area->ifq->ctx->user, area->ifq->ctx->mm_account,
+                                area->mem.account_pages);
 
        kvfree(area->freelist);
        kvfree(area->nia.niovs);