Skip to contentSkip to conversation

USB: fix Scheduling while atomic warning when resuming.

PATCH Jeff Garzik 3 participants 9 messages Dec 22, 2004 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 10 lines · Linux Kernel Mailing List

ChangeSet 1.2215, 2004/12/21 16:25:03-08:00, [email protected]

[PATCH] USB: fix Scheduling while atomic warning when resuming.

This fixes a warning when resuming the USB EHCI host controller driver.

diff -Nru a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c

drivers/usb/host/ehci-hub.c line 127

Quoted 7 lines
drivers/usb/host/ehci-hub.c +1 -1
@@ -122,7 +122,7 @@
 		writel (temp, &ehci->regs->port_status [i]);
 	}
 	i = HCS_N_PORTS (ehci->hcs_params);
-	msleep (20);
+	mdelay (20);
 	while (i--) {
 		temp = readl (&ehci->regs->port_status [i]);

This is more than a little bit silly.

The entire resume function holds spin_lock_irq() for far longer than a timer tick.

If we are going for a minimalist -rc patch, why not drop the lock, sleep, then reacquire the lock?

This strikes me as a bad change, make in haste for -rc, that will get quickly forgotten (and left as-is) once 2.6.10 is released.

Jeff

#2 lore raw
Quoted 2 lines · Jeff Garzik

If we are going for a minimalist -rc patch, why not drop the lock, sleep, then reacquire the lock?

If that lock were dropped, what would prevent other tasks from touching the hardware while it's sending RESUME signaling down the bus, and thereby mucking up the resume sequence?

That 20+ msec is a protocol timer. Normally we'd want khubd to handle such things, and then resume all the child devices, but that's not so readily done for root hubs or during calls from the pm core code.

- Dave

#3 lore raw
Quoted 8 lines · David Brownell
Quoted 1 line · Jeff Garzik

If we are going for a minimalist -rc patch, why not drop the lock, sleep, then reacquire the lock?

If that lock were dropped, what would prevent other tasks from touching the hardware while it's sending RESUME signaling down the bus, and thereby mucking up the resume sequence?

Precisely what other tasks are active for this hardware, during resume?

Jeff

#4 lore raw
Quoted 5 lines · Jeff Garzik
Quoted 3 lines

If that lock were dropped, what would prevent other tasks from touching the hardware while it's sending RESUME signaling down the bus, and thereby mucking up the resume sequence?

Precisely what other tasks are active for this hardware, during resume?

There's no guarantee that suspend() and resume() methods are only called during system-wide suspend and resume.

And likewise, if there were no other tasks, why should you even be concerned about spinning vs sleeping?

- Dave

#5 lore raw
Quoted 11 lines · David Brownell
Quoted 5 lines · Jeff Garzik
Quoted 3 lines

If that lock were dropped, what would prevent other tasks from touching the hardware while it's sending RESUME signaling down the bus, and thereby mucking up the resume sequence?

Precisely what other tasks are active for this hardware, during resume?

There's no guarantee that suspend() and resume() methods are only called during system-wide suspend and resume.

That is precisely the reason why I am concerned. If it was only during system-wide resume, the impact of the very-long mdelay() would be more difficult to notice.

You also ignored my question :)

If the PCI layer is calling the resume method for a PCI device while simultaneously calling the suspend method, that's a PCI layer problem. Similarly, If the USB layer is calling into your driver while you are resuming, something is broken and it ain't your locking.

Jeff

#6 lore raw
Quoted 5 lines

If the PCI layer is calling the resume method for a PCI device while simultaneously calling the suspend method, that's a PCI layer problem. Similarly, If the USB layer is calling into your driver while you are resuming, something is broken and it ain't your locking.

Actually, the later isn't broken, something may well call into the higher level USB drivers while resuming, but indeed, those shouldn't send any URB down the stack when the bus is suspended, and the EHCI driver should drop incoming URBs as well until fully resumed.

I think the lock here is only needed to protect the HCD state transitions David, no ? All we need is make sure that we don't let things get queued (or call into EHCI code path that will end up touch the HW) while suspended.

Ben.

#7 lore raw
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 3 lines

Similarly, If the USB layer is calling into your driver while you are resuming, something is broken and it ain't your locking.

Actually, the later isn't broken, something may well call into the higher level USB drivers while resuming, but indeed, those shouldn't send any URB down the stack when the bus is suspended, and the EHCI driver should drop incoming URBs as well until fully resumed.

