Skip to contentSkip to conversation

Fix device_move() vs. dpm_list issues.

RFC PATCH In review Cornelia Huck 3 participants 7 messages Mar 3, 2009 – Mar 4, 2009

lore
Share & tools
lore
#0 lore raw

cover Fix device_move() vs. dpm_list issues.

Hi,

in thread [1], we discussed the issue of device_move() causing a reordering of devices without adapting the ancestral order in dpm_list. If a device is moved to a new parent that was registered after the device itself, it would still be after its new parent in dpm_list, thus causing the parent to be suspended before its child.

This patchset attempts to remedy this situation by introducing an interface for a driver to manipulate dpm_list with the dpm_list_mtx held. (device_move() does not have enough information to do this manipulation itself.) The calling sequence for a driver would be:

- lock the dpm_list
- call device_move()
- if device_move() succeeded, fix up dpm_list
- unlock the dpm_list

Following are three patches:

Patch 1 - Introduce the dpm_list manipulation interfaces. I'm not sure whether the BUG_ON()s should be WARN_ON()s instead.

Patch 2 - Make bluetooth use the new interfaces. I didn't introduce proper handling for device_move() failures. Very lightly tested (did not break my setup :)), needs proper review.

Patch 3 - Make s390 use the new interfaces. I'm more confident this patch is correct, but it is hard to test power management related stuff without power management support (no regressions were introduced for my attach/detach testcases though).

[1] https://lists.linux-foundation.org/pipermail/linux-pm/2007-July/014428.html

#1 lore raw

2009/3/3 Cornelia Huck <[email protected]>:

Quoted 13 lines

Hi,

in thread [1], we discussed the issue of device_move() causing a reordering of devices without adapting the ancestral order in dpm_list. If a device is moved to a new parent that was registered after the device itself, it would still be after its new parent in dpm_list, thus causing the parent to be suspended before its child.

This patchset attempts to remedy this situation by introducing an interface for a driver to manipulate dpm_list with the dpm_list_mtx held. (device_move() does not have enough information to do this manipulation itself.) The calling sequence for a driver would be:

Quoted 4 lines

- lock the dpm_list
- call device_move()
- if device_move() succeeded, fix up dpm_list
- unlock the dpm_list

IMHO, It is better to fix up dpm_list inside device_move() , like device_add(), which may let s390, bluetooth or other possible users more happy with device_remove().

Thanks

Quoted 22 lines

Following are three patches:

Patch 1 - Introduce the dpm_list manipulation interfaces. I'm not sure whether the BUG_ON()s should be WARN_ON()s instead.

Patch 2 - Make bluetooth use the new interfaces. I didn't introduce proper handling for device_move() failures. Very lightly tested (did not break my setup :)), needs proper review.

Patch 3 - Make s390 use the new interfaces. I'm more confident this patch is correct, but it is hard to test power management related stuff without power management support (no regressions were introduced for my attach/detach testcases though).

[1] https://lists.linux-foundation.org/pipermail/linux-pm/2007-July/014428.html
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm

Signature · 1 line
Lei Ming
#2 lore raw
Quoted 14 lines · Ming Lei

2009/3/3 Cornelia Huck <[email protected]>:

Quoted 13 lines

Hi,

in thread [1], we discussed the issue of device_move() causing a reordering of devices without adapting the ancestral order in dpm_list. If a device is moved to a new parent that was registered after the device itself, it would still be after its new parent in dpm_list, thus causing the parent to be suspended before its child.

This patchset attempts to remedy this situation by introducing an interface for a driver to manipulate dpm_list with the dpm_list_mtx held. (device_move() does not have enough information to do this manipulation itself.) The calling sequence for a driver would be:

Quoted 8 lines
Quoted 4 lines

- lock the dpm_list
- call device_move()
- if device_move() succeeded, fix up dpm_list
- unlock the dpm_list

IMHO, It is better to fix up dpm_list inside device_move() , like device_add(), which may let s390, bluetooth or other possible users more happy with device_remove().

I agree; it would be cleaner if device_move() could fix up dpm_list directly. If it doesn't have enough information to do so then change the interface so that it does. That should be pretty easy since there are only a handful of callers.

Alan Stern

#3 lore raw
Quoted 16 lines · Alan Stern
Quoted 14 lines · Ming Lei

2009/3/3 Cornelia Huck <[email protected]>:

Quoted 13 lines

Hi,

in thread [1], we discussed the issue of device_move() causing a reordering of devices without adapting the ancestral order in dpm_list. If a device is moved to a new parent that was registered after the device itself, it would still be after its new parent in dpm_list, thus causing the parent to be suspended before its child.

This patchset attempts to remedy this situation by introducing an interface for a driver to manipulate dpm_list with the dpm_list_mtx held. (device_move() does not have enough information to do this manipulation itself.) The calling sequence for a driver would be:

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

- lock the dpm_list
- call device_move()
- if device_move() succeeded, fix up dpm_list
- unlock the dpm_list

IMHO, It is better to fix up dpm_list inside device_move() , like device_add(), which may let s390, bluetooth or other possible users more happy with device_remove().

Maybe I'm a bit dense today, but I don't understand the problem with device_remove()?

Quoted 5 lines

I agree; it would be cleaner if device_move() could fix up dpm_list directly. If it doesn't have enough information to do so then change the interface so that it does. That should be pretty easy since there are only a handful of callers.

The only really obvious one is 'move to NULL' -> 'move to end of dpm_list'.
AFAICS, for that device_move() would need the following parameters:
- device to be moved
- new parent
- which device to move in dpm_list (device, parent, or none) and then still the moves I do in the s390 code don't seem obvious for the driver core to get.

