From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 37AFE606A322 for ; Thu, 3 Dec 2026 12:29:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=e5gITWb7 Received: by kanga.kvack.org (Postfix) id A5B9F6B05B5; Thu, 3 Dec 2026 07:29:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A0D516B05B6; Thu, 3 Dec 2026 07:29:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AD816B05B7; Thu, 3 Dec 2026 07:29:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6104A6B05B5 for ; Thu, 3 Dec 2026 07:29:25 -0500 (EST) Received: from smtpin23.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E2E95160644 for ; Thu, 3 Dec 2026 12:29:24 +0000 (UTC) X-FDA: 85502602248.23.260643A Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf02.hostedemail.com (Postfix) with ESMTP id 3BA9F80007 for ; Thu, 3 Dec 2026 12:29:23 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=e5gITWb7; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf02.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796300963; b=0Gvd1eh6gJBRRslEx1CjnoqQ7rDfJG5Xn4tgSpRO+TMe7T3OWiiuA46EFiOT1aVUokZEmf y1Vi7xbseNOswce8A+SEBtSAXBrucfNeONcl0tlKcCdIG4GsBuE8zFSDUjzAdRcHu1ZAeD EzYo7sRkdxlgAWZ8smBIqo0hwX9OwmE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796300963; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Sh8xO2+d50pxpSdQRjS3jxROe7ZeSjEPXUsYzDUj4NQ=; b=VP08TsV4fjvviyqTZelj/peYL4TOFRmn902T1qeYQdoCFCxfeJdS8HxqTd3L8+5ZvRoEzG Z5RGS6z8fmNsLEJRo1VgR31jh7bjNwuoG8RnjAUjUlryLKPOHlQZwXLPUI45FCEgYeblOP VWg9RCv7EXSmd2vcUyTiDZTqlahY8EM= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=e5gITWb7; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf02.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 71AA74556C; Thu, 3 Dec 2026 12:29:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E5381F000C1; Thu, 3 Dec 2026 12:29:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796300962; bh=Sh8xO2+d50pxpSdQRjS3jxROe7ZeSjEPXUsYzDUj4NQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=e5gITWb7qikJULFecviMccTJ3p24ls0hiW6A5J2POEJ+y84gGKesUOpQA0qgsU5kK U5BVYrg8jDQouTtt19n1KGAjOznMZlC5puGZmst4C6NQ0Dz6W/1tWL2XTO4wVVh5vj IzYKtZIQGcfQXHfY5rwqPyKxcYZr6XLgD3EU9Cccfs7JMJw66IrmFgdT9oPMeSoqWz ZkMwO9uD7ducYWH2o/X/WXjSx3boNXH0UfVsEtDQ4tlTNWmzU++pwZAdWq5MOE9ap9 giukwqaZNgwGRPZ5XSp1FjZ1mmc3UqWD14Eb55E4WbUOgpKh0Gh2sEMUkV1bdj5FOy 15BYZcYgCp0ug== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 09/35] mm/hugetlb: free surplus folios of other nodes on free Reply-To: sashiko-reviews@lists.linux.dev To: =?utf-8?b?RGF2aWQgSGlsZGVuYnJhbmQgKEFybSk=?= , "Muchun Song" , "Oscar Salvador" , "Andrew Morton" , "Hongfu Li" , "Jinmeng Zhou" , "Mina Almasry" , "Davidlohr Bueso" , "Naoya Horiguchi" , "Liam R. Howlett" , "Vlastimil Babka" , "Mike Rapoport" , "Michal Hocko" , "Jonathan Corbet" , "Shuah Khan" , "Randy Dunlap" , "Vivek Kasireddy" , "Mel Gorman" , "Hugh Dickins" , "Baolin Wang" , "Dave Airlie" , "Jason Gunthorpe" , "Andy Whitcroft" , "Roman Gushchin" , "Barry Song" , "Andrea Arcangeli" , "Lorenzo Stoakes" , "Suren Baghdasaryan" , "Shakeel Butt" , "Pedro Falcato" , "Jann Horn" , "Guillaume Morin" , "Yang Shi" , "James Houghton" , "Rik van Riel" , "Harry Yoo" , "Lance Yang" , "Axel Rasmussen" , "Peter Xu" , "Sasha Levin" , "Kiryl Shutsemau" , "Christian Brauner" , =?utf-8?b?U3RldmVuIFJvc3RlZHQgKEdvb2ds?= =?utf-8?b?ZSk=?= , "Hongbo Li" , "Gregory Price" , "Zi Yan" , "Joshua Hahn" , "Rakie Kim" , "Ying Huang" , "Matthew Brost" , "Byungchul Park" , "Alistair Popple" , "Andi Kleen" , "David Rientjes" , "Joern Engel" , "Aneesh Kumar K.V" Cc: linux-mm@kvack.org, "Gerd Hoffmann" , "Johannes Weiner" , "Chris Mason" , "Jiaqi Yan" In-Reply-To: <20261203-hugetlb_fixes_2-v2-9-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> <20261203-hugetlb_fixes_2-v2-9-9bbeabb555d2@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 12:29:20 +0000 X-Rspam-User: X-Stat-Signature: nen3pg5kqz1pxjtrto983eeug4fjfuti X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 3BA9F80007 X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796300963-605299 X-HE-Meta: U2FsdGVkX186rV9dhbsNtQfxyGN62APLl9zgZQCnnoMRp5Pp5Ew5bxHQ7bAz3dytL0DbKG1lxW40PAKjozOcxUtQgSG3xyZXAA8fX/hPWQyXb73vxhXAJasN8IIBKcEGdBlj4Sg6n6buBoUh+XEulvhH9DLf+sVjniz/9noHgP8AYLO8OnsXPtKt74EVPLrH+OsLHuyvpffSqrKLRlPg8DOgQsB1FdA0ZPlpClwUnCaVDpPrsVs1lArvspzDPPiy4GFuCFGbKLSGhV8D/D0F3sFvGQ/lgB/VafzkicL5nrnFUILGLnTeXEmJz/tdh2IgH5+RINOJ8XmgJZw0aERRDNWnVFpTTxRxb0JzHivsC5s1z7+4ZJAklEf0v4ak3e7OQwBbX8X/X/UvQ7IpFlaeNSrKnLRHrmZt/5YUkTpipdReJL/KMSa57z1jivXaZrCP3aGyDBDi8etiPivpycUytjkiEAg91eguV6+U5PePFs09oor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Z4KdGV/Jm0Xflzhkse4S4soy8h+PzELr4HlMR8m32KIrXhEFIMuCPjPMq7QtK7pTmMggnM+ZKW3AtV4o2s8jpCAs4X0tUAkR6m4BF0NTp4G9ruAmSDA01AjG31rMB0Pfp4NYpKuobNKqUyfGMKez5mMOOgV5MMNyL/GVvO5cDVW/utaEoBCnh9UWwye7S27Tgy7by/URmFzWGa+jAzcL5Zpq59PDPlTMNTirulyP7+wW5KAg7hWGMP9F8C3EXWgxKdD71EdVfPGls4pJ81jTNZ/+As016HpXRvhPpfYiT7lrYEzYXQW3NGAqyl51Kv0qXM/p05J8d5Y+VWrsES/Fm7/gUxKhlqCRvuWUHqlCEO3VfKG7b9o= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] mm/hugetlb: free_huge_folio() drops healthy surplus for hwpoisoned folio - [Medium] mm: repeated O(N_nodes) scan in free_huge_folio() under hugetlb_lock -- commit 1ff8f928aad331ee2a27cdedef0346559479e7df Author: David Hildenbrand (Arm) mm/hugetlb: free surplus folios of other nodes on free This commit updates free_huge_folio() so that when a freed folio is enqueued back to a node without surplus folios, it removes and frees a free surplus folio from another node if h->free_huge_pages exceeds h->resv_huge_pages. > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 662cb87fe740a..5984377160d37 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c [ ... ] > @@ -1815,19 +1818,35 @@ void free_huge_folio(struct folio *folio) [ ... ] > + enqueue_hugetlb_folio(h, folio); > + > + /* > + * This is not a surplus folio on this node, but we might have surplus > + * folios on other nodes that are no longer required, as reservations > + * are global and surplus folios are per node. So free another folio > + * instead. > + */ > + if (h->surplus_huge_pages && > + h->free_huge_pages > h->resv_huge_pages) > + surplus_folio =3D remove_pool_hugetlb_folio(h, &node_states[N_MEMORY], > + /* acct_surplus=3D */ true); > + spin_unlock_irqrestore(&hugetlb_lock, flags); > + /* We might be in atomic context, but freeing might need vmemmap pages.= */ > + if (surplus_folio) > + update_and_free_hugetlb_folio(h, surplus_folio, true); [Severity: Medium] Can this free a healthy surplus folio on another node when folio is hwpoisoned? When memory_failure() hits an anonymous persistent folio on a node with no surplus folios, me_huge_page() calls folio_put() and then __page_handle_poison() -> dissolve_free_hugetlb_folio(). If another node has a free surplus folio backing a reservation, this frees that folio. dissolve_free_hugetlb_folio() then fails with -EBUSY because available_huge_pages(h) is zero, leaking the healthy subpages. The reservation is also left backed only by the poisoned folio, which dequeue_hugetlb_folio_node_exact() skips, risking SIGBUS on a later fault. Should this check skip freeing another node's surplus folio when folio_test_hwpoison(folio) is true? [Severity: Medium] Can this trigger a repeated O(N_nodes) scan under the IRQ-disabled hugetlb_lock during bulk teardown? When another node has an in-use surplus folio with an empty freelist and h->free_huge_pages > h->resv_huge_pages, remove_pool_hugetlb_folio() scans all N_MEMORY nodes via for_each_node_mask_to_free() and returns NULL. Because that condition stays true, every persistent folio freed by folios_put_refs() during munmap() repeats the full node scan. This turns O(M) bulk teardown into O(M * N_nodes) under the global IRQ-disabled hugetlb_lock, increasing lock contention and IRQ-off latency. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-hugetlb_fi= xes_2-v2-0-9bbeabb555d2@kernel.org?part=3D9