From patchwork Tue Aug 27 11:47:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13779373 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 693C9C54736 for ; Tue, 27 Aug 2024 11:47:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA6EC6B0096; Tue, 27 Aug 2024 07:47:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E86D6B0098; Tue, 27 Aug 2024 07:47:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EB836B0096; Tue, 27 Aug 2024 07:47:44 -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 5E9F06B0093 for ; Tue, 27 Aug 2024 07:47:44 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0B120121836 for ; Tue, 27 Aug 2024 11:47:44 +0000 (UTC) X-FDA: 82497850848.22.7623A45 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf26.hostedemail.com (Postfix) with ESMTP id AF18C14000E for ; Tue, 27 Aug 2024 11:47:41 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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=1724759175; 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=dRrcDQgatmZIkVMhpufPY7A0+CG9AIQSYvm0gWw8fYo=; b=rDfnmmqYklzSnTWGWpSl7y9iXltXZ4OyvMrElZJpFzIQy/12ek1HN635DUfNwhbhtiMaJG 5bG/G9aTGBdfLrnryqqsRy6cMONF9uUoIEww8w/JO+Y17ivjpOnpLr08xA7Q9QwqTj8R2P F6ksi+xjKjUcKQ7m00wkcY8WWYg6vXo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724759175; a=rsa-sha256; cv=none; b=J8hMhm8ANe3rgT+bbtbOMP6Z3dYkqvdJgZcoKFj6LjfG5AsVNMXcRLKFlOZNorLDXz4nwD OCEm4XqFUBU8W7Mr/drhssAPLYulqkBTF5dLbYupF9nnxtVKMJK5h9/FQ3Nl08YLzADU1w lobsBg3XH+kOSsEJKfho7u+H9VkVado= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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.194]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WtQjJ27v7zpTSk; Tue, 27 Aug 2024 19:45:56 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id D710F140202; Tue, 27 Aug 2024 19:47:36 +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; Tue, 27 Aug 2024 19:47:36 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Oscar Salvador , Miaohe Lin , Naoya Horiguchi , , , Jonathan Cameron , Kefeng Wang Subject: [PATCH v3 3/5] mm: memory_hotplug: check hwpoisoned page firstly in do_migrate_range() Date: Tue, 27 Aug 2024 19:47:26 +0800 Message-ID: <20240827114728.3212578-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240827114728.3212578-1-wangkefeng.wang@huawei.com> References: <20240827114728.3212578-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf100008.china.huawei.com (7.185.36.138) X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: AF18C14000E X-Stat-Signature: khqnwny3b4518dd3x4ddhnqo5b4aswxz X-HE-Tag: 1724759261-699703 X-HE-Meta: U2FsdGVkX19itmPdCxEHTCzsPag/VEzda6KMGKtTyZenhXYF4j/f2UAtMecH3V6ig+pug71T8tp5Uk1ZyyiP3FtqxQCb/fGCUZY4kwW8iVfm/b3j+03eFALd5rOo4gfjlfBLQNNwhW6GhE1bHAHLsfZ0JScp0GPutV7zilOthiwtwA1r/o5IMhsjXuYY3AE/lBS2K3g4794FWG8R0NxZi3/yysIAg6abfe60+S7WtEohdaHzok2uAaJVgKg+VG9ujlxhj5YxtrlITG0yg5qFN/bfwlq8dnbLWXg/heS6HkdYOg4lNys1fsxbN/8MJApG36LeSLWBvviNGj9tJ/a57F/cBqvTC4SQsN5SN3xOOfOdV+U8ODnQMORjaavk1PvGA3jDsIthl03fSCQKK9XfdQKJ7e9/Ip6L8ex5vfnjN5wh7Rzl1A/eAzJfCstX64fE7y7tgOp/nlHFs6YurohApTKy8OnqLuX2pmS4Mjyf5g9rv/6TOcZgtSlueFWAkeroHpIphS20fwP9sOHl4mOa0GHmzeRPQX3Qy0jqTB5XnhHc7nDyDmLkaWXF2ey6JYt/mjAxxQz10kTmbdTDfi5JebEWecGiiP6FbZm3uGS1eXyPLJA4m4Q5SGmLEFqlL/xDZ2FjAb7kg+L1IZTnN4G9EoA8mQN/NsJEpBbMseCcUXRTHcBhjbkQ17IR3Uvj7gSiS7lYb6THBLzwlxvBxhwoFOJSDcT9R6IuepBm4er83YbZbt9DWTO81n+gT3pkdocRdihgKr++8E67NRrTs++9BrMOiBeOyro7jTQUz1B2CbDWkZADT4b2TNpck+rSBOjdZeibknIgHBcNtBMcjsbeJtAF4NuzGeeSmq5h3/tT9Z5UxQXF5w7MeY91Y1Z5Yf6fGvJb5p3c+tZBISsJT0g5aOC1G9KlqAALiEi48IisFefpZpI8C0SEAZ2/EFVDt4N1jqPDZffzVxSLfnqQhio x+Cqt6NY waaY2vfCSnLjTLJvBwJ+jf2CqDFfbrlw26Bh9P7WI5OQ23KQiaGGV1Yo36NhYbsBbnu1RyU9Lz4q+eNGnEgupQVKzCo9PdTI+buYvfD1370/ufc3zywVWsUkKmgV9UdUu08YNHWKG/ELPrG2LiLXYGd16zWtydHyjqMpfF2kytof3K8Gwhfazyp2KCNpB/QtB/COdaQxCAy0SJNFn3FUU5091BRB1PU9JoCHU+8z2IS6iK/VqL3nHnN9P1rcS9yOrD2OmtAr/beR5q9ROv/vzG0TngJ8Vt4orquQx 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 page, luckly, after the commit e591ef7d96d6 ("mm, hwpoison,hugetlb,memory_hotplug: hotremove memory section with hwpoisoned hugepage"), the HPageMigratable of hugetlb page will be cleared, 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. Acked-by: David Hildenbrand Signed-off-by: Kefeng Wang Reviewed-by: Miaohe Lin --- mm/memory_hotplug.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 9ef776a25b9d..1335fb6ef7fa 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1793,26 +1793,26 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) * folio_nr_pages() may read garbage. This is fine as the outer * loop will revisit 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 * fail on them. It also doesn't make any sense to migrate them in the * first place. Still try to unmap such a page in case it is still mapped - * (e.g. current hwpoison implementation doesn't unmap KSM pages but keep - * the unmap as the catch all safety net). + * (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_poisoned_folio(folio, TTU_IGNORE_MLOCK); + continue; + } + + if (folio_test_hugetlb(folio)) { + isolate_hugetlb(folio, &source); continue; }