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 2BBD3606A322 for ; Sat, 5 Dec 2026 01:56:10 +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=EbiyAZcD Received: by kanga.kvack.org (Postfix) id 50E586B05B8; Fri, 4 Dec 2026 20:56:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 498E96B05B9; Fri, 4 Dec 2026 20:56:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D5FE6B05BA; Fri, 4 Dec 2026 20:56:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1493A6B05B8 for ; Fri, 4 Dec 2026 20:56:09 -0500 (EST) Received: from smtpin07.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A2874C06B1 for ; Sat, 5 Dec 2026 01:56:08 +0000 (UTC) X-FDA: 85508264016.07.5D74918 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf16.hostedemail.com (Postfix) with ESMTP id 10DB7180003 for ; Sat, 5 Dec 2026 01:56:06 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=EbiyAZcD; spf=pass (imf16.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 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=1796435767; b=E2J15AJI14AL2zCq8nBeXyGJJXOIF6y+QWeDW6bi22cX/c6JeEZlNZaxacAbBZ3fbb0Qvi mlOB54opjQcTzx1TwBmGbRzrPBka7Onl+hPYiNi5Cn/EKkL7EhTWnPysEsm/g80X/bF6HH C8DJn98jfpXEdQd0UQ09oBqob4312nM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796435767; 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=rdooerMe3l2sD96cMQ4L2cn0Iz30VF10PfWJ8Xfysp8=; b=up/cnUIz4YckXa8vvW4zcuyARkhyAYjqR73tX/GEwXU58h5Yg8rP4uNudMqneZKzNsaPPO aKceH4V0sjWtzhipznV9sh4DKy3Su9XKiN5gYef0a0qI58pNfQni+yqh+C5yQjmF1ieL0V lnFYs9u8qr4g7BlPZCmAwdfnROS6Vl4= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=EbiyAZcD; spf=pass (imf16.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 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 tor.source.kernel.org (Postfix) with ESMTP id 0F4B2608FA; Sat, 5 Dec 2026 01:56:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A07D1F0092B; Sat, 5 Dec 2026 01:56:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796435765; bh=rdooerMe3l2sD96cMQ4L2cn0Iz30VF10PfWJ8Xfysp8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=EbiyAZcDm0xY+kbauTTj/ROb/ElS7CZunbPiNXgGqE2BStxSTOfMZ0GnVEPgZ9YKZ 7L7OqqiRQgYDGS4ZNTZEALl1lv3EPwNc++K+QLD3E8QAatgngMdjtjXlBcD0ofvy8H ILia332hLIpinIHJ4pj0Mz9//YOgIJiSsWqSWnw4WfS2Vj1QqGEa/O7zg8K49AbrAz iNRs9nOETB5c2eMgKKMGoIIhTwu9NjSquTmtgVgLWGKxILBkWWA/yQvfe541gtlrvm eIP6Ljl7C0cit5FBc1SArjxIMLBbCHrR7VanG4+44dW5HydvelxKpgN3PgDt7zmfcX dLx/C7QL3pMhA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] mm/hugetlb_vmemmap: fix HWPoison race during vmemmap restore Reply-To: sashiko-reviews@lists.linux.dev To: "Muchun Song" , "Oscar Salvador" , "Andrew Morton" , "Miaohe Lin" , "Mike Rapoport" Cc: "Muchun Song" , "David Hildenbrand" , "Naoya Horiguchi" , "Joao Martins" , linux-mm@kvack.org In-Reply-To: <20261205013246.18791-1-songmuchun@bytedance.com> References: <20261205013246.18791-1-songmuchun@bytedance.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 01:56:04 +0000 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 10DB7180003 X-Rspam-User: X-Stat-Signature: icwgnxbntpqrarp3kbh3rpankn5gwxny X-Spam-Status: No, score=-11.1 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: 1796435766-352293 X-HE-Meta: U2FsdGVkX18ex3XcejqlNYVc8LTjByIUDoccszR68qlMzOx57qihZ1QNrlqIY99htyTtVW6/5futG2T/rkYiHcpJdEweScHEqOAJ9KtLMd7byAky6RmebGpwhng2hjQO+X5bDS8kEYYlsupjaAWTlEYlPqfXXNx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8yI1b7F2njkDAPXIEZKWI90oTi4KwjjktT5dECR8xmY+1RIOw15nLK2Mu90SebaYepZOnU37SEzGxWRfcfyciGfM2KUXU1Mr3w00XTukfx6MfGl5GgMvnbsS4sYBNXNLwJGYOLMgS1nDeqATG6dQrrEwO3FADXy+8sL8xiqyqejHYnz1Wbf7n6+VmNKjUQoaFmzHC2RqCf+HjImbqepZIg88KDptHdNN3qV1/p/CPSvXu5s4+yfwNX9kQaKvvqe2x0R272NWVjIXUM334M60bEwkC7/oWAltImmh8hN74zTyD4Nccyk0q4kBByywQZtuFPVkua5ujoIdJD92K3aiioyHXepVr/pROXyFuL15buF84UIT//I1YpcGLz3i3aKk9d3Ij2vUe68r8NyE3LLhEhF4+62doNfaP5xwsnxPY1djLd2RNihpv/xhOIGCfaGjMjZeZrYhUuw9bJgWNUe6e4VHGNdhSdQpHrU5ES8eBpsZusBfSBHxb7LD/C6hU73/6wsDAXO2VyX9gpVJ3WgeSoEkQVdPjQST+VKySacMm4sYHfqxShqs+x20D3gXztkE2w+HqOaUYYxOpYkxGqPERHdCFsleP8xfAGhDtpB+VyHgkO+6UxYog34kmfZNirBC4q1rGcnuilZCrS9XG/PNz/2nVG10sq9iaS8dvHKKoYumUQVtGdgOBO2p1OkjCk+g== 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_vmemmap: vmemmap_remap_rwsem held across restore allocs - [Low] mm/hugetlb_vmemmap: commit message reverses race ordering vs. code and diagram -- commit 8481ae594b618f95f12ceb1cd57476e303d9ea76 Author: Muchun Song mm/hugetlb_vmemmap: fix HWPoison race during vmemmap restore This commit moves vmemmap_remap_rwsem read locking from vmemmap_restore_folio() into hugetlb_vmemmap_restore_folio() and hugetlb_vmemmap_restore_folios() so it stays held through the final TLB flush, and takes vmemmap_remap_rwsem for write around folio_clear_hugetlb_hwpoison() in try_memory_failure_hugetlb(). > A free folio can be selected for the batch before memory failure marks it > HWPoison. If hwpoison_filter() later rejects the event after restore has > cleared HPG_vmemmap_optimized but before the final TLB flush, the cleanup > path can write a raw tail page through a stale shared mapping: [Severity: Low] Does this sentence reverse the race ordering relative to the code and the diagram below it? Once remove_pool_hugetlb_folio() selects a free folio for a restore batch, remove_hugetlb_folio() clears HPG_freed under hugetlb_lock. A subsequent get_huge_page_for_hwpoison() then sees both HPG_freed and HPG_migratable clear, returns MF_HUGETLB_RETRY, and never reaches hwpoison_filter(). To hit the race, memory failure must run first while HPG_freed is still set and mark the folio HWPoison, before the folio is selected for the restore batch. > diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c > index 336b1405cd6a3..18b9ad149347b 100644 > --- a/mm/hugetlb_vmemmap.c > +++ b/mm/hugetlb_vmemmap.c [ ... ] > @@ -391,13 +394,14 @@ static int vmemmap_restore_folio(const struct folio= *folio, unsigned long flags) > int ret, nid =3D folio_nid(folio); > LIST_HEAD(vmemmap_pages); > =20 > + rwsem_assert_held(&vmemmap_remap_rwsem); > + > start +=3D VMEMMAP_OPTIMIZATION_SIZE; > ret =3D alloc_vmemmap_page_list(&vmemmap_pages, (end - start) / PAGE_SI= ZE, > nid, GFP_KERNEL); > if (ret) > return ret; > =20 > - guard(rwsem_read)(&vmemmap_remap_rwsem); > return vmemmap_restore_range(start, end, &vmemmap_pages, flags); > } > =20 > @@ -435,6 +439,7 @@ static int __hugetlb_vmemmap_restore_folio(struct fol= io *folio, unsigned long fl > */ > int hugetlb_vmemmap_restore_folio(struct folio *folio) > { > + guard(rwsem_read)(&vmemmap_remap_rwsem); > return __hugetlb_vmemmap_restore_folio(folio, 0); > } > =20 > @@ -458,6 +463,10 @@ long hugetlb_vmemmap_restore_folios(struct list_head= *folio_list, > long ret =3D 0; > unsigned long flags =3D VMEMMAP_DEFER_TLB_FLUSH; > =20 > + if (list_empty(folio_list)) > + return 0; > + > + guard(rwsem_read)(&vmemmap_remap_rwsem); > list_for_each_entry_safe(folio, t_folio, folio_list, lru) { > if (folio_test_hugetlb_vmemmap_optimized(folio)) { > ret =3D __hugetlb_vmemmap_restore_folio(folio, flags); [Severity: Medium] Can holding vmemmap_remap_rwsem across alloc_vmemmap_page_list() stall concurrent writers and block freed HVO hugepages from returning to the buddy allocator under memory pressure? Previously vmemmap_restore_folio() allocated vmemmap pages before taking the rwsem. Hoisting the lock into hugetlb_vmemmap_restore_folios() holds the global rwsem across an entire batch of GFP_KERNEL | __GFP_RETRY_MAYFAIL allocations (up to 4,095 pages per 1GB folio), which can stall in reclaim. If hugetlb_vmemmap_optimize_folios() (e.g. from set_max_huge_pages()) queues on down_write(&vmemmap_remap_rwsem) during that stall, rwsem fairness blocks subsequent readers including free_hpage_workfn(), preventing freed HVO hugepages from returning to the buddy allocator to relieve that pressure. Also, single-folio hugetlb_vmemmap_restore_folio() passes flags =3D=3D 0 and flushes the TLB synchronously before folio_clear_hugetlb_vmemmap_optimized(= ), so it does not need the rwsem across alloc_vmemmap_page_list(). Deferring folio_clear_hugetlb_vmemmap_optimized() until after flush_tlb_all= () in hugetlb_vmemmap_restore_folios(), or pre-allocating vmemmap pages outside vmemmap_remap_rwsem, would avoid holding the rwsem across reclaiming allocations. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205013246.1879= 1-1-songmuchun@bytedance.com?part=3D1