Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp306605ima; Thu, 31 Jan 2019 17:13:23 -0800 (PST) X-Google-Smtp-Source: ALg8bN6kNAup6SU1rC/d59F4kAkIKjfRt3tDX47JAoZZD6Q3q+Ox7h+QrtD056i1JalAVGoxZ5Rc X-Received: by 2002:a62:18ce:: with SMTP id 197mr38327453pfy.88.1548983603112; Thu, 31 Jan 2019 17:13:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548983603; cv=none; d=google.com; s=arc-20160816; b=PSlZdL3wTtIB+okdI1tLfPH9CrSuhqSarxMjsXzJCWOR6KWIyYQ3TrDkJnilwnl+w2 apN1+h1pztAkR+TaJ06GfHsLOOfqSVgqxbY3DJgD9JIw/0nEvwbSYN0GZL1suvl0Mta8 Vs/HBEQdfU+Es0N9+/mHN8pLY2h2SDQJdkowJmyOKYCqvlZZD63CRWByfPqj74Q7snI7 x4uVei7cVYa6z0HJOrJQLJbZu7p2MH/SIwExX+C4G2xOVB/Fia0n7x576BAJ2h5fZB9E 2zXYv2qGmH257dcfkvpUxy1r92/w03ADfHhVXP/r26I4CBj2mWUGrBSSNc3Uuj98tAvz 0VTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=fIuYY4ypg4WWyHJibB0u0vE1RCm57Fmo8pneVi5ARWo=; b=RigsYj3H+yNjnBIG8bq5iu20u220cTSLkeU/A6+YrOaFF+Vp/yxjdHulcy6G/gH9Pp 8cjjqlRMMoQh+ltHfj0wkudNj7b4pq7OdDc0iBlpP0V2k/J5BRa2hpBUw9Aq8Ohq3ZOE OQbs+s8QaP1qQoBLmry2fwT0wSRVTAxxEwcigUHixIbU/7rHi0RkHHCKZJgn8zgKTKVW 9/VNaUsdPOd3K16h9XZj3/P2OhlzjUZLqzZmj+0Lkj/3XttH/29hibecLbVglqP7ru9y a75BJT3YOHkVuK3c44hE2gESdO8V9Pjxe625OZNpygMYRIaMq6fttf/Td+r9wr+id/R5 oYlg== 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 j5si6026036pfg.254.2019.01.31.17.13.08; Thu, 31 Jan 2019 17:13:23 -0800 (PST) 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 S1729347AbfBABEd (ORCPT + 99 others); Thu, 31 Jan 2019 20:04:33 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:57441 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727688AbfBABED (ORCPT ); Thu, 31 Jan 2019 20:04:03 -0500 Received: from 79.184.255.169.ipv4.supernova.orange.pl (79.184.255.169) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.183) id cf8606785a29951b; Fri, 1 Feb 2019 02:04:01 +0100 From: "Rafael J. Wysocki" To: Greg Kroah-Hartman Cc: LKML , Linux PM , Ulf Hansson , Daniel Vetter , Lukas Wunner , Andrzej Hajda , Russell King - ARM Linux , Lucas Stach , Linus Walleij , Thierry Reding , Laurent Pinchart , Marek Szyprowski , Joerg Roedel Subject: [PATCH v2 3/9] driver core: Do not resume suppliers under device_links_write_lock() Date: Fri, 01 Feb 2019 01:47:53 +0100 Message-ID: <3345126.YDF5Jo2U6B@aspire.rjw.lan> In-Reply-To: <1952449.TVsm6CJCTy@aspire.rjw.lan> References: <1952449.TVsm6CJCTy@aspire.rjw.lan> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki It is incorrect to call pm_runtime_get_sync() under device_links_write_lock(), because it may end up trying to take device_links_read_lock() while resuming the target device and that will deadlock in the non-SRCU case, so avoid that by resuming the supplier device in device_link_add() before calling device_links_write_lock(). Fixes: 21d5c57b3726 ("PM / runtime: Use device links") Fixes: baa8809f6097 ("PM / runtime: Optimize the use of device links") Signed-off-by: Rafael J. Wysocki --- drivers/base/core.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) Index: linux-pm/drivers/base/core.c =================================================================== --- linux-pm.orig/drivers/base/core.c +++ linux-pm/drivers/base/core.c @@ -201,12 +201,21 @@ struct device_link *device_link_add(stru struct device *supplier, u32 flags) { struct device_link *link; + bool rpm_put_supplier = false; if (!consumer || !supplier || (flags & DL_FLAG_STATELESS && flags & (DL_FLAG_AUTOREMOVE_CONSUMER | DL_FLAG_AUTOREMOVE_SUPPLIER))) return NULL; + if (flags & DL_FLAG_PM_RUNTIME && flags & DL_FLAG_RPM_ACTIVE) { + if (pm_runtime_get_sync(supplier) < 0) { + pm_runtime_put_noidle(supplier); + return NULL; + } + rpm_put_supplier = true; + } + device_links_write_lock(); device_pm_lock(); @@ -250,13 +259,8 @@ struct device_link *device_link_add(stru if (flags & DL_FLAG_PM_RUNTIME) { if (flags & DL_FLAG_RPM_ACTIVE) { - if (pm_runtime_get_sync(supplier) < 0) { - pm_runtime_put_noidle(supplier); - kfree(link); - link = NULL; - goto out; - } link->rpm_active = true; + rpm_put_supplier = false; } pm_runtime_new_link(consumer); /* @@ -328,6 +332,10 @@ struct device_link *device_link_add(stru out: device_pm_unlock(); device_links_write_unlock(); + + if (rpm_put_supplier) + pm_runtime_put(supplier); + return link; } EXPORT_SYMBOL_GPL(device_link_add);