loading firmware while usermodehelper disabled.
Quoted 6 lines · Linus Torvalds
Quoted 4 lines · Dave Jones
We're getting a bunch of reports against Fedora 16 (still using 3.1) which look like some drivers are trying to load firmware on resume from suspend, while usermodehelper is disabled.
Quoted 6 lines
Ok, buggy drivers. You *must*not* load firmware in your resume path, since there is no actual guarantee that any particular device will be resumed after the disk that contains the firmware images.
So it's very simple: drivers that load firmware at resume time are buggy. No ifs, buts, or maybes about it.
Or are they?
You see, PCMCIA cards [don't know about the pccard express stuff] have to deal with a notable exception from this rule since:
pcmcia: improve check for same card in slot after resume "88b060d6c03fcb9e4d2018b4349954c4242a5c7f"
This patch changed the way how suspend/resume is handled. On resume, the pcmcia subsystem obviously does not know if the card has been removed and reinserted, therefore it does not call the resume method of the driver but instead goes for "probe" and things go south from there.
[And now for the $64 question, what happens to USB drivers that are managing devices which are connected to pcmcia usb host cards?]
Signature · 2 lines
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie! Jetzt informieren: http://www.gmx.net/de/go/freephone
Quoted 5 lines · On Sat, Dec 31, 2011 at 7:01 AM, <[email protected]> wrote:
Quoted 3 lines
So it's very simple: drivers that load firmware at resume time are buggy. No ifs, buts, or maybes about it.
Or are they?
Yes they are.
Quoted 7 lines
You see, PCMCIA cards [don't know about the pccard express stuff] have to deal with a notable exception from this rule since:
pcmcia: improve check for same card in slot after resume "
88b060d6c03fcb9e4d2018b4349954c4242a5c7f"This patch changed the way how suspend/resume is handled.
Yes, that's problematic. As is the USB thing making resume a probe event too.
But it doesn't change the fact that if a driver needs to load the firmware at such an event, then the driver is buggy. The reason really is very very simple: there is no guarantee at all that the backing store for the firmware has been resumed first!
It really is that simple.
And as mentioned, I do agree that the underlying *cause* for all these bugs is that our firmware loading helper routines are totally full of sh*t. The whole "request_firmware()" logic makes it very very easy for drivers to get this wrong, and then some bus interfaces (pcmcia and usb) make it almost impossible for drivers to do it right by turning "suspend/resume" into "detach/probe".
But what the driver *should* be doing is to load the firmware at device open time (NOT at "driver load time" - because that can and does happen too early too, for the case of built-in drivers!) and simply keep the firmware around in the case of a suspend/resume event, so that it doesn't have to re-load it off a disk (or network, or whatever) that hasn't been resumed yet!
And this really does solve all problems.
There are drivers that do this right, so it's not impossible. For a network driver, for example, you should load the firmware into memory when the device is opened the first time, and you should unload it only when the device is downed. If you follow those fairly simple rules, you're all good - at a resume event you either do nothing at all about the firmware (network device not up) or you have the firmware in memory and can just re-load it onto the card.
For an example of this, look at
drivers/net/ethernet/realtek/r8169.c
and its explicit caching of firmware (see "rtl_request_firmware()" and the whole "rtl_fw" handling), which actually makes it fairly easy for the rest of the driver to do things right.
However, I really do think that it's
(a) very error-prone
(b) complexity all over
for drivers to have to know to do this on their own. So we have a *few* drivers that do this correctly (after having done it wrong, and then fixing it), but most drivers don't. And I really think that the request_firmware() interface is the problem: the firmware layer should be doing this kind of caching for the drivers, so that drivers wouldn't *have* to.
For example, if somebody builds a kernel that doesn't support suspend or hibernation, then the caching is pointless, so a really *good* caching model would take that into account and just say "I won't waste memory on that case". But duplicating that kind of logic for every driver that needs firmware is just totally crazy. But if we had a good interface to request_firmware(), we might be able to do that kind of thing automatically.
Linus
Quoted 6 lines · Linus Torvalds
But what the driver *should* be doing is to load the firmware at device open time (NOT at "driver load time" - because that can and does happen too early too, for the case of built-in drivers!) and simply keep the firmware around in the case of a suspend/resume event, so that it doesn't have to re-load it off a disk (or network, or whatever) that hasn't been resumed yet!
That doesn't work for the isight firmware loader - there's nothing for userspace to open until the device has had the firmware loaded, at which point it detaches and reattaches as a UVC device. The code could be merged into the UVC driver and a fake v4l device exposed, but even then you'd still need to deal with the underlying usb_device suddenly changing under you.
So for this specific case, I'd like to track down why the behaviour has changed - if the device was previously maintaining state over suspend and now isn't then that's something that's broken, but if it's just that some ordering has changed and now it's losing a race, I'll need to fix it in the driver. One option would be to do away with the kernelspace loader entirely and push it out to a udev helper, or alternatively just have the driver stash the firmware all the time.
Signature · 1 line
Matthew Garrett | [email protected]
Quoted 9 lines · Matthew Garrett
Quoted 6 lines · Linus Torvalds
But what the driver *should* be doing is to load the firmware at device open time (NOT at "driver load time" - because that can and does happen too early too, for the case of built-in drivers!) and simply keep the firmware around in the case of a suspend/resume event, so that it doesn't have to re-load it off a disk (or network, or whatever) that hasn't been resumed yet!
Quoted 6 lines
That doesn't work for the isight firmware loader - there's nothing for userspace to open until the device has had the firmware loaded, at which point it detaches and reattaches as a UVC device. The code could be merged into the UVC driver and a fake v4l device exposed, but even then you'd still need to deal with the underlying
usb_devicesuddenly changing under you.
Well, what you *could* do is to simply say: this driver has to be a module, and cannot be built-in. Or, if built-in, the firmware has to be built-in too (but there are probably licensing issues with that).
At that point, you can load the firmware when you load the isight driver, since hopefully by then you have a real filesystem (not just initrd or something - although you could obviously put the firmware in the initrd image too).
And then, you just keep the firmware in memory as long as the module is loaded. It's not as good as loading at open time, but at least for the suspend/resume case it's better than trying to load it at resume time when it fundamentally cannot work.
Quoted 2 lines
So for this specific case, I'd like to track down why the behaviour has changed
That driver isn't all that recent, it may be that what changed is that you just used to rely on the disk being woken up before the isight device was, and things just magically happened to work.
We explicitly disallowed the "magically happened to work" case because it was so often not true, and when it wasn't true, it resulted in 60-second timeouts (or whatever the "failed to load" timeout was) and non-working devices. So the warning and the failure is actually "new" (well, by now it's been a year or so), to make developers who write drivers *see* the failure instead of having a "it works on my particular hardware and filesystem layout" model.
Linus