From nobody Sun Feb 8 12:14:48 2026 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C9B73112B6 for ; Fri, 19 Dec 2025 18:33:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766169242; cv=none; b=u7+upiTdJFZNVzg8AVAqBCnJ7HsNsmPjVHlUaYYUNtpXI7VA8/OhiJbXfPFMG9/STzgDwDcXlkaEO22icXfOWt1z2yg7qzDIrxMps+o8CIhZ/5eQVuhiUflSqZZwm4HZAwg1iYan37W5GJKQdMpfFjWRq1JERialg0VTXshilJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766169242; c=relaxed/simple; bh=BWDgkic12dNJE2Sx5haKSKRwhtPmZlUx/LnoS7+la7Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=a+MpzAKqt0MlIdCpHk50B5oRQewa9yxlgVWV4apWmm79vXiafhPIiKOzpZxCd65srP/eg2xwID+1u21A9z//px55kWuxtZbfdidw0JAE6bqltTsT8j5uwaWsjPisL9/Q/2cOwb6RiQGr5aZs550YWKGle3HOehhOZcDVTxqUSl4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jiaqiyan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=lM1sXFEd; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jiaqiyan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lM1sXFEd" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7ae3e3e0d06so1874742b3a.0 for ; Fri, 19 Dec 2025 10:33:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1766169239; x=1766774039; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=YytVXTz7eotBywKq0D36ojs/TyujlRl38+2Xq1D1u2Q=; b=lM1sXFEdAt3luRk31cRZzezBzsdKNBuu/knZx15YwyV97gOK/VPIkBOghyGNLpw58Q QNeijDIYAS6tRLSpS2/q6RRCNH6ErAI7QtksPxcir/1Ddvuz/FNYPEncOlbzyYuDocgF rVy9Rp5FSEewC4ScRnigiH7S4NzBrDC46aZR+OU8XmS3x9uSmTpDRTwumqhQI+9gRdfP WyVlhBScNlZA+Nrov3JPXgPifPIBRV1zItyzEQ/BY4EqGnEgcWRDY4GcH7HHPdKzelPe ktVhCYpXg0vmcUiYgSDeStYJe7uK0g6Fplh0sez3AO24SwH4LGFKE74qVDVjBj4CZV1d uVHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766169239; x=1766774039; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YytVXTz7eotBywKq0D36ojs/TyujlRl38+2Xq1D1u2Q=; b=BMDfeopRzPp3usf82WJDTS7x0ToV4O5QDn8Y+/A7xAnZJP1iRI1b4wEAP1vysFckj0 Z4s2k/Pkw6Khqof5KmGYBhAZmb8BaD5n1UpaK5WuNG9jyUj6njmw1rw28UCGfTWW26Zs 9vUi9SLv/SEdvkgfWxPCkwO0bPKh/sJXA0AXgQC85gcX9DyT3LaxAg1QoOrKC3x4VLrW Q4UG7R6bfWPnYvon1v87X4jMNT9838ztwHRAqRb5487f+4OfPGBMRePcmA+bq41mzToi TLd3B1ndH97MbAwH2Ljw/znoH6/LdBz7E5MPiJsKB9zDdZTSSIA8d0zERb/j7I+LdTZ4 PVsA== X-Forwarded-Encrypted: i=1; AJvYcCXzWMFtEpx83QIAfrHL1hvwf7Fi7MXkELd+zlfEW0Z3Otc5QiifPOCm3hNGjrSSwXWa3OufU9kUk/VbbJY=@vger.kernel.org X-Gm-Message-State: AOJu0YzIY0tVr+le5SUEQkpQRgDSob8QtwIhngGS63LjOGrqbXlq6yfn cZG8Vs5HDgwLEnTRxQn62JTe2nhH2SwBgxIkI8F8YwyZd5j5cBvzcT1Dej2KQNF/17VSr5rHvKr O9TpwmS9QpVbSuA== X-Google-Smtp-Source: AGHT+IEzOjUKHHk546qLMa+fb+TkJDXbIwoDrKmpkBwNwz83aSZlApmXkbT2tXI+flv4Y4MXC/eUiYjM/ow/+g== X-Received: from pgjz22.prod.google.com ([2002:a63:e556:0:b0:bac:6acd:818a]) (user=jiaqiyan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:9149:b0:353:110e:9b89 with SMTP id adf61e73a8af0-376a9acef57mr4054062637.49.1766169239272; Fri, 19 Dec 2025 10:33:59 -0800 (PST) Date: Fri, 19 Dec 2025 18:33:44 +0000 In-Reply-To: <20251219183346.3627510-1-jiaqiyan@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251219183346.3627510-1-jiaqiyan@google.com> X-Mailer: git-send-email 2.52.0.322.g1dd061c0dc-goog Message-ID: <20251219183346.3627510-2-jiaqiyan@google.com> Subject: [PATCH v2 1/3] mm/memory-failure: set has_hwpoisoned flags on HugeTLB folio From: Jiaqi Yan To: jackmanb@google.com, hannes@cmpxchg.org, linmiaohe@huawei.com, ziy@nvidia.com, harry.yoo@oracle.com, willy@infradead.org Cc: nao.horiguchi@gmail.com, david@redhat.com, lorenzo.stoakes@oracle.com, william.roche@oracle.com, tony.luck@intel.com, wangkefeng.wang@huawei.com, jane.chu@oracle.com, akpm@linux-foundation.org, osalvador@suse.de, muchun.song@linux.dev, rientjes@google.com, duenwen@google.com, jthoughton@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, Jiaqi Yan Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a free HWPoison HugeTLB folio is dissolved, it becomes non-HugeTLB and is released to buddy allocator as a high-order folio. Set has_hwpoisoned flags on the high-order folio so that buddy allocator can tell that it contains certain HWPoison page(s). This is a prepare change for buddy allocator to handle only the high-order HWPoison folio differently. This cannot be done with hwpoison flag because users cannot tell from the case that the page with hwpoison is hardware corrupted. Signed-off-by: Jiaqi Yan --- include/linux/page-flags.h | 2 +- mm/memory-failure.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index f7a0e4af0c734..d13835e265952 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -904,7 +904,7 @@ static inline int PageTransCompound(const struct page *= page) TESTPAGEFLAG_FALSE(TransCompound, transcompound) #endif =20 -#if defined(CONFIG_MEMORY_FAILURE) && defined(CONFIG_TRANSPARENT_HUGEPAGE) +#if defined(CONFIG_MEMORY_FAILURE) && (defined(CONFIG_TRANSPARENT_HUGEPAGE= ) || defined(CONFIG_HUGETLB_PAGE)) /* * PageHasHWPoisoned indicates that at least one subpage is hwpoisoned in = the * compound page. diff --git a/mm/memory-failure.c b/mm/memory-failure.c index fbc5a01260c89..d204de6c9792a 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1952,6 +1952,7 @@ void folio_clear_hugetlb_hwpoison(struct folio *folio) if (folio_test_hugetlb_vmemmap_optimized(folio)) return; folio_clear_hwpoison(folio); + folio_set_has_hwpoisoned(folio); folio_free_raw_hwp(folio, true); } =20 --=20 2.52.0.322.g1dd061c0dc-goog From nobody Sun Feb 8 12:14:48 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B52F51DE887 for ; Fri, 19 Dec 2025 18:34:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766169243; cv=none; b=rpje0LVqTe6JI4xlBy/YfHWWqdnFTjrQC8OB8onbAByhSG4n0LZw/BD1OBDC1iNm6bPbHU8Uh9CDzv9lFHXDi9PjPEmBxCWL/XsZ2bf5YN++OfWfQM6P1eZUd4UkB9CjPS9egjRUgX0Xaz++QfX+oZ5vUzmjjrXgqCzR8M2SAVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766169243; c=relaxed/simple; bh=u7edsxdy32kamlH2frQDPLe5h0v0WT2y/bCZCe3FPRo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PtAQRo2tGAmJXOrbfht23y8olh79Y1pesUAdhFSbXgBVI/cODN/UUyTJtnBIsypgV4p+XcdSTUQymPMM5ALMefGZQI8SNY0Yqz0z6zb9UgKtbYbNfJccN+NnoYOoZbMrXciOmg+qHIiFUti4M22k+CdZQMZhHhkPaSY1XUs3C4E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jiaqiyan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=R1c/Qb1D; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jiaqiyan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="R1c/Qb1D" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-29f27176aa7so37862745ad.2 for ; Fri, 19 Dec 2025 10:34:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1766169241; x=1766774041; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=iRw5dUG+XR6beJWQo32i4j651BpzChIFWVHC68FGfqc=; b=R1c/Qb1DQayteitsN3cflfZgWoGr4M1cC2CB/9QZgJaH7AzJ/5ET3VsZ6AglqIeM+8 yLVSwKSJBqW9zg+5dsc+BisMOpJWbFnzyDtmqINCAzsKoU7sg7Br4K7mEDtDUeuVrR+t KOH4Ei+RQz33J132AltQoWoIEDQjAKRiC9QbUId2+DNyw1rh0qdj/BzarT9DECl+4nY3 XI4Hn5eVA8xNT23idrCy0eTrVNthX45JmpHlXepsmmgIAwOpU2pFLTGtgLdJCmZX6XYH DhcOlJXrV2sGFZHiNPDL5s+wV2BM0CYSkbg9EDlGKVa3dAGKUmGmiBILFDOR5LQYxCrM oOww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766169241; x=1766774041; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iRw5dUG+XR6beJWQo32i4j651BpzChIFWVHC68FGfqc=; b=ehKyRMsloPv0lSXRg8qfALlhVScEFuH7dqL0JC+wJW+fMTbYzphwA23NGJdAGt0nqV rI4wLM0Yx0Esf9MPxQ3MB/ld01uLCVTIXH0Nr0/H4uU6VhN3gsRIR1ztARWSzqULc44f eeN2Ywu1jEsLF3vo28MtanW15dbDV6hcs6c+QLjxG2pMS6b1bKXEx3KPqd+RmJd021Mz pqcIs4bdy9/jmqUINrVfC3p65kNU5AujwBD9zJwTsa6c8O7y9ea3nWFX8Wad+erK152+ 8c0RDXzijJPSb6aUz7hKNJRiS1XcJR9QkbLwpkFHTxN+OMI+9fYOJKvDAUrJLCLUq70/ n7YA== X-Forwarded-Encrypted: i=1; AJvYcCX2ifX1n6wJOXkX6saYgIayJEq0VkBYY61bXigOCvON1I3yB3t+e2IvWxRWkMERIgv4GpuMjU+q/7xYdFY=@vger.kernel.org X-Gm-Message-State: AOJu0YwAFCr09im4dVMtAo27C2XpwOOYXjkP0vto3K3e1aWRDgBSsl6h yntrN8BBo47c5WtFfp3rMuqp2S3w6Gx3N4JM3LVDndgKtZVAxwp1USjL87ClvFGRGifql8RRia+ n2e793nX3r0hEew== X-Google-Smtp-Source: AGHT+IH20Rlx/YPAgSS/M8SOXQ64kJgEZYeGfthUqW4VqFVoXAcaf4KGIs5xUGj8Yiw5+hGunRG8Qe3zb+OVlQ== X-Received: from plbkp8.prod.google.com ([2002:a17:903:2808:b0:2a0:9afe:8253]) (user=jiaqiyan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:4405:b0:295:565b:c691 with SMTP id d9443c01a7336-2a2f22292e6mr41848565ad.17.1766169240908; Fri, 19 Dec 2025 10:34:00 -0800 (PST) Date: Fri, 19 Dec 2025 18:33:45 +0000 In-Reply-To: <20251219183346.3627510-1-jiaqiyan@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251219183346.3627510-1-jiaqiyan@google.com> X-Mailer: git-send-email 2.52.0.322.g1dd061c0dc-goog Message-ID: <20251219183346.3627510-3-jiaqiyan@google.com> Subject: [PATCH v2 2/3] mm/page_alloc: only free healthy pages in high-order HWPoison folio From: Jiaqi Yan To: jackmanb@google.com, hannes@cmpxchg.org, linmiaohe@huawei.com, ziy@nvidia.com, harry.yoo@oracle.com, willy@infradead.org Cc: nao.horiguchi@gmail.com, david@redhat.com, lorenzo.stoakes@oracle.com, william.roche@oracle.com, tony.luck@intel.com, wangkefeng.wang@huawei.com, jane.chu@oracle.com, akpm@linux-foundation.org, osalvador@suse.de, muchun.song@linux.dev, rientjes@google.com, duenwen@google.com, jthoughton@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, Jiaqi Yan Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" At the end of dissolve_free_hugetlb_folio that a free HugeTLB folio becomes non-HugeTLB, it is released to buddy allocator as a high-order folio, e.g. a folio that contains 262144 pages if the folio was a 1G HugeTLB hugepage. This is problematic if the HugeTLB hugepage contained HWPoison subpages. In that case, since buddy allocator does not check HWPoison for non-zero-order folio, the raw HWPoison page can be given out with its buddy page and be re-used by either kernel or userspace. Memory failure recovery (MFR) in kernel does attempt to take raw HWPoison page off buddy allocator after dissolve_free_hugetlb_folio. However, there is always a time window between dissolve_free_hugetlb_folio frees a HWPoison high-order folio to buddy allocator and MFR takes HWPoison raw page off buddy allocator. One obvious way to avoid this problem is to add page sanity checks in page allocate or free path. However, it is against the past efforts to reduce sanity check overhead [1,2,3]. Introduce free_has_hwpoison_pages to only free the healthy pages and excludes the HWPoison ones in the high-order folio. The idea is to iterate through the sub-pages of the folio to identify contiguous ranges of healthy pages. Instead of freeing pages one by one, decompose healthy ranges into the largest possible blocks. Each block meets the requirements to be freed to buddy allocator (__free_frozen_pages). free_has_hwpoison_pages has linear time complexity O(N) wrt the number of pages in the folio. While the power-of-two decomposition ensures that the number of calls to the buddy allocator is logarithmic for each contiguous healthy range, the mandatory linear scan of pages to identify PageHWPoison defines the overall time complexity. [1] https://lore.kernel.org/linux-mm/1460711275-1130-15-git-send-email-mgor= man@techsingularity.net/ [2] https://lore.kernel.org/linux-mm/1460711275-1130-16-git-send-email-mgor= man@techsingularity.net/ [3] https://lore.kernel.org/all/20230216095131.17336-1-vbabka@suse.cz Signed-off-by: Jiaqi Yan --- mm/page_alloc.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 822e05f1a9646..20c8862ce594e 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2976,8 +2976,109 @@ static void __free_frozen_pages(struct page *page, = unsigned int order, } } =20 +static void prepare_compound_page_to_free(struct page *new_head, + unsigned int order, + unsigned long flags) +{ + new_head->flags.f =3D flags & (~PAGE_FLAGS_CHECK_AT_FREE); + new_head->mapping =3D NULL; + new_head->private =3D 0; + + clear_compound_head(new_head); + if (order) + prep_compound_page(new_head, order); +} + +/* + * Given a range of pages physically contiguous physical, efficiently + * free them in blocks that meet __free_frozen_pages's requirements. + */ +static void free_contiguous_pages(struct page *curr, struct page *next, + unsigned long flags) +{ + unsigned int order; + unsigned int align_order; + unsigned int size_order; + unsigned long pfn; + unsigned long end_pfn =3D page_to_pfn(next); + unsigned long remaining; + + /* + * This decomposition algorithm at every iteration chooses the + * order to be the minimum of two constraints: + * - Alignment: the largest power-of-two that divides current pfn. + * - Size: the largest power-of-two that fits in the + * current remaining number of pages. + */ + while (curr < next) { + pfn =3D page_to_pfn(curr); + remaining =3D end_pfn - pfn; + + align_order =3D ffs(pfn) - 1; + size_order =3D fls_long(remaining) - 1; + order =3D min(align_order, size_order); + + prepare_compound_page_to_free(curr, order, flags); + __free_frozen_pages(curr, order, FPI_NONE); + curr +=3D (1UL << order); + } + + VM_WARN_ON(curr !=3D next); +} + +/* + * Given a high-order compound page containing certain number of HWPoison + * pages, free only the healthy ones to buddy allocator. + * + * It calls __free_frozen_pages O(2^order) times and cause nontrivial + * overhead. So only use this when compound page really contains HWPoison. + * + * This implementation doesn't work in memdesc world. + */ +static void free_has_hwpoison_pages(struct page *page, unsigned int order) +{ + struct page *curr =3D page; + struct page *end =3D page + (1 << order); + struct page *next; + unsigned long flags =3D page->flags.f; + unsigned long nr_pages; + unsigned long total_freed =3D 0; + unsigned long total_hwp =3D 0; + + VM_WARN_ON(flags & PAGE_FLAGS_CHECK_AT_FREE); + + while (curr < end) { + next =3D curr; + nr_pages =3D 0; + + while (next < end && !PageHWPoison(next)) { + ++next; + ++nr_pages; + } + + if (PageHWPoison(next)) + ++total_hwp; + + free_contiguous_pages(curr, next, flags); + + total_freed +=3D nr_pages; + curr =3D PageHWPoison(next) ? next + 1 : next; + } + + pr_info("Excluded %lu hwpoison pages from folio\n", total_hwp); + pr_info("Freed %#lx pages from folio\n", total_freed); +} + void free_frozen_pages(struct page *page, unsigned int order) { + struct folio *folio =3D page_folio(page); + + if (order > 0 && unlikely(folio_test_has_hwpoisoned(folio))) { + folio_clear_has_hwpoisoned(folio); + free_has_hwpoison_pages(page, order); + return; + } + __free_frozen_pages(page, order, FPI_NONE); } =20 --=20 2.52.0.322.g1dd061c0dc-goog From nobody Sun Feb 8 12:14:48 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55C8733D4F2 for ; Fri, 19 Dec 2025 18:34:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766169245; cv=none; b=KNIRQWovchGyMC8G1QLNi2FBPrfzGs8LhmHk9zTH2AMYAK8XaPxxe6LvJwz5HzcIV5slG8rDSFpb4GYjvSKut4qcnxYYRxDmfnCw1MeXXDp5Rv4om7t4O7Kgfo+BKTV+da0ScdC7XKaThH/cZY/VMGxbALaJJLUx/caPq+uQdYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766169245; c=relaxed/simple; bh=QrLZ8icNCwPgbzFit/hzKfnQS3FeTni6NOWImh/i+9I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=uaT4kWx63LxiOpTFZne/EMmD2TWNw4NgxWsAASND4AnLPNMfQoR/vEYp+8EOnZk2rAkzLi60MH1xjfqh/lIPB1UdwYLyyjqGzJaNNt7vayQnozNmy4KWZ62CJp1/2p+cjdB3sajUQQIPiB7NTjwDdoH7sdgZSEyx6BMJpY+mQQY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jiaqiyan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=d7N8pOVu; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jiaqiyan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="d7N8pOVu" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2a07fa318fdso34297365ad.0 for ; Fri, 19 Dec 2025 10:34:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1766169242; x=1766774042; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dexQnRTVXD+ocEkT49jxHkdd8wk4eYUcAZvG8cXVntY=; b=d7N8pOVuiPrC3lGlqpgt4njmOTgj+8ntRNt9Pw+03BgJpRM9IrvXjUGKsfjE6TvbgD 2vOtqeQ29Hd8hk74Xty4Swhlj/o1uaNDcmHdZTMaxgxYW3AVYZZ41JZK9rmk1u7SwNum 0AVMcEPzWB9PXw2/n4OS5y0NIrmLD+ZNYlVjCxZO+pbICF4ykEPd6RcPcssQ62Q6iWI8 W9MXi/H/VfwdJeeFKOrp/k+4LcpMe9zG41HNBujLL8QCZRvqJdQxuKbEv5O8EbW9SIBe z1cxPLD/QvkfPphFcWJhP8oweENFj9uYi/cfC75nuKW7D2JC/eqmrrOFAzMcZkVgDs/U AxBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766169242; x=1766774042; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dexQnRTVXD+ocEkT49jxHkdd8wk4eYUcAZvG8cXVntY=; b=KzKdnJDCKIdtEFW5Kh2RK/dTB+X49XFuMzLsbZagZbe5slq4dNHbiF2L01cerAEdyQ 0zdgA7ZxJ97IvGxRFWEB71dn/YbbaX0kVxJgvxX76vLmRK/gTeHtXFPcLmCobWkfvUNA LjbKl7yoFKvnddjguadXpnogQYAN2HBIWrxEOAIv1evK7niGv4Smy1yezSMg7wDo0q3K YGySAI2fkqu8HK1PgY/SM7kBfFs5KIT23dwuBqKbf8DrvfygyBf8nWzu2EoK1delrkzj prATKkuhkS+IOIJmbvIUi+LD3lKCzwH8b0l9710ClJwXeTyXrYtKjceKtuzU+RXdjmEp krGw== X-Forwarded-Encrypted: i=1; AJvYcCXKJCyeowroaPyWUUvDVs285sxI+MPhgdnzP0X/+g9cNvB6oRgJmq3SAVvxgavFCBkpubekyghV8JkqLtg=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1zvSRcf1DyZNS5tp69fJ34+NkW/xfUReHVsAYCQTg0sHZZE+9 SeiXhi/OufwcUgCsVgWphKUcHj0oY8IOCbYNcAOIoejrNMp1+CYAFLKPiR+uP9VzKAj0kim5jNo WJitR6nDhEAqBbg== X-Google-Smtp-Source: AGHT+IGpZ2pGRoO+xCgyW/fLk9ttUQoZ2NHr3ntaK2W3TUshAxXp/I0SeosreA/3425khqCO+Yb9NQ3gG+U3Yw== X-Received: from plbmf11.prod.google.com ([2002:a17:902:fc8b:b0:2a1:5f23:7ddd]) (user=jiaqiyan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2448:b0:2a0:b7d3:1bf4 with SMTP id d9443c01a7336-2a2f2212833mr41416655ad.5.1766169242492; Fri, 19 Dec 2025 10:34:02 -0800 (PST) Date: Fri, 19 Dec 2025 18:33:46 +0000 In-Reply-To: <20251219183346.3627510-1-jiaqiyan@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251219183346.3627510-1-jiaqiyan@google.com> X-Mailer: git-send-email 2.52.0.322.g1dd061c0dc-goog Message-ID: <20251219183346.3627510-4-jiaqiyan@google.com> Subject: [PATCH v2 3/3] mm/memory-failure: simplify __page_handle_poison From: Jiaqi Yan To: jackmanb@google.com, hannes@cmpxchg.org, linmiaohe@huawei.com, ziy@nvidia.com, harry.yoo@oracle.com, willy@infradead.org Cc: nao.horiguchi@gmail.com, david@redhat.com, lorenzo.stoakes@oracle.com, william.roche@oracle.com, tony.luck@intel.com, wangkefeng.wang@huawei.com, jane.chu@oracle.com, akpm@linux-foundation.org, osalvador@suse.de, muchun.song@linux.dev, rientjes@google.com, duenwen@google.com, jthoughton@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, Jiaqi Yan Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that no HWPoison page will be given away to buddy allocator at the end of dissolve_free_hugetlb_folio, there is no need to drain_all_pages and take_page_off_buddy anymore, so remove them. Also make __page_handle_poison return either 0 for success or negative for failure, following the convention for functions that perform an action. Signed-off-by: Jiaqi Yan --- mm/memory-failure.c | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index d204de6c9792a..54ea840ded162 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -164,33 +164,12 @@ static DEFINE_MUTEX(pfn_space_lock); =20 /* * Return values: - * 1: the page is dissolved (if needed) and taken off from buddy, - * 0: the page is dissolved (if needed) and not taken off from buddy, + * =3D 0: the page is dissolved (if needed) * < 0: failed to dissolve. */ static int __page_handle_poison(struct page *page) { - int ret; - - /* - * zone_pcp_disable() can't be used here. It will - * hold pcp_batch_high_lock and dissolve_free_hugetlb_folio() might hold - * cpu_hotplug_lock via static_key_slow_dec() when hugetlb vmemmap - * optimization is enabled. This will break current lock dependency - * chain and leads to deadlock. - * Disabling pcp before dissolving the page was a deterministic - * approach because we made sure that those pages cannot end up in any - * PCP list. Draining PCP lists expels those pages to the buddy system, - * but nothing guarantees that those pages do not get back to a PCP - * queue if we need to refill those. - */ - ret =3D dissolve_free_hugetlb_folio(page_folio(page)); - if (!ret) { - drain_all_pages(page_zone(page)); - ret =3D take_page_off_buddy(page); - } - - return ret; + return dissolve_free_hugetlb_folio(page_folio(page)); } =20 static bool page_handle_poison(struct page *page, bool hugepage_or_freepag= e, bool release) @@ -200,7 +179,7 @@ static bool page_handle_poison(struct page *page, bool = hugepage_or_freepage, boo * Doing this check for free pages is also fine since * dissolve_free_hugetlb_folio() returns 0 for non-hugetlb folios as wel= l. */ - if (__page_handle_poison(page) <=3D 0) + if (__page_handle_poison(page) < 0) /* * We could fail to take off the target page from buddy * for example due to racy page allocation, but that's @@ -1174,7 +1153,7 @@ static int me_huge_page(struct page_state *ps, struct= page *p) * subpages. */ folio_put(folio); - if (__page_handle_poison(p) > 0) { + if (!__page_handle_poison(p)) { page_ref_inc(p); res =3D MF_RECOVERED; } else { @@ -2067,7 +2046,7 @@ static int try_memory_failure_hugetlb(unsigned long p= fn, int flags, int *hugetlb */ if (res =3D=3D 0) { folio_unlock(folio); - if (__page_handle_poison(p) > 0) { + if (!__page_handle_poison(p)) { page_ref_inc(p); res =3D MF_RECOVERED; } else { --=20 2.52.0.322.g1dd061c0dc-goog