Skip to contentSkip to conversation

powerpc: Support feature fixups in modules

PATCH In review Benjamin Herrenschmidt 2 participants 3 messages Oct 20, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 4/5 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).

arch/powerpc/kernel/module_32.c +29 -10
Index: linux-cell/arch/powerpc/kernel/module_32.c
===================================================================
@@ -24,6 +24,8 @@
 #include <linux/kernel.h>
 #include <linux/cache.h>
 
+#include "setup.h"
+
 #if 0
 #define DEBUGP printk
 #else
@@ -269,33 +271,50 @@ int apply_relocate_add(Elf32_Shdr *sechd
 	return 0;
 }
 
+static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
+				    const Elf_Shdr *sechdrs,
+				    const char *name)
+{
+	char *secstrings;
+	unsigned int i;
+
+	secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
+	for (i = 1; i < hdr->e_shnum; i++)
+		if (strcmp(secstrings+sechdrs[i].sh_name, name) == 0)
+			return &sechdrs[i];
+	return NULL;
+}
+
 int module_finalize(const Elf_Ehdr *hdr,
 		    const Elf_Shdr *sechdrs,
 		    struct module *me)
 {
-	char *secstrings;
-	unsigned int i;
+	const Elf_Shdr *sect;
 
 	me->arch.bug_table = NULL;
 	me->arch.num_bugs = 0;
 
 	/* Find the __bug_table section, if present */
-	secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
-	for (i = 1; i < hdr->e_shnum; i++) {
-		if (strcmp(secstrings+sechdrs[i].sh_name, "__bug_table"))
-			continue;
-		me->arch.bug_table = (void *) sechdrs[i].sh_addr;
-		me->arch.num_bugs = sechdrs[i].sh_size / sizeof(struct bug_entry);
-		break;
+	sect = find_section(hdr, sechdrs, "__bug_table");
+	if (sect != NULL) {
+		me->arch.bug_table = (void *) sect->sh_addr;
+		me->arch.num_bugs = sect->sh_size / sizeof(struct bug_entry);
 	}
 
-	/*
+ 	/*
 	 * Strictly speaking this should have a spinlock to protect against
 	 * traversals, but since we only traverse on BUG()s, a spinlock
 	 * could potentially lead to deadlock and thus be counter-productive.
 	 */
 	list_add(&me->arch.bug_list, &module_bug_list);
 
+	/* Apply feature fixups */
+	sect = find_section(hdr, sechdrs, "__ftr_fixup");
+	if (sect != NULL)
+		do_feature_fixups(cur_cpu_spec->cpu_features,
+				  (void *)sect->sh_addr,
+				  (void *)sect->sh_addr + sect->sh_size);
+
 	return 0;
 }
 
arch/powerpc/kernel/module_64.c +40 -9

81 lines not on this page · raw message

scripts/mod/modpost.c +2 -0
Index: linux-cell/scripts/mod/modpost.c
===================================================================
@@ -921,6 +921,8 @@ static int init_section_ref_ok(const cha
 		".fixup",
 		".smp_locks",
 		".plt",  /* seen on ARCH=um build on x86_64. Harmless */
+		"__ftr_fixup",		/* powerpc cpu feature fixup */
+		"__fw_ftr_fixup",	/* powerpc firmware feature fixup */
 		NULL
 	};
 	/* Start of section names */
Acked-by on v1 4/5
#1 lore raw
Quoted 6 lines · On Fri, 20 Oct 2006 11:47:19 +1000 Benjamin Herrenschmidt…

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).

Quoted 4 lines

Index: linux-cell/arch/powerpc/kernel/module_32.c
===================================================================

arch/powerpc/kernel/module_32.c +0 -0

[...]

Quoted 4 lines
arch/powerpc/kernel/module_32.c +4 -0
+static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
+				    const Elf_Shdr *sechdrs,
+				    const char *name)
+{

arch/powerpc/kernel/module_32.c int apply_relocate_add(Elf32_Shdr *sechd · line 287

Quoted 10 lines
arch/powerpc/kernel/module_32.c +10 -0
+	char *secstrings;
+	unsigned int i;
+
+	secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
+	for (i = 1; i < hdr->e_shnum; i++)
+		if (strcmp(secstrings+sechdrs[i].sh_name, name) == 0)
+			return &sechdrs[i];
+	return NULL;
+}
+

It would be nice if this could be put in some common location instead of duplicated between the two files. It builds differently on 32 and 64 bits due to the type defines, but both will never be used in the same kernel.

-Olof

#2 lore raw
Quoted 27 lines · Olof Johansson
Quoted 6 lines · On Fri, 20 Oct 2006 11:47:19 +1000 Benjamin Herrenschmidt…

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).

Quoted 4 lines

Index: linux-cell/arch/powerpc/kernel/module_32.c
===================================================================

arch/powerpc/kernel/module_32.c +0 -0

[...]

Quoted 11 lines
arch/powerpc/kernel/module_32.c +11 -0
+static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
+				    const Elf_Shdr *sechdrs,
+				    const char *name)
+{
+	char *secstrings;
+	unsigned int i;
+
+	secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
+	for (i = 1; i < hdr->e_shnum; i++)
+		if (strcmp(secstrings+sechdrs[i].sh_name, name) == 0)
+			return &sechdrs[i];
Quoted 8 lines

arch/powerpc/kernel/module_32.c int apply_relocate_add(Elf32_Shdr *sechd · line 287

Quoted 3 lines
arch/powerpc/kernel/module_32.c +3 -0
+	return NULL;
+}
+

It would be nice if this could be put in some common location instead of duplicated between the two files. It builds differently on 32 and 64 bits due to the type defines, but both will never be used in the same kernel.

Or even made completely common, I'll look at it separately.

Ben.