Skip to contentSkip to conversation

mm,memory_hotplug: Fix scan_movable_pages for gigantic hugepages

PATCH Applied Oscar Salvador 5 participants 14 messages Jan 22, 2019 – Jan 30, 2019

Subsystems (2)
lore
Share & tools
lore

Oscar Salvador

author maintainer
#0 lore raw

PATCH 1/1 mm,memory_hotplug: Fix scan_movable_pages for gigantic hugepages

This is the same sort of error we saw in [1].

Gigantic hugepages crosses 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:

kernel: BUG: unable to handle kernel NULL pointer dereference at 0000000000000008
kernel: #PF error: [normal kernel read fault]
kernel: PGD 0 P4D 0
kernel: Oops: 0000 [#1] SMP PTI
kernel: CPU: 1 PID: 1350 Comm: bash Tainted: G            E     5.0.0-rc1-mm1-1-default+ #27
kernel: Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014
kernel: RIP: 0010:__offline_pages+0x6ae/0x900
kernel: Code: 48 c7 c6 d0 3e a4 81 e8 44 c8 ad ff 49 8b 04 24 bf 00 10 00 00 a9 00 00 01 00 74 09 41 0f b6 4c 24 51 48 d3 e7 e8 42 2a c1 ff <8b> 40 08 83 f8 09 0f 84 b0 fc ff ff 83 f8 12 0f 84 a7 fc ff ff 83
kernel: RSP: 0018:ffffc900008e3d20 EFLAGS: 00010246
kernel: RAX: 0000000000000000 RBX: ffffea0000000000 RCX: 0000000000000009
kernel: RDX: ffffffff825c64f0 RSI: 0000000000001000 RDI: 0000000000001000
kernel: RBP: ffffc900008e3d68 R08: 0000000000200000 R09: 00000000000001e4
kernel: R10: 0000000000000058 R11: ffffffff8254a854 R12: ffffea0004200000
kernel: R13: 0000000000108000 R14: 0000000000110000 R15: 0000000000000000
kernel: FS:  00007ff172339b80(0000) GS:ffff88803eb00000(0000) knlGS:0000000000000000
kernel: CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
kernel: CR2: 0000000000000008 CR3: 0000000038d78006 CR4: 00000000003606a0
kernel: DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
kernel: DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
kernel: Call Trace:
kernel:  ? klist_next+0x79/0xe0
kernel:  memory_subsys_offline+0x42/0x60
kernel:  device_offline+0x80/0xa0
kernel:  state_store+0xab/0xc0
kernel:  kernfs_fop_write+0x102/0x180
kernel:  __vfs_write+0x26/0x190
kernel:  ? set_close_on_exec+0x49/0x70
kernel:  vfs_write+0xad/0x1b0
kernel:  ksys_write+0x42/0x90
kernel:  do_syscall_64+0x5b/0x180
kernel:  entry_SYSCALL_64_after_hwframe+0x44/0xa9
kernel: RIP: 0033:0x7ff1719febe4
kernel: Code: 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b7 0f 1f 80 00 00 00 00 8b 05 4a fc 2c 00 48 63 ff 85 c0 75 13 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 f3 c3 66 90 55 53 48 89 d5 48 89 f3 48 83
kernel: RSP: 002b:00007ffd50b7ddc8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
kernel: RAX: ffffffffffffffda RBX: 0000000000000008 RCX: 00007ff1719febe4
kernel: RDX: 0000000000000008 RSI: 00005556e9216b20 RDI: 0000000000000001
kernel: RBP: 00005556e9216b20 R08: 000000000000000a R09: 0000000000000000
kernel: R10: 000000000000000a R11: 0000000000000246 R12: 0000000000000008
kernel: R13: 0000000000000001 R14: 00007ff171cca720 R15: 0000000000000008
kernel: 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)
kernel: CR2: 0000000000000008
kernel: ---[ end trace bdb71590872849fb ]---
kernel: RIP: 0010:__offline_pages+0x6ae/0x900
kernel: Code: 48 c7 c6 d0 3e a4 81 e8 44 c8 ad ff 49 8b 04 24 bf 00 10 00 00 a9 00 00 01 00 74 09 41 0f b6 4c 24 51 48 d3 e7 e8 42 2a c1 ff <8b> 40 08 83 f8 09 0f 84 b0 fc ff ff 83 f8 12 0f 84 a7 fc ff ff 83
kernel: RSP: 0018:ffffc900008e3d20 EFLAGS: 00010246
kernel: RAX: 0000000000000000 RBX: ffffea0000000000 RCX: 0000000000000009
kernel: RDX: ffffffff825c64f0 RSI: 0000000000001000 RDI: 0000000000001000
kernel: RBP: ffffc900008e3d68 R08: 0000000000200000 R09: 00000000000001e4
kernel: R10: 0000000000000058 R11: ffffffff8254a854 R12: ffffea0004200000
kernel: R13: 0000000000108000 R14: 0000000000110000 R15: 0000000000000000
kernel: FS:  00007ff172339b80(0000) GS:ffff88803eb00000(0000) knlGS:0000000000000000
kernel: CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
kernel: CR2: 0000000000000008 CR3: 0000000038d78006 CR4: 00000000003606a0
kernel: DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
kernel: DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400

Fix this by getting the head page and testing against it.

[1] https://patchwork.kernel.org/patch/10739963/

---
 mm/memory_hotplug.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
