Merge tag 'libnvdimm-for-4.3' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm...
[cascardo/linux.git] / mm / memory_hotplug.c
index 24e4c76..aa992e2 100644 (file)
@@ -446,7 +446,7 @@ static int __meminit __add_zone(struct zone *zone, unsigned long phys_start_pfn)
        int nr_pages = PAGES_PER_SECTION;
        int nid = pgdat->node_id;
        int zone_type;
-       unsigned long flags;
+       unsigned long flags, pfn;
        int ret;
 
        zone_type = zone - pgdat->node_zones;
@@ -461,6 +461,14 @@ static int __meminit __add_zone(struct zone *zone, unsigned long phys_start_pfn)
        pgdat_resize_unlock(zone->zone_pgdat, &flags);
        memmap_init_zone(nr_pages, nid, zone_type,
                         phys_start_pfn, MEMMAP_HOTPLUG);
+
+       /* online_page_range is called later and expects pages reserved */
+       for (pfn = phys_start_pfn; pfn < phys_start_pfn + nr_pages; pfn++) {
+               if (!pfn_valid(pfn))
+                       continue;
+
+               SetPageReserved(pfn_to_page(pfn));
+       }
        return 0;
 }
 
@@ -1248,6 +1256,14 @@ int __ref add_memory(int nid, u64 start, u64 size)
 
        mem_hotplug_begin();
 
+       /*
+        * Add new range to memblock so that when hotadd_new_pgdat() is called
+        * to allocate new pgdat, get_pfn_range_for_nid() will be able to find
+        * this new range and calculate total pages correctly.  The range will
+        * be removed at hot-remove time.
+        */
+       memblock_add_node(start, size, nid);
+
        new_node = !node_online(nid);
        if (new_node) {
                pgdat = hotadd_new_pgdat(nid, start);
@@ -1285,6 +1301,7 @@ error:
        if (new_pgdat)
                rollback_node_hotadd(nid, pgdat);
        release_memory_resource(res);
+       memblock_remove(start, size);
 
 out:
        mem_hotplug_done();
@@ -2013,6 +2030,8 @@ void __ref remove_memory(int nid, u64 start, u64 size)
 
        /* remove memmap entry */
        firmware_map_remove(start, start + size, "System RAM");
+       memblock_free(start, size);
+       memblock_remove(start, size);
 
        arch_remove_memory(start, size);