Skip to content

Commit 21c4ff8

Browse files
ozbenhpaulusmack
authored andcommitted
[POWERPC] Support feature fixups in modules
This patch adds support for feature fixups in modules. This involves adding support for R_PPC64_REL64 relocs to the 64 bits module loader. It also modifies modpost.c to ignore the powerpc fixup sections (or it would warn when used in .init.text). Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Acked-by: Olof Johansson <olof@lixom.net> Signed-off-by: Paul Mackerras <paulus@samba.org>
1 parent 0909c8c commit 21c4ff8

3 files changed

Lines changed: 71 additions & 19 deletions

File tree

‎arch/powerpc/kernel/module_32.c‎

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <linux/kernel.h>
2525
#include <linux/cache.h>
2626

27+
#include "setup.h"
28+
2729
#if 0
2830
#define DEBUGP printk
2931
#else
@@ -269,33 +271,50 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
269271
return 0;
270272
}
271273

274+
static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
275+
const Elf_Shdr *sechdrs,
276+
const char *name)
277+
{
278+
char *secstrings;
279+
unsigned int i;
280+
281+
secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
282+
for (i = 1; i < hdr->e_shnum; i++)
283+
if (strcmp(secstrings+sechdrs[i].sh_name, name) == 0)
284+
return &sechdrs[i];
285+
return NULL;
286+
}
287+
272288
int module_finalize(const Elf_Ehdr *hdr,
273289
const Elf_Shdr *sechdrs,
274290
struct module *me)
275291
{
276-
char *secstrings;
277-
unsigned int i;
292+
const Elf_Shdr *sect;
278293

279294
me->arch.bug_table = NULL;
280295
me->arch.num_bugs = 0;
281296

282297
/* Find the __bug_table section, if present */
283-
secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
284-
for (i = 1; i < hdr->e_shnum; i++) {
285-
if (strcmp(secstrings+sechdrs[i].sh_name, "__bug_table"))
286-
continue;
287-
me->arch.bug_table = (void *) sechdrs[i].sh_addr;
288-
me->arch.num_bugs = sechdrs[i].sh_size / sizeof(struct bug_entry);
289-
break;
298+
sect = find_section(hdr, sechdrs, "__bug_table");
299+
if (sect != NULL) {
300+
me->arch.bug_table = (void *) sect->sh_addr;
301+
me->arch.num_bugs = sect->sh_size / sizeof(struct bug_entry);
290302
}
291303

292-
/*
304+
/*
293305
* Strictly speaking this should have a spinlock to protect against
294306
* traversals, but since we only traverse on BUG()s, a spinlock
295307
* could potentially lead to deadlock and thus be counter-productive.
296308
*/
297309
list_add(&me->arch.bug_list, &module_bug_list);
298310

311+
/* Apply feature fixups */
312+
sect = find_section(hdr, sechdrs, "__ftr_fixup");
313+
if (sect != NULL)
314+
do_feature_fixups(cur_cpu_spec->cpu_features,
315+
(void *)sect->sh_addr,
316+
(void *)sect->sh_addr + sect->sh_size);
317+
299318
return 0;
300319
}
301320

‎arch/powerpc/kernel/module_64.c‎

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include <linux/vmalloc.h>
2323
#include <asm/module.h>
2424
#include <asm/uaccess.h>
25+
#include <asm/firmware.h>
26+
27+
#include "setup.h"
2528

2629
/* FIXME: We don't do .init separately. To do this, we'd need to have
2730
a separate r2 value in the init and core section, and stub between
@@ -400,6 +403,11 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
400403
| (value & 0x03fffffc);
401404
break;
402405

406+
case R_PPC64_REL64:
407+
/* 64 bits relative (used by features fixups) */
408+
*location = value - (unsigned long)location;
409+
break;
410+
403411
default:
404412
printk("%s: Unknown ADD relocation: %lu\n",
405413
me->name,
@@ -413,23 +421,33 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
413421

414422
LIST_HEAD(module_bug_list);
415423

416-
int module_finalize(const Elf_Ehdr *hdr,
417-
const Elf_Shdr *sechdrs, struct module *me)
424+
static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
425+
const Elf_Shdr *sechdrs,
426+
const char *name)
418427
{
419428
char *secstrings;
420429
unsigned int i;
421430

431+
secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
432+
for (i = 1; i < hdr->e_shnum; i++)
433+
if (strcmp(secstrings+sechdrs[i].sh_name, name) == 0)
434+
return &sechdrs[i];
435+
return NULL;
436+
}
437+
438+
int module_finalize(const Elf_Ehdr *hdr,
439+
const Elf_Shdr *sechdrs, struct module *me)
440+
{
441+
const Elf_Shdr *sect;
442+
422443
me->arch.bug_table = NULL;
423444
me->arch.num_bugs = 0;
424445

425446
/* Find the __bug_table section, if present */
426-
secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
427-
for (i = 1; i < hdr->e_shnum; i++) {
428-
if (strcmp(secstrings+sechdrs[i].sh_name, "__bug_table"))
429-
continue;
430-
me->arch.bug_table = (void *) sechdrs[i].sh_addr;
431-
me->arch.num_bugs = sechdrs[i].sh_size / sizeof(struct bug_entry);
432-
break;
447+
sect = find_section(hdr, sechdrs, "__bug_table");
448+
if (sect != NULL) {
449+
me->arch.bug_table = (void *) sect->sh_addr;
450+
me->arch.num_bugs = sect->sh_size / sizeof(struct bug_entry);
433451
}
434452

435453
/*
@@ -439,6 +457,19 @@ int module_finalize(const Elf_Ehdr *hdr,
439457
*/
440458
list_add(&me->arch.bug_list, &module_bug_list);
441459

460+
/* Apply feature fixups */
461+
sect = find_section(hdr, sechdrs, "__ftr_fixup");
462+
if (sect != NULL)
463+
do_feature_fixups(cur_cpu_spec->cpu_features,
464+
(void *)sect->sh_addr,
465+
(void *)sect->sh_addr + sect->sh_size);
466+
467+
sect = find_section(hdr, sechdrs, "__fw_ftr_fixup");
468+
if (sect != NULL)
469+
do_feature_fixups(powerpc_firmware_features,
470+
(void *)sect->sh_addr,
471+
(void *)sect->sh_addr + sect->sh_size);
472+
442473
return 0;
443474
}
444475

‎scripts/mod/modpost.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,8 @@ static int init_section_ref_ok(const char *name)
921921
".fixup",
922922
".smp_locks",
923923
".plt", /* seen on ARCH=um build on x86_64. Harmless */
924+
"__ftr_fixup", /* powerpc cpu feature fixup */
925+
"__fw_ftr_fixup", /* powerpc firmware feature fixup */
924926
NULL
925927
};
926928
/* Start of section names */

0 commit comments

Comments
 (0)