linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] drivers-core: move the calling to device_pm_remove behind the calling to bus_remove_device
@ 2012-10-16 15:28 zhanglong
  2012-10-22  1:01 ` Yanmin Zhang
  2012-10-24 19:46 ` Rafael J. Wysocki
  0 siblings, 2 replies; 6+ messages in thread
From: zhanglong @ 2012-10-16 15:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: Rafael J. Wysocki, yanmin_zhang, Alan Stern, linux-pm

We hit an hang issue when removing a mmc device on Medfield Android phone by sysfs interface.

device_pm_remove will call pm_runtime_remove which would disable
runtime PM of the device. After that pm_runtime_get* or
pm_runtime_put* will be ignored. So if we disable the runtime PM
before device really be removed, drivers' _remove callback may
access HW even pm_runtime_get* fails. That is bad.

Consider below call sequence when removing a device:
device_del => device_pm_remove
             => class_intf->remove_dev(dev, class_intf)  => pm_runtime_get_sync/put_sync
             => bus_remove_device => device_release_driver => pm_runtime_get_sync/put_sync

remove_dev might call pm_runtime_get_sync/put_sync.
Then, generic device_release_driver also calls pm_runtime_get_sync/put_sync.
Since device_del => device_pm_remove firstly, later _get_sync wouldn't really wake up the device. 

I git log -p to find the patch which moves the calling to device_pm_remove ahead.
It's below patch:

commit  775b64d2b6ca37697de925f70799c710aab5849a
Author: Rafael J. Wysocki <rjw@sisk.pl>
Date:   Sat Jan 12 20:40:46 2008 +0100

     PM: Acquire device locks on suspend

     This patch reorganizes the way suspend and resume notifications are
     sent to drivers.  The major changes are that now the PM core acquires
     every device semaphore before calling the methods, and calls to
     device_add() during suspends will fail, while calls to device_del()
     during suspends will block.

     It also provides a way to safely remove a suspended device with the
     help of the PM core, by using the device_pm_schedule_removal() callback
     introduced specifically for this purpose, and updates two drivers (msr
     and cpuid) that need to use it. 


As device_pm_schedule_removal is deleted by another patch, we need also revert other parts of the patch,
i.e. move the calling of device_pm_remove after the calling to bus_remove_device.

Signed-off-by: LongX Zhang <longx.zhang@intel.com>
---
 drivers/base/core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index abea76c..150a415 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1180,7 +1180,6 @@ void device_del(struct device *dev)
        if (dev->bus)
                blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
                                             BUS_NOTIFY_DEL_DEVICE, dev);
-       device_pm_remove(dev);
        dpm_sysfs_remove(dev);
        if (parent)
                klist_del(&dev->p->knode_parent);
@@ -1205,6 +1204,7 @@ void device_del(struct device *dev)
        device_remove_file(dev, &uevent_attr);
        device_remove_attrs(dev);
        bus_remove_device(dev);
