linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y
@ 2016-10-27 16:27 Ard Biesheuvel
  2016-10-27 16:27 ` [PATCH v3 1/3] powerpc/reloc32: fix corrupted modversion CRCs Ard Biesheuvel
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: Ard Biesheuvel @ 2016-10-27 16:27 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, mpe, jeyu
  Cc: will.deacon, rusty, akpm, benh, paulus, Ard Biesheuvel

This series is a followup to the single patch 'modversions: treat symbol
CRCs as 32 bit quantities on 64 bit archs', of which two versions have
been sent out so far [0][1]

As pointed out by Michael, GNU ld behaves a bit differently between arm64
and PowerPC64, and where the former gets rid of all runtime relocations
related to CRCs, the latter is not as easily convinced.

Patch #1 fixes the issue where CRCs are corrupted by the runtime relocation
routines for 32-bit PowerPC, for which the original fix was effectively
reverted by commit 0e0ed6406e61 ("powerpc/modules: Module CRC relocation fix
causes perf issues")

Patch #2 adds handling of R_PPC64_ADDR32 relocations against the NULL .dynsym
symbol entry to the PPC64 runtime relocation routines, so it is prepared to
deal with CRCs being emitted as 32-bit quantities.

Patch #3 is the original patch from the v1 and v2 submissions.

Changes since v2:
- added #1 and #2
- updated #3 to deal with CRC entries being emitted from assembler
- added Rusty's ack (#3)

Branch can be found here:
https://git.kernel.org/cgit/linux/kernel/git/ardb/linux.git/log/?h=kcrctab-reloc

[0] http://marc.info/?l=linux-kernel&m=147652300207369&w=2
[1] http://marc.info/?l=linux-kernel&m=147695629614409&w=2

Ard Biesheuvel (3):
  powerpc/reloc32: fix corrupted modversion CRCs
  powerpc/reloc64: add support for 32-bit CRC pseudo-symbols
  modversions: treat symbol CRCs as 32 bit quantities on 64 bit archs

 arch/powerpc/include/asm/module.h |  4 --
 arch/powerpc/kernel/module_64.c   |  8 ----
 arch/powerpc/kernel/reloc_32.S    | 36 +++++++++++++--
 arch/powerpc/kernel/reloc_64.S    | 22 +++++++--
 arch/powerpc/relocs_check.sh      |  3 +-
 include/asm-generic/export.h      |  7 +--
 include/linux/export.h            |  8 ++++
 include/linux/module.h            | 14 +++---
 kernel/module.c                   | 47 +++++++-------------
 9 files changed, 85 insertions(+), 64 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3 1/3] powerpc/reloc32: fix corrupted modversion CRCs
  2016-10-27 16:27 [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y Ard Biesheuvel
@ 2016-10-27 16:27 ` Ard Biesheuvel
  2016-10-28 10:27   ` Suzuki K Poulose
  2016-10-27 16:27 ` [PATCH v3 2/3] powerpc/reloc64: add support for 32-bit CRC pseudo-symbols Ard Biesheuvel
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 18+ messages in thread
From: Ard Biesheuvel @ 2016-10-27 16:27 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, mpe, jeyu
  Cc: will.deacon, rusty, akpm, benh, paulus, Ard Biesheuvel

