try_module_get and friends
Yo,
Ok...so I might just be missing something and you guys will set me right if that is indeed the case, but...
What's protecting the -RT kernel from assumptions about atomicity of module symbol references? Specifically, the kernel doesn't normally need to protect against inter-module symbol references to EXPORT_SYMBOL(s), however, it requires special protection when a function pointer is being passed around - that's why we use things like try_module_get. But it is assumed that it is ok not to do this in atomic contexts.
So, what's protecting the RT kernel from falling over if a CPU frequency governor module is removed at the wrong moment?
Jon.
Quoted 2 lines · Jon Masters
So, what's protecting the RT kernel from falling over if a CPU frequency governor module is removed at the wrong moment?
That's a contrived example, it does the right thing in the ones I've looked it, but it just occurred to me that this might not be general for kernel code where random pointers to modules are getting thrown around.
Jon.
Quoted 8 lines · Jon Masters
Quoted 2 lines · Jon Masters
So, what's protecting the RT kernel from falling over if a CPU frequency governor module is removed at the wrong moment?
That's a contrived example, it does the right thing in the ones I've looked it, but it just occurred to me that this might not be general for kernel code where random pointers to modules are getting thrown around.
I recommend not setting CONFIG_MODULE_UNLOAD on RT kernels for now. I looked at programmatically implementing this in Kconfig, but it seems that CONFIG_MODULE_UNLOAD is never explicitly set anywhere, it's simply in the deconfig for each architecture - anyone know Kconfig well enough to tell us how to fix up Kconfig.preempt to do the right thing?
Jon.
Quoted 10 lines · Jon Masters
Quoted 8 lines · Jon Masters
Quoted 2 lines · Jon Masters
So, what's protecting the RT kernel from falling over if a CPU frequency governor module is removed at the wrong moment?
That's a contrived example, it does the right thing in the ones I've looked it, but it just occurred to me that this might not be general for kernel code where random pointers to modules are getting thrown around.
Quoted 5 lines
I recommend not setting
CONFIG_MODULE_UNLOADon RT kernels for now. I looked at programmatically implementing this inKconfig, but it seems thatCONFIG_MODULE_UNLOADis never explicitly set anywhere, it's simply in the deconfig for each architecture - anyone knowKconfigwell enough to tell us how to fix upKconfig.preemptto do the right thing?
Could you give a different of better example of the problem with modules? This thread has been fairly scant on details ..
Daniel
Quoted 3 lines · Daniel Walker
Could you give a different of better example of the problem with modules? This thread has been fairly scant on details ..
There's a theoretical potential for the system to crash in -rt when unloading a module. Simply because interrupts are threads.
Some device has an interrupt handler that is called and preempted. At that moment the module for that device is unloaded. This calls things like kstop_machine that should make sure that all interrupt handlers have been resolved. But this does not work with -rt, since the interrupt handlers can now be preempted and resume after the kstop_machine and the moduling being unloaded.
Since the code for the interrupt handler no longer exists... KABOOM!
Enough details?
-- Steve
Quoted 10 lines · Steven Rostedt
Some device has an interrupt handler that is called and preempted. At that moment the module for that device is unloaded. This calls things like
kstop_machinethat should make sure that all interrupt handlers have been resolved. But this does not work with -rt, since the interrupt handlers can now be preempted and resume after thekstop_machineand the moduling being unloaded.Since the code for the interrupt handler no longer exists... KABOOM!
Enough details?
yeah, you have to assume the device is not in use, but still handling interrupts?
Daniel
Quoted 7 lines · Steven Rostedt
[...]
There's a theoretical potential for the system to crash in -rt when unloading a module. Simply because interrupts are threads.Some device has an interrupt handler that is called and preempted. At that moment the module for that device is unloaded. [...] Since the code for the interrupt handler no longer exists... KABOOM!
Perhaps you can identify those modules that have asked for interrupts, and block only them from unloading. Or, would it be outrageously expensive to increment the module refcount while one of its interrupt handlers is running?
- FChE
Quoted 11 lines · Frank Ch. Eigler
Quoted 6 lines
There's a theoretical potential for the system to crash in -rt when unloading a module. Simply because interrupts are threads.
Some device has an interrupt handler that is called and preempted. At that moment the module for that device is unloaded. [...] Since the code for the interrupt handler no longer exists... KABOOM!
Perhaps you can identify those modules that have asked for interrupts, and block only them from unloading. Or, would it be outrageously expensive to increment the module refcount while one of its interrupt handlers is running?
Actually, we were simply thinking of calling an rcu_lock before checking the handlers, and releasing the lock when all are done. Then before doing the module unload, we do a rcu_sync. Note, no interrupt handler should ever do a rcu_sync.
-- Steve
Quoted 4 lines · Steven Rostedt
Actually, we were simply thinking of calling an
rcu_lockbefore checking the handlers, and releasing the lock when all are done. Then before doing the module unload, we do arcu_sync. Note, no interrupt handler should ever do arcu_sync.
There's already some smp synchronize inside free_irq, are you sure that's not already handling this for smp? For -rt we could just enable it for UP ..
Daniel
Quoted 11 lines · Daniel Walker
Quoted 4 lines · Steven Rostedt
Actually, we were simply thinking of calling an
rcu_lockbefore checking the handlers, and releasing the lock when all are done. Then before doing the module unload, we do arcu_sync. Note, no interrupt handler should ever do arcu_sync.There's already some smp synchronize inside
free_irq, are you sure that's not already handling this for smp? For -rt we could just enable it for UP ..
If (desc->status & IRQ_INPROGRESS) remains true throughout the execution of the threaded (and thus preemptible) interrupt handler, then the synchronize_irq() should do the trick.
Thanx, Paul
Quoted 11 lines · Frank Ch. Eigler
Quoted 6 lines
There's a theoretical potential for the system to crash in -rt when unloading a module. Simply because interrupts are threads.
Some device has an interrupt handler that is called and preempted. At that moment the module for that device is unloaded. [...] Since the code for the interrupt handler no longer exists... KABOOM!
Perhaps you can identify those modules that have asked for interrupts, and block only them from unloading. Or, would it be outrageously expensive to increment the module refcount while one of its interrupt handlers is running?
Actually this whole thing is theoretical. Since the device would have to free the irq before unloading and interrupt desc->lock protects races like this. Then there is the question of softirqs and tasklets. And random passing of pointers. But this can also happen in mainline since tasklets and softirqs can run in a thread.
We need to look deeper. I'm not sure there is an issue here.
-- Steve
Quoted 13 lines · Steven Rostedt
Quoted 11 lines · Frank Ch. Eigler
Quoted 6 lines
There's a theoretical potential for the system to crash in -rt when unloading a module. Simply because interrupts are threads.
Some device has an interrupt handler that is called and preempted. At that moment the module for that device is unloaded. [...] Since the code for the interrupt handler no longer exists... KABOOM!
Perhaps you can identify those modules that have asked for interrupts, and block only them from unloading. Or, would it be outrageously expensive to increment the module refcount while one of its interrupt handlers is running?
Quoted 7 lines
Actually this whole thing is theoretical. Since the device would have to free the irq before unloading and interrupt
desc->lockprotects races like this. Then there is the question of softirqs and tasklets. And random passing of pointers. But this can also happen in mainline since tasklets and softirqs can run in a thread.We need to look deeper. I'm not sure there is an issue here.
I can poke some more and look at what actually happens on module unload (for now I think a quick test script loading/unloading modules in a loop should show us whether this is enough of a problem in reality), but I do want to point out that I was never concerned with interrupt handlers themselves - only the assumptions mainline makes about "interrupt context" use of pointers without an explicit try_module_get.
Rusty didn't have a simple answer either, so I'll poke.
Jon.