+       device_pm_remove(dev);
        driver_deferred_probe_del(dev);

        /* Notify the platform of the removal, in case they
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] drivers-core: move the calling to device_pm_remove behind the calling to bus_remove_device
  2012-10-16 15:28 [PATCH v2] drivers-core: move the calling to device_pm_remove behind the calling to bus_remove_device zhanglong
@ 2012-10-22  1:01 ` Yanmin Zhang
  2012-10-24 19:46 ` Rafael J. Wysocki
  1 sibling, 0 replies; 6+ messages in thread
From: Yanmin Zhang @ 2012-10-22  1:01 UTC (permalink / raw)
  To: zhanglong, Rafael J. Wysocki; +Cc: linux-kernel, Alan Stern, linux-pm

On Tue, 2012-10-16 at 23:28 +0800, zhanglong wrote:
> We hit an hang issue when removing a mmc device on Medfield Android phone by sysfs interface.
> 
> device_pm_remove will call pm_runtime_remove which would disable
> runtime PM of the device. After that pm_runtime_get* or
> pm_runtime_put* will be ignored. So if we disable the runtime PM
> before device really be removed, drivers' _remove callback may
> access HW even pm_runtime_get* fails. That is bad.
> 
> Consider below call sequence when removing a device:
> device_del => device_pm_remove
>              => class_intf->remove_dev(dev, class_intf)  => pm_runtime_get_sync/put_sync
>              => bus_remove_device => device_release_driver => pm_runtime_get_sync/put_sync
> 
> remove_dev might call pm_runtime_get_sync/put_sync.
> Then, generic device_release_driver also calls pm_runtime_get_sync/put_sync.
> Since device_del => device_pm_remove firstly, later _get_sync wouldn't really wake up the device. 
> 
> I git log -p to find the patch which moves the calling to device_pm_remove ahead.
> It's below patch:
> 
> commit  775b64d2b6ca37697de925f70799c710aab5849a
> Author: Rafael J. Wysocki <rjw@sisk.pl>
> Date:   Sat Jan 12 20:40:46 2008 +0100
> 
>      PM: Acquire device locks on suspend
> 
>      This patch reorganizes the way suspend and resume notifications are
>      sent to drivers.  The major changes are that now the PM core acquires
>      every device semaphore before calling the methods, and calls to
>      device_add() during suspends will fail, while calls to device_del()
>      during suspends will block.
> 
>      It also provides a way to safely remove a suspended device with the
>      help of the PM core, by using the device_pm_schedule_removal() callback
>      introduced specifically for this purpose, and updates two drivers (msr
>      and cpuid) that need to use it. 
> 
> 
> As device_pm_schedule_removal is deleted by another patch, we need also revert other parts of the patch,
> i.e. move the calling of device_pm_remove after the calling to bus_remove_device.
> 
> Signed-off-by: LongX Zhang <longx.zhang@intel.com>
Rafael,

With the patch V2, is there anything else we could improve before it can
be merged into your testing tree?

Thanks,
Yanmin

> ---
>  drivers/base/core.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index abea76c..150a415 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -1180,7 +1180,6 @@ void device_del(struct device *dev)
>         if (dev->bus)
>                 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
>                                              BUS_NOTIFY_DEL_DEVICE, dev);
> -       device_pm_remove(dev);
>         dpm_sysfs_remove(dev);
>         if (parent)
>                 klist_del(&dev->p->knode_parent);
> @@ -1205,6 +1204,7 @@ void device_del(struct device *dev)
>         device_remove_file(dev, &uevent_attr);
>         device_remove_attrs(dev);
>         bus_remove_device(dev);
> +       device_pm_remove(dev);
>         driver_deferred_probe_del(dev);
> 
>         /* Notify the platform of the removal, in case they



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] drivers-core: move the calling to device_pm_remove behind the calling to bus_remove_device
  2012-10-16 15:28 [PATCH v2] drivers-core: move the calling to device_pm_remove behind the calling to bus_remove_device zhanglong
  2012-10-22  1:01 ` Yanmin Zhang
@ 2012-10-24 19:46 ` Rafael J. Wysocki
  2012-10-24 22:13   ` Greg Kroah-Hartman
  1 sibling, 1 reply; 6+ messages in thread
From: Rafael J. Wysocki @ 2012-10-24 19:46 UTC (permalink / raw)
  To: zhanglong, Greg Kroah-Hartman
  Cc: linux-kernel, yanmin_zhang, Alan Stern, linux-pm

On Tuesday 16 of October 2012 23:28:08 zhanglong wrote:
> We hit an hang issue when removing a mmc device on Medfield Android phone by sysfs interface.
> 
> device_pm_remove will call pm_runtime_remove which would disable
> runtime PM of the device. After that pm_runtime_get* or
> pm_runtime_put* will be ignored. So if we disable the runtime PM
> before device really be removed, drivers' _remove callback may
> access HW even pm_runtime_get* fails. That is bad.
> 
> Consider below call sequence when removing a device:
> device_del => device_pm_remove
>              => class_intf->remove_dev(dev, class_intf)  => pm_runtime_get_sync/put_sync
>              => bus_remove_device => device_release_driver => pm_runtime_get_sync/put_sync
> 
> remove_dev might call pm_runtime_get_sync/put_sync.
> Then, generic device_release_driver also calls pm_runtime_get_sync/put_sync.
> Since device_del => device_pm_remove firstly, later _get_sync wouldn't really wake up the device. 
> 
> I git log -p to find the patch which moves the calling to device_pm_remove ahead.
> It's below patch:
> 
> commit  775b64d2b6ca37697de925f70799c710aab5849a
> Author: Rafael J. Wysocki <rjw@sisk.pl>
> Date:   Sat Jan 12 20:40:46 2008 +0100
> 
>      PM: Acquire device locks on suspend
> 
>      This patch reorganizes the way suspend and resume notifications are
>      sent to drivers.  The major changes are that now the PM core acquires
>      every device semaphore before calling the methods, and calls to
>      device_add() during suspends will fail, while calls to device_del()
>      during suspends will block.
> 
>      It also provides a way to safely remove a suspended device with the
>      help of the PM core, by using the device_pm_schedule_removal() callback
>      introduced specifically for this purpose, and updates two drivers (msr
>      and cpuid) that need to use it. 
> 
> 
> As device_pm_schedule_removal is deleted by another patch, we need also revert other parts of the patch,
> i.e. move the calling of device_pm_remove after the calling to bus_remove_device.
> 
> Signed-off-by: LongX Zhang <longx.zhang@intel.com>

Greg, do you see any potential problems with this patch?

Rafael


> ---
>  drivers/base/core.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index abea76c..150a415 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -1180,7 +1180,6 @@ void device_del(struct device *dev)
>         if (dev->bus)
>                 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
>                                              BUS_NOTIFY_DEL_DEVICE, dev);
> -       device_pm_remove(dev);
>         dpm_sysfs_remove(dev);
>         if (parent)
>                 klist_del(&dev->p->knode_parent);
> @@ -1205,6 +1204,7 @@ void device_del(struct device *dev)
>         device_remove_file(dev, &uevent_attr);
>         device_remove_attrs(dev);
>         bus_remove_device(dev);
> +       device_pm_remove(dev);
>         driver_deferred_probe_del(dev);
> 
>         /* Notify the platform of the removal, in case they
> 
-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] drivers-core: move the calling to device_pm_remove behind the calling to bus_remove_device
  2012-10-24 19:46 ` Rafael J. Wysocki
@ 2012-10-24 22:13   ` Greg Kroah-Hartman
  2012-10-24 22:33     ` Rafael J. Wysocki
  0 siblings, 1 reply; 6+ messages in thread
From: Greg Kroah-Hartman @ 2012-10-24 22:13 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: zhanglong, linux-kernel, yanmin_zhang, Alan Stern, linux-pm

On Wed, Oct 24, 2012 at 09:46:19PM +0200, Rafael J. Wysocki wrote:
> On Tuesday 16 of October 2012 23:28:08 zhanglong wrote:
> > We hit an hang issue when removing a mmc device on Medfield Android phone by sysfs interface.
> > 
> > device_pm_remove will call pm_runtime_remove which would disable
> > runtime PM of the device. After that pm_runtime_get* or
> > pm_runtime_put* will be ignored. So if we disable the runtime PM
> > before device really be removed, drivers' _remove callback may
> > access HW even pm_runtime_get* fails. That is bad.
> > 
> > Consider below call sequence when removing a device:
> > device_del => device_pm_remove
> >              => class_intf->remove_dev(dev, class_intf)  => pm_runtime_get_sync/put_sync
> >              => bus_remove_device => device_release_driver => pm_runtime_get_sync/put_sync
> > 
> > remove_dev might call pm_runtime_get_sync/put_sync.
> > Then, generic device_release_driver also calls pm_runtime_get_sync/put_sync.
> > Since device_del => device_pm_remove firstly, later _get_sync wouldn't really wake up the device. 
> > 
> > I git log -p to find the patch which moves the calling to device_pm_remove ahead.
> > It's below patch:
> > 
> > commit  775b64d2b6ca37697de925f70799c710aab5849a
> > Author: Rafael J. Wysocki <rjw@sisk.pl>
> > Date:   Sat Jan 12 20:40:46 2008 +0100
> > 
> >      PM: Acquire device locks on suspend
> > 
> >      This patch reorganizes the way suspend and resume notifications are
> >      sent to drivers.  The major changes are that now the PM core acquires
> >      every device semaphore before calling the methods, and calls to
> >      device_add() during suspends will fail, while calls to device_del()
> >      during suspends will block.
> > 
> >      It also provides a way to safely remove a suspended device with the
> >      help of the PM core, by using the device_pm_schedule_removal() callback
> >      introduced specifically for this purpose, and updates two drivers (msr
> >      and cpuid) that need to use it. 
> > 
> > 
> > As device_pm_schedule_removal is deleted by another patch, we need also revert other parts of the patch,
> > i.e. move the calling of device_pm_remove after the calling to bus_remove_device.
> > 
> > Signed-off-by: LongX Zhang <longx.zhang@intel.com>
> 
> Greg, do you see any potential problems with this patch?

No, no objection from me:

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] drivers-core: move the calling to device_pm_remove behind the calling to bus_remove_device
  2012-10-24 22:13   ` Greg Kroah-Hartman
@ 2012-10-24 22:33     ` Rafael J. Wysocki
  2012-10-25  0:20       ` Yanmin Zhang
  0 siblings, 1 reply; 6+ messages in thread
From: Rafael J. Wysocki @ 2012-10-24 22:33 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: zhanglong, linux-kernel, yanmin_zhang, Alan Stern, linux-pm,
	Yanmin Zhang

On Wednesday 24 of October 2012 15:13:27 Greg Kroah-Hartman wrote:
> On Wed, Oct 24, 2012 at 09:46:19PM +0200, Rafael J. Wysocki wrote:
> > On Tuesday 16 of October 2012 23:28:08 zhanglong wrote:
> > > We hit an hang issue when removing a mmc device on Medfield Android phone by sysfs interface.
> > > 
> > > device_pm_remove will call pm_runtime_remove which would disable
> > > runtime PM of the device. After that pm_runtime_get* or
> > > pm_runtime_put* will be ignored. So if we disable the runtime PM
> > > before device really be removed, drivers' _remove callback may
> > > access HW even pm_runtime_get* fails. That is bad.
> > > 
> > > Consider below call sequence when removing a device:
> > > device_del => device_pm_remove
> > >              => class_intf->remove_dev(dev, class_intf)  => pm_runtime_get_sync/put_sync
> > >              => bus_remove_device => device_release_driver => pm_runtime_get_sync/put_sync
> > > 
> > > remove_dev might call pm_runtime_get_sync/put_sync.
> > > Then, generic device_release_driver also calls pm_runtime_get_sync/put_sync.
> > > Since device_del => device_pm_remove firstly, later _get_sync wouldn't really wake up the device. 
> > > 
> > > I git log -p to find the patch which moves the calling to device_pm_remove ahead.
> > > It's below patch:
> > > 
> > > commit  775b64d2b6ca37697de925f70799c710aab5849a
> > > Author: Rafael J. Wysocki <rjw@sisk.pl>
> > > Date:   Sat Jan 12 20:40:46 2008 +0100
> > > 
> > >      PM: Acquire device locks on suspend
> > > 
> > >      This patch reorganizes the way suspend and resume notifications are
> > >      sent to drivers.  The major changes are that now the PM core acquires
> > >      every device semaphore before calling the methods, and calls to
> > >      device_add() during suspends will fail, while calls to device_del()
> > >      during suspends will block.
> > > 
> > >      It also provides a way to safely remove a suspended device with the
> > >      help of the PM core, by using the device_pm_schedule_removal() callback
> > >      introduced specifically for this purpose, and updates two drivers (msr
> > >      and cpuid) that need to use it. 
> > > 
> > > 
> > > As device_pm_schedule_removal is deleted by another patch, we need also revert other parts of the patch,
> > > i.e. move the calling of device_pm_remove after the calling to bus_remove_device.
> > > 
> > > Signed-off-by: LongX Zhang <longx.zhang@intel.com>
> > 
> > Greg, do you see any potential problems with this patch?
> 
> No, no objection from me:
> 
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

OK, thanks!

Applied to linux-pm.git/linux-next as v3.8 material.

Thanks,
Rafael


-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] drivers-core: move the calling to device_pm_remove behind the calling to bus_remove_device
  2012-10-24 22:33     ` Rafael J. Wysocki
@ 2012-10-25  0:20       ` Yanmin Zhang
  0 siblings, 0 replies; 6+ messages in thread
From: Yanmin Zhang @ 2012-10-25  0:20 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Greg Kroah-Hartman, zhanglong, linux-kernel, Alan Stern, linux-pm

On Thu, 2012-10-25 at 00:33 +0200, Rafael J. Wysocki wrote:
> On Wednesday 24 of October 2012 15:13:27 Greg Kroah-Hartman wrote:
> > On Wed, Oct 24, 2012 at 09:46:19PM +0200, Rafael J. Wysocki wrote:
> > > On Tuesday 16 of October 2012 23:28:08 zhanglong wrote:
> > > > We hit an hang issue when removing a mmc device on Medfield Android phone by sysfs interface.
> > > > 
> > > > device_pm_remove will call pm_runtime_remove which would disable
> > > > runtime PM of the device. After that pm_runtime_get* or
> > > > pm_runtime_put* will be ignored. So if we disable the runtime PM
> > > > before device really be removed, drivers' _remove callback may
> > > > access HW even pm_runtime_get* fails. That is bad.
> > > > 
> > > > Consider below call sequence when removing a device:
> > > > device_del => device_pm_remove
> > > >              => class_intf->remove_dev(dev, class_intf)  => pm_runtime_get_sync/put_sync
> > > >              => bus_remove_device => device_release_driver => pm_runtime_get_sync/put_sync
> > > > 
> > > > remove_dev might call pm_runtime_get_sync/put_sync.
> > > > Then, generic device_release_driver also calls pm_runtime_get_sync/put_sync.
> > > > Since device_del => device_pm_remove firstly, later _get_sync wouldn't really wake up the device. 
> > > > 
> > > > I git log -p to find the patch which moves the calling to device_pm_remove ahead.
> > > > It's below patch:
> > > > 
> > > > commit  775b64d2b6ca37697de925f70799c710aab5849a
> > > > Author: Rafael J. Wysocki <rjw@sisk.pl>
> > > > Date:   Sat Jan 12 20:40:46 2008 +0100
> > > > 
> > > >      PM: Acquire device locks on suspend
> > > > 
> > > >      This patch reorganizes the way suspend and resume notifications are
> > > >      sent to drivers.  The major changes are that now the PM core acquires
> > > >      every device semaphore before calling the methods, and calls to
> > > >      device_add() during suspends will fail, while calls to device_del()
> > > >      during suspends will block.
> > > > 
> > > >      It also provides a way to safely remove a suspended device with the
> > > >      help of the PM core, by using the device_pm_schedule_removal() callback
> > > >      introduced specifically for this purpose, and updates two drivers (msr
> > > >      and cpuid) that need to use it. 
> > > > 
> > > > 
> > > > As device_pm_schedule_removal is deleted by another patch, we need also revert other parts of the patch,
> > > > i.e. move the calling of device_pm_remove after the calling to bus_remove_device.
> > > > 
> > > > Signed-off-by: LongX Zhang <longx.zhang@intel.com>
> > > 
> > > Greg, do you see any potential problems with this patch?
> > 
> > No, no objection from me:
> > 
> > Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 
> OK, thanks!
> 
> Applied to linux-pm.git/linux-next as v3.8 material.
Rafael,

As usual, I really appreciate it!

Yanmin



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-10-25  0:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-16 15:28 [PATCH v2] drivers-core: move the calling to device_pm_remove behind the calling to bus_remove_device zhanglong
2012-10-22  1:01 ` Yanmin Zhang
2012-10-24 19:46 ` Rafael J. Wysocki
2012-10-24 22:13   ` Greg Kroah-Hartman
2012-10-24 22:33     ` Rafael J. Wysocki
2012-10-25  0:20       ` Yanmin Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).