Received: by 10.223.185.116 with SMTP id b49csp983526wrg; Sun, 11 Feb 2018 01:43:49 -0800 (PST) X-Google-Smtp-Source: AH8x225XfoFRgi1qF3h7jg9fwwX2Jrqh6+di+Lv2fw0mzG//GBhEdgjAWHtri8cMNIL1oO0uZtyT X-Received: by 2002:a17:902:4523:: with SMTP id m32-v6mr7721788pld.449.1518342229842; Sun, 11 Feb 2018 01:43:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518342229; cv=none; d=google.com; s=arc-20160816; b=iXbyMMDyuIbMC2BOsGRtmoARwIAO7cWqwNlNvyByEYWqhtwxDOFAGeVx0sAJhC5+x1 apKYfNVp2Lapw2pXbbPHHXmKRYALc8FQC1Tq9xvs86d1RdpGQMuxa+Aat8yfS4vPdf82 vXQIhGPiTeQeazxxOF9ve3Z8Cd9SMrj8CBHMIZFxvNXLlay8S7dqFJsa4LOxJWTxaFvd k20tpKDptUbRqViozpn4NHaZYA27HQBcf8GGSCD71GTyMQ3gOpNwO3PDgCUzCoLrQP7g a45LmxdTTTcqpq8uev5CLE0IgxW+gwszO49Yw2H+cukhxf/WlnXywsbw/io+NYoCnnjI 4NdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:date:from:references :in-reply-to:message-id:arc-authentication-results; bh=tJWhgwdI/WW/VqJMW476zGnMuMF6q2CUkZw/gV7Y4DM=; b=Tb/bd6JKVItBgg3PyBnLhqPmUIlBoIjSEOZOTHUHjCJH2DkAt0ubqG9UcZY9d2kswn twP9mTpcR/CFjIMdjN62Zg6K0aXVxycgg+mSqxc4RutHb9ZJ8mAftqvPwQcApUsTZnYd ENrbKEeKeutasE4iu61BiPrPmL6TbdsmFjFpnUlLokJNzOkwKf7+h/WgDK/zpelW0BI9 hzvnG/3Duq9r/eqE6pXZzH7UYmQkGBXV/8LEMo5BDBiYH/Kqd/ZagZMYYqtj6CqoSwvy 4Z6tNA3tOw2hZARQEDg/i7Tk09pY9osqy9ENAqsMF6wwml18XTnWscPa9jmO2ANj/N0v bHcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b96-v6si3134048pli.325.2018.02.11.01.43.36; Sun, 11 Feb 2018 01:43:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752792AbeBKJjM (ORCPT + 99 others); Sun, 11 Feb 2018 04:39:12 -0500 Received: from mailout3.hostsharing.net ([176.9.242.54]:39659 "EHLO mailout3.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752273AbeBKJjK (ORCPT ); Sun, 11 Feb 2018 04:39:10 -0500 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by mailout3.hostsharing.net (Postfix) with ESMTPS id B48CD100B07A6; Sun, 11 Feb 2018 10:39:19 +0100 (CET) Received: from localhost (6-38-90-81.adsl.cmo.de [81.90.38.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id A1A52603E052; Sun, 11 Feb 2018 10:39:08 +0100 (CET) X-Mailbox-Line: From 2d8f603074131eb87e588d2b803a71765bd3a2fd Mon Sep 17 00:00:00 2001 Message-Id: <2d8f603074131eb87e588d2b803a71765bd3a2fd.1518338788.git.lukas@wunner.de> In-Reply-To: References: From: Lukas Wunner Date: Sun, 11 Feb 2018 10:38:28 +0100 Subject: [PATCH 1/5] workqueue: Allow retrieval of current task's work struct To: Tejun Heo , Lai Jiangshan , Alex Deucher , Dave Airlie , Ben Skeggs Cc: dri-devel@lists.freedesktop.org, Peter Wu , nouveau@lists.freedesktop.org, Lyude Paul , Hans de Goede , Pierre Moreau , linux-kernel@vger.kernel.org, Ismo Toijala , intel-gfx@lists.freedesktop.org, Liviu Dudau , Archit Taneja Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: Tejun Heo Cc: Lai Jiangshan Cc: Dave Airlie Cc: Ben Skeggs Cc: Alex Deucher Signed-off-by: Lukas Wunner --- include/linux/workqueue.h | 1 + kernel/workqueue.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index 4a54ef96aff5..bc0cda180c8b 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -465,6 +465,7 @@ extern bool cancel_delayed_work_sync(struct delayed_work *dwork); extern void workqueue_set_max_active(struct workqueue_struct *wq, int max_active); +extern struct work_struct *current_work(void); extern bool current_is_workqueue_rescuer(void); extern bool workqueue_congested(int cpu, struct workqueue_struct *wq); extern unsigned int work_busy(struct work_struct *work); diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 017044c26233..bb9a519cbf50 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -4179,6 +4179,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? * -- 2.15.1