riscv: __asm_copy_to-from_user: Fix: overrun copy
[linux-2.6-microblaze.git] / mm / memblock.c
index 123feef..0041ff6 100644 (file)
@@ -182,6 +182,8 @@ bool __init_memblock memblock_overlaps_region(struct memblock_type *type,
 {
        unsigned long i;
 
+       memblock_cap_size(base, &size);
+
        for (i = 0; i < type->cnt; i++)
                if (memblock_addrs_overlap(base, size, type->regions[i].base,
                                           type->regions[i].size))
@@ -906,6 +908,11 @@ int __init_memblock memblock_mark_mirror(phys_addr_t base, phys_addr_t size)
  * @base: the base phys addr of the region
  * @size: the size of the region
  *
+ * The memory regions marked with %MEMBLOCK_NOMAP will not be added to the
+ * direct mapping of the physical memory. These regions will still be
+ * covered by the memory map. The struct page representing NOMAP memory
+ * frames in the memory map will be PageReserved()
+ *
  * Return: 0 on success, -errno on failure.
  */
 int __init_memblock memblock_mark_nomap(phys_addr_t base, phys_addr_t size)
@@ -1794,7 +1801,6 @@ bool __init_memblock memblock_is_region_memory(phys_addr_t base, phys_addr_t siz
  */
 bool __init_memblock memblock_is_region_reserved(phys_addr_t base, phys_addr_t size)
 {
-       memblock_cap_size(base, &size);
        return memblock_overlaps_region(&memblock.reserved, base, size);
 }
 
@@ -1941,14 +1947,13 @@ static void __init free_unused_memmap(void)
                 * due to SPARSEMEM sections which aren't present.
                 */
                start = min(start, ALIGN(prev_end, PAGES_PER_SECTION));
-#else
+#endif
                /*
-                * Align down here since the VM subsystem insists that the
-                * memmap entries are valid from the bank start aligned to
-                * MAX_ORDER_NR_PAGES.
+                * Align down here since many operations in VM subsystem
+                * presume that there are no holes in the memory map inside
+                * a pageblock
                 */
-               start = round_down(start, MAX_ORDER_NR_PAGES);
-#endif
+               start = round_down(start, pageblock_nr_pages);
 
                /*
                 * If we had a previous bank, and there is a space
@@ -1958,16 +1963,18 @@ static void __init free_unused_memmap(void)
                        free_memmap(prev_end, start);
 
                /*
-                * Align up here since the VM subsystem insists that the
-                * memmap entries are valid from the bank end aligned to
-                * MAX_ORDER_NR_PAGES.
+                * Align up here since many operations in VM subsystem
+                * presume that there are no holes in the memory map inside
+                * a pageblock
                 */
-               prev_end = ALIGN(end, MAX_ORDER_NR_PAGES);
+               prev_end = ALIGN(end, pageblock_nr_pages);
        }
 
 #ifdef CONFIG_SPARSEMEM
-       if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION))
+       if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION)) {
+               prev_end = ALIGN(end, pageblock_nr_pages);
                free_memmap(prev_end, ALIGN(prev_end, PAGES_PER_SECTION));
+       }
 #endif
 }
 
@@ -2002,6 +2009,26 @@ static unsigned long __init __free_memory_core(phys_addr_t start,
        return end_pfn - start_pfn;
 }
 
+static void __init memmap_init_reserved_pages(void)
+{
+       struct memblock_region *region;
+       phys_addr_t start, end;
+       u64 i;
+
+       /* initialize struct pages for the reserved regions */
+       for_each_reserved_mem_range(i, &start, &end)
+               reserve_bootmem_region(start, end);
+
+       /* and also treat struct pages for the NOMAP regions as PageReserved */
+       for_each_mem_region(region) {
+               if (memblock_is_nomap(region)) {
+                       start = region->base;
+                       end = start + region->size;
+                       reserve_bootmem_region(start, end);
+               }
+       }
+}
+
 static unsigned long __init free_low_memory_core_early(void)
 {
        unsigned long count = 0;
@@ -2010,8 +2037,7 @@ static unsigned long __init free_low_memory_core_early(void)
 
        memblock_clear_hotplug(0, -1);
 
-       for_each_reserved_mem_range(i, &start, &end)
-               reserve_bootmem_region(start, end);
+       memmap_init_reserved_pages();
 
        /*
         * We need to use NUMA_NO_NODE instead of NODE_DATA(0)->node_id