]> rtime.felk.cvut.cz Git - linux-imx.git/commitdiff
powerpc: Relocate prom_init.c on 64bit
authorAnton Blanchard <anton@samba.org>
Mon, 26 Nov 2012 17:39:03 +0000 (17:39 +0000)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Thu, 10 Jan 2013 06:00:25 +0000 (17:00 +1100)
The ppc64 kernel can get loaded at any address which means
our very early init code in prom_init.c must be relocatable. We do
this with a pretty nasty RELOC() macro that we wrap accesses of
variables with. It is very fragile and sometimes we forget to add a
RELOC() to an uncommon path or sometimes a compiler change breaks it.

32bit has a much more elegant solution where we build prom_init.c
with -mrelocatable and then process the relocations manually.
Unfortunately we can't do the equivalent on 64bit and we would
have to build the entire kernel relocatable (-pie), resulting in a
large increase in kernel footprint (megabytes of relocation data).
The relocation data will be marked __initdata but it still creates
more pressure on our already tight memory layout at boot.

Alan Modra pointed out that the 64bit ABI is relocatable even
if we don't build with -pie, we just need to relocate the TOC.
This patch implements that idea and relocates the TOC entries of
prom_init.c. An added bonus is there are very few relocations to
process which helps keep boot times on simulators down.

gcc does not put 64bit integer constants into the TOC but to be
safe we may want a build time script which passes through the
prom_init.c TOC entries to make sure everything looks reasonable.

Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
arch/powerpc/Makefile
arch/powerpc/include/asm/sections.h
arch/powerpc/kernel/Makefile
arch/powerpc/kernel/prom_init.c
arch/powerpc/kernel/prom_init_check.sh
arch/powerpc/kernel/vmlinux.lds.S

index ba45cad088c90b63454fdc6b59b4c4d2143e8735..78c2b024371ac94e47d8b7974d4aa764d8ec9e52 100644 (file)
@@ -136,6 +136,7 @@ head-$(CONFIG_FSL_BOOKE)    := arch/powerpc/kernel/head_fsl_booke.o
 head-$(CONFIG_PPC64)           += arch/powerpc/kernel/entry_64.o
 head-$(CONFIG_PPC_FPU)         += arch/powerpc/kernel/fpu.o
 head-$(CONFIG_ALTIVEC)         += arch/powerpc/kernel/vector.o
+head-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE)  += arch/powerpc/kernel/prom_init.o
 
 core-y                         += arch/powerpc/kernel/ \
                                   arch/powerpc/mm/ \
index a0f358d4a00cd57ba3b22fbbf1024c7daba65fa4..4ee06fe15de41d11e77f7c7c44d2daaea8d10ed2 100644 (file)
@@ -10,6 +10,9 @@
 
 extern char __end_interrupts[];
 
+extern char __prom_init_toc_start[];
+extern char __prom_init_toc_end[];
+
 static inline int in_kernel_text(unsigned long addr)
 {
        if (addr >= (unsigned long)_stext && addr < (unsigned long)__init_end)
index 44fbbea7697aadd085b1b332e60a4a0b3514a2a9..2f6ef4ed5abfb93477875992f57af29248b8995b 100644 (file)
@@ -91,7 +91,6 @@ obj-$(CONFIG_RELOCATABLE_PPC32)       += reloc_32.o
 obj-$(CONFIG_PPC32)            += entry_32.o setup_32.o
 obj-$(CONFIG_PPC64)            += dma-iommu.o iommu.o
 obj-$(CONFIG_KGDB)             += kgdb.o
-obj-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE)   += prom_init.o
 obj-$(CONFIG_MODULES)          += ppc_ksyms.o
 obj-$(CONFIG_BOOTX_TEXT)       += btext.o
 obj-$(CONFIG_SMP)              += smp.o
@@ -142,6 +141,7 @@ GCOV_PROFILE_kprobes.o := n
 extra-$(CONFIG_PPC_FPU)                += fpu.o
 extra-$(CONFIG_ALTIVEC)                += vector.o
 extra-$(CONFIG_PPC64)          += entry_64.o
+extra-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE) += prom_init.o
 
 extra-y                                += systbl_chk.i
 $(obj)/systbl.o:               systbl_chk
index 779f34049a56f1020aeee94174e5584f90c645ae..c78ac5698b9998731e84f8e21b81c10a6ab85f41 100644 (file)
@@ -66,8 +66,8 @@
  * is running at whatever address it has been loaded at.
  * On ppc32 we compile with -mrelocatable, which means that references
  * to extern and static variables get relocated automatically.
