Skip to content

Commit 9753c64

Browse files
committed
io_uring/rsrc: change ubuf->ubuf_end to length tracking
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 <[email protected]>
1 parent 8b0c602 commit 9753c64

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

io_uring/fdinfo.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ __cold void io_uring_show_fdinfo(struct seq_file *m, struct file *file)
177177
seq_printf(m, "UserBufs:\t%u\n", ctx->nr_user_bufs);
178178
for (i = 0; has_lock && i < ctx->nr_user_bufs; i++) {
179179
struct io_mapped_ubuf *buf = ctx->user_bufs[i];
180-
unsigned int len = buf->ubuf_end - buf->ubuf;
181180

182-
seq_printf(m, "%5u: 0x%llx/%u\n", i, buf->ubuf, len);
181+
seq_printf(m, "%5u: 0x%llx/%u\n", i, buf->ubuf, buf->len);
183182
}
184183
if (has_lock && !xa_empty(&ctx->personalities)) {
185184
unsigned long index;

io_uring/rsrc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov,
3838
static const struct io_mapped_ubuf dummy_ubuf = {
3939
/* set invalid range, so io_import_fixed() fails meeting it */
4040
.ubuf = -1UL,
41-
.ubuf_end = 0,
41+
.len = UINT_MAX,
4242
};
4343

4444
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,
985985
size = iov->iov_len;
986986
/* store original address for later verification */
987987
imu->ubuf = (unsigned long) iov->iov_base;
988-
imu->ubuf_end = imu->ubuf + iov->iov_len;
988+
imu->len = iov->iov_len;
989989
imu->nr_bvecs = nr_pages;
990990
imu->folio_shift = PAGE_SHIFT;
991991
if (coalesced)
@@ -1086,7 +1086,7 @@ int io_import_fixed(int ddir, struct iov_iter *iter,
10861086
if (unlikely(check_add_overflow(buf_addr, (u64)len, &buf_end)))
10871087
return -EFAULT;
10881088
/* not inside the mapped region */
1089-
if (unlikely(buf_addr < imu->ubuf || buf_end > imu->ubuf_end))
1089+
if (unlikely(buf_addr < imu->ubuf || buf_end > (imu->ubuf + imu->len)))
10901090
return -EFAULT;
10911091

10921092
/*

io_uring/rsrc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ struct io_rsrc_node {
4242

4343
struct io_mapped_ubuf {
4444
u64 ubuf;
45-
u64 ubuf_end;
45+
unsigned int len;
4646
unsigned int nr_bvecs;
4747
unsigned int folio_shift;
48-
unsigned long acct_pages;
4948
refcount_t refs;
49+
unsigned long acct_pages;
5050
struct bio_vec bvec[] __counted_by(nr_bvecs);
5151
};
5252

0 commit comments

Comments
 (0)