Skip to content

Commit 397f6d1

Browse files
tujinjiang11akpm00
authored andcommitted
mm/memory_hotplug: fix hwpoisoned large folio handling in do_migrate_range()
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 <TASK> 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. [[email protected]: don't abort offlining, fixed typo, add comment] Link: https://lkml.kernel.org/r/[email protected] Fixes: b15c872 ("hwpoison, memory_hotplug: allow hwpoisoned pages to be offlined") Signed-off-by: Jinjiang Tu <[email protected]> Signed-off-by: David Hildenbrand <[email protected]> Acked-by: Zi Yan <[email protected]> Reviewed-by: Miaohe Lin <[email protected]> Cc: Kefeng Wang <[email protected]> Cc: Luis Chamberalin <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: Pankaj Raghav <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 394bfac commit 397f6d1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

mm/memory_hotplug.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,8 +1815,14 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
18151815
pfn = folio_pfn(folio) + folio_nr_pages(folio) - 1;
18161816

18171817
if (folio_contain_hwpoisoned_page(folio)) {
1818-
if (WARN_ON(folio_test_lru(folio)))
1819-
folio_isolate_lru(folio);
1818+
/*
1819+
* unmap_poisoned_folio() cannot handle large folios
1820+
* in all cases yet.
1821+
*/
1822+
if (folio_test_large(folio) && !folio_test_hugetlb(folio))
1823+
goto put_folio;
1824+
if (folio_test_lru(folio) && !folio_isolate_lru(folio))
1825+
goto put_folio;
18201826
if (folio_mapped(folio)) {
18211827
folio_lock(folio);
18221828
unmap_poisoned_folio(folio, pfn, false);

0 commit comments

Comments
 (0)