diff options
| author | Paul Mackerras <paulus@samba.org> | 2013-08-27 02:07:49 -0400 |
|---|---|---|
| committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2013-08-27 02:59:30 -0400 |
| commit | bdbc29c19b2633b1d9c52638fb732bcde7a2031a (patch) | |
| tree | de4fe4de7dc8abe6d79db9e99dd042c1e34cec56 | |
| parent | f5f6cbb61610b7bf9d9d96db9c3979d62a424bab (diff) | |
powerpc: Work around gcc miscompilation of __pa() on 64-bit
On 64-bit, __pa(&static_var) gets miscompiled by recent versions of
gcc as something like:
addis 3,2,.LANCHOR1+4611686018427387904@toc@ha
addi 3,3,.LANCHOR1+4611686018427387904@toc@l
This ends up effectively ignoring the offset, since its bottom 32 bits
are zero, and means that the result of __pa() still has 0xC in the top
nibble. This happens with gcc 4.8.1, at least.
To work around this, for 64-bit we make __pa() use an AND operator,
and for symmetry, we make __va() use an OR operator. Using an AND
operator rather than a subtraction ends up with slightly shorter code
since it can be done with a single clrldi instruction, whereas it
takes three instructions to form the constant (-PAGE_OFFSET) and add
it on. (Note that MEMORY_START is always 0 on 64-bit.)
CC: <stable@vger.kernel.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
| -rw-r--r-- | arch/powerpc/Kconfig | 1 | ||||
| -rw-r--r-- | arch/powerpc/include/asm/page.h | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index dbd9d3c991e8..9cf59816d3e9 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig | |||
| @@ -979,6 +979,7 @@ config RELOCATABLE | |||
| 979 | must live at a different physical address than the primary | 979 | must live at a different physical address than the primary |
| 980 | kernel. | 980 | kernel. |
| 981 | 981 | ||
| 982 | # This value must have zeroes in the bottom 60 bits otherwise lots will break | ||
| 982 | config PAGE_OFFSET | 983 | config PAGE_OFFSET |
| 983 | hex | 984 | hex |
| 984 | default "0xc000000000000000" | 985 | default "0xc000000000000000" |
diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h index 988c812aab5b..b9f426212d3a 100644 --- a/arch/powerpc/include/asm/page.h +++ b/arch/powerpc/include/asm/page.h | |||
| @@ -211,9 +211,19 @@ extern long long virt_phys_offset; | |||
| 211 | #define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) + VIRT_PHYS_OFFSET)) | 211 | #define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) + VIRT_PHYS_OFFSET)) |
| 212 | #define __pa(x) ((unsigned long)(x) - VIRT_PHYS_OFFSET) | 212 | #define __pa(x) ((unsigned long)(x) - VIRT_PHYS_OFFSET) |
| 213 | #else | 213 | #else |
| 214 | #ifdef CONFIG_PPC64 | ||
| 215 | /* | ||
| 216 | * gcc miscompiles (unsigned long)(&static_var) - PAGE_OFFSET | ||
| 217 | * with -mcmodel=medium, so we use & and | instead of - and + on 64-bit. | ||
| 218 | */ | ||
| 219 | #define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) | PAGE_OFFSET)) | ||
| 220 | #define __pa(x) ((unsigned long)(x) & 0x0fffffffffffffffUL) | ||
| 221 | |||
| 222 | #else /* 32-bit, non book E */ | ||
| 214 | #define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) + PAGE_OFFSET - MEMORY_START)) | 223 | #define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) + PAGE_OFFSET - MEMORY_START)) |
| 215 | #define __pa(x) ((unsigned long)(x) - PAGE_OFFSET + MEMORY_START) | 224 | #define __pa(x) ((unsigned long)(x) - PAGE_OFFSET + MEMORY_START) |
| 216 | #endif | 225 | #endif |
| 226 | #endif | ||
| 217 | 227 | ||
| 218 | /* | 228 | /* |
| 219 | * Unfortunately the PLT is in the BSS in the PPC32 ELF ABI, | 229 | * Unfortunately the PLT is in the BSS in the PPC32 ELF ABI, |
