From: Xuewen Yan <xuewen.yan@unisoc.com>
To: <tj@kernel.org>, <longman@redhat.com>
Cc: <jiangshanlai@gmail.com>, <ke.wang@unisoc.com>,
<xuewen.yan94@gmail.com>, <linux-kernel@vger.kernel.org>
Subject: [PATCH v2] workqueue: Add rcu lock check after work execute end
Date: Wed, 10 Jan 2024 11:27:24 +0800 [thread overview]
Message-ID: <20240110032724.3339-1-xuewen.yan@unisoc.com> (raw)
In-Reply-To: <9bed61e4-7c08-4c61-a7e4-bdd39335cec1@redhat.com>
Now the workqueue just check the atomic and lock after
work execute end. However, sometimes, drivers's work
may don't unlock rcu after call rcu_read_lock().
And as a result, it would cause rcu stall, but the rcu stall warning
can not dump the work func, because the work has finished.
In order to quickly discover those works that do not call
rcu_read_unlock after rcu_read_lock(). Add the rcu lock check.
Use rcu_preempt_depth() to check the work's rcu status,
Normally, this value is 0. If this value is bigger than 0,
it means the work are still holding rcu lock.
At this time, we print err info and print the work func.
Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com>
---
V2:
- move check to unlikely() helper (Longman)
---
kernel/workqueue.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 2989b57e154a..c2a73364f5ad 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -2634,11 +2634,12 @@ __acquires(&pool->lock)
lock_map_release(&lockdep_map);
lock_map_release(&pwq->wq->lockdep_map);
- if (unlikely(in_atomic() || lockdep_depth(current) > 0)) {
- pr_err("BUG: workqueue leaked lock or atomic: %s/0x%08x/%d\n"
+ if (unlikely(in_atomic() || lockdep_depth(current) > 0 ||
+ rcu_preempt_depth() > 0)) {
+ pr_err("BUG: workqueue leaked lock or atomic: %s/0x%08x/%d/%d\n"
" last function: %ps\n",
- current->comm, preempt_count(), task_pid_nr(current),
- worker->current_func);
+ current->comm, preempt_count(), rcu_preempt_depth(),
+ task_pid_nr(current), worker->current_func);
debug_show_held_locks(current);
dump_stack();
}
--
2.25.1
next prev parent reply other threads:[~2024-01-10 3:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-09 11:10 [PATCH] " Xuewen Yan
2024-01-09 16:39 ` Waiman Long
2024-01-10 3:27 ` Xuewen Yan [this message]
2024-01-10 9:08 ` [PATCH v2] " Lai Jiangshan
2024-01-10 14:28 ` Waiman Long
2024-01-16 20:22 ` Tejun Heo
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=20240110032724.3339-1-xuewen.yan@unisoc.com \
--to=xuewen.yan@unisoc.com \
--cc=jiangshanlai@gmail.com \
--cc=ke.wang@unisoc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=tj@kernel.org \
--cc=xuewen.yan94@gmail.com \
/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
all inboxes | Powered by JetHome®