1
0

099-module_arch_freeing_init-new-hook-for-archs-before-m.patch 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. From: Rusty Russell <rusty@rustcorp.com.au>
  2. Date: Tue, 20 Jan 2015 09:07:04 +1030
  3. Subject: [PATCH] module_arch_freeing_init(): new hook for archs before module->module_init freed.
  4. Archs have been abusing module_free() to clean up their arch-specific
  5. allocations. Since module_free() is also (ab)used by BPF and trace code,
  6. let's keep it to simple allocations, and provide a hook called before
  7. that.
  8. This means that avr32, ia64, parisc and s390 no longer need to implement
  9. their own module_free() at all. avr32 doesn't need module_finalize()
  10. either.
  11. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  12. Cc: Chris Metcalf <cmetcalf@ezchip.com>
  13. Cc: Haavard Skinnemoen <hskinnemoen@gmail.com>
  14. Cc: Hans-Christian Egtvedt <egtvedt@samfundet.no>
  15. Cc: Tony Luck <tony.luck@intel.com>
  16. Cc: Fenghua Yu <fenghua.yu@intel.com>
  17. Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
  18. Cc: Helge Deller <deller@gmx.de>
  19. Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
  20. Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
  21. Cc: linux-kernel@vger.kernel.org
  22. Cc: linux-ia64@vger.kernel.org
  23. Cc: linux-parisc@vger.kernel.org
  24. Cc: linux-s390@vger.kernel.org
  25. Origin: backport, https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=d453cded05ee219b77815ea194dc36efa5398bca
  26. ---
  27. arch/avr32/kernel/module.c | 13 +------------
  28. arch/ia64/kernel/module.c | 6 ++----
  29. arch/parisc/kernel/module.c | 6 +-----
  30. arch/s390/kernel/module.c | 10 +++-------
  31. arch/tile/kernel/module.c | 2 +-
  32. include/linux/moduleloader.h | 2 ++
  33. kernel/module.c | 7 +++++++
  34. 7 files changed, 17 insertions(+), 29 deletions(-)
  35. --- a/arch/avr32/kernel/module.c
  36. +++ b/arch/avr32/kernel/module.c
  37. @@ -19,12 +19,10 @@
  38. #include <linux/moduleloader.h>
  39. #include <linux/vmalloc.h>
  40. -void module_free(struct module *mod, void *module_region)
  41. +void module_arch_freeing_init(struct module *mod)
  42. {
  43. vfree(mod->arch.syminfo);
  44. mod->arch.syminfo = NULL;
  45. -
  46. - vfree(module_region);
  47. }
  48. static inline int check_rela(Elf32_Rela *rela, struct module *module,
  49. @@ -291,12 +289,3 @@ int apply_relocate_add(Elf32_Shdr *sechd
  50. return ret;
  51. }
  52. -
  53. -int module_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs,
  54. - struct module *module)
  55. -{
  56. - vfree(module->arch.syminfo);
  57. - module->arch.syminfo = NULL;
  58. -
  59. - return 0;
  60. -}
  61. --- a/arch/ia64/kernel/module.c
  62. +++ b/arch/ia64/kernel/module.c
  63. @@ -305,14 +305,12 @@ plt_target (struct plt_entry *plt)
  64. #endif /* !USE_BRL */
  65. void
  66. -module_free (struct module *mod, void *module_region)
  67. +module_arch_freeing_init (struct module *mod)
  68. {
  69. - if (mod && mod->arch.init_unw_table &&
  70. - module_region == mod->module_init) {
  71. + if (mod->arch.init_unw_table) {
  72. unw_remove_unwind_table(mod->arch.init_unw_table);
  73. mod->arch.init_unw_table = NULL;
  74. }
  75. - vfree(module_region);
  76. }
  77. /* Have we already seen one of these relocations? */
  78. --- a/arch/parisc/kernel/module.c
  79. +++ b/arch/parisc/kernel/module.c
  80. @@ -298,14 +298,10 @@ static inline unsigned long count_stubs(
  81. }
  82. #endif
  83. -
  84. -/* Free memory returned from module_alloc */
  85. -void module_free(struct module *mod, void *module_region)
  86. +void module_arch_freeing_init(struct module *mod)
  87. {
  88. kfree(mod->arch.section);
  89. mod->arch.section = NULL;
  90. -
  91. - vfree(module_region);
  92. }
  93. /* Additional bytes needed in front of individual sections */
  94. --- a/arch/s390/kernel/module.c
  95. +++ b/arch/s390/kernel/module.c
  96. @@ -55,14 +55,10 @@ void *module_alloc(unsigned long size)
  97. }
  98. #endif
  99. -/* Free memory returned from module_alloc */
  100. -void module_free(struct module *mod, void *module_region)
  101. +void module_arch_freeing_init(struct module *mod)
  102. {
  103. - if (mod) {
  104. - vfree(mod->arch.syminfo);
  105. - mod->arch.syminfo = NULL;
  106. - }
  107. - vfree(module_region);
  108. + vfree(mod->arch.syminfo);
  109. + mod->arch.syminfo = NULL;
  110. }
  111. static void check_rela(Elf_Rela *rela, struct module *me)
  112. --- a/arch/tile/kernel/module.c
  113. +++ b/arch/tile/kernel/module.c
  114. @@ -83,7 +83,7 @@ void module_free(struct module *mod, voi
  115. 0, 0, 0, NULL, NULL, 0);
  116. /*
  117. - * FIXME: If module_region == mod->module_init, trim exception
  118. + * FIXME: Add module_arch_freeing_init to trim exception
  119. * table entries.
  120. */
  121. }
  122. --- a/include/linux/moduleloader.h
  123. +++ b/include/linux/moduleloader.h
  124. @@ -82,4 +82,6 @@ int module_finalize(const Elf_Ehdr *hdr,
  125. /* Any cleanup needed when module leaves. */
  126. void module_arch_cleanup(struct module *mod);
  127. +/* Any cleanup before freeing mod->module_init */
  128. +void module_arch_freeing_init(struct module *mod);
  129. #endif
  130. --- a/kernel/module.c
  131. +++ b/kernel/module.c
  132. @@ -1840,6 +1840,10 @@ void __weak module_arch_cleanup(struct m
  133. {
  134. }
  135. +void __weak module_arch_freeing_init(struct module *mod)
  136. +{
  137. +}
  138. +
  139. /* Free a module, remove from lists, etc. */
  140. static void free_module(struct module *mod)
  141. {
  142. @@ -1872,6 +1876,7 @@ static void free_module(struct module *m
  143. /* This may be NULL, but that's OK */
  144. unset_module_init_ro_nx(mod);
  145. + module_arch_freeing_init(mod);
  146. module_free(mod, mod->module_init);
  147. kfree(mod->args);
  148. percpu_modfree(mod);
  149. @@ -2983,6 +2988,7 @@ static struct module *layout_and_allocat
  150. static void module_deallocate(struct module *mod, struct load_info *info)
  151. {
  152. percpu_modfree(mod);
  153. + module_arch_freeing_init(mod);
  154. module_free(mod, mod->module_init);
  155. module_free(mod, mod->module_core);
  156. }
  157. @@ -3105,6 +3111,7 @@ static int do_init_module(struct module
  158. rcu_assign_pointer(mod->kallsyms, &mod->core_kallsyms);
  159. #endif
  160. unset_module_init_ro_nx(mod);
  161. + module_arch_freeing_init(mod);
  162. module_free(mod, mod->module_init);
  163. mod->module_init = NULL;
  164. mod->init_size = 0;