Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Kumar Gala | f0c426b | 2008-06-21 02:31:01 +1000 | [diff] [blame] | 2 | /* Kernel module help for powerpc. |
| 3 | Copyright (C) 2001, 2003 Rusty Russell IBM Corporation. |
| 4 | Copyright (C) 2008 Freescale Semiconductor, Inc. |
| 5 | |
Kumar Gala | f0c426b | 2008-06-21 02:31:01 +1000 | [diff] [blame] | 6 | */ |
Kumar Gala | f0c426b | 2008-06-21 02:31:01 +1000 | [diff] [blame] | 7 | #include <linux/elf.h> |
| 8 | #include <linux/moduleloader.h> |
| 9 | #include <linux/err.h> |
| 10 | #include <linux/vmalloc.h> |
| 11 | #include <linux/bug.h> |
| 12 | #include <asm/module.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 13 | #include <linux/uaccess.h> |
Kumar Gala | f0c426b | 2008-06-21 02:31:01 +1000 | [diff] [blame] | 14 | #include <asm/firmware.h> |
| 15 | #include <linux/sort.h> |
Robert Jennings | b88c476 | 2013-10-28 09:20:51 -0500 | [diff] [blame] | 16 | #include <asm/setup.h> |
Kumar Gala | f0c426b | 2008-06-21 02:31:01 +1000 | [diff] [blame] | 17 | |
Daniel Axtens | 7c98bd7 | 2016-09-06 15:32:40 +1000 | [diff] [blame] | 18 | static LIST_HEAD(module_bug_list); |
Kumar Gala | f0c426b | 2008-06-21 02:31:01 +1000 | [diff] [blame] | 19 | |
Kumar Gala | f0c426b | 2008-06-21 02:31:01 +1000 | [diff] [blame] | 20 | static const Elf_Shdr *find_section(const Elf_Ehdr *hdr, |
| 21 | const Elf_Shdr *sechdrs, |
| 22 | const char *name) |
| 23 | { |
| 24 | char *secstrings; |
| 25 | unsigned int i; |
| 26 | |
| 27 | secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset; |
| 28 | for (i = 1; i < hdr->e_shnum; i++) |
| 29 | if (strcmp(secstrings+sechdrs[i].sh_name, name) == 0) |
| 30 | return &sechdrs[i]; |
| 31 | return NULL; |
| 32 | } |
| 33 | |
| 34 | int module_finalize(const Elf_Ehdr *hdr, |
| 35 | const Elf_Shdr *sechdrs, struct module *me) |
| 36 | { |
| 37 | const Elf_Shdr *sect; |
Michael Ellerman | 136cd34 | 2016-03-03 15:26:54 +1100 | [diff] [blame] | 38 | int rc; |
| 39 | |
| 40 | rc = module_finalize_ftrace(me, sechdrs); |
| 41 | if (rc) |
| 42 | return rc; |
Kumar Gala | f0c426b | 2008-06-21 02:31:01 +1000 | [diff] [blame] | 43 | |
Kumar Gala | f0c426b | 2008-06-21 02:31:01 +1000 | [diff] [blame] | 44 | /* Apply feature fixups */ |
| 45 | sect = find_section(hdr, sechdrs, "__ftr_fixup"); |
| 46 | if (sect != NULL) |
| 47 | do_feature_fixups(cur_cpu_spec->cpu_features, |
| 48 | (void *)sect->sh_addr, |
| 49 | (void *)sect->sh_addr + sect->sh_size); |
| 50 | |
Benjamin Herrenschmidt | 7c03d65 | 2008-12-18 19:13:32 +0000 | [diff] [blame] | 51 | sect = find_section(hdr, sechdrs, "__mmu_ftr_fixup"); |
| 52 | if (sect != NULL) |
| 53 | do_feature_fixups(cur_cpu_spec->mmu_features, |
| 54 | (void *)sect->sh_addr, |
| 55 | (void *)sect->sh_addr + sect->sh_size); |
| 56 | |
Kumar Gala | f0c426b | 2008-06-21 02:31:01 +1000 | [diff] [blame] | 57 | #ifdef CONFIG_PPC64 |
| 58 | sect = find_section(hdr, sechdrs, "__fw_ftr_fixup"); |
| 59 | if (sect != NULL) |
| 60 | do_feature_fixups(powerpc_firmware_features, |
| 61 | (void *)sect->sh_addr, |
| 62 | (void *)sect->sh_addr + sect->sh_size); |
Michael Ellerman | 179ab1c | 2018-07-28 09:06:34 +1000 | [diff] [blame] | 63 | #endif /* CONFIG_PPC64 */ |
Michal Suchanek | 815069c | 2018-04-24 14:15:56 +1000 | [diff] [blame] | 64 | |
Naveen N. Rao | 59fe7ea | 2018-05-29 12:21:00 +0530 | [diff] [blame] | 65 | #ifdef PPC64_ELF_ABI_v1 |
| 66 | sect = find_section(hdr, sechdrs, ".opd"); |
| 67 | if (sect != NULL) { |
| 68 | me->arch.start_opd = sect->sh_addr; |
| 69 | me->arch.end_opd = sect->sh_addr + sect->sh_size; |
| 70 | } |
| 71 | #endif /* PPC64_ELF_ABI_v1 */ |
| 72 | |
Michael Ellerman | 179ab1c | 2018-07-28 09:06:34 +1000 | [diff] [blame] | 73 | #ifdef CONFIG_PPC_BARRIER_NOSPEC |
Michal Suchanek | 815069c | 2018-04-24 14:15:56 +1000 | [diff] [blame] | 74 | sect = find_section(hdr, sechdrs, "__spec_barrier_fixup"); |
| 75 | if (sect != NULL) |
| 76 | do_barrier_nospec_fixups_range(barrier_nospec_enabled, |
| 77 | (void *)sect->sh_addr, |
| 78 | (void *)sect->sh_addr + sect->sh_size); |
Michael Ellerman | 179ab1c | 2018-07-28 09:06:34 +1000 | [diff] [blame] | 79 | #endif /* CONFIG_PPC_BARRIER_NOSPEC */ |
Kumar Gala | f0c426b | 2008-06-21 02:31:01 +1000 | [diff] [blame] | 80 | |
Kumar Gala | 2d1b202 | 2008-07-02 01:16:40 +1000 | [diff] [blame] | 81 | sect = find_section(hdr, sechdrs, "__lwsync_fixup"); |
| 82 | if (sect != NULL) |
| 83 | do_lwsync_fixups(cur_cpu_spec->cpu_features, |
| 84 | (void *)sect->sh_addr, |
| 85 | (void *)sect->sh_addr + sect->sh_size); |
| 86 | |
Kumar Gala | f0c426b | 2008-06-21 02:31:01 +1000 | [diff] [blame] | 87 | return 0; |
| 88 | } |