[PATCH v2 11/23] drivers/virtio/virtio_balloon: stop using balloon_page_push/pop()

David Hildenbrand (Red Hat)
2026-01-15T09:21:55Z

Let's stop using these functions so we can remove them. They look like
belonging to the balloon API for managing the device balloon list when
really they are just simple helpers only used by virtio-balloon.

Let's just inline them and switch to a proper
list_for_each_entry_safe().

Signed-off-by: David Hildenbrand (Red Hat) <david@kernel.org>
---
drivers/virtio/virtio_balloon.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 15c1cf5fd249c..6ae00de78b61b 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -242,8 +242,8 @@ static void set_page_pfns(struct virtio_balloon *vb,
static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num)
{
unsigned int num_allocated_pages;
+ struct page *page, *next;
unsigned int num_pfns;
- struct page *page;
LIST_HEAD(pages);

/* We can only do one array worth at a time. */
@@ -262,14 +262,15 @@ static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num)
break;
}

- balloon_page_push(&pages, page);
+ list_add(&page->lru, &pages);
}

mutex_lock(&vb->balloon_lock);

vb->num_pfns = 0;

- while ((page = balloon_page_pop(&pages))) {
+ list_for_each_entry_safe(page, next, &pages, lru) {
+ list_del(&page->lru);
balloon_page_enqueue(&vb->vb_dev_info, page);

set_page_pfns(vb, vb->pfns + vb->num_pfns, page);
@@ -474,15 +475,19 @@ static inline s64 towards_target(struct virtio_balloon *vb)
static unsigned long return_free_pages_to_mm(struct virtio_balloon *vb,
unsigned long num_to_return)
{
- struct page *page;
- unsigned long num_returned;
+ unsigned long num_returned = 0;
+ struct page *page, *next;
+
+ if (unlikely(!num_to_return))
+ return 0;

spin_lock_irq(&vb->free_page_list_lock);
- for (num_returned = 0; num_returned < num_to_return; num_returned++) {
- page = balloon_page_pop(&vb->free_page_list);
- if (!page)
- break;
+
+ list_for_each_entry_safe(page, next, &vb->free_page_list, lru) {
+ list_del(&page->lru);
__free_pages(page, VIRTIO_BALLOON_HINT_BLOCK_ORDER);
+ if (++num_returned == num_to_return)
+ break;
}
vb->num_free_page_blocks -= num_returned;
spin_unlock_irq(&vb->free_page_list_lock);
@@ -717,7 +722,7 @@ static int get_free_page_and_send(struct virtio_balloon *vb)
}
virtqueue_kick(vq);
spin_lock_irq(&vb->free_page_list_lock);
- balloon_page_push(&vb->free_page_list, page);
+ list_add(&page->lru, &vb->free_page_list);
vb->num_free_page_blocks++;
spin_unlock_irq(&vb->free_page_list_lock);
} else {
--
2.52.0