Blob Blame History Raw
From 8472346d38818575e3c8236c9f46769e821adb3c Mon Sep 17 00:00:00 2001
From: Jens Axboe <axboe@kernel.dk>
Date: Thu, 2 Dec 2021 19:40:15 -0700
Subject: [PATCH 4/4] io-wq: don't retry task_work creation failure on fatal
 conditions
Git-commit: a226abcd5d427fe9d42efc442818a4a1821e2664
Patch-mainline: v5.16-rc4
References: bnc#1205113

We don't want to be retrying task_work creation failure if there's
an actual signal pending for the parent task. If we do, then we can
enter an infinite loop of perpetually retrying and each retry failing
with -ERESTARTNOINTR because a signal is pending.

Fixes: 3146cba99aa2 ("io-wq: make worker creation resilient against signals")
Reported-by: Florian Fischer <florian.fl.fischer@fau.de>
Link: https://lore.kernel.org/io-uring/20211202165606.mqryio4yzubl7ms5@pasture/
Tested-by: Florian Fischer <florian.fl.fischer@fau.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de>
---
 fs/io-wq.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/io-wq.c b/fs/io-wq.c
index 10e8cc1edd69..198eea31e0b0 100644
--- a/fs/io-wq.c
+++ b/fs/io-wq.c
@@ -682,6 +682,13 @@ static bool io_wq_work_match_all(struct io_wq_work *work, void *data)
 
 static inline bool io_should_retry_thread(long err)
 {
+	/*
+	 * Prevent perpetual task_work retry, if the task (or its group) is
+	 * exiting.
+	 */
+	if (fatal_signal_pending(current))
+		return false;
+
 	switch (err) {
 	case -EAGAIN:
 	case -ERESTARTSYS:
-- 
2.35.3