Received: by 10.213.65.68 with SMTP id h4csp468815imn; Tue, 13 Mar 2018 10:01:40 -0700 (PDT) X-Google-Smtp-Source: AG47ELtSi4ddgqomVkN6/YwFToKKW6QKohJhG+s29rpSbShFV9kEbCj+KJ8qwG4oAPTELBwTroK8 X-Received: by 10.99.177.66 with SMTP id g2mr1019903pgp.425.1520960500578; Tue, 13 Mar 2018 10:01:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520960500; cv=none; d=google.com; s=arc-20160816; b=R/Bnt5MgE1T0u19JH2IY1KETis7LIey9EZvxTFEhLTiRMGvqFrmsP9hoJmoKk6AlO8 a6MqFtzY3YOARSB2R42OwRvjMHLz2oiE58Ug92R6IExLjNTl8bdm2lr5jnAv9F+k3AHN bpUxiT8cuwCGgel9tcLmVbxlBVzoUWldekfKCsGQk5dLxAChP+XmklH0pT5rh5H2DP5p AtkC8nxkhsRCP7zdBTgU4v4ZDIe55azXgBWQdsmDOc3h9j8tDa/8L0WghubxYpSWjt8c 8ULFUNT3trcJsvTO/MEG2/m64kzKFqKX6O7eQcjZx/rlhbnBcLvyaUqg0deLGz1RxFih 6lww== 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=lBwtu8HQTl0L6lfDdsiR6VIU2wheaD1cxKFqDzDyWK0=; b=rz5G1/itzHuJ6Gsk8NNy2ThWd3E/vXG53g6r7dcuIWucZnUk524+nNuQoOJSxbq+ve kResoAzwWXojHgTVTCdfSuoyyVH/PVXCNK0tNkFKpmLmk6/s4zb0/kDVTyG8q8kgCDnY ACqkRTS3vNm4vheiytzvfYPMoRufF5/90d5X5JspwMDqWc5fZltubNdal6T50IsPGt/Q xOToRQzUpWvKmTRSdk71T7EKcnb9FtU/lAWpAQZPZZkpOJYKx2XlZI8YNYRSiGgsop3Z b/pDra+2MvhalsJp8x09RsWDwXS2HA2TSx0GUHKOqW0IBo9kY0gSb1JSi+QaqxUVu/Xr VLnw== 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 y86si351981pfi.19.2018.03.13.10.01.24; Tue, 13 Mar 2018 10:01:40 -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 S933027AbeCMP3l (ORCPT + 99 others); Tue, 13 Mar 2018 11:29:41 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58462 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932995AbeCMP3j (ORCPT ); Tue, 13 Mar 2018 11:29:39 -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 6F455F8F; Tue, 13 Mar 2018 15:29:38 +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.15 020/146] workqueue: Allow retrieval of current tasks work struct Date: Tue, 13 Mar 2018 16:23:07 +0100 Message-Id: <20180313152322.037126532@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180313152320.439085687@linuxfoundation.org> References: <20180313152320.439085687@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.15-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 @@ -465,6 +465,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 @@ -4169,6 +4169,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