bcm27xx: update patches from RPi foundation
[oweals/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0634-arm64-mm-Fix-initialisation-of-DMA-zones-on-non-NUMA.patch
1 From cd2d09e995bc72711b48b5c271b72e3ea3e99cdf Mon Sep 17 00:00:00 2001
2 From: Will Deacon <will@kernel.org>
3 Date: Tue, 3 Dec 2019 12:10:13 +0000
4 Subject: [PATCH] arm64: mm: Fix initialisation of DMA zones on
5  non-NUMA systems
6
7 commit 93b90414c33f59b7960bc8d607da0ce83377e021 upstream.
8
9 John reports that the recently merged commit 1a8e1cef7603 ("arm64: use
10 both ZONE_DMA and ZONE_DMA32") breaks the boot on his DB845C board:
11
12   | Booting Linux on physical CPU 0x0000000000 [0x517f803c]
13   | Linux version 5.4.0-mainline-10675-g957a03b9e38f
14   | Machine model: Thundercomm Dragonboard 845c
15   | [...]
16   | Built 1 zonelists, mobility grouping on.  Total pages: -188245
17   | Kernel command line: earlycon
18   | firmware_class.path=/vendor/firmware/ androidboot.hardware=db845c
19   | init=/init androidboot.boot_devices=soc/1d84000.ufshc
20   | printk.devkmsg=on buildvariant=userdebug root=/dev/sda2
21   | androidboot.bootdevice=1d84000.ufshc androidboot.serialno=c4e1189c
22   | androidboot.baseband=sda
23   | msm_drm.dsi_display0=dsi_lt9611_1080_video_display:
24   | androidboot.slot_suffix=_a skip_initramfs rootwait ro init=/init
25   |
26   | <hangs indefinitely here>
27
28 This is because, when CONFIG_NUMA=n, zone_sizes_init() fails to handle
29 memblocks that fall entirely within the ZONE_DMA region and erroneously ends up
30 trying to add a negatively-sized region into the following ZONE_DMA32, which is
31 later interpreted as a large unsigned region by the core MM code.
32
33 Rework the non-NUMA implementation of zone_sizes_init() so that the start
34 address of the memblock being processed is adjusted according to the end of the
35 previous zone, which is then range-checked before updating the hole information
36 of subsequent zones.
37
38 Cc: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
39 Cc: Christoph Hellwig <hch@lst.de>
40 Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
41 Link: https://lore.kernel.org/lkml/CALAqxLVVcsmFrDKLRGRq7GewcW405yTOxG=KR3csVzQ6bXutkA@mail.gmail.com
42 Fixes: 1a8e1cef7603 ("arm64: use both ZONE_DMA and ZONE_DMA32")
43 Reported-by: John Stultz <john.stultz@linaro.org>
44 Tested-by: John Stultz <john.stultz@linaro.org>
45 Signed-off-by: Will Deacon <will@kernel.org>
46 Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
47 ---
48  arch/arm64/mm/init.c | 25 +++++++++++--------------
49  1 file changed, 11 insertions(+), 14 deletions(-)
50
51 --- a/arch/arm64/mm/init.c
52 +++ b/arch/arm64/mm/init.c
53 @@ -214,15 +214,14 @@ static void __init zone_sizes_init(unsig
54  {
55         struct memblock_region *reg;
56         unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];
57 -       unsigned long max_dma32 = min;
58 -       unsigned long max_dma = min;
59 +       unsigned long __maybe_unused max_dma, max_dma32;
60  
61         memset(zone_size, 0, sizeof(zone_size));
62  
63 +       max_dma = max_dma32 = min;
64  #ifdef CONFIG_ZONE_DMA
65 -       max_dma = PFN_DOWN(arm64_dma_phys_limit);
66 +       max_dma = max_dma32 = PFN_DOWN(arm64_dma_phys_limit);
67         zone_size[ZONE_DMA] = max_dma - min;
68 -       max_dma32 = max_dma;
69  #endif
70  #ifdef CONFIG_ZONE_DMA32
71         max_dma32 = PFN_DOWN(arm64_dma32_phys_limit);
72 @@ -236,25 +235,23 @@ static void __init zone_sizes_init(unsig
73                 unsigned long start = memblock_region_memory_base_pfn(reg);
74                 unsigned long end = memblock_region_memory_end_pfn(reg);
75  
76 -               if (start >= max)
77 -                       continue;
78  #ifdef CONFIG_ZONE_DMA
79 -               if (start < max_dma) {
80 -                       unsigned long dma_end = min_not_zero(end, max_dma);
81 +               if (start >= min && start < max_dma) {
82 +                       unsigned long dma_end = min(end, max_dma);
83                         zhole_size[ZONE_DMA] -= dma_end - start;
84 +                       start = dma_end;
85                 }
86  #endif
87  #ifdef CONFIG_ZONE_DMA32
88 -               if (start < max_dma32) {
89 +               if (start >= max_dma && start < max_dma32) {
90                         unsigned long dma32_end = min(end, max_dma32);
91 -                       unsigned long dma32_start = max(start, max_dma);
92 -                       zhole_size[ZONE_DMA32] -= dma32_end - dma32_start;
93 +                       zhole_size[ZONE_DMA32] -= dma32_end - start;
94 +                       start = dma32_end;
95                 }
96  #endif
97 -               if (end > max_dma32) {
98 +               if (start >= max_dma32 && start < max) {
99                         unsigned long normal_end = min(end, max);
100 -                       unsigned long normal_start = max(start, max_dma32);
101 -                       zhole_size[ZONE_NORMAL] -= normal_end - normal_start;
102 +                       zhole_size[ZONE_NORMAL] -= normal_end - start;
103                 }
104         }
105