Well, not "drop" like the network layer might, but report an error; if the bus is suspended, so are all its devices and drivers. When a USB device is suspended, all its endpoint queues should be empty. (And devices can be suspended without the bus being suspended...)

Such checks should be part of usbcore, not just one HCD, but we're still working towards better interfaces there. It's excessively painful to write HCDs.

Quoted 2 lines

I think the lock here is only needed to protect the HCD state transitions David, no ?

State transitions and access to hardware. There are a few other code paths that can trigger state transitions then, like rmmod. And Alan's pointed out that we'll be wanting autoresume mechanisms, so that parent hubs implicitly wake up as needed.

One thing we don't have right now is a per-HCD spinlock that usbcore has access to. Periodically I wonder whether such a lock might help sort some of these issues out.

Quoted 3 lines

All we need is make sure that we don't let
things get queued (or call into EHCI code path that will end up touch the HW) while suspended.

That lock protects all HCD code paths that touch HW, As well as the state transitions. I don't recall that any other state transitions require such a long delay, except maybe initialization (which happens before the upper levels of the USB stack see the controller).

- Dave

#8 lore raw
Quoted 10 lines · David Brownell
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 3 lines

Similarly, If the USB layer is calling into your driver while you are resuming, something is broken and it ain't your locking.

Actually, the later isn't broken, something may well call into the higher level USB drivers while resuming, but indeed, those shouldn't send any URB down the stack when the bus is suspended, and the EHCI driver should drop incoming URBs as well until fully resumed.

Quoted 4 lines

Well, not "drop" like the network layer might, but report an error; if the bus is suspended, so are all its devices and drivers. When a USB device is suspended, all its endpoint queues should be empty. (And devices can be suspended without the bus being suspended...)

Oh sure, yes, "drop" wasn't the best choice of word, but error is what I meant. Sorry.

Quoted 3 lines

Such checks should be part of usbcore, not just one HCD, but we're still working towards better interfaces there. It's excessively painful to write HCDs.

Yes :)

Quoted 25 lines
Quoted 3 lines

I think the lock here is only needed to protect the HCD state transitions David, no ?

State transitions and access to hardware. There are a few other code paths that can trigger state transitions then, like rmmod. And Alan's pointed out that we'll be wanting autoresume mechanisms, so that parent hubs implicitly wake up as needed.

One thing we don't have right now is a per-HCD spinlock that usbcore has access to. Periodically I wonder whether such a lock might help sort some of these issues out.

Quoted 3 lines

All we need is make sure that we don't let
things get queued (or call into EHCI code path that will end up touch the HW) while suspended.

That lock protects all HCD code paths that touch HW, As well as the state transitions. I don't recall that any other state transitions require such a long delay, except maybe initialization (which happens before the upper levels of the USB stack see the controller).

- Dave

Signature · 1 line
Benjamin Herrenschmidt <[email protected]>
#9 lore raw
In reply to Jeff Garzik
Quoted 8 lines · Jeff Garzik
Quoted 2 lines

There's no guarantee that suspend() and resume() methods are only called during system-wide suspend and resume.

That is precisely the reason why I am concerned. If it was only during system-wide resume, the impact of the very-long mdelay() would be more difficult to notice.

You also ignored my question :)

I didn't ignore it; I answered it with a question! If you had answered mine, you'd have had the answer to yours ... :)

One way another task can be active during resume is with sysfs:
"echo -n 0 > /sys/devices/.../power/state", after similar selective suspend of the device. That's uncommon for now, primarily useful for unit-testing driver suspend/resume. Plus, its design is currently borked; the pm core code doesn't bother to suspend children of the device first. But I do expect that selective suspend/resume should work in Linux; it's not reasonable to design the pm framework otherwise.

But in any case, while it'd be difficult to notice that mdelay() in current systems (since selective suspend/resume is still rare) it'd clearly be wrong to assume that resume() methods don't need to have mutual exclusion during their critical sections.

Quoted 2 lines

If the PCI layer is calling the resume method for a PCI device while simultaneously calling the suspend method, that's a PCI layer problem.

I never suggested such a scenario. Though that would be another case where such critical sections matter, like the remove() method.

Quoted 2 lines

Similarly, If the USB layer is calling into your driver while you are resuming, something is broken and it ain't your locking.

Which gets back to the question I asked you: if not the lock in question, what's ensuring that everything behaves right?

As I said originally, I don't much like long udelays, but at least it's clearly correct in terms of mutual exclusion. You've not shown any solution that's equivalently correct.

- Dave