From: Boqun Feng <boqun.feng@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>,
"Paul E . McKenney" <paulmck@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Frederic Weisbecker <frederic@kernel.org>,
Boqun Feng <boqun.feng@gmail.com>
Subject: [RFC 1/2] NOT FOR MERGE: A selftest shows that re-entrance can happen
Date: Fri, 8 Oct 2021 18:04:53 +0800 [thread overview]
Message-ID: <20211008100454.2802393-2-boqun.feng@gmail.com> (raw)
In-Reply-To: <20211008100454.2802393-1-boqun.feng@gmail.com>
Re-entrance can be confirmed when PREEMPT=y as the racy output below:
[ 1.498285] second queue succeeds
[ 1.500679] result of i is 1031665
[ 1.501069] result of i is 1221348
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
---
kernel/workqueue.c | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 33a6b4a2443d..1418710bffcd 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -6099,3 +6099,44 @@ void __init workqueue_init(void)
wq_online = true;
wq_watchdog_init();
}
+
+struct temp_work {
+ struct work_struct work;
+ int i;
+};
+
+#include <linux/delay.h>
+static void __init work_func(struct work_struct *work)
+{
+ struct temp_work *tmp = (struct temp_work *)work;
+ int p = 0;
+ int q;
+
+ for (p = 0; p < 1000000; p++) {
+ q = READ_ONCE(tmp->i);
+ WRITE_ONCE(tmp->i, q + 1);
+ }
+
+ printk("result of i is %d\n", tmp->i);
+}
+
+static int __init work_reentry(void)
+{
+ struct temp_work tmp;
+
+ tmp.i = 0;
+
+ INIT_WORK_ONSTACK(&tmp.work, work_func);
+
+ queue_work_on(1, system_wq, &tmp.work);
+
+ while (!queue_work_on(2, system_unbound_wq, &tmp.work)) { }
+
+ printk("second queue succeeds\n");
+
+ flush_work(&tmp.work);
+
+ return 0;
+}
+
+late_initcall(work_reentry);
--
2.32.0
next prev parent reply other threads:[~2021-10-08 10:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-08 10:04 [RFC 0/2] Re-entrace of a work when requeued to a different workqueue Boqun Feng
2021-10-08 10:04 ` Boqun Feng [this message]
2021-10-08 10:04 ` [RFC 2/2] workqueue: Fix work re-entrance when requeue " Boqun Feng
2021-10-09 2:06 ` Lai Jiangshan
2021-10-09 3:21 ` Boqun Feng
2021-10-09 15:06 ` Boqun Feng
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=20211008100454.2802393-2-boqun.feng@gmail.com \
--to=boqun.feng@gmail.com \
--cc=frederic@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox