Petr Mladek 19f434
From 60f540389a5d2df25ddc7ad511b4fa2880dea521 Mon Sep 17 00:00:00 2001
Petr Mladek 19f434
From: Petr Mladek <pmladek@suse.com>
Petr Mladek 19f434
Date: Tue, 7 Mar 2023 13:53:33 +0100
Petr Mladek 19f434
Subject: [PATCH] workqueue: Interrupted create_worker() is not a repeated
Petr Mladek 19f434
 event
Petr Mladek 19f434
Git-commit: 60f540389a5d2df25ddc7ad511b4fa2880dea521
Petr Mladek 19f434
Patch-mainline: v6.4-rc1
Petr Mladek 19f434
References: bsc#1211044
Petr Mladek 19f434
Petr Mladek 19f434
kthread_create_on_node() might get interrupted(). It is rare but realistic.
Petr Mladek 19f434
For example, when an unbound workqueue is allocated in module_init()
Petr Mladek 19f434
callback. It is done in the context of the "modprobe" process. And,
Petr Mladek 19f434
for example, systemd might kill pending processes when switching root
Petr Mladek 19f434
from initrd to the booted system.
Petr Mladek 19f434
Petr Mladek 19f434
The interrupt is a one-off event and the race might be hard to reproduce.
Petr Mladek 19f434
It is always worth printing.
Petr Mladek 19f434
Petr Mladek 19f434
Signed-off-by: Petr Mladek <pmladek@suse.com>
Petr Mladek 19f434
Signed-off-by: Tejun Heo <tj@kernel.org>
Petr Mladek 19f434
Petr Mladek 19f434
---
Petr Mladek 19f434
 kernel/workqueue.c | 9 +++++++--
Petr Mladek 19f434
 1 file changed, 7 insertions(+), 2 deletions(-)
Petr Mladek 19f434
Petr Mladek 19f434
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
Petr Mladek 19f434
index 9760f0fca82d..5f0ecaaaf997 100644
Petr Mladek 19f434
--- a/kernel/workqueue.c
Petr Mladek 19f434
+++ b/kernel/workqueue.c
Petr Mladek 19f434
@@ -1959,8 +1959,13 @@ static struct worker *create_worker(struct worker_pool *pool)
Petr Mladek 19f434
 	worker->task = kthread_create_on_node(worker_thread, worker, pool->node,
Petr Mladek 19f434
 					      "kworker/%s", id_buf);
Petr Mladek 19f434
 	if (IS_ERR(worker->task)) {
Petr Mladek 19f434
-		pr_err_once("workqueue: Failed to create a worker thread: %ld",
Petr Mladek 19f434
-			    PTR_ERR(worker->task));
Petr Mladek 19f434
+		if (PTR_ERR(worker->task) == -EINTR) {
Petr Mladek 19f434
+			pr_err("workqueue: Interrupted when creating a worker thread \"kworker/%s\"\n",
Petr Mladek 19f434
+			       id_buf);
Petr Mladek 19f434
+		} else {
Petr Mladek 19f434
+			pr_err_once("workqueue: Failed to create a worker thread: %ld",
Petr Mladek 19f434
+				    PTR_ERR(worker->task));
Petr Mladek 19f434
+		}
Petr Mladek 19f434
 		goto fail;
Petr Mladek 19f434
 	}
Petr Mladek 19f434
 
Petr Mladek 19f434
-- 
Petr Mladek 19f434
2.35.3
Petr Mladek 19f434