Skip to content

Commit 791ab8b

Browse files
committed
arm64: Ignore any DMA offsets in the max_zone_phys() calculation
Currently, the kernel assumes that if RAM starts above 32-bit (or zone_bits), there is still a ZONE_DMA/DMA32 at the bottom of the RAM and such constrained devices have a hardwired DMA offset. In practice, we haven't noticed any such hardware so let's assume that we can expand ZONE_DMA32 to the available memory if no RAM below 4GB. Similarly, ZONE_DMA is expanded to the 4GB limit if no RAM addressable by zone_bits. Signed-off-by: Catalin Marinas <[email protected]> Tested-by: Nicolas Saenz Julienne <[email protected]> Reviewed-by: Nicolas Saenz Julienne <[email protected]> Cc: Nicolas Saenz Julienne <[email protected]> Cc: Robin Murphy <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent f8394f2 commit 791ab8b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

arch/arm64/mm/init.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,21 @@ static void __init reserve_elfcorehdr(void)
175175
#endif /* CONFIG_CRASH_DUMP */
176176

177177
/*
178-
* Return the maximum physical address for a zone with a given address size
179-
* limit. It currently assumes that for memory starting above 4G, 32-bit
180-
* devices will use a DMA offset.
178+
* Return the maximum physical address for a zone accessible by the given bits
179+
* limit. If DRAM starts above 32-bit, expand the zone to the maximum
180+
* available memory, otherwise cap it at 32-bit.
181181
*/
182182
static phys_addr_t __init max_zone_phys(unsigned int zone_bits)
183183
{
184-
phys_addr_t offset = memblock_start_of_DRAM() & GENMASK_ULL(63, zone_bits);
185-
return min(offset + (1ULL << zone_bits), memblock_end_of_DRAM());
184+
phys_addr_t zone_mask = DMA_BIT_MASK(zone_bits);
185+
phys_addr_t phys_start = memblock_start_of_DRAM();
186+
187+
if (phys_start > U32_MAX)
188+
zone_mask = PHYS_ADDR_MAX;
189+
else if (phys_start > zone_mask)
190+
zone_mask = U32_MAX;
191+
192+
return min(zone_mask, memblock_end_of_DRAM() - 1) + 1;
186193
}
187194

188195
static void __init zone_sizes_init(unsigned long min, unsigned long max)

0 commit comments

Comments
 (0)