Merge tag 'modules-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof...
[linux-block.git] / arch / powerpc / kernel / module.c
CommitLineData
1a59d1b8 1// SPDX-License-Identifier: GPL-2.0-or-later
f0c426bc
KG
2/* Kernel module help for powerpc.
3 Copyright (C) 2001, 2003 Rusty Russell IBM Corporation.
4 Copyright (C) 2008 Freescale Semiconductor, Inc.
5
f0c426bc 6*/
f0c426bc
KG
7#include <linux/elf.h>
8#include <linux/moduleloader.h>
9#include <linux/err.h>
8abddd96 10#include <linux/mm.h>
f0c426bc
KG
11#include <linux/bug.h>
12#include <asm/module.h>
7c0f6ba6 13#include <linux/uaccess.h>
f0c426bc
KG
14#include <asm/firmware.h>
15#include <linux/sort.h>
b88c4767 16#include <asm/setup.h>
2ec13df1 17#include <asm/sections.h>
f0c426bc 18
7c98bd72 19static LIST_HEAD(module_bug_list);
f0c426bc 20
f0c426bc
KG
21static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
22 const Elf_Shdr *sechdrs,
23 const char *name)
24{
25 char *secstrings;
26 unsigned int i;
27
28 secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
29 for (i = 1; i < hdr->e_shnum; i++)
30 if (strcmp(secstrings+sechdrs[i].sh_name, name) == 0)
31 return &sechdrs[i];
32 return NULL;
33}
34
35int module_finalize(const Elf_Ehdr *hdr,
36 const Elf_Shdr *sechdrs, struct module *me)
37{
38 const Elf_Shdr *sect;
136cd345
ME
39 int rc;
40
41 rc = module_finalize_ftrace(me, sechdrs);
42 if (rc)
43 return rc;
f0c426bc 44
f0c426bc
KG
45 /* Apply feature fixups */
46 sect = find_section(hdr, sechdrs, "__ftr_fixup");
47 if (sect != NULL)
48 do_feature_fixups(cur_cpu_spec->cpu_features,
49 (void *)sect->sh_addr,
50 (void *)sect->sh_addr + sect->sh_size);
51
7c03d653
BH
52 sect = find_section(hdr, sechdrs, "__mmu_ftr_fixup");
53 if (sect != NULL)
54 do_feature_fixups(cur_cpu_spec->mmu_features,
55 (void *)sect->sh_addr,
56 (void *)sect->sh_addr + sect->sh_size);
57
f0c426bc
KG
58#ifdef CONFIG_PPC64
59 sect = find_section(hdr, sechdrs, "__fw_ftr_fixup");
60 if (sect != NULL)
61 do_feature_fixups(powerpc_firmware_features,
62 (void *)sect->sh_addr,
63 (void *)sect->sh_addr + sect->sh_size);
179ab1cb 64#endif /* CONFIG_PPC64 */
815069ca 65
7d40aff8 66#ifdef CONFIG_PPC64_ELF_ABI_V1
59fe7eaf
NR
67 sect = find_section(hdr, sechdrs, ".opd");
68 if (sect != NULL) {
69 me->arch.start_opd = sect->sh_addr;
70 me->arch.end_opd = sect->sh_addr + sect->sh_size;
71 }
7d40aff8 72#endif /* CONFIG_PPC64_ELF_ABI_V1 */
59fe7eaf 73
179ab1cb 74#ifdef CONFIG_PPC_BARRIER_NOSPEC
815069ca
MS
75 sect = find_section(hdr, sechdrs, "__spec_barrier_fixup");
76 if (sect != NULL)
77 do_barrier_nospec_fixups_range(barrier_nospec_enabled,
78 (void *)sect->sh_addr,
79 (void *)sect->sh_addr + sect->sh_size);
179ab1cb 80#endif /* CONFIG_PPC_BARRIER_NOSPEC */
f0c426bc 81
2d1b2027
KG
82 sect = find_section(hdr, sechdrs, "__lwsync_fixup");
83 if (sect != NULL)
84 do_lwsync_fixups(cur_cpu_spec->cpu_features,
85 (void *)sect->sh_addr,
86 (void *)sect->sh_addr + sect->sh_size);
87
f0c426bc
KG
88 return 0;
89}