mm/memory_hotplug.c +10 -5
index ec22c86d9f89..25aee4f04a72 100644
@@ -1335,12 +1335,17 @@ static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
 			if (__PageMovable(page))
 				return pfn;
 			if (PageHuge(page)) {
-				if (hugepage_migration_supported(page_hstate(page)) &&
-				    page_huge_active(page))
+				struct page *head = compound_head(page);
+
+				if (hugepage_migration_supported(page_hstate(head)) &&
+				    page_huge_active(head))
 					return pfn;
-				else
-					pfn = round_up(pfn + 1,
-						1 << compound_order(page)) - 1;
+				else {
+					unsigned long skip;
+
+					skip = (1 << compound_order(head)) - (page - head);
+					pfn += skip - 1;
+				}
 			}
 		}
 	}
Signature · 1 line
2.13.7
Reviewed-by on v1 1/1
#1 lore raw
Quoted 66 lines · Oscar Salvador

This is the same sort of error we saw in [1].

Gigantic hugepages crosses 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:

kernel: BUG: unable to handle kernel NULL pointer dereference at 0000000000000008
kernel: #PF error: [normal kernel read fault]
kernel: PGD 0 P4D 0
kernel: Oops: 0000 [#1] SMP PTI
kernel: CPU: 1 PID: 1350 Comm: bash Tainted: G            E     5.0.0-rc1-mm1-1-default+ #27
kernel: Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014
kernel: RIP: 0010:__offline_pages+0x6ae/0x900
kernel: Code: 48 c7 c6 d0 3e a4 81 e8 44 c8 ad ff 49 8b 04 24 bf 00 10 00 00 a9 00 00 01 00 74 09 41 0f b6 4c 24 51 48 d3 e7 e8 42 2a c1 ff <8b> 40 08 83 f8 09 0f 84 b0 fc ff ff 83 f8 12 0f 84 a7 fc ff ff 83
kernel: RSP: 0018:ffffc900008e3d20 EFLAGS: 00010246
kernel: RAX: 0000000000000000 RBX: ffffea0000000000 RCX: 0000000000000009
kernel: RDX: ffffffff825c64f0 RSI: 0000000000001000 RDI: 0000000000001000
kernel: RBP: ffffc900008e3d68 R08: 0000000000200000 R09: 00000000000001e4
kernel: R10: 0000000000000058 R11: ffffffff8254a854 R12: ffffea0004200000
kernel: R13: 0000000000108000 R14: 0000000000110000 R15: 0000000000000000
kernel: FS:  00007ff172339b80(0000) GS:ffff88803eb00000(0000) knlGS:0000000000000000
kernel: CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
kernel: CR2: 0000000000000008 CR3: 0000000038d78006 CR4: 00000000003606a0
kernel: DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
kernel: DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
kernel: Call Trace:
kernel:  ? klist_next+0x79/0xe0
kernel:  memory_subsys_offline+0x42/0x60
kernel:  device_offline+0x80/0xa0
kernel:  state_store+0xab/0xc0
kernel:  kernfs_fop_write+0x102/0x180
kernel:  __vfs_write+0x26/0x190
kernel:  ? set_close_on_exec+0x49/0x70
kernel:  vfs_write+0xad/0x1b0
kernel:  ksys_write+0x42/0x90
kernel:  do_syscall_64+0x5b/0x180
kernel:  entry_SYSCALL_64_after_hwframe+0x44/0xa9
kernel: RIP: 0033:0x7ff1719febe4
kernel: Code: 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b7 0f 1f 80 00 00 00 00 8b 05 4a fc 2c 00 48 63 ff 85 c0 75 13 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 f3 c3 66 90 55 53 48 89 d5 48 89 f3 48 83
kernel: RSP: 002b:00007ffd50b7ddc8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
kernel: RAX: ffffffffffffffda RBX: 0000000000000008 RCX: 00007ff1719febe4
kernel: RDX: 0000000000000008 RSI: 00005556e9216b20 RDI: 0000000000000001
kernel: RBP: 00005556e9216b20 R08: 000000000000000a R09: 0000000000000000
kernel: R10: 000000000000000a R11: 0000000000000246 R12: 0000000000000008
kernel: R13: 0000000000000001 R14: 00007ff171cca720 R15: 0000000000000008
kernel: 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)
kernel: CR2: 0000000000000008
kernel: ---[ end trace bdb71590872849fb ]---
kernel: RIP: 0010:__offline_pages+0x6ae/0x900
kernel: Code: 48 c7 c6 d0 3e a4 81 e8 44 c8 ad ff 49 8b 04 24 bf 00 10 00 00 a9 00 00 01 00 74 09 41 0f b6 4c 24 51 48 d3 e7 e8 42 2a c1 ff <8b> 40 08 83 f8 09 0f 84 b0 fc ff ff 83 f8 12 0f 84 a7 fc ff ff 83
kernel: RSP: 0018:ffffc900008e3d20 EFLAGS: 00010246
kernel: RAX: 0000000000000000 RBX: ffffea0000000000 RCX: 0000000000000009
kernel: RDX: ffffffff825c64f0 RSI: 0000000000001000 RDI: 0000000000001000
kernel: RBP: ffffc900008e3d68 R08: 0000000000200000 R09: 00000000000001e4
kernel: R10: 0000000000000058 R11: ffffffff8254a854 R12: ffffea0004200000
kernel: R13: 0000000000108000 R14: 0000000000110000 R15: 0000000000000000
kernel: FS:  00007ff172339b80(0000) GS:ffff88803eb00000(0000) knlGS:0000000000000000
kernel: CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
kernel: CR2: 0000000000000008 CR3: 0000000038d78006 CR4: 00000000003606a0
kernel: DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
kernel: DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Quoted 5 lines

