Re: [PATCH RFC] powerpc/32: fix handling of stack protector with recent GCC

2017-01-18 Thread Christian Kujau
On Mon, 16 Jan 2017, Christophe Leroy wrote:
>  Christian, can you test it ?

OK, so with that applied to v4.10-rc4, compilation still fails with GCC 
4.9.2 and CC_STACKPROTECTOR_STRONG=y, see below. But it compiles just fine 
with CC_STACKPROTECTOR_REGULAR=y and boots to!

Cross-compiling the same with GCC 5.2.0 works, even for 
CC_STACKPROTECTOR_STRONG=y and the system boots just fine.

So, with that limitation, feel free to add:

 Tested-by: Christian Kujau 


Thanks for the fix!
Christian.



$ gcc --version | head -1
gcc-4.9.real (Debian 4.9.2-10) 4.9.2

$ grep CC_STACKPROTECTOR_STRONG $DIR/.config
CONFIG_CC_STACKPROTECTOR_STRONG=y

$ make O=$DIR V=1 bindeb-pkg
[...]
+ ld -EB -m elf32ppc -Bstatic --build-id -X -o .tmp_vmlinux1 -T 
./arch/powerpc/kernel/vmlinux.lds arch/powerpc/kernel/head_32.o 
arch/powerpc/kernel/fpu.o arch/powerpc/kernel/vector.o 
arch/powerpc/kernel/prom_init.o init/built-in.o --start-group 
usr/built-in.o arch/powerpc/kernel/built-in.o arch/powerpc/mm/built-in.o 
arch/powerpc/lib/built-in.o arch/powerpc/sysdev/built-in.o 
arch/powerpc/platforms/built-in.o arch/powerpc/math-emu/built-in.o 
arch/powerpc/crypto/built-in.o arch/powerpc/net/built-in.o 
kernel/built-in.o certs/built-in.o mm/built-in.o fs/built-in.o 
ipc/built-in.o security/built-in.o crypto/built-in.o block/built-in.o 
lib/lib.a lib/built-in.o drivers/built-in.o sound/built-in.o 
firmware/built-in.o net/built-in.o virt/built-in.o --end-group
arch/powerpc/platforms/built-in.o: In function `bootx_printf':
/usr/local/src/linux-git/arch/powerpc/platforms/powermac/bootx_init.c:88: 
undefined reference to `__stack_chk_fail_local'
arch/powerpc/platforms/built-in.o: In function `bootx_add_display_props':
/usr/local/src/linux-git/arch/powerpc/platforms/powermac/bootx_init.c:211: 
undefined reference to `__stack_chk_fail_local' 
arch/powerpc/platforms/built-in.o: In function `bootx_scan_dt_build_struct':
/usr/local/src/linux-git/arch/powerpc/platforms/powermac/bootx_init.c:350: 
undefined reference to `__stack_chk_fail_local'
arch/powerpc/platforms/built-in.o: In function `bootx_init':
/usr/local/src/linux-git/arch/powerpc/platforms/powermac/bootx_init.c:596: 
undefined reference to `__stack_chk_fail_local'
/usr/bin/ld.bfd.real: .tmp_vmlinux1: hidden symbol `__stack_chk_fail_local' 
isn't defined
/usr/bin/ld.bfd.real: final link failed: Bad value

-- 
BOFH excuse #66:

bit bucket overflow



[PATCH] powerpc: Ignore reserved field in DCSR and PVR reads and writes

2017-01-18 Thread Anton Blanchard
From: Anton Blanchard 

IBM bit 31 (for the rest of us - bit 0) is a reserved field in the
instruction definition of mtspr and mfspr. Hardware is encouraged to
(and does) ignore it.

As a result, if userspace executes an mtspr DSCR with the reserved bit
set, we get a DSCR facility unavailable exception. The kernel fails to
match against the expected value/mask, and we silently return to
userspace to try and re-execute the same mtspr DSCR instruction. We
loop forever until the process is killed.

We should do something here, and it seems mirroring what hardware does
is the better option vs killing the process. While here, relax the
matching of mfspr PVR too.

Signed-off-by: Anton Blanchard 
---
 arch/powerpc/include/asm/ppc-opcode.h | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/ppc-opcode.h 
b/arch/powerpc/include/asm/ppc-opcode.h
index c56ea8c..c4ced1d 100644
--- a/arch/powerpc/include/asm/ppc-opcode.h
+++ b/arch/powerpc/include/asm/ppc-opcode.h
@@ -157,7 +157,7 @@
 #define PPC_INST_MCRXR 0x7c000400
 #define PPC_INST_MCRXR_MASK0xfc0007fe
 #define PPC_INST_MFSPR_PVR 0x7c1f42a6
-#define PPC_INST_MFSPR_PVR_MASK0xfc1f
+#define PPC_INST_MFSPR_PVR_MASK0xfc1e
 #define PPC_INST_MFTMR 0x7c0002dc
 #define PPC_INST_MSGSND0x7c00019c
 #define PPC_INST_MSGCLR0x7c0001dc
@@ -174,13 +174,13 @@
 #define PPC_INST_RFDI  0x4c4e
 #define PPC_INST_RFMCI 0x4c4c
 #define PPC_INST_MFSPR_DSCR0x7c1102a6
-#define PPC_INST_MFSPR_DSCR_MASK   0xfc1f
+#define PPC_INST_MFSPR_DSCR_MASK   0xfc1e
 #define PPC_INST_MTSPR_DSCR0x7c1103a6
-#define PPC_INST_MTSPR_DSCR_MASK   0xfc1f
+#define PPC_INST_MTSPR_DSCR_MASK   0xfc1e
 #define PPC_INST_MFSPR_DSCR_USER   0x7c0302a6
-#define PPC_INST_MFSPR_DSCR_USER_MASK  0xfc1f
+#define PPC_INST_MFSPR_DSCR_USER_MASK  0xfc1e
 #define PPC_INST_MTSPR_DSCR_USER   0x7c0303a6
-#define PPC_INST_MTSPR_DSCR_USER_MASK  0xfc1f
+#define PPC_INST_MTSPR_DSCR_USER_MASK  0xfc1e
 #define PPC_INST_MFVSRD0x7c66
 #define PPC_INST_MTVSRD0x7c000166
 #define PPC_INST_SLBFEE0x7c0007a7
-- 
2.9.3



Re: [PATCH v4 3/3] modversions: treat symbol CRCs as 32 bit quantities on 64 bit archs

2017-01-18 Thread Linus Torvalds
On Wed, Jan 18, 2017 at 2:37 PM, Ard Biesheuvel
 wrote:
>
> For a ballpark number of 10,000 CRCs in the core kernel, this would
> increase the size of the image by 40 KB for 32-bit architectures (and
> if saving 40 KB is essential, chances are you won't be using
> modversions in the first place).

As you say, I don't think the space issue is much of a problem.

I'm more worried about the replacement of one crazy model that has
problems due to linker subtlety with _another_ one.

Your genksyms.c change is not exactly obvious. I looked at it, and my
brain just shut down. Why both the

  LONG(0x%08lx);

_and_ the

  "%s__crc_%s = 0x%08lx;\n"

in the linker script? I'm sure there's a good reason, but I'd like to
see a more explicit explanation fo what the generated linker script
does and what the rules are.

 Linus


[PATCH] powerpc/powernv: Validate memcons descriptor and output buffer

2017-01-18 Thread Gavin Shan
Currently, it's assumed that memcons and its output buffer are included
in the linear mapping. It's not true when "mem=384M" is included in
bootargs. The system runs into kernel crash eventually.

   # od -x /proc/device-tree/ibm,opal/ibm,opal-memcons
   000   0b30 0010
   010

This validates memcons descriptor and its output buffer to ensure they
are valid in linear mapping. Otherwise, the interface won't be populated
to avoid kernel crash during system boot.

Cc: sta...@vger.kernel.org #3.15+
Fixes: bfc36894a48 ("powerpc/powernv: Add OPAL message log interface")
Signed-off-by: Gavin Shan 
---
 arch/powerpc/platforms/powernv/opal-msglog.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/powernv/opal-msglog.c 
b/arch/powerpc/platforms/powernv/opal-msglog.c
index 39d6ff9..34dc2f2 100644
--- a/arch/powerpc/platforms/powernv/opal-msglog.c
+++ b/arch/powerpc/platforms/powernv/opal-msglog.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* OPAL in-memory console. Defined in OPAL source at core/console.c */
 struct memcons {
@@ -104,7 +105,7 @@ static struct bin_attribute opal_msglog_attr = {
 
 void __init opal_msglog_init(void)
 {
-   u64 mcaddr;
+   u64 mcaddr, obuf_top;
struct memcons *mc;
 
if (of_property_read_u64(opal_node, "ibm,opal-memcons", )) {
@@ -112,6 +113,12 @@ void __init opal_msglog_init(void)
return;
}
 
+   if (memory_limit && (mcaddr + sizeof(*mc)) > memory_limit) {
+   pr_warn("OPAL: memcons descriptor (0x%llx, 0x%lx) is out of 
memory (0x%llx)\n",
+   mcaddr, sizeof(*mc), memory_limit);
+   return;
+   }
+
mc = phys_to_virt(mcaddr);
if (!mc) {
pr_warn("OPAL: memory console address is invalid\n");
@@ -123,6 +130,13 @@ void __init opal_msglog_init(void)
return;
}
 
+   obuf_top = be64_to_cpu(mc->obuf_phys) + be32_to_cpu(mc->obuf_size);
+   if (memory_limit && obuf_top > memory_limit) {
+   pr_warn("OPAL: memcons output buffer ceiling (0x%llx) is out of 
memory (0x%llx)\n",
+   obuf_top, memory_limit);
+   return;
+   }
+
opal_memcons = mc;
 }
 
-- 
2.7.4



[PATCH v2] powerpc/eeh: Fix wrong flag passed to eeh_unfreeze_pe()

2017-01-18 Thread Gavin Shan
In __eeh_clear_pe_frozen_state(), we should pass the flag's value
instead of its address to eeh_unfreeze_pe(). The isolated flag is
cleared if no error returned from __eeh_clear_pe_frozen_state().
We never observed the error from the function. So the isolated flag
should have been always cleared, no real issue is caused because
of the misused @flag.

This fixes the code by passing the value of @flag to eeh_unfreeze_pe().

Cc: sta...@vger.kernel.org #3.18+
Fixes: 5cfb20b96f6 ("powerpc/eeh: Emulate EEH recovery for VFIO devices")
Signed-off-by: Gavin Shan 
---
v2: Improved changelog and dereference @flag for once
---
 arch/powerpc/kernel/eeh_driver.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/eeh_driver.c b/arch/powerpc/kernel/eeh_driver.c
index d88573b..b948871 100644
--- a/arch/powerpc/kernel/eeh_driver.c
+++ b/arch/powerpc/kernel/eeh_driver.c
@@ -545,7 +545,7 @@ static void *eeh_pe_detach_dev(void *data, void *userdata)
 static void *__eeh_clear_pe_frozen_state(void *data, void *flag)
 {
struct eeh_pe *pe = (struct eeh_pe *)data;
-   bool *clear_sw_state = flag;
+   bool clear_sw_state = *(bool *)flag;
int i, rc = 1;
 
for (i = 0; rc && i < 3; i++)
-- 
2.7.4



Re: [PATCH] powerpc/eeh: Fix wrong flag passed to eeh_unfreeze_pe()

2017-01-18 Thread Gavin Shan
On Wed, Jan 18, 2017 at 04:49:58PM +1100, Michael Ellerman wrote:
>Gavin Shan  writes:
>
>> In __eeh_clear_pe_frozen_state(), we should pass the flag's value
>> instead of its address to eeh_unfreeze_pe(). This doesn't introduce
>> any problems, but the code is just wrong.
>
>It means any caller that passes false, will be getting the wrong
>behaviour. eg. I see at least one call in eeh_reset_device() which
>passes false to eeh_clear_pe_frozen_state(), which is then passed to
>__eeh_clear_pe_frozen_state().
>

Yes, when __eeh_clear_pe_frozen_state() succeeds on all child PEs, the
isolated flag is cleared. No failure from __eeh_clear_pe_frozen_state()
was observed previously.

>But I guess you're saying that caller doesn't actually see a bug because
>of this?
>

Yes, I'll update the changelog accordingly, to give more details as above.

>> This fixes the code by passing flag's value to eeh_unfreeze_pe().
>>
>> Cc: sta...@vger.kernel.org #3.18+
>> Fixes: 5cfb20b96f6 ("powerpc/eeh: Emulate EEH recovery for VFIO devices")
>> Signed-off-by: Gavin Shan 
>>
>> diff --git a/arch/powerpc/kernel/eeh_driver.c 
>> b/arch/powerpc/kernel/eeh_driver.c
>> index d88573b..fa15fa6 100644
>> --- a/arch/powerpc/kernel/eeh_driver.c
>> +++ b/arch/powerpc/kernel/eeh_driver.c
>> @@ -549,7 +549,7 @@ static void *__eeh_clear_pe_frozen_state(void *data, 
>> void *flag)
>
>   bool *clear_sw_state = flag;
>
>>  int i, rc = 1;
>>  
>>  for (i = 0; rc && i < 3; i++)
>> -rc = eeh_unfreeze_pe(pe, clear_sw_state);
>> +rc = eeh_unfreeze_pe(pe, *clear_sw_state);
>
>
>I think it would be better to just do the dereference once:
>
>   bool clear_sw_state = *(bool *)flag;
>   int i, rc = 1;
>
>   for (i = 0; rc && i < 3; i++)
>   rc = eeh_unfreeze_pe(pe, clear_sw_state);
>

Thanks, Michael. I'll update in v2.

Thanks,
Gavin



[RFC PATCH] modversions: redefine kcrctab entries as relative CRC pointers

2017-01-18 Thread 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__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.

So redefine the kcrctab entries as signed relative offsets pointing to
the CRC value elsewhere in the kernel image. This removes all the ELF
hackery involving symbols and relocations, at the cost of 4 additional
bytes of space per CRC on 32-bit architectures.

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

Signed-off-by: Ard Biesheuvel 
---
 arch/powerpc/include/asm/module.h |  4 --
 arch/powerpc/kernel/module_64.c   |  8 
 include/asm-generic/export.h  |  9 ++--
 include/linux/export.h|  9 ++--
 include/linux/module.h| 14 +++---
 kernel/module.c   | 50 +---
 scripts/genksyms/genksyms.c   |  5 +-
 scripts/kallsyms.c| 12 +
 8 files changed, 52 insertions(+), 59 deletions(-)

diff --git a/arch/powerpc/include/asm/module.h 
b/arch/powerpc/include/asm/module.h
index cc12c61ef315..53885512b8d3 100644
--- a/arch/powerpc/include/asm/module.h
+++ b/arch/powerpc/include/asm/module.h
@@ -90,9 +90,5 @@ static inline int module_finalize_ftrace(struct module *mod, 
const Elf_Shdr *sec
 }
 #endif
 
-#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 bb1807184bad..0b0f89685b67 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 63554e9f6e0c..5e95a552a871 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,8 +49,8 @@ KSYM(__kstrtab_\name):
.section ___kcrctab\sec+\name,"a"
.balign KCRC_ALIGN
 KSYM(__kcrctab_\name):
-   __put KSYM(__crc_\name)
-   .weak KSYM(__crc_\name)
+   .long KSYM(__crcp_\name) - .
+   .weak KSYM(__crcp_\name)
.previous
 #endif
 #endif
diff --git a/include/linux/export.h b/include/linux/export.h
index 2a0f61fbc731..5e9d32316632 100644
--- a/include/linux/export.h
+++ b/include/linux/export.h
@@ -44,11 +44,10 @@ extern struct module __this_module;
 /* Mark the CRC weak since genksyms apparently decides not to
  * generate a checksums for some symbols */
 #define __CRC_SYMBOL(sym, sec) \
-   extern __visible void *__crc_##sym __attribute__((weak));   \
-   static const unsigned long __kcrctab_##sym  \
-   __used  \
-   __attribute__((section("___kcrctab" sec "+" #sym), used))   \
-   = (unsigned long) &__crc_##sym;
+   asm("   .section \"___kcrctab" sec "+" #sym "\", \"a\"  \n" \
+   "   .weak   " VMLINUX_SYMBOL_STR(__crcp_##sym) "\n" \
+   "   .long   " VMLINUX_SYMBOL_STR(__crcp_##sym) " - .\n" \
+   "   .previous   \n");
 #else
 #define 

Re: [PATCH v4 3/3] modversions: treat symbol CRCs as 32 bit quantities on 64 bit archs

2017-01-18 Thread Ard Biesheuvel
On 18 January 2017 at 18:35, Linus Torvalds
 wrote:
> On Wed, Jan 18, 2017 at 10:27 AM, Linus Torvalds
>  wrote:
>>
>> I wonder what happened to gold, and why it didn't take over. I'm
>> assuming it had _other_ bugs.. Oh well.
>
> Google for gold problems, I note that it has been reported to get
> "internal error"s during kernel builds - and at least some of them
> have been due to ksyms.
>
> So the core problem seems to mainly be that gcc normally itself never
> generates any absolute symbols, so the whole ksyms model depends on
> things that get almost zero testing in the toolchain.
>
> Oh well.
>

There is one alternative that gets rid of all the hackiness, but it
does increase the CRC footprint on 32-bit platforms:

diff --git a/scripts/genksyms/genksyms.c b/scripts/genksyms/genksyms.c
index 06121ce524a7..9f739c7224c3 100644
--- a/scripts/genksyms/genksyms.c
+++ b/scripts/genksyms/genksyms.c
@@ -693,7 +693,10 @@ void export_symbol(const char *name)
fputs(">\n", debugfile);

/* Used as a linker script. */
-   printf("%s__crc_%s = 0x%08lx ;\n", mod_prefix, name, crc);
+   printf("SECTIONS { .rodata.__crc_%s : ALIGN(4) "
+  "{ %s__crcp_%s = .; LONG(0x%08lx); } }\n"
+  "%s__crc_%s = 0x%08lx;\n",
+  name, mod_prefix, name, crc, mod_prefix, name, crc);
}
 }

diff --git a/include/asm-generic/export.h b/include/asm-generic/export.h
index e3508a3d6e53..5e95a552a871 100644
--- a/include/asm-generic/export.h
+++ b/include/asm-generic/export.h
@@ -49,8 +49,8 @@ KSYM(__kstrtab_\name):
.section ___kcrctab\sec+\name,"a"
.balign KCRC_ALIGN
 KSYM(__kcrctab_\name):
-   .long KSYM(__crc_\name)
-   .weak KSYM(__crc_\name)
+   .long KSYM(__crcp_\name) - .
+   .weak KSYM(__crcp_\name)
.previous
 #endif
 #endif

(and an equivalent change in include/linux/export.h)

So the kcrctab contains the relative (signed) offset to where the CRC
is stored, which gets rid of any absolute relocations. To grab the
CRC, we only have to add the value of the kcrctab entry to its
address, and dereference the resulting pointer.

This would remove the need for patches 1 and 2, and get rid of the
overhead of the runtime relocation entries not only for arm64 but for
powerpc as well. It would also get rid of the abuse of ELF symbols
once and for all, hopefully avoiding bugs in GNU ld and gold in the
future.

For a ballpark number of 10,000 CRCs in the core kernel, this would
increase the size of the image by 40 KB for 32-bit architectures (and
if saving 40 KB is essential, chances are you won't be using
modversions in the first place). For 64-bit architectures, there would
be no change in size, of course, except for saving 24 bytes of __init
space *per CRC* for arm64 and powerpc64 with CONFIG_RELOCATABLE=y

I will send out a separate RFC so we can discuss this alternative


Re: [PATCH 30/37] dt-bindings: PCI: dra7xx: Add dt bindings to enable legacy mode

2017-01-18 Thread Rob Herring
On Thu, Jan 12, 2017 at 03:56:19PM +0530, Kishon Vijay Abraham I wrote:
> Update device tree binding documentation of TI's dra7xx PCI
> controller to include property for enabling legacy mode.
> 
> Signed-off-by: Kishon Vijay Abraham I 
> ---
>  Documentation/devicetree/bindings/pci/ti-pci.txt |4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/pci/ti-pci.txt 
> b/Documentation/devicetree/bindings/pci/ti-pci.txt
> index 62f5f59..ed85e8e 100644
> --- a/Documentation/devicetree/bindings/pci/ti-pci.txt
> +++ b/Documentation/devicetree/bindings/pci/ti-pci.txt
> @@ -39,6 +39,10 @@ DEVICE MODE
>   - interrupts : one interrupt entries must be specified for main interrupt.
>   - num-ib-windows : number of inbound address translation windows
>   - num-ob-windows : number of outbound address translation windows
> + - syscon-legacy-mode: phandle to the syscon dt node. The 1st argument should
> +contain the register offset within syscon and the 2nd
> +argument should contain the bit field for setting the
> +legacy mode

What's legacy mode?

>  
>  Optional Property:
>   - gpios : Should be added if a gpio line is required to drive PERST# line
> -- 
> 1.7.9.5
> 
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 28/37] dt-bindings: PCI: dra7xx: Add dt bindings for pci dra7xx EP mode

2017-01-18 Thread Rob Herring
On Thu, Jan 12, 2017 at 03:56:17PM +0530, Kishon Vijay Abraham I wrote:
> Add device tree binding documentation for pci dra7xx EP mode.
> 
> Signed-off-by: Kishon Vijay Abraham I 
> ---
>  Documentation/devicetree/bindings/pci/ti-pci.txt |   37 
> ++
>  1 file changed, 30 insertions(+), 7 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/pci/ti-pci.txt 
> b/Documentation/devicetree/bindings/pci/ti-pci.txt
> index 60e2516..62f5f59 100644
> --- a/Documentation/devicetree/bindings/pci/ti-pci.txt
> +++ b/Documentation/devicetree/bindings/pci/ti-pci.txt
> @@ -1,17 +1,22 @@
>  TI PCI Controllers
>  
>  PCIe Designware Controller
> - - compatible: Should be "ti,dra7-pcie""
> - - reg : Two register ranges as listed in the reg-names property
> - - reg-names : The first entry must be "ti-conf" for the TI specific 
> registers
> -The second entry must be "rc-dbics" for the designware pcie
> -registers
> -The third entry must be "config" for the PCIe configuration space
> + - compatible: Should be "ti,dra7-pcie" for RC
> +Should be "ti,dra7-pcie-ep" for EP
>   - phys : list of PHY specifiers (used by generic PHY framework)
>   - phy-names : must be "pcie-phy0", "pcie-phy1", "pcie-phyN".. based on the
>  number of PHYs as specified in *phys* property.
>   - ti,hwmods : Name of the hwmod associated to the pcie, "pcie",
>  where  is the instance number of the pcie from the HW spec.
> + - num-lanes as specified in ../designware-pcie.txt
> +
> +HOST MODE
> +=
> + - reg : Two register ranges as listed in the reg-names property
> + - reg-names : The first entry must be "ti-conf" for the TI specific 
> registers
> +The second entry must be "rc-dbics" for the designware pcie
> +registers
> +The third entry must be "config" for the PCIe configuration space
>   - interrupts : Two interrupt entries must be specified. The first one is for
>   main interrupt line and the second for MSI interrupt line.
>   - #address-cells,
> @@ -19,13 +24,31 @@ PCIe Designware Controller
> #interrupt-cells,
> device_type,
> ranges,
> -   num-lanes,
> interrupt-map-mask,
> interrupt-map : as specified in ../designware-pcie.txt
>  
> +DEVICE MODE
> +===
> + - reg : Four register ranges as listed in the reg-names property
> + - reg-names : "ti-conf" for the TI specific registers
> +"ep_dbics" for the standard configuration registers as
> + they are locally accessed within the DIF CS space
> +"ep_dbics2" for the standard configuration registers as
> + they are locally accessed within the DIF CS2 space
> +"addr_space" used to map remote RC address space
> + - interrupts : one interrupt entries must be specified for main interrupt.
> + - num-ib-windows : number of inbound address translation windows
> + - num-ob-windows : number of outbound address translation windows
> +
>  Optional Property:
>   - gpios : Should be added if a gpio line is required to drive PERST# line
>  
> +NOTE: Two dt nodes should be added for each PCI controller; one for host

s/should/may/

Don't define dts source structure here. You could also have 2 files with 
each config and just include the right one for each board.

We don't want overlapping memory regions defined in DT and this kind of 
violates that, but I guess status is sufficient.

With that,

Acked-by: Rob Herring 

> +mode and another for device mode. So in order for PCI to
> +work in host mode, EP mode dt node should be disabled and in order to PCI to
> +work in EP mode, host mode dt node should be disabled. And host mode and EP
> +mode are mutually exclusive.
> +
>  Example:
>  axi {
>   compatible = "simple-bus";
> -- 
> 1.7.9.5
> 
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 25/37] dt-bindings: PCI: Add dt bindings for pci designware EP mode

2017-01-18 Thread Rob Herring
On Thu, Jan 12, 2017 at 03:56:14PM +0530, Kishon Vijay Abraham I wrote:
> Add device tree binding documentation for pci designware EP mode.
> 
> Signed-off-by: Kishon Vijay Abraham I 
> ---
>  .../devicetree/bindings/pci/designware-pcie.txt|   26 
> ++--
>  1 file changed, 18 insertions(+), 8 deletions(-)

Acked-by: Rob Herring 


Re: [PATCH v4 3/3] modversions: treat symbol CRCs as 32 bit quantities on 64 bit archs

2017-01-18 Thread Linus Torvalds
On Wed, Jan 18, 2017 at 10:27 AM, Linus Torvalds
 wrote:
>
> I wonder what happened to gold, and why it didn't take over. I'm
> assuming it had _other_ bugs.. Oh well.

Google for gold problems, I note that it has been reported to get
"internal error"s during kernel builds - and at least some of them
have been due to ksyms.

So the core problem seems to mainly be that gcc normally itself never
generates any absolute symbols, so the whole ksyms model depends on
things that get almost zero testing in the toolchain.

Oh well.

  Linus


Re: [PATCH v4 3/3] modversions: treat symbol CRCs as 32 bit quantities on 64 bit archs

2017-01-18 Thread Linus Torvalds
On Wed, Jan 18, 2017 at 5:52 AM, Ard Biesheuvel
 wrote:
>
> It turns out that this odd treatment of absolute symbols (i.e.,
> symbols having section number SHN_ABS) is a known issue in GNU ld
>
> https://sourceware.org/ml/binutils/2012-05/msg00019.html

Ugh. I hate the GNU linker. It's slow, it does nasty crazy fixups, and
it's apparently buggy too.

I wonder what happened to gold, and why it didn't take over. I'm
assuming it had _other_ bugs.. Oh well.

 Linus


Re: [PATCH v4 2/3] powerpc/reloc64: add support for 32-bit CRC pseudo-symbols

2017-01-18 Thread Ard Biesheuvel
On 17 January 2017 at 19:26, Ard Biesheuvel  wrote:
> 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.
>
> As it turns out, binutils for powerpc does not account for any relocations
> beyond R_PPC64_RELATIVE ones in the RELACOUNT field of the .dynamic section,
> which is unfortunate, since we need to do extra work to figure out the size
> of the relocation array. So with a little help from the linker scripts,
> grab an end pointer rather than a count, and iterate over the entire section.
>

While this is the case of RELACOUNT, RELASZ appears to behave as
expected. For instance, on a random vmlinux file (with patch 3/3
applied), I get

Dynamic Section:
  HASH 0xc0cf5a40
  STRTAB   0xc0cf4d80
  SYMTAB   0xc0cf3e98
  STRSZ0x0bae
  SYMENT   0x0018
  DEBUG0x
  RELA 0xc0cf5ee8
  RELASZ   0x003308b8
  RELAENT  0x0018
  TEXTREL  0x
  FLAGS_1  0x0800
  RELACOUNT0x00020444

where RELACOUNT is the number of just the R_PPC64_RELATIVE
relocations, whereas RELASZ covers all of them (which is why RELASZ /
RELAENT != RELACOUNT)

So if preferred, I can respin this patch to retrieve RELASZ from the
dynamic section rather than the end of the .rela section from the
linker script, which would reduce the delta of this patch somewhat.


> Signed-off-by: Ard Biesheuvel 
> ---
>  arch/powerpc/kernel/reloc_64.S| 60 
>  arch/powerpc/kernel/vmlinux.lds.S |  1 +
>  arch/powerpc/relocs_check.sh  |  5 +-
>  3 files changed, 40 insertions(+), 26 deletions(-)
>
> diff --git a/arch/powerpc/kernel/reloc_64.S b/arch/powerpc/kernel/reloc_64.S
> index d88736fbece6..e50f5d778ea2 100644
> --- a/arch/powerpc/kernel/reloc_64.S
> +++ b/arch/powerpc/kernel/reloc_64.S
> @@ -12,8 +12,8 @@
>  #include 
>
>  RELA = 7
> -RELACOUNT = 0x6ff9
>  R_PPC64_RELATIVE = 22
> +R_PPC64_ADDR32 = 1
>
>  /*
>   * r3 = desired final address of kernel
> @@ -29,29 +29,27 @@ _GLOBAL(relocate)
> add r9,r9,r12   /* r9 has runtime addr of .rela.dyn section */
> ld  r10,(p_st - 0b)(r12)
> add r10,r10,r12 /* r10 has runtime addr of _stext */
> +   ld  r8,(p_rela_end - 0b)(r12)
> +   add r8,r8,r12   /* r8 has addr of end of .rela.dyn section */
>
> /*
> -* Scan the dynamic section for the RELA and RELACOUNT entries.
> +* Scan the dynamic section for the RELA entry.
> +* NOTE: the RELACOUNT entry only covers R_PPC64_RELATIVE relocations,
> +*   so we cannot use it here.
>  */
> li  r7,0
> -   li  r8,0
>  1: ld  r6,0(r11)   /* get tag */
> cmpdi   r6,0
> -   beq 4f  /* end of list */
> +   beq 3f  /* end of list */
> cmpdi   r6,RELA
> -   bne 2f
> -   ld  r7,8(r11)   /* get RELA pointer in r7 */
> -   b   3f
> -2: addis   r6,r6,(-RELACOUNT)@ha
> -   cmpdi   r6,RELACOUNT@l
> -   bne 3f
> -   ld  r8,8(r11)   /* get RELACOUNT value in r8 */
> -3: addir11,r11,16
> +   beq 2f
> +   addir11,r11,16
> b   1b
> -4: cmpdi   r7,0/* check we have both RELA and RELACOUNT */
> -   cmpdi   cr1,r8,0
> -   beq 6f
> -   beq cr1,6f
> +2: ld  r7,8(r11)   /* get RELA pointer in r7 */
> +3: cmpdi   r7,0/* check we have both RELA and a non-empty */
> +   cmpdcr1,r8,r9   /* .rela.dyn section   */
> +   beq 7f
> +   beq cr1,7f
>
> /*
>  * Work out linktime address of _stext and hence the
> @@ -63,26 +61,40 @@ _GLOBAL(relocate)
> subfr7,r7,r9/* cur_offset */
> subfr10,r7,r10
>  

Re: [PATCH v4 3/3] modversions: treat symbol CRCs as 32 bit quantities on 64 bit archs

2017-01-18 Thread Ard Biesheuvel
On 18 January 2017 at 11:37, Ard Biesheuvel  wrote:
> On 17 January 2017 at 23:47, Linus Torvalds
>  wrote:
>> On Tue, Jan 17, 2017 at 11:26 AM, Ard Biesheuvel
>>  wrote:
>>> 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:
>>
>> So the whole relocation of the crc is obviously completely crazy, but
>> you don't actually seem to *change* that. You just work around it, and
>> you make the symbols 32-bit. The latter part I agree with
>> whole-heartedly, btw.
>>
>> But do we really have to accept this relocation insanity?
>>
>> So I don't actually disagree with this patch 3/3 (turning the whole
>> crc array into an array of "u32" is clearly the right thing to do),
>> but the two other patches look oddly broken.
>>
>> Why are those CRC's relocatable to begin with? Shouldn't they be
>> absolute values? Why do they get those idiotic relocation things? They
>> seem to be absolute on x86-64 (just doing a 'nm vmlinux', so I might
>> be missing something), why aren't they on ppc?
>>
>
> On powerpc and arm64, those __crc_xxx symbols are absolute as well,
> but oddly enough, that does not mean they are not subject to runtime
> relocation under -pie, which is how arm64 and powerpc create their
> relocatable kernel images.

It turns out that this odd treatment of absolute symbols (i.e.,
symbols having section number SHN_ABS) is a known issue in GNU ld

https://sourceware.org/ml/binutils/2012-05/msg00019.html


> The difference with x86 is that they
> invented their own tooling to do runtime relocation, based on
> --emit-relocs and filtering based on symbol names, so they don't rely
> on ELF relocations at all for runtime relocation of the core kernel.
>
> On ppc64:
>
> $ nm vmlinux |grep __crc_ |head
> 9d37922d a __crc___ablkcipher_walk_complete
> c4309a46 a __crc_ablkcipher_walk_done
> 38e1d7e1 a __crc_ablkcipher_walk_phys
> a55b33a4 a __crc_abort_creds
> 5776482e a __crc_access_process_vm
> 1215a9fb a __crc_account_page_dirtied
> b25ee3c8 a __crc_account_page_redirty
> ccab9422 a __crc_ack_all_badblocks
> 27013bae a __crc_acomp_request_alloc
> 13236c1b a __crc_acomp_request_free
>
> [note the lowercase 'a', this is due to my attempt at emitting them as 
> HIDDEN()]
>
> On arm64, patch 3/3 is sufficient, because the linker infers from the
> size of the symbol reference that it is not a memory address, and
> resolves the relocation at link time.
>
>> Is there something wrong with our generation script? Can we possibly
>> do something like
>>
>>   -   printf("%s__crc_%s = 0x%08lx ;\n", mod_prefix, name, crc);
>>   +   printf("%s__crc_%s = ABSOLUTE(0x%08lx) ;\n", mod_prefix, name, 
>> crc);
>>
>> in genksyms.c to get rid of the crazty relocation entries?
>>
>
> Nope, no difference at all, given that the symbols were ABSOLUTE to
> begin with. Emitting them as HIDDEN() does not help either, nor does
> passing -Bsymbolic on the linker command line.
>
> So on powerpc, the linker insists on emitting the relocation into the
> runtime relocation section [*], regardless of whether it is ABSOLUTE()
> or HIDDEN(), or whether -Bsymbolic is being passed. My suspicion is
> that, due to the fact that PIE handling is closely related to shared
> library handling, the linker defers the resolution of relocations
> against __crc_xxx symbols to runtime because they are preemptible
> under ELF rules for shared libraries, i.e., an application linking to
> a shared library is able to override symbols that the shared library
> defines, and the shared library *must* update its internal references
> to point to the new version of the symbol. Of course, this makes no
> sense at all for PIE binaries, and on arm64, the toolchain does the
> right thing in this regard when passing the -Bsymbolic parameter. On
> powerpc, however, the linker *insists* on exposing these relocations
> to the runtime loader, even if they are marked hidden (which is
> supposed to inhibit this behavior).
>
> I have also tried using relative references (which always get resolved
> at link time), e.g.,
>
> diff --git a/include/linux/export.h b/include/linux/export.h
> index a000d421526d..df3f6762b3c0 100644
> --- a/include/linux/export.h
> +++ b/include/linux/export.h
> @@ -54,7 +54,9 @@ extern struct module __this_module;
>  #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" \
> +   "   .globl  " VMLINUX_SYMBOL_STR(__crc_rel_##sym) " \n" \
> +   

Re: [v2] powerpc/perf: use MSR to report privilege level on P9 DD1

2017-01-18 Thread Michael Ellerman
On Wed, 2017-01-18 at 03:42:56 UTC, Madhavan Srinivasan wrote:
> Since SIER and SIAR updates are not valid for some
> samples, patch forces the use of MSR and regs->nip instead
> for misc_flag updates. This is done by adding a new ppmu
> flag and updating user_siar value in perf_read_regs() accordingly.
> 
> Signed-off-by: Madhavan Srinivasan 

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/27593d72c4ad451ed13af35354b941

cheers


Re: selftest/powerpc: Wrong PMC initialized in pmc56_overflow test

2017-01-18 Thread Michael Ellerman
On Mon, 2016-12-19 at 12:16:53 UTC, Madhavan Srinivasan wrote:
> Test uses PMC2 to count the event. But PMC1 is being initialized.
> Patch to fix it.
> 
> Fixes: 3752e453f6ba ('selftests/powerpc: Add tests of PMU EBBs')
> Signed-off-by: Madhavan Srinivasan 

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/df21d2fa733035e4d414379960f94b

cheers


Re: powerpc: fix pgtable pmd cache init

2017-01-18 Thread Michael Ellerman
On Tue, 2017-01-03 at 15:55:17 UTC, Nicholas Piggin wrote:
> Commit 9b081e10805cd ("powerpc: port 64 bits pgtable_cache to 32 bits")
> mixed up PMD_INDEX_SIZE and PMD_CACHE_INDEX a couple of times. This
> resulted in 64s/hash/4k configs to panic at boot with a false positive
> error check.
> 
> Fix that and simplify error handling by moving the check to the caller.
> 
> Fixes: 9b081e10805cd ("powerpc: port 64 bits pgtable_cache to 32 bits")
> Cc: Christophe Leroy 
> Cc: Aneesh Kumar K.V 
> Cc: Scott Wood 
> Cc: linuxppc-dev@lists.ozlabs.org
> Signed-off-by: Nicholas Piggin 

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/bf5ca68dd2eef59a936969e802d811

cheers


Re: powerpc/icp-opal: Fix missing KVM case and harden replay

2017-01-18 Thread Michael Ellerman
On Mon, 2017-01-16 at 17:58:53 UTC, Benjamin Herrenschmidt wrote:
> The icp-opal call is missing the code from icp-native to recover
> interrupts snatched by KVM. Without that, when running KVM, we can
> get into a situation where an interrupt is lost and the CPU stuck
> with an elevated CPPR.
> 
> Also harden replay by always checking the return from opal_int_eoi
> 
> Signed-off-by: Benjamin Herrenschmidt 

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/9728a7c8ab2f7a1c8d5c95278d2e4f

cheers


Re: powerpc/mm: fix memory hotplug BUG() on radix

2017-01-18 Thread Michael Ellerman
On Tue, 2017-01-03 at 20:39:51 UTC, Reza Arbab wrote:
> Memory hotplug is leading to hash page table calls, even on radix:
> 
> ...
>   arch_add_memory
>   create_section_mapping
>   htab_bolt_mapping
>   BUG_ON(!ppc_md.hpte_insert);
> 
> To fix, refactor {create,remove}_section_mapping() into hash__ and
> radix__ variants. Leave the radix versions stubbed for now.
> 
> Reviewed-by: Aneesh Kumar K.V 
> Acked-by: Balbir Singh 
> Signed-off-by: Reza Arbab 

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/32b53c012e0bfe20b2745962a89db0

cheers


Re: powerpc/mm: Fix little-endian 4K hugetlb

2017-01-18 Thread Michael Ellerman
On Wed, 2016-12-14 at 04:37:53 UTC, "Aneesh Kumar K.V" wrote:
> When we switched to big endian page table, we never updated
> the hugepd format such that it can work for both big endian and
> little endian config. This patch series update hugepd format
> such that it is looked at as __be64 value in big endian page
> table config.
> 
> This patch also switch hugepd_t.pd from signed long to unsigned long.
> I did update the FSL hugepd_ok check to check for the top bit instead
> of checking > 0.
> 
> Fixes: 5dc1ef858c12f8 ("powerpc/mm: Use big endian Linux page tables for 
> book3s 64")
> Signed-off-by: Aneesh Kumar K.V 

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/20717e1ff52672e31f9399c45d8893

cheers


Re: powerpc/eeh: Enable IO path on permanent error

2017-01-18 Thread Michael Ellerman
On Thu, 2017-01-05 at 23:39:49 UTC, Gavin Shan wrote:
> We give up recovery on permanent error, simply shutdown the affected
> devices and remove them. If the devices can't be put into quiet state,
> they spew more traffic that is likely to cause another unexpected EEH
> error. This was observed on "p8dtu2u" machine:
> 
>0002:00:00.0 PCI bridge: IBM Device 03dc
>0002:01:00.0 Ethernet controller: Intel Corporation \
> Ethernet Controller X710/X557-AT 10GBASE-T (rev 02)
>0002:01:00.1 Ethernet controller: Intel Corporation \
> Ethernet Controller X710/X557-AT 10GBASE-T (rev 02)
>0002:01:00.2 Ethernet controller: Intel Corporation \
> Ethernet Controller X710/X557-AT 10GBASE-T (rev 02)
>0002:01:00.3 Ethernet controller: Intel Corporation \
> Ethernet Controller X710/X557-AT 10GBASE-T (rev 02)
> 
> On P8 PowerNV platform, the IO path is frozen when shutdowning the
> devices, meaning the memory registers are inaccessible. It is why
> the devices can't be put into quiet state before removing them.
> This fixes the issue by enabling IO path prior to putting the devices
> into quiet state.
> 
> Link: https://github.com/open-power/supermicro-openpower/issues/419
> Reported-by: Pridhiviraj Paidipeddi 
> Signed-off-by: Gavin Shan 
> Acked-by: Russell Currey 

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/387bbc974f6adf91aa635090f73434

cheers


Re: powerpc/mm/hugetlb: Don't panic if we don't find the default huge page size

2017-01-18 Thread Michael Ellerman
On Tue, 2016-12-13 at 14:04:11 UTC, "Aneesh Kumar K.V" wrote:
> generic hugetlbfs can handle that condition correctly. With HPAGE_SHIFT = 0
> we get
> [0.241333] hugetlbfs: disabling because there are no supported hugepage sizes
> 
> bash-4.2# echo 30 > /proc/sys/vm/nr_hugepages
> bash: echo: write error: Operation not supported
> 
> Fixes: "powerpc: get hugetlbpage handling more generic"
> Reported-by: Chris Smart 
> Signed-off-by: Aneesh Kumar K.V 
> Acked-By: Michael Neuling 

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/ff8b85796dad5de869dc29903c9566

cheers


Re: [2/2] powerpc/perf: fix PM_BR_CMPL event code for power9

2017-01-18 Thread Michael Ellerman
On Mon, 2017-01-09 at 13:30:15 UTC, Madhavan Srinivasan wrote:
> Use 0x10012 event code for PM_BR_CMPL event in
> power9 event list instead of current 0x40060.
> 
> Fixes:34922527a2bcb ('powerpc/perf: Add power9 event list macros for generic 
> and cache events')
> Signed-off-by: Madhavan Srinivasan 

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/d89f473ff6f84872e761419f7233d6

cheers


Re: [PATCH v4 3/3] modversions: treat symbol CRCs as 32 bit quantities on 64 bit archs

2017-01-18 Thread Ard Biesheuvel
On 17 January 2017 at 23:47, Linus Torvalds
 wrote:
> On Tue, Jan 17, 2017 at 11:26 AM, Ard Biesheuvel
>  wrote:
>> 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:
>
> So the whole relocation of the crc is obviously completely crazy, but
> you don't actually seem to *change* that. You just work around it, and
> you make the symbols 32-bit. The latter part I agree with
> whole-heartedly, btw.
>
> But do we really have to accept this relocation insanity?
>
> So I don't actually disagree with this patch 3/3 (turning the whole
> crc array into an array of "u32" is clearly the right thing to do),
> but the two other patches look oddly broken.
>
> Why are those CRC's relocatable to begin with? Shouldn't they be
> absolute values? Why do they get those idiotic relocation things? They
> seem to be absolute on x86-64 (just doing a 'nm vmlinux', so I might
> be missing something), why aren't they on ppc?
>

On powerpc and arm64, those __crc_xxx symbols are absolute as well,
but oddly enough, that does not mean they are not subject to runtime
relocation under -pie, which is how arm64 and powerpc create their
relocatable kernel images. The difference with x86 is that they
invented their own tooling to do runtime relocation, based on
--emit-relocs and filtering based on symbol names, so they don't rely
on ELF relocations at all for runtime relocation of the core kernel.

On ppc64:

$ nm vmlinux |grep __crc_ |head
9d37922d a __crc___ablkcipher_walk_complete
c4309a46 a __crc_ablkcipher_walk_done
38e1d7e1 a __crc_ablkcipher_walk_phys
a55b33a4 a __crc_abort_creds
5776482e a __crc_access_process_vm
1215a9fb a __crc_account_page_dirtied
b25ee3c8 a __crc_account_page_redirty
ccab9422 a __crc_ack_all_badblocks
27013bae a __crc_acomp_request_alloc
13236c1b a __crc_acomp_request_free

[note the lowercase 'a', this is due to my attempt at emitting them as HIDDEN()]

On arm64, patch 3/3 is sufficient, because the linker infers from the
size of the symbol reference that it is not a memory address, and
resolves the relocation at link time.

> Is there something wrong with our generation script? Can we possibly
> do something like
>
>   -   printf("%s__crc_%s = 0x%08lx ;\n", mod_prefix, name, crc);
>   +   printf("%s__crc_%s = ABSOLUTE(0x%08lx) ;\n", mod_prefix, name, crc);
>
> in genksyms.c to get rid of the crazty relocation entries?
>

Nope, no difference at all, given that the symbols were ABSOLUTE to
begin with. Emitting them as HIDDEN() does not help either, nor does
passing -Bsymbolic on the linker command line.

So on powerpc, the linker insists on emitting the relocation into the
runtime relocation section [*], regardless of whether it is ABSOLUTE()
or HIDDEN(), or whether -Bsymbolic is being passed. My suspicion is
that, due to the fact that PIE handling is closely related to shared
library handling, the linker defers the resolution of relocations
against __crc_xxx symbols to runtime because they are preemptible
under ELF rules for shared libraries, i.e., an application linking to
a shared library is able to override symbols that the shared library
defines, and the shared library *must* update its internal references
to point to the new version of the symbol. Of course, this makes no
sense at all for PIE binaries, and on arm64, the toolchain does the
right thing in this regard when passing the -Bsymbolic parameter. On
powerpc, however, the linker *insists* on exposing these relocations
to the runtime loader, even if they are marked hidden (which is
supposed to inhibit this behavior).

I have also tried using relative references (which always get resolved
at link time), e.g.,

diff --git a/include/linux/export.h b/include/linux/export.h
index a000d421526d..df3f6762b3c0 100644
--- a/include/linux/export.h
+++ b/include/linux/export.h
@@ -54,7 +54,9 @@ extern struct module __this_module;
 #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" \
+   "   .globl  " VMLINUX_SYMBOL_STR(__crc_rel_##sym) " \n" \
+   VMLINUX_SYMBOL_STR(__crc_rel_##sym)":
 \n" \
+   "   .long   " VMLINUX_SYMBOL_STR(__crc_##sym) " - . \n" \
"   .previous   \n");
 #endif
 #else
diff --git a/scripts/genksyms/genksyms.c b/scripts/genksyms/genksyms.c
index 06121ce524a7..8dd9f1da8898 100644
--- a/scripts/genksyms/genksyms.c
+++ b/scripts/genksyms/genksyms.c
@@ -693,7 +693,8 @@ void export_symbol(const char *name)