Skip to content

Commit 4a9cb36

Browse files
author
Russell King
committed
ARM: fixup SMP alternatives in modules
With certain configurations, we inline the unlock functions in modules, which results in SMP alternatives being created in modules. We need to fix those up when loading a module to prevent undefined instruction faults. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 0193c00 commit 4a9cb36

2 files changed

Lines changed: 47 additions & 13 deletions

File tree

‎arch/arm/kernel/head.S‎

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ ENDPROC(__turn_mmu_on)
391391

392392

393393
#ifdef CONFIG_SMP_ON_UP
394+
__INIT
394395
__fixup_smp:
395396
and r3, r9, #0x000f0000 @ architecture version
396397
teq r3, #0x000f0000 @ CPU ID supported?
@@ -415,18 +416,7 @@ __fixup_smp_on_up:
415416
sub r3, r0, r3
416417
add r4, r4, r3
417418
add r5, r5, r3
418-
2: cmp r4, r5
419-
movhs pc, lr
420-
ldmia r4!, {r0, r6}
421-
ARM( str r6, [r0, r3] )
422-
THUMB( add r0, r0, r3 )
423-
#ifdef __ARMEB__
424-
THUMB( mov r6, r6, ror #16 ) @ Convert word order for big-endian.
425-
#endif
426-
THUMB( strh r6, [r0], #2 ) @ For Thumb-2, store as two halfwords
427-
THUMB( mov r6, r6, lsr #16 ) @ to be robust against misaligned r3.
428-
THUMB( strh r6, [r0] )
429-
b 2b
419+
b __do_fixup_smp_on_up
430420
ENDPROC(__fixup_smp)
431421

432422
.align
@@ -440,7 +430,31 @@ smp_on_up:
440430
ALT_SMP(.long 1)
441431
ALT_UP(.long 0)
442432
.popsection
433+
#endif
443434

435+
.text
436+
__do_fixup_smp_on_up:
437+
cmp r4, r5
438+
movhs pc, lr
439+
ldmia r4!, {r0, r6}
440+
ARM( str r6, [r0, r3] )
441+
THUMB( add r0, r0, r3 )
442+
#ifdef __ARMEB__
443+
THUMB( mov r6, r6, ror #16 ) @ Convert word order for big-endian.
444444
#endif
445+
THUMB( strh r6, [r0], #2 ) @ For Thumb-2, store as two halfwords
446+
THUMB( mov r6, r6, lsr #16 ) @ to be robust against misaligned r3.
447+
THUMB( strh r6, [r0] )
448+
b __do_fixup_smp_on_up
449+
ENDPROC(__do_fixup_smp_on_up)
450+
451+
ENTRY(fixup_smp)
452+
stmfd sp!, {r4 - r6, lr}
453+
mov r4, r0
454+
add r5, r0, r1
455+
mov r3, #0
456+
bl __do_fixup_smp_on_up
457+
ldmfd sp!, {r4 - r6, pc}
458+
ENDPROC(fixup_smp)
445459

446460
#include "head-common.S"

‎arch/arm/kernel/module.c‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <asm/pgtable.h>
2424
#include <asm/sections.h>
25+
#include <asm/smp_plat.h>
2526
#include <asm/unwind.h>
2627

2728
#ifdef CONFIG_XIP_KERNEL
@@ -268,12 +269,28 @@ struct mod_unwind_map {
268269
const Elf_Shdr *txt_sec;
269270
};
270271

272+
static const Elf_Shdr *find_mod_section(const Elf32_Ehdr *hdr,
273+
const Elf_Shdr *sechdrs, const char *name)
274+
{
275+
const Elf_Shdr *s, *se;
276+
const char *secstrs = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
277+
278+
for (s = sechdrs, se = sechdrs + hdr->e_shnum; s < se; s++)
279+
if (strcmp(name, secstrs + s->sh_name) == 0)
280+
return s;
281+
282+
return NULL;
283+
}
284+
285+
extern void fixup_smp(const void *, unsigned long);
286+
271287
int module_finalize(const Elf32_Ehdr *hdr, const Elf_Shdr *sechdrs,
272288
struct module *mod)
273289
{
290+
const Elf_Shdr * __maybe_unused s = NULL;
274291
#ifdef CONFIG_ARM_UNWIND
275292
const char *secstrs = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
276-
const Elf_Shdr *s, *sechdrs_end = sechdrs + hdr->e_shnum;
293+
const Elf_Shdr *sechdrs_end = sechdrs + hdr->e_shnum;
277294
struct mod_unwind_map maps[ARM_SEC_MAX];
278295
int i;
279296

@@ -315,6 +332,9 @@ int module_finalize(const Elf32_Ehdr *hdr, const Elf_Shdr *sechdrs,
315332
maps[i].txt_sec->sh_addr,
316333
maps[i].txt_sec->sh_size);
317334
#endif
335+
s = find_mod_section(hdr, sechdrs, ".alt.smp.init");
336+
if (s && !is_smp())
337+
fixup_smp((void *)s->sh_addr, s->sh_size);
318338
return 0;
319339
}
320340

0 commit comments

Comments
 (0)