From mboxrd@z Thu Jan 1 00:00:00 1970 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 B984432937A for ; Sun, 31 May 2026 05:58:35 +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=1780207117; cv=none; b=QjsO2Mp9RKbZPRHZcWP3OV0a9k4XkBEnsHrXdh5Y8zb9oA2pV9P8O/9PY/5LA05eXvcxvpRf3fozIm3U01jnr1Y1RIX2qlIee7Y7qqXdLStZLrWnTma287Ywep8AicN8HcTA7sGOAiz6sj5snngiZLZDzIYSlHaSCe6dv/xyU3A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780207117; c=relaxed/simple; bh=TUvW6376g3KB8xyMm7kLmqPxUuft4wG8bsL17fT0O+M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=l/3OVkg7SdmBIXD8y8MKQABoD6ALXm0KCilF36sQAJj98Sao6aI10N7qHgMjZu+TomP23lQRJTdnJf7pyUcTDyYnw9TyJtTvF5TRVgiE1DukU9agJL3DXG/ZiJ26e+GjTy5GhuZUDbtd71CqVg9p1YhIXGgP7SypkZMK2QhrJaY= 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=i3VsqqFm; 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="i3VsqqFm" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2c0b35fa876so6520415ad.1 for ; Sat, 30 May 2026 22:58:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780207115; x=1780811915; 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=WZW1Swft1eWJtZExgmIavtPOzBDQuGx01Vq9nniKO/I=; b=i3VsqqFmN5hHYVl+92ZbEL0gubP02oFPn179MhTZoV/Z4Pjulq1tsVICRqnaUDAiaE sqgxhIqACB+oCr0nd4QdKvAtAuLTjds0GQhg24tlu+C9Dr/2fU789LnmzTU+15Lzq7+3 RHIT+FUVbVTwTZYvgLeSrv0yvQSud4Yy1riNW2FLKQx6AWj0myb5l0nu4uijXttvBhGb ivaN2bgctxN9vPT+vy659w12wwK4oqspR/HMEkq74u+U1c9fRnBVniiPmyqeZ+Bx7TJl SIa4xFkeiDKkeFAovlnJv0P1ov4DXxNhrLRvubPi7s4shPa1hwfBqp4vg0o5L50q8uqy cx9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780207115; x=1780811915; 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=WZW1Swft1eWJtZExgmIavtPOzBDQuGx01Vq9nniKO/I=; b=s/QtJbG9TsHcmdFjIRbjqinHCtBB0RIMYLEymjyFNAe3UEPTFmgLrIMP8H/Qvnxuvx aqJE89sO51O9YxGM11X4fz3KZbuCMZgTrbU0BhkgQ4vLqAJx0jham+DZu2oL0CHRfFwA gN80etNbRsz0ktVV0Gl4t7iSXBGV3HYhTln9w+jv7L2q4vjXVlvPXzEvurXMQMci++mB PMqFy0MD2wmtu/AaXK5lzyBpdfT9zFKt2cx3C9dlFMWBJoV/BVuq7NjYQxNOGM/agscK QVBr3DaDRwyt3y+0OwJihu9cyyy9tS7VrG43C4OPDTsfC6chTqVnFW1jdK5gG7Nmadqz 1rmA== X-Forwarded-Encrypted: i=1; AFNElJ+BrphWHLfbl9SPuBMYDuLVLAxPPmiuYK+YR39rD2eW9oiteig7YoNbBJVBE+1qDSZAU0DCzKfmTXR448A=@vger.kernel.org X-Gm-Message-State: AOJu0YzrsquJpNGvZhgC3TVJK4BE7vjuILsQ/lxYgLwAEItwH86HSfBn u0xNTfWGMWl2swu7R532Lj0l0v1uJhdRVp0T77T35Fd1t+FtEIxsK3/n2I7nMXV5C7e1BT6Bx+m ERk25g4vRBjMcug== X-Received: from plbkn8.prod.google.com ([2002:a17:903:788:b0:2bf:20bc:ee77]) (user=jiaqiyan job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1c6:b0:2bd:9c0a:32c with SMTP id d9443c01a7336-2bf3683b78dmr65642835ad.19.1780207114820; Sat, 30 May 2026 22:58:34 -0700 (PDT) Date: Sun, 31 May 2026 05:58:28 +0000 In-Reply-To: <20260531055829.3636554-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: <20260531055829.3636554-1-jiaqiyan@google.com> X-Mailer: git-send-email 2.54.0.823.g6e5bcc1fc9-goog Message-ID: <20260531055829.3636554-4-jiaqiyan@google.com> Subject: [PATCH v5 3/4] mm/memory-failure: skip take_page_off_buddy after dissolving HWPoison HugeTLB page From: Jiaqi Yan To: ljs@kernel.org, linmiaohe@huawei.com, osalvador@kernel.org, ziy@nvidia.com, harry.yoo@oracle.com, willy@infradead.org Cc: osalvador@suse.de, lorenzo.stoakes@oracle.com, jackmanb@google.com, hannes@cmpxchg.org, nao.horiguchi@gmail.com, david@kernel.org, william.roche@oracle.com, tony.luck@intel.com, wangkefeng.wang@huawei.com, jane.chu@oracle.com, akpm@linux-foundation.org, muchun.song@linux.dev, liam@infradead.org, rientjes@google.com, duenwen@google.com, jthoughton@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, vbabka@suse.cz, rppt@kernel.org, shuah@kernel.org, surenb@google.com, mhocko@suse.com, boudewijn@delta-utec.com, Jiaqi Yan Content-Type: text/plain; charset="UTF-8" Now that HWPoison subpage(s) within HugeTLB page will be rejected by buddy allocator during dissolve_free_hugetlb_folio(), there is no need to drain_all_pages() and take_page_off_buddy() anymore. In fact, calling take_page_off_buddy() after dissolve_free_hugetlb_folio() succeeded returns false, making caller think __page_handle_poison() failed. Add __hugepage_handle_poison() and replace __page_handle_poison() at HugeTLB specific call sites. The being handled HugeTLB page either is free at the moment of try_memory_failure_hugetlb(), or becomes free at the moment of me_huge_page(). Signed-off-by: Jiaqi Yan --- mm/memory-failure.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 95979b7995c1..098c4407e818 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -163,6 +163,30 @@ static struct rb_root_cached pfn_space_itree = RB_ROOT_CACHED; static DEFINE_MUTEX(pfn_space_lock); /* + * Only for a HugeTLB page being handled by memory_failure(). The key + * difference to soft_offline() is that, no HWPoison subpage will make + * into buddy allocator after a successful dissolve_free_hugetlb_folio(), + * so take_page_off_buddy() is unnecessary. + */ +static int __hugepage_handle_poison(struct page *page) +{ + struct folio *folio = page_folio(page); + + VM_WARN_ON_FOLIO(!folio_test_hwpoison(folio), folio); + + /* + * Can't use dissolve_free_hugetlb_folio() without a reliable + * raw_hwp_list telling which subpage is HWPoison. + */ + if (folio_test_hugetlb_raw_hwp_unreliable(folio)) + /* raw_hwp_list becomes unreliable when kmalloc() fails. */ + return -ENOMEM; + + return dissolve_free_hugetlb_folio(folio); +} + +/* + * Only for a free or HugeTLB page being handled by soft_offline(). * 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, @@ -1166,11 +1190,11 @@ static int me_huge_page(struct page_state *ps, struct page *p) * subpages. */ folio_put(folio); - if (__page_handle_poison(p) > 0) { + if (__hugepage_handle_poison(p)) { + res = MF_FAILED; + } else { page_ref_inc(p); res = MF_RECOVERED; - } else { - res = MF_FAILED; } } @@ -2076,11 +2100,11 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags) */ if (res == MF_HUGETLB_FREED) { folio_unlock(folio); - if (__page_handle_poison(p) > 0) { + if (__hugepage_handle_poison(p)) { + res = MF_FAILED; + } else { page_ref_inc(p); res = MF_RECOVERED; - } else { - res = MF_FAILED; } return action_result(pfn, MF_MSG_FREE_HUGE, res); } -- 2.54.0.823.g6e5bcc1fc9-goog