* Re: kksymoops
@ 2002-11-20 4:15 Kevin Brosius
0 siblings, 0 replies; 5+ messages in thread
From: Kevin Brosius @ 2002-11-20 4:15 UTC (permalink / raw)
To: kernel, Jeff Garzik
> Jeff Garzik wrote:
>
> > Rusty,
> >
> > What is the status of kksymoops?
>
>
>
> LOL -- look at me eat my words.
>
> I see it's now in Linus's tree -- thanks much!
>
Thanks guys! (I figured I'd give him a day or two before pinging Rusty
directly.) This'll help chase some driver problems on the USB side.
--
Kevin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Module Refcount & Stuff mini-FAQ
@ 2002-11-18 22:58 Rusty Russell
2002-11-19 3:10 ` kksymoops Jeff Garzik
2002-11-19 3:50 ` kksymoops Jeff Garzik
0 siblings, 2 replies; 5+ messages in thread
From: Rusty Russell @ 2002-11-18 22:58 UTC (permalink / raw)
To: linux-kernel; +Cc: Doug Ledford, Alexander Viro
[ Suggestions welcome ]
Golden Rule: If you are calling though a function pointer into a
(different) module, you must hold a reference to that module.
Otherwise you risk sleeping in the module while it is unloaded.
Q: How do I get a reference to a module?
A: Usually, a successful call to try_module_get(owner). You don't
need to check for owner != NULL, BTW.
Q: When does try_module_get(owner) fail?
A: When the module is not ready to be entered (ie. still in
init_module) or it is being removed. It fails to prevent you
entering the module as it is being discarded (init might fail, or
it's being removed).
Q: But modules call my register() routine which wants to call back
into one of the function pointers immediately, and so
try_module_get() fails!
A: You're being called from the module, so someone already has a
reference (unless there's a bug), so you don't need a
try_module_get().
This does mean that if you were to register a structure for
*another* module (does anyone do this?) you'd need to have a
reference to it.
Q: How do I put the reference back?
A: Using module_put(owner) (owner == NULL is OK).
Q: Do I really need to put try_module_get() before every function ptr
call?
A: If the function does not sleep (any cannot be preempted) ie. is
called in softirq or hardirq context, you can omit this step, since
you obviously won't sleep inside the module.
Also, most structs have clear "start" and "stop" functions
(eg. mount/umount), so you only need one try_module_get()
on start, and module_put() on stop.
Q: Is it safe to call try_module_get() and module_put() from an
interrtupt / softirq?
A: Yes.
Q: My code use "MOD_INC_USE_COUNT". Do I still need to adjust my
module count when someone calls one of my functions?
A: No, you never need to adjust your own module count. There are five
ways a function in your module can get called: firstly, it could be
your module_init() function, in which case the module code holds a
reference. It could be another module using one of your
EXPORT_SYMBOL'ed functions, in which case you cannot be removed
since they would have to be removed first. It could be a module
which found an EXPORT_SYMBOL'ed function using symbol_get(), in
which case they hold a reference count. It could be through a
function pointer which your module gave out previously, which is
discussed above. Finally, it could be from within your own module,
in which case someone must already hold a reference.
Q: My code uses "__MOD_INC_USE_COUNT(reg->owner)", but now I get a
warning at runtime that it is unsafe. What do I need to do?
A: You need to use try_module_get(), and not call into the module if
it fails (act as if it hasn't registered yet). Note that you no
longer need to check for NULL yourself, try_module_get() does that.
Q: My code used "GET_USE_COUNT(module)" to get the reference count.
A: Don't do that. If module unloading is disabled, there is no
reference count, and there is never a single value you can assign
to.
Q: My code used "try_inc_mod_count(module)" to get the reference
count. Should I change it?
A: No hurry. try_module_get() is exactly the same: the new name
reflects that this is now the only way to get a reference.
Q: How does the code in try_module_get() work?
A: It disables preemption for a moment, checks the live flag, and then
increments a per-cpu counter if the module is live. This is even
lighter-weight (in icache and cycles) than using a brlock, but has
the same effect. If CONFIG_MODULE_UNLOAD=n, it just becomes a
check that the module is live.
Q: How does the module remove code work?
A: It stops the machine by scheduling threads for every other CPU,
then they all disable interrupts. At this stage we know that noone
is in try_module_get(), so we can reliably read the counter. If
zero, or the rmmod user specified --wait, we set the live flag to
false. After this, the reference count should not increase, and
each module_put() will wake us up, so we can check the counter
again.
Q: Are these changes all so you could implement an in-kernel module
linker?
A: No, they were to prevent load and unload races without altering
every module, nor introducing drastic new requirements.
Q: Doesn't putting linking code into the kernel just add bloat?
A: The total linking code is about 200 generic lines, 100
x86-specific lines. The ia64 linking code is about 500 lines (it's
the most complex). Richard Henderson has a great suggestion for
simplifying it furthur, which I'm implementing now. "insmod" is
now a single portable system call, meaning insmod can be written in
about 20 lines of code.
The previous code required to implement the two module loading
system call, the module querying system call, and the /proc/ksyms
output, required a little more code than the current x86 linker.
Q: Why not just fix the old code?
A: Because having something so intimate with the kernel in userspace
greatly restricts what changes the kernel can make. Moving into
the kernel means I have implemented modversions, typesafe
extensible module parameters and kallsyms without altering
userspace in any way. Future extensions won't have to worry about
the modversions problem.
Q: Why not implement two-stage insert / two-stage delete?
A: Because I implemented it first and it sucked. And because this
*is* two-stage insert and two-stage delete, without exposing it to
the modules using it, with the added advantage that the second
stage is atomic (activation/deactivation is simply changing
mod->live, modulo locking implementation magic detailed above).
This prevents the race between deactivating the module and finding
that someone has starting using it as you are deactivating it.
Hope that helps?
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
^ permalink raw reply [flat|nested] 5+ messages in thread
* kksymoops
2002-11-18 22:58 Module Refcount & Stuff mini-FAQ Rusty Russell
@ 2002-11-19 3:10 ` Jeff Garzik
2002-11-19 21:10 ` kksymoops Rusty Russell
2002-11-19 3:50 ` kksymoops Jeff Garzik
1 sibling, 1 reply; 5+ messages in thread
From: Jeff Garzik @ 2002-11-19 3:10 UTC (permalink / raw)
To: Rusty Russell; +Cc: linux-kernel
Rusty,
What is the status of kksymoops?
I realize that you have a full plate, but [for the short time it existed
in mainline] this was a incredibly useful feature for end users
providing bug reports to me (and others).
I'm _not_ asking "when", just wondering what the plan is to resuscitate
kksymoops.
Jeff
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: kksymoops
2002-11-19 3:10 ` kksymoops Jeff Garzik
@ 2002-11-19 21:10 ` Rusty Russell
2002-11-20 15:46 ` kksymoops Kai Germaschewski
0 siblings, 1 reply; 5+ messages in thread
From: Rusty Russell @ 2002-11-19 21:10 UTC (permalink / raw)
To: Jeff Garzik; +Cc: linux-kernel, Kai Germaschewski
In message <3DD9AB88.4000102@pobox.com> you write:
> I'm _not_ asking "when", just wondering what the plan is to resuscitate
> kksymoops.
Looks like someone pushed my patch. Erm, OK, wonder if it works on
x86? 8)
My mental TODO list looked something like this:
1) Drop the optimization which checks against addr between _stext and
_etext, as this skips __init functions on most archs.
2) Only put in the symbols for functions (currently CONFIG_KALLSYMS=y
adds 400k on my laptop: ouch!).
3) Keith asked me to rename it, so as not to get confused with the
previous patches and kgdb support). I guess it's too late for this
one.
4) Use a simple scheme like the mini-oopser did to reduce the symbol
table size furthur (I got it down to 70k IIRC).
5) See if Kai prefers the compile step inside the Makefile rather than
in the script.
6) It'd be nice if CONFIG_KALLSYMS=m worked.
If someone wants to champion any or all of these, be my guest, there's
plenty to go around 8)
Cheers,
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: kksymoops
2002-11-19 21:10 ` kksymoops Rusty Russell
@ 2002-11-20 15:46 ` Kai Germaschewski
0 siblings, 0 replies; 5+ messages in thread
From: Kai Germaschewski @ 2002-11-20 15:46 UTC (permalink / raw)
To: Rusty Russell; +Cc: Jeff Garzik, linux-kernel
On Wed, 20 Nov 2002, Rusty Russell wrote:
> In message <3DD9AB88.4000102@pobox.com> you write:
> > I'm _not_ asking "when", just wondering what the plan is to resuscitate
> > kksymoops.
>
> Looks like someone pushed my patch. Erm, OK, wonder if it works on
> x86? 8)
I think Linus himself did that ;)
> My mental TODO list looked something like this:
> 1) Drop the optimization which checks against addr between _stext and
> _etext, as this skips __init functions on most archs.
Well, this was put in to avoid all kind of garbage in the traces, so it
shouldn't just go without replacement. Probably one could even get it
correct now, using ->module_init() and ->module_core() (just set them for
the core kernel as well).
> 2) Only put in the symbols for functions (currently CONFIG_KALLSYMS=y
> adds 400k on my laptop: ouch!).
I'm not to sure about this, I sometimes find it useful to have variables
on the stack identified correctly.
> 3) Keith asked me to rename it, so as not to get confused with the
> previous patches and kgdb support). I guess it's too late for this
> one.
Nothing wrong with a follow-up patch, is it?
> 5) See if Kai prefers the compile step inside the Makefile rather than
> in the script.
I'll actually have to look into this. The script is probably fine.
> 6) It'd be nice if CONFIG_KALLSYMS=m worked.
Shouldn't be too hard.
Well, I know talk is cheap. I'll try to find some time to actually look
into some of these issues and come up with patches.
--Kai
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: kksymoops
2002-11-18 22:58 Module Refcount & Stuff mini-FAQ Rusty Russell
2002-11-19 3:10 ` kksymoops Jeff Garzik
@ 2002-11-19 3:50 ` Jeff Garzik
1 sibling, 0 replies; 5+ messages in thread
From: Jeff Garzik @ 2002-11-19 3:50 UTC (permalink / raw)
To: Rusty Russell; +Cc: linux-kernel
Jeff Garzik wrote:
> Rusty,
>
> What is the status of kksymoops?
LOL -- look at me eat my words.
I see it's now in Linus's tree -- thanks much!
Jeff
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-11-20 15:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-20 4:15 kksymoops Kevin Brosius
-- strict thread matches above, loose matches on Subject: below --
2002-11-18 22:58 Module Refcount & Stuff mini-FAQ Rusty Russell
2002-11-19 3:10 ` kksymoops Jeff Garzik
2002-11-19 21:10 ` kksymoops Rusty Russell
2002-11-20 15:46 ` kksymoops Kai Germaschewski
2002-11-19 3:50 ` kksymoops Jeff Garzik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox