From patchwork Thu Apr 25 08:40:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13642967 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 A1CCBC4345F for ; Thu, 25 Apr 2024 08:41:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C35486B0089; Thu, 25 Apr 2024 04:40:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D8616B0087; Thu, 25 Apr 2024 04:40:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B9F46B0095; Thu, 25 Apr 2024 04:40:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 0C4146B0089 for ; Thu, 25 Apr 2024 04:40:56 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id ABF858045C for ; Thu, 25 Apr 2024 08:40:55 +0000 (UTC) X-FDA: 82047408870.05.267A639 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf10.hostedemail.com (Postfix) with ESMTP id 535D3C000B for ; Thu, 25 Apr 2024 08:40:51 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.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=1714034454; 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=9XE27iMZAYmpUQWxEPn0jlvkOw792lA4y9C2bFT42BE=; b=Ils+gO5VnTYuiiijvJqUf9zkmDJO6M+uiepUyySyKNS8FFNT3GQ7BvG5QSlh9W6rwSX2db 1/Qs5a0/iCSSFcsPjjYdPKy7e6UNnIyJM+b4TT8R+egBNy9XJf9n0M/wIFycwPZQ5RWKDd W38gyPYhGKmv9d13jHcysNSpBRpdksg= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714034454; a=rsa-sha256; cv=none; b=1VoVd+SFZlIEYqgW+PCJmBYQpjYZDQ3LqBr++oR1ZpEdRVKVyDuSWOgjuTz9J3+qbwXcV9 azlWhpypd7Zi/7ToEFeOLpTx/2DxavDfkrw7AjZsVa6tNft4rI/RHaHhzs34xbe0uEUbJE jYs2r0/+vq5KACbifi9NVRiQVacH1Fc= Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4VQ8Rg4NhDzcbyj; Thu, 25 Apr 2024 16:39:43 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id A16401403D3; Thu, 25 Apr 2024 16:40:48 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 25 Apr 2024 16:40:48 +0800 From: Kefeng Wang To: Andrew Morton CC: , David Hildenbrand , Miaohe Lin , Naoya Horiguchi , Oscar Salvador , Zi Yan , Hugh Dickins , Jonathan Corbet , , Vishal Moola , Kefeng Wang Subject: [PATCH v2 01/10] mm: memory_hotplug: check hwpoisoned page firstly in do_migrate_range() Date: Thu, 25 Apr 2024 16:40:19 +0800 Message-ID: <20240425084028.3888403-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240425084028.3888403-1-wangkefeng.wang@huawei.com> References: <20240425084028.3888403-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 dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Queue-Id: 535D3C000B X-Stat-Signature: wh5ucy5nyuihdqg97id56u6wgmgewpam X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1714034451-300054 X-HE-Meta: U2FsdGVkX1+uR9vdl/IaTu4BDxdQs0OETIwVkG70XmoKDJ0Tqs9z65YnlojWk/yvb2KhwyzcIDVTsbVehjTyKEN3yENajmfbgeeaVLorwV1WL6nHwuAEajITbiQ9w4MpILS1CSWXoaHjCtmDq2u1sGuorEoCY5qZPVqLkL6TzL0CBboCWksVvOARp+1w+m+UK/8y9XvpbVybMXqJeirkmLv+SI4vu7MZBjw6jd1NJ7mzAd96J5nT7y0pTRDImSGLQ+0OYOogGYfyS2Ttt76lvx6+DyyZHa4ztf4rdbnh5arsYKkhL5q7ng0KiIeM2Et9Mj2xcFBo6GfzZqWpP2WQDJhlW8v11lotaswsorHvG/lM+dJ8PAeBECTdzK+cKHOTpmodYT+RElpSV5rgDTi4q7F21sr34KrZR8UshkcRc6Ua8dl/y5fvo8Mma4JK5hfWfqfKSFHtPWUHhV4aOLfZ32Jf8AtKr4lsG6Ac/NFElb79sgf/voWfunHT+RjIKu+quDa6bnLDZsr1ZU149hWu3ct27NBH0+BjUWNQLh3oEP2/+s4Qj1+6qXEnmcaeh6bx7V3Hk0IwppkjJ7K44ziCaav2O4oECoAweNm0lb1M2mXx/UCaDEVYXdx+Gowc11mkPzbBS+cbCamSgbJUHasta/pahwrnDedorNmDJ0mM68JwNMYuepNrs9499BAgvJNdWKRK74hMYYyN6PCkFO4ApflXJWcc0IEgNHJe5WsTx5rbUSoqq7fyYW0NMyBhFihU8lMXbEGQAB04YHAQniZjpVTAWw3aBbt7rwxTWvHM36GdpnGhNHDkg6Xk+JjziYGEO1j8EE2XBzvj6ou96xr6PvUiv7QWTp43hU87eJw+UZUy0seUZcCAd9OrEYRGxdC6brVBJTEpAafA5TTP7MTmzV5VA5lVRydykwNZf2EEsEPLXLT9n+GTSIjXpaRD01uHZd0vg7hM6KEb21eM6Xb TmLjI7M8 O6kzD3DKWiNjN8mT+FqwthkyIabAvy7NcrGgpx6u9bfwi48qwcldGJRMMUMdjbaThxHFuBk7qJqAsACLar7WeidlUdHcok28gYWjwwB6F60/m+d+UHzATVzztdKhq2bxw4w1YLq8Cv+R8N2IzhmOgwoGxFiPtDGwh+7WTu2DoiKQ1VAJFpTh8UVjImIxQoZaXVLzympPOoPLIf7hH5tzfxTTbHyQmIcFq8JgTaxbpPne4FCXHSRPztox0sZsV4KHFpb/KDmCKNw0tVaU= 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 dead loop still occur if offline a hwpoison hugetlb, luckly, with commit e591ef7d96d6 ("mm,hwpoison,hugetlb,memory_hotplug: hotremove memory 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 deed 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 scan_movable_pages() loop, it will be isolated in do_migrate_range() and but fails to migrated, In order to avoid this 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, also add some warn when the folio is still mapped. Signed-off-by: Kefeng Wang --- mm/memory_hotplug.c | 62 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 431b1f6753c0..1985caf73e5a 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1772,6 +1772,35 @@ static int scan_movable_pages(unsigned long start, unsigned long end, return 0; } +static bool isolate_and_unmap_hwposion_folio(struct folio *folio) +{ + if (WARN_ON(folio_test_lru(folio))) + folio_isolate_lru(folio); + + if (!folio_mapped(folio)) + return true; + + if (folio_test_hugetlb(folio) && !folio_test_anon(folio)) { + struct address_space *mapping; + + mapping = hugetlb_page_mapping_lock_write(&folio->page); + if (mapping) { + /* + * In shared mappings, try_to_unmap could potentially + * call huge_pmd_unshare. Because of this, take + * semaphore in write mode here and set TTU_RMAP_LOCKED + * to let lower levels know we have taken the lock. + */ + try_to_unmap(folio, TTU_IGNORE_MLOCK | TTU_RMAP_LOCKED); + i_mmap_unlock_write(mapping); + } + } else { + try_to_unmap(folio, TTU_IGNORE_MLOCK); + } + + return folio_mapped(folio); +} + static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) { unsigned long pfn; @@ -1790,28 +1819,33 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) folio = page_folio(page); head = &folio->page; - if (PageHuge(page)) { - pfn = page_to_pfn(head) + compound_nr(head) - 1; - isolate_hugetlb(folio, &source); - continue; - } else if (PageTransHuge(page)) - pfn = page_to_pfn(head) + thp_nr_pages(page) - 1; - /* * 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 (WARN_ON(folio_test_lru(folio))) - folio_isolate_lru(folio); - if (folio_mapped(folio)) - try_to_unmap(folio, TTU_IGNORE_MLOCK); + if (unlikely(PageHWPoison(page))) { + folio = page_folio(page); + if (isolate_and_unmap_hwposion_folio(folio)) { + if (__ratelimit(&migrate_rs)) { + pr_warn("%#lx: failed to unmap hwpoison folio\n", + pfn); + } + } + + if (folio_test_large(folio)) + pfn = folio_pfn(folio) + folio_nr_pages(folio) - 1; continue; } + if (PageHuge(page)) { + pfn = page_to_pfn(head) + compound_nr(head) - 1; + isolate_hugetlb(folio, &source); + continue; + } else if (PageTransHuge(page)) + pfn = page_to_pfn(head) + thp_nr_pages(page) - 1; + if (!get_page_unless_zero(page)) continue; /*