From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73AC7C32771 for ; Sat, 24 Sep 2022 11:43:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A09146B00B0; Sat, 24 Sep 2022 07:43:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B8906B00B1; Sat, 24 Sep 2022 07:43:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 880786B00B2; Sat, 24 Sep 2022 07:43:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 75D346B00B0 for ; Sat, 24 Sep 2022 07:43:23 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 484168086A for ; Sat, 24 Sep 2022 11:43:23 +0000 (UTC) X-FDA: 79946793486.07.356296A Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf26.hostedemail.com (Postfix) with ESMTP id 8CF81140002 for ; Sat, 24 Sep 2022 11:43:20 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MZRqt5Rb7z1P6rB; Sat, 24 Sep 2022 19:39:06 +0800 (CST) Received: from [10.174.151.185] (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 24 Sep 2022 19:43:17 +0800 Subject: Re: [PATCH v3 1/4] mm,hwpoison,hugetlb,memory_hotplug: hotremove memory section with hwpoisoned hugepage To: Naoya Horiguchi , CC: Andrew Morton , David Hildenbrand , Mike Kravetz , Yang Shi , Oscar Salvador , Muchun Song , Jane Chu , Naoya Horiguchi , References: <20220921091359.25889-1-naoya.horiguchi@linux.dev> <20220921091359.25889-2-naoya.horiguchi@linux.dev> From: Miaohe Lin Message-ID: <91a4759f-88e4-f9ac-aff5-41d2db5ecfdd@huawei.com> Date: Sat, 24 Sep 2022 19:43:16 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20220921091359.25889-2-naoya.horiguchi@linux.dev> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664019803; a=rsa-sha256; cv=none; b=k8HDHGSAB8Q9f7SWufMU2ZC08xVrHCNyG84ezZrm3VjYM+M5T+VngXO6dDh71koErQJkoc 4iuIYszC8AMIP0KrDEnpgZ471r5fjBK8VtnJTLQyH4Eei2BYrf0HobvxRVCB7MMBgEI+63 bI8R+YR/1MmSIlenNP/5GLKtgOF9jQE= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf26.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664019803; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X7xATbRpoZZRO+I7LgxgnlgeFUr7sNyfrdV8OfdK7A0=; b=LKOw9rZjmelpKnv/ZNToGSo5d0pnOrnMYsDjvv8Z0vG63DbqcmS85pYuY0m3Od6l6IoFke tqW5p/zVoNFV2leqiJHXyU0HsMGG6weD8ECydu1IDGgKeWp2D7PErFmDQ2kwXBNooC0cPE Sjh19DFqZZ9vEEK14/XAkhbLwDP9+SI= X-Rspamd-Server: rspam11 X-Rspam-User: X-Rspamd-Queue-Id: 8CF81140002 Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf26.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Stat-Signature: a3fp3muihyyak3aosdyxbahj8ieyabq3 X-HE-Tag: 1664019800-439165 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2022/9/21 17:13, Naoya Horiguchi wrote: > From: Naoya Horiguchi > > HWPoisoned page is not supposed to be accessed once marked, but currently > such accesses can happen during memory hotremove because do_migrate_range() > can be called before dissolve_free_huge_pages() is called. > > Clear HPageMigratable for hwpoisoned hugepages to prevent them from being > migrated. This should be done in hugetlb_lock to avoid race against > isolate_hugetlb(). > > get_hwpoison_huge_page() needs to have a flag to show it's called from > unpoison to take refcount of hwpoisoned hugepages, so add it. > > Reported-by: Miaohe Lin > Signed-off-by: Naoya Horiguchi Thanks for your work, Naoya. Maybe something to improve below. > --- > ChangeLog v2 -> v3 > - move to the approach of clearing HPageMigratable instead of shifting > dissolve_free_huge_pages. > --- > include/linux/hugetlb.h | 4 ++-- > mm/hugetlb.c | 4 ++-- > mm/memory-failure.c | 12 ++++++++++-- > 3 files changed, 14 insertions(+), 6 deletions(-) > > @@ -7267,7 +7267,7 @@ int get_hwpoison_huge_page(struct page *page, bool *hugetlb) > *hugetlb = true; > if (HPageFreed(page)) > ret = 0; > - else if (HPageMigratable(page)) > + else if (HPageMigratable(page) || unpoison) Is unpoison_memory() expected to restore the HPageMigratable flag as well ? > ret = get_page_unless_zero(page); > else > ret = -EBUSY; > diff --git a/mm/memory-failure.c b/mm/memory-failure.c > index 145bb561ddb3..5942e1c0407e 100644 > --- a/mm/memory-failure.c > +++ b/mm/memory-failure.c > @@ -1244,7 +1244,7 @@ static int __get_hwpoison_page(struct page *page, unsigned long flags) > int ret = 0; > bool hugetlb = false; > > - ret = get_hwpoison_huge_page(head, &hugetlb); > + ret = get_hwpoison_huge_page(head, &hugetlb, false); > if (hugetlb) > return ret; > > @@ -1334,7 +1334,7 @@ static int __get_unpoison_page(struct page *page) > int ret = 0; > bool hugetlb = false; > > - ret = get_hwpoison_huge_page(head, &hugetlb); > + ret = get_hwpoison_huge_page(head, &hugetlb, true); > if (hugetlb) > return ret; > > @@ -1815,6 +1815,13 @@ int __get_huge_page_for_hwpoison(unsigned long pfn, int flags) > goto out; > } > > + /* > + * Clearing HPageMigratable for hwpoisoned hugepages to prevent them > + * from being migrated by memory hotremove. > + */ > + if (count_increased) > + ClearHPageMigratable(head); I believe this can prevent hwpoisoned hugepages from being migrated though there still be some windows. > + > return ret; > out: > if (count_increased) > @@ -1862,6 +1869,7 @@ static int try_memory_failure_hugetlb(unsigned long pfn, int flags, int *hugetlb > > if (hwpoison_filter(p)) { > hugetlb_clear_page_hwpoison(head); > + SetHPageMigratable(head); Would we set HPageMigratable flag for free hugetlb pages here? IIUC, they're not expected to have this flag set. Thanks, Miaohe Lin > unlock_page(head); > if (res == 1) > put_page(head); >