Received: by 10.213.65.68 with SMTP id h4csp461883imn; Fri, 16 Mar 2018 08:28:22 -0700 (PDT) X-Google-Smtp-Source: AG47ELt/eTuCyurointek9K8twM0+JxwwbDYR+R6Ibr4U/AgFKIQicoJpfgw1oXW4AZVJ5TL9nSk X-Received: by 2002:a17:902:341:: with SMTP id 59-v6mr2494612pld.407.1521214102066; Fri, 16 Mar 2018 08:28:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521214102; cv=none; d=google.com; s=arc-20160816; b=EioGSAjHnqsz3P+CXRXDTftUcpEG5SM4Is/6yZ/qyIiY56X3m+ccdfxQ1X3WR/nI5P sOOhsD+EW7MT59I6aKRMo9EYzKjpp3dg4XEOpCIm7h+PCI735J6tAPXBqCoPnBmran6S CzYuPg+JICb0pff72porOBg/hiuC5FJZAWzputNmq+pc1cjwf4rKbRXKW1CXapOVr+z1 RfPwJambp+tdfhByH8n2pW84GlQrZoJSHhRyYJ/gEil4U+wSt6GGPZwCPK/Cpc03grzo 0CEN7h7dW4boycaBQfpolgqpdKgKBC1MkhsJEL+evzrBsnMw2TSu0+zKM2Xh2qXReeUs 4ckw== 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=SfyaXvf0Y6jq+G8MytGKkuLGS7ZtouXTeCR4oBdT+2U=; b=kUZHkHs0Lw44y63k5uPuui+AELwOgKfbHYdW0gQLI3WdrgMW0ysncr4N05hYecEDTv YDAlttyuOymQPCxpVE5+NfSKhRu+jm8x+0PhRIQYEiAz612JlwGJxPidzxZgQPZnqHwe jpFt/dtCoubDjDGfYK6/3qsRsgd3AS58vW7znaNqvP2BlSSRL/zeNbQHO+r/QNr0xST0 BGQGG9qmUtM+naWDLLpGd2zx7Ci0n350rnMdWpSDom6NhkML9St5cNw3lD6QebVWDDit uco/lsdciCOyvL1m/VEZDFZ6+mktkJRL3E9m55Z0RCR5To7aL73n8ge97jwmWmq9b1Wi tbUQ== 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 j6si5682676pfa.413.2018.03.16.08.28.07; Fri, 16 Mar 2018 08:28: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 S1754210AbeCPP1E (ORCPT + 99 others); Fri, 16 Mar 2018 11:27:04 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34030 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754171AbeCPP1A (ORCPT ); Fri, 16 Mar 2018 11:27:00 -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 3D9A31235; Fri, 16 Mar 2018 15:26:59 +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.4 05/63] workqueue: Allow retrieval of current tasks work struct Date: Fri, 16 Mar 2018 16:22:37 +0100 Message-Id: <20180316152300.616874568@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152259.964532775@linuxfoundation.org> References: <20180316152259.964532775@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.4-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 @@ -451,6 +451,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 @@ -4048,6 +4048,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