Skip to content

Commit 0aa69d5

Browse files
committed
Merge tag 'for-6.5/io_uring-2023-06-23' of git://git.kernel.dk/linux
Pull io_uring updates from Jens Axboe: "Nothing major in this release, just a bunch of cleanups and some optimizations around networking mostly. - clean up file request flags handling (Christoph) - clean up request freeing and CQ locking (Pavel) - support for using pre-registering the io_uring fd at setup time (Josh) - Add support for user allocated ring memory, rather than having the kernel allocate it. Mostly for packing rings into a huge page (me) - avoid an unnecessary double retry on receive (me) - maintain ordering for task_work, which also improves performance (me) - misc cleanups/fixes (Pavel, me)" * tag 'for-6.5/io_uring-2023-06-23' of git://git.kernel.dk/linux: (39 commits) io_uring: merge conditional unlock flush helpers io_uring: make io_cq_unlock_post static io_uring: inline __io_cq_unlock io_uring: fix acquire/release annotations io_uring: kill io_cq_unlock() io_uring: remove IOU_F_TWQ_FORCE_NORMAL io_uring: don't batch task put on reqs free io_uring: move io_clean_op() io_uring: inline io_dismantle_req() io_uring: remove io_free_req_tw io_uring: open code io_put_req_find_next io_uring: add helpers to decode the fixed file file_ptr io_uring: use io_file_from_index in io_msg_grab_file io_uring: use io_file_from_index in __io_sync_cancel io_uring: return REQ_F_ flags from io_file_get_flags io_uring: remove io_req_ffs_set io_uring: remove a confusing comment above io_file_get_flags io_uring: remove the mode variable in io_file_get_flags io_uring: remove __io_file_supports_nowait io_uring: wait interruptibly for request completions on exit ...
2 parents 3eccc0c + c98c81a commit 0aa69d5

File tree

21 files changed

+416
-334
lines changed

21 files changed

+416
-334
lines changed

block/fops.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ static int blkdev_open(struct inode *inode, struct file *filp)
481481
* during an unstable branch.
482482
*/
483483
filp->f_flags |= O_LARGEFILE;
484-
filp->f_mode |= FMODE_NOWAIT | FMODE_BUF_RASYNC;
484+
filp->f_mode |= FMODE_BUF_RASYNC;
485485

486486
if (filp->f_flags & O_NDELAY)
487487
filp->f_mode |= FMODE_NDELAY;
@@ -494,6 +494,9 @@ static int blkdev_open(struct inode *inode, struct file *filp)
494494
if (IS_ERR(bdev))
495495
return PTR_ERR(bdev);
496496

497+
if (bdev_nowait(bdev))
498+
filp->f_mode |= FMODE_NOWAIT;
499+
497500
filp->private_data = bdev;
498501
filp->f_mapping = bdev->bd_inode->i_mapping;
499502
filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping);

drivers/nvme/host/ioctl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ static enum rq_end_io_ret nvme_uring_cmd_end_io(struct request *req,
521521
if (cookie != NULL && blk_rq_is_poll(req))
522522
nvme_uring_task_cb(ioucmd, IO_URING_F_UNLOCKED);
523523
else
524-
io_uring_cmd_complete_in_task(ioucmd, nvme_uring_task_cb);
524+
io_uring_cmd_do_in_task_lazy(ioucmd, nvme_uring_task_cb);
525525

526526
return RQ_END_IO_FREE;
527527
}
@@ -543,7 +543,7 @@ static enum rq_end_io_ret nvme_uring_cmd_end_io_meta(struct request *req,
543543
if (cookie != NULL && blk_rq_is_poll(req))
544544
nvme_uring_task_meta_cb(ioucmd, IO_URING_F_UNLOCKED);
545545
else
546-
io_uring_cmd_complete_in_task(ioucmd, nvme_uring_task_meta_cb);
546+
io_uring_cmd_do_in_task_lazy(ioucmd, nvme_uring_task_meta_cb);
547547

548548
return RQ_END_IO_NONE;
549549
}

