Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3198500pxb; Mon, 9 Nov 2020 05:24:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPb1MKm/dJOSrQHtbxGv+T4eRoXi4qjI1hY37ytAduqVHNGuw+Tl1O5y86QfiQTW6/P5gg X-Received: by 2002:a05:6402:14c6:: with SMTP id f6mr15851579edx.359.1604928258749; Mon, 09 Nov 2020 05:24:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604928258; cv=none; d=google.com; s=arc-20160816; b=ceTYzsJlzsMs11H4u7sN0RBeiUrONVVwpV58DqHW8RCKEQS7Douj+tGvdNZYJSvD2x Njm+rtpKhE+rjc4bWzsi+DxG1FMvQA5jQghAocwGywhP5K9f1YjiLy/YkRT72r8OSVN8 4ELyWRaPVlBTVew2p7/Pimsh8txdVfp0vcinz0WJ+spQfq+TspmseJ6nv4lrfp5QbTau jmETgMu9Mfxu2iwQASZsk61CzUCKV0WKZtRhs1Waj36FK30QUPG5zDyYYQB9EEc9vz3r tFiyWmIbDN9yB1hlFTiOgTrn1pwcXUm5RWwYp39FW5MykZxKxHe/df0FInsZgMNzfg8B sz3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KUc+txe2aD9HrZ56RuSNSWcvXyy8TBkbDeX67ZQ5aNM=; b=XqCqVQwzupuDN2Rz2A3Z7raFQIOfKolfawDdCOjqpzqO3rV0KXpO3QFl5NBG+ZIOtZ 79EJOTNHFY81iE+RG1XsMErGRowpZYquRZaG8rC2ELVJbG636+vwp80buUBYHpwswwgf rkyDwxGe09jKaYVOySPd224oq2ScLUO2+pyetNzpe0yAye0ZUxpuv05JMAdcVjn2FZ2K SeJA82FwqiHTQcEHlsYbI7MAt1mehX6cuBde2ZKlIDXVAW7issi+vPovEYIpFCqpnJmB WLBVcCmgoJAlXrBjsLPt2+OyWbW+Ks+wjT5twZlSeedUHuEOWlM0/ecmylZR85ShmCID ASGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MOnWSRiK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q10si6462064ejn.234.2020.11.09.05.23.55; Mon, 09 Nov 2020 05:24:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MOnWSRiK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388175AbgKINWK (ORCPT + 99 others); Mon, 9 Nov 2020 08:22:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:50076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733228AbgKINWF (ORCPT ); Mon, 9 Nov 2020 08:22:05 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B9B0120663; Mon, 9 Nov 2020 13:22:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604928124; bh=4neTZfsWsgDJac2MUCAwgoPtEy1/kmvoM43g7TTrffY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MOnWSRiKYm9Y21zc8otPMxLK+HGvJS0I7DOmsqEEmVPYoEE4Bf4z7+ew86Xyhyqhm 5UqQFObHrfAVEAinigLYVHdJ1BNFFsQDL8DGlzv24MsXaeA+7aNN6QY5n/0R4wpHzq oxtWuWqfzRvtiN5Gz0fkZtLjqGyQ+vH3npdgIrxw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Rafael J. Wysocki" , Xiang Chen Subject: [PATCH 5.9 128/133] PM: runtime: Drop runtime PM references to supplier on link removal Date: Mon, 9 Nov 2020 13:56:30 +0100 Message-Id: <20201109125036.844040612@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125030.706496283@linuxfoundation.org> References: <20201109125030.706496283@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki commit e0e398e204634db8fb71bd89cf2f6e3e5bd09b51 upstream. While removing a device link, drop the supplier device's runtime PM usage counter as many times as needed to drop all of the runtime PM references to it from the consumer in addition to dropping the consumer's link count. Fixes: baa8809f6097 ("PM / runtime: Optimize the use of device links") Signed-off-by: Rafael J. Wysocki Cc: 5.1+ # 5.1+ Tested-by: Xiang Chen Reviewed-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 6 ++---- drivers/base/power/runtime.c | 21 ++++++++++++++++++++- include/linux/pm_runtime.h | 4 ++-- 3 files changed, 24 insertions(+), 7 deletions(-) --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -763,8 +763,7 @@ static void __device_link_del(struct kre dev_dbg(link->consumer, "Dropping the link to %s\n", dev_name(link->supplier)); - if (link->flags & DL_FLAG_PM_RUNTIME) - pm_runtime_drop_link(link->consumer); + pm_runtime_drop_link(link); list_del_rcu(&link->s_node); list_del_rcu(&link->c_node); @@ -778,8 +777,7 @@ static void __device_link_del(struct kre dev_info(link->consumer, "Dropping the link to %s\n", dev_name(link->supplier)); - if (link->flags & DL_FLAG_PM_RUNTIME) - pm_runtime_drop_link(link->consumer); + pm_runtime_drop_link(link); list_del(&link->s_node); list_del(&link->c_node); --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1729,7 +1729,7 @@ void pm_runtime_new_link(struct device * spin_unlock_irq(&dev->power.lock); } -void pm_runtime_drop_link(struct device *dev) +static void pm_runtime_drop_link_count(struct device *dev) { spin_lock_irq(&dev->power.lock); WARN_ON(dev->power.links_count == 0); @@ -1737,6 +1737,25 @@ void pm_runtime_drop_link(struct device spin_unlock_irq(&dev->power.lock); } +/** + * pm_runtime_drop_link - Prepare for device link removal. + * @link: Device link going away. + * + * Drop the link count of the consumer end of @link and decrement the supplier + * device's runtime PM usage counter as many times as needed to drop all of the + * PM runtime reference to it from the consumer. + */ +void pm_runtime_drop_link(struct device_link *link) +{ + if (!(link->flags & DL_FLAG_PM_RUNTIME)) + return; + + pm_runtime_drop_link_count(link->consumer); + + while (refcount_dec_not_one(&link->rpm_active)) + pm_runtime_put(link->supplier); +} + static bool pm_runtime_need_not_resume(struct device *dev) { return atomic_read(&dev->power.usage_count) <= 1 && --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h @@ -58,7 +58,7 @@ extern void pm_runtime_clean_up_links(st extern void pm_runtime_get_suppliers(struct device *dev); extern void pm_runtime_put_suppliers(struct device *dev); extern void pm_runtime_new_link(struct device *dev); -extern void pm_runtime_drop_link(struct device *dev); +extern void pm_runtime_drop_link(struct device_link *link); /** * pm_runtime_get_if_in_use - Conditionally bump up runtime PM usage counter. @@ -280,7 +280,7 @@ static inline void pm_runtime_clean_up_l static inline void pm_runtime_get_suppliers(struct device *dev) {} static inline void pm_runtime_put_suppliers(struct device *dev) {} static inline void pm_runtime_new_link(struct device *dev) {} -static inline void pm_runtime_drop_link(struct device *dev) {} +static inline void pm_runtime_drop_link(struct device_link *link) {} #endif /* !CONFIG_PM */