From patchwork Thu Jul 25 01:16:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13741490 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 AA21AC3DA70 for ; Thu, 25 Jul 2024 01:17:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A29F6B0088; Wed, 24 Jul 2024 21:16:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F31086B0095; Wed, 24 Jul 2024 21:16:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBF896B0088; Wed, 24 Jul 2024 21:16:58 -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 768256B0088 for ; Wed, 24 Jul 2024 21:16:58 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2BEEC140D0C for ; Thu, 25 Jul 2024 01:16:58 +0000 (UTC) X-FDA: 82376510916.04.2BF3B37 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf16.hostedemail.com (Postfix) with ESMTP id EF646180005 for ; Thu, 25 Jul 2024 01:16:54 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.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=1721870193; 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=qv7aaZRlHNMD4k1nOC3+xDOa/W10CgNBt7BHj9IogfA=; b=DJz7fQAo6rMOCwFls0bZ049cqGJpSQMRgRDm5WiI0u5SoTIUc8yP1vX1FfwQgaNif3b9qZ buUlX3tXJ7WEz1hoyR/GJ0AMtbv1HvQEzrywChobrHMs/RmFEYgXHG7MK+ftaPyfniOu5z pOtd87Kl3J460jO9EWx0MU58Nl55Vlg= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.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=1721870193; a=rsa-sha256; cv=none; b=mImeKlw08sxmYvwS5w/Gm3t6gQhAEZfhmTVy3sPeuV8BGKlQq8ZzU3PiOsKIIi76RH8LhN 4Z0LgJ/jTJNxZco6GGUKQSfFtbl7yjyTOpT7aIXVNCKRnHJLy6x/OLsSL7XtLHfi9sXX8p AWV3cTW4wDmN57y3AFDHlmk5c0ok87c= Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WTtGb63JfzMr5s; Thu, 25 Jul 2024 09:15:03 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 46A9F140444; Thu, 25 Jul 2024 09:16:51 +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; Thu, 25 Jul 2024 09:16:50 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Oscar Salvador , Miaohe Lin , Naoya Horiguchi , , Kefeng Wang Subject: [PATCH 1/4] mm: memory-failure: add unmap_posioned_folio() Date: Thu, 25 Jul 2024 09:16:44 +0800 Message-ID: <20240725011647.1306045-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240725011647.1306045-1-wangkefeng.wang@huawei.com> References: <20240725011647.1306045-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf100008.china.huawei.com (7.185.36.138) X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: EF646180005 X-Stat-Signature: jesm59g4ttanar44hqrifce8qnpdu4rc X-HE-Tag: 1721870214-854607 X-HE-Meta: U2FsdGVkX1+YvhH66BM3oN67wFHS4PuExvlKIFaxeAT0MI87/95iIvTvwFvABbgaXOb9jLczaVLifjTTl2gOt/p5lV8lbED6eWZeDOH4es/gyFXL0/XAIOBrJH8eN25WLofzHNgzNwbtOEIobsqZgdQjfEhB4LPlw3YyHBzktTbTOnUjfvHQVU+C0BVDqHIttNzDZV6luOkD7vSAZQ0RtJ69pMSlMJKG8U4kMYMbiQpG3KrIOYqPWZ7GvgJW4AcZnN9PONju+VJ9nOPqYmTsKhKYjsdsXfskuu8FLe8QsPd4kccFy22exDRGp2v0vYNDhYXZSI3ODZL2/f1qDnabncP/urhCpC/eAyqdnBr68aqVR5vYy4r2oZV0naYdQwUWGwz73JFopvTnuZ6nzHQH8t5+V8bJhEFCMVO/fHaXlrKp33OLP5sfgl+3C5T4LJrY2fHTVEZ1ZveQ0UKzCEkq2BSLRwQ06s6mrPIuXEZaufsg4wz8QcyYcBbIfO2R+pZHvcHzmt/DW/o3mxEleevLtveGq9+C1I7UEd3gf1fHBczTm2S631cfO5K7UZHHKrkbnr5dh5/B9YD8ZAF66AR/fAlwf/4JgvMqKT9/Fp2J05P7j+s6OZXzSnge9kgVC/Z5txHnMWfUgaJ1AYE+/fITq262ESKpnyN1jdP5SJRtBO/RP8+SjJ2zRswhFDWiGoQBy/0ZNl+pgB/uYR50lUStibuNdiUPpLWA1X8LC4cnqLkjl6Skg0E/VyheyH9jkTLpwBTVwGw3jae0tlkSH8pmuVjgKvxkm7t0BXmDjPAvXFkQcuGF65I3Aaj+2YPohd3yu9k1DjskPDmAxpcUZpwTiBpseDe8XVWp2GhHiw7qIGpODqjQk7GMd3ceIkZ0oUT9f9u59tYBl0tMRdVUWuknTZedUJTw0knJ/HAsRbu0VmGOaCDHsktrATA8qtjBJW/nlbnIv0tRi/kPYXIN0zD BwtBx0Y3 MPbhFC3YZHM2STQ29MY8j+SLMEXjFytDtVfyZmxX+vyB73K/bgX8OxO0kiJN1uZ+W2s4DLgzm1rozk6dEdlRkuMiieWWzVIU34BY3IfJeTl8v2Bv+oLGy76b+J/a92R3siyCLshQi74vgoyQf3bFuRvzx51sXWQ3yWPrZGSpncOMPtRSbpiuA3IZOc801WdmMLII5/hBj//yKcwfaCNwlTR2EIf1qYL4/ufVB7LeL2VWW7rDo20aSDf1h0JkGxsQi7oHMyvpLQNlsS2A= 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: Add unmap_posioned_folio() helper which will be reused by do_migrate_range() from memory hotplug soon. Signed-off-by: Kefeng Wang Acked-by: David Hildenbrand --- mm/internal.h | 9 +++++++++ mm/memory-failure.c | 43 ++++++++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 7a3bcc6d95e7..c5bd24c4fa3a 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1069,6 +1069,8 @@ static inline int find_next_best_node(int node, nodemask_t *used_node_mask) /* * mm/memory-failure.c */ +#ifdef CONFIG_MEMORY_FAILURE +int unmap_posioned_folio(struct folio *folio, enum ttu_flags ttu); void shake_folio(struct folio *folio); extern int hwpoison_filter(struct page *p); @@ -1089,6 +1091,13 @@ void add_to_kill_ksm(struct task_struct *tsk, struct page *p, unsigned long ksm_addr); unsigned long page_mapped_in_vma(struct page *page, struct vm_area_struct *vma); +#else +static inline int unmap_posioned_folio(struct folio *folio, enum ttu_flags ttu) +{ + return 0; +} +#endif + extern unsigned long __must_check vm_mmap_pgoff(struct file *, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 8c765329829f..99d92565cbb0 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1554,6 +1554,30 @@ static int get_hwpoison_page(struct page *p, unsigned long flags) return ret; } +int unmap_posioned_folio(struct folio *folio, enum ttu_flags ttu) +{ + if (folio_test_hugetlb(folio) && !folio_test_anon(folio)) { + struct address_space *mapping; + /* + * For hugetlb pages 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 indicate we have taken the lock + * at this higher level. + */ + mapping = hugetlb_folio_mapping_lock_write(folio); + if (!mapping) + return -EAGAIN; + + try_to_unmap(folio, ttu|TTU_RMAP_LOCKED); + i_mmap_unlock_write(mapping); + } else { + try_to_unmap(folio, ttu); + } + + return 0; +} + /* * Do all that is necessary to remove user space mappings. Unmap * the pages and send SIGBUS to the processes if the data was dirty. @@ -1615,23 +1639,8 @@ static bool hwpoison_user_mappings(struct folio *folio, struct page *p, */ collect_procs(folio, p, &tokill, flags & MF_ACTION_REQUIRED); - if (folio_test_hugetlb(folio) && !folio_test_anon(folio)) { - /* - * For hugetlb pages 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 indicate we have taken the lock - * at this higher level. - */ - mapping = hugetlb_folio_mapping_lock_write(folio); - if (mapping) { - try_to_unmap(folio, ttu|TTU_RMAP_LOCKED); - i_mmap_unlock_write(mapping); - } else - pr_info("%#lx: could not lock mapping for mapped huge page\n", pfn); - } else { - try_to_unmap(folio, ttu); - } + if (unmap_posioned_folio(folio, ttu)) + pr_info("%#lx: could not lock mapping for mapped huge page\n", pfn); unmap_success = !folio_mapped(folio); if (!unmap_success)