From nobody Wed Oct 8 00:39:52 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2623F2F2730 for ; Fri, 4 Jul 2025 10:25:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751624738; cv=none; b=oUEX1qKEsxzVzZutjAJaBXy3r7ceR5AdzXHHAYfuRPrXFxoYaytyYzzcMQdeH6dtqAc8n1fRNtsyoaoaHNsc0IlwXx+3mdJN+IQUVL3QzkKI9ywebood0LrN+7mH/1e69h/uLEo8hLHnDOjGs6Qt/fVQgg3FcFfokOJfdIT4Usg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751624738; c=relaxed/simple; bh=I63+tICEwC4FRjr5OpxcwU6Xz35bpjNotIszeWd/mZg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J0FEtUwWbpJb82QzFBNg1JN8pN9xbaJ9wt5rgZ2lKO3P5faI0Y6N2jwSppUWVld7Lu3qEeQC619mlTkkCC2qs3XOt0p3avaY+3jTwURqASJ/B9II9VOdZsrWIBPhQwbfoH8eotWG6aJ4E6/hDPwxcm10NN2zXAHADlWaQN1T9Tk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Ao+/f5wH; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ao+/f5wH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1751624736; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rzG8kZhPdoUa83Bv+EhsniO+15GPe15At7nc5LLJ+tY=; b=Ao+/f5wHEVXwRg2dXPDPFP+nZwJAvj0NdFmPWsu/S8t4tY7z9VjMXnx6reitOd2MHWdLC9 R0FnE+7d6MikBRXTWQWF1meiIX2cBAzLAyKm+8wuYr7VkQuo80Tv3Ow01j2VeLfSqExDop ZsR6fqQ/RqngFr8McAmneY17y3zLau8= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-182-n_5L5L8-PNCPH5u3LFbGfg-1; Fri, 04 Jul 2025 06:25:35 -0400 X-MC-Unique: n_5L5L8-PNCPH5u3LFbGfg-1 X-Mimecast-MFC-AGG-ID: n_5L5L8-PNCPH5u3LFbGfg_1751624734 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3a3696a0d3aso354516f8f.2 for ; Fri, 04 Jul 2025 03:25:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751624734; x=1752229534; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rzG8kZhPdoUa83Bv+EhsniO+15GPe15At7nc5LLJ+tY=; b=Mn1etEKlF87WB8vBemw0xYPX8IjaAb/7DB4vY9E6vrgHaZEB7M0oRMjF1YiEkWDLOO OLlvR9ksHFkKk54gTduuHpztSW9HuecbTeeciVHCoLepcQQmlu8+e8sCAb1OsrnrdFP7 M2gZS4Mn+SBtljje1/X7LByc66EdNqh72TojXcadrAzVb1sJSUvIGgeoxlZHGDr5JWmT JIkBOEyqgCtLyA2WIvYowV/o76D4DK0TdO7RHtZM9BvPa9ucVHJwLKyrHYtPz2Bo+s5d 1d22BqCwJoNoajEggb1NHDkun4fgIT5KBYJhvEagQe0vn8XZ0diFFtDZlBVTEV5i0/iY GgBw== X-Gm-Message-State: AOJu0YwbtMXGHKv1LPuRZab3Mn1qlBp3UvTtRgXuj/Vt+39oa50glxVD FodQytXAfnEEn5H8zdRyJN0pd0stmCA6LgTAoGEfd9os8bAUIbji7DMf+v92ZJwkASIuuIQLUBQ Tn3tXoA44u996FjXuV4b9iRs1lYzVct44OeuSl6wkvvZfM9xDN2OB93OKi+KxVEXstWVn3PjOWx 2KVfVdARTKrGiTEig+NTtGkcJi+lAN89rr/2ZWL+/XLnXdBQ== X-Gm-Gg: ASbGnct/jx6T4RoV0pWRoy1czFTIskrXdKuYEwNmLcSvkO+1RsHso5Oh55y2D2hIjiP Dox4kZOHzh6aAOkoZ7Z86khvWPtEt0DgEOO0bomqRife8d4OSvsEBQMHf3+/ADGiMf4oQXlDONh 8lOFsi8ydaXuFTf8tmzXbTU2XZPKSoR8i6GaS9egw5LWjCCa8DsMj9//d0ffH9ZLULje9/A22ol ACzGJCTTiFR9JuuNBPItHro8L+9xODoW9EyPJ/lnSvk/bUYEZ3T2sNA8GZhSZlKhNAOnXROUYL0 Ht69DaVJHk1Td9mP+rEFdWcB/bQY07T6UWQjMT+P98mDz9qQzsvk8nI1OczhwnJRLpgIKzhFSZ+ Hi+mvuQ== X-Received: by 2002:a05:6000:2f86:b0:3a4:fbaf:749e with SMTP id ffacd0b85a97d-3b4964ea59fmr1485344f8f.49.1751624733894; Fri, 04 Jul 2025 03:25:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHzOdZy9kGaBK2IhW4pGMieYfGDGuCayvREmmwE/RZquZQddy2FKZttIuDRBnk85RTka/4UcQ== X-Received: by 2002:a05:6000:2f86:b0:3a4:fbaf:749e with SMTP id ffacd0b85a97d-3b4964ea59fmr1485265f8f.49.1751624733234; Fri, 04 Jul 2025 03:25:33 -0700 (PDT) Received: from localhost (p200300d82f2c5500098823f9faa07232.dip0.t-ipconnect.de. [2003:d8:2f2c:5500:988:23f9:faa0:7232]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-454a9bea4a9sm50548875e9.37.2025.07.04.03.25.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Jul 2025 03:25:32 -0700 (PDT) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, virtualization@lists.linux.dev, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , Jonathan Corbet , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Jerrin Shaji George , Arnd Bergmann , Greg Kroah-Hartman , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Alexander Viro , Christian Brauner , Jan Kara , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , "Matthew Wilcox (Oracle)" , Minchan Kim , Sergey Senozhatsky , Brendan Jackman , Johannes Weiner , Jason Gunthorpe , John Hubbard , Peter Xu , Xu Xin , Chengming Zhou , Miaohe Lin , Naoya Horiguchi , Oscar Salvador , Rik van Riel , Harry Yoo , Qi Zheng , Shakeel Butt Subject: [PATCH v2 02/29] mm/balloon_compaction: convert balloon_page_delete() to balloon_page_finalize() Date: Fri, 4 Jul 2025 12:24:56 +0200 Message-ID: <20250704102524.326966-3-david@redhat.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250704102524.326966-1-david@redhat.com> References: <20250704102524.326966-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Reviewed-by: Lorenzo Stoakes Signed-off-by: David Hildenbrand --- arch/powerpc/platforms/pseries/cmm.c | 2 +- drivers/misc/vmw_balloon.c | 3 +- drivers/virtio/virtio_balloon.c | 4 +-- include/linux/balloon_compaction.h | 43 +++++++++++----------------- mm/balloon_compaction.c | 3 +- 5 files changed, 21 insertions(+), 34 deletions(-) diff --git a/arch/powerpc/platforms/pseries/cmm.c b/arch/powerpc/platforms/= pseries/cmm.c index 5f4037c1d7fe8..5e0a718d1be7b 100644 --- a/arch/powerpc/platforms/pseries/cmm.c +++ b/arch/powerpc/platforms/pseries/cmm.c @@ -532,7 +532,6 @@ static int cmm_migratepage(struct balloon_dev_info *b_d= ev_info, =20 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); =20 @@ -542,6 +541,7 @@ static int cmm_migratepage(struct balloon_dev_info *b_d= ev_info, */ plpar_page_set_active(page); =20 + balloon_page_finalize(page); /* balloon page list reference */ put_page(page); =20 diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c index c817d8c216413..6653fc53c951c 100644 --- a/drivers/misc/vmw_balloon.c +++ b/drivers/misc/vmw_balloon.c @@ -1778,8 +1778,7 @@ static int vmballoon_migratepage(struct balloon_dev_i= nfo *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); =20 /* Inflate */ diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloo= n.c index 89da052f4f687..e299e18346a30 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -866,15 +866,13 @@ static int virtballoon_migratepage(struct balloon_dev= _info *vb_dev_info, tell_host(vb, vb->inflate_vq); =20 /* 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 =3D VIRTIO_BALLOON_PAGES_PER_PAGE; set_page_pfns(vb, vb->pfns, page); tell_host(vb, vb->deflate_vq); =20 mutex_unlock(&vb->balloon_lock); =20 + balloon_page_finalize(page); put_page(page); /* balloon reference */ =20 return MIGRATEPAGE_SUCCESS; diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_com= paction.h index 5ca2d56996201..b9f19da37b089 100644 --- a/include/linux/balloon_compaction.h +++ b/include/linux/balloon_compaction.h @@ -97,27 +97,6 @@ static inline void balloon_page_insert(struct balloon_de= v_info *balloon, list_add(&page->lru, &balloon->pages); } =20 -/* - * 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 ball= oon - * 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 dev= ice * that enqueues the given page. @@ -141,12 +120,6 @@ static inline void balloon_page_insert(struct balloon_= dev_info *balloon, list_add(&page->lru, &balloon->pages); } =20 -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; @@ -154,6 +127,22 @@ static inline gfp_t balloon_mapping_gfp_mask(void) =20 #endif /* CONFIG_BALLOON_COMPACTION */ =20 +/* + * 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 diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c index fcb60233aa35d..ec176bdb8a78b 100644 --- a/mm/balloon_compaction.c +++ b/mm/balloon_compaction.c @@ -94,7 +94,8 @@ size_t balloon_page_list_dequeue(struct balloon_dev_info = *b_dev_info, if (!trylock_page(page)) continue; =20 - 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); --=20 2.49.0