From mboxrd@z Thu Jan 1 00:00:00 1970 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 7C8F0377EC5 for ; Sun, 5 Jul 2026 18:07:21 +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=1783274842; cv=none; b=DM7xqgtexQBcgf0GVTlASHKFaliDAvzakEyfskYi8JirrKEHFUkv4Pu0BiE1/EAWNGD0sdHIxaEA0JVtEW8MsWpjAabendXaNcvq7Nd9aryZ4MU6J8zGXsznmepE0UDToHQmnPXRFzUWR74OjQIWkw9VOX2NtnTsJZYsKJg8Lnw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783274842; c=relaxed/simple; bh=mU1ngYlbE0fj/yEk7qXA26hIpj4sf/dD8T1aN6cf3ag=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JFI22ImyM4su4R+U2CrYaeXM5Dpzfhc+Jo0XTDY/6o0XLWqwekYnp6YzJu7kIqB/aMypZq/fgSnlJFM4cVDodXqG2eW4eSob0uUxCJtx70DwozsXw1jku9t8KjVu+ywEls0OQDD602cAmfF8wsgTQXf03fN4BKJld52eA3oPtqs= 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=RDKRMVjE; 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="RDKRMVjE" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-8478ff5d801so4121219b3a.2 for ; Sun, 05 Jul 2026 11:07:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783274841; x=1783879641; 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=ocGv2/ydC5mD1rUx0KODf5OBUXgAG7lxLgoXanxhcGo=; b=RDKRMVjEL7i340g2+xkgJFdQbutLWXuSCj4rZit1yxldlLAqPkWdK359D2LKf53rvb 6AOpkY7yic346rFuhpc946t+9aUsvmJ+HBZhh7ZlcAQuoyW07/qMHpLwKKPLztysDLJW cjAfl2WxPa0IIvUMJJ8mDU7fYHbqsSJPqCT3RXjhZ8QcZ5cNNx2tO7NZgOimzZtwKz+J czZfp9x/PHgXxXLOwSYARG/f6i2jKqskoo6oVcTU7gkw/S//5BN2MKez4fkaNIEjMWia j3jTwig22I2LJDFJFaVpp7H6fqdLICPzvAkOARLCox9ihqveInefezyz6ImOAknB+exq Rvrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783274841; x=1783879641; 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=ocGv2/ydC5mD1rUx0KODf5OBUXgAG7lxLgoXanxhcGo=; b=l0eGg6TKgaZTH9C5XHA6YZP+Lia4k9lLqSfrzw0qTIkOvv0cRE8sLPtLdLo0ZoJ9eE huh0HNo0W4LQBrkc8YEPs5FK9P+SKwhpBwNf/Ufq8mz4q3sTjl8JgDR18qUTRy/RMCdC TTaxKM2hIcyYpUaqfV7lMUtothqXPKLz1aTx4pRq133cbWlVFdG9S7C6TArQEdvYblkD MTGNOXZyb5J6mJ1/Ezzw8yb3IMqOXQokareVvncWP50vV+qnwjbHlTlQNYel7Yiyn1z/ XIE7GH1hmYDYWtNuJfPQnVAqPTbdT4UrYJ9EJtlRdZUpUtn+V5rynUnVpBwc5UkLaZ35 XeJg== X-Forwarded-Encrypted: i=1; AHgh+RqyA8lT2BOudjnkoqGp5Tr77uOxtSmKhwXRMvFbIv836Wi/RN2v+q2AG3Bn887C3GuMBqxLLOrqyejK2u0=@vger.kernel.org X-Gm-Message-State: AOJu0Yyq2ywVkLcp3IKpT+pkwg+sLvTSmVY7HBXsUHCkCRktTnNJIxhj 4daaMeVJuLxjKM6hSc32Gjz/yu68LiP90sHTxzWZGVCjns9gxQZiYT7GHqRLn+Ly3dHAJq2zOYr 7sDwNqSKfZSjTsw== X-Received: from pfbei38.prod.google.com ([2002:a05:6a00:80e6:b0:847:7a66:88f3]) (user=jiaqiyan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3395:b0:847:9226:e7be with SMTP id d2e1a72fcca58-847f6b5963dmr7532154b3a.0.1783274840178; Sun, 05 Jul 2026 11:07:20 -0700 (PDT) Date: Sun, 5 Jul 2026 18:07:13 +0000 In-Reply-To: <20260705180714.3708947-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: <20260705180714.3708947-1-jiaqiyan@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260705180714.3708947-5-jiaqiyan@google.com> Subject: [PATCH v6 4/5] mm/memory-failure: skip take_page_off_buddy after dissolving HWPoison HugeTLB page From: Jiaqi Yan To: linmiaohe@huawei.com, ljs@kernel.org, ziy@nvidia.com, vbabka@kernel.org Cc: osalvador@kernel.org, harry.yoo@oracle.com, willy@infradead.org, osalvador@suse.de, 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 3d15b4c1b694..a37b67550718 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -174,6 +174,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); + + /* + * Can't use dissolve_free_hugetlb_folio() without a reliable + * raw_hwp_list telling which subpage is HWPoison. So do not free + * them to the buddy allocator. dequeue_hugetlb_folio_node_exact() + * will ensure to never re-allocate this hugepage. + */ + 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; } } @@ -2133,11 +2157,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.55.0.rc0.799.gd6f94ed593-goog