From patchwork Sat Aug 17 08:49:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13767071 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 4B3CEC52D7F for ; Sat, 17 Aug 2024 08:54:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 235516B0290; Sat, 17 Aug 2024 04:54:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BDF86B0414; Sat, 17 Aug 2024 04:54:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 011786B02A3; Sat, 17 Aug 2024 04:54:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id CE5DB6B0290 for ; Sat, 17 Aug 2024 04:54:08 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7EF4FC0545 for ; Sat, 17 Aug 2024 08:54:08 +0000 (UTC) X-FDA: 82461125376.20.8DA8C1D Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf21.hostedemail.com (Postfix) with ESMTP id 045BA1C0002 for ; Sat, 17 Aug 2024 08:54:05 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723884771; 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=S1fVY/WKJzMRDG5Xb+nNm7fDXazsjCAm5noFkzuJuxg=; b=U1LM3eDV5iXpJPTIjtoZgDAlAaSaqbm+KlusW7Wsm5bGlJsXmjr7UQfdiElpqG/nMWlDw5 oSVikgXquzyDleN+EqcKXuSDZSUK4tHZ+rY+LUxVWlRec1FuqDUwFi+3upBtFI9d5RR39I iE7KB4MVs518Ex/qaeCxvJpsuVJm3z0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723884771; a=rsa-sha256; cv=none; b=0aUU1eeYomIwEzM1hruzeHiu72YB0/YUcNKO/uWNy6inA6zovO5ObtCfxK/kDUoHrj9WTI wzui7VA54f3RQjY/66/VHKkob2gaCpZXCXnk4y9bcH075mKj0pkFM0jUIcn4hRv1VDpwKk gOl7Nxf+XWVuZxwqgk43gy591yD3w+c= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4WmCFr3m8yz1S7qQ; Sat, 17 Aug 2024 16:49:04 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 9D7ED1A016C; Sat, 17 Aug 2024 16:54:00 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 17 Aug 2024 16:54:00 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Oscar Salvador , Miaohe Lin , Naoya Horiguchi , , Kefeng Wang Subject: [PATCH v2 3/5] mm: memory_hotplug: check hwpoisoned page firstly in do_migrate_range() Date: Sat, 17 Aug 2024 16:49:39 +0800 Message-ID: <20240817084941.2375713-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240817084941.2375713-1-wangkefeng.wang@huawei.com> References: <20240817084941.2375713-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemf100008.china.huawei.com (7.185.36.138) X-Stat-Signature: 11h1qomuqcfiahj714usfk8ob3qszoan X-Rspamd-Queue-Id: 045BA1C0002 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1723884845-900839 X-HE-Meta: U2FsdGVkX18WfqBqn6JwGfJ+nYDc3NILR4n6eNhvk5GqA13hkAKkvYl2vFChiU84uIjkFoorHM4A+iZ+kZ62SwzQsf4bhCM58UiKrBWkolS3fQWEy4o1bJdF7NWeOVSamWkfbnkFyEp+lKsL8+iuD6HDVCSDBQzjtoRBXbTiC0sgcrXEA545WB4uGPRNeBb7Wsd/NOGjSb1P+SdUhd8lRZ0vXROhqxI6vEplSGq5LvQsnZz+KzwigbbZ34QK+SaxV6Ho2kRdUbl6+NJn8TsIiqeyiJcHiMA94yMau+9oa5sKvD3f3OtB8kjswTNb/iNSD2uwkO1nfv56QqIwrLc1deHlZoadOwfUjgJP2j29r7x2tNuW9jdKk5V65plYFerE70diYRg3fN5bBiFI0c1HaXNIrQMGngBkvQ9g3X+QeOlFG6AM2BEbVXTNYWHR8tBlP6Wd10oMYxiRMQI8tsgBmmP0CdEkBJtKdLExSbn6BlfAYjXSriwaQOWgfLvvB8DxU7EI5c2umzi31ZxV7Yd0UHCW0zrMtGOWVA4nJiXLApG0Sca532dP/XDFtauiUOFZdvxFTsWt3V0C7H0VDBDD79SER1b6u7kGIREjlItkUM9FCPHbGSNQJc2VDwdn52X8KhXV/1hdPlKDTIvjILnUga6uNe1RFDHiQh6izbjKuhvKPb74+5lHhV4npSkKQihW8euCMmlEJDHYc1Yoi2288lvUUjiCwdddjbrKxN++w/e651RXa1mPp/nf2zXS94iXNiEHRydmhVavMxSrTbf6CAfcAYRyAIRWzGojFzoVzakVTNYzJOyST9WcBa/L6WCfLs7ieWbiZM07blkT+DR011ciyLsl8pjtukdIcQNHVFYZbFhEs32oNbJfWJaI6VwIPdYl4OFTWgg2IRh9YdfKT+pNdoJHBRQ+5DOf9WZb96R3bYff9oJ1gBA3o0Z5C1tk4zGOFShOJoROx57eBvQ vpT3fCuH 6KwoJbkmWnLffqxLq9N5WXgZ0QXgHVoVG+MF9C4+NiK/lTF92pOVyfWFHuTHUaqVMGmDsC6SiLnWKBgbRIWMDe9+v9dYK64XbpSYv55GS6pCBkkGDV2L2pC7Y4lERTcNF0iMWiLaZXbbCAuzAJf9sgWmsQUIaKHXax+mPaoVWYKfBEVyxlT1cvM9ZTsLDtzlsWnTEo3faq6uGRMqTEloDUeWQKhj6jI2P8Sj/EFsgOVFXu3H8/eOpuXQEndfs4YWLbGl4 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: List-Subscribe: List-Unsubscribe: The commit b15c87263a69 ("hwpoison, memory_hotplug: allow hwpoisoned pages to be offlined") don't handle the hugetlb pages, the endless loop still occur if offline a hwpoison hugetlb, luckly, with the commit e591ef7d96d6 ("mm,hwpoison,hugetlb,memory_hotplug: hotremove memory section with hwpoisoned hugepage") section with hwpoisoned hugepage"), the HPageMigratable of hugetlb page will be clear, and the hwpoison hugetlb page will be skipped in scan_movable_pages(), so the endless loop issue is fixed. However if the HPageMigratable() check passed(without reference and lock), the hugetlb page may be hwpoisoned, it won't cause issue since the hwpoisoned page will be handled correctly in the next movable pages scan loop, and it will be isolated in do_migrate_range() but fails to migrate. In order to avoid the unnecessary isolation and unify all hwpoisoned page handling, let's unconditionally check hwpoison firstly, and if it is a hwpoisoned hugetlb page, try to unmap it as the catch all safety net like normal page does. Signed-off-by: Kefeng Wang Acked-by: David Hildenbrand --- mm/memory_hotplug.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index dc19b0e28fbc..02a0d4fbc3fe 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1793,13 +1793,8 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) * but out loop could handle that as it revisits the split * folio later. */ - if (folio_test_large(folio)) { + if (folio_test_large(folio)) pfn = folio_pfn(folio) + folio_nr_pages(folio) - 1; - if (folio_test_hugetlb(folio)) { - isolate_hugetlb(folio, &source); - continue; - } - } /* * HWPoison pages have elevated reference counts so the migration would @@ -1808,11 +1803,17 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) * (e.g. current hwpoison implementation doesn't unmap KSM pages but keep * the unmap as the catch all safety net). */ - if (PageHWPoison(page)) { + if (folio_test_hwpoison(folio) || + (folio_test_large(folio) && folio_test_has_hwpoisoned(folio))) { if (WARN_ON(folio_test_lru(folio))) folio_isolate_lru(folio); if (folio_mapped(folio)) - try_to_unmap(folio, TTU_IGNORE_MLOCK); + unmap_posioned_folio(folio, TTU_IGNORE_MLOCK); + continue; + } + + if (folio_test_hugetlb(folio)) { + isolate_hugetlb(folio, &source); continue; }