Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2481609imm; Thu, 7 Jun 2018 11:19:10 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKw3sz97XFD3IwN69xyoE89LXupTGabKh4TRujupg1v9Gdd4x/4eXwZazpGsdDHQDkAMBaF X-Received: by 2002:a17:902:b18b:: with SMTP id s11-v6mr3181889plr.190.1528395550444; Thu, 07 Jun 2018 11:19:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528395550; cv=none; d=google.com; s=arc-20160816; b=pf4xTMp0AOYuIvX6NdDteNCQ5hlM7CBjyDPDXXqTv16nw4B+mPh37YxUQ+J2SuLtUe 1SuG+vF74bnKxQlPPcCgkhYNyqxXrmzMrlC1+vT5E3zO4XBHNHXd5eBt29rGyVju4vLu A+gSnt/o7eghMKy+Rybn5Ojf7hFc/kqp+eD/eyODi7ZU543nELfRVilNIGoQ2ym9K8DH o3sInnXzmuB+TfMgqitrADxXl+zcPJPSlcOSBhR+7/+tG+aPtxDrYLv2SZY7NSW99Zzk R++Zf0Hk++TwtGIjhUbkJvBTJ3hJ43wc6sWnQfcjvGbOtrJIhE2DkqrUjgfxIFMt2ZaK 6keA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=Kvcyj1HE2mO9QVrNfpnGLEca05WWp56CVduhWUZepjc=; b=rNEFGy6NaDJKKFJXgmvFspRSwBoLYMWBOFthMnBWBM4sozQckrc5H46AjVZk8Ql0by 0Qhz/T8FpWLRh3T6gVFUndQXbloIINSDaBzZ9ALQJNB8NK7siyHt1RWNOHbrpwEh9Hl8 T0U/2eoveF35QSkdm4JrMW73t6uKi8KL198dACdsY22aediCwPSWxZXgnp4x4kYkXHzU IeKe6FcF8tiRULxS0je54sKJvkVvI7Ovk0G7J4ftfoqaff9rs0RAwZqwDpbT9ayf/rqx Jkgl222quyn6AhJJMWda6o68TAoaF3hqfUF1yxnhaJ2KAyXElsspe6ThUWXn0gSiT6o/ u2Qw== 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 r1-v6si26153831pgu.52.2018.06.07.11.18.55; Thu, 07 Jun 2018 11:19:10 -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 S964772AbeFGPBW (ORCPT + 99 others); Thu, 7 Jun 2018 11:01:22 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41380 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934578AbeFGPBT (ORCPT ); Thu, 7 Jun 2018 11:01:19 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbb-0005Zm-Kd; Thu, 07 Jun 2018 15:09:35 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb8-00034z-CZ; Thu, 07 Jun 2018 15:09:06 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Dave Airlie" , "Ben Skeggs" , "Lai Jiangshan" , "Alex Deucher" , "Tejun Heo" , "Lukas Wunner" , "Lyude Paul" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 254/410] workqueue: Allow retrieval of current task's work struct In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 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: Ben Hutchings --- include/linux/workqueue.h | 1 + kernel/workqueue.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -455,6 +455,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 @@ -4369,6 +4369,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