diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2015-01-19 17:37:04 -0500 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2015-01-19 20:08:32 -0500 |
commit | d453cded05ee219b77815ea194dc36efa5398bca (patch) | |
tree | 9f38c5ed55b653803eabecce959320d734606029 | |
parent | c772be52319de9756fd82f36d37a6d3e003441e3 (diff) |
module_arch_freeing_init(): new hook for archs before module->module_init freed.
Archs have been abusing module_free() to clean up their arch-specific
allocations. Since module_free() is also (ab)used by BPF and trace code,
let's keep it to simple allocations, and provide a hook called before
that.
This means that avr32, ia64, parisc and s390 no longer need to implement
their own module_free() at all. avr32 doesn't need module_finalize()
either.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Cc: Chris Metcalf <cmetcalf@ezchip.com>
Cc: Haavard Skinnemoen <hskinnemoen@gmail.com>
Cc: Hans-Christian Egtvedt <egtvedt@samfundet.no>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
Cc: Helge Deller <deller@gmx.de>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-ia64@vger.kernel.org
Cc: linux-parisc@vger.kernel.org
Cc: linux-s390@vger.kernel.org
-rw-r--r-- | arch/avr32/kernel/module.c | 13 | ||||
-rw-r--r-- | arch/ia64/kernel/module.c | 6 | ||||
-rw-r--r-- | arch/parisc/kernel/module.c | 6 | ||||
-rw-r--r-- | arch/s390/kernel/module.c | 10 | ||||
-rw-r--r-- | arch/tile/kernel/module.c | 2 | ||||
-rw-r--r-- | include/linux/moduleloader.h | 2 | ||||
-rw-r--r-- | kernel/module.c | 7 |
7 files changed, 17 insertions, 29 deletions
diff --git a/arch/avr32/kernel/module.c b/arch/avr32/kernel/module.c index 2c9412908024..164efa009e5b 100644 --- a/arch/avr32/kernel/module.c +++ b/arch/avr32/kernel/module.c | |||
@@ -19,12 +19,10 @@ | |||
19 | #include <linux/moduleloader.h> | 19 | #include <linux/moduleloader.h> |
20 | #include <linux/vmalloc.h> | 20 | #include <linux/vmalloc.h> |
21 | 21 | ||
22 | void module_free(struct module *mod, void *module_region) | 22 | void module_arch_freeing_init(struct module *mod) |
23 | { | 23 | { |
24 | vfree(mod->arch.syminfo); | 24 | vfree(mod->arch.syminfo); |
25 | mod->arch.syminfo = NULL; | 25 | mod->arch.syminfo = NULL; |
26 | |||
27 | vfree(module_region); | ||
28 | } | 26 | } |
29 | 27 | ||
30 | static inline int check_rela(Elf32_Rela *rela, struct module *module, | 28 | static inline int check_rela(Elf32_Rela *rela, struct module *module, |
@@ -291,12 +289,3 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, const char *strtab, | |||
291 | 289 | ||
292 | return ret; | 290 | return ret; |
293 | } | 291 | } |
294 | |||
295 | int module_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, | ||
296 | struct module *module) | ||
297 | { | ||
298 | vfree(module->arch.syminfo); | ||
299 | module->arch.syminfo = NULL; | ||
300 | |||
301 | return 0; | ||
302 | } | ||
diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c index 24603be24c14..29754aae5177 100644 --- a/arch/ia64/kernel/module.c +++ b/arch/ia64/kernel/module.c | |||
@@ -305,14 +305,12 @@ plt_target (struct plt_entry *plt) | |||
305 | #endif /* !USE_BRL */ | 305 | #endif /* !USE_BRL */ |
306 | 306 | ||
307 | void | 307 | void |
308 | module_free (struct module *mod, void *module_region) | 308 | module_arch_freeing_init (struct module *mod) |
309 | { | 309 | { |
310 | if (mod && mod->arch.init_unw_table && | 310 | if (mod->arch.init_unw_table) { |
311 | module_region == mod->module_init) { | ||
312 | unw_remove_unwind_table(mod->arch.init_unw_table); | 311 | unw_remove_unwind_table(mod->arch.init_unw_table); |
313 | mod->arch.init_unw_table = NULL; | 312 | mod->arch.init_unw_table = NULL; |
314 | } | 313 | } |
315 | vfree(module_region); | ||
316 | } | 314 | } |
317 | 315 | ||
318 | /* Have we already seen one of these relocations? */ | 316 | /* Have we already seen one of these relocations? */ |
diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c index 50dfafc3f2c1..5822e8e200e6 100644 --- a/arch/parisc/kernel/module.c +++ b/arch/parisc/kernel/module.c | |||
@@ -298,14 +298,10 @@ static inline unsigned long count_stubs(const Elf_Rela *rela, unsigned long n) | |||
298 | } | 298 | } |
299 | #endif | 299 | #endif |
300 | 300 | ||
301 | 301 | void module_arch_freeing_init(struct module *mod) | |
302 | /* Free memory returned from module_alloc */ | ||
303 | void module_free(struct module *mod, void *module_region) | ||
304 | { | 302 | { |
305 | kfree(mod->arch.section); | 303 | kfree(mod->arch.section); |
306 | mod->arch.section = NULL; | 304 | mod->arch.section = NULL; |
307 | |||
308 | vfree(module_region); | ||
309 | } | 305 | } |
310 | 306 | ||
311 | /* Additional bytes needed in front of individual sections */ | 307 | /* Additional bytes needed in front of individual sections */ |
diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c index b89b59158b95..409d152585be 100644 --- a/arch/s390/kernel/module.c +++ b/arch/s390/kernel/module.c | |||
@@ -55,14 +55,10 @@ void *module_alloc(unsigned long size) | |||
55 | } | 55 | } |
56 | #endif | 56 | #endif |
57 | 57 | ||
58 | /* Free memory returned from module_alloc */ | 58 | void module_arch_freeing_init(struct module *mod) |
59 | void module_free(struct module *mod, void *module_region) | ||
60 | { | 59 | { |
61 | if (mod) { | 60 | vfree(mod->arch.syminfo); |
62 | vfree(mod->arch.syminfo); | 61 | mod->arch.syminfo = NULL; |
63 | mod->arch.syminfo = NULL; | ||
64 | } | ||
65 | vfree(module_region); | ||
66 | } | 62 | } |
67 | 63 | ||
68 | static void check_rela(Elf_Rela *rela, struct module *me) | 64 | static void check_rela(Elf_Rela *rela, struct module *me) |
diff --git a/arch/tile/kernel/module.c b/arch/tile/kernel/module.c index 96447c9160a0..62a597e810d6 100644 --- a/arch/tile/kernel/module.c +++ b/arch/tile/kernel/module.c | |||
@@ -83,7 +83,7 @@ void module_free(struct module *mod, void *module_region) | |||
83 | 0, 0, 0, NULL, NULL, 0); | 83 | 0, 0, 0, NULL, NULL, 0); |
84 | 84 | ||
85 | /* | 85 | /* |
86 | * FIXME: If module_region == mod->module_init, trim exception | 86 | * FIXME: Add module_arch_freeing_init to trim exception |
87 | * table entries. | 87 | * table entries. |
88 | */ | 88 | */ |
89 | } | 89 | } |
diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h index 7eeb9bbfb816..054eac853090 100644 --- a/include/linux/moduleloader.h +++ b/include/linux/moduleloader.h | |||
@@ -82,4 +82,6 @@ int module_finalize(const Elf_Ehdr *hdr, | |||
82 | /* Any cleanup needed when module leaves. */ | 82 | /* Any cleanup needed when module leaves. */ |
83 | void module_arch_cleanup(struct module *mod); | 83 | void module_arch_cleanup(struct module *mod); |
84 | 84 | ||
85 | /* Any cleanup before freeing mod->module_init */ | ||
86 | void module_arch_freeing_init(struct module *mod); | ||
85 | #endif | 87 | #endif |
diff --git a/kernel/module.c b/kernel/module.c index 3965511ae133..68be0b1f9e7f 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -1804,6 +1804,10 @@ void __weak module_arch_cleanup(struct module *mod) | |||
1804 | { | 1804 | { |
1805 | } | 1805 | } |
1806 | 1806 | ||
1807 | void __weak module_arch_freeing_init(struct module *mod) | ||
1808 | { | ||
1809 | } | ||
1810 | |||
1807 | /* Free a module, remove from lists, etc. */ | 1811 | /* Free a module, remove from lists, etc. */ |
1808 | static void free_module(struct module *mod) | 1812 | static void free_module(struct module *mod) |
1809 | { | 1813 | { |
@@ -1841,6 +1845,7 @@ static void free_module(struct module *mod) | |||
1841 | 1845 | ||
1842 | /* This may be NULL, but that's OK */ | 1846 | /* This may be NULL, but that's OK */ |
1843 | unset_module_init_ro_nx(mod); | 1847 | unset_module_init_ro_nx(mod); |
1848 | module_arch_freeing_init(mod); | ||
1844 | module_free(mod, mod->module_init); | 1849 | module_free(mod, mod->module_init); |
1845 | kfree(mod->args); | 1850 | kfree(mod->args); |
1846 | percpu_modfree(mod); | 1851 | percpu_modfree(mod); |
@@ -2930,6 +2935,7 @@ static struct module *layout_and_allocate(struct load_info *info, int flags) | |||
2930 | static void module_deallocate(struct module *mod, struct load_info *info) | 2935 | static void module_deallocate(struct module *mod, struct load_info *info) |
2931 | { | 2936 | { |
2932 | percpu_modfree(mod); | 2937 | percpu_modfree(mod); |
2938 | module_arch_freeing_init(mod); | ||
2933 | module_free(mod, mod->module_init); | 2939 | module_free(mod, mod->module_init); |
2934 | module_free(mod, mod->module_core); | 2940 | module_free(mod, mod->module_core); |
2935 | } | 2941 | } |
@@ -3055,6 +3061,7 @@ static int do_init_module(struct module *mod) | |||
3055 | mod->strtab = mod->core_strtab; | 3061 | mod->strtab = mod->core_strtab; |
3056 | #endif | 3062 | #endif |
3057 | unset_module_init_ro_nx(mod); | 3063 | unset_module_init_ro_nx(mod); |
3064 | module_arch_freeing_init(mod); | ||
3058 | module_free(mod, mod->module_init); | 3065 | module_free(mod, mod->module_init); |
3059 | mod->module_init = NULL; | 3066 | mod->module_init = NULL; |
3060 | mod->init_size = 0; | 3067 | mod->init_size = 0; |