From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CDA8839EB5B for ; Fri, 10 Jul 2026 05:59:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783663177; cv=none; b=A0mFksoGca/qfei6fsBiGY++VCoRjMJmx0iZQwDffuWvsYyMldHwZQleYXtqZ2XScCTCWlFPL8VNE4bkZUMPB++DXTJ/bVC6woYlOsDE1lWqpk97vYj5ayFLXwONIev30gS/3oFiWCSg0Ew508buUobantPv1/G8Sr7l6o6gQP4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783663177; c=relaxed/simple; bh=74HpFWRFRTO3Ef08AiFl7DxF5dkmm6WMDaEm4lC7tlk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EAzFhjc6YHB06te2LwfVFmmlnyUA5UctwHywil7r3l11QXGyfF0e0cNt55hj2GcvofLwcU+5StNq/7OM0EQXEhUzGOLQ8KBrvZwixXTFo7rMdmku9WV2NK5Kdzn2QT1seEcoR/LWN1r60/wRx5hPvXu6gxEWjovRP3eNzXKeVng= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=m8MH6uHr; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="m8MH6uHr" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2D7721E7D; Thu, 9 Jul 2026 22:59:26 -0700 (PDT) Received: from cesw-amp-gbt-1s-m12830-01.blr.arm.com (cesw-amp-gbt-1s-m12830-01.blr.arm.com [10.164.195.33]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2BE9B3F85F; Thu, 9 Jul 2026 22:59:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1783663170; bh=74HpFWRFRTO3Ef08AiFl7DxF5dkmm6WMDaEm4lC7tlk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m8MH6uHr6tfyXXYzpTwtFTbAt9HftVJg17b7MOHYYx5/i1m3s5xfWGbo6deU1DvSF 0rceOxATmMECerhpnDm+D3ndcUnsYHzacEUENhw9iqNQK1Ky3d7EVpDf5ij2y/63yz p3KD/1kdLi03SpQ1Ho1ShGAr48Kwhu0DZ74pLvwg= From: Dev Jain To: akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, muchun.song@linux.dev, osalvador@suse.de Cc: Dev Jain , riel@surriel.com, liam@infradead.org, vbabka@kernel.org, harry@kernel.org, jannh@google.com, lance.yang@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, ryan.roberts@arm.com, anshuman.khandual@arm.com Subject: [PATCH v2 1/5] mm/rmap: convert page -> folio for hwpoison checks Date: Fri, 10 Jul 2026 05:59:10 +0000 Message-ID: <20260710055915.638659-2-dev.jain@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710055915.638659-1-dev.jain@arm.com> References: <20260710055915.638659-1-dev.jain@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit try_to_unmap() receives hugetlb folios only from the hwpoison path. hugetlb_update_hwpoison() sets the hugetlb folio's head-page hwpoison bit, and page_vma_mapped_walk() reports the hugetlb mapping at the head PFN, so the previous PageHWPoison(subpage) check happened to work for hugetlb. For non-hugetlb folios, unmap_poisoned_folio() currently rejects large folios before calling try_to_unmap(). Hence it is always the case that if try_to_unmap_one() handles an hwpoisoned folio, then the head page is marked with the poison bit. Therefore, convert the poisoned subpage checks to folio_test_hwpoison(). No functional change intended, except that, while at it, convert VM_BUG_* to VM_WARN_*. Acked-by: David Hildenbrand (Arm) Signed-off-by: Dev Jain --- mm/rmap.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 9939400e77c79..dbb077f8443e3 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -2122,10 +2122,11 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, bool anon = folio_test_anon(folio); /* - * The try_to_unmap() is only passed a hugetlb page - * in the case where the hugetlb page is poisoned. + * The try_to_unmap() is only passed a hugetlb folio + * in the case where the hugetlb folio contains a + * poisoned page. */ - VM_BUG_ON_PAGE(!PageHWPoison(subpage), subpage); + VM_WARN_ON_FOLIO(!folio_test_hwpoison(folio), folio); /* * huge_pmd_unshare may unmap an entire PMD page. * There is no way of knowing exactly which PMDs may @@ -2204,7 +2205,11 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, /* Update high watermark before we lower rss */ update_hiwater_rss(mm); - if (PageHWPoison(subpage) && (flags & TTU_HWPOISON)) { + /* + * With TTU_HWPOISON, we only expect small folios or hugetlb + * folios here for now. + */ + if (folio_test_hwpoison(folio) && (flags & TTU_HWPOISON)) { pteval = swp_entry_to_pte(make_hwpoison_entry(subpage)); if (folio_test_hugetlb(folio)) { hugetlb_count_sub(folio_nr_pages(folio), mm); -- 2.43.0