Skip to content

Commit

Permalink
module_arch_freeing_init(): new hook for archs before module->module_…
Browse files Browse the repository at this point in the history
…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]
  • Loading branch information
rustyrussell committed Jan 20, 2015
1 parent c772be5 commit d453cde
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 29 deletions.
13 changes: 1 addition & 12 deletions arch/avr32/kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
#include <linux/moduleloader.h>
#include <linux/vmalloc.h>

void module_free(struct module *mod, void *module_region)
void module_arch_freeing_init(struct module *mod)
{
vfree(mod->arch.syminfo);
mod->arch.syminfo = NULL;

vfree(module_region);
}

static inline int check_rela(Elf32_Rela *rela, struct module *module,
Expand Down Expand Up @@ -291,12 +289,3 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, const char *strtab,

return ret;
}

int module_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs,
struct module *module)
{
vfree(module->arch.syminfo);
module->arch.syminfo = NULL;

return 0;
}
6 changes: 2 additions & 4 deletions arch/ia64/kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,12 @@ plt_target (struct plt_entry *plt)
#endif /* !USE_BRL */

void
module_free (struct module *mod, void *module_region)
module_arch_freeing_init (struct module *mod)
{
if (mod && mod->arch.init_unw_table &&
module_region == mod->module_init) {
if (mod->arch.init_unw_table) {
unw_remove_unwind_table(mod->arch.init_unw_table);
mod->arch.init_unw_table = NULL;
}
vfree(module_region);
}

/* Have we already seen one of these relocations? */
Expand Down
6 changes: 1 addition & 5 deletions arch/parisc/kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,10 @@ static inline unsigned long count_stubs(const Elf_Rela *rela, unsigned long n)
}
#endif


/* Free memory returned from module_alloc */
void module_free(struct module *mod, void *module_region)
void module_arch_freeing_init(struct module *mod)
{
kfree(mod->arch.section);
mod->arch.section = NULL;

vfree(module_region);
}

/* Additional bytes needed in front of individual sections */
Expand Down
10 changes: 3 additions & 7 deletions arch/s390/kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,10 @@ void *module_alloc(unsigned long size)
}
#endif

/* Free memory returned from module_alloc */
void module_free(struct module *mod, void *module_region)
void module_arch_freeing_init(struct module *mod)
{
if (mod) {
vfree(mod->arch.syminfo);
mod->arch.syminfo = NULL;
}
vfree(module_region);
vfree(mod->arch.syminfo);
mod->arch.syminfo = NULL;
}

static void check_rela(Elf_Rela *rela, struct module *me)
Expand Down
2 changes: 1 addition & 1 deletion arch/tile/kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void module_free(struct module *mod, void *module_region)
0, 0, 0, NULL, NULL, 0);

/*
* FIXME: If module_region == mod->module_init, trim exception
* FIXME: Add module_arch_freeing_init to trim exception
* table entries.
*/
}
Expand Down
2 changes: 2 additions & 0 deletions include/linux/moduleloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,6 @@ int module_finalize(const Elf_Ehdr *hdr,
/* Any cleanup needed when module leaves. */
void module_arch_cleanup(struct module *mod);

/* Any cleanup before freeing mod->module_init */
void module_arch_freeing_init(struct module *mod);
#endif
7 changes: 7 additions & 0 deletions kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,10 @@ void __weak module_arch_cleanup(struct module *mod)
{
}

void __weak module_arch_freeing_init(struct module *mod)
{
}

/* Free a module, remove from lists, etc. */
static void free_module(struct module *mod)
{
Expand Down Expand Up @@ -1841,6 +1845,7 @@ static void free_module(struct module *mod)

/* This may be NULL, but that's OK */
unset_module_init_ro_nx(mod);
module_arch_freeing_init(mod);
module_free(mod, mod->module_init);
kfree(mod->args);
percpu_modfree(mod);
Expand Down Expand Up @@ -2930,6 +2935,7 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
static void module_deallocate(struct module *mod, struct load_info *info)
{
percpu_modfree(mod);
module_arch_freeing_init(mod);
module_free(mod, mod->module_init);
module_free(mod, mod->module_core);
}
Expand Down Expand Up @@ -3055,6 +3061,7 @@ static int do_init_module(struct module *mod)
mod->strtab = mod->core_strtab;
#endif
unset_module_init_ro_nx(mod);
module_arch_freeing_init(mod);
module_free(mod, mod->module_init);
mod->module_init = NULL;
mod->init_size = 0;
Expand Down

0 comments on commit d453cde

Please sign in to comment.