Skip to content

Commit d453cde

Browse files
committed
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 <[email protected]> Cc: Chris Metcalf <[email protected]> Cc: Haavard Skinnemoen <[email protected]> Cc: Hans-Christian Egtvedt <[email protected]> Cc: Tony Luck <[email protected]> Cc: Fenghua Yu <[email protected]> Cc: "James E.J. Bottomley" <[email protected]> Cc: Helge Deller <[email protected]> Cc: Martin Schwidefsky <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected]
1 parent c772be5 commit d453cde

File tree

7 files changed

+17
-29
lines changed

7 files changed

+17
-29
lines changed

arch/avr32/kernel/module.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
#include <linux/moduleloader.h>
2020
#include <linux/vmalloc.h>
2121

22-
void module_free(struct module *mod, void *module_region)
22+
void module_arch_freeing_init(struct module *mod)
2323
{
2424
vfree(mod->arch.syminfo);
2525
mod->arch.syminfo = NULL;
26-
27-
vfree(module_region);
2826
}
2927

3028
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,
291289

292290
return ret;
293291
}
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-
}

arch/ia64/kernel/module.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,12 @@ plt_target (struct plt_entry *plt)
305305
#endif /* !USE_BRL */
306306

307307
void
308-
module_free (struct module *mod, void *module_region)
308+
module_arch_freeing_init (struct module *mod)
309309
{
310-
if (mod && mod->arch.init_unw_table &&
311-
module_region == mod->module_init) {
310+
if (mod->arch.init_unw_table) {
312311
unw_remove_unwind_table(mod->arch.init_unw_table);
313312
mod->arch.init_unw_table = NULL;
314313
}
315-
vfree(module_region);
316314
}
317315

318316
/* Have we already seen one of these relocations? */

arch/parisc/kernel/module.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,10 @@ static inline unsigned long count_stubs(const Elf_Rela *rela, unsigned long n)
298298
}
299299
#endif
300300

301-
302-
/* Free memory returned from module_alloc */
303-
void module_free(struct module *mod, void *module_region)
301+
void module_arch_freeing_init(struct module *mod)
304302
{
305303
kfree(mod->arch.section);
306304
mod->arch.section = NULL;
307-
308-
vfree(module_region);
309305
}
310306

311307
/* Additional bytes needed in front of individual sections */

arch/s390/kernel/module.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,10 @@ void *module_alloc(unsigned long size)
5555
}
5656
#endif
5757

58-
/* Free memory returned from module_alloc */
59-
void module_free(struct module *mod, void *module_region)
58+
void module_arch_freeing_init(struct module *mod)
6059
{
61-
if (mod) {
62-
vfree(mod->arch.syminfo);
63-
mod->arch.syminfo = NULL;
64-
}
65-
vfree(module_region);
60+
vfree(mod->arch.syminfo);
61+
mod->arch.syminfo = NULL;
6662
}
6763

6864
static void check_rela(Elf_Rela *rela, struct module *me)

arch/tile/kernel/module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void module_free(struct module *mod, void *module_region)
8383
0, 0, 0, NULL, NULL, 0);
8484

8585
/*
86-
* FIXME: If module_region == mod->module_init, trim exception
86+
* FIXME: Add module_arch_freeing_init to trim exception
8787
* table entries.
8888
*/
8989
}

include/linux/moduleloader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,6 @@ int module_finalize(const Elf_Ehdr *hdr,
8282
/* Any cleanup needed when module leaves. */
8383
void module_arch_cleanup(struct module *mod);
8484

85+
/* Any cleanup before freeing mod->module_init */
86+
void module_arch_freeing_init(struct module *mod);
8587
#endif

kernel/module.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,10 @@ void __weak module_arch_cleanup(struct module *mod)
18041804
{
18051805
}
18061806

1807+
void __weak module_arch_freeing_init(struct module *mod)
1808+
{
1809+
}
1810+
18071811
/* Free a module, remove from lists, etc. */
18081812
static void free_module(struct module *mod)
18091813
{
@@ -1841,6 +1845,7 @@ static void free_module(struct module *mod)
18411845

18421846
/* This may be NULL, but that's OK */
18431847
unset_module_init_ro_nx(mod);
1848+
module_arch_freeing_init(mod);
18441849
module_free(mod, mod->module_init);
18451850
kfree(mod->args);
18461851
percpu_modfree(mod);
@@ -2930,6 +2935,7 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
29302935
static void module_deallocate(struct module *mod, struct load_info *info)
29312936
{
29322937
percpu_modfree(mod);
2938+
module_arch_freeing_init(mod);
29332939
module_free(mod, mod->module_init);
29342940
module_free(mod, mod->module_core);
29352941
}
@@ -3055,6 +3061,7 @@ static int do_init_module(struct module *mod)
30553061
mod->strtab = mod->core_strtab;
30563062
#endif
30573063
unset_module_init_ro_nx(mod);
3064+
module_arch_freeing_init(mod);
30583065
module_free(mod, mod->module_init);
30593066
mod->module_init = NULL;
30603067
mod->init_size = 0;

0 commit comments

Comments
 (0)