- * On ppc64 we have to relocate the references explicitly with
- * RELOC.  (Note that strings count as static variables.)
+ * ppc64 objects are always relocatable, we just need to relocate the
+ * TOC.
  *
  * Because OF may have mapped I/O devices into the area starting at
  * KERNELBASE, particularly on CHRP machines, we can't safely call
  * On ppc64, 64 bit values are truncated to 32 bits (and
  * fortunately don't get interpreted as two arguments).
  */
+#define RELOC(x)       (x)
+#define ADDR(x)                (u32)(unsigned long)(x)
+
 #ifdef CONFIG_PPC64
-#define RELOC(x)        (*PTRRELOC(&(x)))
-#define ADDR(x)                (u32) add_reloc_offset((unsigned long)(x))
 #define OF_WORKAROUNDS 0
 #else
-#define RELOC(x)       (x)
-#define ADDR(x)                (u32) (x)
 #define OF_WORKAROUNDS of_workarounds
 int of_workarounds;
 #endif
@@ -334,9 +333,6 @@ static void __init prom_printf(const char *format, ...)
        struct prom_t *_prom = &RELOC(prom);
 
        va_start(args, format);
-#ifdef CONFIG_PPC64
-       format = PTRRELOC(format);
-#endif
        for (p = format; *p != 0; p = q) {
                for (q = p; *q != 0 && *q != '\n' && *q != '%'; ++q)
                        ;
@@ -437,9 +433,6 @@ static unsigned int __init prom_claim(unsigned long virt, unsigned long size,
 
 static void __init __attribute__((noreturn)) prom_panic(const char *reason)
 {
-#ifdef CONFIG_PPC64
-       reason = PTRRELOC(reason);
-#endif
        prom_print(reason);
        /* Do not call exit because it clears the screen on pmac
         * it also causes some sort of double-fault on early pmacs */
@@ -929,7 +922,7 @@ static void __init prom_send_capabilities(void)
                 * (we assume this is the same for all cores) and use it to
                 * divide NR_CPUS.
                 */
-               cores = (u32 *)PTRRELOC(&ibm_architecture_vec[IBM_ARCH_VEC_NRCORES_OFFSET]);
+               cores = (u32 *)&ibm_architecture_vec[IBM_ARCH_VEC_NRCORES_OFFSET];
                if (*cores != NR_CPUS) {
                        prom_printf("WARNING ! "
                                    "ibm_architecture_vec structure inconsistent: %lu!\n",
@@ -2850,6 +2843,53 @@ static void __init prom_check_initrd(unsigned long r3, unsigned long r4)
 #endif /* CONFIG_BLK_DEV_INITRD */
 }
 
+#ifdef CONFIG_PPC64
+#ifdef CONFIG_RELOCATABLE
+static void reloc_toc(void)
+{
+}
+
+static void unreloc_toc(void)
+{
+}
+#else
+static void __reloc_toc(void *tocstart, unsigned long offset,
+                       unsigned long nr_entries)
+{
+       unsigned long i;
+       unsigned long *toc_entry = (unsigned long *)tocstart;
+
+       for (i = 0; i < nr_entries; i++) {
+               *toc_entry = *toc_entry + offset;
+               toc_entry++;
+       }
+}
+
+static void reloc_toc(void)
+{
+       unsigned long offset = reloc_offset();
+       unsigned long nr_entries =
+               (__prom_init_toc_end - __prom_init_toc_start) / sizeof(long);
+
+       /* Need to add offset to get at __prom_init_toc_start */
+       __reloc_toc(__prom_init_toc_start + offset, offset, nr_entries);
+
+       mb();
+}
+
+static void unreloc_toc(void)
+{
+       unsigned long offset = reloc_offset();
+       unsigned long nr_entries =
+               (__prom_init_toc_end - __prom_init_toc_start) / sizeof(long);
+
+       mb();
+
+       /* __prom_init_toc_start has been relocated, no need to add offset */
+       __reloc_toc(__prom_init_toc_start, -offset, nr_entries);
+}
+#endif
+#endif
 
 /*
  * We enter here early on, when the Open Firmware prom is still
@@ -2867,6 +2907,8 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,
 #ifdef CONFIG_PPC32
        unsigned long offset = reloc_offset();
        reloc_got2(offset);
+#else
+       reloc_toc();
 #endif
 
        _prom = &RELOC(prom);
@@ -3061,6 +3103,8 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,
 
 #ifdef CONFIG_PPC32
        reloc_got2(-offset);
+#else
+       unreloc_toc();
 #endif
 
 #ifdef CONFIG_PPC_EARLY_DEBUG_OPAL
index 70f4286eaa7ab74f38e99b4526657f7044f68e65..3765da6be4f250d2a7aec7887460c2a0e89e6255 100644 (file)
@@ -22,7 +22,7 @@ __secondary_hold_acknowledge __secondary_hold_spinloop __start
 strcmp strcpy strlcpy strlen strncmp strstr logo_linux_clut224
 reloc_got2 kernstart_addr memstart_addr linux_banner _stext
 opal_query_takeover opal_do_takeover opal_enter_rtas opal_secondary_entry
-boot_command_line"
+boot_command_line __prom_init_toc_start __prom_init_toc_end"
 
 NM="$1"
 OBJ="$2"
index 65d1c08cf09ecdc72dd6d24affaab9130a28f3b2..654e479802f2098afb74c0fea0bb0b68e25707f5 100644 (file)
@@ -218,6 +218,11 @@ SECTIONS
 
        .got : AT(ADDR(.got) - LOAD_OFFSET) {
                __toc_start = .;
+#ifndef CONFIG_RELOCATABLE
+               __prom_init_toc_start = .;
+               arch/powerpc/kernel/prom_init.o*(.toc .got)
+               __prom_init_toc_end = .;
+#endif
                *(.got)
                *(.toc)
        }