Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp307807ima; Thu, 31 Jan 2019 17:14:52 -0800 (PST) X-Google-Smtp-Source: ALg8bN7UPJFWeYQNkMOrboDoEkYo/7zNztOIgmYOAFbohEcIqPXV1G7T1fYuUCSWcvy4yhYjfR/8 X-Received: by 2002:aa7:8802:: with SMTP id c2mr36887903pfo.20.1548983692901; Thu, 31 Jan 2019 17:14:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548983692; cv=none; d=google.com; s=arc-20160816; b=YsJW5++gMbcElJFRlQ63bofvHmXfOoHUeIV4CGv2Zw5bimvm7jgjcx6z5zuriRWDe8 +qnRd5KkqvESGHXwjpf71q/PxbWPhFYe1CGV1MSRPIRKo4SR/bJHmG6iliZZw6hTVBqg 85dF8pZ9YuRaVj7O+yKAWWDigooug0phJVGyzx9lOoZ0eV7Uln3PzK6SuggqnwIWzrwx D3wW1nv9RRoev5xosfZl+2yIkeYbTwQfVZy4qMxgiOIMUGclqiMt9+rwkWGGMX9Oudhl qC00KfupJGRKzsCwktSsIwqD66haXClQpLK9f8CRT+90wOsdQQIgEclRnSHRCBKHit2R Fsxg== 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=aMPI+DrhwgtkShBWv+xgcyy17LbQn5JXtNPAE0Xyo40=; b=WRHqNEBlvKbZLFTANBcX6vjvVvrwtGoJ5sMv2kB9u4IlQPBBASdiZQ766QGfaNiR9F Y6DEduM4iRqXyUXoWAyoWWB2UNzS6vm5cXXGFRrA+FNrHa6mynBHlx9QlyKsrkCNxRAu BvxFZn35SnF9iX0/v6cwMrc9YvcNLqL3Bdme7XDxLMn/vvDDoJ3+Mt9pn7jHz6pLxQHm zDu652pt6/4JTXRZkK/wtyofKj3CAZcfKHgC504EKeOKQhBdbEBWZUjkWj1ldODQsk7+ pdyexaVjAbRCMrTm1A+Zf0zCzzvUcoc5GE+9yAQBjZljosnm0wbdREUsy2nM4PDHQFDZ P88g== 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 t3si5760384pgo.585.2019.01.31.17.14.37; Thu, 31 Jan 2019 17:14:52 -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 S1729371AbfBABEk (ORCPT + 99 others); Thu, 31 Jan 2019 20:04:40 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:48374 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725787AbfBABEC (ORCPT ); Thu, 31 Jan 2019 20:04:02 -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 2945aa19392aad69; Fri, 1 Feb 2019 02:04:00 +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 6/9] driver core: Do not call rpm_put_suppliers() in pm_runtime_drop_link() Date: Fri, 01 Feb 2019 01:52:45 +0100 Message-ID: <4428766.iRGOQCpFvn@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 Calling rpm_put_suppliers() from pm_runtime_drop_link() is excessive as it affects all suppliers of the consumer device and not just the one pointed to by the device link being dropped. Worst case it may cause the consumer device to stop working unexpectedly. Moreover, in principle it is racy with respect to runtime PM of the consumer device. To avoid these problems drop runtime PM references on the particular supplier pointed to by the link in question only and do that after the link has been dropped from the consumer device's list of links to suppliers, which is in device_link_free(). Fixes: a0504aecba76 ("PM / runtime: Drop usage count for suppliers at device link removal") Signed-off-by: Rafael J. Wysocki --- drivers/base/core.c | 3 +++ drivers/base/power/runtime.c | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) Index: linux-pm/drivers/base/core.c =================================================================== --- linux-pm.orig/drivers/base/core.c +++ linux-pm/drivers/base/core.c @@ -374,6 +374,9 @@ EXPORT_SYMBOL_GPL(device_link_add); static void device_link_free(struct device_link *link) { + while (refcount_dec_not_one(&link->rpm_active)) + pm_runtime_put(link->supplier); + put_device(link->consumer); put_device(link->supplier); kfree(link); Index: linux-pm/drivers/base/power/runtime.c =================================================================== --- linux-pm.orig/drivers/base/power/runtime.c +++ linux-pm/drivers/base/power/runtime.c @@ -1611,8 +1611,6 @@ void pm_runtime_new_link(struct device * void pm_runtime_drop_link(struct device *dev) { - rpm_put_suppliers(dev); - spin_lock_irq(&dev->power.lock); WARN_ON(dev->power.links_count == 0); dev->power.links_count--;