]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
io_uring/rsrc: change ubuf->ubuf_end to length tracking
authorJens Axboe <axboe@kernel.dk>
Sun, 15 Sep 2024 14:53:45 +0000 (08:53 -0600)
committerJens Axboe <axboe@kernel.dk>
Sun, 15 Sep 2024 15:15:22 +0000 (09:15 -0600)
If we change it to tracking ubuf->start + ubuf->len, then we can reduce
the size of struct io_mapped_ubuf by another 4 bytes, effectively 8
bytes, as a hole is eliminated too.

This shrinks io_mapped_ubuf to 32 bytes.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/fdinfo.c
io_uring/rsrc.c
io_uring/rsrc.h

index d43e1b5fcb36da3360f689e5a86ca7b145497a14..6b1247664b35550336c957b0fae17a4773b054d1 100644 (file)
@@ -177,9 +177,8 @@ __cold void io_uring_show_fdinfo(struct seq_file *m, struct file *file)
        seq_printf(m, "UserBufs:\t%u\n", ctx->nr_user_bufs);
        for (i = 0; has_lock && i < ctx->nr_user_bufs; i++) {
                struct io_mapped_ubuf *buf = ctx->user_bufs[i];
-               unsigned int len = buf->ubuf_end - buf->ubuf;
 
-               seq_printf(m, "%5u: 0x%llx/%u\n", i, buf->ubuf, len);
+               seq_printf(m, "%5u: 0x%llx/%u\n", i, buf->ubuf, buf->len);
        }
        if (has_lock && !xa_empty(&ctx->personalities)) {
                unsigned long index;
index 2477995e2d656d470a33756459da6d3f05b3a649..131bcdda577a1b7bc89141c08478b6fa982597b7 100644 (file)
@@ -38,7 +38,7 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov,
 static const struct io_mapped_ubuf dummy_ubuf = {
        /* set invalid range, so io_import_fixed() fails meeting it */
        .ubuf = -1UL,
-       .ubuf_end = 0,
+       .len = UINT_MAX,
 };
 
 int __io_account_mem(struct user_struct *user, unsigned long nr_pages)
@@ -985,7 +985,7 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov,
        size = iov->iov_len;
        /* store original address for later verification */
        imu->ubuf = (unsigned long) iov->iov_base;
-       imu->ubuf_end = imu->ubuf + iov->iov_len;
+       imu->len = iov->iov_len;
        imu->nr_bvecs = nr_pages;
        imu->folio_shift = PAGE_SHIFT;
        if (coalesced)
@@ -1086,7 +1086,7 @@ int io_import_fixed(int ddir, struct iov_iter *iter,
        if (unlikely(check_add_overflow(buf_addr, (u64)len, &buf_end)))
                return -EFAULT;
        /* not inside the mapped region */
-       if (unlikely(buf_addr < imu->ubuf || buf_end > imu->ubuf_end))
+       if (unlikely(buf_addr < imu->ubuf || buf_end > (imu->ubuf + imu->len)))
                return -EFAULT;
 
        /*
index e290d2be328545ab9c86abe2e30468082fb59a47..8ed58803621027a1d4d9d9b43a142823a46c3417 100644 (file)
@@ -42,11 +42,11 @@ struct io_rsrc_node {
 
 struct io_mapped_ubuf {
        u64             ubuf;
-       u64             ubuf_end;
+       unsigned int    len;
        unsigned int    nr_bvecs;
        unsigned int    folio_shift;
-       unsigned long   acct_pages;
        refcount_t      refs;
+       unsigned long   acct_pages;
        struct bio_vec  bvec[] __counted_by(nr_bvecs);
 };