Fix this by getting the head page and testing against it.

[1] https://patchwork.kernel.org/patch/10739963/

Looks good.

Quoted 31 lines
---
 mm/memory_hotplug.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
mm/memory_hotplug.c +10 -5
index ec22c86d9f89..25aee4f04a72 100644
@@ -1335,12 +1335,17 @@ static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
 			if (__PageMovable(page))
 				return pfn;
 			if (PageHuge(page)) {
-				if (hugepage_migration_supported(page_hstate(page)) &&
-				    page_huge_active(page))
+				struct page *head = compound_head(page);
+
+				if (hugepage_migration_supported(page_hstate(head)) &&
+				    page_huge_active(head))
 					return pfn;
-				else
-					pfn = round_up(pfn + 1,
-						1 << compound_order(page)) - 1;
+				else {
+					unsigned long skip;
+
+					skip = (1 << compound_order(head)) - (page - head);
+					pfn += skip - 1;
+				}
 			}
 		}
 	}
Acked-by on v1 1/1
#2 lore raw
In reply to Oscar Salvador
Quoted 66 lines · Oscar Salvador

This is the same sort of error we saw in [1].

Gigantic hugepages crosses 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:

kernel: BUG: unable to handle kernel NULL pointer dereference at 0000000000000008
kernel: #PF error: [normal kernel read fault]
kernel: PGD 0 P4D 0
kernel: Oops: 0000 [#1] SMP PTI
kernel: CPU: 1 PID: 1350 Comm: bash Tainted: G            E     5.0.0-rc1-mm1-1-default+ #27
kernel: Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014
kernel: RIP: 0010:__offline_pages+0x6ae/0x900
kernel: Code: 48 c7 c6 d0 3e a4 81 e8 44 c8 ad ff 49 8b 04 24 bf 00 10 00 00 a9 00 00 01 00 74 09 41 0f b6 4c 24 51 48 d3 e7 e8 42 2a c1 ff <8b> 40 08 83 f8 09 0f 84 b0 fc ff ff 83 f8 12 0f 84 a7 fc ff ff 83
kernel: RSP: 0018:ffffc900008e3d20 EFLAGS: 00010246
kernel: RAX: 0000000000000000 RBX: ffffea0000000000 RCX: 0000000000000009
kernel: RDX: ffffffff825c64f0 RSI: 0000000000001000 RDI: 0000000000001000
kernel: RBP: ffffc900008e3d68 R08: 0000000000200000 R09: 00000000000001e4
kernel: R10: 0000000000000058 R11: ffffffff8254a854 R12: ffffea0004200000
kernel: R13: 0000000000108000 R14: 0000000000110000 R15: 0000000000000000
kernel: FS:  00007ff172339b80(0000) GS:ffff88803eb00000(0000) knlGS:0000000000000000
kernel: CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
kernel: CR2: 0000000000000008 CR3: 0000000038d78006 CR4: 00000000003606a0
kernel: DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
kernel: DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
kernel: Call Trace:
kernel:  ? klist_next+0x79/0xe0
kernel:  memory_subsys_offline+0x42/0x60
kernel:  device_offline+0x80/0xa0
kernel:  state_store+0xab/0xc0
kernel:  kernfs_fop_write+0x102/0x180
kernel:  __vfs_write+0x26/0x190
kernel:  ? set_close_on_exec+0x49/0x70
kernel:  vfs_write+0xad/0x1b0
kernel:  ksys_write+0x42/0x90
kernel:  do_syscall_64+0x5b/0x180
kernel:  entry_SYSCALL_64_after_hwframe+0x44/0xa9
kernel: RIP: 0033:0x7ff1719febe4
kernel: Code: 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b7 0f 1f 80 00 00 00 00 8b 05 4a fc 2c 00 48 63 ff 85 c0 75 13 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 f3 c3 66 90 55 53 48 89 d5 48 89 f3 48 83
kernel: RSP: 002b:00007ffd50b7ddc8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
kernel: RAX: ffffffffffffffda RBX: 0000000000000008 RCX: 00007ff1719febe4
kernel: RDX: 0000000000000008 RSI: 00005556e9216b20 RDI: 0000000000000001
kernel: RBP: 00005556e9216b20 R08: 000000000000000a R09: 0000000000000000
kernel: R10: 000000000000000a R11: 0000000000000246 R12: 0000000000000008
kernel: R13: 0000000000000001 R14: 00007ff171cca720 R15: 0000000000000008
kernel: 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)
kernel: CR2: 0000000000000008
kernel: ---[ end trace bdb71590872849fb ]---
kernel: RIP: 0010:__offline_pages+0x6ae/0x900
kernel: Code: 48 c7 c6 d0 3e a4 81 e8 44 c8 ad ff 49 8b 04 24 bf 00 10 00 00 a9 00 00 01 00 74 09 41 0f b6 4c 24 51 48 d3 e7 e8 42 2a c1 ff <8b> 40 08 83 f8 09 0f 84 b0 fc ff ff 83 f8 12 0f 84 a7 fc ff ff 83
kernel: RSP: 0018:ffffc900008e3d20 EFLAGS: 00010246
kernel: RAX: 0000000000000000 RBX: ffffea0000000000 RCX: 0000000000000009
kernel: RDX: ffffffff825c64f0 RSI: 0000000000001000 RDI: 0000000000001000
kernel: RBP: ffffc900008e3d68 R08: 0000000000200000 R09: 00000000000001e4
kernel: R10: 0000000000000058 R11: ffffffff8254a854 R12: ffffea0004200000
kernel: R13: 0000000000108000 R14: 0000000000110000 R15: 0000000000000000
kernel: FS:  00007ff172339b80(0000) GS:ffff88803eb00000(0000) knlGS:0000000000000000
kernel: CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
kernel: CR2: 0000000000000008 CR3: 0000000038d78006 CR4: 00000000003606a0
kernel: DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
kernel: DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Quoted 3 lines

