Skip to contentSkip to conversation

drivers-core: move the calling to device_pm_remove behind the calling to bus_remove_device

PATCH Applied zhanglong 4 participants 6 messages Oct 16, 2012 – Oct 25, 2012 Driver core

lore
Share & tools
lore

zhanglong

author
#0 lore raw

PATCH v2 1/1 drivers-core: move the calling to device_pm_remove behind the calling to bus_remove_device

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 <[email protected]>
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.

---
 drivers/base/core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/core.c +1 -1
index abea76c..150a415 100644
@@ -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
Signature · 1 line
1.7.10
#1 lore raw
Quoted 38 lines · zhanglong

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 <[email protected]>
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.

Quoted 4 lines

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.

Rafael,

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

Thanks,
Yanmin

Quoted 24 lines
---
 drivers/base/core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/core.c +1 -1
index abea76c..150a415 100644
@@ -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
#2 lore raw
In reply to zhanglong
Quoted 38 lines · 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 <[email protected]>
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.

Quoted 4 lines

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.

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

Rafael

Quoted 25 lines
---
 drivers/base/core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/core.c +1 -1
index abea76c..150a415 100644
@@ -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
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
maintainer Acked-by
#3 lore raw
Quoted 39 lines · Rafael J. Wysocki
Quoted 38 lines · 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 <[email protected]>
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.

Quoted 6 lines
Quoted 4 lines

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.

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

No, no objection from me:

#4 lore raw
Quoted 43 lines · On Wednesday 24 of October 2012 15:13:27 Greg Kroah-Hartman wrote:
Quoted 42 lines · Rafael J. Wysocki
Quoted 41 lines · 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 <[email protected]>
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.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

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

No, no objection from me:

OK, thanks!

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

Thanks,
Rafael

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#5 lore raw
Quoted 48 lines · Rafael J. Wysocki
Quoted 47 lines · On Wednesday 24 of October 2012 15:13:27 Greg Kroah-Hartman wrote:
Quoted 45 lines · Rafael J. Wysocki
Quoted 38 lines · 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 <[email protected]>
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.

Quoted 4 lines

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.

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

Quoted 7 lines
Quoted 3 lines

No, no objection from me:

OK, thanks!

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

Rafael,

As usual, I really appreciate it!

Yanmin