Skip to content

Commit 2c41fab

Browse files
committed
Merge tag 'io_uring-5.12-2021-03-21' of git://git.kernel.dk/linux-block
Pull io_uring followup fixes from Jens Axboe: - The SIGSTOP change from Eric, so we properly ignore that for PF_IO_WORKER threads. - Disallow sending signals to PF_IO_WORKER threads in general, we're not interested in having them funnel back to the io_uring owning task. - Stable fix from Stefan, ensuring we properly break links for short send/sendmsg recv/recvmsg if MSG_WAITALL is set. - Catch and loop when needing to run task_work before a PF_IO_WORKER threads goes to sleep. * tag 'io_uring-5.12-2021-03-21' of git://git.kernel.dk/linux-block: io_uring: call req_set_fail_links() on short send[msg]()/recv[msg]() with MSG_WAITALL io-wq: ensure task is running before processing task_work signal: don't allow STOP on PF_IO_WORKER threads signal: don't allow sending any signals to PF_IO_WORKER threads
2 parents 1d4345e + 0031275 commit 2c41fab

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

fs/io-wq.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,16 @@ static struct io_wq_work *io_get_next_work(struct io_wqe *wqe)
386386
return NULL;
387387
}
388388

389-
static void io_flush_signals(void)
389+
static bool io_flush_signals(void)
390390
{
391391
if (unlikely(test_tsk_thread_flag(current, TIF_NOTIFY_SIGNAL))) {
392+
__set_current_state(TASK_RUNNING);
392393
if (current->task_works)
393394
task_work_run();
394395
clear_tsk_thread_flag(current, TIF_NOTIFY_SIGNAL);
396+
return true;
395397
}
398+
return false;
396399
}
397400

398401
static void io_assign_current_work(struct io_worker *worker,
@@ -499,7 +502,8 @@ static int io_wqe_worker(void *data)
499502
}
500503
__io_worker_idle(wqe, worker);
501504
raw_spin_unlock_irq(&wqe->lock);
502-
io_flush_signals();
505+
if (io_flush_signals())
506+
continue;
503507
ret = schedule_timeout(WORKER_IDLE_TIMEOUT);
504508
if (try_to_freeze() || ret)
505509
continue;

fs/io_uring.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4386,6 +4386,7 @@ static int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
43864386
struct io_async_msghdr iomsg, *kmsg;
43874387
struct socket *sock;
43884388
unsigned flags;
4389+
int min_ret = 0;
43894390
int ret;
43904391

43914392
sock = sock_from_file(req->file);
@@ -4406,6 +4407,9 @@ static int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
44064407
else if (issue_flags & IO_URING_F_NONBLOCK)
44074408
flags |= MSG_DONTWAIT;
44084409

4410+
if (flags & MSG_WAITALL)
4411+
min_ret = iov_iter_count(&kmsg->msg.msg_iter);
4412+
44094413
ret = __sys_sendmsg_sock(sock, &kmsg->msg, flags);
44104414
if ((issue_flags & IO_URING_F_NONBLOCK) && ret == -EAGAIN)
44114415
return io_setup_async_msg(req, kmsg);
@@ -4416,7 +4420,7 @@ static int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags)
44164420
if (kmsg->free_iov)
44174421
kfree(kmsg->free_iov);
44184422
req->flags &= ~REQ_F_NEED_CLEANUP;
4419-
if (ret < 0)
4423+
if (ret < min_ret)
44204424
req_set_fail_links(req);
44214425
__io_req_complete(req, issue_flags, ret, 0);
44224426
return 0;
@@ -4429,6 +4433,7 @@ static int io_send(struct io_kiocb *req, unsigned int issue_flags)
44294433
struct iovec iov;
44304434
struct socket *sock;
44314435
unsigned flags;
4436+
int min_ret = 0;
44324437
int ret;
44334438

44344439
sock = sock_from_file(req->file);
@@ -4450,14 +4455,17 @@ static int io_send(struct io_kiocb *req, unsigned int issue_flags)
44504455
else if (issue_flags & IO_URING_F_NONBLOCK)
44514456
flags |= MSG_DONTWAIT;
44524457

