Received: by 10.213.65.68 with SMTP id h4csp436474imn; Tue, 13 Mar 2018 09:01:22 -0700 (PDT) X-Google-Smtp-Source: AG47ELsX75uVZMX0O+BDqQDZX5diSusuwMbba6EK61FN64D3izw5p1B8OgOBWjLdPiDmJXQRpOu5 X-Received: by 2002:a17:902:be16:: with SMTP id r22-v6mr1003731pls.268.1520956882752; Tue, 13 Mar 2018 09:01:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520956882; cv=none; d=google.com; s=arc-20160816; b=xbKWZS/xtMTxUF4ajQAfab72S/TyLElL3Q5DEuB3kc6TH5irije+zUIDuKiytVf+/d eHtvb8xzG/1mg1UDWtLoo2vLkNAvnOrPYS/JaMRQ1/KMfr/wDDrZMJ3epUnIUkE1KeEG lZwRzu+QemYN/92Y6hMiSU5OsQlTl0rEd09wF0ic8COl8S/8NrfFvEFvho8E0hxN3kCH m2zqFxk81y3TKIeDe4F3ewa0S4IEDqwB1xtpLO7+cZfKEmpdu3gyxu83nBqfU1Z32lWK Jmx7S2mXyp7syO7C/IhSEK/n+NLylG1pGxE/XJUiWzXMMDj5kxo/yv8Ii57r1rFcCAUm /vtA== 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=bM3GaZ7VSa/FzsUZHn0BZJF0lyaWluLvvFw3hLthyoA=; b=TzgmPvscpvvV2MtV8xnCieunEjJvYMzz3TenQ7E5n6QBktbuc4Ef6FOAUSYFxRdlgX iq0zSYGKfwt5VZfKej3aIr3r0zE95zHlWyLHGQuGaQwMeomTcjL9rpVuAdp+QCld2lHh cDDeKy6Ebat7zSLReQHBOyyoe9bXolNJ2VWPkespnINDNkcs0W2NyTzxxjZ92B7lPCve V68YhR3aheSgHByIj58pUFCwvFk9LvlQmLVVjO2lQgoLpGSU/R4YnAv+4sV53YW84/6C cB6n/6R00hpjJG7qYiVbIJJvXRaOERCoC7iSJ9HCUwkSV+Cu/QhrvEe+2TWp0VtMjiZD k88g== 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 y8-v6si281356plt.378.2018.03.13.09.01.05; Tue, 13 Mar 2018 09:01:22 -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 S934467AbeCMPhy (ORCPT + 99 others); Tue, 13 Mar 2018 11:37:54 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34122 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934448AbeCMPhv (ORCPT ); Tue, 13 Mar 2018 11:37:51 -0400 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D96AB1250; Tue, 13 Mar 2018 15:37:50 +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.14 061/140] workqueue: Allow retrieval of current tasks work struct Date: Tue, 13 Mar 2018 16:24:24 +0100 Message-Id: <20180313152502.336736048@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180313152458.201155692@linuxfoundation.org> References: <20180313152458.201155692@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.14-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 @@ -467,6 +467,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 @@ -4185,6 +4185,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