Skip to content

Commit 713ab91

Browse files
committed
Merge tag 'powerpc-5.16-4' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux
Pull powerpc fixes from Michael Ellerman: "Fix a recently introduced oops at boot on 85xx in some configurations. Fix crashes when loading some livepatch modules with STRICT_MODULE_RWX. Thanks to Joe Lawrence, Russell Currey, and Xiaoming Ni" * tag 'powerpc-5.16-4' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux: powerpc/module_64: Fix livepatching for RO modules powerpc/85xx: Fix oops when CONFIG_FSL_PMC=n
2 parents 9273d6c + 8734b41 commit 713ab91

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

arch/powerpc/kernel/module_64.c

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,17 @@ static inline int create_stub(const Elf64_Shdr *sechdrs,
422422
const char *name)
423423
{
424424
long reladdr;
425+
func_desc_t desc;
426+
int i;
425427

426428
if (is_mprofile_ftrace_call(name))
427429
return create_ftrace_stub(entry, addr, me);
428430

429-
memcpy(entry->jump, ppc64_stub_insns, sizeof(ppc64_stub_insns));
431+
for (i = 0; i < sizeof(ppc64_stub_insns) / sizeof(u32); i++) {
432+
if (patch_instruction(&entry->jump[i],
433+
ppc_inst(ppc64_stub_insns[i])))
434+
return 0;
435+
}
430436

431437
/* Stub uses address relative to r2. */
432438
reladdr = (unsigned long)entry - my_r2(sechdrs, me);
@@ -437,10 +443,24 @@ static inline int create_stub(const Elf64_Shdr *sechdrs,
437443
}
438444
pr_debug("Stub %p get data from reladdr %li\n", entry, reladdr);
439445

440-
entry->jump[0] |= PPC_HA(reladdr);
441-
entry->jump[1] |= PPC_LO(reladdr);
442-
entry->funcdata = func_desc(addr);
443-
entry->magic = STUB_MAGIC;
446+
if (patch_instruction(&entry->jump[0],
447+
ppc_inst(entry->jump[0] | PPC_HA(reladdr))))
448+
return 0;
449+
450+
if (patch_instruction(&entry->jump[1],
451+
ppc_inst(entry->jump[1] | PPC_LO(reladdr))))
452+
return 0;
453+
454+
// func_desc_t is 8 bytes if ABIv2, else 16 bytes
455+
desc = func_desc(addr);
456+
for (i = 0; i < sizeof(func_desc_t) / sizeof(u32); i++) {
457+
if (patch_instruction(((u32 *)&entry->funcdata) + i,
458+
ppc_inst(((u32 *)(&desc))[i])))
459+
return 0;
460+
}
461+
462+
if (patch_instruction(&entry->magic, ppc_inst(STUB_MAGIC)))
463+
return 0;
444464

445465
return 1;
446466
}
@@ -495,8 +515,11 @@ static int restore_r2(const char *name, u32 *instruction, struct module *me)
495515
me->name, *instruction, instruction);
496516
return 0;
497517
}
518+
498519
/* ld r2,R2_STACK_OFFSET(r1) */
499-
*instruction = PPC_INST_LD_TOC;
520+
if (patch_instruction(instruction, ppc_inst(PPC_INST_LD_TOC)))
521+
return 0;
522+
500523
return 1;
501524
}
502525

@@ -636,9 +659,12 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
636659
}
637660

638661
/* Only replace bits 2 through 26 */
639-
*(uint32_t *)location
640-
= (*(uint32_t *)location & ~0x03fffffc)
662+
value = (*(uint32_t *)location & ~0x03fffffc)
641663
| (value & 0x03fffffc);
664+
665+
if (patch_instruction((u32 *)location, ppc_inst(value)))
666+
return -EFAULT;
667+
642668
break;
643669

644670
case R_PPC64_REL64:

arch/powerpc/platforms/85xx/smp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static int smp_85xx_start_cpu(int cpu)
220220
local_irq_save(flags);
221221
hard_irq_disable();
222222

223-
if (qoriq_pm_ops)
223+
if (qoriq_pm_ops && qoriq_pm_ops->cpu_up_prepare)
224224
qoriq_pm_ops->cpu_up_prepare(cpu);
225225

226226
/* if cpu is not spinning, reset it */
@@ -292,7 +292,7 @@ static int smp_85xx_kick_cpu(int nr)
292292
booting_thread_hwid = cpu_thread_in_core(nr);
293293
primary = cpu_first_thread_sibling(nr);
294294

295-
if (qoriq_pm_ops)
295+
if (qoriq_pm_ops && qoriq_pm_ops->cpu_up_prepare)
296296
qoriq_pm_ops->cpu_up_prepare(nr);
297297

298298
/*

0 commit comments

Comments
 (0)