Commit 0e0ed6406e61 ("powerpc/modules: Module CRC relocation fix causes
perf issues") fixed an issue with relocatable PIE kernels in a way that
essentially reintroduced the issue again for 32-bit builds.

Since the chosen approach does is not applicable to 32-bit, fix the
issue by updating the runtime relocation routine to ignore the load
offset for the interval [__start___kcrctab, __stop___kcrctab_gpl_future),
which is where the CRCs reside. This ensures that the values of the CRC
pseudo-symbols are no longer made dependent on the runtime load offset.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/powerpc/kernel/reloc_32.S | 36 +++++++++++++++++---
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/reloc_32.S b/arch/powerpc/kernel/reloc_32.S
index f366fedb0872..150686b9febb 100644
--- a/arch/powerpc/kernel/reloc_32.S
+++ b/arch/powerpc/kernel/reloc_32.S
@@ -87,12 +87,12 @@ eodyn:				/* End of Dyn Table scan */
 	 * Work out the current offset from the link time address of .rela
 	 * section.
 	 *  cur_offset[r7] = rela.run[r9] - rela.link [r7]
-	 *  _stext.link[r12] = _stext.run[r10] - cur_offset[r7]
-	 *  final_offset[r3] = _stext.final[r3] - _stext.link[r12]
+	 *  _stext.link[r11] = _stext.run[r10] - cur_offset[r7]
+	 *  final_offset[r3] = _stext.final[r3] - _stext.link[r11]
 	 */
 	subf	r7, r7, r9	/* cur_offset */
-	subf	r12, r7, r10
-	subf	r3, r12, r3	/* final_offset */
+	subf	r11, r7, r10
+	subf	r3, r11, r3	/* final_offset */
 
 	subf	r8, r6, r8	/* relaz -= relaent */
 	/*
@@ -101,6 +101,21 @@ eodyn:				/* End of Dyn Table scan */
 	 * r13	- points to the symbol table
 	 */
 
+#ifdef CONFIG_MODVERSIONS
+	/*
+	 * Treat R_PPC_RELATIVE relocations differently when they target the
+	 * interval [__start___kcrctab, __stop___kcrctab_gpl_future): in this
+	 * case, the relocated quantities are CRC pseudo-symbols, which should
+	 * be preserved as-is, rather than be modified to take the runtime
+	 * offset into account.
+	 */
+	lwz	r10, (p_kcrc_start - 0b)(r12)
+	lwz	r11, (p_kcrc_stop - 0b)(r12)
+	subf	r12, r7, r12			/* link time addr of 0b */
+	add	r10, r10, r12
+	add	r11, r11, r12
+#endif
+
 	/*
 	 * Check if we have a relocation based on symbol
 	 * r5 will hold the value of the symbol.
@@ -135,7 +150,15 @@ get_type:
 	bne	hi16
 	lwz	r4, 0(r9)	/* r_offset */
 	lwz	r0, 8(r9)	/* r_addend */
+#ifdef CONFIG_MODVERSIONS
+	cmplw	r4, r10
+	blt	do_add
+	cmplw	r4, r11
+	blt	skip_add
+do_add:
+#endif
 	add	r0, r0, r3	/* final addend */
+skip_add:
 	stwx	r0, r4, r7	/* memory[r4+r7]) = (u32)r0 */
 	b	nxtrela		/* continue */
 
@@ -207,3 +230,8 @@ p_dyn:		.long	__dynamic_start - 0b
 p_rela:		.long	__rela_dyn_start - 0b
 p_sym:		.long	__dynamic_symtab - 0b
 p_st:		.long	_stext - 0b
+
+#ifdef CONFIG_MODVERSIONS
+p_kcrc_start:	.long	__start___kcrctab - 0b
+p_kcrc_stop:	.long	__stop___kcrctab_gpl_future - 0b
+#endif
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 2/3] powerpc/reloc64: add support for 32-bit CRC pseudo-symbols
  2016-10-27 16:27 [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y Ard Biesheuvel
  2016-10-27 16:27 ` [PATCH v3 1/3] powerpc/reloc32: fix corrupted modversion CRCs Ard Biesheuvel
@ 2016-10-27 16:27 ` Ard Biesheuvel
  2016-11-25 11:29   ` Michael Ellerman
  2016-10-27 16:27 ` [PATCH v3 3/3] modversions: treat symbol CRCs as 32 bit quantities on 64 bit archs Ard Biesheuvel
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 18+ messages in thread
From: Ard Biesheuvel @ 2016-10-27 16:27 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, mpe, jeyu
  Cc: will.deacon, rusty, akpm, benh, paulus, Ard Biesheuvel

In preparation of modifying the core modversions code to emit the CRCs
as 32-bit quantities, ensure that 64-bit PowerPC will be able to deal
with this when CONFIG_RELOCATABLE=y, in which case the CRCs will be
emitted into the final ELF binary as R_PPC64_ADDR32 relocations.

Since 32-bit relocations cannot be used to relocate memory addresses on
64-bit architectures, and since the CRC pseudo-symbol references are
emitted as anonymous relocations (i.e., against the NULL symbol in the
.dynsym section) with the final value recorded in the addend (*), we
can disregard any relocations where the symbol index != 0.

* Note that unsatisfied CRC pseudo-symbol references are emitted as
  R_PPC64_ADDR32 relocations against named symbols that are typed as
  weak undefined in the .dynsym symbol table. These can simply be
  ignored (as before), considering that zero CRCs are interpreted as
  missing, and the module code deals with that accordingly.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/powerpc/kernel/reloc_64.S | 22 ++++++++++++++++----
 arch/powerpc/relocs_check.sh   |  3 ++-
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/kernel/reloc_64.S b/arch/powerpc/kernel/reloc_64.S
index d88736fbece6..7927e00be746 100644
--- a/arch/powerpc/kernel/reloc_64.S
+++ b/arch/powerpc/kernel/reloc_64.S
@@ -14,6 +14,7 @@
 RELA = 7
 RELACOUNT = 0x6ffffff9
 R_PPC64_RELATIVE = 22
+R_PPC64_ADDR32 = 1
 
 /*
  * r3 = desired final address of kernel
@@ -66,10 +67,10 @@ _GLOBAL(relocate)
 
 	/*
 	 * Run through the list of relocations and process the
-	 * R_PPC64_RELATIVE ones.
+	 * R_PPC64_RELATIVE and R_PPC64_ADDR32 ones.
 	 */
 	mtctr	r8
-5:	ld	r0,8(9)		/* ELF64_R_TYPE(reloc->r_info) */
+5:	ld	r0,8(9)		/* reloc->r_info (type *and* symbol index) */
 	cmpdi	r0,R_PPC64_RELATIVE
 	bne	6f
 	ld	r6,0(r9)	/* reloc->r_offset */
@@ -77,9 +78,22 @@ _GLOBAL(relocate)
 	add	r0,r0,r3
 	stdx	r0,r7,r6
 	addi	r9,r9,24
-	bdnz	5b
+	b	7f
+
+	/*
+	 * CRCs of exported symbols are emitted as 32-bit relocations against
+	 * the NULL .dynsym entry, with the CRC value recorded in the addend.
+	 */
+6:	cmpdi	r0,R_PPC64_ADDR32
+	bne	7f
+	ld	r6,0(r9)	/* reloc->r_offset */
+	ld	r0,16(r9)	/* reloc->r_addend */
+	stwx	r0,r7,r6
+	addi	r9,r9,24
+
+7:	bdnz	5b
+	blr
 
-6:	blr
 
 .balign 8
 p_dyn:	.llong	__dynamic_start - 0b
diff --git a/arch/powerpc/relocs_check.sh b/arch/powerpc/relocs_check.sh
index ec2d5c835170..2f510fbc87da 100755
--- a/arch/powerpc/relocs_check.sh
+++ b/arch/powerpc/relocs_check.sh
@@ -43,7 +43,8 @@ R_PPC_ADDR16_HA
 R_PPC_RELATIVE
 R_PPC_NONE' |
 	grep -E -v '\<R_PPC64_ADDR64[[:space:]]+mach_' |
-	grep -E -v '\<R_PPC64_ADDR64[[:space:]]+__crc_'
+	grep -E -v '\<R_PPC64_ADDR64[[:space:]]+__crc_' |
+	grep -E -v '\<R_PPC64_ADDR32[[:space:]]+\*ABS\*'
 )
 
 if [ -z "$bad_relocs" ]; then
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 3/3] modversions: treat symbol CRCs as 32 bit quantities on 64 bit archs
  2016-10-27 16:27 [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y Ard Biesheuvel
  2016-10-27 16:27 ` [PATCH v3 1/3] powerpc/reloc32: fix corrupted modversion CRCs Ard Biesheuvel
  2016-10-27 16:27 ` [PATCH v3 2/3] powerpc/reloc64: add support for 32-bit CRC pseudo-symbols Ard Biesheuvel
@ 2016-10-27 16:27 ` Ard Biesheuvel
  2016-11-04  9:55 ` [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y Ard Biesheuvel
  2016-11-16 19:23 ` Uwe Kleine-König
  4 siblings, 0 replies; 18+ messages in thread
From: Ard Biesheuvel @ 2016-10-27 16:27 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, mpe, jeyu
  Cc: will.deacon, rusty, akpm, benh, paulus, Ard Biesheuvel

The modversion symbol CRCs are emitted as ELF symbols, which allows us to
easily populate the kcrctab sections by relying on the linker to associate
each kcrctab slot with the correct value.

This has a couple of downsides:
- Given that the CRCs are treated as memory addresses, we waste 4 bytes
  for each CRC on 64 bit architectures,
- On architectures that support runtime relocation, a R_<arch>_RELATIVE
  relocation entry is emitted for each CRC value, which identifies it as
  a quantity that requires fixing up based on the actual runtime load
  offset of the kernel. This results in corrupted CRCs unless we
  explicitly undo the fixup (and this is currently being handled in the
  core module code)
- Such runtime relocation entries take up 24 bytes of __init space each,
  resulting in a x8 overhead in [uncompressed] kernel size for CRCs.

Switching to explicit 32 bit values on 64 bit architectures fixes most
of these issues, given that 32 bit values are not treated as quantities
that require fixing up based on the actual runtime load offset. Note that
on some ELF64 architectures [such as PPC64], these 32-bit values are still
emitted as runtime relocatable quantities, even if the value resolves to
a build time constant. However, these can easily be distinguished from
variables that do need fixing up, and the CRCs can be emitted correctly
in the arch specific runtime relocation routines right off the bat.

So redefine all CRC fields and variables as u32, and redefine the
__CRC_SYMBOL() macro for 64 bit builds to emit the CRC reference using
inline assembler (which is necessary since 64-bit C code cannot use
32-bit types to hold memory addresses, even if they are ultimately
resolved using values that do not exceed 0xffffffff.

Note that this mostly reverts commit d4703aefdbc8 ("module: handle ppc64
relocating kcrctabs when CONFIG_RELOCATABLE=y")

Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/powerpc/include/asm/module.h |  4 --
 arch/powerpc/kernel/module_64.c   |  8 ----
 include/asm-generic/export.h      |  7 +--
 include/linux/export.h            |  8 ++++
 include/linux/module.h            | 14 +++---
 kernel/module.c                   | 47 +++++++-------------
 6 files changed, 33 insertions(+), 55 deletions(-)

diff --git a/arch/powerpc/include/asm/module.h b/arch/powerpc/include/asm/module.h
index cd4ffd86765f..94a7f7aa3ae8 100644
--- a/arch/powerpc/include/asm/module.h
+++ b/arch/powerpc/include/asm/module.h
@@ -94,9 +94,5 @@ struct exception_table_entry;
 void sort_ex_table(struct exception_table_entry *start,
 		   struct exception_table_entry *finish);
 
-#if defined(CONFIG_MODVERSIONS) && defined(CONFIG_PPC64)
-#define ARCH_RELOCATES_KCRCTAB
-#define reloc_start PHYSICAL_START
-#endif
 #endif /* __KERNEL__ */
 #endif	/* _ASM_POWERPC_MODULE_H */
diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c
index 183368e008cf..be9b2d5ff846 100644
--- a/arch/powerpc/kernel/module_64.c
+++ b/arch/powerpc/kernel/module_64.c
@@ -286,14 +286,6 @@ static void dedotify_versions(struct modversion_info *vers,
 	for (end = (void *)vers + size; vers < end; vers++)
 		if (vers->name[0] == '.') {
 			memmove(vers->name, vers->name+1, strlen(vers->name));
-#ifdef ARCH_RELOCATES_KCRCTAB
-			/* The TOC symbol has no CRC computed. To avoid CRC
-			 * check failing, we must force it to the expected
-			 * value (see CRC check in module.c).
-			 */
-			if (!strcmp(vers->name, "TOC."))
-				vers->crc = -(unsigned long)reloc_start;
-#endif
 		}
 }
 
diff --git a/include/asm-generic/export.h b/include/asm-generic/export.h
index 43199a049da5..d245910d026b 100644
--- a/include/asm-generic/export.h
+++ b/include/asm-generic/export.h
@@ -9,18 +9,15 @@
 #ifndef KSYM_ALIGN
 #define KSYM_ALIGN 8
 #endif
-#ifndef KCRC_ALIGN
-#define KCRC_ALIGN 8
-#endif
 #else
 #define __put .long
 #ifndef KSYM_ALIGN
 #define KSYM_ALIGN 4
 #endif
+#endif
 #ifndef KCRC_ALIGN
 #define KCRC_ALIGN 4
 #endif
-#endif
 
 #ifdef CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX
 #define KSYM(name) _##name
@@ -52,7 +49,7 @@ KSYM(__kstrtab_\name):
 	.section ___kcrctab\sec+\name,"a"
 	.balign KCRC_ALIGN
 KSYM(__kcrctab_\name):
-	__put KSYM(__crc_\name)
+	.long KSYM(__crc_\name)
 	.weak KSYM(__crc_\name)
 	.previous
 #endif
diff --git a/include/linux/export.h b/include/linux/export.h
index 2a0f61fbc731..a000d421526d 100644
--- a/include/linux/export.h
+++ b/include/linux/export.h
@@ -41,6 +41,7 @@ extern struct module __this_module;
 
 #if defined(__KERNEL__) && !defined(__GENKSYMS__)
 #ifdef CONFIG_MODVERSIONS
+#ifndef CONFIG_64BIT
 /* Mark the CRC weak since genksyms apparently decides not to
  * generate a checksums for some symbols */
 #define __CRC_SYMBOL(sym, sec)						\
@@ -50,6 +51,13 @@ extern struct module __this_module;
 	__attribute__((section("___kcrctab" sec "+" #sym), used))	\
 	= (unsigned long) &__crc_##sym;
 #else
+#define __CRC_SYMBOL(sym, sec)						\
+	asm("	.section \"___kcrctab" sec "+" #sym "\", \"a\"	\n"	\
+	    "	.weak	" VMLINUX_SYMBOL_STR(__crc_##sym) "	\n"	\
+	    "	.long	" VMLINUX_SYMBOL_STR(__crc_##sym) "	\n"	\
+	    "	.previous					\n");
+#endif
+#else
 #define __CRC_SYMBOL(sym, sec)
 #endif
 
diff --git a/include/linux/module.h b/include/linux/module.h
index 0c3207d26ac0..e0067673f5e5 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -346,7 +346,7 @@ struct module {
 
 	/* Exported symbols */
 	const struct kernel_symbol *syms;
-	const unsigned long *crcs;
+	const u32 *crcs;
 	unsigned int num_syms;
 
 	/* Kernel parameters. */
@@ -359,18 +359,18 @@ struct module {
 	/* GPL-only exported symbols. */
 	unsigned int num_gpl_syms;
 	const struct kernel_symbol *gpl_syms;
-	const unsigned long *gpl_crcs;
+	const u32 *gpl_crcs;
 
 #ifdef CONFIG_UNUSED_SYMBOLS
 	/* unused exported symbols. */
 	const struct kernel_symbol *unused_syms;
-	const unsigned long *unused_crcs;
+	const u32 *unused_crcs;
 	unsigned int num_unused_syms;
 
 	/* GPL-only, unused exported symbols. */
 	unsigned int num_unused_gpl_syms;
 	const struct kernel_symbol *unused_gpl_syms;
-	const unsigned long *unused_gpl_crcs;
+	const u32 *unused_gpl_crcs;
 #endif
 
 #ifdef CONFIG_MODULE_SIG
@@ -382,7 +382,7 @@ struct module {
 
 	/* symbols that will be GPL-only in the near future. */
 	const struct kernel_symbol *gpl_future_syms;
-	const unsigned long *gpl_future_crcs;
+	const u32 *gpl_future_crcs;
 	unsigned int num_gpl_future_syms;
 
 	/* Exception table */
@@ -523,7 +523,7 @@ struct module *find_module(const char *name);
 
 struct symsearch {
 	const struct kernel_symbol *start, *stop;
-	const unsigned long *crcs;
+	const u32 *crcs;
 	enum {
 		NOT_GPL_ONLY,
 		GPL_ONLY,
@@ -539,7 +539,7 @@ struct symsearch {
  */
 const struct kernel_symbol *find_symbol(const char *name,
 					struct module **owner,
-					const unsigned long **crc,
+					const u32 **crc,
 					bool gplok,
 					bool warn);
 
diff --git a/kernel/module.c b/kernel/module.c
index f57dd63186e6..18d92e710a13 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -386,16 +386,16 @@ extern const struct kernel_symbol __start___ksymtab_gpl[];
 extern const struct kernel_symbol __stop___ksymtab_gpl[];
 extern const struct kernel_symbol __start___ksymtab_gpl_future[];
 extern const struct kernel_symbol __stop___ksymtab_gpl_future[];
-extern const unsigned long __start___kcrctab[];
-extern const unsigned long __start___kcrctab_gpl[];
-extern const unsigned long __start___kcrctab_gpl_future[];
+extern const u32 __start___kcrctab[];
+extern const u32 __start___kcrctab_gpl[];
+extern const u32 __start___kcrctab_gpl_future[];
 #ifdef CONFIG_UNUSED_SYMBOLS
 extern const struct kernel_symbol __start___ksymtab_unused[];
 extern const struct kernel_symbol __stop___ksymtab_unused[];
 extern const struct kernel_symbol __start___ksymtab_unused_gpl[];
 extern const struct kernel_symbol __stop___ksymtab_unused_gpl[];
-extern const unsigned long __start___kcrctab_unused[];
-extern const unsigned long __start___kcrctab_unused_gpl[];
+extern const u32 __start___kcrctab_unused[];
+extern const u32 __start___kcrctab_unused_gpl[];
 #endif
 
 #ifndef CONFIG_MODVERSIONS
@@ -494,7 +494,7 @@ struct find_symbol_arg {
 
 	/* Output */
 	struct module *owner;
-	const unsigned long *crc;
+	const u32 *crc;
 	const struct kernel_symbol *sym;
 };
 
@@ -560,7 +560,7 @@ static bool find_symbol_in_section(const struct symsearch *syms,
  * (optional) module which owns it.  Needs preempt disabled or module_mutex. */
 const struct kernel_symbol *find_symbol(const char *name,
 					struct module **owner,
-					const unsigned long **crc,
+					const u32 **crc,
 					bool gplok,
 					bool warn)
 {
@@ -1257,23 +1257,11 @@ static int try_to_force_load(struct module *mod, const char *reason)
 }
 
 #ifdef CONFIG_MODVERSIONS
-/* If the arch applies (non-zero) relocations to kernel kcrctab, unapply it. */
-static unsigned long maybe_relocated(unsigned long crc,
-				     const struct module *crc_owner)
-{
-#ifdef ARCH_RELOCATES_KCRCTAB
-	if (crc_owner == NULL)
-		return crc - (unsigned long)reloc_start;
-#endif
-	return crc;
-}
-
 static int check_version(Elf_Shdr *sechdrs,
 			 unsigned int versindex,
 			 const char *symname,
 			 struct module *mod,
-			 const unsigned long *crc,
-			 const struct module *crc_owner)
+			 const u32 *crc)
 {
 	unsigned int i, num_versions;
 	struct modversion_info *versions;
@@ -1294,10 +1282,10 @@ static int check_version(Elf_Shdr *sechdrs,
 		if (strcmp(versions[i].name, symname) != 0)
 			continue;
 
-		if (versions[i].crc == maybe_relocated(*crc, crc_owner))
+		if (versions[i].crc == *crc)
 			return 1;
-		pr_debug("Found checksum %lX vs module %lX\n",
-		       maybe_relocated(*crc, crc_owner), versions[i].crc);
+		pr_debug("Found checksum %X vs module %lX\n",
+		       *crc, versions[i].crc);
 		goto bad_version;
 	}
 
@@ -1314,7 +1302,7 @@ static inline int check_modstruct_version(Elf_Shdr *sechdrs,
 					  unsigned int versindex,
 					  struct module *mod)
 {
-	const unsigned long *crc;
+	const u32 *crc;
 
 	/*
 	 * Since this should be found in kernel (which can't be removed), no
@@ -1328,8 +1316,7 @@ static inline int check_modstruct_version(Elf_Shdr *sechdrs,
 	}
 	preempt_enable();
 	return check_version(sechdrs, versindex,
-			     VMLINUX_SYMBOL_STR(module_layout), mod, crc,
-			     NULL);
+			     VMLINUX_SYMBOL_STR(module_layout), mod, crc);
 }
 
 /* First part is kernel version, which we ignore if module has crcs. */
@@ -1347,8 +1334,7 @@ static inline int check_version(Elf_Shdr *sechdrs,
 				unsigned int versindex,
 				const char *symname,
 				struct module *mod,
-				const unsigned long *crc,
-				const struct module *crc_owner)
+				const u32 *crc)
 {
 	return 1;
 }
@@ -1375,7 +1361,7 @@ static const struct kernel_symbol *resolve_symbol(struct module *mod,
 {
 	struct module *owner;
 	const struct kernel_symbol *sym;
-	const unsigned long *crc;
+	const u32 *crc;
 	int err;
 
 	/*
@@ -1390,8 +1376,7 @@ static const struct kernel_symbol *resolve_symbol(struct module *mod,
 	if (!sym)
 		goto unlock;
 
-	if (!check_version(info->sechdrs, info->index.vers, name, mod, crc,
-			   owner)) {
+	if (!check_version(info->sechdrs, info->index.vers, name, mod, crc)) {
 		sym = ERR_PTR(-EINVAL);
 		goto getname;
 	}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 1/3] powerpc/reloc32: fix corrupted modversion CRCs
  2016-10-27 16:27 ` [PATCH v3 1/3] powerpc/reloc32: fix corrupted modversion CRCs Ard Biesheuvel
@ 2016-10-28 10:27   ` Suzuki K Poulose
  0 siblings, 0 replies; 18+ messages in thread
From: Suzuki K Poulose @ 2016-10-28 10:27 UTC (permalink / raw)
  To: Ard Biesheuvel, linux-kernel, linux-arm-kernel, mpe, jeyu
  Cc: will.deacon, rusty, akpm, benh, paulus, Athira Rajeev, ananth

On 27/10/16 17:27, Ard Biesheuvel wrote:
> Commit 0e0ed6406e61 ("powerpc/modules: Module CRC relocation fix causes
> perf issues") fixed an issue with relocatable PIE kernels in a way that
> essentially reintroduced the issue again for 32-bit builds.
>
> Since the chosen approach does is not applicable to 32-bit, fix the
> issue by updating the runtime relocation routine to ignore the load
> offset for the interval [__start___kcrctab, __stop___kcrctab_gpl_future),
> which is where the CRCs reside. This ensures that the values of the CRC
> pseudo-symbols are no longer made dependent on the runtime load offset.
>
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

Ard,

These changes look good to me (having originally written the code).

Reviewed-by : Suzuki K Poulose <suzuki.poulose@arm.com>

Cheers
Suzuki

> ---
>  arch/powerpc/kernel/reloc_32.S | 36 +++++++++++++++++---
>  1 file changed, 32 insertions(+), 4 deletions(-)
>
> diff --git a/arch/powerpc/kernel/reloc_32.S b/arch/powerpc/kernel/reloc_32.S
> index f366fedb0872..150686b9febb 100644
> --- a/arch/powerpc/kernel/reloc_32.S
> +++ b/arch/powerpc/kernel/reloc_32.S
> @@ -87,12 +87,12 @@ eodyn:				/* End of Dyn Table scan */
>  	 * Work out the current offset from the link time address of .rela
>  	 * section.
>  	 *  cur_offset[r7] = rela.run[r9] - rela.link [r7]
> -	 *  _stext.link[r12] = _stext.run[r10] - cur_offset[r7]
> -	 *  final_offset[r3] = _stext.final[r3] - _stext.link[r12]
> +	 *  _stext.link[r11] = _stext.run[r10] - cur_offset[r7]
> +	 *  final_offset[r3] = _stext.final[r3] - _stext.link[r11]
>  	 */
>  	subf	r7, r7, r9	/* cur_offset */
> -	subf	r12, r7, r10
> -	subf	r3, r12, r3	/* final_offset */
> +	subf	r11, r7, r10
> +	subf	r3, r11, r3	/* final_offset */
>
>  	subf	r8, r6, r8	/* relaz -= relaent */
>  	/*
> @@ -101,6 +101,21 @@ eodyn:				/* End of Dyn Table scan */
>  	 * r13	- points to the symbol table
>  	 */
>
> +#ifdef CONFIG_MODVERSIONS
> +	/*
> +	 * Treat R_PPC_RELATIVE relocations differently when they target the
> +	 * interval [__start___kcrctab, __stop___kcrctab_gpl_future): in this
> +	 * case, the relocated quantities are CRC pseudo-symbols, which should
> +	 * be preserved as-is, rather than be modified to take the runtime
> +	 * offset into account.
> +	 */
> +	lwz	r10, (p_kcrc_start - 0b)(r12)
> +	lwz	r11, (p_kcrc_stop - 0b)(r12)
> +	subf	r12, r7, r12			/* link time addr of 0b */
> +	add	r10, r10, r12
> +	add	r11, r11, r12
> +#endif
> +
>  	/*
>  	 * Check if we have a relocation based on symbol
>  	 * r5 will hold the value of the symbol.
> @@ -135,7 +150,15 @@ get_type:
>  	bne	hi16
>  	lwz	r4, 0(r9)	/* r_offset */
>  	lwz	r0, 8(r9)	/* r_addend */
> +#ifdef CONFIG_MODVERSIONS
> +	cmplw	r4, r10
> +	blt	do_add
> +	cmplw	r4, r11
> +	blt	skip_add
> +do_add:
> +#endif
>  	add	r0, r0, r3	/* final addend */
> +skip_add:
>  	stwx	r0, r4, r7	/* memory[r4+r7]) = (u32)r0 */
>  	b	nxtrela		/* continue */
>
> @@ -207,3 +230,8 @@ p_dyn:		.long	__dynamic_start - 0b
>  p_rela:		.long	__rela_dyn_start - 0b
>  p_sym:		.long	__dynamic_symtab - 0b
>  p_st:		.long	_stext - 0b
> +
> +#ifdef CONFIG_MODVERSIONS
> +p_kcrc_start:	.long	__start___kcrctab - 0b
> +p_kcrc_stop:	.long	__stop___kcrctab_gpl_future - 0b
> +#endif
>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y
  2016-10-27 16:27 [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y Ard Biesheuvel
                   ` (2 preceding siblings ...)
  2016-10-27 16:27 ` [PATCH v3 3/3] modversions: treat symbol CRCs as 32 bit quantities on 64 bit archs Ard Biesheuvel
@ 2016-11-04  9:55 ` Ard Biesheuvel
  2016-11-10  4:22   ` Michael Ellerman
  2016-11-16 19:23 ` Uwe Kleine-König
  4 siblings, 1 reply; 18+ messages in thread
From: Ard Biesheuvel @ 2016-11-04  9:55 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, Michael Ellerman, jeyu
  Cc: Will Deacon, Rusty Russell, Andrew Morton,
	Benjamin Herrenschmidt, paulus, Ard Biesheuvel

On 27 October 2016 at 17:27, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> This series is a followup to the single patch 'modversions: treat symbol
> CRCs as 32 bit quantities on 64 bit archs', of which two versions have
> been sent out so far [0][1]
>
> As pointed out by Michael, GNU ld behaves a bit differently between arm64
> and PowerPC64, and where the former gets rid of all runtime relocations
> related to CRCs, the latter is not as easily convinced.
>
> Patch #1 fixes the issue where CRCs are corrupted by the runtime relocation
> routines for 32-bit PowerPC, for which the original fix was effectively
> reverted by commit 0e0ed6406e61 ("powerpc/modules: Module CRC relocation fix
> causes perf issues")
>
> Patch #2 adds handling of R_PPC64_ADDR32 relocations against the NULL .dynsym
> symbol entry to the PPC64 runtime relocation routines, so it is prepared to
> deal with CRCs being emitted as 32-bit quantities.
>
> Patch #3 is the original patch from the v1 and v2 submissions.
>
> Changes since v2:
> - added #1 and #2
> - updated #3 to deal with CRC entries being emitted from assembler
> - added Rusty's ack (#3)
>
> Branch can be found here:
> https://git.kernel.org/cgit/linux/kernel/git/ardb/linux.git/log/?h=kcrctab-reloc
>
> [0] http://marc.info/?l=linux-kernel&m=147652300207369&w=2
> [1] http://marc.info/?l=linux-kernel&m=147695629614409&w=2
>

Ping?

> Ard Biesheuvel (3):
>   powerpc/reloc32: fix corrupted modversion CRCs
>   powerpc/reloc64: add support for 32-bit CRC pseudo-symbols
>   modversions: treat symbol CRCs as 32 bit quantities on 64 bit archs
>
>  arch/powerpc/include/asm/module.h |  4 --
>  arch/powerpc/kernel/module_64.c   |  8 ----
>  arch/powerpc/kernel/reloc_32.S    | 36 +++++++++++++--
>  arch/powerpc/kernel/reloc_64.S    | 22 +++++++--
>  arch/powerpc/relocs_check.sh      |  3 +-
>  include/asm-generic/export.h      |  7 +--
>  include/linux/export.h            |  8 ++++
>  include/linux/module.h            | 14 +++---
>  kernel/module.c                   | 47 +++++++-------------
>  9 files changed, 85 insertions(+), 64 deletions(-)
>
> --
> 2.7.4
>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y
  2016-11-04  9:55 ` [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y Ard Biesheuvel
@ 2016-11-10  4:22   ` Michael Ellerman
  2016-11-15  9:13     ` Ard Biesheuvel
  0 siblings, 1 reply; 18+ messages in thread
From: Michael Ellerman @ 2016-11-10  4:22 UTC (permalink / raw)
  To: Ard Biesheuvel, linux-kernel, linux-arm-kernel, jeyu
  Cc: Will Deacon, Rusty Russell, Andrew Morton,
	Benjamin Herrenschmidt, paulus, Ard Biesheuvel

Ard Biesheuvel <ard.biesheuvel@linaro.org> writes:

> On 27 October 2016 at 17:27, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>> This series is a followup to the single patch 'modversions: treat symbol
>> CRCs as 32 bit quantities on 64 bit archs', of which two versions have
>> been sent out so far [0][1]
>>
>> As pointed out by Michael, GNU ld behaves a bit differently between arm64
>> and PowerPC64, and where the former gets rid of all runtime relocations
>> related to CRCs, the latter is not as easily convinced.
>>
>> Patch #1 fixes the issue where CRCs are corrupted by the runtime relocation
>> routines for 32-bit PowerPC, for which the original fix was effectively
>> reverted by commit 0e0ed6406e61 ("powerpc/modules: Module CRC relocation fix
>> causes perf issues")
>>
>> Patch #2 adds handling of R_PPC64_ADDR32 relocations against the NULL .dynsym
>> symbol entry to the PPC64 runtime relocation routines, so it is prepared to
>> deal with CRCs being emitted as 32-bit quantities.
>>
>> Patch #3 is the original patch from the v1 and v2 submissions.
>>
>> Changes since v2:
>> - added #1 and #2
>> - updated #3 to deal with CRC entries being emitted from assembler
>> - added Rusty's ack (#3)
>>
>> Branch can be found here:
>> https://git.kernel.org/cgit/linux/kernel/git/ardb/linux.git/log/?h=kcrctab-reloc
>>
>> [0] http://marc.info/?l=linux-kernel&m=147652300207369&w=2
>> [1] http://marc.info/?l=linux-kernel&m=147695629614409&w=2
>
> Ping?

Sorry, you didn't cc linuxppc-dev, so it's not in my patchwork list
which tends to mean I miss it.

Will try and test and get back to you.

cheers

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y
  2016-11-10  4:22   ` Michael Ellerman
@ 2016-11-15  9:13     ` Ard Biesheuvel
  2016-11-25  8:44       ` Ard Biesheuvel
  0 siblings, 1 reply; 18+ messages in thread
From: Ard Biesheuvel @ 2016-11-15  9:13 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: linux-kernel, linux-arm-kernel, jeyu, Will Deacon, Rusty Russell,
	Andrew Morton, Benjamin Herrenschmidt, paulus

On 10 November 2016 at 05:22, Michael Ellerman <mpe@ellerman.id.au> wrote:
> Ard Biesheuvel <ard.biesheuvel@linaro.org> writes:
>
>> On 27 October 2016 at 17:27, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>>> This series is a followup to the single patch 'modversions: treat symbol
>>> CRCs as 32 bit quantities on 64 bit archs', of which two versions have
>>> been sent out so far [0][1]
>>>
>>> As pointed out by Michael, GNU ld behaves a bit differently between arm64
>>> and PowerPC64, and where the former gets rid of all runtime relocations
>>> related to CRCs, the latter is not as easily convinced.
>>>
>>> Patch #1 fixes the issue where CRCs are corrupted by the runtime relocation
>>> routines for 32-bit PowerPC, for which the original fix was effectively
>>> reverted by commit 0e0ed6406e61 ("powerpc/modules: Module CRC relocation fix
>>> causes perf issues")
>>>
>>> Patch #2 adds handling of R_PPC64_ADDR32 relocations against the NULL .dynsym
>>> symbol entry to the PPC64 runtime relocation routines, so it is prepared to
>>> deal with CRCs being emitted as 32-bit quantities.
>>>
>>> Patch #3 is the original patch from the v1 and v2 submissions.
>>>
>>> Changes since v2:
>>> - added #1 and #2
>>> - updated #3 to deal with CRC entries being emitted from assembler
>>> - added Rusty's ack (#3)
>>>
>>> Branch can be found here:
>>> https://git.kernel.org/cgit/linux/kernel/git/ardb/linux.git/log/?h=kcrctab-reloc
>>>
>>> [0] http://marc.info/?l=linux-kernel&m=147652300207369&w=2
>>> [1] http://marc.info/?l=linux-kernel&m=147695629614409&w=2
>>
>> Ping?
>
> Sorry, you didn't cc linuxppc-dev, so it's not in my patchwork list
> which tends to mean I miss it.
>

Ah, my mistake. Apologies.

> Will try and test and get back to you.
>

Thanks!

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y
  2016-10-27 16:27 [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y Ard Biesheuvel
                   ` (3 preceding siblings ...)
  2016-11-04  9:55 ` [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y Ard Biesheuvel
@ 2016-11-16 19:23 ` Uwe Kleine-König
  2016-11-16 20:29   ` Ard Biesheuvel
  4 siblings, 1 reply; 18+ messages in thread
From: Uwe Kleine-König @ 2016-11-16 19:23 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-kernel, linux-arm-kernel, mpe, jeyu, benh, rusty,
	will.deacon, paulus, akpm

On Thu, Oct 27, 2016 at 05:27:08PM +0100, Ard Biesheuvel wrote:
> This series is a followup to the single patch 'modversions: treat symbol
> CRCs as 32 bit quantities on 64 bit archs', of which two versions have
> been sent out so far [0][1]
> 
> As pointed out by Michael, GNU ld behaves a bit differently between arm64
> and PowerPC64, and where the former gets rid of all runtime relocations
> related to CRCs, the latter is not as easily convinced.
> 
> Patch #1 fixes the issue where CRCs are corrupted by the runtime relocation
> routines for 32-bit PowerPC, for which the original fix was effectively
> reverted by commit 0e0ed6406e61 ("powerpc/modules: Module CRC relocation fix
> causes perf issues")
> 
> Patch #2 adds handling of R_PPC64_ADDR32 relocations against the NULL .dynsym
> symbol entry to the PPC64 runtime relocation routines, so it is prepared to
> deal with CRCs being emitted as 32-bit quantities.
> 
> Patch #3 is the original patch from the v1 and v2 submissions.

Is this related to me seeing 

[    2.111424] mvneta: module verification failed: signature and/or required key missing - tainting kernel
[    2.126061] scsi_mod: no symbol version for _clear_bit
[    2.131257] scsi_mod: Unknown symbol _clear_bit (err -22)
[    2.138093] mvneta: no symbol version for _clear_bit
[    2.143117] mvneta: Unknown symbol _clear_bit (err -22)
[    2.144135] mvmdio: no symbol version for __gnu_mcount_nc
[    2.144138] mvmdio: Unknown symbol __gnu_mcount_nc (err -22)
...

? If so, this would be great to mention it in the commit log to make
people searching for this issue actually find this patch set.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y
  2016-11-16 19:23 ` Uwe Kleine-König
@ 2016-11-16 20:29   ` Ard Biesheuvel
  0 siblings, 0 replies; 18+ messages in thread
From: Ard Biesheuvel @ 2016-11-16 20:29 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: linux-kernel, linux-arm-kernel, Michael Ellerman, jeyu,
	Benjamin Herrenschmidt, Rusty Russell, Will Deacon, paulus,
	Andrew Morton

On 16 November 2016 at 19:23, Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
> On Thu, Oct 27, 2016 at 05:27:08PM +0100, Ard Biesheuvel wrote:
>> This series is a followup to the single patch 'modversions: treat symbol
>> CRCs as 32 bit quantities on 64 bit archs', of which two versions have
>> been sent out so far [0][1]
>>
>> As pointed out by Michael, GNU ld behaves a bit differently between arm64
>> and PowerPC64, and where the former gets rid of all runtime relocations
>> related to CRCs, the latter is not as easily convinced.
>>
>> Patch #1 fixes the issue where CRCs are corrupted by the runtime relocation
>> routines for 32-bit PowerPC, for which the original fix was effectively
>> reverted by commit 0e0ed6406e61 ("powerpc/modules: Module CRC relocation fix
>> causes perf issues")
>>
>> Patch #2 adds handling of R_PPC64_ADDR32 relocations against the NULL .dynsym
>> symbol entry to the PPC64 runtime relocation routines, so it is prepared to
>> deal with CRCs being emitted as 32-bit quantities.
>>
>> Patch #3 is the original patch from the v1 and v2 submissions.
>
> Is this related to me seeing
>
> [    2.111424] mvneta: module verification failed: signature and/or required key missing - tainting kernel
> [    2.126061] scsi_mod: no symbol version for _clear_bit
> [    2.131257] scsi_mod: Unknown symbol _clear_bit (err -22)
> [    2.138093] mvneta: no symbol version for _clear_bit
> [    2.143117] mvneta: Unknown symbol _clear_bit (err -22)
> [    2.144135] mvmdio: no symbol version for __gnu_mcount_nc
> [    2.144138] mvmdio: Unknown symbol __gnu_mcount_nc (err -22)
> ...
>
> ? If so, this would be great to mention it in the commit log to make
> people searching for this issue actually find this patch set.
>

No, I don't think it is. My guess would be that it is caused by

https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=4dd1837d75

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y
  2016-11-15  9:13     ` Ard Biesheuvel
@ 2016-11-25  8:44       ` Ard Biesheuvel
  2016-11-25 11:12         ` Michael Ellerman
  0 siblings, 1 reply; 18+ messages in thread
From: Ard Biesheuvel @ 2016-11-25  8:44 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: linux-kernel, linux-arm-kernel, jeyu, Will Deacon, Rusty Russell,
	Andrew Morton, Benjamin Herrenschmidt, paulus

On 15 November 2016 at 09:13, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> On 10 November 2016 at 05:22, Michael Ellerman <mpe@ellerman.id.au> wrote:
>> Ard Biesheuvel <ard.biesheuvel@linaro.org> writes:
>>
>>> On 27 October 2016 at 17:27, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>>>> This series is a followup to the single patch 'modversions: treat symbol
>>>> CRCs as 32 bit quantities on 64 bit archs', of which two versions have
>>>> been sent out so far [0][1]
>>>>
>>>> As pointed out by Michael, GNU ld behaves a bit differently between arm64
>>>> and PowerPC64, and where the former gets rid of all runtime relocations
>>>> related to CRCs, the latter is not as easily convinced.
>>>>
>>>> Patch #1 fixes the issue where CRCs are corrupted by the runtime relocation
>>>> routines for 32-bit PowerPC, for which the original fix was effectively
>>>> reverted by commit 0e0ed6406e61 ("powerpc/modules: Module CRC relocation fix
>>>> causes perf issues")
>>>>
>>>> Patch #2 adds handling of R_PPC64_ADDR32 relocations against the NULL .dynsym
>>>> symbol entry to the PPC64 runtime relocation routines, so it is prepared to
>>>> deal with CRCs being emitted as 32-bit quantities.
>>>>
>>>> Patch #3 is the original patch from the v1 and v2 submissions.
>>>>
>>>> Changes since v2:
>>>> - added #1 and #2
>>>> - updated #3 to deal with CRC entries being emitted from assembler
>>>> - added Rusty's ack (#3)
>>>>
>>>> Branch can be found here:
>>>> https://git.kernel.org/cgit/linux/kernel/git/ardb/linux.git/log/?h=kcrctab-reloc
>>>>
>>>> [0] http://marc.info/?l=linux-kernel&m=147652300207369&w=2
>>>> [1] http://marc.info/?l=linux-kernel&m=147695629614409&w=2
>>>
>>> Ping?
>>
>> Sorry, you didn't cc linuxppc-dev, so it's not in my patchwork list
>> which tends to mean I miss it.
>>
>
> Ah, my mistake. Apologies.
>
>> Will try and test and get back to you.
>>
>

Ping?

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y
  2016-11-25  8:44       ` Ard Biesheuvel
@ 2016-11-25 11:12         ` Michael Ellerman
  0 siblings, 0 replies; 18+ messages in thread
From: Michael Ellerman @ 2016-11-25 11:12 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-kernel, linux-arm-kernel, jeyu, Will Deacon, Rusty Russell,
	Andrew Morton, Benjamin Herrenschmidt, paulus

Ard Biesheuvel <ard.biesheuvel@linaro.org> writes:

> On 15 November 2016 at 09:13, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>> On 10 November 2016 at 05:22, Michael Ellerman <mpe@ellerman.id.au> wrote:
>>> Ard Biesheuvel <ard.biesheuvel@linaro.org> writes:
>>>
>>>> On 27 October 2016 at 17:27, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>>>>> This series is a followup to the single patch 'modversions: treat symbol
>>>>> CRCs as 32 bit quantities on 64 bit archs', of which two versions have
>>>>> been sent out so far [0][1]
>>>>>
>>>>> As pointed out by Michael, GNU ld behaves a bit differently between arm64
>>>>> and PowerPC64, and where the former gets rid of all runtime relocations
>>>>> related to CRCs, the latter is not as easily convinced.
>>>>>
>>>>> Patch #1 fixes the issue where CRCs are corrupted by the runtime relocation
>>>>> routines for 32-bit PowerPC, for which the original fix was effectively
>>>>> reverted by commit 0e0ed6406e61 ("powerpc/modules: Module CRC relocation fix
>>>>> causes perf issues")
>>>>>
>>>>> Patch #2 adds handling of R_PPC64_ADDR32 relocations against the NULL .dynsym
>>>>> symbol entry to the PPC64 runtime relocation routines, so it is prepared to
>>>>> deal with CRCs being emitted as 32-bit quantities.
>>>>>
>>>>> Patch #3 is the original patch from the v1 and v2 submissions.
>>>>>
>>>>> Changes since v2:
>>>>> - added #1 and #2
>>>>> - updated #3 to deal with CRC entries being emitted from assembler
>>>>> - added Rusty's ack (#3)
>>>>>
>>>>> Branch can be found here:
>>>>> https://git.kernel.org/cgit/linux/kernel/git/ardb/linux.git/log/?h=kcrctab-reloc
>>>>>
>>>>> [0] http://marc.info/?l=linux-kernel&m=147652300207369&w=2
>>>>> [1] http://marc.info/?l=linux-kernel&m=147695629614409&w=2
>>>>
>>>> Ping?
>>>
>>> Sorry, you didn't cc linuxppc-dev, so it's not in my patchwork list
>>> which tends to mean I miss it.
>>
>> Ah, my mistake. Apologies.
>>
>>> Will try and test and get back to you.
>
> Ping?

Sorry :/

I tried testing it last week or so but it was interacting badly with the
other modversion CRC problems we were having (fixed recently in my fixes
branch).

I'll rebase on top of those fixes and try again.

cheers

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/3] powerpc/reloc64: add support for 32-bit CRC pseudo-symbols
  2016-10-27 16:27 ` [PATCH v3 2/3] powerpc/reloc64: add support for 32-bit CRC pseudo-symbols Ard Biesheuvel
@ 2016-11-25 11:29   ` Michael Ellerman
  2016-11-25 12:48     ` Ard Biesheuvel
  0 siblings, 1 reply; 18+ messages in thread
From: Michael Ellerman @ 2016-11-25 11:29 UTC (permalink / raw)
  To: Ard Biesheuvel, linux-kernel, linux-arm-kernel, jeyu
  Cc: will.deacon, rusty, akpm, benh, paulus, Ard Biesheuvel

Ard Biesheuvel <ard.biesheuvel@linaro.org> writes:

> diff --git a/arch/powerpc/relocs_check.sh b/arch/powerpc/relocs_check.sh
> index ec2d5c835170..2f510fbc87da 100755
> --- a/arch/powerpc/relocs_check.sh
> +++ b/arch/powerpc/relocs_check.sh
> @@ -43,7 +43,8 @@ R_PPC_ADDR16_HA
>  R_PPC_RELATIVE
>  R_PPC_NONE' |
>  	grep -E -v '\<R_PPC64_ADDR64[[:space:]]+mach_' |
> -	grep -E -v '\<R_PPC64_ADDR64[[:space:]]+__crc_'
> +	grep -E -v '\<R_PPC64_ADDR64[[:space:]]+__crc_' |
> +	grep -E -v '\<R_PPC64_ADDR32[[:space:]]+\*ABS\*'

I'm still getting:

WARNING: 24 bad relocations
c000000000d307c4 R_PPC64_ADDR32    __crc___arch_hweight16
c000000000d307c8 R_PPC64_ADDR32    __crc___arch_hweight32
c000000000d307cc R_PPC64_ADDR32    __crc___arch_hweight64
c000000000d307d0 R_PPC64_ADDR32    __crc___arch_hweight8
c000000000d30848 R_PPC64_ADDR32    __crc___bswapdi2
c000000000d30854 R_PPC64_ADDR32    __crc___clear_user
c000000000d30868 R_PPC64_ADDR32    __crc___copy_tofrom_user
c000000000d30d4c R_PPC64_ADDR32    __crc__mcount
c000000000d31344 R_PPC64_ADDR32    __crc_copy_page
c000000000d3141c R_PPC64_ADDR32    __crc_current_stack_pointer
c000000000d31840 R_PPC64_ADDR32    __crc_empty_zero_page
c000000000d31a7c R_PPC64_ADDR32    __crc_flush_dcache_range
c000000000d31a84 R_PPC64_ADDR32    __crc_flush_icache_range
c000000000d32608 R_PPC64_ADDR32    __crc_load_fp_state
c000000000d32614 R_PPC64_ADDR32    __crc_load_vr_state
c000000000d32828 R_PPC64_ADDR32    __crc_memchr
c000000000d32830 R_PPC64_ADDR32    __crc_memcmp
c000000000d32834 R_PPC64_ADDR32    __crc_memcpy
c000000000d32840 R_PPC64_ADDR32    __crc_memmove
c000000000d32888 R_PPC64_ADDR32    __crc_memset
c000000000d33c9c R_PPC64_ADDR32    __crc_store_fp_state
c000000000d33ca0 R_PPC64_ADDR32    __crc_store_vr_state
c000000000d33cf0 R_PPC64_ADDR32    __crc_strncmp
c000000000d33cf4 R_PPC64_ADDR32    __crc_strncpy


If I just add those to the whitelist it builds, but then things aren't
happy at boot:


[    7.607687] kvm: disagrees about version of symbol module_layout
[    7.846799] virtio: disagrees about version of symbol module_layout
[   22.012615] crc32c_vpmsum: disagrees about version of symbol module_layout
[   22.012959] libcrc32c: disagrees about version of symbol module_layout


cheers

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/3] powerpc/reloc64: add support for 32-bit CRC pseudo-symbols
  2016-11-25 11:29   ` Michael Ellerman
@ 2016-11-25 12:48     ` Ard Biesheuvel
  2016-12-01  9:39       ` Michael Ellerman
  0 siblings, 1 reply; 18+ messages in thread
From: Ard Biesheuvel @ 2016-11-25 12:48 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: linux-kernel, linux-arm-kernel, jeyu, Will Deacon, Rusty Russell,
	Andrew Morton, Benjamin Herrenschmidt, paulus

On 25 November 2016 at 11:29, Michael Ellerman <mpe@ellerman.id.au> wrote:
> Ard Biesheuvel <ard.biesheuvel@linaro.org> writes:
>
>> diff --git a/arch/powerpc/relocs_check.sh b/arch/powerpc/relocs_check.sh
>> index ec2d5c835170..2f510fbc87da 100755
>> --- a/arch/powerpc/relocs_check.sh
>> +++ b/arch/powerpc/relocs_check.sh
>> @@ -43,7 +43,8 @@ R_PPC_ADDR16_HA
>>  R_PPC_RELATIVE
>>  R_PPC_NONE' |
>>       grep -E -v '\<R_PPC64_ADDR64[[:space:]]+mach_' |
>> -     grep -E -v '\<R_PPC64_ADDR64[[:space:]]+__crc_'
>> +     grep -E -v '\<R_PPC64_ADDR64[[:space:]]+__crc_' |
>> +     grep -E -v '\<R_PPC64_ADDR32[[:space:]]+\*ABS\*'
>
> I'm still getting:
>
> WARNING: 24 bad relocations
> c000000000d307c4 R_PPC64_ADDR32    __crc___arch_hweight16
> c000000000d307c8 R_PPC64_ADDR32    __crc___arch_hweight32
> c000000000d307cc R_PPC64_ADDR32    __crc___arch_hweight64
> c000000000d307d0 R_PPC64_ADDR32    __crc___arch_hweight8
> c000000000d30848 R_PPC64_ADDR32    __crc___bswapdi2
> c000000000d30854 R_PPC64_ADDR32    __crc___clear_user
> c000000000d30868 R_PPC64_ADDR32    __crc___copy_tofrom_user
> c000000000d30d4c R_PPC64_ADDR32    __crc__mcount
> c000000000d31344 R_PPC64_ADDR32    __crc_copy_page
> c000000000d3141c R_PPC64_ADDR32    __crc_current_stack_pointer
> c000000000d31840 R_PPC64_ADDR32    __crc_empty_zero_page
> c000000000d31a7c R_PPC64_ADDR32    __crc_flush_dcache_range
> c000000000d31a84 R_PPC64_ADDR32    __crc_flush_icache_range
> c000000000d32608 R_PPC64_ADDR32    __crc_load_fp_state
> c000000000d32614 R_PPC64_ADDR32    __crc_load_vr_state
> c000000000d32828 R_PPC64_ADDR32    __crc_memchr
> c000000000d32830 R_PPC64_ADDR32    __crc_memcmp
> c000000000d32834 R_PPC64_ADDR32    __crc_memcpy
> c000000000d32840 R_PPC64_ADDR32    __crc_memmove
> c000000000d32888 R_PPC64_ADDR32    __crc_memset
> c000000000d33c9c R_PPC64_ADDR32    __crc_store_fp_state
> c000000000d33ca0 R_PPC64_ADDR32    __crc_store_vr_state
> c000000000d33cf0 R_PPC64_ADDR32    __crc_strncmp
> c000000000d33cf4 R_PPC64_ADDR32    __crc_strncpy
>

Ah right, my bad. The regex above should switch to ADDR32 as well for
__crc_ symbols.

>
> If I just add those to the whitelist it builds, but then things aren't
> happy at boot:
>
>
> [    7.607687] kvm: disagrees about version of symbol module_layout
> [    7.846799] virtio: disagrees about version of symbol module_layout
> [   22.012615] crc32c_vpmsum: disagrees about version of symbol module_layout
> [   22.012959] libcrc32c: disagrees about version of symbol module_layout
>

Sigh. I suppose your modversions fixes are queued for v4.10? It's
probably best to revisit this after the v4.10 merge window closes
then, just to make sure I'm not aiming for a moving target.

Thanks,
Ard.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/3] powerpc/reloc64: add support for 32-bit CRC pseudo-symbols
  2016-11-25 12:48     ` Ard Biesheuvel
@ 2016-12-01  9:39       ` Michael Ellerman
  2016-12-01  9:45         ` Ard Biesheuvel
  0 siblings, 1 reply; 18+ messages in thread
From: Michael Ellerman @ 2016-12-01  9:39 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-kernel, linux-arm-kernel, jeyu, Will Deacon, Rusty Russell,
	Andrew Morton, Benjamin Herrenschmidt, paulus

Ard Biesheuvel <ard.biesheuvel@linaro.org> writes:
> On 25 November 2016 at 11:29, Michael Ellerman <mpe@ellerman.id.au> wrote:
>> Ard Biesheuvel <ard.biesheuvel@linaro.org> writes:
>>
>> [    7.607687] kvm: disagrees about version of symbol module_layout
>> [    7.846799] virtio: disagrees about version of symbol module_layout
>> [   22.012615] crc32c_vpmsum: disagrees about version of symbol module_layout
>> [   22.012959] libcrc32c: disagrees about version of symbol module_layout
>>
>
> Sigh. I suppose your modversions fixes are queued for v4.10? It's
> probably best to revisit this after the v4.10 merge window closes
> then, just to make sure I'm not aiming for a moving target.

Actually they were merged into 4.9-rc7 ish.

But I'm still seeing the same as above with this series rebased on top
of that, and I'm a bit short on time to debug it ATM.

So during the 4.10 cycle is probably the best we can hope for, sorry.

cheers

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/3] powerpc/reloc64: add support for 32-bit CRC pseudo-symbols
  2016-12-01  9:39       ` Michael Ellerman
@ 2016-12-01  9:45         ` Ard Biesheuvel
  2016-12-01 16:28           ` Ard Biesheuvel
  0 siblings, 1 reply; 18+ messages in thread
From: Ard Biesheuvel @ 2016-12-01  9:45 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: linux-kernel, linux-arm-kernel, jeyu, Will Deacon, Rusty Russell,
	Andrew Morton, Benjamin Herrenschmidt, paulus

On 1 December 2016 at 09:39, Michael Ellerman <mpe@ellerman.id.au> wrote:
> Ard Biesheuvel <ard.biesheuvel@linaro.org> writes:
>> On 25 November 2016 at 11:29, Michael Ellerman <mpe@ellerman.id.au> wrote:
>>> Ard Biesheuvel <ard.biesheuvel@linaro.org> writes:
>>>
>>> [    7.607687] kvm: disagrees about version of symbol module_layout
>>> [    7.846799] virtio: disagrees about version of symbol module_layout
>>> [   22.012615] crc32c_vpmsum: disagrees about version of symbol module_layout
>>> [   22.012959] libcrc32c: disagrees about version of symbol module_layout
>>>
>>
>> Sigh. I suppose your modversions fixes are queued for v4.10? It's
>> probably best to revisit this after the v4.10 merge window closes
>> then, just to make sure I'm not aiming for a moving target.
>
> Actually they were merged into 4.9-rc7 ish.
>
> But I'm still seeing the same as above with this series rebased on top
> of that, and I'm a bit short on time to debug it ATM.
>
> So during the 4.10 cycle is probably the best we can hope for, sorry.
>

Not a problem. The only question is whether 1/3 of this series fixes
an actual bug or not, given that the CONFIG_RELOCATABLE workaround has
been made ppc64 only.

But for the remaining patches, I'm happy to respin after the v4.10
merge window closes, and get something queued for v4.11

-- 
Ard.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 2/3] powerpc/reloc64: add support for 32-bit CRC pseudo-symbols
  2016-12-01  9:45         ` Ard Biesheuvel
@ 2016-12-01 16:28           ` Ard Biesheuvel
  0 siblings, 0 replies; 18+ messages in thread
From: Ard Biesheuvel @ 2016-12-01 16:28 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: linux-kernel, linux-arm-kernel, jeyu, Will Deacon, Rusty Russell,
	Andrew Morton, Benjamin Herrenschmidt, paulus

On 1 December 2016 at 09:45, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> On 1 December 2016 at 09:39, Michael Ellerman <mpe@ellerman.id.au> wrote:
>> Ard Biesheuvel <ard.biesheuvel@linaro.org> writes:
>>> On 25 November 2016 at 11:29, Michael Ellerman <mpe@ellerman.id.au> wrote:
>>>> Ard Biesheuvel <ard.biesheuvel@linaro.org> writes:
>>>>
>>>> [    7.607687] kvm: disagrees about version of symbol module_layout
>>>> [    7.846799] virtio: disagrees about version of symbol module_layout
>>>> [   22.012615] crc32c_vpmsum: disagrees about version of symbol module_layout
>>>> [   22.012959] libcrc32c: disagrees about version of symbol module_layout
>>>>
>>>
>>> Sigh. I suppose your modversions fixes are queued for v4.10? It's
>>> probably best to revisit this after the v4.10 merge window closes
>>> then, just to make sure I'm not aiming for a moving target.
>>
>> Actually they were merged into 4.9-rc7 ish.
>>
>> But I'm still seeing the same as above with this series rebased on top
>> of that, and I'm a bit short on time to debug it ATM.
>>
>> So during the 4.10 cycle is probably the best we can hope for, sorry.
>>
>
> Not a problem. The only question is whether 1/3 of this series fixes
> an actual bug or not, given that the CONFIG_RELOCATABLE workaround has
> been made ppc64 only.
>
> But for the remaining patches, I'm happy to respin after the v4.10
> merge window closes, and get something queued for v4.11
>

Actually, given the uncertain fate of modversions in general, we may
no longer have to bother by the time the v4.11 merge window opens ...

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y
@ 2016-10-27 16:26 Ard Biesheuvel
  0 siblings, 0 replies; 18+ messages in thread
From: Ard Biesheuvel @ 2016-10-27 16:26 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, mpe, jeyu
  Cc: will.deacon, rusty, akpm, benh, paulus, Ard Biesheuvel

This series is a followup to the single patch 'modversions: treat symbol
CRCs as 32 bit quantities on 64 bit archs', of which two versions have
been sent out so far [0][1]

As pointed out by Michael, GNU ld behaves a bit differently between arm64
and PowerPC64, and where the former gets rid of all runtime relocations
related to CRCs, the latter is not as easily convinced.

Patch #1 fixes the issue where CRCs are corrupted by the runtime relocation
routines for 32-bit PowerPC, for which the original fix was effectively
reverted by commit 0e0ed6406e61 ("powerpc/modules: Module CRC relocation fix
causes perf issues")

Patch #2 adds handling of R_PPC64_ADDR32 relocations against the NULL .dynsym
symbol entry to the PPC64 runtime relocation routines, so it is prepared to
deal with CRCs being emitted as 32-bit quantities.

Patch #3 is the original patch from the v1 and v2 submissions.

Changes since v2:
- added #1 and #2
- updated #3 to deal with CRC entries being emitted from assembler
- added Rusty's ack (#3)

[0] http://marc.info/?l=linux-kernel&m=147652300207369&w=2
[1] http://marc.info/?l=linux-kernel&m=147695629614409&w=2

Ard Biesheuvel (3):
  powerpc/reloc32: fix corrupted modversion CRCs
  powerpc/reloc64: add support for 32-bit CRC pseudo-symbols
  modversions: treat symbol CRCs as 32 bit quantities on 64 bit archs

 arch/powerpc/include/asm/module.h |  4 --
 arch/powerpc/kernel/module_64.c   |  8 ----
 arch/powerpc/kernel/reloc_32.S    | 36 +++++++++++++--
 arch/powerpc/kernel/reloc_64.S    | 22 +++++++--
 arch/powerpc/relocs_check.sh      |  3 +-
 include/asm-generic/export.h      |  7 +--
 include/linux/export.h            |  8 ++++
 include/linux/module.h            | 14 +++---
 kernel/module.c                   | 47 +++++++-------------
 9 files changed, 85 insertions(+), 64 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2016-12-01 16:29 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-27 16:27 [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y Ard Biesheuvel
2016-10-27 16:27 ` [PATCH v3 1/3] powerpc/reloc32: fix corrupted modversion CRCs Ard Biesheuvel
2016-10-28 10:27   ` Suzuki K Poulose
2016-10-27 16:27 ` [PATCH v3 2/3] powerpc/reloc64: add support for 32-bit CRC pseudo-symbols Ard Biesheuvel
2016-11-25 11:29   ` Michael Ellerman
2016-11-25 12:48     ` Ard Biesheuvel
2016-12-01  9:39       ` Michael Ellerman
2016-12-01  9:45         ` Ard Biesheuvel
2016-12-01 16:28           ` Ard Biesheuvel
2016-10-27 16:27 ` [PATCH v3 3/3] modversions: treat symbol CRCs as 32 bit quantities on 64 bit archs Ard Biesheuvel
2016-11-04  9:55 ` [PATCH v3 0/3] modversions: Fix CRC mangling under CONFIG_RELOCATABLE=y Ard Biesheuvel
2016-11-10  4:22   ` Michael Ellerman
2016-11-15  9:13     ` Ard Biesheuvel
2016-11-25  8:44       ` Ard Biesheuvel
2016-11-25 11:12         ` Michael Ellerman
2016-11-16 19:23 ` Uwe Kleine-König
2016-11-16 20:29   ` Ard Biesheuvel
  -- strict thread matches above, loose matches on Subject: below --
2016-10-27 16:26 Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).