Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vmw_balloon: indicate success when effectively deflating during migration

When migrating a balloon page, we first deflate the old page to then
inflate the new page.

However, if inflating the new page succeeded, we effectively deflated the
old page, reducing the balloon size.

In that case, the migration actually worked: similar to migrating+
immediately deflating the new page. The old page will be freed back to
the buddy.

Right now, the core will leave the page be marked as isolated (as we
returned an error). When later trying to putback that page, we will run
into the WARN_ON_ONCE() in balloon_page_putback().

That handling was changed in commit 3544c4faccb8 ("mm/balloon_compaction:
stop using __ClearPageMovable()"); before that change, we would have
tolerated that way of handling it.

To fix it, let's just return 0 in that case, making the core effectively
just clear the "isolated" flag + freeing it back to the buddy as if the
migration succeeded. Note that the new page will also get freed when the
core puts the last reference.

Note that this also makes it all be more consistent: we will no longer
unisolate the page in the balloon driver while keeping it marked as being
isolated in migration core.

This was found by code inspection.

Link: https://lkml.kernel.org/r/20251014124455.478345-1-david@redhat.com
Fixes: 3544c4faccb8 ("mm/balloon_compaction: stop using __ClearPageMovable()")
Signed-off-by: David Hildenbrand <david@redhat.com>
Cc: Jerrin Shaji George <jerrin.shaji-george@broadcom.com>
Cc: Broadcom internal kernel review list <bcm-kernel-feedback-list@broadcom.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Hildenbrand and committed by
Andrew Morton
4ba5a8a7 c3fa5b1b

+3 -5
+3 -5
drivers/misc/vmw_balloon.c
··· 1737 1737 { 1738 1738 unsigned long status, flags; 1739 1739 struct vmballoon *b; 1740 - int ret; 1740 + int ret = 0; 1741 1741 1742 1742 b = container_of(b_dev_info, struct vmballoon, b_dev_info); 1743 1743 ··· 1796 1796 * A failure happened. While we can deflate the page we just 1797 1797 * inflated, this deflation can also encounter an error. Instead 1798 1798 * we will decrease the size of the balloon to reflect the 1799 - * change and report failure. 1799 + * change. 1800 1800 */ 1801 1801 atomic64_dec(&b->size); 1802 - ret = -EBUSY; 1803 1802 } else { 1804 1803 /* 1805 1804 * Success. Take a reference for the page, and we will add it to 1806 1805 * the list after acquiring the lock. 1807 1806 */ 1808 1807 get_page(newpage); 1809 - ret = 0; 1810 1808 } 1811 1809 1812 1810 /* Update the balloon list under the @pages_lock */ ··· 1815 1817 * If we succeed just insert it to the list and update the statistics 1816 1818 * under the lock. 1817 1819 */ 1818 - if (!ret) { 1820 + if (status == VMW_BALLOON_SUCCESS) { 1819 1821 balloon_page_insert(&b->b_dev_info, newpage); 1820 1822 __count_vm_event(BALLOON_MIGRATE); 1821 1823 }