Skip to content

Commit 6d7d5da

Browse files
Magnus DammRussell King
Magnus Damm
authored and
Russell King
committed
ARM: 7864/1: Handle 64-bit memory in case of 32-bit phys_addr_t
Use CONFIG_ARCH_PHYS_ADDR_T_64BIT to determine if ignoring or truncating of memory banks is neccessary. This may be needed in the case of 64-bit memory bank addresses but when phys_addr_t is kept 32-bit. Signed-off-by: Magnus Damm <[email protected]> Signed-off-by: Russell King <[email protected]>
1 parent 6a5014a commit 6d7d5da

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

arch/arm/kernel/setup.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ void __init dump_machine_table(void)
624624
int __init arm_add_memory(u64 start, u64 size)
625625
{
626626
struct membank *bank = &meminfo.bank[meminfo.nr_banks];
627+
u64 aligned_start;
627628

628629
if (meminfo.nr_banks >= NR_BANKS) {
629630
printk(KERN_CRIT "NR_BANKS too low, "
@@ -636,21 +637,28 @@ int __init arm_add_memory(u64 start, u64 size)
636637
* Size is appropriately rounded down, start is rounded up.
637638
*/
638639
size -= start & ~PAGE_MASK;
639-
bank->start = PAGE_ALIGN(start);
640+
aligned_start = PAGE_ALIGN(start);
640641

641-
#ifndef CONFIG_ARM_LPAE
642-
if (bank->start + size < bank->start) {
642+
#ifndef CONFIG_ARCH_PHYS_ADDR_T_64BIT
643+
if (aligned_start > ULONG_MAX) {
644+
printk(KERN_CRIT "Ignoring memory at 0x%08llx outside "
645+
"32-bit physical address space\n", (long long)start);
646+
return -EINVAL;
647+
}
648+
649+
if (aligned_start + size > ULONG_MAX) {
643650
printk(KERN_CRIT "Truncating memory at 0x%08llx to fit in "
644651
"32-bit physical address space\n", (long long)start);
645652
/*
646653
* To ensure bank->start + bank->size is representable in
647654
* 32 bits, we use ULONG_MAX as the upper limit rather than 4GB.
648655
* This means we lose a page after masking.
649656
*/
650-
size = ULONG_MAX - bank->start;
657+
size = ULONG_MAX - aligned_start;
651658
}
652659
#endif
653660

661+
bank->start = aligned_start;
654662
bank->size = size & ~(phys_addr_t)(PAGE_SIZE - 1);
655663

656664
/*

0 commit comments

Comments
 (0)