Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 03E3A47CA76 for ; Wed, 5 Aug 2026 21:06:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785963988; cv=none; b=srrofxqYQfCx/tbmrmcQ/c5RExbvGvFVIRHUyEQ2fY6bjs67/YQw088ndfif66D+3tAuWladNH0Rq+BaIyKDlZG6uceeHplwmounOsCWvRR0DEDajpF8kOgk9/qNOvH0iNP5ZVdjIRfJG9+IUfpWn0aCk+JoBzobQcQwhWODhVQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785963988; c=relaxed/simple; bh=IrBQBslEq4TI7InTZCjPxz4xe2xq7SF8gREBhiZJmTU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QH9/JhD43Ges2c7b30olNkOD2a5WIr1g4TP/dNPp9s+U/j+UOoF/Q67HU3nTu/dYiRmpBY/nBhfQ0tWj7RHdma//bbNcQXNp/Koj/r7/fkgxdqsQ+y3eVts0Z265/lojtKn8T/sHNqlyYhYFcNy6YttqG3DwAr5UpfzvC4fkulE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=BNAnez1c; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="BNAnez1c" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=GltmsNqVWJkuDcD5Rt9s3dnWU67+Xt6v0JKxF0Dmboc=; b=BNAnez1c1JQkBPhIjWfh1w0M4m ObEuUjkNWKCNBdM07gsNCQ6zLVwCPgWHcLzDSn6pYTeCYZaCOCZ31LlRmBAWtPD0JC5gVmo3YYDPW mulVFEIcH5niuc+yiKKyYLCI9Qv4adeZNBoCV175nz7fGWOEJyz2td/NkikknQy7NxkSF2e9mrWxV JUGs7+yarN2fEMhfdKkh6ai3BAnfYkxCmUl9wHR5W/V3cmoWzOmhwgSn+80gKkt1HE/J2sZVMwxRi ZKHIUeuE22gz7EtRtiWZS6DW/jLlzdcIWSdM7NjwawVhnewXm8F4wX3XBS4BeQ3inAPhcV/PIzzOt 2C+24vEw==; Received: from willy by casper.infradead.org with local (Exim 4.99.1 #2 (Red Hat Linux)) id 1wrioJ-00000004h6H-46dd; Wed, 05 Aug 2026 21:06:00 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton , Jane Chu , linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Muchun Song , Oscar Salvador , David Hildenbrand , Miaohe Lin , Naoya Horiguchi , Jan Kara , linux-fsdevel@vger.kernel.org, Christian Brauner , Jiaqi Yan , "Gregory Price (Meta)" Subject: [PATCH v9 07/15] hugetlb: Move poison to pages before clearing hugetlb page type Date: Wed, 5 Aug 2026 22:05:47 +0100 Message-ID: <20260805210557.1118966-8-willy@infradead.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260805210557.1118966-1-willy@infradead.org> References: <20260805210557.1118966-1-willy@infradead.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit For is_page_hwpoison() to be reliable, we need to set the hwpoison flag on each page before clearing the hugetlb flag. Introduce folio_clear_hugetlb() to make this easier. This does not by itself make is_page_hwpoison() reliable; see subsequent patches. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Gregory Price (Meta) Reviewed-by: Miaohe Lin Reviewed-by: Jane Chu --- mm/hugetlb.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index cc8d98399913..47403d02be88 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1381,6 +1381,18 @@ static struct folio *alloc_gigantic_frozen_folio(int order, gfp_t gfp_mask, int } #endif +static void folio_clear_hugetlb(struct folio *folio) +{ + /* + * Move HWPoison flag to each error page + * which makes any healthy pages reusable. + */ + if (unlikely(folio_test_hwpoison(folio))) + folio_clear_hugetlb_hwpoison(folio); + + __folio_clear_hugetlb(folio); +} + /* * Remove hugetlb folio from lists. * If vmemmap exists for the folio, clear the hugetlb flag so that the @@ -1419,7 +1431,7 @@ void remove_hugetlb_folio(struct hstate *h, struct folio *folio, * to tail struct pages. */ if (!folio_test_hugetlb_vmemmap_optimized(folio)) - __folio_clear_hugetlb(folio); + folio_clear_hugetlb(folio); h->nr_huge_pages--; h->nr_huge_pages_node[nid]--; @@ -1493,17 +1505,10 @@ static void __update_and_free_hugetlb_folio(struct hstate *h, */ if (folio_test_hugetlb(folio)) { spin_lock_irq(&hugetlb_lock); - __folio_clear_hugetlb(folio); + folio_clear_hugetlb(folio); spin_unlock_irq(&hugetlb_lock); } - /* - * Move PageHWPoison flag from head page to the raw error pages, - * which makes any healthy subpages reusable. - */ - if (unlikely(folio_test_hwpoison(folio))) - folio_clear_hugetlb_hwpoison(folio); - VM_BUG_ON_FOLIO(folio_ref_count(folio), folio); if (folio_test_hugetlb_cma(folio)) hugetlb_cma_free_frozen_folio(folio); @@ -1595,7 +1600,7 @@ static void bulk_vmemmap_restore_error(struct hstate *h, list_for_each_entry_safe(folio, t_folio, non_hvo_folios, lru) { list_del(&folio->lru); spin_lock_irq(&hugetlb_lock); - __folio_clear_hugetlb(folio); + folio_clear_hugetlb(folio); spin_unlock_irq(&hugetlb_lock); update_and_free_hugetlb_folio(h, folio, false); cond_resched(); @@ -1620,7 +1625,7 @@ static void bulk_vmemmap_restore_error(struct hstate *h, } else { list_del(&folio->lru); spin_lock_irq(&hugetlb_lock); - __folio_clear_hugetlb(folio); + folio_clear_hugetlb(folio); spin_unlock_irq(&hugetlb_lock); update_and_free_hugetlb_folio(h, folio, false); cond_resched(); @@ -1653,14 +1658,14 @@ static void update_and_free_pages_bulk(struct hstate *h, * should only be pages on the non_hvo_folios list. * Do note that the non_hvo_folios list could be empty. * Without HVO enabled, ret will be 0 and there is no need to call - * __folio_clear_hugetlb as this was done previously. + * folio_clear_hugetlb as this was done previously. */ VM_WARN_ON(!list_empty(folio_list)); VM_WARN_ON(ret < 0); if (!list_empty(&non_hvo_folios) && ret) { spin_lock_irq(&hugetlb_lock); list_for_each_entry(folio, &non_hvo_folios, lru) - __folio_clear_hugetlb(folio); + folio_clear_hugetlb(folio); spin_unlock_irq(&hugetlb_lock); } -- 2.47.3