Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Copyright (C) 2001 Rusty Russell.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 2003, 2004 Ralf Baechle (ralf@linux-mips.org)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (C) 2005 Thiemo Seufer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #undef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/extable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/moduleloader.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/numa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/jump_label.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) struct mips_hi16 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct mips_hi16 *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	Elf_Addr *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	Elf_Addr value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static LIST_HEAD(dbe_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static DEFINE_SPINLOCK(dbe_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #ifdef MODULE_START
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) void *module_alloc(unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	return __vmalloc_node_range(size, 1, MODULE_START, MODULE_END,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 				GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 				__builtin_return_address(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static int apply_r_mips_none(struct module *me, u32 *location,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 			     u32 base, Elf_Addr v, bool rela)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static int apply_r_mips_32(struct module *me, u32 *location,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 			   u32 base, Elf_Addr v, bool rela)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	*location = base + v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) static int apply_r_mips_26(struct module *me, u32 *location,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			   u32 base, Elf_Addr v, bool rela)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (v % 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		pr_err("module %s: dangerous R_MIPS_26 relocation\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		       me->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		pr_err("module %s: relocation overflow\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		       me->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	*location = (*location & ~0x03ffffff) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		    ((base + (v >> 2)) & 0x03ffffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static int apply_r_mips_hi16(struct module *me, u32 *location,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			     u32 base, Elf_Addr v, bool rela)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct mips_hi16 *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (rela) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		*location = (*location & 0xffff0000) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			    ((((long long) v + 0x8000LL) >> 16) & 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	 * We cannot relocate this one now because we don't know the value of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	 * the carry we need to add.  Save the information, and let LO16 do the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	 * actual relocation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	n = kmalloc(sizeof *n, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (!n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	n->addr = (Elf_Addr *)location;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	n->value = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	n->next = me->arch.r_mips_hi16_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	me->arch.r_mips_hi16_list = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static void free_relocation_chain(struct mips_hi16 *l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct mips_hi16 *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	while (l) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		next = l->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		kfree(l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		l = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static int apply_r_mips_lo16(struct module *me, u32 *location,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			     u32 base, Elf_Addr v, bool rela)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	unsigned long insnlo = base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct mips_hi16 *l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	Elf_Addr val, vallo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (rela) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		*location = (*location & 0xffff0000) | (v & 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	/* Sign extend the addend we extract from the lo insn.	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	vallo = ((insnlo & 0xffff) ^ 0x8000) - 0x8000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	if (me->arch.r_mips_hi16_list != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		l = me->arch.r_mips_hi16_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		while (l != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			struct mips_hi16 *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			unsigned long insn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			 * The value for the HI16 had best be the same.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			if (v != l->value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				goto out_danger;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			 * Do the HI16 relocation.  Note that we actually don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			 * need to know anything about the LO16 itself, except
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			 * where to find the low 16 bits of the addend needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			 * by the LO16.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			insn = *l->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			val = ((insn & 0xffff) << 16) + vallo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			val += v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			 * Account for the sign extension that will happen in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			 * the low bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			val = ((val >> 16) + ((val & 0x8000) != 0)) & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			insn = (insn & ~0xffff) | val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			*l->addr = insn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			next = l->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			kfree(l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			l = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		me->arch.r_mips_hi16_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	 * Ok, we're done with the HI16 relocs.	 Now deal with the LO16.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	val = v + vallo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	insnlo = (insnlo & ~0xffff) | (val & 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	*location = insnlo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) out_danger:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	free_relocation_chain(l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	me->arch.r_mips_hi16_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	pr_err("module %s: dangerous R_MIPS_LO16 relocation\n", me->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static int apply_r_mips_pc(struct module *me, u32 *location, u32 base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			   Elf_Addr v, unsigned int bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	unsigned long mask = GENMASK(bits - 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	unsigned long se_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	long offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if (v % 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		pr_err("module %s: dangerous R_MIPS_PC%u relocation\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		       me->name, bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	/* retrieve & sign extend implicit addend if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	offset = base & mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	offset |= (offset & BIT(bits - 1)) ? ~mask : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	offset += ((long)v - (long)location) >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	/* check the sign bit onwards are identical - ie. we didn't overflow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	se_bits = (offset & BIT(bits - 1)) ? ~0ul : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if ((offset & ~mask) != (se_bits & ~mask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		pr_err("module %s: relocation overflow\n", me->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		return -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	*location = (*location & ~mask) | (offset & mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static int apply_r_mips_pc16(struct module *me, u32 *location,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			     u32 base, Elf_Addr v, bool rela)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	return apply_r_mips_pc(me, location, base, v, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static int apply_r_mips_pc21(struct module *me, u32 *location,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			     u32 base, Elf_Addr v, bool rela)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	return apply_r_mips_pc(me, location, base, v, 21);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static int apply_r_mips_pc26(struct module *me, u32 *location,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			     u32 base, Elf_Addr v, bool rela)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	return apply_r_mips_pc(me, location, base, v, 26);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static int apply_r_mips_64(struct module *me, u32 *location,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			   u32 base, Elf_Addr v, bool rela)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (WARN_ON(!rela))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	*(Elf_Addr *)location = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static int apply_r_mips_higher(struct module *me, u32 *location,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			       u32 base, Elf_Addr v, bool rela)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (WARN_ON(!rela))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	*location = (*location & 0xffff0000) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		    ((((long long)v + 0x80008000LL) >> 32) & 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static int apply_r_mips_highest(struct module *me, u32 *location,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 				u32 base, Elf_Addr v, bool rela)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (WARN_ON(!rela))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	*location = (*location & 0xffff0000) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		    ((((long long)v + 0x800080008000LL) >> 48) & 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  * reloc_handler() - Apply a particular relocation to a module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)  * @me: the module to apply the reloc to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)  * @location: the address at which the reloc is to be applied
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)  * @base: the existing value at location for REL-style; 0 for RELA-style
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)  * @v: the value of the reloc, with addend for RELA-style
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)  * Each implemented reloc_handler function applies a particular type of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)  * relocation to the module @me. Relocs that may be found in either REL or RELA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)  * variants can be handled by making use of the @base & @v parameters which are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)  * set to values which abstract the difference away from the particular reloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)  * implementations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)  * Return: 0 upon success, else -ERRNO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) typedef int (*reloc_handler)(struct module *me, u32 *location,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			     u32 base, Elf_Addr v, bool rela);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /* The handlers for known reloc types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static reloc_handler reloc_handlers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	[R_MIPS_NONE]		= apply_r_mips_none,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	[R_MIPS_32]		= apply_r_mips_32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	[R_MIPS_26]		= apply_r_mips_26,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	[R_MIPS_HI16]		= apply_r_mips_hi16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	[R_MIPS_LO16]		= apply_r_mips_lo16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	[R_MIPS_PC16]		= apply_r_mips_pc16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	[R_MIPS_64]		= apply_r_mips_64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	[R_MIPS_HIGHER]		= apply_r_mips_higher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	[R_MIPS_HIGHEST]	= apply_r_mips_highest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	[R_MIPS_PC21_S2]	= apply_r_mips_pc21,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	[R_MIPS_PC26_S2]	= apply_r_mips_pc26,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static int __apply_relocate(Elf_Shdr *sechdrs, const char *strtab,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			    unsigned int symindex, unsigned int relsec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			    struct module *me, bool rela)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		Elf_Mips_Rel *rel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		Elf_Mips_Rela *rela;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	} r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	reloc_handler handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	Elf_Sym *sym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	u32 *location, base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	unsigned int i, type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	Elf_Addr v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	size_t reloc_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	pr_debug("Applying relocate section %u to %u\n", relsec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	       sechdrs[relsec].sh_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	r.rel = (void *)sechdrs[relsec].sh_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	reloc_sz = rela ? sizeof(*r.rela) : sizeof(*r.rel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	me->arch.r_mips_hi16_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	for (i = 0; i < sechdrs[relsec].sh_size / reloc_sz; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		/* This is where to make the change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			+ r.rel->r_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		/* This is the symbol it is referring to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		sym = (Elf_Sym *)sechdrs[symindex].sh_addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 			+ ELF_MIPS_R_SYM(*r.rel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		if (sym->st_value >= -MAX_ERRNO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			/* Ignore unresolved weak symbol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			if (ELF_ST_BIND(sym->st_info) == STB_WEAK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			pr_warn("%s: Unknown symbol %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 				me->name, strtab + sym->st_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 			err = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		type = ELF_MIPS_R_TYPE(*r.rel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		if (type < ARRAY_SIZE(reloc_handlers))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			handler = reloc_handlers[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			handler = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		if (!handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			pr_err("%s: Unknown relocation type %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 			       me->name, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		if (rela) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			v = sym->st_value + r.rela->r_addend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			base = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 			r.rela = &r.rela[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			v = sym->st_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			base = *location;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			r.rel = &r.rel[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		err = handler(me, location, base, v, rela);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	 * Normally the hi16 list should be deallocated at this point. A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	 * malformed binary however could contain a series of R_MIPS_HI16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	 * relocations not followed by a R_MIPS_LO16 relocation, or if we hit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	 * an error processing a reloc we might have gotten here before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	 * reaching the R_MIPS_LO16. In either case, free up the list and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	 * return an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	if (me->arch.r_mips_hi16_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		free_relocation_chain(me->arch.r_mips_hi16_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		me->arch.r_mips_hi16_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		err = err ?: -ENOEXEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) int apply_relocate(Elf_Shdr *sechdrs, const char *strtab,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		   unsigned int symindex, unsigned int relsec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		   struct module *me)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	return __apply_relocate(sechdrs, strtab, symindex, relsec, me, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) #ifdef CONFIG_MODULES_USE_ELF_RELA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		       unsigned int symindex, unsigned int relsec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		       struct module *me)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	return __apply_relocate(sechdrs, strtab, symindex, relsec, me, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) #endif /* CONFIG_MODULES_USE_ELF_RELA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) /* Given an address, look for it in the module exception tables. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) const struct exception_table_entry *search_module_dbetables(unsigned long addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	const struct exception_table_entry *e = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	struct mod_arch_specific *dbe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	spin_lock_irqsave(&dbe_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	list_for_each_entry(dbe, &dbe_list, dbe_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		e = search_extable(dbe->dbe_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 				   dbe->dbe_end - dbe->dbe_start, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		if (e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	spin_unlock_irqrestore(&dbe_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	/* Now, if we found one, we are running inside it now, hence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	   we cannot unload the module, hence no refcnt needed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	return e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) /* Put in dbe list if necessary. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) int module_finalize(const Elf_Ehdr *hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		    const Elf_Shdr *sechdrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		    struct module *me)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	const Elf_Shdr *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	/* Make jump label nops. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	jump_label_apply_nops(me);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	INIT_LIST_HEAD(&me->arch.dbe_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		if (strcmp("__dbe_table", secstrings + s->sh_name) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		me->arch.dbe_start = (void *)s->sh_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		me->arch.dbe_end = (void *)s->sh_addr + s->sh_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		spin_lock_irq(&dbe_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		list_add(&me->arch.dbe_list, &dbe_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		spin_unlock_irq(&dbe_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) void module_arch_cleanup(struct module *mod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	spin_lock_irq(&dbe_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	list_del(&mod->arch.dbe_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	spin_unlock_irq(&dbe_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }