Received: by 10.213.65.68 with SMTP id h4csp463776imn; Fri, 16 Mar 2018 08:31:32 -0700 (PDT) X-Google-Smtp-Source: AG47ELs9+BaZmxsygLpou2oyqw4fOJreHIwvF3xlR0wfsgNyrdnjqgtgY2YlrxkwC5rODQRzl4xq X-Received: by 10.99.190.5 with SMTP id l5mr76973pgf.25.1521214292206; Fri, 16 Mar 2018 08:31:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521214292; cv=none; d=google.com; s=arc-20160816; b=eknNCOuXVZ7MljuJ/rCG2RXw4ukA38kovLKip4f0x/x/jdx/1JrUhD5CRfbvcGAP2E llOXSZkRxKQMYYExIXRbhboyov48OhRO0NXS3jcjxbTD6GSEhNWfE8UWW1T5Q24qM564 trzl7tsYHGdXqocH2ZWM+hDl5WTlmHyMCd1NpRTTXMxIgEez5oFLoNl35ezg4ERZggcQ /hqSvN//AUOchRcflgGKStHnR1Oqd6EdT43zhp2kVg31126RsF91kgiuiSAcESqz+BQo s9QA9HFXcALqY+eKWkUSdIEEmRvndctNBAAXcEnN3ObMIR7GEUB80YRNbfBn4Ns6M0mz utmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Ivwxt1zghRRMtPhuRilXfPxiXbcz1KSxY6p08Oe0DHs=; b=vD1v4bExE8Y8YL/ltRpehk0q7UKhdGwYX9NSi0gwLXnftwi2drJrLSueCl8AlskQZs rrhtilATI2whdwRCZepYvDewIS29FFRgrpoP3ukFvm/ghyVInMdnZL8Yx8Yqn/X58w6x Hrazi2n2hfvpaQoUy6MjkDdAIfuCxj091+QJ0gQbD7dC9OkeDF8OvptF0Urmn8Yn0WK0 7G9W9ODmJRTpXjBShjShi3eI5/gQgArOcSRS9ywJ5TD0mjCvrbyrt3VPdA7uFP/dgQeq yfIQaDcM343RuAwbYRr/V0XIDQ6OmVmyG4IV1d6tVorth8G85R2vqwQcPipD5WIv0IlP /uaQ== 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 t11-v6si6330523plr.411.2018.03.16.08.31.18; Fri, 16 Mar 2018 08:31:32 -0700 (PDT) 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 S932303AbeCPPaQ (ORCPT + 99 others); Fri, 16 Mar 2018 11:30:16 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:36364 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754334AbeCPPaL (ORCPT ); Fri, 16 Mar 2018 11:30:11 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5D8201003; Fri, 16 Mar 2018 15:30:10 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lai Jiangshan , Dave Airlie , Ben Skeggs , Alex Deucher , Tejun Heo , Lyude Paul , Lukas Wunner Subject: [PATCH 4.9 07/86] workqueue: Allow retrieval of current tasks work struct Date: Fri, 16 Mar 2018 16:22:30 +0100 Message-Id: <20180316152317.743198327@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152317.167709497@linuxfoundation.org> References: <20180316152317.167709497@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lukas Wunner commit 27d4ee03078aba88c5e07dcc4917e8d01d046f38 upstream. 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 Cc: Dave Airlie Cc: Ben Skeggs Cc: Alex Deucher Acked-by: Tejun Heo Reviewed-by: Lyude Paul Signed-off-by: Lukas Wunner Link: https://patchwork.freedesktop.org/patch/msgid/2d8f603074131eb87e588d2b803a71765bd3a2fd.1518338788.git.lukas@wunner.de Signed-off-by: Greg Kroah-Hartman --- include/linux/workqueue.h | 1 + kernel/workqueue.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -453,6 +453,7 @@ extern bool cancel_delayed_work_sync(str 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); --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -4130,6 +4130,22 @@ void workqueue_set_max_active(struct wor 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