4458+
if (flags & MSG_WAITALL)
4459+
min_ret = iov_iter_count(&msg.msg_iter);
4460+
44534461
msg.msg_flags = flags;
44544462
ret = sock_sendmsg(sock, &msg);
44554463
if ((issue_flags & IO_URING_F_NONBLOCK) && ret == -EAGAIN)
44564464
return -EAGAIN;
44574465
if (ret == -ERESTARTSYS)
44584466
ret = -EINTR;
44594467

4460-
if (ret < 0)
4468+
if (ret < min_ret)
44614469
req_set_fail_links(req);
44624470
__io_req_complete(req, issue_flags, ret, 0);
44634471
return 0;
@@ -4609,6 +4617,7 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
46094617
struct socket *sock;
46104618
struct io_buffer *kbuf;
46114619
unsigned flags;
4620+
int min_ret = 0;
46124621
int ret, cflags = 0;
46134622
bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
46144623

@@ -4640,6 +4649,9 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
46404649
else if (force_nonblock)
46414650
flags |= MSG_DONTWAIT;
46424651

4652+
if (flags & MSG_WAITALL)
4653+
min_ret = iov_iter_count(&kmsg->msg.msg_iter);
4654+
46434655
ret = __sys_recvmsg_sock(sock, &kmsg->msg, req->sr_msg.umsg,
46444656
kmsg->uaddr, flags);
46454657
if (force_nonblock && ret == -EAGAIN)
@@ -4653,7 +4665,7 @@ static int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags)
46534665
if (kmsg->free_iov)
46544666
kfree(kmsg->free_iov);
46554667
req->flags &= ~REQ_F_NEED_CLEANUP;
4656-
if (ret < 0)
4668+
if (ret < min_ret || ((flags & MSG_WAITALL) && (kmsg->msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))))
46574669
req_set_fail_links(req);
46584670
__io_req_complete(req, issue_flags, ret, cflags);
46594671
return 0;
@@ -4668,6 +4680,7 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags)
46684680
struct socket *sock;
46694681
struct iovec iov;
46704682
unsigned flags;
4683+
int min_ret = 0;
46714684
int ret, cflags = 0;
46724685
bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
46734686

@@ -4699,6 +4712,9 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags)
46994712
else if (force_nonblock)
47004713
flags |= MSG_DONTWAIT;
47014714

4715+
if (flags & MSG_WAITALL)
4716+
min_ret = iov_iter_count(&msg.msg_iter);
4717+
47024718
ret = sock_recvmsg(sock, &msg, flags);
47034719
if (force_nonblock && ret == -EAGAIN)
47044720
return -EAGAIN;
@@ -4707,7 +4723,7 @@ static int io_recv(struct io_kiocb *req, unsigned int issue_flags)
47074723
out_free:
47084724
if (req->flags & REQ_F_BUFFER_SELECTED)
47094725
cflags = io_put_recv_kbuf(req);
4710-
if (ret < 0)
4726+
if (ret < min_ret || ((flags & MSG_WAITALL) && (msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))))
47114727
req_set_fail_links(req);
47124728
__io_req_complete(req, issue_flags, ret, cflags);
47134729
return 0;

kernel/signal.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ bool task_set_jobctl_pending(struct task_struct *task, unsigned long mask)
288288
JOBCTL_STOP_SIGMASK | JOBCTL_TRAPPING));
289289
BUG_ON((mask & JOBCTL_TRAPPING) && !(mask & JOBCTL_PENDING_MASK));
290290

291-
if (unlikely(fatal_signal_pending(task) || (task->flags & PF_EXITING)))
291+
if (unlikely(fatal_signal_pending(task) ||
292+
(task->flags & (PF_EXITING | PF_IO_WORKER))))
292293
return false;
293294

294295
if (mask & JOBCTL_STOP_SIGMASK)
@@ -833,6 +834,9 @@ static int check_kill_permission(int sig, struct kernel_siginfo *info,
833834

834835
if (!valid_signal(sig))
835836
return -EINVAL;
837+
/* PF_IO_WORKER threads don't take any signals */
838+
if (t->flags & PF_IO_WORKER)
839+
return -ESRCH;
836840

837841
if (!si_fromuser(info))
838842
return 0;

0 commit comments

Comments
 (0)