]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
mips: Combine memblock init and memory reservation loops
authorSerge Semin <fancer.lancer@gmail.com>
Tue, 23 Apr 2019 22:47:39 +0000 (01:47 +0300)
committerPaul Burton <paul.burton@mips.com>
Wed, 24 Apr 2019 22:24:58 +0000 (15:24 -0700)
Before bootmem was completely removed from the kernel, the last loop
in the bootmem_init() had been used to reserve the correspondingly
marked regions, initialize sparsemem sections and to free the low memory
pages, which then would be used for early memory allocations. After the
bootmem removing patchset had been merged the loop was left to do the first
two things only. But it didn't do them quite well.

First of all it leaves the BOOT_MEM_INIT_RAM memory types unreserved,
which is definitely bug (although it isn't noticeable due to being used
by the kernel region only, which is fully marked as reserved). Secondly
the reservation is supposed to be done for any memory including the
high one. (I couldn't figure out why the highmem was ignored in the first
place, since platforms and dts' may declare any memory region for
reservation) Thirdly the reserved_end variable had been used here to not
accidentally free memory occupied by kernel. Since we already reserved the
corresponding region higher in this method there is no need in using the
variable here anymore. Fourthly the sparsemem should be aware of all the
memory types in the system including the ROM_DATA even if it is going to
be reserved for the whole system uptime. Finally after all these notes are
fixed the loop of memory reservation can be freely merged into the memory
installation loop as it's done in this patch.

Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
Signed-off-by: Paul Burton <paul.burton@mips.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: James Hogan <jhogan@kernel.org>
Cc: Matt Redfearn <matt.redfearn@mips.com>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Thomas Bogendoerfer <tbogendoerfer@suse.de>
Cc: Huacai Chen <chenhc@lemote.com>
Cc: Stefan Agner <stefan@agner.ch>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: linux-mips@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
arch/mips/kernel/setup.c

index 53d93a727d1a91b5a2deb90df51364ab5627c1d0..185e0e42e009a1691d9ecf9ed96ffd5653775d7e 100644 (file)
@@ -483,55 +483,21 @@ static void __init bootmem_init(void)
                        continue;
 
                memblock_add_node(PFN_PHYS(start), PFN_PHYS(end - start), 0);
-       }
-
-       /*
-        * Register fully available low RAM pages with the bootmem allocator.
-        */
-       for (i = 0; i < boot_mem_map.nr_map; i++) {
-               unsigned long start, end, size;
-
-               start = PFN_UP(boot_mem_map.map[i].addr);
-               end   = PFN_DOWN(boot_mem_map.map[i].addr
-                                   + boot_mem_map.map[i].size);
 
-               /*
-                * Reserve usable memory.
-                */
+               /* Reserve any memory except the ordinary RAM ranges. */
                switch (boot_mem_map.map[i].type) {
                case BOOT_MEM_RAM:
                        break;
-               case BOOT_MEM_INIT_RAM:
-                       memory_present(0, start, end);
-                       continue;
-               default:
-                       /* Not usable memory */
-                       if (start > min_low_pfn && end < max_low_pfn)
-                               memblock_reserve(boot_mem_map.map[i].addr,
-                                               boot_mem_map.map[i].size);
-
-                       continue;
+               default: /* Reserve the rest of the memory types at boot time */
+                       memblock_reserve(PFN_PHYS(start), PFN_PHYS(end - start));
+                       break;
                }
 
                /*
-                * We are rounding up the start address of usable memory
-                * and at the end of the usable range downwards.
-                */
-               if (start >= max_low_pfn)
-                       continue;
-               if (start < reserved_end)
-                       start = reserved_end;
-               if (end > max_low_pfn)
-                       end = max_low_pfn;
-
-               /*
-                * ... finally, is the area going away?
+                * In any case the added to the memblock memory regions
+                * (highmem/lowmem, available/reserved, etc) are considered
+                * as present, so inform sparsemem about them.
                 */
-               if (end <= start)
-                       continue;
-               size = end - start;
-
-               /* Register lowmem ranges */
                memory_present(0, start, end);
        }