Skip to content

Commit eeb0efd

Browse files
osalvadorvilardagatorvalds
authored andcommitted
mm,memory_hotplug: fix scan_movable_pages() for gigantic hugepages
This is the same sort of error we saw in commit 17e2e7d ("mm, page_alloc: fix has_unmovable_pages for HugePages"). Gigantic hugepages cross several memblocks, so it can be that the page we get in scan_movable_pages() is a page-tail belonging to a 1G-hugepage. If that happens, page_hstate()->size_to_hstate() will return NULL, and we will blow up in hugepage_migration_supported(). The splat is as follows: BUG: unable to handle kernel NULL pointer dereference at 0000000000000008 #PF error: [normal kernel read fault] PGD 0 P4D 0 Oops: 0000 [#1] SMP PTI CPU: 1 PID: 1350 Comm: bash Tainted: G E 5.0.0-rc1-mm1-1-default+ torvalds#27 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014 RIP: 0010:__offline_pages+0x6ae/0x900 Call Trace: memory_subsys_offline+0x42/0x60 device_offline+0x80/0xa0 state_store+0xab/0xc0 kernfs_fop_write+0x102/0x180 __vfs_write+0x26/0x190 vfs_write+0xad/0x1b0 ksys_write+0x42/0x90 do_syscall_64+0x5b/0x180 entry_SYSCALL_64_after_hwframe+0x44/0xa9 Modules linked in: af_packet(E) xt_tcpudp(E) ipt_REJECT(E) xt_conntrack(E) nf_conntrack(E) nf_defrag_ipv4(E) ip_set(E) nfnetlink(E) ebtable_nat(E) ebtable_broute(E) bridge(E) stp(E) llc(E) iptable_mangle(E) iptable_raw(E) iptable_security(E) ebtable_filter(E) ebtables(E) iptable_filter(E) ip_tables(E) x_tables(E) kvm_intel(E) kvm(E) irqbypass(E) crct10dif_pclmul(E) crc32_pclmul(E) ghash_clmulni_intel(E) bochs_drm(E) ttm(E) aesni_intel(E) drm_kms_helper(E) aes_x86_64(E) crypto_simd(E) cryptd(E) glue_helper(E) drm(E) virtio_net(E) syscopyarea(E) sysfillrect(E) net_failover(E) sysimgblt(E) pcspkr(E) failover(E) i2c_piix4(E) fb_sys_fops(E) parport_pc(E) parport(E) button(E) btrfs(E) libcrc32c(E) xor(E) zstd_decompress(E) zstd_compress(E) xxhash(E) raid6_pq(E) sd_mod(E) ata_generic(E) ata_piix(E) ahci(E) libahci(E) libata(E) crc32c_intel(E) serio_raw(E) virtio_pci(E) virtio_ring(E) virtio(E) sg(E) scsi_mod(E) autofs4(E) [akpm@linux-foundation.org: fix brace layout, per David. Reduce indentation] Link: http://lkml.kernel.org/r/20190122154407.18417-1-osalvador@suse.de Signed-off-by: Oscar Salvador <osalvador@suse.de> Reviewed-by: Anthony Yznaga <anthony.yznaga@oracle.com> Acked-by: Michal Hocko <mhocko@suse.com> Reviewed-by: David Hildenbrand <david@redhat.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1b69ac6 commit eeb0efd

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

mm/memory_hotplug.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,23 +1305,27 @@ int test_pages_in_a_zone(unsigned long start_pfn, unsigned long end_pfn,
13051305
static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
13061306
{
13071307
unsigned long pfn;
1308-
struct page *page;
1308+
13091309
for (pfn = start; pfn < end; pfn++) {
1310-
if (pfn_valid(pfn)) {
1311-
page = pfn_to_page(pfn);
1312-
if (PageLRU(page))
1313-
return pfn;
1314-
if (__PageMovable(page))
1315-
return pfn;
1316-
if (PageHuge(page)) {
1317-
if (hugepage_migration_supported(page_hstate(page)) &&
1318-
page_huge_active(page))
1319-
return pfn;
1320-
else
1321-
pfn = round_up(pfn + 1,
1322-
1 << compound_order(page)) - 1;
1323-
}
1324-
}
1310+
struct page *page, *head;
1311+
unsigned long skip;
1312+
1313+
if (!pfn_valid(pfn))
1314+
continue;
1315+
page = pfn_to_page(pfn);
1316+
if (PageLRU(page))
1317+
return pfn;
1318+
if (__PageMovable(page))
1319+
return pfn;
1320+
1321+
if (!PageHuge(page))
1322+
continue;
1323+
head = compound_head(page);
1324+
if (hugepage_migration_supported(page_hstate(head)) &&
1325+
page_huge_active(head))
1326+
return pfn;
1327+
skip = (1 << compound_order(head)) - (page - head);
1328+
pfn += skip - 1;
13251329
}
13261330
return 0;
13271331
}

0 commit comments

Comments
 (0)