Given that the callers still need to specify what to do, I find it much easier (and the resulting code much more understandable) if the callers fix up dpm_list...

#4 lore raw
Quoted 7 lines · Cornelia Huck
Quoted 4 lines · Alan Stern

I agree; it would be cleaner if device_move() could fix up dpm_list directly. If it doesn't have enough information to do so then change the interface so that it does. That should be pretty easy since there are only a handful of callers.

Quoted 6 lines

The only really obvious one is 'move to NULL' -> 'move to end of dpm_list'.
AFAICS, for that device_move() would need the following parameters:
- device to be moved
- new parent

Those two are, of course, the parameters it already has.

Quoted 3 lines

- which device to move in dpm_list (device, parent, or none) and then still the moves I do in the s390 code don't seem obvious for the driver core to get.

After looking through your s390 patch more carefully, I get a mixed-up feeling -- as though you think dpm_list goes in reverse order. It doesn't; devices are added in order of registration, so parents come _before_ children. Thus, this makes no sense:

ret = device_move(&cdev->dev, &sch->dev);
...

+ /*
+ * We already reorder dpm_list here since we may not hold
+ * the dpm_list mutex when deregistering other_sch.
+ * Order of devices will be correct after moving sch since
+ * sch's parent (the css) is guaranteed to be after cdev
+ * already.
+ */
+ device_pm_move_after(&sch->dev, &cdev->dev);

The existing code makes cdev a child of sch, so when the dust clears we want sch to come _before_ cdev in dpm_list. But the new code does the opposite; it puts sch after cdev.

Anyway, the moves you add in the s390 and Bluetooth patches all fall into one of these three patterns:

	Move the device to just after its new parent;

	Move the parent to just before the device;

	Move the device to the end.

Therefore all you need to do is add a third argument to device_move(); it can be a enumeration taking on one of the values

DPM_ORDER_DEV_AFTER_PARENT,
DPM_ORDER_PARENT_BEFORE_DEV,
DPM_ORDER_DEV_LAST.

(Come to think of it, I don't understand the reason for moving the device to the end of dpm_list. What point is there in doing this?)

Quoted 3 lines

Given that the callers still need to specify what to do, I find it much easier (and the resulting code much more understandable) if the callers fix up dpm_list...

I disagree. Doing it the way described above would add less than 10 lines of code to device_move() and one argument to each caller, whereas your changes are a lot more extensive.

Alan Stern

#5 lore raw
Quoted 2 lines · Alan Stern

After looking through your s390 patch more carefully, I get a mixed-up feeling -- as though you think dpm_list goes in reverse order.

list_add_tail confused me...

Quoted 6 lines

Therefore all you need to do is add a third argument to device_move(); it can be a enumeration taking on one of the values

DPM_ORDER_DEV_AFTER_PARENT,
DPM_ORDER_PARENT_BEFORE_DEV,
DPM_ORDER_DEV_LAST.

and DPM_ORDER_DO_NOTHING.

Quoted 3 lines

(Come to think of it, I don't understand the reason for moving the device to the end of dpm_list. What point is there in doing this?)

Completeness. It is not strictly needed.

Quoted 9 lines
Quoted 5 lines

Given that the callers still need to specify what to do, I find it much easier (and the resulting code much more understandable) if the callers fix up dpm_list...

I disagree. Doing it the way described above would add less than 10 lines of code to device_move() and one argument to each caller, whereas your changes are a lot more extensive.

I'm still not quite convinced, but I'll give it a try.

#6 lore raw
In reply to Cornelia Huck

2009/3/3 Cornelia Huck <[email protected]>:

Quoted 24 lines
Quoted 21 lines · Alan Stern
Quoted 19 lines · Ming Lei

2009/3/3 Cornelia Huck <[email protected]>:

Quoted 17 lines

Hi,

in thread [1], we discussed the issue of device_move() causing a reordering of devices without adapting the ancestral order in dpm_list. If a device is moved to a new parent that was registered after the device itself, it would still be after its new parent in dpm_list, thus causing the parent to be suspended before its child.

This patchset attempts to remedy this situation by introducing an interface for a driver to manipulate dpm_list with the dpm_list_mtx held. (device_move() does not have enough information to do this manipulation itself.) The calling sequence for a driver would be:

- lock the dpm_list
- call device_move()
- if device_move() succeeded, fix up dpm_list
- unlock the dpm_list

Quoted 6 lines
Quoted 3 lines
Quoted 3 lines

IMHO, It is better to fix up dpm_list inside device_move() , like device_add(), which may let s390, bluetooth or other possible users more happy with device_remove().

Maybe I'm a bit dense today, but I don't understand the problem with device_remove()?

My fault, It should be device_move(), :-)
Thanks!

Quoted 21 lines
Quoted 6 lines

I agree; it would be cleaner if device_move() could fix up dpm_list directly.  If it doesn't have enough information to do so then change the interface so that it does.  That should be pretty easy since there are only a handful of callers.

The only really obvious one is 'move to NULL' -> 'move to end of dpm_list'.
AFAICS, for that device_move() would need the following parameters:
- device to be moved
- new parent
- which device to move in dpm_list (device, parent, or none) and then still the moves I do in the s390 code don't seem obvious for the driver core to get.

Given that the callers still need to specify what to do, I find it much easier (and the resulting code much more understandable) if the callers fix up dpm_list...

Signature · 1 line
Lei Ming