mm/memory_hotplug: make remove_memory() take the device_hotplug_lock
[sfrench/cifs-2.6.git] / arch / powerpc / platforms / powernv / memtrace.c
index 51dc398ae3f7a2431b39f6705a4cfc495a378aeb..773623f6bfb15fd562a517a6f93bf475ae44a3fd 100644 (file)
@@ -90,17 +90,15 @@ static bool memtrace_offline_pages(u32 nid, u64 start_pfn, u64 nr_pages)
        walk_memory_range(start_pfn, end_pfn, (void *)MEM_OFFLINE,
                          change_memblock_state);
 
-       lock_device_hotplug();
-       remove_memory(nid, start_pfn << PAGE_SHIFT, nr_pages << PAGE_SHIFT);
-       unlock_device_hotplug();
 
        return true;
 }
 
 static u64 memtrace_alloc_node(u32 nid, u64 size)
 {
-       u64 start_pfn, end_pfn, nr_pages;
+       u64 start_pfn, end_pfn, nr_pages, pfn;
        u64 base_pfn;
+       u64 bytes = memory_block_size_bytes();
 
        if (!node_spanned_pages(nid))
                return 0;
@@ -113,8 +111,21 @@ static u64 memtrace_alloc_node(u32 nid, u64 size)
        end_pfn = round_down(end_pfn - nr_pages, nr_pages);
 
        for (base_pfn = end_pfn; base_pfn > start_pfn; base_pfn -= nr_pages) {
-               if (memtrace_offline_pages(nid, base_pfn, nr_pages) == true)
+               if (memtrace_offline_pages(nid, base_pfn, nr_pages) == true) {
+                       /*
+                        * Remove memory in memory block size chunks so that
+                        * iomem resources are always split to the same size and
+                        * we never try to remove memory that spans two iomem
+                        * resources.
+                        */
+                       lock_device_hotplug();
+                       end_pfn = base_pfn + nr_pages;
+                       for (pfn = base_pfn; pfn < end_pfn; pfn += bytes>> PAGE_SHIFT) {
+                               __remove_memory(nid, pfn << PAGE_SHIFT, bytes);
+                       }
+                       unlock_device_hotplug();
                        return base_pfn << PAGE_SHIFT;
+               }
        }
 
        return 0;