• Vitaly Kuznetsov's avatar
    hv_balloon: fix bugs in num_pages_onlined accounting · bba072d1
    Vitaly Kuznetsov authored
    Our num_pages_onlined accounting is buggy:
    1) In case we're offlining a memory block which was present at boot (e.g.
       when there was no hotplug at all) we subtract 32k from 0 and as
       num_pages_onlined is unsigned get a very big positive number.
    
    2) Commit 6df8d9aa ("Drivers: hv: balloon: Correctly update onlined
       page count") made num_pages_onlined counter accurate on onlining but
       totally incorrect on offlining for partly populated regions: no matter
       how many pages were onlined and what was actually added to
       num_pages_onlined counter we always subtract the full region (32k) so
       again, num_pages_onlined can wrap around zero. By onlining/offlining
       the same partly populated region multiple times we can make the
       situation worse.
    
    Solve these issues by doing accurate accounting on offlining: walk HAS
    list, check for covered range and gaps.
    
    Fixes: 6df8d9aa ("Drivers: hv: balloon: Correctly update onlined page count")
    Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
    Signed-off-by: default avatarK. Y. Srinivasan <kys@microsoft.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    bba072d1
hv_balloon.c 43.2 KB