Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] arm64: mm: Fix initialisation of DMA zones on non-NUMA systems
@ 2019-12-03 12:10 Will Deacon
  2019-12-03 18:47 ` John Stultz
  2019-12-04 11:26 ` Catalin Marinas
  0 siblings, 2 replies; 4+ messages in thread
From: Will Deacon @ 2019-12-03 12:10 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Catalin Marinas, linux-kernel, Bjorn Andersson, John Stultz,
	Will Deacon, Christoph Hellwig, Nicolas Saenz Julienne

John reports that the recently merged commit 1a8e1cef7603 ("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 <nsaenzjulienne@suse.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Link: https://lore.kernel.org/lkml/CALAqxLVVcsmFrDKLRGRq7GewcW405yTOxG=KR3csVzQ6bXutkA@mail.gmail.com
Fixes: 1a8e1cef7603 ("arm64: use both ZONE_DMA and ZONE_DMA32")
Reported-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Will Deacon <will@kernel.org>
---
 arch/arm64/mm/init.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

Compile-tested only.

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index be9481cdf3b9..b65dffdfb201 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -214,15 +214,14 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)
 {
 	struct memblock_region *reg;
 	unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];
-	unsigned long max_dma32 = min;
-	unsigned long __maybe_unused max_dma = min;
+	unsigned long __maybe_unused max_dma, max_dma32;
 
 	memset(zone_size, 0, sizeof(zone_size));
 
+	max_dma = max_dma32 = min;
 #ifdef CONFIG_ZONE_DMA
-	max_dma = PFN_DOWN(arm64_dma_phys_limit);
+	max_dma = max_dma32 = PFN_DOWN(arm64_dma_phys_limit);
 	zone_size[ZONE_DMA] = max_dma - min;
-	max_dma32 = max_dma;
 #endif
 #ifdef CONFIG_ZONE_DMA32
 	max_dma32 = PFN_DOWN(arm64_dma32_phys_limit);
@@ -236,25 +235,23 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)
 		unsigned long start = memblock_region_memory_base_pfn(reg);
 		unsigned long end = memblock_region_memory_end_pfn(reg);
 
-		if (start >= max)
-			continue;
 #ifdef CONFIG_ZONE_DMA
-		if (start < max_dma) {
-			unsigned long dma_end = min_not_zero(end, max_dma);
+		if (start >= min && start < max_dma) {
+			unsigned long dma_end = min(end, max_dma);
 			zhole_size[ZONE_DMA] -= dma_end - start;
+			start = dma_end;
 		}
 #endif
 #ifdef CONFIG_ZONE_DMA32
-		if (start < max_dma32) {
+		if (start >= max_dma && start < max_dma32) {
 			unsigned long dma32_end = min(end, max_dma32);
-			unsigned long dma32_start = max(start, max_dma);
-			zhole_size[ZONE_DMA32] -= dma32_end - dma32_start;
+			zhole_size[ZONE_DMA32] -= dma32_end - start;
+			start = dma32_end;
 		}
 #endif
-		if (end > max_dma32) {
+		if (start >= max_dma32 && start < max) {
 			unsigned long normal_end = min(end, max);
-			unsigned long normal_start = max(start, max_dma32);
-			zhole_size[ZONE_NORMAL] -= normal_end - normal_start;
+			zhole_size[ZONE_NORMAL] -= normal_end - start;
 		}
 	}
 
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] arm64: mm: Fix initialisation of DMA zones on non-NUMA systems
  2019-12-03 12:10 [PATCH] arm64: mm: Fix initialisation of DMA zones on non-NUMA systems Will Deacon
@ 2019-12-03 18:47 ` John Stultz
  2019-12-03 18:52   ` John Stultz
  2019-12-04 11:26 ` Catalin Marinas
  1 sibling, 1 reply; 4+ messages in thread
From: John Stultz @ 2019-12-03 18:47 UTC (permalink / raw)
  To: Will Deacon
  Cc: Catalin Marinas, lkml, Bjorn Andersson, linux-arm-kernel,
	Christoph Hellwig, Nicolas Saenz Julienne

On Tue, Dec 3, 2019 at 4:10 AM Will Deacon <will@kernel.org> wrote:
>
> John reports that the recently merged commit 1a8e1cef7603 ("arm64: use
> both ZONE_DMA and ZONE_DMA32") breaks the boot on his DB845C board:

I've also tripped on the same issue with the original HiKey board, and
can validate that this patch resolves the issue there.

Tested-by: John Stultz <john.stultz@linaro.org>

thanks
-john

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] arm64: mm: Fix initialisation of DMA zones on non-NUMA systems
  2019-12-03 18:47 ` John Stultz
@ 2019-12-03 18:52   ` John Stultz
  0 siblings, 0 replies; 4+ messages in thread
From: John Stultz @ 2019-12-03 18:52 UTC (permalink / raw)
  To: Will Deacon
  Cc: Catalin Marinas, lkml, Bjorn Andersson, linux-arm-kernel,
	Christoph Hellwig, Nicolas Saenz Julienne

On Tue, Dec 3, 2019 at 10:47 AM John Stultz <john.stultz@linaro.org> wrote:
>
> On Tue, Dec 3, 2019 at 4:10 AM Will Deacon <will@kernel.org> wrote:
> >
> > John reports that the recently merged commit 1a8e1cef7603 ("arm64: use
> > both ZONE_DMA and ZONE_DMA32") breaks the boot on his DB845C board:
>
> I've also tripped on the same issue with the original HiKey board, and
> can validate that this patch resolves the issue there.
>
> Tested-by: John Stultz <john.stultz@linaro.org>

Also validated on db845c.
Thanks so much for the quick fix!
-john

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] arm64: mm: Fix initialisation of DMA zones on non-NUMA systems
  2019-12-03 12:10 [PATCH] arm64: mm: Fix initialisation of DMA zones on non-NUMA systems Will Deacon
  2019-12-03 18:47 ` John Stultz
@ 2019-12-04 11:26 ` Catalin Marinas
  1 sibling, 0 replies; 4+ messages in thread
From: Catalin Marinas @ 2019-12-04 11:26 UTC (permalink / raw)
  To: Will Deacon
  Cc: linux-kernel, Bjorn Andersson, John Stultz, linux-arm-kernel,
	Christoph Hellwig, Nicolas Saenz Julienne

On Tue, Dec 03, 2019 at 12:10:13PM +0000, Will Deacon wrote:
> John reports that the recently merged commit 1a8e1cef7603 ("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 <nsaenzjulienne@suse.de>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
> Link: https://lore.kernel.org/lkml/CALAqxLVVcsmFrDKLRGRq7GewcW405yTOxG=KR3csVzQ6bXutkA@mail.gmail.com
> Fixes: 1a8e1cef7603 ("arm64: use both ZONE_DMA and ZONE_DMA32")
> Reported-by: John Stultz <john.stultz@linaro.org>
> Signed-off-by: Will Deacon <will@kernel.org>

Queued for 5.5-rc1. Thanks.

-- 
Catalin

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-03 12:10 [PATCH] arm64: mm: Fix initialisation of DMA zones on non-NUMA systems Will Deacon
2019-12-03 18:47 ` John Stultz
2019-12-03 18:52   ` John Stultz
2019-12-04 11:26 ` Catalin Marinas

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/1 linux-arm-kernel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org
	public-inbox-index linux-arm-kernel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git