Skip to content

Commit 93b9041

Browse files
willdeaconctmarinas
authored andcommitted
arm64: mm: Fix initialisation of DMA zones on non-NUMA systems
John reports that the recently merged commit 1a8e1ce ("arm64: use both ZONE_DMA and ZONE_DMA32") breaks the boot on his DB845C board: | Booting Linux on physical CPU 0x0000000000 [0x517f803c] | Linux version 5.4.0-mainline-10675-g957a03b9e38f | Machine model: Thundercomm Dragonboard 845c | [...] | Built 1 zonelists, mobility grouping on. Total pages: -188245 | Kernel command line: earlycon | firmware_class.path=/vendor/firmware/ androidboot.hardware=db845c | init=/init androidboot.boot_devices=soc/1d84000.ufshc | printk.devkmsg=on buildvariant=userdebug root=/dev/sda2 | androidboot.bootdevice=1d84000.ufshc androidboot.serialno=c4e1189c | androidboot.baseband=sda | msm_drm.dsi_display0=dsi_lt9611_1080_video_display: | androidboot.slot_suffix=_a skip_initramfs rootwait ro init=/init | | <hangs indefinitely here> This is because, when CONFIG_NUMA=n, zone_sizes_init() fails to handle memblocks that fall entirely within the ZONE_DMA region and erroneously ends up trying to add a negatively-sized region into the following ZONE_DMA32, which is later interpreted as a large unsigned region by the core MM code. Rework the non-NUMA implementation of zone_sizes_init() so that the start address of the memblock being processed is adjusted according to the end of the previous zone, which is then range-checked before updating the hole information of subsequent zones. Cc: Nicolas Saenz Julienne <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Bjorn Andersson <[email protected]> Link: https://lore.kernel.org/lkml/CALAqxLVVcsmFrDKLRGRq7GewcW405yTOxG=KR3csVzQ6bXutkA@mail.gmail.com Fixes: 1a8e1ce ("arm64: use both ZONE_DMA and ZONE_DMA32") Reported-by: John Stultz <[email protected]> Tested-by: John Stultz <[email protected]> Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent d8e85e1 commit 93b9041

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

arch/arm64/mm/init.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,14 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)
214214
{
215215
struct memblock_region *reg;
216216
unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];
217-
unsigned long max_dma32 = min;
218-
unsigned long __maybe_unused max_dma = min;
217+
unsigned long __maybe_unused max_dma, max_dma32;
219218

220219
memset(zone_size, 0, sizeof(zone_size));
221220

221+
max_dma = max_dma32 = min;
222222
#ifdef CONFIG_ZONE_DMA
223-
max_dma = PFN_DOWN(arm64_dma_phys_limit);
223+
max_dma = max_dma32 = PFN_DOWN(arm64_dma_phys_limit);
224224
zone_size[ZONE_DMA] = max_dma - min;
225-
max_dma32 = max_dma;
226225
#endif
227226
#ifdef CONFIG_ZONE_DMA32
228227
max_dma32 = PFN_DOWN(arm64_dma32_phys_limit);
@@ -236,25 +235,23 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)
236235
unsigned long start = memblock_region_memory_base_pfn(reg);
237236
unsigned long end = memblock_region_memory_end_pfn(reg);
238237

239-
if (start >= max)
240-
continue;
241238
#ifdef CONFIG_ZONE_DMA
242-
if (start < max_dma) {
243-
unsigned long dma_end = min_not_zero(end, max_dma);
239+
if (start >= min && start < max_dma) {
240+
unsigned long dma_end = min(end, max_dma);
244241
zhole_size[ZONE_DMA] -= dma_end - start;
242+
start = dma_end;
245243
}
246244
#endif
247245
#ifdef CONFIG_ZONE_DMA32
248-
if (start < max_dma32) {
246+
if (start >= max_dma && start < max_dma32) {
249247
unsigned long dma32_end = min(end, max_dma32);
250-
unsigned long dma32_start = max(start, max_dma);
251-
zhole_size[ZONE_DMA32] -= dma32_end - dma32_start;
248+
zhole_size[ZONE_DMA32] -= dma32_end - start;
249+
start = dma32_end;
252250
}
253251
#endif
254-
if (end > max_dma32) {
252+
if (start >= max_dma32 && start < max) {
255253
unsigned long normal_end = min(end, max);
256-
unsigned long normal_start = max(start, max_dma32);
257-
zhole_size[ZONE_NORMAL] -= normal_end - normal_start;
254+
zhole_size[ZONE_NORMAL] -= normal_end - start;
258255
}
259256
}
260257

0 commit comments

Comments
 (0)