1 --- a/arch/mips/include/asm/module.h
2 +++ b/arch/mips/include/asm/module.h
3 @@ -9,11 +9,6 @@ struct mod_arch_specific {
4 struct list_head dbe_list;
5 const struct exception_table_entry *dbe_start;
6 const struct exception_table_entry *dbe_end;
10 - unsigned int phys_plt_offset;
11 - unsigned int virt_plt_offset;
14 typedef uint8_t Elf64_Byte; /* Type for a 8-bit quantity. */
15 --- a/arch/mips/kernel/module.c
16 +++ b/arch/mips/kernel/module.c
17 @@ -45,117 +45,6 @@ static struct mips_hi16 *mips_hi16_list;
18 static LIST_HEAD(dbe_list);
19 static DEFINE_SPINLOCK(dbe_lock);
22 - * Get the potential max trampolines size required of the init and
23 - * non-init sections. Only used if we cannot find enough contiguous
24 - * physically mapped memory to put the module into.
27 -get_plt_size(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs,
28 - const char *secstrings, unsigned int symindex, bool is_init)
30 - unsigned long ret = 0;
34 - /* Everything marked ALLOC (this includes the exported symbols) */
35 - for (i = 1; i < hdr->e_shnum; ++i) {
36 - unsigned int info = sechdrs[i].sh_info;
38 - if (sechdrs[i].sh_type != SHT_REL
39 - && sechdrs[i].sh_type != SHT_RELA)
42 - /* Not a valid relocation section? */
43 - if (info >= hdr->e_shnum)
46 - /* Don't bother with non-allocated sections */
47 - if (!(sechdrs[info].sh_flags & SHF_ALLOC))
50 - /* If it's called *.init*, and we're not init, we're
52 - if ((strstr(secstrings + sechdrs[i].sh_name, ".init") != 0)
56 - syms = (Elf_Sym *) sechdrs[symindex].sh_addr;
57 - if (sechdrs[i].sh_type == SHT_REL) {
58 - Elf_Mips_Rel *rel = (void *) sechdrs[i].sh_addr;
59 - unsigned int size = sechdrs[i].sh_size / sizeof(*rel);
61 - for (j = 0; j < size; ++j) {
64 - if (ELF_MIPS_R_TYPE(rel[j]) != R_MIPS_26)
67 - sym = syms + ELF_MIPS_R_SYM(rel[j]);
68 - if (!is_init && sym->st_shndx != SHN_UNDEF)
71 - ret += 4 * sizeof(int);
74 - Elf_Mips_Rela *rela = (void *) sechdrs[i].sh_addr;
75 - unsigned int size = sechdrs[i].sh_size / sizeof(*rela);
77 - for (j = 0; j < size; ++j) {
80 - if (ELF_MIPS_R_TYPE(rela[j]) != R_MIPS_26)
83 - sym = syms + ELF_MIPS_R_SYM(rela[j]);
84 - if (!is_init && sym->st_shndx != SHN_UNDEF)
87 - ret += 4 * sizeof(int);
96 -static void *alloc_phys(unsigned long size)
102 - size = PAGE_ALIGN(size);
103 - order = get_order(size);
105 - page = alloc_pages(GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN |
106 - __GFP_THISNODE, order);
110 - split_page(page, order);
112 - for (p = page + (size >> PAGE_SHIFT); p < page + (1 << order); ++p)
115 - return page_address(page);
119 -static void free_phys(void *ptr, unsigned long size)
124 - page = virt_to_page(ptr);
125 - end = page + (PAGE_ALIGN(size) >> PAGE_SHIFT);
127 - for (; page < end; ++page)
132 void *module_alloc(unsigned long size)
135 @@ -163,99 +52,21 @@ void *module_alloc(unsigned long size)
136 GFP_KERNEL, PAGE_KERNEL, -1,
137 __builtin_return_address(0));
144 - ptr = alloc_phys(size);
146 - /* If we failed to allocate physically contiguous memory,
147 - * fall back to regular vmalloc. The module loader code will
148 - * create jump tables to handle long jumps */
150 - return vmalloc(size);
156 -static inline bool is_phys_addr(void *ptr)
159 - return (KSEGX((unsigned long)ptr) == CKSEG0);
161 - return (KSEGX(ptr) == KSEG0);
162 + return vmalloc(size);
166 /* Free memory returned from module_alloc */
167 void module_free(struct module *mod, void *module_region)
169 - if (is_phys_addr(module_region)) {
170 - if (mod->module_init == module_region)
171 - free_phys(module_region, mod->init_size);
172 - else if (mod->module_core == module_region)
173 - free_phys(module_region, mod->core_size);
177 - vfree(module_region);
181 -static void *__module_alloc(int size, bool phys)
186 - ptr = kmalloc(size, GFP_KERNEL);
188 - ptr = vmalloc(size);
192 -static void __module_free(void *ptr)
194 - if (is_phys_addr(ptr))
198 + vfree(module_region);
201 int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
202 char *secstrings, struct module *mod)
204 - unsigned int symindex = 0;
205 - unsigned int core_size, init_size;
208 - for (i = 1; i < hdr->e_shnum; i++)
209 - if (sechdrs[i].sh_type == SHT_SYMTAB)
212 - core_size = get_plt_size(hdr, sechdrs, secstrings, symindex, false);
213 - init_size = get_plt_size(hdr, sechdrs, secstrings, symindex, true);
215 - mod->arch.phys_plt_offset = 0;
216 - mod->arch.virt_plt_offset = 0;
217 - mod->arch.phys_plt_tbl = NULL;
218 - mod->arch.virt_plt_tbl = NULL;
220 - if ((core_size + init_size) == 0)
223 - mod->arch.phys_plt_tbl = __module_alloc(core_size + init_size, 1);
224 - if (!mod->arch.phys_plt_tbl)
227 - mod->arch.virt_plt_tbl = __module_alloc(core_size + init_size, 0);
228 - if (!mod->arch.virt_plt_tbl) {
229 - __module_free(mod->arch.phys_plt_tbl);
230 - mod->arch.phys_plt_tbl = NULL;
237 @@ -278,36 +89,28 @@ static int apply_r_mips_32_rela(struct m
241 -static Elf_Addr add_plt_entry_to(unsigned *plt_offset,
242 - void *start, Elf_Addr v)
243 +static int apply_r_mips_26_rel(struct module *me, u32 *location, Elf_Addr v)
245 - unsigned *tramp = start + *plt_offset;
246 - *plt_offset += 4 * sizeof(int);
248 - /* adjust carry for addiu */
249 - if (v & 0x00008000)
252 - tramp[0] = 0x3c190000 | (v >> 16); /* lui t9, hi16 */
253 - tramp[1] = 0x27390000 | (v & 0xffff); /* addiu t9, t9, lo16 */
254 - tramp[2] = 0x03200008; /* jr t9 */
255 - tramp[3] = 0x00000000; /* nop */
257 + pr_err("module %s: dangerous R_MIPS_26 REL relocation\n",
262 - return (Elf_Addr) tramp;
264 + if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) {
266 + "module %s: relocation overflow\n",
271 -static Elf_Addr add_plt_entry(struct module *me, void *location, Elf_Addr v)
273 - if (is_phys_addr(location))
274 - return add_plt_entry_to(&me->arch.phys_plt_offset,
275 - me->arch.phys_plt_tbl, v);
277 - return add_plt_entry_to(&me->arch.virt_plt_offset,
278 - me->arch.virt_plt_tbl, v);
279 + *location = (*location & ~0x03ffffff) |
280 + ((*location + (v >> 2)) & 0x03ffffff);
285 -static int set_r_mips_26(struct module *me, u32 *location, u32 ofs, Elf_Addr v)
286 +static int apply_r_mips_26_rela(struct module *me, u32 *location, Elf_Addr v)
289 pr_err("module %s: dangerous R_MIPS_26 RELArelocation\n",
290 @@ -316,31 +119,17 @@ static int set_r_mips_26(struct module *
293 if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) {
294 - v = add_plt_entry(me, location, v + (ofs << 2));
298 "module %s: relocation overflow\n",
306 - *location = (*location & ~0x03ffffff) | ((ofs + (v >> 2)) & 0x03ffffff);
307 + *location = (*location & ~0x03ffffff) | ((v >> 2) & 0x03ffffff);
312 -static int apply_r_mips_26_rel(struct module *me, u32 *location, Elf_Addr v)
314 - return set_r_mips_26(me, location, *location & 0x03ffffff, v);
317 -static int apply_r_mips_26_rela(struct module *me, u32 *location, Elf_Addr v)
319 - return set_r_mips_26(me, location, 0, v);
322 static int apply_r_mips_hi16_rel(struct module *me, u32 *location, Elf_Addr v)
325 @@ -608,32 +397,11 @@ int module_finalize(const Elf_Ehdr *hdr,
326 list_add(&me->arch.dbe_list, &dbe_list);
327 spin_unlock_irq(&dbe_lock);
330 - /* Get rid of the fixup trampoline if we're running the module
331 - * from physically mapped address space */
332 - if (me->arch.phys_plt_offset == 0) {
333 - __module_free(me->arch.phys_plt_tbl);
334 - me->arch.phys_plt_tbl = NULL;
336 - if (me->arch.virt_plt_offset == 0) {
337 - __module_free(me->arch.virt_plt_tbl);
338 - me->arch.virt_plt_tbl = NULL;
344 void module_arch_cleanup(struct module *mod)
346 - if (mod->arch.phys_plt_tbl) {
347 - __module_free(mod->arch.phys_plt_tbl);
348 - mod->arch.phys_plt_tbl = NULL;
350 - if (mod->arch.virt_plt_tbl) {
351 - __module_free(mod->arch.virt_plt_tbl);
352 - mod->arch.virt_plt_tbl = NULL;
355 spin_lock_irq(&dbe_lock);
356 list_del(&mod->arch.dbe_list);
357 spin_unlock_irq(&dbe_lock);
358 --- a/arch/mips/Makefile
359 +++ b/arch/mips/Makefile
360 @@ -90,8 +90,8 @@ all-$(CONFIG_SYS_SUPPORTS_ZBOOT)+= vmlin
361 cflags-y += -G 0 -mno-abicalls -fno-pic -pipe
362 cflags-y += -msoft-float
363 LDFLAGS_vmlinux += -G 0 -static -n -nostdlib
364 -KBUILD_AFLAGS_MODULE += -mno-long-calls
365 -KBUILD_CFLAGS_MODULE += -mno-long-calls
366 +KBUILD_AFLAGS_MODULE += -mlong-calls
367 +KBUILD_CFLAGS_MODULE += -mlong-calls
369 cflags-y += -ffreestanding