summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorLukas Wunner <lukas@wunner.de>2018-02-11 10:38:28 +0100
committerSasha Levin <alexander.levin@microsoft.com>2018-03-20 23:49:50 -0400
commit42164a26b1395588966626b83097f9a4483e3bee (patch)
tree5a0de051931c6ab59bd1f9da432eb43c3e8892a1 /kernel
parent8760c0ccf0cbc1758578e275708fcc456318f6d7 (diff)
workqueue: Allow retrieval of current task's work struct
[ Upstream commit 27d4ee03078aba88c5e07dcc4917e8d01d046f38 ] Introduce a helper to retrieve the current task's work struct if it is a workqueue worker. This allows us to fix a long-standing deadlock in several DRM drivers wherein the ->runtime_suspend callback waits for a specific worker to finish and that worker in turn calls a function which waits for runtime suspend to finish. That function is invoked from multiple call sites and waiting for runtime suspend to finish is the correct thing to do except if it's executing in the context of the worker. Cc: Lai Jiangshan <jiangshanlai@gmail.com> Cc: Dave Airlie <airlied@redhat.com> Cc: Ben Skeggs <bskeggs@redhat.com> Cc: Alex Deucher <alexander.deucher@amd.com> Acked-by: Tejun Heo <tj@kernel.org> Reviewed-by: Lyude Paul <lyude@redhat.com> Signed-off-by: Lukas Wunner <lukas@wunner.de> Link: https://patchwork.freedesktop.org/patch/msgid/2d8f603074131eb87e588d2b803a71765bd3a2fd.1518338788.git.lukas@wunner.de Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/workqueue.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 376db986db9b..782ba721984b 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -4063,6 +4063,22 @@ void workqueue_set_max_active(struct workqueue_struct *wq, int max_active)
EXPORT_SYMBOL_GPL(workqueue_set_max_active);
/**
+ * current_work - retrieve %current task's work struct
+ *
+ * Determine if %current task is a workqueue worker and what it's working on.
+ * Useful to find out the context that the %current task is running in.
+ *
+ * Return: work struct if %current task is a workqueue worker, %NULL otherwise.
+ */
+struct work_struct *current_work(void)
+{
+ struct worker *worker = current_wq_worker();
+
+ return worker ? worker->current_work : NULL;
+}
+EXPORT_SYMBOL(current_work);
+
+/**
* current_is_workqueue_rescuer - is %current workqueue rescuer?
*
* Determine whether %current is a workqueue rescuer. Can be used from