From patchwork Thu Jan 16 06:16:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wupeng Ma X-Patchwork-Id: 13941320 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 14D11C02183 for ; Thu, 16 Jan 2025 06:24:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FC9E6B0085; Thu, 16 Jan 2025 01:24:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 926DE280001; Thu, 16 Jan 2025 01:24:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B3A16B008C; Thu, 16 Jan 2025 01:24:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 452F06B008A for ; Thu, 16 Jan 2025 01:24:37 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 01CA3120771 for ; Thu, 16 Jan 2025 06:24:36 +0000 (UTC) X-FDA: 83012326194.01.B6ABA2A Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf26.hostedemail.com (Postfix) with ESMTP id 9E23F14000A for ; Thu, 16 Jan 2025 06:24:33 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf26.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737008675; a=rsa-sha256; cv=none; b=kXEOUUfnKg4qW9CrWmZYLnt+SZXWyIabfRjWlrII+9F/GqIrg3AXwj8Fjpu4lvG2tnOHUg 2JGTWy4Q39OQwTG8PeqmUj/l/js8hTTX1OyolnGYBGoScTo+i9EavsyPhtyr0tYZOJxCts vFbqGoMFERSEr/X1+fWt6kxozIWx25o= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf26.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737008675; 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=yEVpDe5o9C8UDsftW8NkOjgyf85YOhtiDvfaTi+Epls=; b=KZXAEPoINevbHhOTepkE1y0H2BeNRGU+NbGCpySDGOs0gMXx6OYwoS/4mMTbPVZFBi7+IR e211abs+qfkBrHI7ptaZB+qAS7GbQfLDKYDq5Y2XewQXYISCErjfxfYY26k2WzXzHUKhgx 31rlFA8WMeSzziIY6oBvvTYB608Rhek= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4YYXqp1nZKz1xmrf; Thu, 16 Jan 2025 14:23:34 +0800 (CST) Received: from kwepemg100017.china.huawei.com (unknown [7.202.181.58]) by mail.maildlp.com (Postfix) with ESMTPS id 0630E14034E; Thu, 16 Jan 2025 14:24:28 +0800 (CST) Received: from huawei.com (10.175.124.71) by kwepemg100017.china.huawei.com (7.202.181.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 16 Jan 2025 14:24:27 +0800 From: Wupeng Ma To: , , , , , CC: , , Subject: [PATCH v2 2/3] hwpoison, memory_hotplug: lock folio before unmap hwpoisoned folio Date: Thu, 16 Jan 2025 14:16:56 +0800 Message-ID: <20250116061657.227027-3-mawupeng1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250116061657.227027-1-mawupeng1@huawei.com> References: <20250116061657.227027-1-mawupeng1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.71] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemg100017.china.huawei.com (7.202.181.58) X-Rspam-User: X-Rspamd-Queue-Id: 9E23F14000A X-Rspamd-Server: rspam10 X-Stat-Signature: 5odc5hpzmktpxn7noj7ojy61jtm5mo7s X-HE-Tag: 1737008673-490533 X-HE-Meta: U2FsdGVkX19WhUoEsVt8siwG8ii+Wv/N9IYXcLzBY3n3YnAqRSwbYggWpBkHzypNZ0cSSynwLEoAugIpzXMr75aISMeHygHp9Lb5uCAQ5IgyYlVUlU2Pm4BbffPO52F+zsN/ZPDjRPhU+6PZf3gjOl+IcyM/6m+GUytrjYmva/ZogzVG896hs5DoRDfRYmptVTFUMEatzUmiQ7SzWjaA9OfsRZWrzoOX6n/Efk1jyNLkLvlEoa2ZPF+aVgoVoh/2zm7fpBo0LU0T666ZzUUgcH461+mdgoZ5FbzL1PZlpjPHxIeW7p6pSK7d5rasToMss0szXXwvX5Nu0RWfBA/4H5uYFC1Y+A+QQLc62uwV/QfzMOQEvxrbA96wpZPYZUSU6Nq6d6nLgtDERV39Df/x8ki81iACEOdfKIfUmzGg8mfKf5HzgO5mExaQJ39B2s6zI4z8m5MkHTp+vPe1UaDPjqAEANzxOXURZ4Vl1EgUTqZaFlovdsKclb61KGl+wMJq3yFlbiLHS8nyYUcLhS6ufMUI5buEgfHg03QMSyVqGEKOH2c9o6d0tErGB0DnqVj7o0aaaD3jff93zAr+Nn6qTifXYArCgU1CLrHSFofujCeOHU3zz52ftANu+aOpFRhIG5YL2MbRK1yXMMtsCcmKgTIH6XaincaAlnmC2n3L+B1Tr+gSsHvVoVV+cvrhLPd5/QFwQVy6Ps88hFjWfTBpnWAUKo9cIywU2Z/bkxul/8lQyPM35s6OaUKubqtKJ+jsVKsuKUSx/hSMC6dlvx+AJQOCMomx3u2MDeYUQMjt1nSV0QHPEXMO8YhwfIR6HlBpt4za/23xaCtX7KZroBlVGWKMivaNPwEeLdGUG7OMmMbYdjgSaoCKVYzLirviwrqolUmdzL1pm+esnlhukAcRbsuhR/AKODSWddPAb8/uAI+gTQ5qRj8IjmUwIIYq+b9sgoYABLsqUPmwnO7i1g7 9jyflZAR O+2I1rKZdmwusltxkm293WcjvzZeDVfTlda8XZN9yeMsKsAeZAtUOIzy+b5m/clCPs2Mq+caSAk1Cya9O0cC44k6Kz7+ERR6ZvFCgE+xRuzwMwlKzQxO2PwlUHR9wNPvyGTpsQVIE2UWYVhqpB+N7GMT8oMbIRGqVQmOuQhsvHThIIweW2BtPkBpWkciZgS0K6D59yDUwrcjYE5w0a3KzDBV6+GChCckmNhb/B5buTBKnIo8k0Lvw24ub6Yc2PVa6u7KV 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: From: Ma Wupeng Commit b15c87263a69 ("hwpoison, memory_hotplug: allow hwpoisoned pages to be offlined) add page poison checks in do_migrate_range in order to make offline hwpoisoned page possible by introducing isolate_lru_page and try_to_unmap for hwpoisoned page. However folio lock must be held before calling try_to_unmap. Add it to fix this problem. Waring will be produced if folio is not locked during unmap: ------------[ cut here ]------------ kernel BUG at ./include/linux/swapops.h:400! Internal error: Oops - BUG: 00000000f2000800 [#1] PREEMPT SMP Modules linked in: CPU: 4 UID: 0 PID: 411 Comm: bash Tainted: G W 6.13.0-rc1-00016-g3c434c7ee82a-dirty #41 Tainted: [W]=WARN Hardware name: QEMU QEMU Virtual Machine, BIOS 0.0.0 02/06/2015 pstate: 40400005 (nZcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : try_to_unmap_one+0xb08/0xd3c lr : try_to_unmap_one+0x3dc/0xd3c Call trace: try_to_unmap_one+0xb08/0xd3c (P) try_to_unmap_one+0x3dc/0xd3c (L) rmap_walk_anon+0xdc/0x1f8 rmap_walk+0x3c/0x58 try_to_unmap+0x88/0x90 unmap_poisoned_folio+0x30/0xa8 do_migrate_range+0x4a0/0x568 offline_pages+0x5a4/0x670 memory_block_action+0x17c/0x374 memory_subsys_offline+0x3c/0x78 device_offline+0xa4/0xd0 state_store+0x8c/0xf0 dev_attr_store+0x18/0x2c sysfs_kf_write+0x44/0x54 kernfs_fop_write_iter+0x118/0x1a8 vfs_write+0x3a8/0x4bc ksys_write+0x6c/0xf8 __arm64_sys_write+0x1c/0x28 invoke_syscall+0x44/0x100 el0_svc_common.constprop.0+0x40/0xe0 do_el0_svc+0x1c/0x28 el0_svc+0x30/0xd0 el0t_64_sync_handler+0xc8/0xcc el0t_64_sync+0x198/0x19c Code: f9407be0 b5fff320 d4210000 17ffff97 (d4210000) ---[ end trace 0000000000000000 ]--- Fixes: b15c87263a69 ("hwpoison, memory_hotplug: allow hwpoisoned pages to be offlined") Signed-off-by: Ma Wupeng --- mm/memory_hotplug.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 3de661e57e92..2815bd4ea483 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1805,8 +1805,11 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) (folio_test_large(folio) && folio_test_has_hwpoisoned(folio))) { if (WARN_ON(folio_test_lru(folio))) folio_isolate_lru(folio); - if (folio_mapped(folio)) + if (folio_mapped(folio)) { + folio_lock(folio); unmap_poisoned_folio(folio, pfn, false); + folio_unlock(folio); + } continue; }