From mboxrd@z Thu Jan 1 00:00:00 1970 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 0C40CC77B7C for ; Thu, 3 Jul 2025 08:24:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DDDA6B0146; Thu, 3 Jul 2025 04:24:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B3D06B0147; Thu, 3 Jul 2025 04:24:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F0D46B0148; Thu, 3 Jul 2025 04:24:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7F67F6B0146 for ; Thu, 3 Jul 2025 04:24:44 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3B4C8107417 for ; Thu, 3 Jul 2025 08:24:44 +0000 (UTC) X-FDA: 83622267288.23.622BC3C Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf17.hostedemail.com (Postfix) with ESMTP id 2BE484000B for ; Thu, 3 Jul 2025 08:24:40 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of tujinjiang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=tujinjiang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751531082; 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=kFYMd6OT9l4zaPx66gE+tTxVjHUywYMJ5OYM/fltCck=; b=aES2DYBDm9TZRV8Pm/4G6mzuJpEi2dyGaa1PPV97Teafqo2CqLC6jKuqh1PGQ8H1AneFF/ 8C0k1LLWIXoeCZWwjkXORBZeOgY3t08vUImLBVBE+T+uqT+JFw6iP0FUxcYaGa0ycsOVIQ KEeyyJBXR9dZZN4SMqKm4fZtSEVSGas= 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 tujinjiang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=tujinjiang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751531082; a=rsa-sha256; cv=none; b=0jjPsAUXNj3GeprXdowBBtOLVEgXVOmAdkGypLpdXrdnkotkHoYULeoh9F2XkmDqz/Fm/+ Z57AD5rSZakNO1g9fSNACdqykRI0doc7arsznhqEtb/b5BNKRt11/6GCC4Ol6cwtNOQz9Y QJ1hHihyzzUYSXp0tQwqYrf/WGb8oVg= Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4bXqSV3hjgz14LqH; Thu, 3 Jul 2025 16:19:54 +0800 (CST) Received: from kwepemo200002.china.huawei.com (unknown [7.202.195.209]) by mail.maildlp.com (Postfix) with ESMTPS id 67938180B60; Thu, 3 Jul 2025 16:24:35 +0800 (CST) Received: from [10.174.179.13] (10.174.179.13) by kwepemo200002.china.huawei.com (7.202.195.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 3 Jul 2025 16:24:34 +0800 Message-ID: <61325284-d1d6-a973-8aa7-c0f226db95fa@huawei.com> Date: Thu, 3 Jul 2025 16:24:34 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v2 2/2] mm/memory_hotplug: fix hwpoisoned large folio handling in do_migrate_range To: David Hildenbrand , Oscar Salvador CC: , , , , References: <20250627125747.3094074-1-tujinjiang@huawei.com> <20250627125747.3094074-3-tujinjiang@huawei.com> <373d02c5-2b62-8543-b786-8fd591ad56eb@huawei.com> From: Jinjiang Tu In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.13] X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemo200002.china.huawei.com (7.202.195.209) X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 2BE484000B X-Stat-Signature: of6oac4khxrpejf8fxq58kw9kxfuq146 X-HE-Tag: 1751531080-550243 X-HE-Meta: U2FsdGVkX18qoH5ksIDNr9NHFPVNTKG9wHlMCuZU2mldVDEfAL1QfhxV87zokeQQ3gvbWC7QxDSRjrzr3BDFguQBeafXrsoRmiRzPzN7ayepvzdusHB0WTrYPrg+fW3od6mKJ6mrQFqLVRqCv6IwzplFzkYDvfF1BFoTkEutzTpq+P+wOm2nF0uLvTX5C2OjcHiPYvWpt+w7pvxUUhQKufedFsfzzmPkCHHVXDDn7L/8jgcnipKZef+TGKQHMGMnxfyuQZT5Wo7IXZZ4TKszZPpEf2+SDyzUI6aAZfPJAUtEg4R46WewlkQH5Ao8yrZN8yf4mPeJLu7IvFDOw8e3rxrL0onxclRNr2qJBhS8Lig5Gs3X8CcwC/U/HNzzCWylzJkybXqOaCx9PYScu6/MrZLmZqrhmT9uFqQslXVS2AEjMPZCKtudemEqRZHmijoFhnw+aLWln9zPiRRxvQY+pFozvG5JwDK+TWm976bn4acrWCgjLYe33GyMXCACkcpCsReQWWgu7bXWimSQJuGI0q7Yp+s2QKeLGy3ns6jq79ruR8jUQx0f3g7PX/cREGq61mL2To87JeTVEYzOALYuw97hltWJDcWtWsLfqNXz9SaQG6sc+cag91/BagU2qK0+O5wU7kciuJdtwCLHRRfoZzn26b7jhyIZwg8DuFn28LWfBlbClzW1inaT8bKqecwAfnvkQedNF/AZQWTC93RhW1S9dK94YrSU2l9y1338xgYye+6ZiH3PJofVENw8S0pHH83CZmaB/I+0hlA0gVArsc2TG3+FxV1RK1IiAfg8Enq1rqQCCWSmi1z/ZDwg+vCaBKUBTlFAEpjLwWqwRB17/VeJRSDlUX2cz4InP5wtiYkNKiJyl5lAHesFC608XW2v8oDsqYME/S+5wE4eSlPPik5hhqkssM6W6YFezMHrLSYQqoZE0xU4f7/B9Dhaz/t5JdCo/xt6HKveo82DwIx T9VCVhM+ J/r29w67msW9Jz10F7KejhyN/mB0I68uJ7UIM7hx4hoPz8v/3ifhucJvnM1hKOmiH/gbZ5AsHSMaUCxDEXW9t07ECfdWjv/RaILO4VOmj5mv7UQmtpaosATFAvO4GfsbElTKox1Gv0X8Kwni8b0GGWSz0yOMpDZnGP0Xy8DTnKsrbPNiD6M1u4369Bzrph93Y7GvwGllYzLAYzGRTQPh9D4ZOp6DLbsLObXLwaHR5c6SN7fj5KdbxtJ8/rCGN5sxXC52wDsJ2yN9eG8A= 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: 在 2025/7/3 15:57, David Hildenbrand 写道: > On 03.07.25 09:46, Jinjiang Tu wrote: >> >> 在 2025/7/1 22:21, Oscar Salvador 写道: >>> On Fri, Jun 27, 2025 at 08:57:47PM +0800, Jinjiang Tu wrote: >>>> In do_migrate_range(), the hwpoisoned folio may be large folio, which >>>> can't be handled by unmap_poisoned_folio(). >>>> >>>> I can reproduce this issue in qemu after adding delay in >>>> memory_failure() >>>> >>>> BUG: kernel NULL pointer dereference, address: 0000000000000000 >>>> Workqueue: kacpi_hotplug acpi_hotplug_work_fn >>>> RIP: 0010:try_to_unmap_one+0x16a/0xfc0 >>>>    >>>>    rmap_walk_anon+0xda/0x1f0 >>>>    try_to_unmap+0x78/0x80 >>>>    ? __pfx_try_to_unmap_one+0x10/0x10 >>>>    ? __pfx_folio_not_mapped+0x10/0x10 >>>>    ? __pfx_folio_lock_anon_vma_read+0x10/0x10 >>>>    unmap_poisoned_folio+0x60/0x140 >>>>    do_migrate_range+0x4d1/0x600 >>>>    ? slab_memory_callback+0x6a/0x190 >>>>    ? notifier_call_chain+0x56/0xb0 >>>>    offline_pages+0x3e6/0x460 >>>>    memory_subsys_offline+0x130/0x1f0 >>>>    device_offline+0xba/0x110 >>>>    acpi_bus_offline+0xb7/0x130 >>>>    acpi_scan_hot_remove+0x77/0x290 >>>>    acpi_device_hotplug+0x1e0/0x240 >>>>    acpi_hotplug_work_fn+0x1a/0x30 >>>>    process_one_work+0x186/0x340 >>>> >>>> In this case, just make offline_pages() fail. >>>> >>>> Besides, do_migrate_range() may be called between memory_failure set >>>> hwposion flag and ioslate the folio from lru, so remove WARN_ON(). >>>> In other >>>> places, unmap_poisoned_folio() is called when the folio is >>>> isolated, obey >>>> it in do_migrate_range() too. >>>> >>>> Fixes: b15c87263a69 ("hwpoison, memory_hotplug: allow hwpoisoned >>>> pages to be offlined") >>>> Signed-off-by: Jinjiang Tu >>> ... >>>> @@ -2041,11 +2048,9 @@ int offline_pages(unsigned long start_pfn, >>>> unsigned long nr_pages, >>>>                   ret = scan_movable_pages(pfn, end_pfn, &pfn); >>>>                if (!ret) { >>>> -                /* >>>> -                 * TODO: fatal migration failures should bail >>>> -                 * out >>>> -                 */ >>>> -                do_migrate_range(pfn, end_pfn); >>>> +                ret = do_migrate_range(pfn, end_pfn); >>>> +                if (ret) >>>> +                    break; >>> I am not really sure about this one. >>> I get the reason you're adding it, but note that migrate_pages() can >>> also return >>> "fatal" errors and we don't propagate that. >>> >>> The moto has always been to migrate as much as possible, and this >>> changes this >>> behaviour. >> If we just skip to next pfn, offline_pages() will deadloop meaningless >> util received signal. > > Yeah, that's also not good, > >> It seems there is no document to guarantee memory offline have to >> migrate as much as possible. > > We should try offlining as good as possible. But if there is something > we just cannot possibly migrate, there is no sense in retrying. > > Now, could we run into this case here because we are racing with other > code, and actually retrying again could make it work? > > Remind me again: how exactly do we arrive at this point of having a > large folio that is hwpoisoned but still mapped? > > In memory_failure(), we do on a  large folio > > 1) folio_set_has_hwpoisoned > 2) try_to_split_thp_page > 3) if splitting fails, kill_procs_now If 2) is executed when do_migrate_range() increment the refcount of the folio, the split fails, and retry is meaningless. Since we don't know if memory_failure() finishes, we couldn't know when to abort retry. > > So given that, couldn't we just retry the migration until the race is > over and we are good? >