From patchwork Fri Aug 16 09:04:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13765782 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 B0479C531DE for ; Fri, 16 Aug 2024 09:05:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE04A8D0059; Fri, 16 Aug 2024 05:05:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC6908D005A; Fri, 16 Aug 2024 05:05:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 918FE8D0059; Fri, 16 Aug 2024 05:05:14 -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 68E488D005A for ; Fri, 16 Aug 2024 05:05:14 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A8BB1141B25 for ; Fri, 16 Aug 2024 09:05:13 +0000 (UTC) X-FDA: 82457524506.04.9963BE4 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf17.hostedemail.com (Postfix) with ESMTP id F36BF40027 for ; Fri, 16 Aug 2024 09:05:10 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723799057; a=rsa-sha256; cv=none; b=xIyCGI2WpUdJXwWGdck1dQVR3apWVRU3wZNIi4Q881AMQfbWNMZ9oxOeOwjUq8GiKemSlf cIFQxxzTDaJx6yvvzX6/i7Q7AWSAHqHUxApHOY/SkeHp5uAOmin9YnYw8mnz1+VNzb43Bz nRQ+DzAoGcCPCljHxgrqLzgbGS+DqnU= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723799057; 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=khJuWYhZwI8BbxRlqM3Mz7vStZbppgfXOQKESbVVV5M=; b=dX1Hr3MrR01vCBh+9aogq4IEUxP2d435PJQtGfmQzD9C97kxY0RdRH/LdlMox7uDCK3pfN DB3HHTU98Eii7/Y5FveeVa0DJQiIndQAAIZWq8FhjtIDFS6NRtXHVpaozpSGKwlJWLeZhg pgL4CJAbAWf1DRw5l9Sk721DdCzf0mc= Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WlbfV1KkyzcdXF; Fri, 16 Aug 2024 17:04:50 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 42501140137; Fri, 16 Aug 2024 17:05:07 +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; Fri, 16 Aug 2024 17:05:06 +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: Fri, 16 Aug 2024 17:04:33 +0800 Message-ID: <20240816090435.888946-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240816090435.888946-1-wangkefeng.wang@huawei.com> References: <20240816090435.888946-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-Rspamd-Queue-Id: F36BF40027 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: dgnf47hqdibpqb5zq3egnrbpwser4rg1 X-HE-Tag: 1723799110-698774 X-HE-Meta: U2FsdGVkX1+714Eyatw6t5kT89zAP14QmDCgGvdwLvbGyP0wRnRxM1PkZROwQNShcPGRscDyQdoCfzzGHyYq6WbVJG78XQZSjCA+iwBDZQDlPi5J/EniB+yNiCP8/QK7/VCXVhjLbb/7eGBpLRtVx/VFpCMOcHVh0gCD3AaYHcTSu4/QCIOx4HgxAyvaQyyZMGB245QdXVFWLsydeZmcXDsysnvMaweY7Xk29l2P+yRaCaVh9vykv5nj7qz6XJFvv6j0w+M+dLIkb6eXsyZyl0pXSnEAKMhjBkHwO5anLVNWNLVrlWhadCkEUphfe6EMuDsXNGL/7gZq63W5G4QXuGuuJwZbpIjSYkjQ/QWCVu9rSdwmdnQ+QcqjFTYpPX7+Lr6O59H0rNzx4bw+hxTC3ywmprm+jjYicfbtxg/gdGwZqDt36LcVE7Sw8Y6ZPg/hPpiYTmAGRTKD9IE1JC6oXIVGJhKJm8cFDteFo6kPDRPThy5GyiFnDemTjXdSYddJb9on4rFByba3iicrvf+WhJaqmOYxvOgvSO4QiA+Lor0NbgbTh3dkeW7ikEbZnJd80QmRpSo8o+K/TuVOqsGBJHwYCfhG43EmPtKeydjyVv5Fn3skmb0WEFAk0ATc0t7S+jLJiqZXSOBuCCR0h4avMG0wFFGCNwRTo+nZ2LOIjh6GahsPlGgW9bZvJkvnuT5Rtg4AcK9LHb0y9zkJ4vfOs93MXtmG0Ca5nrJ4uWmpuRLiyG3WaxFnwz2lDndCqr6VYrdId5pElxwV9+rVSciKNMCgIXWaoGJuU4QUHQlFHhxK+NtuuRrMpsYsGaWbwNWJTnCK9MzgMrEkhbe+AfV9GFKHi3Jx8L8smgSacaAB1WDvn1414L5WRKmrSlTpeukov9w3Sipjmg03v91kOE/kyXI3vcO3/usARPXrIS8LBWKFsGQfovrAbRMOn5vIfY02xF/zJdpj4WpddmhYaRR 15IyBKyB ZbzxJDBJ4PFmm4TMxravZEnMy4SHuqXv00zw8m4zx7UwZJlThLGvnDbTa9nOw2zp7bsZhDjQkEijnoV/M7MRYk4KUnOV2bV9dOWFbiptn9XQMX3OPNJhTe/yrx3nR97n8uYSAi85lmCTkv3TxjgwpK9QtIdbreu6Qwfmpn76vb4MsIgHezgcujxwfV9W8mV/aq+aHsvJE9FWcWjClw2O/OCDfCqWW3uW+aW+Sr57/Bm4mAOY9gEfaT2ZaOxQToR7IK8uXq6SlWlNmaQE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, 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 --- 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 7c674cec3c18..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); - 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; }