From nobody Thu Dec 18 23:24:43 2025 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (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 A86892EBBBC for ; Tue, 16 Dec 2025 21:57:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.177.32 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765922242; cv=none; b=hoLt2MNX/voTugwhNvqH0PsDTn/DA6hea3GMKZORmhklaoQopp5fCmFnjDYY3HAKlA+TLlJ0LGWm22fp3wbbun36kpkOxVfTK7h7pDCa+208z7sA8g0Ran5K3GXPWcr4SvFI2NFPJTDgWAntPuzthLnOEkFbMUJgnWOxW6PWpGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765922242; c=relaxed/simple; bh=pERUyNj3MGT0zk42UH4y3VO3bbD1SDfm8m0ODrfnH3k=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=WkRem6OyxjRSdiqgQLTqlsVjzAd1rNRGOhMUqEirRoaJxsBkkw77v3Dt0bhYTRb8Nb/AtEMrs81/BWN3IvEn9b3FNTq8uwH2YBMML9BqX9jx6+gfQXHNKWc6FeYrmGtgIReqnIdsMLVhRWGGLNHly7MoaCE3wcwFKtni5bg3i8g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=Zi9gtxwH; arc=none smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Zi9gtxwH" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 5BGKRDHt1141350; Tue, 16 Dec 2025 21:56:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=corp-2025-04-25; bh=1maYaTCzXyFDam1/GOsNUZkqL3tqT HSS7WQOdxTEj4Q=; b=Zi9gtxwH4LDls3AoMp5OULHuEzdpD3DHg8mGpnFEQscnQ 3Yx7krRxw7wQhpbSGrJZ5AahGPrm5Q3PpwrwLUwumnl71vq2gYImN1kCcZBBjneN SRgY6SkqAuxIJFqIs4rcCs1RgX39CMYUNtns2sFpF1klnJT75Uz2vhydbi9Khrft y0h1OBiU4ua/AJBBWOvcu6cxl3dhya0OKfWvOgLeideIkHvcpklIT6xY8Om4vf81 9nm3uGG+fMLefDR9zucawoBm00KDy+HYBjFclJ8AgkluYe9Ndo24N+WPdLxvML5Y /gXIdud34Tc97/Bs/UwRmx+Acxb05bgJaZEYFI7qw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4b0xx2csjv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Dec 2025 21:56:52 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5BGJjgI1029610; Tue, 16 Dec 2025 21:56:51 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4b0xkb18wv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Dec 2025 21:56:51 +0000 Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 5BGLuoSP021467; Tue, 16 Dec 2025 21:56:50 GMT Received: from brm-x62-16.us.oracle.com (brm-x62-16.us.oracle.com [10.80.150.37]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 4b0xkb18wc-1; Tue, 16 Dec 2025 21:56:50 +0000 From: Jane Chu To: muchun.song@linux.dev, osalvador@suse.de, david@kernel.org, linmiaohe@huawei.com, jiaqiyan@google.com, william.roche@oracle.com, rientjes@google.com, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com, Liam.Howlett@Oracle.com, rppt@kernel.org, surenb@google.com, mhocko@suse.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/memory-failure: fix missing ->mf_stats count in hugetlb poison Date: Tue, 16 Dec 2025 14:56:21 -0700 Message-ID: <20251216215621.920093-1-jane.chu@oracle.com> X-Mailer: git-send-email 2.43.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-12-16_02,2025-12-16_05,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2512160186 X-Authority-Analysis: v=2.4 cv=B8W0EetM c=1 sm=1 tr=0 ts=6941d5a4 cx=c_pps a=OOZaFjgC48PWsiFpTAqLcw==:117 a=OOZaFjgC48PWsiFpTAqLcw==:17 a=wP3pNCr1ah4A:10 a=VkNPw1HP01LnGYTKEx00:22 a=VwQbUJbxAAAA:8 a=yPCof4ZbAAAA:8 a=Z4_W6085pIye7jCVOdoA:9 X-Proofpoint-ORIG-GUID: NGtefr_kkv30ifT3GwXBgvOwh_KfBsfA X-Proofpoint-GUID: NGtefr_kkv30ifT3GwXBgvOwh_KfBsfA X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMjE2MDE4NiBTYWx0ZWRfX9n1/pFDsLJ9j prEil1jt21Qi2tIWRnXfL8UeKDkXCXfp2Jj/G12+xvvlMRubSaF7mwDOAu5ae6iIza28p5+DYOw YFm4FBW8zRYp5l5jP9jFmaK0wMRu4rcHbeA0L0a54RY9Pzn4auT4QvsygF2+91iKXbrIYVXvAmw foyjvw7qeSBd/as9HtLMyrJ1xmun8SO7EsVmcHRf8ZW2rvmuPKeRXIcLV+OSJ2OVx/w+T2Jjha9 vBl9F7CzyhwshUN5Wc4epUNUaBHVh7yXUC3gf8217W0uJB8kon5VVqnhx6NNoGK8r/znncT9do8 b16cvRQ9prbFBZZ/q252kt0oAMizJERfT5xT+7kWGMJZng/rRq2n0CG22kOptq8tDXsJmBm2ZFK oorFkUsHjwT+g0V6DywYWZJU7mbc/Q== Content-Type: text/plain; charset="utf-8" When a newly poisoned subpage ends up in an already poisoned hugetlb folio, 'num_poisoned_pages' is incremented, but the per node ->mf_stats is not. Fix the inconsistency by designating action_result() to update them both. Fixes: 18f41fa616ee4 ("mm: memory-failure: bump memory failure stats to pgl= ist_data") Cc: Signed-off-by: Jane Chu --- include/linux/hugetlb.h | 4 ++-- include/linux/mm.h | 4 ++-- mm/hugetlb.c | 4 ++-- mm/memory-failure.c | 22 +++++++++++++--------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 8e63e46b8e1f..2e6690c9df96 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -157,7 +157,7 @@ long hugetlb_unreserve_pages(struct inode *inode, long = start, long end, bool folio_isolate_hugetlb(struct folio *folio, struct list_head *list); int get_hwpoison_hugetlb_folio(struct folio *folio, bool *hugetlb, bool un= poison); int get_huge_page_for_hwpoison(unsigned long pfn, int flags, - bool *migratable_cleared); + bool *migratable_cleared, bool *samepg); void folio_putback_hugetlb(struct folio *folio); void move_hugetlb_state(struct folio *old_folio, struct folio *new_folio, = int reason); void hugetlb_fix_reserve_counts(struct inode *inode); @@ -420,7 +420,7 @@ static inline int get_hwpoison_hugetlb_folio(struct fol= io *folio, bool *hugetlb, } =20 static inline int get_huge_page_for_hwpoison(unsigned long pfn, int flags, - bool *migratable_cleared) + bool *migratable_cleared, bool *samepg) { return 0; } diff --git a/include/linux/mm.h b/include/linux/mm.h index 7c79b3369b82..68b1812e9c0a 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -4036,7 +4036,7 @@ extern int soft_offline_page(unsigned long pfn, int f= lags); extern const struct attribute_group memory_failure_attr_group; extern void memory_failure_queue(unsigned long pfn, int flags); extern int __get_huge_page_for_hwpoison(unsigned long pfn, int flags, - bool *migratable_cleared); + bool *migratable_cleared, bool *samepg); void num_poisoned_pages_inc(unsigned long pfn); void num_poisoned_pages_sub(unsigned long pfn, long i); #else @@ -4045,7 +4045,7 @@ static inline void memory_failure_queue(unsigned long= pfn, int flags) } =20 static inline int __get_huge_page_for_hwpoison(unsigned long pfn, int flag= s, - bool *migratable_cleared) + bool *migratable_cleared, bool *samepg) { return 0; } diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 0455119716ec..f78562a578e5 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -7818,12 +7818,12 @@ int get_hwpoison_hugetlb_folio(struct folio *folio,= bool *hugetlb, bool unpoison } =20 int get_huge_page_for_hwpoison(unsigned long pfn, int flags, - bool *migratable_cleared) + bool *migratable_cleared, bool *samepg) { int ret; =20 spin_lock_irq(&hugetlb_lock); - ret =3D __get_huge_page_for_hwpoison(pfn, flags, migratable_cleared); + ret =3D __get_huge_page_for_hwpoison(pfn, flags, migratable_cleared, same= pg); spin_unlock_irq(&hugetlb_lock); return ret; } diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 3edebb0cda30..070f43bb110a 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1873,7 +1873,8 @@ static unsigned long __folio_free_raw_hwp(struct foli= o *folio, bool move_flag) return count; } =20 -static int folio_set_hugetlb_hwpoison(struct folio *folio, struct page *pa= ge) +static int folio_set_hugetlb_hwpoison(struct folio *folio, struct page *pa= ge, + bool *samepg) { struct llist_head *head; struct raw_hwp_page *raw_hwp; @@ -1889,17 +1890,16 @@ static int folio_set_hugetlb_hwpoison(struct folio = *folio, struct page *page) return -EHWPOISON; head =3D raw_hwp_list_head(folio); llist_for_each_entry(p, head->first, node) { - if (p->page =3D=3D page) + if (p->page =3D=3D page) { + *samepg =3D true; return -EHWPOISON; + } } =20 raw_hwp =3D kmalloc(sizeof(struct raw_hwp_page), GFP_ATOMIC); if (raw_hwp) { raw_hwp->page =3D page; llist_add(&raw_hwp->node, head); - /* the first error event will be counted in action_result(). */ - if (ret) - num_poisoned_pages_inc(page_to_pfn(page)); } else { /* * Failed to save raw error info. We no longer trace all @@ -1956,7 +1956,7 @@ void folio_clear_hugetlb_hwpoison(struct folio *folio) * -EHWPOISON - the hugepage is already hwpoisoned */ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags, - bool *migratable_cleared) + bool *migratable_cleared, bool *samepg) { struct page *page =3D pfn_to_page(pfn); struct folio *folio =3D page_folio(page); @@ -1981,7 +1981,7 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, i= nt flags, goto out; } =20 - if (folio_set_hugetlb_hwpoison(folio, page)) { + if (folio_set_hugetlb_hwpoison(folio, page, samepg)) { ret =3D -EHWPOISON; goto out; } @@ -2014,11 +2014,12 @@ static int try_memory_failure_hugetlb(unsigned long= pfn, int flags, int *hugetlb struct page *p =3D pfn_to_page(pfn); struct folio *folio; unsigned long page_flags; + bool samepg =3D false; bool migratable_cleared =3D false; =20 *hugetlb =3D 1; retry: - res =3D get_huge_page_for_hwpoison(pfn, flags, &migratable_cleared); + res =3D get_huge_page_for_hwpoison(pfn, flags, &migratable_cleared, &same= pg); if (res =3D=3D 2) { /* fallback to normal page handling */ *hugetlb =3D 0; return 0; @@ -2027,7 +2028,10 @@ static int try_memory_failure_hugetlb(unsigned long = pfn, int flags, int *hugetlb folio =3D page_folio(p); res =3D kill_accessing_process(current, folio_pfn(folio), flags); } - action_result(pfn, MF_MSG_ALREADY_POISONED, MF_FAILED); + if (samepg) + action_result(pfn, MF_MSG_ALREADY_POISONED, MF_FAILED); + else + action_result(pfn, MF_MSG_HUGE, MF_FAILED); return res; } else if (res =3D=3D -EBUSY) { if (!(flags & MF_NO_RETRY)) { --=20 2.43.5