From nobody Mon Jun 8 05:28:33 2026 Received: from mail-gw02.astralinux.ru (mail-gw02.astralinux.ru [93.188.205.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2DB478F29; Fri, 5 Jun 2026 17:26:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.188.205.243 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780680398; cv=none; b=IELCoPJ9wKYX9tPOSMdRqxisNbNhVbDFY2otiCj5W6d1D4n0obRq7+bHc8VjHeGahk/txRw8V7YL3hoGbcYy/3e2nFsc7L55bbgM2JP+gqys+Ed2COCF0q2lVoYgAq0WaHKyjoZDbgAU9qs3XD/Bwl0pZbK7wLbcbN6gJLm27cw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780680398; c=relaxed/simple; bh=I1udSyvjJtZNsTU1DKRRMlaA3SuRLgeegsMwVMcxdTI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=cDOiryUPTFBLn0/o4tMOoIo8kRr1VHuBiOUdHum1mx0h3imS7dp1FvlYyVrXBHiqPTNpj6aiRTp42aG/ck+aGGZZTHNJj0VfbICn0sfZwUSxXlm5Wbm1ifSOMuyNIlhIN/WQ0BiQX5/SOPhB85B2b5bP5gASu60AcsXqyp2zMZo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=astralinux.ru; spf=pass smtp.mailfrom=astralinux.ru; dkim=pass (2048-bit key) header.d=astralinux.ru header.i=@astralinux.ru header.b=QioEPdcf; arc=none smtp.client-ip=93.188.205.243 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=astralinux.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=astralinux.ru Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=astralinux.ru header.i=@astralinux.ru header.b="QioEPdcf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=astralinux.ru; s=mail; t=1780680389; bh=I1udSyvjJtZNsTU1DKRRMlaA3SuRLgeegsMwVMcxdTI=; h=From:To:Cc:Subject:Date:From; b=QioEPdcf+nmDVP4XK23s0EgFOosVQ9Q6bpPnchrXclYBC+KkXCNYEco6QNvPYuO7x xsbVeyqecQcv5d5PNfKnexqxPKoMFp+7ToItF/8nRlI8SQWXAcIM6Xq1BbB7WIz2cb oUSJGlYz508QTwgDl9+PfMYHbD1IJXQkI6WaHlhYulLRObwDXT7Rb0Xw2QPj1hWbka IppiKzq7dcwFoPBpbRAKEIn8aE6prSpDbB0PyT0TDz7a7Ra1lnxU7gUSJA7r/4adEo BEV2vZacUiu0k/7GcweZgQy5TQ2IArr5+IGV2VTLrAgJ0nuWrb6yMOmzqXIR0/ASof Xa/zS1BIoe/PQ== Received: from gca-msk-a-srv-ksmg01.astralinux.ru (localhost [127.0.0.1]) by mail-gw02.astralinux.ru (Postfix) with ESMTP id F39331F9BF; Fri, 5 Jun 2026 20:26:28 +0300 (MSK) Received: from new-mail.astralinux.ru (unknown [10.205.207.13]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail-gw02.astralinux.ru (Postfix) with ESMTPS; Fri, 5 Jun 2026 20:26:22 +0300 (MSK) Received: from rbta-msk-lt-302690.astralinux.ru (unknown [10.198.53.178]) by new-mail.astralinux.ru (Postfix) with ESMTPA id 4gX7dT3xl6zJpKL; Fri, 05 Jun 2026 20:26:21 +0300 (MSK) From: Alexandra Diupina To: stable@vger.kernel.org, Greg Kroah-Hartman Cc: Alexandra Diupina , David Hildenbrand , Oscar Salvador , Andrew Morton , Michal Hocko , Naoya Horiguchi , linux-mm@kvack.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org, Jinjiang Tu , Zi Yan , Miaohe Lin , Kefeng Wang , Luis Chamberalin , Matthew Wilcox , Michal Hocko , Pankaj Raghav Subject: [PATCH 6.1] mm/memory_hotplug: fix hwpoisoned large folio handling in do_migrate_range() Date: Fri, 5 Jun 2026 20:26:04 +0300 Message-Id: <20260605172604.16034-1-adiupina@astralinux.ru> X-Mailer: git-send-email 2.30.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-KSMG-AntiPhishing: NotDetected, bases: 2026/06/05 16:47:00 X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Envelope-From: adiupina@astralinux.ru X-KSMG-AntiSpam-Info: LuaCore: 107 0.3.107 575e75fe8e3b9d45c142d144823c5de38605099e, {date_rfc_vio_soft_silent}, {Tracking_uf_ne_domains}, {Tracking_internal2}, {Tracking_from_domain_doesnt_match_to}, 127.0.0.199:7.1.2;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;new-mail.astralinux.ru:7.1.1;lkml.kernel.org:7.1.1;astralinux.ru:7.1.1, FromAlignment: s X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiSpam-Lua-Profiles: 203696 [Jun 05 2026] X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Version: 6.1.1.22 X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.0.7854, bases: 2026/06/05 16:27:00 #28217824 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: NotDetected, bases: 2026/06/05 16:47:00 X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 Content-Type: text/plain; charset="utf-8" From: Jinjiang Tu commit 397f6d14f9c370e4910e6885294c340f39dedbf5 upstream. 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 Besides, do_migrate_range() may be called between memory_failure set hwpoison flag and isolate 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. [david@redhat.com: don't abort offlining, fixed typo, add comment] Link: https://lkml.kernel.org/r/3c214dff-9649-4015-840f-10de0e03ebe4@redhat= .com Fixes: b15c87263a69 ("hwpoison, memory_hotplug: allow hwpoisoned pages to b= e offlined") Signed-off-by: Jinjiang Tu Signed-off-by: David Hildenbrand Acked-by: Zi Yan Reviewed-by: Miaohe Lin Cc: Kefeng Wang Cc: Luis Chamberalin Cc: Matthew Wilcox (Oracle) Cc: Michal Hocko Cc: Oscar Salvador Cc: Pankaj Raghav Signed-off-by: Andrew Morton [ Alexandra: replace continue with put_folio label ] Signed-off-by: Alexandra Diupina --- mm/memory_hotplug.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index c8cc2f63c3ea..013db41f6ce2 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1654,15 +1654,21 @@ do_migrate_range(unsigned long start_pfn, unsigned = long end_pfn) * the unmap as the catch all safety net). */ if (PageHWPoison(page)) { - if (WARN_ON(folio_test_lru(folio))) - folio_isolate_lru(folio); + /* + * unmap_poisoned_folio() cannot handle large folios + * in all cases yet. + */ + if (folio_test_large(folio) && !folio_test_hugetlb(folio)) + goto put_folio; + if (folio_test_lru(folio) && !folio_isolate_lru(folio)) + goto put_folio; if (folio_mapped(folio)) { folio_lock(folio); try_to_unmap(folio, TTU_IGNORE_MLOCK); folio_unlock(folio); } =20 - continue; + goto put_folio; } =20 if (!get_page_unless_zero(page)) @@ -1687,6 +1693,7 @@ do_migrate_range(unsigned long start_pfn, unsigned lo= ng end_pfn) dump_page(page, "isolation failed"); } } +put_folio: put_page(page); } if (!list_empty(&source)) { --=20 2.30.2