Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752092AbbKJJdw (ORCPT ); Tue, 10 Nov 2015 04:33:52 -0500 Received: from mail-vk0-f47.google.com ([209.85.213.47]:35690 "EHLO mail-vk0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751750AbbKJJdq (ORCPT ); Tue, 10 Nov 2015 04:33:46 -0500 MIME-Version: 1.0 In-Reply-To: <1445956731-6304-3-git-send-email-tomeu.vizoso@collabora.com> References: <1445956731-6304-1-git-send-email-tomeu.vizoso@collabora.com> <1445956731-6304-3-git-send-email-tomeu.vizoso@collabora.com> From: Daniel Kurtz Date: Tue, 10 Nov 2015 17:33:26 +0800 X-Google-Sender-Auth: s8pEJ6WOCDu0X7G1Hgr7KVqUAQU Message-ID: Subject: Re: [PATCH v11 2/4] PM / Domains: add setter for dev.pm_domain To: Tomeu Vizoso Cc: linux-pm@vger.kernel.org, Alan Stern , "Rafael J. Wysocki" , martyn.welch@collabora.co.uk, Ulf Hansson , Russell King , Kevin Hilman , Greg Kroah-Hartman , "linux-kernel@vger.kernel.org" , dri-devel , linux-acpi@vger.kernel.org, Tony Lindgren , Pavel Machek , Tomas Winkler , linux-omap@vger.kernel.org, "linux-arm-kernel@lists.infradead.org" , Len Brown Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3990 Lines: 97 Hi Tomeu, On Tue, Oct 27, 2015 at 10:38 PM, Tomeu Vizoso wrote: > Adds a function that sets the pointer to dev_pm_domain in struct device > and that warns if the device has already finished probing. The reason > why we want to enforce that is because in the general case that can > cause problems and also that we can simplify code quite a bit if we can > always assume that. > > This patch also changes all current code that directly sets the > dev.pm_domain pointer. > > Signed-off-by: Tomeu Vizoso > Reviewed-by: Ulf Hansson > --- [snip...] > diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c > index f32b802b98f4..a70f8a5cdfd7 100644 > --- a/drivers/base/power/common.c > +++ b/drivers/base/power/common.c > @@ -128,3 +128,24 @@ void dev_pm_domain_detach(struct device *dev, bool power_off) > dev->pm_domain->detach(dev, power_off); > } > EXPORT_SYMBOL_GPL(dev_pm_domain_detach); > + > +/** > + * dev_pm_domain_set - Set PM domain of a device. > + * @dev: Device whose PM domain is to be set. > + * @pd: PM domain to be set, or NULL. > + * > + * Sets the PM domain the device belongs to. The PM domain of a device needs > + * to be set before its probe finishes (it's bound to a driver). > + * > + * This function must be called with the device lock held. > + */ > +void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd) > +{ > + if (dev->pm_domain == pd) > + return; > + > + WARN(device_is_bound(dev), > + "PM domains can only be changed for unbound devices\n"); > + dev->pm_domain = pd; > +} When testing this patch, I have a platform driver with a device in a genpd that hits this WARN() during shutdown with a backtrace like: [ 930.476714] ------------[ cut here ]------------ [ 930.481323] WARNING: CPU: 3 PID: 10110 at drivers/base/power/common.c:154 dev_pm_domain_set+0x50/0x60() [ 930.494605] PM domains can only be changed for unbound devices [ 930.541047] Call trace: [ 930.543470] [] dump_backtrace+0x0/0x140 [ 930.548820] [] show_stack+0x1c/0x28 [ 930.553826] [] dump_stack+0x74/0x94 [ 930.558831] [] warn_slowpath_common+0x90/0xb8 [ 930.564698] [] warn_slowpath_fmt+0x84/0xac [ 930.570305] [] dev_pm_domain_set+0x4c/0x60 [ 930.575913] [] pm_genpd_remove_device+0xc4/0x174 [ 930.582038] [] genpd_dev_pm_detach+0x7c/0xd4 [ 930.587818] [] dev_pm_domain_detach+0x34/0x44 [ 930.593685] [] platform_drv_shutdown+0x30/0x40 [ 930.599639] [] device_shutdown+0x12c/0x184 [ 930.605247] [] kernel_restart_prepare+0x38/0x44 [ 930.611285] [] kernel_restart+0x1c/0x68 [ 930.616634] [] SyS_reboot+0x1b4/0x210 [ 930.621810] ---[ end trace 0551d0a7afcd5f6f ]--- The problem appears to be that: * On boot, platform_drv_probe() calls dev_pm_domain_attach() before drv->probe(); thus, it calls dev_pm_domain_attach() while the device is unbound. * However, for a platform_device, the reboot path calls device_shutdown(), but not __device_release_driver(): device_shutdown() dev->driver->shutdown => platform_drv_shutdown() dev_pm_domain_detach() dev->pm_domain->detach() => genpd_dev_pm_detach() pm_genpd_remove_device() dev_pm_domain_set(dev, NULL); So, for a platform_device in a genpd power domain with .shutdown installed, platform_drv_shutdown() calls dev_pm_domain_detach() while the device is still bound, which triggers the WARN(). Thanks, -Dan -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/