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
5353 __cold void io_uring_show_fdinfo(struct seq_file *m, struct file *f)
5454 {
5555 struct io_ring_ctx *ctx = f->private_data;
56− struct io_sq_data *sq = NULL;
5756 struct io_overflow_cqe *ocqe;
5857 struct io_rings *r = ctx->rings;
5958 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
6463 unsigned int cq_shift = 0;
6564 unsigned int sq_shift = 0;
6665 unsigned int sq_entries, cq_entries;
66+ int sq_pid = -1, sq_cpu = -1;
6767 bool has_lock;
6868 unsigned int i;
6969
@@ -143,13 +143,19 @@ __cold void io_uring_show_fdinfo(struct seq_file *m, struct file *f) · 73 unmodified lines
143143 has_lock = mutex_trylock(&ctx->uring_lock);
144144
145145 if (has_lock && (ctx->flags & IORING_SETUP_SQPOLL)) {
146− sq = ctx->sq_data;
147− if (!sq->thread)
148− sq = NULL;
146+ struct io_sq_data *sq = ctx->sq_data;
147+
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+ }
149155 }
150156
151− seq_printf(m, "SqThread:\t%d\n", sq ? task_pid_nr(sq->thread) : -1);
152− seq_printf(m, "SqThreadCpu:\t%d\n", sq ? task_cpu(sq->thread) : -1);
157+ seq_printf(m, "SqThread:\t%d\n", sq_pid);
158+ seq_printf(m, "SqThreadCpu:\t%d\n", sq_cpu);
153159 seq_printf(m, "UserFiles:\t%u\n", ctx->nr_user_files);
154160 for (i = 0; has_lock && i < ctx->nr_user_files; i++) {
155161 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
913913 kiocb_start_write(kiocb);
914914 kiocb->ki_flags |= IOCB_WRITE;
915915
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−
925916 if (likely(req->file->f_op->write_iter))
926917 ret2 = call_write_iter(req->file, kiocb, &s->iter);
927918 else if (req->file->f_op->write)