blob: df649acb563190c36816f26e60a5f3c93b0a89f3 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Kumar Galaf0c426b2008-06-21 02:31:01 +10002/* Kernel module help for powerpc.
3 Copyright (C) 2001, 2003 Rusty Russell IBM Corporation.
4 Copyright (C) 2008 Freescale Semiconductor, Inc.
5
Kumar Galaf0c426b2008-06-21 02:31:01 +10006*/
Kumar Galaf0c426b2008-06-21 02:31:01 +10007#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 Torvalds7c0f6ba2016-12-24 11:46:01 -080013#include <linux/uaccess.h>
Kumar Galaf0c426b2008-06-21 02:31:01 +100014#include <asm/firmware.h>
15#include <linux/sort.h>
Robert Jenningsb88c4762013-10-28 09:20:51 -050016#include <asm/setup.h>
Kumar Galaf0c426b2008-06-21 02:31:01 +100017
Daniel Axtens7c98bd72016-09-06 15:32:40 +100018static LIST_HEAD(module_bug_list);
Kumar Galaf0c426b2008-06-21 02:31:01 +100019
Kumar Galaf0c426b2008-06-21 02:31:01 +100020static 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
34int module_finalize(const Elf_Ehdr *hdr,
35 const Elf_Shdr *sechdrs, struct module *me)
36{
37 const Elf_Shdr *sect;
Michael Ellerman136cd342016-03-03 15:26:54 +110038 int rc;
39
40 rc = module_finalize_ftrace(me, sechdrs);
41 if (rc)
42 return rc;
Kumar Galaf0c426b2008-06-21 02:31:01 +100043
Kumar Galaf0c426b2008-06-21 02:31:01 +100044 /* 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 Herrenschmidt7c03d652008-12-18 19:13:32 +000051 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 Galaf0c426b2008-06-21 02:31:01 +100057#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 Ellerman179ab1c2018-07-28 09:06:34 +100063#endif /* CONFIG_PPC64 */
Michal Suchanek815069c2018-04-24 14:15:56 +100064
Naveen N. Rao59fe7ea2018-05-29 12:21:00 +053065#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 Ellerman179ab1c2018-07-28 09:06:34 +100073#ifdef CONFIG_PPC_BARRIER_NOSPEC
Michal Suchanek815069c2018-04-24 14:15:56 +100074 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 Ellerman179ab1c2018-07-28 09:06:34 +100079#endif /* CONFIG_PPC_BARRIER_NOSPEC */
Kumar Galaf0c426b2008-06-21 02:31:01 +100080
Kumar Gala2d1b2022008-07-02 01:16:40 +100081 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 Galaf0c426b2008-06-21 02:31:01 +100087 return 0;
88}