Fix this by getting the head page and testing against it.

[1] https://patchwork.kernel.org/patch/10739963/

So this should be probably folded into the above patch as it is incomplete unless I am missing something.

Quoted 1 line

Other than that the change looks good to me.

Quoted 33 lines
---
 mm/memory_hotplug.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
mm/memory_hotplug.c +10 -5
index ec22c86d9f89..25aee4f04a72 100644
@@ -1335,12 +1335,17 @@ static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
 			if (__PageMovable(page))
 				return pfn;
 			if (PageHuge(page)) {
-				if (hugepage_migration_supported(page_hstate(page)) &&
-				    page_huge_active(page))
+				struct page *head = compound_head(page);
+
+				if (hugepage_migration_supported(page_hstate(head)) &&
+				    page_huge_active(head))
 					return pfn;
-				else
-					pfn = round_up(pfn + 1,
-						1 << compound_order(page)) - 1;
+				else {
+					unsigned long skip;
+
+					skip = (1 << compound_order(head)) - (page - head);
+					pfn += skip - 1;
+				}
 			}
 		}
 	}
Signature · 1 line
2.13.7
Signature · 2 lines
Michal Hocko
SUSE Labs
author maintainer
#3 lore raw
Quoted 2 lines · Michal Hocko

So this should be probably folded into the above patch as it is incomplete unless I am missing something.

Well, they are triggered from different paths.
The former error was triggered in:

removable_show
is_mem_section_removable
is_pageblock_removable_nolock
has_unmovable_pages

while this one is triggered when actually doing the offline operation

__offline_pages
scan_movable_pages

But I do agree that one without the other is not really useful, an incomplete. The truth is that I did not spot this one when fixing [1] because I did not really try to offline the memblock back then, so my fault.

While I agree that the best approach would be to fold this one into [1], I am not sure if it is too late for that as it seems that [1] was already released into mainline, and moreover to stable.

I guess I will have Andrew decide what is the best way to carry on here.

[1] https://patchwork.kernel.org/patch/10739963/

Quoted 6 lines
Quoted 2 lines

Other than that the change looks good to me.

Thanks!

Signature · 2 lines
Oscar Salvador
SUSE L3
#4 lore raw
Quoted 7 lines · Oscar Salvador
Quoted 2 lines · Michal Hocko

So this should be probably folded into the above patch as it is incomplete unless I am missing something.

Well, they are triggered from different paths.
The former error was triggered in:

Quoted 6 lines

removable_show
is_mem_section_removable
is_pageblock_removable_nolock
has_unmovable_pages

while this one is triggered when actually doing the offline operation

But it would trigger from the offline path as well, no?

Quoted 6 lines

__offline_pages
scan_movable_pages

But I do agree that one without the other is not really useful, an incomplete. The truth is that I did not spot this one when fixing [1] because I did not really try to offline the memblock back then, so my fault.

I should have noticed that during the review but those paths are really far away from each other so this is hard to spot indeed

Quoted 3 lines

While I agree that the best approach would be to fold this one into [1], I am not sure if it is too late for that as it seems that [1] was already released into mainline, and moreover to stable.

OK, I wasn't aware of that. Then my suggestion is clearly moot.

Quoted 15 lines

I guess I will have Andrew decide what is the best way to carry on here.

[1] https://patchwork.kernel.org/patch/10739963/

Quoted 6 lines
Quoted 2 lines

Other than that the change looks good to me.

Thanks!

Signature · 2 lines
Oscar Salvador
SUSE L3
Signature · 2 lines
Michal Hocko
SUSE Labs
Reviewed-by on v1 1/1
#5 lore raw
In reply to Oscar Salvador
Quoted 84 lines · Oscar Salvador

This is the same sort of error we saw in [1].

Gigantic hugepages crosses 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:

