Forcible removal of modules
Hi. Here's my question, with a little introduction.
Sometimes modules need to be reloaded in order to cause some sort of reinitialization (of the driver or of the hardware) to occur. Sometimes this has to be done every time a machine is suspended. E.g., some sound driver modules need to be reloaded after an APM suspend because the sound chip forgets its configuration during the suspend. Obviously, one would like to be able to automate the process of unloading and reloading the modules by putting some commands in the apmd_proxy script. Sometimes, though, "rmmod themodulename" fails because some process is holding open a device handled by the device driver module in question.
The solution to this is to do a "fuser" on the device nodes associated with the device driver and kill all the processes reported to be using those nodes. However, this is easier said than done because of one
problem: while you are killing a batch of processes that are using the device node, other processes may be opening that device node! What is needed is a way of preventing processes from opening a given device node.
Now, one way of doing this is to change the device permissions on the node to 000. Unfortunately this does not work well with devfs under the circumstances we have in mind here: because once the permissions are changed the device driver is removed; then devfs stores "000" as the permissions that are to be used for that device node when it is created again.
My question is: Is there some better way of blocking all open() calls to a particular device driver while processes using it are being killed off?
Thomas Hood
_______________________________________________________
Send a cool gift with your E-Card
http://www.bluemountain.com/giftcenter/
Quoted 3 lines · Thomas Hood
My question is: Is there some better way of blocking all
open()calls to a particular device driver while processes using it are being killed off?
Not yet. There have been some off list discussions about redoing the module load/unload process to avoid races, as part of that we will get forced module unregister followed by unload when the use count goes to zero. Probably 2.5 changes.
Quoted 3 lines · Thomas Hood
Sometimes modules need to be reloaded in order
to cause some sort of reinitialization (of the
driver or of the hardware) to occur.
Why not set up the device driver to handle PM events itself. See Documentation/pm.txt under Driver Interface.
I have a race free version of pm_send_all if you want it.
[...]
Signature · 1 line
http://www.penguinpowered.com/~vii
Quoted 2 lines · John Fremlin
Why not set up the device driver to handle PM events itself. See
Documentation/pm.txtunder Driver Interface.
For PCI drivers, you implement the ::suspend and ::remove hooks.
Quoted 1 line
I have a race free version of
pm_send_allif you want it.
Is this the same thing that is in 2.4.3-pre3?
Signature · 3 lines
Jeff Garzik | "You see, in this world there's two kinds of Building 1024 | people, my friend: Those with loaded guns MandrakeSoft | and those who dig. You dig." --Blondie
Racing power management
In reply to Thomas HoodQuoted 9 lines · Jeff Garzik
Quoted 2 lines · John Fremlin
Why not set up the device driver to handle PM events itself. See
Documentation/pm.txtunder Driver Interface.For PCI drivers, you implement the ::suspend and ::remove hooks.
Quoted 1 line
I have a race free version of
pm_send_allif you want it.Is this the same thing that is in 2.4.3-pre3?
Aarrgh. Looks like Alan Cox got his version in kernel first. (I did write mine before.)
If I am not mistaken there is one (hypothetical) race still remaining in Alan's version. Last time I checked the only code doing pm_send_all was in the i386 APM driver (and so of course there is no chance of any race at all even with the old version, if I understand correctly).
But suppose there were another pm_send_all caller. APM would decide to user suspend and call pm_send_all asking for a SUSPEND to check it was allowed to. While this is happening some clueless loser decides to pm_send_all RESUME for whatever reason. This loser has to wait until the APM pm_send_all finishes, but hypothetically and if I am not mistaken, his pm_send_all RESUME could get in just after the APM pm_send_all finished and just before APM made the physical BIOS call to suspend the machine. This would screw stuff up of course.
You may say, this is rather improbable if not impossible, but it does suggest that it would be a good idea to have locking wrapping pm_send_all and the hardware machine suspend request. Cue: John's pmpolicy patch.
Unfortunately, my patch adds another thing as well: /sbin/powermanager so it got (is getting) trampled on by a lot of people who didn't like that idea. If anybody wants the race free PM by itself, I can factor out that bit.
Signature · 1 line
http://www.penguinpowered.com/~vii
Quoted 3 lines
For PCI drivers, you implement the ::suspend and ::remove hooks.
Quoted 1 line
I have a race free version of
pm_send_allif you want it.Is this the same thing that is in 2.4.3-pre3?
Mine is race free for the basics, his is a far far more elegant solution to the whole problem space. It might be 2.5 stuff but its definitely a good idea