~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/powerpc/kernel/module.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/powerpc/kernel/module.c (Version linux-6.12-rc7) and /arch/sparc/kernel/module.c (Version linux-5.9.16)


  1 // SPDX-License-Identifier: GPL-2.0-or-later   !!   1 // SPDX-License-Identifier: GPL-2.0
  2 /*  Kernel module help for powerpc.            !!   2 /* Kernel module help for sparc64.
  3     Copyright (C) 2001, 2003 Rusty Russell IBM !!   3  *
  4     Copyright (C) 2008 Freescale Semiconductor !!   4  * Copyright (C) 2001 Rusty Russell.
                                                   >>   5  * Copyright (C) 2002 David S. Miller.
                                                   >>   6  */
  5                                                     7 
  6 */                                             << 
  7 #include <linux/elf.h>                         << 
  8 #include <linux/moduleloader.h>                     8 #include <linux/moduleloader.h>
  9 #include <linux/err.h>                         !!   9 #include <linux/kernel.h>
                                                   >>  10 #include <linux/elf.h>
                                                   >>  11 #include <linux/vmalloc.h>
                                                   >>  12 #include <linux/fs.h>
                                                   >>  13 #include <linux/gfp.h>
                                                   >>  14 #include <linux/string.h>
                                                   >>  15 #include <linux/ctype.h>
 10 #include <linux/mm.h>                              16 #include <linux/mm.h>
 11 #include <linux/bug.h>                         !!  17 
 12 #include <asm/module.h>                        !!  18 #include <asm/processor.h>
 13 #include <linux/uaccess.h>                     !!  19 #include <asm/spitfire.h>
 14 #include <asm/firmware.h>                      !!  20 #include <asm/cacheflush.h>
 15 #include <linux/sort.h>                        !!  21 
 16 #include <asm/setup.h>                         !!  22 #include "entry.h"
 17 #include <asm/sections.h>                      !!  23 
 18                                                !!  24 #ifdef CONFIG_SPARC64
 19 static const Elf_Shdr *find_section(const Elf_ !!  25 
 20                                     const Elf_ !!  26 #include <linux/jump_label.h>
 21                                     const char !!  27 
                                                   >>  28 static void *module_map(unsigned long size)
                                                   >>  29 {
                                                   >>  30         if (PAGE_ALIGN(size) > MODULES_LEN)
                                                   >>  31                 return NULL;
                                                   >>  32         return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
                                                   >>  33                                 GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE,
                                                   >>  34                                 __builtin_return_address(0));
                                                   >>  35 }
                                                   >>  36 #else
                                                   >>  37 static void *module_map(unsigned long size)
                                                   >>  38 {
                                                   >>  39         return vmalloc(size);
                                                   >>  40 }
                                                   >>  41 #endif /* CONFIG_SPARC64 */
                                                   >>  42 
                                                   >>  43 void *module_alloc(unsigned long size)
                                                   >>  44 {
                                                   >>  45         void *ret;
                                                   >>  46 
                                                   >>  47         ret = module_map(size);
                                                   >>  48         if (ret)
                                                   >>  49                 memset(ret, 0, size);
                                                   >>  50 
                                                   >>  51         return ret;
                                                   >>  52 }
                                                   >>  53 
                                                   >>  54 /* Make generic code ignore STT_REGISTER dummy undefined symbols.  */
                                                   >>  55 int module_frob_arch_sections(Elf_Ehdr *hdr,
                                                   >>  56                               Elf_Shdr *sechdrs,
                                                   >>  57                               char *secstrings,
                                                   >>  58                               struct module *mod)
                                                   >>  59 {
                                                   >>  60         unsigned int symidx;
                                                   >>  61         Elf_Sym *sym;
                                                   >>  62         char *strtab;
                                                   >>  63         int i;
                                                   >>  64 
                                                   >>  65         for (symidx = 0; sechdrs[symidx].sh_type != SHT_SYMTAB; symidx++) {
                                                   >>  66                 if (symidx == hdr->e_shnum-1) {
                                                   >>  67                         printk("%s: no symtab found.\n", mod->name);
                                                   >>  68                         return -ENOEXEC;
                                                   >>  69                 }
                                                   >>  70         }
                                                   >>  71         sym = (Elf_Sym *)sechdrs[symidx].sh_addr;
                                                   >>  72         strtab = (char *)sechdrs[sechdrs[symidx].sh_link].sh_addr;
                                                   >>  73 
                                                   >>  74         for (i = 1; i < sechdrs[symidx].sh_size / sizeof(Elf_Sym); i++) {
                                                   >>  75                 if (sym[i].st_shndx == SHN_UNDEF) {
                                                   >>  76                         if (ELF_ST_TYPE(sym[i].st_info) == STT_REGISTER)
                                                   >>  77                                 sym[i].st_shndx = SHN_ABS;
                                                   >>  78                 }
                                                   >>  79         }
                                                   >>  80         return 0;
                                                   >>  81 }
                                                   >>  82 
                                                   >>  83 int apply_relocate_add(Elf_Shdr *sechdrs,
                                                   >>  84                        const char *strtab,
                                                   >>  85                        unsigned int symindex,
                                                   >>  86                        unsigned int relsec,
                                                   >>  87                        struct module *me)
 22 {                                                  88 {
 23         char *secstrings;                      << 
 24         unsigned int i;                            89         unsigned int i;
                                                   >>  90         Elf_Rela *rel = (void *)sechdrs[relsec].sh_addr;
                                                   >>  91         Elf_Sym *sym;
                                                   >>  92         u8 *location;
                                                   >>  93         u32 *loc32;
                                                   >>  94 
                                                   >>  95         for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
                                                   >>  96                 Elf_Addr v;
                                                   >>  97 
                                                   >>  98                 /* This is where to make the change */
                                                   >>  99                 location = (u8 *)sechdrs[sechdrs[relsec].sh_info].sh_addr
                                                   >> 100                         + rel[i].r_offset;
                                                   >> 101                 loc32 = (u32 *) location;
                                                   >> 102 
                                                   >> 103 #ifdef CONFIG_SPARC64
                                                   >> 104                 BUG_ON(((u64)location >> (u64)32) != (u64)0);
                                                   >> 105 #endif /* CONFIG_SPARC64 */
                                                   >> 106 
                                                   >> 107                 /* This is the symbol it is referring to.  Note that all
                                                   >> 108                    undefined symbols have been resolved.  */
                                                   >> 109                 sym = (Elf_Sym *)sechdrs[symindex].sh_addr
                                                   >> 110                         + ELF_R_SYM(rel[i].r_info);
                                                   >> 111                 v = sym->st_value + rel[i].r_addend;
                                                   >> 112 
                                                   >> 113                 switch (ELF_R_TYPE(rel[i].r_info) & 0xff) {
                                                   >> 114                 case R_SPARC_DISP32:
                                                   >> 115                         v -= (Elf_Addr) location;
                                                   >> 116                         *loc32 = v;
                                                   >> 117                         break;
                                                   >> 118 #ifdef CONFIG_SPARC64
                                                   >> 119                 case R_SPARC_64:
                                                   >> 120                         location[0] = v >> 56;
                                                   >> 121                         location[1] = v >> 48;
                                                   >> 122                         location[2] = v >> 40;
                                                   >> 123                         location[3] = v >> 32;
                                                   >> 124                         location[4] = v >> 24;
                                                   >> 125                         location[5] = v >> 16;
                                                   >> 126                         location[6] = v >>  8;
                                                   >> 127                         location[7] = v >>  0;
                                                   >> 128                         break;
                                                   >> 129 
                                                   >> 130                 case R_SPARC_WDISP19:
                                                   >> 131                         v -= (Elf_Addr) location;
                                                   >> 132                         *loc32 = (*loc32 & ~0x7ffff) |
                                                   >> 133                                 ((v >> 2) & 0x7ffff);
                                                   >> 134                         break;
                                                   >> 135 
                                                   >> 136                 case R_SPARC_OLO10:
                                                   >> 137                         *loc32 = (*loc32 & ~0x1fff) |
                                                   >> 138                                 (((v & 0x3ff) +
                                                   >> 139                                   (ELF_R_TYPE(rel[i].r_info) >> 8))
                                                   >> 140                                  & 0x1fff);
                                                   >> 141                         break;
                                                   >> 142 #endif /* CONFIG_SPARC64 */
                                                   >> 143 
                                                   >> 144                 case R_SPARC_32:
                                                   >> 145                 case R_SPARC_UA32:
                                                   >> 146                         location[0] = v >> 24;
                                                   >> 147                         location[1] = v >> 16;
                                                   >> 148                         location[2] = v >>  8;
                                                   >> 149                         location[3] = v >>  0;
                                                   >> 150                         break;
                                                   >> 151 
                                                   >> 152                 case R_SPARC_WDISP30:
                                                   >> 153                         v -= (Elf_Addr) location;
                                                   >> 154                         *loc32 = (*loc32 & ~0x3fffffff) |
                                                   >> 155                                 ((v >> 2) & 0x3fffffff);
                                                   >> 156                         break;
                                                   >> 157 
                                                   >> 158                 case R_SPARC_WDISP22:
                                                   >> 159                         v -= (Elf_Addr) location;
                                                   >> 160                         *loc32 = (*loc32 & ~0x3fffff) |
                                                   >> 161                                 ((v >> 2) & 0x3fffff);
                                                   >> 162                         break;
                                                   >> 163 
                                                   >> 164                 case R_SPARC_LO10:
                                                   >> 165                         *loc32 = (*loc32 & ~0x3ff) | (v & 0x3ff);
                                                   >> 166                         break;
                                                   >> 167 
                                                   >> 168                 case R_SPARC_HI22:
                                                   >> 169                         *loc32 = (*loc32 & ~0x3fffff) |
                                                   >> 170                                 ((v >> 10) & 0x3fffff);
                                                   >> 171                         break;
                                                   >> 172 
                                                   >> 173                 default:
                                                   >> 174                         printk(KERN_ERR "module %s: Unknown relocation: %x\n",
                                                   >> 175                                me->name,
                                                   >> 176                                (int) (ELF_R_TYPE(rel[i].r_info) & 0xff));
                                                   >> 177                         return -ENOEXEC;
                                                   >> 178                 }
                                                   >> 179         }
                                                   >> 180         return 0;
                                                   >> 181 }
 25                                                   182 
 26         secstrings = (char *)hdr + sechdrs[hdr !! 183 #ifdef CONFIG_SPARC64
 27         for (i = 1; i < hdr->e_shnum; i++)     !! 184 static void do_patch_sections(const Elf_Ehdr *hdr,
 28                 if (strcmp(secstrings+sechdrs[ !! 185                               const Elf_Shdr *sechdrs)
 29                         return &sechdrs[i];    !! 186 {
 30         return NULL;                           !! 187         const Elf_Shdr *s, *sun4v_1insn = NULL, *sun4v_2insn = NULL;
                                                   >> 188         char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
                                                   >> 189 
                                                   >> 190         for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
                                                   >> 191                 if (!strcmp(".sun4v_1insn_patch", secstrings + s->sh_name))
                                                   >> 192                         sun4v_1insn = s;
                                                   >> 193                 if (!strcmp(".sun4v_2insn_patch", secstrings + s->sh_name))
                                                   >> 194                         sun4v_2insn = s;
                                                   >> 195         }
                                                   >> 196 
                                                   >> 197         if (sun4v_1insn && tlb_type == hypervisor) {
                                                   >> 198                 void *p = (void *) sun4v_1insn->sh_addr;
                                                   >> 199                 sun4v_patch_1insn_range(p, p + sun4v_1insn->sh_size);
                                                   >> 200         }
                                                   >> 201         if (sun4v_2insn && tlb_type == hypervisor) {
                                                   >> 202                 void *p = (void *) sun4v_2insn->sh_addr;
                                                   >> 203                 sun4v_patch_2insn_range(p, p + sun4v_2insn->sh_size);
                                                   >> 204         }
 31 }                                                 205 }
 32                                                   206 
 33 int module_finalize(const Elf_Ehdr *hdr,          207 int module_finalize(const Elf_Ehdr *hdr,
 34                 const Elf_Shdr *sechdrs, struc !! 208                     const Elf_Shdr *sechdrs,
                                                   >> 209                     struct module *me)
 35 {                                                 210 {
 36         const Elf_Shdr *sect;                  !! 211         /* make jump label nops */
 37         int rc;                                !! 212         jump_label_apply_nops(me);
 38                                                   213 
 39         rc = module_finalize_ftrace(me, sechdr !! 214         do_patch_sections(hdr, sechdrs);
 40         if (rc)                                !! 215 
 41                 return rc;                     !! 216         /* Cheetah's I-cache is fully coherent.  */
 42                                                !! 217         if (tlb_type == spitfire) {
 43         /* Apply feature fixups */             !! 218                 unsigned long va;
 44         sect = find_section(hdr, sechdrs, "__f !! 219 
 45         if (sect != NULL)                      !! 220                 flushw_all();
 46                 do_feature_fixups(cur_cpu_spec !! 221                 for (va =  0; va < (PAGE_SIZE << 1); va += 32)
 47                                   (void *)sect !! 222                         spitfire_put_icache_tag(va, 0x0);
 48                                   (void *)sect !! 223                 __asm__ __volatile__("flush %g6");
 49                                                !! 224         }
 50         sect = find_section(hdr, sechdrs, "__m << 
 51         if (sect != NULL)                      << 
 52                 do_feature_fixups(cur_cpu_spec << 
 53                                   (void *)sect << 
 54                                   (void *)sect << 
 55                                                << 
 56 #ifdef CONFIG_PPC64                            << 
 57         sect = find_section(hdr, sechdrs, "__f << 
 58         if (sect != NULL)                      << 
 59                 do_feature_fixups(powerpc_firm << 
 60                                   (void *)sect << 
 61                                   (void *)sect << 
 62 #endif /* CONFIG_PPC64 */                      << 
 63                                                << 
 64 #ifdef CONFIG_PPC64_ELF_ABI_V1                 << 
 65         sect = find_section(hdr, sechdrs, ".op << 
 66         if (sect != NULL) {                    << 
 67                 me->arch.start_opd = sect->sh_ << 
 68                 me->arch.end_opd = sect->sh_ad << 
 69         }                                      << 
 70 #endif /* CONFIG_PPC64_ELF_ABI_V1 */           << 
 71                                                << 
 72 #ifdef CONFIG_PPC_BARRIER_NOSPEC               << 
 73         sect = find_section(hdr, sechdrs, "__s << 
 74         if (sect != NULL)                      << 
 75                 do_barrier_nospec_fixups_range << 
 76                                   (void *)sect << 
 77                                   (void *)sect << 
 78 #endif /* CONFIG_PPC_BARRIER_NOSPEC */         << 
 79                                                << 
 80         sect = find_section(hdr, sechdrs, "__l << 
 81         if (sect != NULL)                      << 
 82                 do_lwsync_fixups(cur_cpu_spec- << 
 83                                  (void *)sect- << 
 84                                  (void *)sect- << 
 85                                                   225 
 86         return 0;                                 226         return 0;
 87 }                                                 227 }
                                                   >> 228 #endif /* CONFIG_SPARC64 */
 88                                                   229 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php