]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mm/balloon_compaction: convert balloon_page_delete() to balloon_page_finalize()
authorDavid Hildenbrand <david@redhat.com>
Mon, 5 Jan 2026 19:28:25 +0000 (14:28 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Jan 2026 12:10:10 +0000 (13:10 +0100)
[ Upstream commit 15504b1163007bbfbd9a63460d5c14737c16e96d ]

Let's move the removal of the page from the balloon list into the single
caller, to remove the dependency on the PG_isolated flag and clarify
locking requirements.

Note that for now, balloon_page_delete() was used on two paths:

(1) Removing a page from the balloon for deflation through
    balloon_page_list_dequeue()
(2) Removing an isolated page from the balloon for migration in the
    per-driver migration handlers. Isolated pages were already removed from
    the balloon list during isolation.

So instead of relying on the flag, we can just distinguish both cases
directly and handle it accordingly in the caller.

We'll shuffle the operations a bit such that they logically make more
sense (e.g., remove from the list before clearing flags).

In balloon migration functions we can now move the balloon_page_finalize()
out of the balloon lock and perform the finalization just before dropping
the balloon reference.

Document that the page lock is currently required when modifying the
movability aspects of a page; hopefully we can soon decouple this from the
page lock.

Link: https://lkml.kernel.org/r/20250704102524.326966-3-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Brendan Jackman <jackmanb@google.com>
Cc: Byungchul Park <byungchul@sk.com>
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Eugenio Pé rez <eperezma@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Gregory Price <gourry@gourry.net>
Cc: Harry Yoo <harry.yoo@oracle.com>
Cc: "Huang, Ying" <ying.huang@linux.alibaba.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Jerrin Shaji George <jerrin.shaji-george@broadcom.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mathew Brost <matthew.brost@intel.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Naoya Horiguchi <nao.horiguchi@gmail.com>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Peter Xu <peterx@redhat.com>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Rakie Kim <rakie.kim@sk.com>
Cc: Rik van Riel <riel@surriel.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: xu xin <xu.xin16@zte.com.cn>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Stable-dep-of: 0da2ba35c0d5 ("powerpc/pseries/cmm: adjust BALLOON_MIGRATE when migrating pages")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/powerpc/platforms/pseries/cmm.c
drivers/misc/vmw_balloon.c
drivers/virtio/virtio_balloon.c
include/linux/balloon_compaction.h
mm/balloon_compaction.c

index 6b38ccd63c90888310baed1d8ae13135fc850654..d54d599be8b37080fa52b48e1cef4833dacff95a 100644 (file)
@@ -550,7 +550,6 @@ static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
 
        spin_lock_irqsave(&b_dev_info->pages_lock, flags);
        balloon_page_insert(b_dev_info, newpage);
-       balloon_page_delete(page);
        b_dev_info->isolated_pages--;
        spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
 
@@ -560,6 +559,7 @@ static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
         */
        plpar_page_set_active(page);
 
+       balloon_page_finalize(page);
        /* balloon page list reference */
        put_page(page);
 
index dab8ad9fed6b39e4f6d3f06e3981a24305c9f9c4..d836ef958e39bf75b332b6f8a7a3f99adb552c7e 100644 (file)
@@ -1805,8 +1805,7 @@ static int vmballoon_migratepage(struct balloon_dev_info *b_dev_info,
         * @pages_lock . We keep holding @comm_lock since we will need it in a
         * second.
         */
-       balloon_page_delete(page);
-
+       balloon_page_finalize(page);
        put_page(page);
 
        /* Inflate */
index 0f3c22cee4e71fb4d8182f1d5a8c89a28893b49f..82cfa1575027ec951fb1c8a66286be8a213635f5 100644 (file)
@@ -796,15 +796,13 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info,
        tell_host(vb, vb->inflate_vq);
 
        /* balloon's page migration 2nd step -- deflate "page" */
-       spin_lock_irqsave(&vb_dev_info->pages_lock, flags);
-       balloon_page_delete(page);
-       spin_unlock_irqrestore(&vb_dev_info->pages_lock, flags);
        vb->num_pfns = VIRTIO_BALLOON_PAGES_PER_PAGE;
        set_page_pfns(vb, vb->pfns, page);
        tell_host(vb, vb->deflate_vq);
 
        mutex_unlock(&vb->balloon_lock);
 
+       balloon_page_finalize(page);
        put_page(page); /* balloon reference */
 
        return MIGRATEPAGE_SUCCESS;
index edb7f6d41faa043d0a59b80eb0ba30307dea8fdf..ee30fb134478368b81e9bdd1249b4bdf7fc98e9d 100644 (file)
@@ -99,27 +99,6 @@ static inline void balloon_page_insert(struct balloon_dev_info *balloon,
        list_add(&page->lru, &balloon->pages);
 }
 
-/*
- * balloon_page_delete - delete a page from balloon's page list and clear
- *                      the page->private assignement accordingly.
- * @page    : page to be released from balloon's page list
- *
- * Caller must ensure the page is locked and the spin_lock protecting balloon
- * pages list is held before deleting a page from the balloon device.
- */
-static inline void balloon_page_delete(struct page *page)
-{
-       __ClearPageOffline(page);
-       __ClearPageMovable(page);
-       set_page_private(page, 0);
-       /*
-        * No touch page.lru field once @page has been isolated
-        * because VM is using the field.
-        */
-       if (!PageIsolated(page))
-               list_del(&page->lru);
-}
-
 /*
  * balloon_page_device - get the b_dev_info descriptor for the balloon device
  *                      that enqueues the given page.
@@ -143,12 +122,6 @@ static inline void balloon_page_insert(struct balloon_dev_info *balloon,
        list_add(&page->lru, &balloon->pages);
 }
 
-static inline void balloon_page_delete(struct page *page)
-{
-       __ClearPageOffline(page);
-       list_del(&page->lru);
-}
-
 static inline gfp_t balloon_mapping_gfp_mask(void)
 {
        return GFP_HIGHUSER;
@@ -156,6 +129,22 @@ static inline gfp_t balloon_mapping_gfp_mask(void)
 
 #endif /* CONFIG_BALLOON_COMPACTION */
 
+/*
+ * balloon_page_finalize - prepare a balloon page that was removed from the
+ *                        balloon list for release to the page allocator
+ * @page: page to be released to the page allocator
+ *
+ * Caller must ensure that the page is locked.
+ */
+static inline void balloon_page_finalize(struct page *page)
+{
+       if (IS_ENABLED(CONFIG_BALLOON_COMPACTION)) {
+               __ClearPageMovable(page);
+               set_page_private(page, 0);
+       }
+       __ClearPageOffline(page);
+}
+
 /*
  * balloon_page_push - insert a page into a page list.
  * @head : pointer to list
index 282211d89c9016acdecb2afe173aef07a8ad94a9..0ee974b4e41b28842c98b83ac0d7ad9e23901a1c 100644 (file)
@@ -93,7 +93,8 @@ size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
                if (!trylock_page(page))
                        continue;
 
-               balloon_page_delete(page);
+               list_del(&page->lru);
+               balloon_page_finalize(page);
                __count_vm_event(BALLOON_DEFLATE);
                list_add(&page->lru, pages);
                unlock_page(page);