"Shrink zones before removing memory" causes kernel panic with kpagecount

From: Qian Cai
Date: Tue Oct 08 2019 - 16:18:23 EST


The linux-next series "mm/memory_hotplug: Shrink zones before removing memory"
[1] causes a kernel panic while reading /proc/kpagecount after offlining a
memory section. It was reproduced on both x86 and powerpc. Reverted the whole
series fixed the problem.

[1] https://lore.kernel.org/linux-mm/20191006085646.5768-1-david@xxxxxxxxxx/

#Âecho offline > /sys/devices/system/memory/memory124/stateÂ
# cat /proc/kpagecount

[ÂÂ133.268032][ T8809] remove from free list 7c000 256 7d000
[ÂÂ133.268134][ T8809] remove from free list 7c100 256 7d000
[ÂÂ133.268153][ T8809] remove from free list 7c200 256 7d000
[ÂÂ133.268182][ T8809] remove from free list 7c300 256 7d000
[ÂÂ133.268212][ T8809] remove from free list 7c400 256 7d000
[ÂÂ133.268241][ T8809] remove from free list 7c500 256 7d000
[ÂÂ133.268260][ T8809] remove from free list 7c600 256 7d000
[ÂÂ133.268289][ T8809] remove from free list 7c700 256 7d000
[ÂÂ133.268329][ T8809] remove from free list 7c800 256 7d000
[ÂÂ133.268359][ T8809] remove from free list 7c900 256 7d000
[ÂÂ133.268399][ T8809] remove from free list 7ca00 256 7d000
[ÂÂ133.268429][ T8809] remove from free list 7cb00 256 7d000
[ÂÂ133.268458][ T8809] remove from free list 7cc00 256 7d000
[ÂÂ133.268488][ T8809] remove from free list 7cd00 256 7d000
[ÂÂ133.268517][ T8809] remove from free list 7ce00 256 7d000
[ÂÂ133.268546][ T8809] remove from free list 7cf00 256 7d000
[ÂÂ133.268580][ T8809] Offlined Pages 4096
[ÂÂ144.038732][ T8944] BUG: Unable to handle kernel data access at
0xfffffffffffffffe
[ÂÂ144.038769][ T8944] Faulting instruction address: 0xc000000000590c08
[ÂÂ144.038794][ T8944] Oops: Kernel access of bad area, sig: 11 [#1]
[ÂÂ144.038807][ T8944] LE PAGE_SIZE=64K MMU=Radix MMU=Hash SMP NR_CPUS=256
DEBUG_PAGEALLOC NUMA PowerNV
[ÂÂ144.038822][ T8944] Modules linked in: ip_tables x_tables xfs sd_mod bnx2x
mdio ahci libahci tg3 libata libphy firmware_class dm_mirror dm_region_hash
dm_log dm_mod
[ÂÂ144.038864][ T8944] CPU: 116 PID: 8944 Comm: cat Not tainted 5.4.0-rc2+ #6
[ÂÂ144.038898][ T8944] NIP:ÂÂc000000000590c08 LR: c000000000577330 CTR:
c0000000005909d0
[ÂÂ144.038945][ T8944] REGS: c00020196bd6fa30 TRAP: 0380ÂÂÂNot taintedÂÂ(5.4.0-
rc2+)
[ÂÂ144.038989][ T8944] MSR:ÂÂ9000000000009033 <SF,HV,EE,ME,IR,DR,RI,LE>ÂÂCR:
48022428ÂÂXER: 20040000
[ÂÂ144.039028][ T8944] CFAR: c000000000590ad0 IRQMASK: 0Â
[ÂÂ144.039028][ T8944] GPR00: c000000000577330 c00020196bd6fcc0 c000000001122d00
c0002009d3d4a880Â
[ÂÂ144.039028][ T8944] GPR04: 00007fffb6870000 0000000000020000 fffffffffffffffe
c00c000000000000Â
[ÂÂ144.039028][ T8944] GPR08: 0000000001f00000 c00c000001f00000 0000000000000001
c0000000009413d0Â
[ÂÂ144.039028][ T8944] GPR12: c0000000005909d0 c000201fff677000 0000000000000000
0000000000000000Â
[ÂÂ144.039028][ T8944] GPR16: 0000000000000002 00007fffca34cfa8 ffffffffffffffff
0000000000000000Â
[ÂÂ144.039028][ T8944] GPR20: 0000000000000000 0000000000000000 c000000000000000
c00020196bd6fdf0Â
[ÂÂ144.039028][ T8944] GPR24: 00007fffb6870000 0000000007ffffff 0000000000000000
c000000000aa6c20Â
[ÂÂ144.039028][ T8944] GPR28: 00007fffb6890000 0000000000000008 000000000007c000
00007fffb6870000Â
[ÂÂ144.039240][ T8944] NIP [c000000000590c08] kpagecount_read+0x238/0x3f0
[ÂÂ144.039263][ T8944] LR [c000000000577330] proc_reg_read+0x90/0x130
[ÂÂ144.039274][ T8944] Call Trace:
[ÂÂ144.039304][ T8944] [c00020196bd6fd30] [c000000000577330]
proc_reg_read+0x90/0x130
[ÂÂ144.039342][ T8944] [c00020196bd6fd60] [c0000000004978bc]
__vfs_read+0x3c/0x70
[ÂÂ144.039377][ T8944] [c00020196bd6fd80] [c00000000049799c] vfs_read+0xac/0x170
[ÂÂ144.039423][ T8944] [c00020196bd6fdd0] [c000000000497dfc]
ksys_read+0x7c/0x140
[ÂÂ144.039472][ T8944] [c00020196bd6fe20] [c00000000000b378]
system_call+0x5c/0x68
[ÂÂ144.039495][ T8944] Instruction dump:
[ÂÂ144.039513][ T8944] 4e800020 60000000 3d22000d 3929c098 7bc83664 e8e90000
7d274215 418200acÂ
[ÂÂ144.039540][ T8944] e9490008 38caffff 714a0001 7cc9309e <e9460000> 2faaffff
e9490008 419e00fcÂ
[ÂÂ144.039580][ T8944] ---[ end trace 96fb2ea2d503fda9 ]---
[ÂÂ144.492072][ T8944]Â
[ÂÂ145.492172][ T8944] Kernel panic - not syncing: Fatal exception