kernel: BUG: unable to handle kernel NULL pointer dereference at 0000000000000008
kernel: #PF error: [normal kernel read fault]
kernel: PGD 0 P4D 0
kernel: Oops: 0000 [#1] SMP PTI
kernel: CPU: 1 PID: 1350 Comm: bash Tainted: G            E     5.0.0-rc1-mm1-1-default+ #27
kernel: Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.0.0-prebuilt.qemu-project.org 04/01/2014
kernel: RIP: 0010:__offline_pages+0x6ae/0x900
kernel: Code: 48 c7 c6 d0 3e a4 81 e8 44 c8 ad ff 49 8b 04 24 bf 00 10 00 00 a9 00 00 01 00 74 09 41 0f b6 4c 24 51 48 d3 e7 e8 42 2a c1 ff <8b> 40 08 83 f8 09 0f 84 b0 fc ff ff 83 f8 12 0f 84 a7 fc ff ff 83
kernel: RSP: 0018:ffffc900008e3d20 EFLAGS: 00010246
kernel: RAX: 0000000000000000 RBX: ffffea0000000000 RCX: 0000000000000009
kernel: RDX: ffffffff825c64f0 RSI: 0000000000001000 RDI: 0000000000001000
kernel: RBP: ffffc900008e3d68 R08: 0000000000200000 R09: 00000000000001e4
kernel: R10: 0000000000000058 R11: ffffffff8254a854 R12: ffffea0004200000
kernel: R13: 0000000000108000 R14: 0000000000110000 R15: 0000000000000000
kernel: FS:  00007ff172339b80(0000) GS:ffff88803eb00000(0000) knlGS:0000000000000000
kernel: CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
kernel: CR2: 0000000000000008 CR3: 0000000038d78006 CR4: 00000000003606a0
kernel: DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
kernel: DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
kernel: Call Trace:
kernel:  ? klist_next+0x79/0xe0
kernel:  memory_subsys_offline+0x42/0x60
kernel:  device_offline+0x80/0xa0
kernel:  state_store+0xab/0xc0
kernel:  kernfs_fop_write+0x102/0x180
kernel:  __vfs_write+0x26/0x190
kernel:  ? set_close_on_exec+0x49/0x70
kernel:  vfs_write+0xad/0x1b0
kernel:  ksys_write+0x42/0x90
kernel:  do_syscall_64+0x5b/0x180
kernel:  entry_SYSCALL_64_after_hwframe+0x44/0xa9
kernel: RIP: 0033:0x7ff1719febe4
kernel: Code: 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b7 0f 1f 80 00 00 00 00 8b 05 4a fc 2c 00 48 63 ff 85 c0 75 13 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 f3 c3 66 90 55 53 48 89 d5 48 89 f3 48 83
kernel: RSP: 002b:00007ffd50b7ddc8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
kernel: RAX: ffffffffffffffda RBX: 0000000000000008 RCX: 00007ff1719febe4
kernel: RDX: 0000000000000008 RSI: 00005556e9216b20 RDI: 0000000000000001
kernel: RBP: 00005556e9216b20 R08: 000000000000000a R09: 0000000000000000
kernel: R10: 000000000000000a R11: 0000000000000246 R12: 0000000000000008
kernel: R13: 0000000000000001 R14: 00007ff171cca720 R15: 0000000000000008
kernel: 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)
kernel: CR2: 0000000000000008
kernel: ---[ end trace bdb71590872849fb ]---
kernel: RIP: 0010:__offline_pages+0x6ae/0x900
kernel: Code: 48 c7 c6 d0 3e a4 81 e8 44 c8 ad ff 49 8b 04 24 bf 00 10 00 00 a9 00 00 01 00 74 09 41 0f b6 4c 24 51 48 d3 e7 e8 42 2a c1 ff <8b> 40 08 83 f8 09 0f 84 b0 fc ff ff 83 f8 12 0f 84 a7 fc ff ff 83
kernel: RSP: 0018:ffffc900008e3d20 EFLAGS: 00010246
kernel: RAX: 0000000000000000 RBX: ffffea0000000000 RCX: 0000000000000009
kernel: RDX: ffffffff825c64f0 RSI: 0000000000001000 RDI: 0000000000001000
kernel: RBP: ffffc900008e3d68 R08: 0000000000200000 R09: 00000000000001e4
kernel: R10: 0000000000000058 R11: ffffffff8254a854 R12: ffffea0004200000
kernel: R13: 0000000000108000 R14: 0000000000110000 R15: 0000000000000000
kernel: FS:  00007ff172339b80(0000) GS:ffff88803eb00000(0000) knlGS:0000000000000000
kernel: CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
kernel: CR2: 0000000000000008 CR3: 0000000038d78006 CR4: 00000000003606a0
kernel: DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
kernel: DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400

Fix this by getting the head page and testing against it.

[1] https://patchwork.kernel.org/patch/10739963/

---
 mm/memory_hotplug.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
mm/memory_hotplug.c +0 -1
index ec22c86d9f89..25aee4f04a72 100644
@@ -1335,12 +1335,17 @@ static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
 			if (__PageMovable(page))
 				return pfn;
 			if (PageHuge(page)) {
-				if (hugepage_migration_supported(page_hstate(page)) &&

mm/memory_hotplug.c static unsigned long scan_movable_pages(unsigned long start, unsigned long end) · line 1343

Quoted 10 lines
mm/memory_hotplug.c +5 -4
-				    page_huge_active(page))
+				struct page *head = compound_head(page);
+
+				if (hugepage_migration_supported(page_hstate(head)) &&
+				    page_huge_active(head))
 					return pfn;
-				else
-					pfn = round_up(pfn + 1,
-						1 << compound_order(page)) - 1;
+				else {

If you use {} for the else case, please also do so for the if case.

Apart from that this looks good to me

Quoted 9 lines
mm/memory_hotplug.c +5 -0
+					unsigned long skip;
+
+					skip = (1 << compound_order(head)) - (page - head);
+					pfn += skip - 1;
+				}
 			}
 		}
 	}
Signature · 3 lines
Thanks,

David / dhildenb
author maintainer
#6 lore raw
Quoted 1 line · David Hildenbrand

If you use {} for the else case, please also do so for the if case.

Diff on top:

