Drivers: hv: balloon: Correctly update onlined page count
authorAlex Ng <alexng@messages.microsoft.com>
Sun, 6 Aug 2017 20:12:53 +0000 (13:12 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 16 Aug 2017 16:14:42 +0000 (09:14 -0700)
Previously, num_pages_onlined was updated using value from memory online
notifier. This is incorrect because they assume that all hot-added pages
are online, even though we only online the amount that's backed by the
host. We should update num_pages_onlined only when the balloon driver
marks a page as online.

Signed-off-by: Alex Ng <alexng@messages.microsoft.com>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hv/hv_balloon.c

index f5728deff8933994680e09b46988daa8005369d1..0a5c318eedc10731c16f73d1a4716cb6d330b709 100644 (file)
@@ -584,10 +584,6 @@ static int hv_memory_notifier(struct notifier_block *nb, unsigned long val,
 
        switch (val) {
        case MEM_ONLINE:
-               spin_lock_irqsave(&dm_device.ha_lock, flags);
-               dm_device.num_pages_onlined += mem->nr_pages;
-               spin_unlock_irqrestore(&dm_device.ha_lock, flags);
-               /* Fall through */
        case MEM_CANCEL_ONLINE:
                if (dm_device.ha_waiting) {
                        dm_device.ha_waiting = false;
@@ -644,6 +640,9 @@ static void hv_page_online_one(struct hv_hotadd_state *has, struct page *pg)
        __online_page_set_limits(pg);
        __online_page_increment_counters(pg);
        __online_page_free(pg);
+
+       WARN_ON_ONCE(!spin_is_locked(&dm_device.ha_lock));
+       dm_device.num_pages_onlined++;
 }
 
 static void hv_bring_pgs_online(struct hv_hotadd_state *has,