From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout10.his.huawei.com (canpmsgout10.his.huawei.com [113.46.200.225]) (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 A5ED33B42E8 for ; Mon, 17 Aug 2026 07:23:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.225 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786951436; cv=none; b=N0Ui1TmlNPXs1IQJaGcZlh9Ekp7Zs7lQ1yTdHH2rFHZpY2W6Wt1xW8ne0o4/T1n/0zwAKHAjoGd/YZ3O9TgVujuYVqkEAIjaj0S2+Qen0gFCMt5GNe+VOhqwrdRcxQOkNr5JJyDjtjTIgmlmutDlg3c13F7kJOfqg6u0SkDpVlw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786951436; c=relaxed/simple; bh=Xz0XDa5SEaVhS2YYFSGxMN2zbWidjcKDS5X7Eaw2SZQ=; h=Subject:To:CC:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=VFSUHSFMis27vtzvtGKvjJzVkxa8tJsdJj+F46ppEET6aDAYxtoW+FQTm/i4NzS9jTBNWtg7WUTzv1Ja3JaYBzFo1EvuzNlHom9P5xCSyYa9HEh7ouGAM8IyWieQfVaZMXWROmA3aPY2XTIPlg87qsv8h3Ba8ioxAATwNFqoqKI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=wy+zW023; arc=none smtp.client-ip=113.46.200.225 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="wy+zW023" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=xWH1usVd09PJQj81vk8s/B/+j0Sidd2Zk//Vvn6sQZ4=; b=wy+zW023oSvdOVx4ltYTaTj8lkFakmRbbBhviqWbUpQAMo98lxlh4E1MpCufTIRhmIRvZj/d4 OjShh521fG1l5gF7ZO8bMEkRsH1Vobk/5/cBHepCZNiqkxE08p2/gANFTF5LKgBWbknAgyK9yQI UYmU/7rC4SU8U9uazlVYwU0= Received: from mail.maildlp.com (unknown [172.19.163.15]) by canpmsgout10.his.huawei.com (SkyGuard) with ESMTPS id 4hNkZB5hLGz1K98V; Mon, 17 Aug 2026 15:13:06 +0800 (CST) Received: from dggemv712-chm.china.huawei.com (unknown [10.1.198.32]) by mail.maildlp.com (Postfix) with ESMTPS id E217740578; Mon, 17 Aug 2026 15:23:46 +0800 (CST) Received: from kwepemq500010.china.huawei.com (7.202.194.235) by dggemv712-chm.china.huawei.com (10.1.198.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 17 Aug 2026 15:23:46 +0800 Received: from [10.173.124.160] (10.173.124.160) by kwepemq500010.china.huawei.com (7.202.194.235) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 17 Aug 2026 15:23:45 +0800 Subject: Re: [PATCH v6 4/5] mm/memory-failure: skip take_page_off_buddy after dissolving HWPoison HugeTLB page To: Jiaqi Yan CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , References: <20260705180714.3708947-1-jiaqiyan@google.com> <20260705180714.3708947-5-jiaqiyan@google.com> From: Miaohe Lin Message-ID: Date: Mon, 17 Aug 2026 15:23:44 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To kwepemq500010.china.huawei.com (7.202.194.235) On 2026/8/17 8:29, Jiaqi Yan wrote: > On Fri, Jul 17, 2026 at 12:37 AM Miaohe Lin wrote: >> >> On 2026/7/6 2:07, Jiaqi Yan wrote: >>> 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; >> >> There are some branches in __update_and_free_hugetlb_folio that will leave hugetlb >> folio untouched: >> >> static void __update_and_free_hugetlb_folio(struct hstate *h, >> struct folio *folio) >> { >> bool clear_flag = folio_test_hugetlb_vmemmap_optimized(folio); >> >> if (hstate_is_gigantic_no_runtime(h)) >> return;<-- 1 > > Thanks for catching this, Miaohe. > > I think the most challenging part is that > update_and_free_hugetlb_folio() must support deferring freeing (via > schedule_work()), so adding a return value isn't that straightforward > without some refactoring... > > If making __hugepage_handle_poison() check > hstate_is_gigantic_no_runtime() == 0 (or > gigantic_page_runtime_supported() == 1) isn't an absurd idea, we can I'm afraid this might not be a good idea. Maybe we could re-check page state after calling dissolve_free_hugetlb_folio? > just do that and avoid adding return value to > __update_and_free_hugetlb_folio(). > >> >> /* >> * If we don't know which subpages are hwpoisoned, we can't free >> * the hugepage, so it's leaked intentionally. >> */ >> if (folio_test_hugetlb_raw_hwp_unreliable(folio)) >> return;<-- 2 > > __hugepage_handle_poison() already checked this, and with mf_mutex no > one can set raw_hwp_unreliable. Agreed. > >> >> /* >> * If folio is not vmemmap optimized (!clear_flag), then the folio >> * is no longer identified as a hugetlb page. hugetlb_vmemmap_restore_folio >> * can only be passed hugetlb pages and will BUG otherwise. >> */ >> if (clear_flag && hugetlb_vmemmap_restore_folio(h, folio)) { >> spin_lock_irq(&hugetlb_lock); >> /* >> * If we cannot allocate vmemmap pages, just refuse to free the >> * page and put the page back on the hugetlb free list and treat >> * as a surplus page. >> */ >> add_hugetlb_folio(h, folio, true); >> spin_unlock_irq(&hugetlb_lock); >> return;<-- 3 > > __hugepage_handle_poison() should not get into this if-block because > dissolve_free_hugetlb_folio() must have > hugetlb_vmemmap_restore_folio()-ed successfully, so clear_flag must be > false here. Otherwise dissolve_free_hugetlb_folio() already returns > early without update_and_free_hugetlb_folio(). Agreed. Thanks. .