Skip to content

Commit b78c702

Browse files
Ard BiesheuvelAlex Shi
authored andcommitted
arm64: mm: treat memstart_addr as a signed quantity
Commit c031a4213c11 ("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: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> (cherry picked from commit 020d044f66874eba058ce8264fc550f3eca67879) Signed-off-by: Alex Shi <alex.shi@linaro.org>
1 parent 27fa6e5 commit b78c702

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

arch/arm64/include/asm/memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
#include <linux/bitops.h>
136136
#include <linux/mmdebug.h>
137137

138-
extern phys_addr_t memstart_addr;
138+
extern s64 memstart_addr;
139139
/* PHYS_OFFSET - the physical address of the start of memory. */
140140
#define PHYS_OFFSET ({ VM_BUG_ON(memstart_addr & 1); memstart_addr; })
141141

arch/arm64/mm/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
* executes, which assigns it its actual value. So use a default value
5555
* that cannot be mistaken for a real physical address.
5656
*/
57-
phys_addr_t memstart_addr __read_mostly = ~0ULL;
57+
s64 memstart_addr __read_mostly = -1;
5858
phys_addr_t arm64_dma_phys_limit __read_mostly;
5959

6060
#ifdef CONFIG_BLK_DEV_INITRD
@@ -188,7 +188,7 @@ void __init arm64_memblock_init(void)
188188
* linear mapping. Take care not to clip the kernel which may be
189189
* high in memory.
190190
*/
191-
memblock_remove(max(memstart_addr + linear_region_size, __pa(_end)),
191+
memblock_remove(max_t(u64, memstart_addr + linear_region_size, __pa(_end)),
192192
ULLONG_MAX);
193193
if (memblock_end_of_DRAM() > linear_region_size)
194194
memblock_remove(0, memblock_end_of_DRAM() - linear_region_size);

0 commit comments

Comments
 (0)