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 E887B3B47DD for ; Sat, 25 Jul 2026 16:01:08 +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=1784995273; cv=none; b=BPrGckMaNGFJOUAg/wD0gWzL9SqgB4S+lTFayPuikDeK1hu5GMOOKQ/PiaQtGBeBby3SaWrA7aoP5unL259MZt/ejyu+HX9zT4eYHtsQkntFY8S1IRS3hX9RLPki0O49YyigBTYElJeD0PZlvMQctA+AdIz7ibThjE62uZyptSE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784995273; c=relaxed/simple; bh=gIOJ6AnvD6Nc1ZfV7weuowitMStETCKYS45U/XhgEJ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ub6pHCicDRQR+O/LX8ICckCkva6n42jM+23LFhkuJzmmgsF4/Mf2Sd2TiX/tp/cok0RkKZwYcAPaU9HortddRiA6HyIqsia9c1mgPuIoeOsIolwaZJCsb+haXL0RIEr0aN/3UV19KIRfP+qGT0RQqSnibk1BM5V8MJ+pwgFHhGo= 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=BZeo0oA/; 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="BZeo0oA/" 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=w135vdZkdaB/jReXI2LYBKmUn2lW/7fw2pzK/ZW/NKc=; b=BZeo0oA/sHAwlpi6isjGgkZmCw HVAoAzoF2ZpocFJHYeg9W2cc+k39U8LHU9A21qkbSmtF5vgirOYpWROXGD3rje+H3Jot52gJyGXpO MmKVxzOwqqO+WiUJF/V/UGbrebS/RkuMK1mPEdKX9hpfb5X6VWYdLsUnNB/uh29iN/naOTbUGr1rK yoa0qjxmAy3EgdlillSyQPcN09bRWRHsrqezgj6kv5x8LvO3PWqXXGzx8xWvo+WlzJP9R+gSrMhzl xxDqSXsYKJ/9pkuNhtilTlUgwTk4scYBeY9Z9+sytuy/Q+AnUcGr3TVGvKuFDWC4+lncYAL+NQ1Ia bfORI9cg==; Received: from willy by casper.infradead.org with local (Exim 4.99.1 #2 (Red Hat Linux)) id 1wnens-00000006X7c-0anP; Sat, 25 Jul 2026 16:00:44 +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 Subject: [PATCH v5 07/12] mm: Check individual hugetlb pages for poison Date: Sat, 25 Jul 2026 17:00:35 +0100 Message-ID: <20260725160042.1557264-8-willy@infradead.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260725160042.1557264-1-willy@infradead.org> References: <20260725160042.1557264-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 So far, is_page_hwpoison() has returned true for the entire poisoned hugetlb folio, but we can usually allow access to the pages which aren't poisoned. It's slightly tricky due to not having a reference to the folio, but the hugetlb lock can save us here. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/page-flags.h | 4 +++- mm/memory-failure.c | 43 +++++++++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 4fab3fbfd430..ee026ba9b0b5 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -1094,6 +1094,8 @@ static inline bool PageHuge(const struct page *page) return folio_test_hugetlb(page_folio(page)); } +bool hugetlb_unref_page_hwpoison(const struct page *page); + /* * Check if a page is currently marked HWPoisoned. This check is best * effort only and inherently racy: there is no way to synchronize with @@ -1108,7 +1110,7 @@ static inline bool is_page_hwpoison(const struct page *page) return true; folio = page_folio(page); if (folio_test_huge_poison(folio)) - return true; + return hugetlb_unref_page_hwpoison(page); /* In case we raced with hugetlb transferring flags */ return PageHWPoison(page); } diff --git a/mm/memory-failure.c b/mm/memory-failure.c index e2f50b4aba82..32f91935b210 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1820,17 +1820,12 @@ struct hwp_page { struct page *page; }; -/* - * Check if a given @page in a hugetlb folio is HWPOISON. - */ -bool hugetlb_page_hwpoison(const struct folio *folio, const struct page *page) +static bool precise_page_poisoned(const struct folio *folio, + const struct page *page) { const struct hwp_page *p; unsigned long flags; - if (!folio_test_has_hwpoisoned(folio)) - return false; - /* * When RawHwpUnreliable is set, kernel lost track of which pages * are HWPOISON. So return as if ALL pages are HWPOISONed. @@ -1848,6 +1843,40 @@ bool hugetlb_page_hwpoison(const struct folio *folio, const struct page *page) return p != NULL; } +/* + * Check if a given @page in a hugetlb folio is HWPOISON. + */ +bool hugetlb_page_hwpoison(const struct folio *folio, const struct page *page) +{ + if (!folio_test_has_hwpoisoned(folio)) + return false; + + return precise_page_poisoned(folio, page); +} + +/* + * We have no reference on the folio containing this page. + * The hugetlb_lock keeps hugetlb folios from being freed. + */ +bool hugetlb_unref_page_hwpoison(const struct page *page) +{ + const struct folio *folio; + unsigned long flags; + bool ret; + + spin_lock_irqsave(&hugetlb_lock, flags); + folio = page_folio(page); + if (!folio_test_huge_poison(folio)) { + ret = PageHWPoison(page); + goto unlock; + } + + ret = precise_page_poisoned(folio, page); +unlock: + spin_unlock_irqrestore(&hugetlb_lock, flags); + return ret; +} + static unsigned long __folio_free_raw_hwp(struct folio *folio, bool move_flag) { struct hwp_page *p, *next; -- 2.47.3