mm/memory_hotplug.c +2 -2
index 25aee4f04a72..d5810e522b72 100644
@@ -1338,9 +1338,9 @@ static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
 				struct page *head = compound_head(page);
 
 				if (hugepage_migration_supported(page_hstate(head)) &&
-				    page_huge_active(head))
+				    page_huge_active(head)) {
 					return pfn;
-				else {
+				} else {
 					unsigned long skip;
 
 					skip = (1 << compound_order(head)) - (page - head);
Quoted 3 lines

Apart from that this looks good to me

Thanks David ;-)

Signature · 2 lines
Oscar Salvador
SUSE L3
maintainer
#7 lore raw
Quoted 12 lines · On Fri, 25 Jan 2019 08:58:33 +0100 Oscar Salvador <[email protected]> wrote:
Quoted 1 line · David Hildenbrand

If you use {} for the else case, please also do so for the if case.

Diff on top:

mm/memory_hotplug.c +0 -0
index 25aee4f04a72..d5810e522b72 100644
@@ -1338,9 +1338,9 @@ static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
 				struct page *head = compound_head(page);

mm/memory_hotplug.c static unsigned long scan_movable_pages(unsigned long start, unsigned long end) · line 1346

Quoted 10 lines
mm/memory_hotplug.c +2 -2
 
 				if (hugepage_migration_supported(page_hstate(head)) &&
-				    page_huge_active(head))
+				    page_huge_active(head)) {
 					return pfn;
-				else {
+				} else {
 					unsigned long skip;
 
 					skip = (1 << compound_order(head)) - (page - head);

The indenting is getting a bit deep also, so how about this?

static unsigned long scan_movable_pages(unsigned long start, unsigned long end)

{
	unsigned long pfn;

	for (pfn = start; pfn < end; pfn++) {
		struct page *page, *head;
	
		if (!pfn_valid(pfn))
			continue;
		page = pfn_to_page(pfn);
		if (PageLRU(page))
			return pfn;
		if (__PageMovable(page))
			return pfn;

		if (!PageHuge(page))
			continue;
		head = compound_head(page);
		if (hugepage_migration_supported(page_hstate(head)) &&
		    page_huge_active(head)) {
			return pfn;
		} else {
			unsigned long skip;

			skip = (1 << compound_order(head)) - (page - head);
			pfn += skip - 1;
		}
	}
	return 0;
}

From: Andrew Morton <[email protected]>
Subject: mmmemory_hotplug-fix-scan_movable_pages-for-gigantic-hugepages-fix

fix brace layout, per David. Also reduce indentation

Cc Anthony Yznaga <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Oscar Salvador <[email protected]>

---

 mm/memory_hotplug.c |   38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mmmemory_hotplug-fix-scan_movable_pages-for-gigantic-hugepages-fix +20 -18
@@ -1305,27 +1305,29 @@ int test_pages_in_a_zone(unsigned long s
 static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
 {
 	unsigned long pfn;
-	struct page *page;
+
 	for (pfn = start; pfn < end; pfn++) {
-		if (pfn_valid(pfn)) {
-			page = pfn_to_page(pfn);
-			if (PageLRU(page))
-				return pfn;
-			if (__PageMovable(page))
-				return pfn;
-			if (PageHuge(page)) {
-				struct page *head = compound_head(page);
+		struct page *page, *head;
+	
+		if (!pfn_valid(pfn))
+			continue;
+		page = pfn_to_page(pfn);
+		if (PageLRU(page))
+			return pfn;
+		if (__PageMovable(page))
+			return pfn;
 
-				if (hugepage_migration_supported(page_hstate(head)) &&
-				    page_huge_active(head))
-					return pfn;
-				else {
-					unsigned long skip;
+		if (!PageHuge(page))
+			continue;
+		head = compound_head(page);
+		if (hugepage_migration_supported(page_hstate(head)) &&
+		    page_huge_active(head)) {
+			return pfn;
+		} else {
+			unsigned long skip;
 
-					skip = (1 << compound_order(head)) - (page - head);
-					pfn += skip - 1;
-				}
-			}
+			skip = (1 << compound_order(head)) - (page - head);
+			pfn += skip - 1;
 		}
 	}
 	return 0;

_

maintainer
#8 lore raw
Quoted 40 lines · On Mon, 28 Jan 2019 14:53:09 -0800 Andrew Morton <[email protected]>…
Quoted 12 lines · On Fri, 25 Jan 2019 08:58:33 +0100 Oscar Salvador <[email protected]> wrote:
Quoted 1 line · David Hildenbrand

If you use {} for the else case, please also do so for the if case.

Diff on top:

mm/memory_hotplug.c +0 -0
index 25aee4f04a72..d5810e522b72 100644
@@ -1338,9 +1338,9 @@ static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
 				struct page *head = compound_head(page);

mm/memory_hotplug.c static unsigned long scan_movable_pages(unsigned long start, unsigned long end) · line 1346

Quoted 10 lines
mm/memory_hotplug.c +2 -2
 
 				if (hugepage_migration_supported(page_hstate(head)) &&
-				    page_huge_active(head))
+				    page_huge_active(head)) {
 					return pfn;
-				else {
+				} else {
 					unsigned long skip;
 
 					skip = (1 << compound_order(head)) - (page - head);

The indenting is getting a bit deep also, so how about this?

static unsigned long scan_movable_pages(unsigned long start, unsigned long end)

{
	unsigned long pfn;

	for (pfn = start; pfn < end; pfn++) {
		struct page *page, *head;
	
		if (!pfn_valid(pfn))
			continue;
		page = pfn_to_page(pfn);
		if (PageLRU(page))
			return pfn;
		if (__PageMovable(page))
Quoted 8 lines
			return pfn;

		if (!PageHuge(page))
			continue;
		head = compound_head(page);
		if (hugepage_migration_supported(page_hstate(head)) &&
		    page_huge_active(head)) {
			return pfn;

checkpatch pointed out that else-after-return isn't needed so we can do

static unsigned long scan_movable_pages(unsigned long start, unsigned long end)

{
	unsigned long pfn;

	for (pfn = start; pfn < end; pfn++) {
		struct page *page, *head;
		unsigned long skip;

		if (!pfn_valid(pfn))
			continue;
		page = pfn_to_page(pfn);
		if (PageLRU(page))
			return pfn;
		if (__PageMovable(page))
			return pfn;

		if (!PageHuge(page))
			continue;
		head = compound_head(page);
		if (hugepage_migration_supported(page_hstate(head)) &&
		    page_huge_active(head))
			return pfn;
		skip = (1 << compound_order(head)) - (page - head);
		pfn += skip - 1;
	}
	return 0;
}
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mmmemory_hotplug-fix-scan_movable_pages-for-gigantic-hugepages-fix +18 -19
@@ -1305,28 +1305,27 @@ int test_pages_in_a_zone(unsigned long s
 static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
 {
 	unsigned long pfn;
-	struct page *page;
+
 	for (pfn = start; pfn < end; pfn++) {
-		if (pfn_valid(pfn)) {
-			page = pfn_to_page(pfn);
-			if (PageLRU(page))
-				return pfn;
-			if (__PageMovable(page))
-				return pfn;
-			if (PageHuge(page)) {
-				struct page *head = compound_head(page);
+		struct page *page, *head;
+		unsigned long skip;
 
-				if (hugepage_migration_supported(page_hstate(head)) &&
-				    page_huge_active(head))
-					return pfn;
-				else {
-					unsigned long skip;
+		if (!pfn_valid(pfn))
+			continue;
+		page = pfn_to_page(pfn);
+		if (PageLRU(page))
+			return pfn;
+		if (__PageMovable(page))
+			return pfn;
 
-					skip = (1 << compound_order(head)) - (page - head);
-					pfn += skip - 1;
-				}
-			}
-		}
+		if (!PageHuge(page))
+			continue;
+		head = compound_head(page);
+		if (hugepage_migration_supported(page_hstate(head)) &&
+		    page_huge_active(head))
+			return pfn;
+		skip = (1 << compound_order(head)) - (page - head);
+		pfn += skip - 1;
 	}
 	return 0;
 }

_

#9 lore raw

On Mon 28-01-19 14:56:17, Andrew Morton wrote:
[...]

Quoted 49 lines
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mmmemory_hotplug-fix-scan_movable_pages-for-gigantic-hugepages-fix +18 -19
@@ -1305,28 +1305,27 @@ int test_pages_in_a_zone(unsigned long s
 static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
 {
 	unsigned long pfn;
-	struct page *page;
+
 	for (pfn = start; pfn < end; pfn++) {
-		if (pfn_valid(pfn)) {
-			page = pfn_to_page(pfn);
-			if (PageLRU(page))
-				return pfn;
-			if (__PageMovable(page))
-				return pfn;
-			if (PageHuge(page)) {
-				struct page *head = compound_head(page);
+		struct page *page, *head;
+		unsigned long skip;
 
-				if (hugepage_migration_supported(page_hstate(head)) &&
-				    page_huge_active(head))
-					return pfn;
-				else {
-					unsigned long skip;
+		if (!pfn_valid(pfn))
+			continue;
+		page = pfn_to_page(pfn);
+		if (PageLRU(page))
+			return pfn;
+		if (__PageMovable(page))
+			return pfn;
 
-					skip = (1 << compound_order(head)) - (page - head);
-					pfn += skip - 1;
-				}
-			}
-		}
+		if (!PageHuge(page))
+			continue;
+		head = compound_head(page);
+		if (hugepage_migration_supported(page_hstate(head)) &&
+		    page_huge_active(head))
+			return pfn;
+		skip = (1 << compound_order(head)) - (page - head);
+		pfn += skip - 1;
 	}
 	return 0;
 }
Quoted 2 lines

_

LGTM

Signature · 2 lines
Michal Hocko
SUSE Labs
author maintainer
#10 lore raw
In reply to Andrew Morton
Quoted 40 lines · Andrew Morton
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mmmemory_hotplug-fix-scan_movable_pages-for-gigantic-hugepages-fix +11 -19
@@ -1305,28 +1305,27 @@ int test_pages_in_a_zone(unsigned long s
 static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
 {
 	unsigned long pfn;
-	struct page *page;
+
 	for (pfn = start; pfn < end; pfn++) {
-		if (pfn_valid(pfn)) {
-			page = pfn_to_page(pfn);
-			if (PageLRU(page))
-				return pfn;
-			if (__PageMovable(page))
-				return pfn;
-			if (PageHuge(page)) {
-				struct page *head = compound_head(page);
+		struct page *page, *head;
+		unsigned long skip;
 
-				if (hugepage_migration_supported(page_hstate(head)) &&
-				    page_huge_active(head))
-					return pfn;
-				else {
-					unsigned long skip;
+		if (!pfn_valid(pfn))
+			continue;
+		page = pfn_to_page(pfn);
+		if (PageLRU(page))
+			return pfn;
+		if (__PageMovable(page))
+			return pfn;
 
-					skip = (1 << compound_order(head)) - (page - head);
-					pfn += skip - 1;
-				}
-			}
-		}
+		if (!PageHuge(page))

mm/memory_hotplug.c int test_pages_in_a_zone(unsigned long s · line 1331

Quoted 10 lines
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mmmemory_hotplug-fix-scan_movable_pages-for-gigantic-hugepages-fix +7 -0
+			continue;
+		head = compound_head(page);
+		if (hugepage_migration_supported(page_hstate(head)) &&
+		    page_huge_active(head))
+			return pfn;
+		skip = (1 << compound_order(head)) - (page - head);
+		pfn += skip - 1;
 	}
 	return 0;
 }

It looks much better, thanks a lot for the cleanup Andrew!

Signature · 2 lines
Oscar Salvador
SUSE L3
#11 lore raw
In reply to Andrew Morton
Quoted 117 lines · Andrew Morton
Quoted 40 lines · On Mon, 28 Jan 2019 14:53:09 -0800 Andrew Morton <[email protected]>…
Quoted 12 lines · On Fri, 25 Jan 2019 08:58:33 +0100 Oscar Salvador <[email protected]> wrote:
Quoted 1 line · David Hildenbrand

If you use {} for the else case, please also do so for the if case.

Diff on top:

mm/memory_hotplug.c +0 -0
index 25aee4f04a72..d5810e522b72 100644
@@ -1338,9 +1338,9 @@ static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
 				struct page *head = compound_head(page);

mm/memory_hotplug.c static unsigned long scan_movable_pages(unsigned long start, unsigned long end) · line 1346

Quoted 10 lines
mm/memory_hotplug.c +2 -2
 
 				if (hugepage_migration_supported(page_hstate(head)) &&
-				    page_huge_active(head))
+				    page_huge_active(head)) {
 					return pfn;
-				else {
+				} else {
 					unsigned long skip;
 
 					skip = (1 << compound_order(head)) - (page - head);

The indenting is getting a bit deep also, so how about this?

static unsigned long scan_movable_pages(unsigned long start, unsigned long end)

{
	unsigned long pfn;

	for (pfn = start; pfn < end; pfn++) {
		struct page *page, *head;
	
		if (!pfn_valid(pfn))
			continue;
		page = pfn_to_page(pfn);
		if (PageLRU(page))
			return pfn;
		if (__PageMovable(page))
Quoted 8 lines
			return pfn;

		if (!PageHuge(page))
			continue;
		head = compound_head(page);
		if (hugepage_migration_supported(page_hstate(head)) &&
		    page_huge_active(head)) {
			return pfn;

checkpatch pointed out that else-after-return isn't needed so we can do

static unsigned long scan_movable_pages(unsigned long start, unsigned long end)

{
	unsigned long pfn;

	for (pfn = start; pfn < end; pfn++) {
		struct page *page, *head;
		unsigned long skip;

		if (!pfn_valid(pfn))
			continue;
		page = pfn_to_page(pfn);
		if (PageLRU(page))
			return pfn;
		if (__PageMovable(page))
			return pfn;

		if (!PageHuge(page))
			continue;
		head = compound_head(page);
		if (hugepage_migration_supported(page_hstate(head)) &&
		    page_huge_active(head))
			return pfn;
		skip = (1 << compound_order(head)) - (page - head);
		pfn += skip - 1;
	}
	return 0;
}
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mmmemory_hotplug-fix-scan_movable_pages-for-gigantic-hugepages-fix +10 -17
@@ -1305,28 +1305,27 @@ int test_pages_in_a_zone(unsigned long s
 static unsigned long scan_movable_pages(unsigned long start, unsigned long end)
 {
 	unsigned long pfn;
-	struct page *page;
+
 	for (pfn = start; pfn < end; pfn++) {
-		if (pfn_valid(pfn)) {
-			page = pfn_to_page(pfn);
-			if (PageLRU(page))
-				return pfn;
-			if (__PageMovable(page))
-				return pfn;
-			if (PageHuge(page)) {
-				struct page *head = compound_head(page);
+		struct page *page, *head;
+		unsigned long skip;
 
-				if (hugepage_migration_supported(page_hstate(head)) &&
-				    page_huge_active(head))
-					return pfn;
-				else {
-					unsigned long skip;
+		if (!pfn_valid(pfn))
+			continue;
+		page = pfn_to_page(pfn);
+		if (PageLRU(page))
+			return pfn;
+		if (__PageMovable(page))
+			return pfn;
 
-					skip = (1 << compound_order(head)) - (page - head);
-					pfn += skip - 1;
-				}

mm/memory_hotplug.c int test_pages_in_a_zone(unsigned long s · line 1328

Quoted 10 lines
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mmmemory_hotplug-fix-scan_movable_pages-for-gigantic-hugepages-fix +8 -2
-			}
-		}
+		if (!PageHuge(page))
+			continue;
+		head = compound_head(page);
+		if (hugepage_migration_supported(page_hstate(head)) &&
+		    page_huge_active(head))
+			return pfn;
+		skip = (1 << compound_order(head)) - (page - head);
+		pfn += skip - 1;

Not sure if encoding the -1 in the previous line is even better now that we have more space

skip = (1 << compound_order(head)) - (page - head + 1);

Looks good to me.

Quoted 5 lines
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mmmemory_hotplug-fix-scan_movable_pages-for-gigantic-hugepages-fix +0 -0
 	}
 	return 0;
 }

_

Signature · 3 lines
Thanks,

David / dhildenb
author maintainer
#12 lore raw
Quoted 8 lines · David Hildenbrand

Not sure if encoding the -1 in the previous line is even better now that we have more space

skip = (1 << compound_order(head)) - (page - head + 1);

Looks good to me.

Quoted 1 line

}

I would rather not do that.
For me looks a bit "subtle" why do we add up 1 after substracting page - head. I think that doing "skip - 1" looks more clear, but I do not have a strong opinion here.

Signature · 2 lines
Oscar Salvador
SUSE L3