From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796183287; b=QPzpwIMUbJp+16/uE2U/l7OIA2HqeZ3LbCiAlWsm0uFhFhlwAvarrAwgvNAOW9q3nd1K dzdZdez7m3xNsQtVuaF7Szsk1scU4PDJP32PAR9N/raJsSxY7RD9ZaGDPq2AzykdftYwj lXJRCMoHC/6bQ2PH6caZ4wGj5hE7cg9yhtLFhT1IyzZDyrUn3SGbE36hyKzPXHbAOO5mu bkyIIoaemHoiUxvH6hfzZFpbZlZaIGyGO0M3bfcQuk7p7csn9if6CI15DGj1Kyyo6jd/a tQBnPcq7j9xBWZtCgXq4aZtXd+hlEEpWPQmR6Lm9SGL/kTQ4C3i1aJcURH8OzFKwoMA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796183287; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=GMkyDtB7RTuPJw/Q2iDW4v7xqbDNyrfmWNoO+Q2tOPQ=; b=Vwz5AejFqM3KtBr9JEkJ/R55HlVoYQ5qsJ4shkreIadyK9clLnU8SjGoQvOtPEE3vlN8 BgSIJ8ynPf4H+vd8Y5NOnhQhqqu+llReXfk/vaGKPtM34BpteXIWM5RPxl/Z4WmVUza5V h7bduMGNyCeuWyqSiBRt/0trmSLf1ECJTpij7XaJr5SBcCiCZVAlaRarsQjyv4VsAL8E5 4hH0D35DhTzu9fNUq7SXYuuVHTZdpl8QYjKqKD0M3rHGvx0CQreBpz/0DVj6SIlvTcIho igRlhrraei2w2Vq7whp1gm+Yzk7a+XKTJRs8puv/zP3yz4dEezdhoste/ey7pwx5vtQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=TqUgUQzu; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53C0E606A322 for ; Wed, 2 Dec 2026 03:48:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=TqUgUQzu Received: by smtp.kernel.org (Postfix) with ESMTPSA id C07EE1F00896; Wed, 2 Dec 2026 03:48:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796183286; bh=GMkyDtB7RTuPJw/Q2iDW4v7xqbDNyrfmWNoO+Q2tOPQ=; h=Date:To:From:In-Reply-To:References:Subject; b=TqUgUQzuOt8iTcTPbQW2w6htL4qbmNugLdGE1cXUBiGr5NiQ0yKlOX0nOAoaiWmDw teGMFnmmoW8a8r7QdfS2ZyQtCnWlwl/IzoCvpBFeusw91Hsnfbq1C7HerttmdYUjCl 5AJHVoMcJ3xoidVXhGExD3N9dxY2ttOXa1DwSSPg= Date: Tue, 01 Dec 2026 19:48:06 -0800 To: mm-commits@vger.kernel.org,ziy@nvidia.com,ying.huang@linux.alibaba.com, vivek.kasireddy@intel.com,vbabka@kernel.org,surenb@google.com, skhan@linuxfoundation.org,shy828301@gmail.com,shakeel.butt@linux.dev, sasha.levin@oracle.com,rppt@kernel.org,rientjes@google.com,riel@surriel.com, rdunlap@infradead.org,rakie.kim@sk.com,pfalcato@suse.de,osalvador@suse.de, osalvador@kernel.org,nao.horiguchi@gmail.com,muchun.song@linux.dev, mhocko@suse.cz,mhocko@suse.com,mel@csn.ul.ie,matthew.brost@intel.com, mason@kernel.org,luojiajun3@huawei.com,ljs@kernel.org, liwanp@linux.vnet.ibm.com,lihongfu@kylinos.cn,liam@infradead.org, lance.yang@linux.dev,kraxel@redhat.com,kenneth.w.chen@intel.com, kas@kernel.org,kamezawa.hiroyu@jp.fujitsu.com,jthoughton@google.com, joshua.hahnjy@gmail.com,josef@toxicpanda.com,joern@logfs.org, jinmengzhou22@gmail.com,jiaqiyan@google.com,jgg@ziepe.ca,jannh@google.com, hughd@google.com,harry@kernel.org,guillaume@morinfr.org,gourry@gourry.net, dave.mccracken@oracle.com,corbet@lwn.net,byungchul@sk.com, baolin.wang@linux.alibaba.com,apw@shadowen.org,apopple@nvidia.com, aneesh.kumar@linux.vnet.ibm.com,ak@linux.intel.com,airlied@redhat.com, agl@us.ibm.com,ackerleytng@google.com,aarcange@redhat.com,4ncienth@gmail.com, david@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261125-hugetlb_fixes_2-v1-1-db27fd2f71a8@kernel.org> References: <20261125-hugetlb_fixes_2-v1-1-db27fd2f71a8@kernel.org> Subject: [merged mm-hotfixes-stable] mm-hugetlb-charge-the-copy-made-at-fork-to-the-parent.patch removed from -mm tree Message-Id: <20261202034806.C07EE1F00896@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The quilt patch titled Subject: mm/hugetlb: charge the copy made at fork to the parent has been removed from the -mm tree. Its filename was mm-hugetlb-charge-the-copy-made-at-fork-to-the-parent.patch This patch was dropped because it was merged into the mm-hotfixes-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm ------------------------------------------------------ From: "David Hildenbrand (Arm)" Subject: mm/hugetlb: charge the copy made at fork to the parent Date: Wed, 25 Nov 2026 23:32:59 +0100 When copying page tables during fork(), the child is not yet assigned to the right memcg. When copying possibly pinned anon hugetlb folios, we must charge them to the parent's memcg, otherwise we can end up allocating more hugetlb folios than allowed. Let's fix it by charging the copy to the parent's mm, like we do when copying small folios in copy_present_page(), introducing a new helper function alloc_hugetlb_folio_for_fork(). Link: https://lore.kernel.org/20261125-hugetlb_fixes_2-v1-0-db27fd2f71a8@kernel.org Link: https://patch.msgid.link/20261125-hugetlb_fixes_2-v1-1-db27fd2f71a8@kernel.org Fixes: c2deb1356d82 ("mm/hugetlb: charge folios to the target mm's memcg") Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Andrew Morton Reported-by: Chris Mason Acked-by: Michal Hocko Tested-by: Hongfu Li Link: https://lore.kernel.org/5dc5ea66-ba09-48d3-8c72-bcc5c141b6d9@kylinos.cn Reviewed-by: Hongfu Li Reviewed-by: Muchun Song (ByteDance) Acked-by: Oscar Salvador (SUSE) Cc: Oscar Salvador Cc: Jinmeng Zhou Cc: Andrea Arcangeli Cc: Naoya Horiguchi Cc: Hugh Dickins Cc: Baolin Wang Cc: Dave Airlie Cc: Vivek Kasireddy Cc: Gerd Hoffmann Cc: Mike Rapoport Cc: Mel Gorman Cc: Dave McCracken Cc: Andy Whitcroft Cc: Adam Litke Cc: Lorenzo Stoakes Cc: Rik van Riel Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Harry Yoo Cc: Jann Horn Cc: Lance Yang Cc: James Houghton Cc: Yang Shi Cc: Suren Baghdasaryan Cc: Shakeel Butt Cc: Pedro Falcato Cc: Gregory Price Cc: Zi Yan Cc: Joshua Hahn Cc: Rakie Kim Cc: Ying Huang Cc: Matthew Brost Cc: Byungchul Park Cc: Alistair Popple Cc: Wanpeng Li Cc: Andi Kleen Cc: Kenneth W Chen Cc: David Rientjes Cc: Joern Engel Cc: Jonathan Corbet Cc: Shuah Khan Cc: Randy Dunlap Cc: Michal Hocko Cc: Aneesh Kumar K.V Cc: KAMEZAWA Hiroyuki Cc: Kiryl Shutsemau Cc: Sasha Levin Cc: Guillaume Morin Cc: Jason Gunthorpe Cc: luojiajun Cc: Josef Bacik Cc: Daehyeon Ko <4ncienth@gmail.com> Cc: Ackerley Tng Cc: Jiaqi Yan mm/hugetlb.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) --- a/mm/hugetlb.c~mm-hugetlb-charge-the-copy-made-at-fork-to-the-parent +++ a/mm/hugetlb.c @@ -3005,8 +3005,9 @@ typedef enum { * allocation). New call sites should (probably) never set it to true!! * When it's set, the allocation will bypass all vma level reservations. */ -struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, - unsigned long addr, bool cow_from_owner) +static struct folio *__alloc_hugetlb_folio(struct vm_area_struct *vma, + unsigned long addr, bool cow_from_owner, + struct mm_struct *memcg_mm) { struct hugepage_subpool *spool = subpool_vma(vma); struct hstate *h = hstate_vma(vma); @@ -3089,7 +3090,7 @@ struct folio *alloc_hugetlb_folio(struct .nodemask = nodemask, }; - folio = hugetlb_alloc_folio(h, &mpoli, vma->vm_mm, alloc_flags); + folio = hugetlb_alloc_folio(h, &mpoli, memcg_mm, alloc_flags); mpol_cond_put(mpol); @@ -3143,6 +3144,23 @@ out_end_reservation: return ERR_PTR(ret); } +struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, + unsigned long addr, bool cow_from_owner) +{ + return __alloc_hugetlb_folio(vma, addr, cow_from_owner, vma->vm_mm); +} + +/* + * Allocate a folio for a copy in the child VMA during fork(), charged to the + * parent's mm: the child is not in its memory cgroup yet. + */ +static struct folio *alloc_hugetlb_folio_for_fork(struct vm_area_struct *dst_vma, + unsigned long addr, struct mm_struct *src_mm) +{ + return __alloc_hugetlb_folio(dst_vma, addr, /* cow_from_owner = */ false, + src_mm); +} + static __init void *alloc_bootmem(struct hstate *h, int nid, bool node_exact) { if (hugetlb_early_cma(h)) @@ -5081,7 +5099,7 @@ again: spin_unlock(src_ptl); spin_unlock(dst_ptl); /* Do not use reserve as it's private owned */ - new_folio = alloc_hugetlb_folio(dst_vma, addr, false); + new_folio = alloc_hugetlb_folio_for_fork(dst_vma, addr, src); if (IS_ERR(new_folio)) { folio_put(pte_folio); ret = PTR_ERR(new_folio); _ Patches currently in -mm which might be from david@kernel.org are mm-mprotect-dont-skip-uffd-marker-install-when-racing-with-pte-table-reclaim.patch mm-userfaultfd-prevent-poison-marker-loss.patch mm-hugetlb-compare-against-persistent-count-when-freeing-lowmem-folios.patch mm-hugetlb-preserve-reservations-when-shrinking-on-highmem.patch mm-hugetlb-account-temporary-folios-separately.patch mm-hugetlb-account-temporary-folios-separately-fix.patch mm-hugetlb-serialize-page-cache-allocations-with-truncation.patch mm-hugetlb-serialize-page-cache-allocations-with-truncation-fix.patch mm-memfd-recheck-the-page-cache-before-allocating-a-hugetlb-folio.patch mm-hugetlb-count-again-if-the-reserve-map-shrank.patch mm-hugetlb-account-restored-reservations-before-freeing-folios.patch mm-hugetlb-delay-anon-folio-rmap-removal-until-after-the-tlb-flush.patch mm-userfaultfd-reject-dax-mappings.patch mm-hugetlb-always-mark-new-page-cache-folios-migratable.patch mm-memfd-mark-new-hugetlb-folios-migratable.patch mm-hugetlb-free-surplus-folios-of-other-nodes-on-free.patch hugetlbfs-dont-zero-poisoned-pages-in-a-hole-punch.patch mm-hugetlb-only-check-pmd-table-sharing-for-pmd-sized-folios.patch mm-migrate-check-hugetlb-pmd-sharing-in-move_pages.patch mm-hugetlb-dont-share-page-tables-of-a-vma-during-mprotect.patch mm-hugetlb-count-migration-entries-at-fork-and-unmap.patch mm-hugetlb-stop-accounting-hugetlbpages-once-pmd-tables-were-shared.patch fs-proc-task_mmu-dont-clear-vm_softdirty-on-hugetlb-vmas.patch rfc-mm-hugetlb_cgroup-charge-faults-to-mm-owner.patch mm-filemap-avoid-retrying-faults-on-uffd-wp-markers.patch