io_uring: Move old async data allocation helper to header
authorGabriel Krisman Bertazi <krisman@suse.de>
Mon, 16 Dec 2024 20:46:14 +0000 (15:46 -0500)
committerJens Axboe <axboe@kernel.dk>
Fri, 27 Dec 2024 17:08:11 +0000 (10:08 -0700)
There are two remaining uses of the old async data allocator that do not
rely on the alloc cache.  I don't want to make them use the new
allocator helper because that would require a if(cache) check, which
will result in dead code for the cached case (for callers passing a
cache, gcc can't prove the cache isn't NULL, and will therefore preserve
the check.  Since this is an inline function and just a few lines long,
keep a second helper to deal with cases where we don't have an async
data cache.

No functional change intended here.  This is just moving the helper
around and making it inline.

Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de>
Link: https://lore.kernel.org/r/20241216204615.759089-9-krisman@suse.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/io_uring.c
io_uring/io_uring.h
io_uring/timeout.c
io_uring/waitid.c

index 66a93170ad68d4bde4917404cacbb66fec60c68b..e6d12104f8cb0fdc3610d3e8a8149ccdee67ae3e 100644 (file)
@@ -1643,19 +1643,6 @@ io_req_flags_t io_file_get_flags(struct file *file)
        return res;
 }
 
-bool io_alloc_async_data(struct io_kiocb *req)
-{
-       const struct io_issue_def *def = &io_issue_defs[req->opcode];
-
-       WARN_ON_ONCE(!def->async_size);
-       req->async_data = kmalloc(def->async_size, GFP_KERNEL);
-       if (req->async_data) {
-               req->flags |= REQ_F_ASYNC_DATA;
-               return false;
-       }
-       return true;
-}
-
 static u32 io_get_sequence(struct io_kiocb *req)
 {
        u32 seq = req->ctx->cached_sq_head;
index e43e9194dd0ad1873f00f4cf1a9f8a099eed27af..032758b28d786651f8d41b965706b592f976612b 100644 (file)
@@ -12,6 +12,7 @@
 #include "io-wq.h"
 #include "slist.h"
 #include "filetable.h"
+#include "opdef.h"
 
 #ifndef CREATE_TRACE_POINTS
 #include <trace/events/io_uring.h>
@@ -233,6 +234,17 @@ static inline void *io_uring_alloc_async_data(struct io_alloc_cache *cache,
        return req->async_data;
 }
 
+static inline void *io_uring_alloc_async_data_nocache(struct io_kiocb *req)
+{
+       const struct io_issue_def *def = &io_issue_defs[req->opcode];
+
+       WARN_ON_ONCE(!def->async_size);
+       req->async_data = kmalloc(def->async_size, GFP_KERNEL);
+       if (req->async_data)
+               req->flags |= REQ_F_ASYNC_DATA;
+       return req->async_data;
+}
+
 static inline bool req_has_async_data(struct io_kiocb *req)
 {
        return req->flags & REQ_F_ASYNC_DATA;
index bbe58638eca79c56cc835b5203edd62def00f6bc..a166fd90667a2ac8cb0d32774b0bce275bf26a95 100644 (file)
@@ -525,10 +525,9 @@ static int __io_timeout_prep(struct io_kiocb *req,
 
        if (WARN_ON_ONCE(req_has_async_data(req)))
                return -EFAULT;
-       if (io_alloc_async_data(req))
+       data = io_uring_alloc_async_data_nocache(req);
+       if (!data)
                return -ENOMEM;
-
-       data = req->async_data;
        data->req = req;
        data->flags = flags;
 
index daef5dd644f0497ceb9f2a72d25b70003fb9b846..6778c0ee76c427d54579ea84c98b1b78df53e5a0 100644 (file)
@@ -303,10 +303,10 @@ int io_waitid(struct io_kiocb *req, unsigned int issue_flags)
        struct io_waitid_async *iwa;
        int ret;
 
-       if (io_alloc_async_data(req))
+       iwa = io_uring_alloc_async_data_nocache(req);
+       if (!iwa)
                return -ENOMEM;
 
-       iwa = req->async_data;
        iwa->req = req;
 
        ret = kernel_waitid_prepare(&iwa->wo, iw->which, iw->upid, &iw->info,