From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout05.his.huawei.com (canpmsgout05.his.huawei.com [113.46.200.220]) (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 D10332DD5E2 for ; Tue, 16 Jun 2026 07:05:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.220 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781593550; cv=none; b=Uc5ixj3WGqmc/ReflCBI6vwYL4V9SpKSq8BGR6I0bOtHmv/9eI4ChExCmcZaSkdrxyt2/ML/O+xWo8LIBASaAf/ye5pinf1/R66RuBW8vLjkGquf9hptmslweaX+YjlY8KjErkyd2JAHrppi2kdZJzJlOuAA7aXgR8pg9cAsik4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781593550; c=relaxed/simple; bh=9D7H76Em+dL8qyRWtgNCJeHObNSzdh8+fixfJRjXT80=; h=Subject:To:CC:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=FPFYAsn8jpAImogxbbMfjxCgM5RJwDF+itDowcNwFE1S7RbiiPe53F4wN7KsC4tdGp8SGwwFE4M99PVXBi/YN8Sy0X+2NJgV1Yl5QfC5vuntZCBBaqvwgTCY2N+NvoeYEIkOBqkgP+tJhGKPvdXpZZNrZYIs2IJY9ewieJebv+s= 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=I4DRB97m; arc=none smtp.client-ip=113.46.200.220 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="I4DRB97m" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=WNjPtzx9KC92dLgZijnBG7SRb4TTuAgfrVUzfk4oV2U=; b=I4DRB97mz4RacHRN87yCxF858MQoP//c/Y5E0+Y5fSVoPR4zp0tWFn4yEafPVe3u6dJymGAvb rNzIIPMIyc/dyHt9rMS+LppuRm4wOT2ytb/vupn9jWCn7+Xp+ny1h08I0B6pGR5BYwlwelShgel 9CGD7JlKnPLKPcCkWDT8iTY= Received: from mail.maildlp.com (unknown [172.19.162.223]) by canpmsgout05.his.huawei.com (SkyGuard) with ESMTPS id 4gfd7x13z2z12LJD; Tue, 16 Jun 2026 14:56:45 +0800 (CST) Received: from dggemv705-chm.china.huawei.com (unknown [10.3.19.32]) by mail.maildlp.com (Postfix) with ESMTPS id C85A540561; Tue, 16 Jun 2026 15:05:36 +0800 (CST) Received: from kwepemq500010.china.huawei.com (7.202.194.235) by dggemv705-chm.china.huawei.com (10.3.19.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 16 Jun 2026 15:05:36 +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; Tue, 16 Jun 2026 15:05:34 +0800 Subject: Re: [PATCH v5 3/4] mm/memory-failure: skip take_page_off_buddy after dissolving HWPoison HugeTLB page To: Jiaqi Yan CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , References: <20260531055829.3636554-1-jiaqiyan@google.com> <20260531055829.3636554-4-jiaqiyan@google.com> From: Miaohe Lin Message-ID: <7439fb8b-3ca4-06b9-1e57-b4de7f76bdb4@huawei.com> Date: Tue, 16 Jun 2026 15:05:34 +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: kwepems100001.china.huawei.com (7.221.188.238) To kwepemq500010.china.huawei.com (7.202.194.235) On 2026/6/15 8:16, Jiaqi Yan wrote: > On Tue, Jun 9, 2026 at 12:21 AM Miaohe Lin wrote: >> >> On 2026/5/31 13:58, 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 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. >> >> This reminds me that hugetlb_raw_hwp_unreliable folios can be freed into buddy yet? >> Should we handle them too? > > I think we can (very likely already?) handle such > hugetlb_raw_hwp_unreliable folios by "leaking" them: neither freeing > them to the buddy allocator nor allocating them in > dequeue_hugetlb_folio_node_exact(). > >> >>> + */ >>> + if (folio_test_hugetlb_raw_hwp_unreliable(folio)) >>> + /* raw_hwp_list becomes unreliable when kmalloc() fails. */ >>> + return -ENOMEM; >> >> If folios have hugetlb_raw_hwp_unreliable set, hugetlb_update_hwpoison will return >> MF_HUGETLB_FOLIO_PRE_POISONED thus these folios cannot reach here, e.g. me_huge_page. >> The only way these folios can reach here is that they are hwpoisoned first time so >> hugetlb_update_hwpoison returns 0 even if hugetlb_raw_hwp_unreliable is set at the same > > For first time HWPoison-ed hugetlb folio, hugetlb_update_hwpoison() > still returns rc=0 when kmalloc_obj() fails. So > get_huge_page_for_hwpoison() won't override ret with rc. IOW, ret will > be MF_HUGETLB_IN_USED or MF_HUGETLB_FREED. I believe > MF_HUGETLB_IN_USED can still get into me_huge_page(). MF_HUGETLB_FREED > goes directly to __hugepage_handle_poison(). > > So my intent is to block both places from dissolve_free_hugetlb_folio(). > >> time. In that case, we can simply dissolve the hugetlb folios and then take the sole hwpoisoned >> @page off buddy? But this might not be a good idea as it is really fragile... > > I think it is fragile too, and would prefer the leaking approach. > What's your thoughts? It's very rare to fail allocating memory for struct raw_hwp_page, because it's only a few tens of bytes. So I think leaking approach might be acceptable. Thanks. .