Commit 020d044f authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Catalin Marinas

arm64: mm: treat memstart_addr as a signed quantity

Commit c031a421 ("arm64: kaslr: randomize the linear region")
implements randomization of the linear region, by subtracting a random
multiple of PUD_SIZE from memstart_addr. This causes the virtual mapping
of system RAM to move upwards in the linear region, and at the same time
causes memstart_addr to assume a value which may be negative if the offset
of system RAM in the physical space is smaller than its offset relative to
PAGE_OFFSET in the virtual space.

Since memstart_addr is effectively an offset now, redefine its type as s64
so that expressions involving shifting or division preserve its sign.
Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
parent a6e1f727
...@@ -135,7 +135,7 @@ ...@@ -135,7 +135,7 @@
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/mmdebug.h> #include <linux/mmdebug.h>
extern phys_addr_t memstart_addr; extern s64 memstart_addr;
/* PHYS_OFFSET - the physical address of the start of memory. */ /* PHYS_OFFSET - the physical address of the start of memory. */
#define PHYS_OFFSET ({ VM_BUG_ON(memstart_addr & 1); memstart_addr; }) #define PHYS_OFFSET ({ VM_BUG_ON(memstart_addr & 1); memstart_addr; })
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
* executes, which assigns it its actual value. So use a default value * executes, which assigns it its actual value. So use a default value
* that cannot be mistaken for a real physical address. * that cannot be mistaken for a real physical address.
*/ */
phys_addr_t memstart_addr __read_mostly = ~0ULL; s64 memstart_addr __read_mostly = -1;
phys_addr_t arm64_dma_phys_limit __read_mostly; phys_addr_t arm64_dma_phys_limit __read_mostly;
#ifdef CONFIG_BLK_DEV_INITRD #ifdef CONFIG_BLK_DEV_INITRD
...@@ -181,7 +181,7 @@ void __init arm64_memblock_init(void) ...@@ -181,7 +181,7 @@ void __init arm64_memblock_init(void)
* linear mapping. Take care not to clip the kernel which may be * linear mapping. Take care not to clip the kernel which may be
* high in memory. * high in memory.
*/ */
memblock_remove(max(memstart_addr + linear_region_size, __pa(_end)), memblock_remove(max_t(u64, memstart_addr + linear_region_size, __pa(_end)),
ULLONG_MAX); ULLONG_MAX);
if (memblock_end_of_DRAM() > linear_region_size) if (memblock_end_of_DRAM() > linear_region_size)
memblock_remove(0, memblock_end_of_DRAM() - linear_region_size); memblock_remove(0, memblock_end_of_DRAM() - linear_region_size);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment