All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
To: Tejun Heo <tj@kernel.org>
Cc: 0day robot <lkp@intel.com>, LKML <linux-kernel@vger.kernel.org>,
	lkp@lists.01.org, kernel test robot <oliver.sang@intel.com>
Subject: [PATCH] workqueue: Use private WQ for schedule_on_each_cpu() API
Date: Mon, 21 Feb 2022 19:38:09 +0900	[thread overview]
Message-ID: <3a20c799-c18e-dd3a-3161-fee6bca1491e@I-love.SAKURA.ne.jp> (raw)
In-Reply-To: <20220221083358.GC835@xsang-OptiPlex-9020>

Since schedule_on_each_cpu() calls schedule_work_on() and flush_work(),
we should avoid using system_wq in order to avoid unexpected locking
dependency.

  [T1] Running RCU-tasks wait API self tests
  [T9] Please do not flush events WQ.
  [T9] CPU: 0 PID: 9 Comm: rcu_tasks_rude_ Not tainted 5.16.0-06523-g29bd199e4e73 #1
  [T9] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014
  [T9] Call Trace:
  [T9]  <TASK>
  [T9]  dump_stack_lvl+0x45/0x59
  [T9]  check_flush_dependency.cold+0x18/0x49
  [T9]  __flush_work+0x202/0xa00
  [T9]  schedule_on_each_cpu+0x1d8/0x300
  [T9]  rcu_tasks_kthread+0x21f/0x580
  [T9]  kthread+0x3a4/0x480
  [T9]  ret_from_fork+0x22/0x30
  [T9]  </TASK>
  [T1] Performance Events: unsupported p6 CPU model 42 no PMU driver, software events only.

Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
Tejun, are you OK with https://lkml.kernel.org/r/2f887679-c783-bf18-a2aa-aa9a709bfb38@I-love.SAKURA.ne.jp ?

 kernel/workqueue.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 8e6e64372441..6ebc6cb15c1c 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3345,10 +3345,16 @@ int schedule_on_each_cpu(work_func_t func)
 {
 	int cpu;
 	struct work_struct __percpu *works;
+	struct workqueue_struct *wq;
 
 	works = alloc_percpu(struct work_struct);
 	if (!works)
 		return -ENOMEM;
+	wq = alloc_workqueue("events_sync", 0, 0);
+	if (!wq) {
+		free_percpu(works);
+		return -ENOMEM;
+	}
 
 	cpus_read_lock();
 
@@ -3363,6 +3369,7 @@ int schedule_on_each_cpu(work_func_t func)
 		flush_work(per_cpu_ptr(works, cpu));
 
 	cpus_read_unlock();
+	destroy_workqueue(wq);
 	free_percpu(works);
 	return 0;
 }
-- 
2.32.0



WARNING: multiple messages have this Message-ID (diff)
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
To: lkp@lists.01.org
Subject: [PATCH] workqueue: Use private WQ for schedule_on_each_cpu() API
Date: Mon, 21 Feb 2022 19:38:09 +0900	[thread overview]
Message-ID: <3a20c799-c18e-dd3a-3161-fee6bca1491e@I-love.SAKURA.ne.jp> (raw)
In-Reply-To: <20220221083358.GC835@xsang-OptiPlex-9020>

[-- Attachment #1: Type: text/plain, Size: 1867 bytes --]

Since schedule_on_each_cpu() calls schedule_work_on() and flush_work(),
we should avoid using system_wq in order to avoid unexpected locking
dependency.

  [T1] Running RCU-tasks wait API self tests
  [T9] Please do not flush events WQ.
  [T9] CPU: 0 PID: 9 Comm: rcu_tasks_rude_ Not tainted 5.16.0-06523-g29bd199e4e73 #1
  [T9] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014
  [T9] Call Trace:
  [T9]  <TASK>
  [T9]  dump_stack_lvl+0x45/0x59
  [T9]  check_flush_dependency.cold+0x18/0x49
  [T9]  __flush_work+0x202/0xa00
  [T9]  schedule_on_each_cpu+0x1d8/0x300
  [T9]  rcu_tasks_kthread+0x21f/0x580
  [T9]  kthread+0x3a4/0x480
  [T9]  ret_from_fork+0x22/0x30
  [T9]  </TASK>
  [T1] Performance Events: unsupported p6 CPU model 42 no PMU driver, software events only.

Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
Tejun, are you OK with https://lkml.kernel.org/r/2f887679-c783-bf18-a2aa-aa9a709bfb38(a)I-love.SAKURA.ne.jp ?

 kernel/workqueue.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 8e6e64372441..6ebc6cb15c1c 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3345,10 +3345,16 @@ int schedule_on_each_cpu(work_func_t func)
 {
 	int cpu;
 	struct work_struct __percpu *works;
+	struct workqueue_struct *wq;
 
 	works = alloc_percpu(struct work_struct);
 	if (!works)
 		return -ENOMEM;
+	wq = alloc_workqueue("events_sync", 0, 0);
+	if (!wq) {
+		free_percpu(works);
+		return -ENOMEM;
+	}
 
 	cpus_read_lock();
 
@@ -3363,6 +3369,7 @@ int schedule_on_each_cpu(work_func_t func)
 		flush_work(per_cpu_ptr(works, cpu));
 
 	cpus_read_unlock();
+	destroy_workqueue(wq);
 	free_percpu(works);
 	return 0;
 }
-- 
2.32.0


  reply	other threads:[~2022-02-21 11:09 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-21  8:33 [workqueue] 29bd199e4e: WARNING:possible_circular_locking_dependency_detected kernel test robot
2022-02-21  8:33 ` kernel test robot
2022-02-21 10:38 ` Tetsuo Handa [this message]
2022-02-21 10:38   ` [PATCH] workqueue: Use private WQ for schedule_on_each_cpu() API Tetsuo Handa
2022-02-22 17:29   ` Tejun Heo
2022-02-22 17:29     ` Tejun Heo
2022-02-23  0:57     ` Tetsuo Handa
2022-02-23  0:57       ` Tetsuo Handa
2022-02-23 21:33       ` Tejun Heo
2022-02-23 21:33         ` Tejun Heo
2022-02-23 22:26         ` Tetsuo Handa
2022-02-23 22:26           ` Tetsuo Handa
2022-02-23 22:29           ` Tejun Heo
2022-02-23 22:29             ` Tejun Heo
2022-02-28 14:03             ` [PATCH v3] workqueue: Warn flushing of kernel-global workqueues Tetsuo Handa
2022-02-28 14:03               ` Tetsuo Handa
2022-02-28 18:42               ` Tejun Heo
2022-02-28 18:42                 ` Tejun Heo
2022-03-17 22:25                 ` Tetsuo Handa
2022-03-17 22:25                   ` Tetsuo Handa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3a20c799-c18e-dd3a-3161-fee6bca1491e@I-love.SAKURA.ne.jp \
    --to=penguin-kernel@i-love.sakura.ne.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=lkp@lists.01.org \
    --cc=oliver.sang@intel.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.