include/linux/io_uring.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,23 @@ int io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
4646
struct iov_iter *iter, void *ioucmd);
4747
void io_uring_cmd_done(struct io_uring_cmd *cmd, ssize_t ret, ssize_t res2,
4848
unsigned issue_flags);
49-
void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
50-
void (*task_work_cb)(struct io_uring_cmd *, unsigned));
5149
struct sock *io_uring_get_socket(struct file *file);
5250
void __io_uring_cancel(bool cancel_all);
5351
void __io_uring_free(struct task_struct *tsk);
5452
void io_uring_unreg_ringfd(void);
5553
const char *io_uring_get_opcode(u8 opcode);
54+
void __io_uring_cmd_do_in_task(struct io_uring_cmd *ioucmd,
55+
void (*task_work_cb)(struct io_uring_cmd *, unsigned),
56+
unsigned flags);
57+
/* users should follow semantics of IOU_F_TWQ_LAZY_WAKE */
58+
void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd *ioucmd,
59+
void (*task_work_cb)(struct io_uring_cmd *, unsigned));
60+
61+
static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
62+
void (*task_work_cb)(struct io_uring_cmd *, unsigned))
63+
{
64+
__io_uring_cmd_do_in_task(ioucmd, task_work_cb, 0);
65+
}
5666

5767
static inline void io_uring_files_cancel(void)
5868
{
@@ -85,6 +95,10 @@ static inline void io_uring_cmd_complete_in_task(struct io_uring_cmd *ioucmd,
8595
void (*task_work_cb)(struct io_uring_cmd *, unsigned))
8696
{
8797
}
98+
static inline void io_uring_cmd_do_in_task_lazy(struct io_uring_cmd *ioucmd,
99+
void (*task_work_cb)(struct io_uring_cmd *, unsigned))
100+
{
101+
}
88102
static inline struct sock *io_uring_get_socket(struct file *file)
89103
{
90104
return NULL;

include/linux/io_uring_types.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,16 @@ struct io_ring_ctx {
211211
unsigned int compat: 1;
212212

213213
enum task_work_notify_mode notify_method;
214+
215+
/*
216+
* If IORING_SETUP_NO_MMAP is used, then the below holds
217+
* the gup'ed pages for the two rings, and the sqes.
218+
*/
219+
unsigned short n_ring_pages;
220+
unsigned short n_sqe_pages;
221+
struct page **ring_pages;
222+
struct page **sqe_pages;
223+
214224
struct io_rings *rings;
215225
struct task_struct *submitter_task;
216226
struct percpu_ref refs;

include/uapi/linux/io_uring.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,18 @@ enum {
173173
*/
174174
#define IORING_SETUP_DEFER_TASKRUN (1U << 13)
175175

176+
/*
177+
* Application provides the memory for the rings
178+
*/
179+
#define IORING_SETUP_NO_MMAP (1U << 14)
180+
181+
/*
182+
* Register the ring fd in itself for use with
183+
* IORING_REGISTER_USE_REGISTERED_RING; return a registered fd index rather
184+
* than an fd.
185+
*/
186+
#define IORING_SETUP_REGISTERED_FD_ONLY (1U << 15)
187+
176188
enum io_uring_op {
177189
IORING_OP_NOP,
178190
IORING_OP_READV,
@@ -406,7 +418,7 @@ struct io_sqring_offsets {
406418
__u32 dropped;
407419
__u32 array;
408420
__u32 resv1;
409-
__u64 resv2;
421+
__u64 user_addr;
410422
};
411423

412424
/*
@@ -425,7 +437,7 @@ struct io_cqring_offsets {
425437
__u32 cqes;
426438
__u32 flags;
427439
__u32 resv1;
428-
__u64 resv2;
440+
__u64 user_addr;
429441
};
430442

431443
/*

io_uring/cancel.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,10 @@ static int __io_sync_cancel(struct io_uring_task *tctx,
216216
/* fixed must be grabbed every time since we drop the uring_lock */
217217
if ((cd->flags & IORING_ASYNC_CANCEL_FD) &&
218218
(cd->flags & IORING_ASYNC_CANCEL_FD_FIXED)) {
219-
unsigned long file_ptr;
220-
221219
if (unlikely(fd >= ctx->nr_user_files))
222220
return -EBADF;
223221
fd = array_index_nospec(fd, ctx->nr_user_files);
224-
file_ptr = io_fixed_file_slot(&ctx->file_table, fd)->file_ptr;
225-
cd->file = (struct file *) (file_ptr & FFS_MASK);
222+
cd->file = io_file_from_index(&ctx->file_table, fd);
226223
if (!cd->file)
227224
return -EBADF;
228225
}

io_uring/filetable.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file,
7878
file_slot = io_fixed_file_slot(&ctx->file_table, slot_index);
7979

8080
if (file_slot->file_ptr) {
81-
struct file *old_file;
82-
83-
old_file = (struct file *)(file_slot->file_ptr & FFS_MASK);
84-
ret = io_queue_rsrc_removal(ctx->file_data, slot_index, old_file);
81+
ret = io_queue_rsrc_removal(ctx->file_data, slot_index,
82+
io_slot_file(file_slot));
8583
if (ret)
8684
return ret;
8785

@@ -140,7 +138,6 @@ int io_fixed_fd_install(struct io_kiocb *req, unsigned int issue_flags,
140138
int io_fixed_fd_remove(struct io_ring_ctx *ctx, unsigned int offset)
141139
{
142140
struct io_fixed_file *file_slot;
143-
struct file *file;
144141
int ret;
145142

146143
if (unlikely(!ctx->file_data))
@@ -153,8 +150,8 @@ int io_fixed_fd_remove(struct io_ring_ctx *ctx, unsigned int offset)
153150
if (!file_slot->file_ptr)
154151
return -EBADF;
155152

156-
file = (struct file *)(file_slot->file_ptr & FFS_MASK);
157-
ret = io_queue_rsrc_removal(ctx->file_data, offset, file);
153+
ret = io_queue_rsrc_removal(ctx->file_data, offset,
154+
io_slot_file(file_slot));
158155
if (ret)
159156
return ret;
160157

io_uring/filetable.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
#include <linux/file.h>
66
#include <linux/io_uring_types.h>
77

8-
#define FFS_NOWAIT 0x1UL
9-
#define FFS_ISREG 0x2UL
10-
#define FFS_MASK ~(FFS_NOWAIT|FFS_ISREG)
11-
128
bool io_alloc_file_tables(struct io_file_table *table, unsigned nr_files);
139
void io_free_file_tables(struct io_file_table *table);
1410

@@ -43,21 +39,31 @@ io_fixed_file_slot(struct io_file_table *table, unsigned i)
4339
return &table->files[i];
4440
}
4541

42+
#define FFS_NOWAIT 0x1UL
43+
#define FFS_ISREG 0x2UL
44+
#define FFS_MASK ~(FFS_NOWAIT|FFS_ISREG)
45+
46+
static inline unsigned int io_slot_flags(struct io_fixed_file *slot)
47+
{
48+
return (slot->file_ptr & ~FFS_MASK) << REQ_F_SUPPORT_NOWAIT_BIT;
49+
}
50+
51+
static inline struct file *io_slot_file(struct io_fixed_file *slot)
52+
{
53+
return (struct file *)(slot->file_ptr & FFS_MASK);
54+
}
55+
4656
static inline struct file *io_file_from_index(struct io_file_table *table,
4757
int index)
4858
{
49-
struct io_fixed_file *slot = io_fixed_file_slot(table, index);
50-
51-
return (struct file *) (slot->file_ptr & FFS_MASK);
59+
return io_slot_file(io_fixed_file_slot(table, index));
5260
}
5361

5462
static inline void io_fixed_file_set(struct io_fixed_file *file_slot,
5563
struct file *file)
5664
{
57-
unsigned long file_ptr = (unsigned long) file;
58-
59-
file_ptr |= io_file_get_flags(file);
60-
file_slot->file_ptr = file_ptr;
65+
file_slot->file_ptr = (unsigned long)file |
66+
(io_file_get_flags(file) >> REQ_F_SUPPORT_NOWAIT_BIT);
6167
}
6268

6369
static inline void io_reset_alloc_hint(struct io_ring_ctx *ctx)

0 commit comments

Comments
 (0)