History

Merge tag 'io_uring-6.6-2023-10-27' of git://git.kernel.dk/linux

Pull io_uring fixes from Jens Axboe: "Fix for an issue reported where reading fdinfo could find a NULL thread as we didn't properly synchronize, and then a disable for the IOCB_DIO_CALLER_COMP optimization as a recent reported highlighted how that could lead to deadlocks if the task issued async O_DIRECT writes and then proceeded to do sync fallocate() calls" * tag 'io_uring-6.6-2023-10-27' of git://git.kernel.dk/linux: io_uring/rw: disable IOCB_DIO_CALLER_COMP io_uring/fdinfo: lock SQ thread while retrieving thread cpu/pid

Linus Torvalds committed 3 years ago

Commit 56567a22 parents 2dc4e0f 838b35b2 files · +12 −15Browse files

Unified · Split

2 files
  1. io_uring/fdinfo.c +12 −6
  2. io_uring/rw.c +0 −9
io_uring/fdinfo.c+12−6
@@ -53,7 +53,6 @@ static __cold int io_uring_show_cred(struct seq_file *m, unsigned int id, · 52 unmodified lines
53__cold void io_uring_show_fdinfo(struct seq_file *m, struct file *f)53__cold void io_uring_show_fdinfo(struct seq_file *m, struct file *f)
54{54{
55 struct io_ring_ctx *ctx = f->private_data;55 struct io_ring_ctx *ctx = f->private_data;
56 struct io_sq_data *sq = NULL;
57 struct io_overflow_cqe *ocqe;56 struct io_overflow_cqe *ocqe;
58 struct io_rings *r = ctx->rings;57 struct io_rings *r = ctx->rings;
59 unsigned int sq_mask = ctx->sq_entries - 1, cq_mask = ctx->cq_entries - 1;58 unsigned int sq_mask = ctx->sq_entries - 1, cq_mask = ctx->cq_entries - 1;
@@ -64,6 +63,7 @@ __cold void io_uring_show_fdinfo(struct seq_file *m, struct file *f) · 4 unmodified lines
64 unsigned int cq_shift = 0;63 unsigned int cq_shift = 0;
65 unsigned int sq_shift = 0;64 unsigned int sq_shift = 0;
66 unsigned int sq_entries, cq_entries;65 unsigned int sq_entries, cq_entries;
66 int sq_pid = -1, sq_cpu = -1;
67 bool has_lock;67 bool has_lock;
68 unsigned int i;68 unsigned int i;
69 69
@@ -143,13 +143,19 @@ __cold void io_uring_show_fdinfo(struct seq_file *m, struct file *f) · 73 unmodified lines
143 has_lock = mutex_trylock(&ctx->uring_lock);143 has_lock = mutex_trylock(&ctx->uring_lock);
144 144
145 if (has_lock && (ctx->flags & IORING_SETUP_SQPOLL)) {145 if (has_lock && (ctx->flags & IORING_SETUP_SQPOLL)) {
146 sq = ctx->sq_data;146 struct io_sq_data *sq = ctx->sq_data;
147 if (!sq->thread)147
148 sq = NULL;148 if (mutex_trylock(&sq->lock)) {
149 if (sq->thread) {
150 sq_pid = task_pid_nr(sq->thread);
151 sq_cpu = task_cpu(sq->thread);
152 }
153 mutex_unlock(&sq->lock);
154 }
149 }155 }
150 156
151 seq_printf(m, "SqThread:\t%d\n", sq ? task_pid_nr(sq->thread) : -1);157 seq_printf(m, "SqThread:\t%d\n", sq_pid);
152 seq_printf(m, "SqThreadCpu:\t%d\n", sq ? task_cpu(sq->thread) : -1);158 seq_printf(m, "SqThreadCpu:\t%d\n", sq_cpu);
153 seq_printf(m, "UserFiles:\t%u\n", ctx->nr_user_files);159 seq_printf(m, "UserFiles:\t%u\n", ctx->nr_user_files);
154 for (i = 0; has_lock && i < ctx->nr_user_files; i++) {160 for (i = 0; has_lock && i < ctx->nr_user_files; i++) {
155 struct file *f = io_file_from_index(&ctx->file_table, i);161 struct file *f = io_file_from_index(&ctx->file_table, i);
io_uring/rw.c+0−9
@@ -913,15 +913,6 @@ int io_write(struct io_kiocb *req, unsigned int issue_flags) · 912 unmodified lines
913 kiocb_start_write(kiocb);913 kiocb_start_write(kiocb);
914 kiocb->ki_flags |= IOCB_WRITE;914 kiocb->ki_flags |= IOCB_WRITE;
915 915
916 /*
917 * For non-polled IO, set IOCB_DIO_CALLER_COMP, stating that our handler
918 * groks deferring the completion to task context. This isn't
919 * necessary and useful for polled IO as that can always complete
920 * directly.
921 */
922 if (!(kiocb->ki_flags & IOCB_HIPRI))
923 kiocb->ki_flags |= IOCB_DIO_CALLER_COMP;
924
925 if (likely(req->file->f_op->write_iter))916 if (likely(req->file->f_op->write_iter))
926 ret2 = call_write_iter(req->file, kiocb, &s->iter);917 ret2 = call_write_iter(req->file, kiocb, &s->iter);
927 else if (req->file->f_op->write)918 else if (req->file->f_op->write)