Skip to content

Commit ac9f4f3

Browse files
committed
Merge tag 'io_uring-6.18-20251113' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux
Pull io_uring fixes from Jens Axboe: - Use the actual segments in a request when for bvec based buffers - Fix an odd case where the iovec might get leaked for a read/write request, if it was newly allocated, overflowed the alloc cache, and hit an early error - Minor tweak to the query API added in this release, returning the number of available entries * tag 'io_uring-6.18-20251113' of git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux: io_uring/rsrc: don't use blk_rq_nr_phys_segments() as number of bvecs io_uring/query: return number of available queries io_uring/rw: ensure allocated iovec gets cleared for early failure
2 parents b86caed + 2d0e88f commit ac9f4f3

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

include/uapi/linux/io_uring/query.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ struct io_uring_query_opcode {
3636
__u64 enter_flags;
3737
/* Bitmask of all supported IOSQE_* flags */
3838
__u64 sqe_flags;
39+
/* The number of available query opcodes */
40+
__u32 nr_query_opcodes;
41+
__u32 __pad;
3942
};
4043

4144
#endif

io_uring/query.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ static ssize_t io_query_ops(void *data)
2020
e->ring_setup_flags = IORING_SETUP_FLAGS;
2121
e->enter_flags = IORING_ENTER_FLAGS;
2222
e->sqe_flags = SQE_VALID_FLAGS;
23+
e->nr_query_opcodes = __IO_URING_QUERY_MAX;
24+
e->__pad = 0;
2325
return sizeof(*e);
2426
}
2527

io_uring/rsrc.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -943,8 +943,8 @@ int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq,
943943
struct req_iterator rq_iter;
944944
struct io_mapped_ubuf *imu;
945945
struct io_rsrc_node *node;
946-
struct bio_vec bv, *bvec;
947-
u16 nr_bvecs;
946+
struct bio_vec bv;
947+
unsigned int nr_bvecs = 0;
948948
int ret = 0;
949949

950950
io_ring_submit_lock(ctx, issue_flags);
@@ -965,8 +965,11 @@ int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq,
965965
goto unlock;
966966
}
967967

968-
nr_bvecs = blk_rq_nr_phys_segments(rq);
969-
imu = io_alloc_imu(ctx, nr_bvecs);
968+
/*
969+
* blk_rq_nr_phys_segments() may overestimate the number of bvecs
970+
* but avoids needing to iterate over the bvecs
971+
*/
972+
imu = io_alloc_imu(ctx, blk_rq_nr_phys_segments(rq));
970973
if (!imu) {
971974
kfree(node);
972975
ret = -ENOMEM;
@@ -977,16 +980,15 @@ int io_buffer_register_bvec(struct io_uring_cmd *cmd, struct request *rq,
977980
imu->len = blk_rq_bytes(rq);
978981
imu->acct_pages = 0;
979982
imu->folio_shift = PAGE_SHIFT;
980-
imu->nr_bvecs = nr_bvecs;
981983
refcount_set(&imu->refs, 1);
982984
imu->release = release;
983985
imu->priv = rq;
984986
imu->is_kbuf = true;
985987
imu->dir = 1 << rq_data_dir(rq);
986988

987-
bvec = imu->bvec;
988989
rq_for_each_bvec(bv, rq, rq_iter)
989-
*bvec++ = bv;
990+
imu->bvec[nr_bvecs++] = bv;
991+
imu->nr_bvecs = nr_bvecs;
990992

991993
node->buf = imu;
992994
data->nodes[index] = node;

io_uring/rw.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,10 @@ int io_read_mshot_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
463463

464464
void io_readv_writev_cleanup(struct io_kiocb *req)
465465
{
466+
struct io_async_rw *rw = req->async_data;
467+
466468
lockdep_assert_held(&req->ctx->uring_lock);
469+
io_vec_free(&rw->vec);
467470
io_rw_recycle(req, 0);
468471
}
469472

0 commit comments

Comments
 (0)