xref: /linux/arch/s390/kernel/module.c (revision 4d7b321a9ce0782a953874ec69acc2b12b9cb2cd)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *  Kernel module help for s390.
4  *
5  *  S390 version
6  *    Copyright IBM Corp. 2002, 2003
7  *    Author(s): Arnd Bergmann (arndb@de.ibm.com)
8  *		 Martin Schwidefsky (schwidefsky@de.ibm.com)
9  *
10  *  based on i386 version
11  *    Copyright (C) 2001 Rusty Russell.
12  */
13 #include <linux/module.h>
14 #include <linux/elf.h>
15 #include <linux/vmalloc.h>
16 #include <linux/fs.h>
17 #include <linux/ftrace.h>
18 #include <linux/string.h>
19 #include <linux/kernel.h>
20 #include <linux/kasan.h>
21 #include <linux/moduleloader.h>
22 #include <linux/bug.h>
23 #include <linux/memory.h>
24 #include <linux/execmem.h>
25 #include <asm/alternative.h>
26 #include <asm/nospec-branch.h>
27 #include <asm/facility.h>
28 #include <asm/ftrace.lds.h>
29 #include <asm/set_memory.h>
30 #include <asm/setup.h>
31 
32 #if 0
33 #define DEBUGP printk
34 #else
35 #define DEBUGP(fmt , ...)
36 #endif
37 
38 #define PLT_ENTRY_SIZE 22
39 
40 static struct execmem_info execmem_info __ro_after_init;
41 
42 struct execmem_info __init *execmem_arch_setup(void)
43 {
44 	unsigned long module_load_offset = 0;
45 	unsigned long start;
46 
47 	if (kaslr_enabled())
48 		module_load_offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE;
49 
50 	start = MODULES_VADDR + module_load_offset;
51 
52 	execmem_info = (struct execmem_info){
53 		.ranges = {
54 			[EXECMEM_DEFAULT] = {
55 				.flags	= EXECMEM_KASAN_SHADOW,
56 				.start	= start,
57 				.end	= MODULES_END,
58 				.pgprot	= PAGE_KERNEL,
59 				.alignment = MODULE_ALIGN,
60 			},
61 		},
62 	};
63 
64 	return &execmem_info;
65 }
66 
67 #ifdef CONFIG_FUNCTION_TRACER
68 void module_arch_cleanup(struct module *mod)
69 {
70 	execmem_free(mod->arch.trampolines_start);
71 }
72 #endif
73 
74 void module_arch_freeing_init(struct module *mod)
75 {
76 	if (is_livepatch_module(mod) &&
77 	    mod->state == MODULE_STATE_LIVE)
78 		return;
79 
80 	vfree(mod->arch.syminfo);
81 	mod->arch.syminfo = NULL;
82 }
83 
84 static void check_rela(Elf_Rela *rela, struct module *me)
85 {
86 	struct mod_arch_syminfo *info;
87 
88 	info = me->arch.syminfo + ELF_R_SYM (rela->r_info);
89 	switch (ELF_R_TYPE (rela->r_info)) {
90 	case R_390_GOT12:	/* 12 bit GOT offset.  */
91 	case R_390_GOT16:	/* 16 bit GOT offset.  */
92 	case R_390_GOT20:	/* 20 bit GOT offset.  */
93 	case R_390_GOT32:	/* 32 bit GOT offset.  */
94 	case R_390_GOT64:	/* 64 bit GOT offset.  */
95 	case R_390_GOTENT:	/* 32 bit PC rel. to GOT entry shifted by 1. */
96 	case R_390_GOTPLT12:	/* 12 bit offset to jump slot.	*/
97 	case R_390_GOTPLT16:	/* 16 bit offset to jump slot.  */
98 	case R_390_GOTPLT20:	/* 20 bit offset to jump slot.  */
99 	case R_390_GOTPLT32:	/* 32 bit offset to jump slot.  */
100 	case R_390_GOTPLT64:	/* 64 bit offset to jump slot.	*/
101 	case R_390_GOTPLTENT:	/* 32 bit rel. offset to jump slot >> 1. */
102 		if (info->got_offset == -1UL) {
103 			info->got_offset = me->arch.got_size;
104 			me->arch.got_size += sizeof(void*);
105 		}
106 		break;
107 	case R_390_PLT16DBL:	/* 16 bit PC rel. PLT shifted by 1.  */
108 	case R_390_PLT32DBL:	/* 32 bit PC rel. PLT shifted by 1.  */
109 	case R_390_PLT32:	/* 32 bit PC relative PLT address.  */
110 	case R_390_PLT64:	/* 64 bit PC relative PLT address.  */
111 	case R_390_PLTOFF16:	/* 16 bit offset from GOT to PLT. */
112 	case R_390_PLTOFF32:	/* 32 bit offset from GOT to PLT. */
113 	case R_390_PLTOFF64:	/* 16 bit offset from GOT to PLT. */
114 		if (info->plt_offset == -1UL) {
115 			info->plt_offset = me->arch.plt_size;
116 			me->arch.plt_size += PLT_ENTRY_SIZE;
117 		}
118 		break;
119 	case R_390_COPY:
120 	case R_390_GLOB_DAT:
121 	case R_390_JMP_SLOT:
122 	case R_390_RELATIVE:
123 		/* Only needed if we want to support loading of
124 		   modules linked with -shared. */
125 		break;
126 	}
127 }
128 
129 /*
130  * Account for GOT and PLT relocations. We can't add sections for
131  * got and plt but we can increase the core module size.
132  */
133 int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
134 			      char *secstrings, struct module *me)
135 {
136 	Elf_Shdr *symtab;
137 	Elf_Sym *symbols;
138 	Elf_Rela *rela;
139 	char *strings;
140 	int nrela, i, j;
141 	struct module_memory *mod_mem;
142 
143 	/* Find symbol table and string table. */
144 	symtab = NULL;
145 	for (i = 0; i < hdr->e_shnum; i++)
146 		switch (sechdrs[i].sh_type) {
147 		case SHT_SYMTAB:
148 			symtab = sechdrs + i;
149 			break;
150 		}
151 	if (!symtab) {
152 		printk(KERN_ERR "module %s: no symbol table\n", me->name);
153 		return -ENOEXEC;
154 	}
155 
156 	/* Allocate one syminfo structure per symbol. */
157 	me->arch.nsyms = symtab->sh_size / sizeof(Elf_Sym);
158 	me->arch.syminfo = vmalloc(array_size(sizeof(struct mod_arch_syminfo),
159 					      me->arch.nsyms));
160 	if (!me->arch.syminfo)
161 		return -ENOMEM;
162 	symbols = (void *) hdr + symtab->sh_offset;
163 	strings = (void *) hdr + sechdrs[symtab->sh_link].sh_offset;
164 	for (i = 0; i < me->arch.nsyms; i++) {
165 		if (symbols[i].st_shndx == SHN_UNDEF &&
166 		    strcmp(strings + symbols[i].st_name,
167 			   "_GLOBAL_OFFSET_TABLE_") == 0)
168 			/* "Define" it as absolute. */
169 			symbols[i].st_shndx = SHN_ABS;
170 		me->arch.syminfo[i].got_offset = -1UL;
171 		me->arch.syminfo[i].plt_offset = -1UL;
172 		me->arch.syminfo[i].got_initialized = 0;
173 		me->arch.syminfo[i].plt_initialized = 0;
174 	}
175 
176 	/* Search for got/plt relocations. */
177 	me->arch.got_size = me->arch.plt_size = 0;
178 	for (i = 0; i < hdr->e_shnum; i++) {
179 		if (sechdrs[i].sh_type != SHT_RELA)
180 			continue;
181 		nrela = sechdrs[i].sh_size / sizeof(Elf_Rela);
182 		rela = (void *) hdr + sechdrs[i].sh_offset;
183 		for (j = 0; j < nrela; j++)
184 			check_rela(rela + j, me);
185 	}
186 
187 	/* Increase core size by size of got & plt and set start
188 	   offsets for got and plt. */
189 	mod_mem = &me->mem[MOD_TEXT];
190 	mod_mem->size = ALIGN(mod_mem->size, 4);
191 	me->arch.got_offset = mod_mem->size;
192 	mod_mem->size += me->arch.got_size;
193 	me->arch.plt_offset = mod_mem->size;
194 	if (me->arch.plt_size) {
195 		if (IS_ENABLED(CONFIG_EXPOLINE) && !nospec_disable)
196 			me->arch.plt_size += PLT_ENTRY_SIZE;
197 		mod_mem->size += me->arch.plt_size;
198 	}
199 	return 0;
200 }
201 
202 static int apply_rela_bits(Elf_Addr loc, Elf_Addr val,
203 			   int sign, int bits, int shift,
204 			   void *(*write)(void *dest, const void *src, size_t len))
205 {
206 	unsigned long umax;
207 	long min, max;
208 	void *dest = (void *)loc;
209 
210 	if (val & ((1UL << shift) - 1))
211 		return -ENOEXEC;
212 	if (sign) {
213 		val = (Elf_Addr)(((long) val) >> shift);
214 		min = -(1L << (bits - 1));
215 		max = (1L << (bits - 1)) - 1;
216 		if ((long) val < min || (long) val > max)
217 			return -ENOEXEC;
218 	} else {
219 		val >>= shift;
220 		umax = ((1UL << (bits - 1)) << 1) - 1;
221 		if ((unsigned long) val > umax)
222 			return -ENOEXEC;
223 	}
224 
225 	if (bits == 8) {
226 		unsigned char tmp = val;
227 		write(dest, &tmp, 1);
228 	} else if (bits == 12) {
229 		unsigned short tmp = (val & 0xfff) |
230 			(*(unsigned short *) loc & 0xf000);
231 		write(dest, &tmp, 2);
232 	} else if (bits == 16) {
233 		unsigned short tmp = val;
234 		write(dest, &tmp, 2);
235 	} else if (bits == 20) {
236 		unsigned int tmp = (val & 0xfff) << 16 |
237 			(val & 0xff000) >> 4 | (*(unsigned int *) loc & 0xf00000ff);
238 		write(dest, &tmp, 4);
239 	} else if (bits == 32) {
240 		unsigned int tmp = val;
241 		write(dest, &tmp, 4);
242 	} else if (bits == 64) {
243 		unsigned long tmp = val;
244 		write(dest, &tmp, 8);
245 	}
246 	return 0;
247 }
248 
249 static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
250 		      const char *strtab, struct module *me,
251 		      void *(*write)(void *dest, const void *src, size_t len))
252 {
253 	struct mod_arch_syminfo *info;
254 	Elf_Addr loc, val;
255 	int r_type, r_sym;
256 	int rc = -ENOEXEC;
257 
258 	/* This is where to make the change */
259 	loc = base + rela->r_offset;
260 	/* This is the symbol it is referring to.  Note that all
261 	   undefined symbols have been resolved.  */
262 	r_sym = ELF_R_SYM(rela->r_info);
263 	r_type = ELF_R_TYPE(rela->r_info);
264 	info = me->arch.syminfo + r_sym;
265 	val = symtab[r_sym].st_value;
266 
267 	switch (r_type) {
268 	case R_390_NONE:	/* No relocation.  */
269 		rc = 0;
270 		break;
271 	case R_390_8:		/* Direct 8 bit.   */
272 	case R_390_12:		/* Direct 12 bit.  */
273 	case R_390_16:		/* Direct 16 bit.  */
274 	case R_390_20:		/* Direct 20 bit.  */
275 	case R_390_32:		/* Direct 32 bit.  */
276 	case R_390_64:		/* Direct 64 bit.  */
277 		val += rela->r_addend;
278 		if (r_type == R_390_8)
279 			rc = apply_rela_bits(loc, val, 0, 8, 0, write);
280 		else if (r_type == R_390_12)
281 			rc = apply_rela_bits(loc, val, 0, 12, 0, write);
282 		else if (r_type == R_390_16)
283 			rc = apply_rela_bits(loc, val, 0, 16, 0, write);
284 		else if (r_type == R_390_20)
285 			rc = apply_rela_bits(loc, val, 1, 20, 0, write);
286 		else if (r_type == R_390_32)
287 			rc = apply_rela_bits(loc, val, 0, 32, 0, write);
288 		else if (r_type == R_390_64)
289 			rc = apply_rela_bits(loc, val, 0, 64, 0, write);
290 		break;
291 	case R_390_PC16:	/* PC relative 16 bit.  */
292 	case R_390_PC16DBL:	/* PC relative 16 bit shifted by 1.  */
293 	case R_390_PC32DBL:	/* PC relative 32 bit shifted by 1.  */
294 	case R_390_PC32:	/* PC relative 32 bit.  */
295 	case R_390_PC64:	/* PC relative 64 bit.	*/
296 		val += rela->r_addend - loc;
297 		if (r_type == R_390_PC16)
298 			rc = apply_rela_bits(loc, val, 1, 16, 0, write);
299 		else if (r_type == R_390_PC16DBL)
300 			rc = apply_rela_bits(loc, val, 1, 16, 1, write);
301 		else if (r_type == R_390_PC32DBL)
302 			rc = apply_rela_bits(loc, val, 1, 32, 1, write);
303 		else if (r_type == R_390_PC32)
304 			rc = apply_rela_bits(loc, val, 1, 32, 0, write);
305 		else if (r_type == R_390_PC64)
306 			rc = apply_rela_bits(loc, val, 1, 64, 0, write);
307 		break;
308 	case R_390_GOT12:	/* 12 bit GOT offset.  */
309 	case R_390_GOT16:	/* 16 bit GOT offset.  */
310 	case R_390_GOT20:	/* 20 bit GOT offset.  */
311 	case R_390_GOT32:	/* 32 bit GOT offset.  */
312 	case R_390_GOT64:	/* 64 bit GOT offset.  */
313 	case R_390_GOTENT:	/* 32 bit PC rel. to GOT entry shifted by 1. */
314 	case R_390_GOTPLT12:	/* 12 bit offset to jump slot.	*/
315 	case R_390_GOTPLT20:	/* 20 bit offset to jump slot.  */
316 	case R_390_GOTPLT16:	/* 16 bit offset to jump slot.  */
317 	case R_390_GOTPLT32:	/* 32 bit offset to jump slot.  */
318 	case R_390_GOTPLT64:	/* 64 bit offset to jump slot.	*/
319 	case R_390_GOTPLTENT:	/* 32 bit rel. offset to jump slot >> 1. */
320 		if (info->got_initialized == 0) {
321 			Elf_Addr *gotent = me->mem[MOD_TEXT].base +
322 					   me->arch.got_offset +
323 					   info->got_offset;
324 
325 			write(gotent, &val, sizeof(*gotent));
326 			info->got_initialized = 1;
327 		}
328 		val = info->got_offset + rela->r_addend;
329 		if (r_type == R_390_GOT12 ||
330 		    r_type == R_390_GOTPLT12)
331 			rc = apply_rela_bits(loc, val, 0, 12, 0, write);
332 		else if (r_type == R_390_GOT16 ||
333 			 r_type == R_390_GOTPLT16)
334 			rc = apply_rela_bits(loc, val, 0, 16, 0, write);
335 		else if (r_type == R_390_GOT20 ||
336 			 r_type == R_390_GOTPLT20)
337 			rc = apply_rela_bits(loc, val, 1, 20, 0, write);
338 		else if (r_type == R_390_GOT32 ||
339 			 r_type == R_390_GOTPLT32)
340 			rc = apply_rela_bits(loc, val, 0, 32, 0, write);
341 		else if (r_type == R_390_GOT64 ||
342 			 r_type == R_390_GOTPLT64)
343 			rc = apply_rela_bits(loc, val, 0, 64, 0, write);
344 		else if (r_type == R_390_GOTENT ||
345 			 r_type == R_390_GOTPLTENT) {
346 			val += (Elf_Addr)me->mem[MOD_TEXT].base +
347 				me->arch.got_offset - loc;
348 			rc = apply_rela_bits(loc, val, 1, 32, 1, write);
349 		}
350 		break;
351 	case R_390_PLT16DBL:	/* 16 bit PC rel. PLT shifted by 1.  */
352 	case R_390_PLT32DBL:	/* 32 bit PC rel. PLT shifted by 1.  */
353 	case R_390_PLT32:	/* 32 bit PC relative PLT address.  */
354 	case R_390_PLT64:	/* 64 bit PC relative PLT address.  */
355 	case R_390_PLTOFF16:	/* 16 bit offset from GOT to PLT. */
356 	case R_390_PLTOFF32:	/* 32 bit offset from GOT to PLT. */
357 	case R_390_PLTOFF64:	/* 16 bit offset from GOT to PLT. */
358 		if (info->plt_initialized == 0) {
359 			unsigned char insn[PLT_ENTRY_SIZE];
360 			char *plt_base;
361 			char *ip;
362 
363 			plt_base = me->mem[MOD_TEXT].base + me->arch.plt_offset;
364 			ip = plt_base + info->plt_offset;
365 			*(int *)insn = 0x0d10e310;	/* basr 1,0  */
366 			*(int *)&insn[4] = 0x100c0004;	/* lg	1,12(1) */
367 			if (IS_ENABLED(CONFIG_EXPOLINE) && !nospec_disable) {
368 				char *jump_r1;
369 
370 				jump_r1 = plt_base + me->arch.plt_size -
371 					PLT_ENTRY_SIZE;
372 				/* brcl	0xf,__jump_r1 */
373 				*(short *)&insn[8] = 0xc0f4;
374 				*(int *)&insn[10] = (jump_r1 - (ip + 8)) / 2;
375 			} else {
376 				*(int *)&insn[8] = 0x07f10000;	/* br %r1 */
377 			}
378 			*(long *)&insn[14] = val;
379 
380 			write(ip, insn, sizeof(insn));
381 			info->plt_initialized = 1;
382 		}
383 		if (r_type == R_390_PLTOFF16 ||
384 		    r_type == R_390_PLTOFF32 ||
385 		    r_type == R_390_PLTOFF64)
386 			val = me->arch.plt_offset - me->arch.got_offset +
387 				info->plt_offset + rela->r_addend;
388 		else {
389 			if (!((r_type == R_390_PLT16DBL &&
390 			       val - loc + 0xffffUL < 0x1ffffeUL) ||
391 			      (r_type == R_390_PLT32DBL &&
392 			       val - loc + 0xffffffffULL < 0x1fffffffeULL)))
393 				val = (Elf_Addr) me->mem[MOD_TEXT].base +
394 					me->arch.plt_offset +
395 					info->plt_offset;
396 			val += rela->r_addend - loc;
397 		}
398 		if (r_type == R_390_PLT16DBL)
399 			rc = apply_rela_bits(loc, val, 1, 16, 1, write);
400 		else if (r_type == R_390_PLTOFF16)
401 			rc = apply_rela_bits(loc, val, 0, 16, 0, write);
402 		else if (r_type == R_390_PLT32DBL)
403 			rc = apply_rela_bits(loc, val, 1, 32, 1, write);
404 		else if (r_type == R_390_PLT32 ||
405 			 r_type == R_390_PLTOFF32)
406 			rc = apply_rela_bits(loc, val, 0, 32, 0, write);
407 		else if (r_type == R_390_PLT64 ||
408 			 r_type == R_390_PLTOFF64)
409 			rc = apply_rela_bits(loc, val, 0, 64, 0, write);
410 		break;
411 	case R_390_GOTOFF16:	/* 16 bit offset to GOT.  */
412 	case R_390_GOTOFF32:	/* 32 bit offset to GOT.  */
413 	case R_390_GOTOFF64:	/* 64 bit offset to GOT. */
414 		val = val + rela->r_addend -
415 			((Elf_Addr) me->mem[MOD_TEXT].base + me->arch.got_offset);
416 		if (r_type == R_390_GOTOFF16)
417 			rc = apply_rela_bits(loc, val, 0, 16, 0, write);
418 		else if (r_type == R_390_GOTOFF32)
419 			rc = apply_rela_bits(loc, val, 0, 32, 0, write);
420 		else if (r_type == R_390_GOTOFF64)
421 			rc = apply_rela_bits(loc, val, 0, 64, 0, write);
422 		break;
423 	case R_390_GOTPC:	/* 32 bit PC relative offset to GOT. */
424 	case R_390_GOTPCDBL:	/* 32 bit PC rel. off. to GOT shifted by 1. */
425 		val = (Elf_Addr) me->mem[MOD_TEXT].base + me->arch.got_offset +
426 			rela->r_addend - loc;
427 		if (r_type == R_390_GOTPC)
428 			rc = apply_rela_bits(loc, val, 1, 32, 0, write);
429 		else if (r_type == R_390_GOTPCDBL)
430 			rc = apply_rela_bits(loc, val, 1, 32, 1, write);
431 		break;
432 	case R_390_COPY:
433 	case R_390_GLOB_DAT:	/* Create GOT entry.  */
434 	case R_390_JMP_SLOT:	/* Create PLT entry.  */
435 	case R_390_RELATIVE:	/* Adjust by program base.  */
436 		/* Only needed if we want to support loading of
437 		   modules linked with -shared. */
438 		return -ENOEXEC;
439 	default:
440 		printk(KERN_ERR "module %s: unknown relocation: %u\n",
441 		       me->name, r_type);
442 		return -ENOEXEC;
443 	}
444 	if (rc) {
445 		printk(KERN_ERR "module %s: relocation error for symbol %s "
446 		       "(r_type %i, value 0x%lx)\n",
447 		       me->name, strtab + symtab[r_sym].st_name,
448 		       r_type, (unsigned long) val);
449 		return rc;
450 	}
451 	return 0;
452 }
453 
454 static int __apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
455 		       unsigned int symindex, unsigned int relsec,
456 		       struct module *me,
457 		       void *(*write)(void *dest, const void *src, size_t len))
458 {
459 	Elf_Addr base;
460 	Elf_Sym *symtab;
461 	Elf_Rela *rela;
462 	unsigned long i, n;
463 	int rc;
464 
465 	DEBUGP("Applying relocate section %u to %u\n",
466 	       relsec, sechdrs[relsec].sh_info);
467 	base = sechdrs[sechdrs[relsec].sh_info].sh_addr;
468 	symtab = (Elf_Sym *) sechdrs[symindex].sh_addr;
469 	rela = (Elf_Rela *) sechdrs[relsec].sh_addr;
470 	n = sechdrs[relsec].sh_size / sizeof(Elf_Rela);
471 
472 	for (i = 0; i < n; i++, rela++) {
473 		rc = apply_rela(rela, base, symtab, strtab, me, write);
474 		if (rc)
475 			return rc;
476 	}
477 	return 0;
478 }
479 
480 int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
481 		       unsigned int symindex, unsigned int relsec,
482 		       struct module *me)
483 {
484 	bool early = me->state == MODULE_STATE_UNFORMED;
485 	void *(*write)(void *, const void *, size_t) = memcpy;
486 
487 	if (!early)
488 		write = s390_kernel_write;
489 
490 	return __apply_relocate_add(sechdrs, strtab, symindex, relsec, me,
491 				    write);
492 }
493 
494 #ifdef CONFIG_FUNCTION_TRACER
495 static int module_alloc_ftrace_hotpatch_trampolines(struct module *me,
496 						    const Elf_Shdr *s)
497 {
498 	char *start, *end;
499 	int numpages;
500 	size_t size;
501 
502 	size = FTRACE_HOTPATCH_TRAMPOLINES_SIZE(s->sh_size);
503 	numpages = DIV_ROUND_UP(size, PAGE_SIZE);
504 	start = execmem_alloc(EXECMEM_FTRACE, numpages * PAGE_SIZE);
505 	if (!start)
506 		return -ENOMEM;
507 	set_memory_rox((unsigned long)start, numpages);
508 	end = start + size;
509 
510 	me->arch.trampolines_start = (struct ftrace_hotpatch_trampoline *)start;
511 	me->arch.trampolines_end = (struct ftrace_hotpatch_trampoline *)end;
512 	me->arch.next_trampoline = me->arch.trampolines_start;
513 
514 	return 0;
515 }
516 #endif /* CONFIG_FUNCTION_TRACER */
517 
518 int module_finalize(const Elf_Ehdr *hdr,
519 		    const Elf_Shdr *sechdrs,
520 		    struct module *me)
521 {
522 	const Elf_Shdr *s;
523 	char *secstrings, *secname;
524 	void *aseg;
525 #ifdef CONFIG_FUNCTION_TRACER
526 	int ret;
527 #endif
528 
529 	if (IS_ENABLED(CONFIG_EXPOLINE) &&
530 	    !nospec_disable && me->arch.plt_size) {
531 		unsigned int *ij;
532 
533 		ij = me->mem[MOD_TEXT].base + me->arch.plt_offset +
534 			me->arch.plt_size - PLT_ENTRY_SIZE;
535 		ij[0] = 0xc6000000;	/* exrl	%r0,.+10	*/
536 		ij[1] = 0x0005a7f4;	/* j	.		*/
537 		ij[2] = 0x000007f1;	/* br	%r1		*/
538 	}
539 
540 	secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
541 	for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
542 		aseg = (void *) s->sh_addr;
543 		secname = secstrings + s->sh_name;
544 
545 		if (!strcmp(".altinstructions", secname))
546 			/* patch .altinstructions */
547 			apply_alternatives(aseg, aseg + s->sh_size);
548 
549 		if (IS_ENABLED(CONFIG_EXPOLINE) &&
550 		    (str_has_prefix(secname, ".s390_indirect")))
551 			nospec_revert(aseg, aseg + s->sh_size);
552 
553 		if (IS_ENABLED(CONFIG_EXPOLINE) &&
554 		    (str_has_prefix(secname, ".s390_return")))
555 			nospec_revert(aseg, aseg + s->sh_size);
556 
557 #ifdef CONFIG_FUNCTION_TRACER
558 		if (!strcmp(FTRACE_CALLSITE_SECTION, secname)) {
559 			ret = module_alloc_ftrace_hotpatch_trampolines(me, s);
560 			if (ret < 0)
561 				return ret;
562 		}
563 #endif /* CONFIG_FUNCTION_TRACER */
564 	}
565 
566 	return 0;
567 }
568