From: Rusty Russell <rusty@rustcorp.com.au>
To: Werner Almesberger <wa@almesberger.net>
Cc: Roman Zippel <zippel@linux-m68k.org>,
kuznet@ms2.inr.ac.ru, davem@redhat.com, kronos@kronoz.cjb.net,
linux-kernel@vger.kernel.org
Subject: Re: [RFC] Is an alternative module interface needed/possible?
Date: Tue, 18 Feb 2003 15:54:12 +1100 [thread overview]
Message-ID: <20030218050349.44B092C04E@lists.samba.org> (raw)
In-Reply-To: Your message of "Mon, 17 Feb 2003 22:18:37 -0300." <20030217221837.Q2092@almesberger.net>
In message <20030217221837.Q2092@almesberger.net> you write:
> > failure: if the object is still busy, we just return -EBUSY. This is
> > simple, but this doesn't work for modules, since during module exit you
> > can't fail anymore.
Of course, they never could fail module exit. You could use
can_unload() which was only protected by the BKL, hence so rarely
used: grep 2.4.20 to see all four users.
Having a separate can_unload function means a window between asking
can_unload() and doing the actual unload. Doing it in the function
itself (ie. cleanup returns an int, or a separate "prepare_to_unload"
kind of function) means you have to deal with the "I started
deregistering my stuff, but then had to re-register them" which leaves
a race where the module is partially unavailable (ie. the spurious
failure problem).
Both these problems are soluble, but they're not trivial.
> That's a modules API problem. And yes, I think modules should
> eventually be able to say that they're busy.
Take a look at the current ip_conntrack code. It keeps its own
reference count and spins until it hits zero in unload, because
otherwise it would never be unloadable (it attaches a callback to each
packet, so logically it would bump its refcount there). In 2.5 it can
use try_module_get() and be unloaded with rmmod --wait in this worst
case (I'm slack, patching is on my todo list).
Security modules have the same issues, and Greg Kroah-Hartmann was
telling me USB has it as well.
You can see why I considered deprecating module unloading: it's a hard
problem, and fixing it in general probably means massive changes.
Which I'm happy to leave to someone else.
> By the way, a loong time ago, in the modules thread, I suggested
> a "decrement_module_count_and_return" function [1]. Such a
> construct would be useful in this specific case.
Stephen and I even implemented one, for x86 (see below). But
implementing the matching "enter and inc" case remains problematic, so
I dropped that idea.
Anyway, good luck!
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Name: module_put_return primitive for x86
Author: Rusty Russell
Status: Experimental
Depends: Module/forceunload.patch.gz
D: This patch implements module_put_return() for x86, which allows a
D: module to control its own reference counts in some cases. A module
D: must never use module_put() on itself, since this may result in the
D: module being removable immediately: this is the alternative, which
D: atomically decrements the count and returns.
D:
D: Each architecture will need to implement this for preempt.
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .13134-linux-2.5.38/arch/i386/kernel/module.c .13134-linux-2.5.38.updated/arch/i386/kernel/module.c
--- .13134-linux-2.5.38/arch/i386/kernel/module.c 2002-09-25 02:02:28.000000000 +1000
+++ .13134-linux-2.5.38.updated/arch/i386/kernel/module.c 2002-09-25 02:02:56.000000000 +1000
@@ -28,6 +28,9 @@
#define DEBUGP(fmt , ...)
#endif
+/* For the magic module return. */
+struct module_percpu module_percpu[NR_CPUS];
+
static void *alloc_and_zero(unsigned long size)
{
void *ret;
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .13134-linux-2.5.38/arch/i386/lib/module.S .13134-linux-2.5.38.updated/arch/i386/lib/module.S
--- .13134-linux-2.5.38/arch/i386/lib/module.S 1970-01-01 10:00:00.000000000 +1000
+++ .13134-linux-2.5.38.updated/arch/i386/lib/module.S 2002-09-25 02:02:56.000000000 +1000
@@ -0,0 +1,33 @@
+/* Icky, icky, return trampoline for dying modules. Entered with
+ interrupts off. (C) 2002 Stephen Rothwell, IBM Corporation. */
+
+#include <asm/thread_info.h>
+
+.text
+.align 4
+.globl __magic_module_return
+
+#define MODULE_PERCPU_SIZE_ORDER 3
+
+__magic_module_return:
+ /* Save one working variable */
+ pushl %eax
+
+ /* Get CPU number from current. */
+ GET_THREAD_INFO(%eax)
+ movl TI_CPU(%eax), %eax
+
+ /* Push module_percpu[cpu].flags on the stack */
+ shll $MODULE_PERCPU_SIZE_ORDER, %eax
+ pushl module_percpu(%eax)
+
+ /* Put module_percpu[cpu].returnaddr into %eax */
+ movl module_percpu+4(%eax), %eax
+
+ /* Push returnaddr and restore eax */
+ xchgl %eax, 4(%esp)
+
+ /* Restore interrupts */
+ popf
+ /* Go home */
+ ret
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .13134-linux-2.5.38/include/asm-i386/module.h .13134-linux-2.5.38.updated/include/asm-i386/module.h
--- .13134-linux-2.5.38/include/asm-i386/module.h 2002-09-25 02:02:28.000000000 +1000
+++ .13134-linux-2.5.38.updated/include/asm-i386/module.h 2002-09-25 02:02:56.000000000 +1000
@@ -8,4 +8,33 @@ struct mod_arch_specific
#define Elf_Shdr Elf32_Shdr
#define Elf_Sym Elf32_Sym
#define Elf_Ehdr Elf32_Ehdr
+
+/* Non-preemtible decrement the refcount and return. */
+#define module_put_return(firstarg , ...) \
+do { \
+ unsigned int cpu; \
+ unsigned long flags; \
+ \
+ local_irq_save(flags); \
+ if (unlikely(module_put(THIS_MODULE)) { \
+ module_percpu[cpu].flags = flags; \
+ module_percpu[cpu].returnaddr = ((void **)&(firstarg))[-1]; \
+ ((void **)&(firstarg))[-1] = __magic_module_return; \
+ } else \
+ local_irq_restore(flags); \
+ return __VA_ARGS__; \
+} while(0)
+
+/* FIXME: Use per-cpu vars --RR */
+struct module_percpu
+{
+ unsigned long flags;
+ void *returnaddr;
+};
+
+extern struct module_percpu module_percpu[NR_CPUS];
+
+/* Restore flags and return to caller. */
+extern void __magic_module_return(void);
+
#endif /* _ASM_I386_MODULE_H */
next prev parent reply other threads:[~2003-02-18 4:53 UTC|newest]
Thread overview: 78+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-01-02 22:50 [RFC] Migrating net/sched to new module interface Kronos
2003-01-03 5:10 ` Rusty Russell
2003-01-03 8:37 ` David S. Miller
2003-01-04 6:09 ` Rusty Russell
2003-01-04 16:21 ` Kronos
2003-01-13 22:32 ` kuznet
2003-01-13 23:23 ` Max Krasnyansky
2003-01-14 17:49 ` Kronos
2003-01-15 0:21 ` Roman Zippel
2003-01-15 1:19 ` kuznet
2003-01-15 7:31 ` Werner Almesberger
2003-01-15 8:16 ` Rusty Russell
2003-01-15 9:33 ` Werner Almesberger
2003-01-16 1:12 ` Rusty Russell
2003-01-16 2:42 ` Werner Almesberger
2003-01-16 3:31 ` Rusty Russell
2003-01-16 4:20 ` Werner Almesberger
2003-01-16 4:25 ` David S. Miller
2003-01-16 4:49 ` Werner Almesberger
2003-01-16 16:05 ` Roman Zippel
2003-01-16 18:15 ` Roman Zippel
2003-01-16 18:58 ` Werner Almesberger
2003-01-16 23:53 ` Roman Zippel
2003-01-17 1:04 ` Greg KH
2003-01-17 2:27 ` Rusty Russell
2003-01-17 21:40 ` Roman Zippel
2003-02-13 23:16 ` Werner Almesberger
2003-02-14 1:57 ` Rusty Russell
2003-02-14 3:44 ` Werner Almesberger
2003-02-14 11:16 ` Roman Zippel
2003-02-14 12:04 ` Rusty Russell
2003-02-14 12:49 ` Roman Zippel
2003-02-17 1:59 ` Rusty Russell
2003-02-17 10:53 ` Roman Zippel
2003-02-17 23:31 ` Rusty Russell
2003-02-18 12:26 ` Roman Zippel
2003-02-14 13:21 ` Roman Zippel
2003-02-14 13:53 ` Werner Almesberger
2003-02-14 14:24 ` Roman Zippel
2003-02-14 18:30 ` Werner Almesberger
2003-02-14 20:09 ` Roman Zippel
2003-02-15 0:12 ` Werner Almesberger
2003-02-15 0:51 ` Roman Zippel
2003-02-15 2:28 ` Werner Almesberger
2003-02-15 23:20 ` Roman Zippel
2003-02-17 17:04 ` Werner Almesberger
2003-02-17 23:09 ` [RFC] Is an alternative module interface needed/possible? Roman Zippel
2003-02-18 1:18 ` Werner Almesberger
2003-02-18 4:54 ` Rusty Russell [this message]
2003-02-18 7:20 ` Werner Almesberger
2003-02-18 12:06 ` Roman Zippel
2003-02-18 14:12 ` Werner Almesberger
2003-02-18 12:45 ` Thomas Molina
2003-02-18 17:22 ` Werner Almesberger
2003-02-19 3:30 ` Rusty Russell
2003-02-19 4:11 ` Werner Almesberger
2003-02-19 23:38 ` Rusty Russell
2003-02-20 9:46 ` Roman Zippel
2003-02-20 0:40 ` Roman Zippel
2003-02-20 2:17 ` Werner Almesberger
2003-02-23 16:02 ` Roman Zippel
2003-02-26 23:26 ` Werner Almesberger
2003-02-27 12:34 ` Roman Zippel
2003-02-27 13:20 ` Werner Almesberger
2003-02-27 14:33 ` Roman Zippel
2003-02-23 23:34 ` Kevin O'Connor
2003-02-24 12:14 ` Roman Zippel
2003-02-18 12:35 ` Roman Zippel
2003-02-18 14:14 ` Werner Almesberger
2003-02-19 1:48 ` Roman Zippel
2003-02-19 2:27 ` Werner Almesberger
2003-01-16 13:44 ` [RFC] Migrating net/sched to new module interface Roman Zippel
2003-01-15 17:04 ` Roman Zippel
-- strict thread matches above, loose matches on Subject: below --
2003-02-20 12:09 [RFC] Is an alternative module interface needed/possible? Adam J. Richter
2003-02-20 12:46 ` Roman Zippel
2003-02-20 13:51 Adam J. Richter
2003-02-20 14:06 ` Werner Almesberger
2003-02-20 15:38 ` Roman Zippel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030218050349.44B092C04E@lists.samba.org \
--to=rusty@rustcorp.com.au \
--cc=davem@redhat.com \
--cc=kronos@kronoz.cjb.net \
--cc=kuznet@ms2.inr.ac.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=wa@almesberger.net \
--cc=zippel@linux-m68k.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox