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 02374606A32D for ; Thu, 3 Dec 2026 12:29:29 +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=Ky4RjgE6 Received: by kanga.kvack.org (Postfix) id 26B516B05B3; Thu, 3 Dec 2026 07:29:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 21C736B05B5; Thu, 3 Dec 2026 07:29:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10B116B05B6; Thu, 3 Dec 2026 07:29:23 -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 DBAC16B05B3 for ; Thu, 3 Dec 2026 07:29:22 -0500 (EST) Received: from smtpin01.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7E4E71C3ED0 for ; Thu, 3 Dec 2026 12:29:22 +0000 (UTC) X-FDA: 85502602164.01.332799A Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf23.hostedemail.com (Postfix) with ESMTP id D7828140002 for ; Thu, 3 Dec 2026 12:29:20 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=Ky4RjgE6; spf=pass (imf23.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796300961; b=EQ4UlO9sqUX0XePdtZC3g/PDZvdQ/LsIZ3DPOQA2WRyex2dOM4ICF/HrCdtRj18OInUfL3 0Sj65CemzYnaDipRipZwyoVwMiTpVVxd6Mmy3lBo4O1Nkbnm4EBjQjJ43A3BIbxW/CMvG2 9TVu6L73zI2ssDdjsKHXasBDKaLtylY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796300961; 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=gr6tSA31rGxnrYdoLmlAr00TtptDLYjQCUxgeG5Rj1o=; b=qj1tmjKe0LMacZwiDNEP8nyimLQK9/UQLecffTWnnphcLFSNb9ek0VI7t/YelMBCLeIK8O hhQzvjDqpac/fJL110LTbeE24M2HPg20LYdG8wzlT3bWDOrJmpPBSzX9i34VzhUKqr4p1r EddsVeag65pCo3ihREp0SmlsujnxUsU= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=Ky4RjgE6; spf=pass (imf23.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 07D8E4237A; Thu, 3 Dec 2026 12:29:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9ED21F000C1; Thu, 3 Dec 2026 12:29:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796300959; bh=gr6tSA31rGxnrYdoLmlAr00TtptDLYjQCUxgeG5Rj1o=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Ky4RjgE6cGiFd16J2d3zqqacQqw1cX9s0S95k6s1Y1wS0ObXStMZAapcGv2s286Eo RqP9ACVOLuruo0nDBt195JnlrQx97tUmDhc7+vIALd7dbewxIRErGuB+Yrcbzx4onc qiLAmzbkdLdk6YgZQ2v4LcV3Wj1AiyXfFANIZ3DDj2sEQJ+dT+3urw9PfAmFpS63gI 0p1LqW0thwWYHyOUOt3CK49zVZBtapt4CrBIYWGC9d0hvgkzUJa9Bip/o2cjMyXdT6 w3ahJ03hIw3aEvB2Jj39k1yqxzzHQWnCO+dxrSv3tswK3HssV+YAYBsd+ay/iY/9Wo uKO9rSmOAkSTw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 04/35] mm/hugetlb: return the reservation to the subpool on error 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-4-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> <20261203-hugetlb_fixes_2-v2-4-9bbeabb555d2@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 12:29:17 +0000 X-Rspamd-Server: rspam08 X-Rspam-User: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Stat-Signature: 7tsdipned3qczemxiof5us1f3hmwcfyy X-Rspamd-Queue-Id: D7828140002 X-HE-Tag: 1796300960-50515 X-HE-Meta: U2FsdGVkX19ZfO5KAhMeCUoJxgqwqpAMHsEm9C+H+Yuj6QKviaF1Y0/H4JxHkv/uJYbJl9gT3IOz7mHLBBaqj/n3wZsFLXZyqrl3I1Tg499MT1Ghd/hwmp1rPxOuw+GSsZbT6Ss6a8w8Pom4LyWekyxpKMiWOJdTOtHgJ8KZZty0x/TwJWVeGLJDntCSFRp6eFnjXtPzkR00ewQH+9651w2ZL8VdeV/YvkL8l4caYIqStfNSCMNPD8Hpl7RejI14PxO93tCKjlY0X97tnVCTAsWLOmNb81uewqZg9hlqmYQwRi8Eylvx+s7IYOH43EjyAPn/LSkB1dVrhq8t8UIIgwq/Zsj6vEYhhzI8hUlijdP9PGj92w+41Oh3rirOJnZkW3ZJ2LN3Jd44FmK4Mj+W1OiJqpvMXwXI9F+2BfcBvhOIvv/lQweQDoXw0lg8uVps2ZDtqeCSBVmvaGntLp2Jk/zmSym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VpbuxM8QmLl0laX3ZRQRTgWp/zsA1hO/RQAp/ePOWTzFEbjmklj3aFWEH5Koj8vzLtiEQD3sEHV1xHRA+XZ+lkW5N5uAnNeFpm4sNXDg9xIa5NS2Vc6SWjmopFeS1ZwvQN34jO0sy9IpqZ3HaDskIL5+8+pmf7DrfiDt47PFZdxXcATyngvYZg2xHT92S345m0I/uBtA7S6OxeVRCMlOswlCbUJu4D8nLtQB4067PQ/9hCqa3h8jNaOz833zf3R5G6KopAXY3x+jFjjzWA/loheYA4BA5o4usQKmHybc3zkfK2VGybQutQRpuvoytwgWGqYKbbYDAE1XJP+8V2SkIXsF7ExvI4jX4JUdLatXXC1gYfpft6QxYyUBd738o= 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: - [Low] mm/hugetlb: stale CoW-only HPG_restore_reserve comment in hugetlb.h - [Low] mm/hugetlb: inaccurate Fixes trailer citing 1c5ecae3a93f -- commit 60d3433873fb76ac98b3288706485f76d8784a94 Author: David Hildenbrand (Arm) > mm/hugetlb: return the reservation to the subpool on error > > When we fault in a folio in a shared hugetlb mapping at an index that is > not reserved yet on a min_size=3D mount, alloc_hugetlb_folio() can take t= he > reservation from the subpool minimum, and we perform the reservation for > the folio's index in the reserve map. > > If something goes wrong before adding the folio to the page cache, > restore_reserve_on_error() is supposed to undo the reservation in the > reserve map, and free_huge_folio() is supposed to return the reservation > to the subpool, like we do for CoW mappings already. > > However, as the folio consumed a global reservation, it has > HPG_restore_reserve set. So restore_reserve_on_error() keeps the > reservation in the reserve map, and free_huge_folio() restores the global > reservation instead of returning it to the subpool. > > Consequently, the reservation from the subpool minimum is stuck at that > index until truncation. As vma_commit_reservation() does not charge the > hugetlb cgroup reservation, a later fault at that index will consume it > without a cgroup charge. > > Reproduced with a failing UFFDIO_COPY on a min_size=3D mount, followed by > a fault at the same index, inside a hugetlb cgroup: > > hugetlb.2MB.rsvd.current: 0 instead of 2097152 > > Let's fix it by clearing HPG_restore_reserve in shared mappings as well. > On success, adding the folio to the page cache clears the flag. > > Note that we have to clear the flag before vma_commit_reservation() > now, such that the race handling can set it again when we raced with > another reservation. > > This has low urgency, as it only affects the subpool minimum and the > hugetlb cgroup reservation accounting on min_size=3D mounts. > > Fixes: 1c5ecae3a93f ("hugetlbfs: add minimum size accounting to subpools") > Reported-by: Sashiko > Cc: stable@vger.kernel.org > Signed-off-by: David Hildenbrand (Arm) [Severity: Low] Should the Fixes: tag cite d85f69b0b533 ("mm/hugetlb: alloc_huge_page handle areas hole punched by fallocate") instead of 1c5ecae3a93f ("hugetlbfs: add minimum size accounting to subpools")? In 1c5ecae3a93f ("hugetlbfs: add minimum size accounting to subpools"), alloc_huge_page() ignored a zero return from hugepage_subpool_get_pages(), so unreserved shared faults did not consume subpool minimum reservations or set PagePrivate, and free_huge_page() always put pages to the subpool. Consuming subpool minimum reservations via gbl_chg =3D=3D 0 on unreserved shared faults was introduced in d85f69b0b533 ("mm/hugetlb: alloc_huge_page handle areas hole punched by fallocate"). Skipping hugepage_subpool_put_pages() on restore_reserve came in 0919e1b69ab4 ("hugetlbfs: on restore reserve error path retain subpool reservation"). Removing reserve-map entries in restore_reserve_on_error() when HPG_restore_reserve is clear came in 846be08578ed ("mm/hugetlb: expand restore_reserve_on_error functionality"). [ ... ] > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index fbe79ae4c0f3c..025aae6d0b72e 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c [ ... ] > @@ -3200,6 +3202,18 @@ static struct folio *__alloc_hugetlb_folio(struct = vm_area_struct *vma, > =20 > hugetlb_set_folio_subpool(folio, spool); > =20 > + /* > + * On error, let folio freeing code return the reservation to the > + * subpool, unless we consumed a reservation from the reserve map. > + * > + * In private mappings, the reserve map might not exist or already > + * account for another folio at this index. In shared mappings, > + * restore_reserve_on_error() will remove the reservation we are about > + * to add to the reserve map, unless updating the reserve map fails. > + */ > + if (map_chg !=3D MAP_CHG_REUSE) > + folio_clear_hugetlb_restore_reserve(folio); [Severity: Low] Should the HPG_restore_reserve comment in include/linux/hugetlb.h also be updated to match this change? Both Documentation/mm/hugetlbfs_reserv.rst and restore_reserve_on_error() were updated, but the comment above enum hugetlb_page_flags still limits clearing the flag to CoW mappings: include/linux/hugetlb.h (above enum hugetlb_page_flags): * HPG_restore_reserve - Set when a hugetlb page consumes a reservation at * allocation time. Cleared when page is fully instantiated. Free * routine checks flag to restore a reservation on error paths. * Cleared when allocating for a CoW mapping using a subpool * reservation, which the free routine returns to the subpool. Leaving it as-is contradicts __alloc_hugetlb_folio() and Documentation/mm/hugetlbfs_reserv.rst. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-hugetlb_fi= xes_2-v2-0-9bbeabb555d2@kernel.org?part=3D4