Re: [PATCH v3 0/6] mm: Further memory block device cleanups

From: David Hildenbrand
Date: Fri Jun 21 2019 - 14:56:54 EST


On 21.06.19 20:24, David Hildenbrand wrote:
> On 21.06.19 17:15, Qian Cai wrote:
>> On Thu, 2019-06-20 at 20:31 +0200, David Hildenbrand wrote:
>>> @Andrew: Only patch 1, 4 and 6 changed compared to v1.
>>>
>>> Some further cleanups around memory block devices. Especially, clean up
>>> and simplify walk_memory_range(). Including some other minor cleanups.
>>>
>>> Compiled + tested on x86 with DIMMs under QEMU. Compile-tested on ppc64.
>>>
>>> v2 -> v3:
>>> - "mm/memory_hotplug: Rename walk_memory_range() and pass start+size .."
>>> -- Avoid warning on ppc.
>>> - "drivers/base/memory.c: Get rid of find_memory_block_hinted()"
>>> -- Fixup a comment regarding hinted devices.
>>>
>>> v1 -> v2:
>>> - "mm: Section numbers use the type "unsigned long""
>>> -- "unsigned long i" -> "unsigned long nr", in one case -> "int i"
>>> - "drivers/base/memory.c: Get rid of find_memory_block_hinted("
>>> -- Fix compilation error
>>> -- Get rid of the "hint" parameter completely
>>>
>>> David Hildenbrand (6):
>>> Â mm: Section numbers use the type "unsigned long"
>>> Â drivers/base/memory: Use "unsigned long" for block ids
>>> Â mm: Make register_mem_sect_under_node() static
>>> Â mm/memory_hotplug: Rename walk_memory_range() and pass start+size
>>> ÂÂÂÂinstead of pfns
>>> Â mm/memory_hotplug: Move and simplify walk_memory_blocks()
>>> Â drivers/base/memory.c: Get rid of find_memory_block_hinted()
>>>
>>> Âarch/powerpc/platforms/powernv/memtrace.c |ÂÂ23 ++---
>>> Âdrivers/acpi/acpi_memhotplug.cÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂ19 +---
>>> Âdrivers/base/memory.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ| 120 +++++++++++++---------
>>> Âdrivers/base/node.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂ8 +-
>>> Âinclude/linux/memory.hÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂ5 +-
>>> Âinclude/linux/memory_hotplug.hÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂ2 -
>>> Âinclude/linux/mmzone.hÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂ4 +-
>>> Âinclude/linux/node.hÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂÂ7 --
>>> Âmm/memory_hotplug.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂ57 +---------
>>> Âmm/sparse.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ|ÂÂ12 +--
>>> Â10 files changed, 106 insertions(+), 151 deletions(-)
>>>
>>
>> This series causes a few machines are unable to boot triggering endless soft
>> lockups. Reverted those commits fixed the issue.
>>
>> 97f4217d1da0 Revert "mm/memory_hotplug: rename walk_memory_range() and pass
>> start+size instead of pfns"
>> c608eebf33c6 Revert "mm-memory_hotplug-rename-walk_memory_range-and-pass-
>> startsize-instead-of-pfns-fix"
>> 34b5e4ab7558 Revert "mm/memory_hotplug: move and simplify walk_memory_blocks()"
>> 59a9f3eec5d1 Revert "drivers/base/memory.c: Get rid of
>> find_memory_block_hinted()"
>> 5cfcd52288b6 Revert "drivers-base-memoryc-get-rid-of-find_memory_block_hinted-
>> v3"
>>
>> [ÂÂÂÂ4.582081][ÂÂÂÂT1] ACPI FADT declares the system doesn't support PCIe ASPM,
>> so disable it
>> [ÂÂÂÂ4.590405][ÂÂÂÂT1] ACPI: bus type PCI registered
>> [ÂÂÂÂ4.592908][ÂÂÂÂT1] PCI: MMCONFIG for domain 0000 [bus 00-ff] at [mem
>> 0x80000000-0x8fffffff] (base 0x80000000)
>> [ÂÂÂÂ4.601860][ÂÂÂÂT1] PCI: MMCONFIG at [mem 0x80000000-0x8fffffff] reserved in
>> E820
>> [ÂÂÂÂ4.601860][ÂÂÂÂT1] PCI: Using configuration type 1 for base access
>> [ÂÂÂ28.661336][ÂÂÂC16] watchdog: BUG: soft lockup - CPU#16 stuck for 22s!
>> [swapper/0:1]
>> [ÂÂÂ28.671351][ÂÂÂC16] Modules linked in:
>> [ÂÂÂ28.671354][ÂÂÂC16] CPU: 16 PID: 1 Comm: swapper/0 Not tainted 5.2.0-rc5-
>> next-20190621+ #1
>> [ÂÂÂ28.681366][ÂÂÂC16] Hardware name: HPE ProLiant DL385 Gen10/ProLiant DL385
>> Gen10, BIOS A40 03/09/2018
>> [ÂÂÂ28.691334][ÂÂÂC16] RIP: 0010:_raw_spin_unlock_irqrestore+0x2f/0x40
>> [ÂÂÂ28.701334][ÂÂÂC16] Code: 55 48 89 e5 41 54 49 89 f4 be 01 00 00 00 53 48 8b
>> 55 08 48 89 fb 48 8d 7f 18 e8 4c 89 7d ff 48 89 df e8 94 f9 7d ff 41 54 9d <65>
>> ff 0d c2 44 8d 48 5b 41 5c 5d c3 0f 1f 44 00 00 0f 1f 44 00 00
>> [ÂÂÂ28.711354][ÂÂÂC16] RSP: 0018:ffff888205b27bf8 EFLAGS: 00000246 ORIG_RAX:
>> ffffffffffffff13
>> [ÂÂÂ28.721372][ÂÂÂC16] RAX: 0000000000000000 RBX: ffff8882053d6138 RCX:
>> ffffffffb6f2a3b8
>> [ÂÂÂ28.731371][ÂÂÂC16] RDX: 1ffff11040a7ac27 RSI: dffffc0000000000 RDI:
>> ffff8882053d6138
>> [ÂÂÂ28.741371][ÂÂÂC16] RBP: ffff888205b27c08 R08: ffffed1040a7ac28 R09:
>> ffffed1040a7ac27
>> [ÂÂÂ28.751334][ÂÂÂC16] R10: ffffed1040a7ac27 R11: ffff8882053d613b R12:
>> 0000000000000246
>> [ÂÂÂ28.751370][ÂÂÂC16] R13: ffff888205b27c98 R14: ffff8884504d0a20 R15:
>> 0000000000000000
>> [ÂÂÂ28.761368][ÂÂÂC16] FS:ÂÂ0000000000000000(0000) GS:ffff888454500000(0000)
>> knlGS:0000000000000000
>> [ÂÂÂ28.771373][ÂÂÂC16] CS:ÂÂ0010 DS: 0000 ES: 0000 CR0: 0000000080050033
>> [ÂÂÂ28.781334][ÂÂÂC16] CR2: 0000000000000000 CR3: 00000007c9012000 CR4:
>> 00000000001406a0
>> [ÂÂÂ28.791333][ÂÂÂC16] Call Trace:
>> [ÂÂÂ28.791374][ÂÂÂC16]ÂÂklist_next+0xd8/0x1c0
>> [ÂÂÂ28.791374][ÂÂÂC16]ÂÂsubsys_find_device_by_id+0x13b/0x1f0
>> [ÂÂÂ28.801334][ÂÂÂC16]ÂÂ? bus_find_device_by_name+0x20/0x20
>> [ÂÂÂ28.801370][ÂÂÂC16]ÂÂ? kobject_put+0x23/0x250
>> [ÂÂÂ28.811333][ÂÂÂC16]ÂÂwalk_memory_blocks+0x6c/0xb8
>> [ÂÂÂ28.811353][ÂÂÂC16]ÂÂ? write_policy_show+0x40/0x40
>> [ÂÂÂ28.821334][ÂÂÂC16]ÂÂlink_mem_sections+0x7e/0xa0
>> [ÂÂÂ28.821369][ÂÂÂC16]ÂÂ? unregister_memory_block_under_nodes+0x210/0x210
>> [ÂÂÂ28.831353][ÂÂÂC16]ÂÂ? __register_one_node+0x3bd/0x600
>> [ÂÂÂ28.831353][ÂÂÂC16]ÂÂtopology_init+0xbf/0x126
>> [ÂÂÂ28.841364][ÂÂÂC16]ÂÂ? enable_cpu0_hotplug+0x1a/0x1a
>> [ÂÂÂ28.841368][ÂÂÂC16]ÂÂdo_one_initcall+0xfe/0x45a
>> [ÂÂÂ28.851334][ÂÂÂC16]ÂÂ? initcall_blacklisted+0x150/0x150
>> [ÂÂÂ28.851353][ÂÂÂC16]ÂÂ? kasan_check_write+0x14/0x20
>> [ÂÂÂ28.861333][ÂÂÂC16]ÂÂ? up_write+0x75/0x140
>> [ÂÂÂ28.861369][ÂÂÂC16]ÂÂkernel_init_freeable+0x619/0x6ac
>> [ÂÂÂ28.871333][ÂÂÂC16]ÂÂ? rest_init+0x188/0x188
>> [ÂÂÂ28.871353][ÂÂÂC16]ÂÂkernel_init+0x11/0x138
>> [ÂÂÂ28.881363][ÂÂÂC16]ÂÂ? rest_init+0x188/0x188
>> [ÂÂÂ28.881363][ÂÂÂC16]ÂÂret_from_fork+0x22/0x40
>> [ÂÂÂ56.661336][ÂÂÂC16] watchdog: BUG: soft lockup - CPU#16 stuck for 22s!
>> [swapper/0:1]
>> [ÂÂÂ56.671352][ÂÂÂC16] Modules linked in:
>> [ÂÂÂ56.671354][ÂÂÂC16] CPU: 16 PID: 1 Comm: swapper/0 Tainted:
>> GÂÂÂÂÂÂÂÂÂÂÂÂÂLÂÂÂÂ5.2.0-rc5-next-20190621+ #1
>> [ÂÂÂ56.681357][ÂÂÂC16] Hardware name: HPE ProLiant DL385 Gen10/ProLiant DL385
>> Gen10, BIOS A40 03/09/2018
>> [ÂÂÂ56.691356][ÂÂÂC16] RIP: 0010:subsys_find_device_by_id+0x168/0x1f0
>> [ÂÂÂ56.701334][ÂÂÂC16] Code: 48 85 c0 74 3e 48 8d 78 58 e8 14 77 ca ff 4d 8b 7e
>> 58 4d 85 ff 74 2c 49 8d bf a0 03 00 00 e8 bf 75 ca ff 45 39 a7 a0 03 00 00 <75>
>> c9 4c 89 ff e8 0e 89 ff ff 48 85 c0 74 bc 48 89 df e8 21 3b 24
>> [ÂÂÂ56.721333][ÂÂÂC16] RSP: 0018:ffff888205b27c68 EFLAGS: 00000287 ORIG_RAX:
>> ffffffffffffff13
>> [ÂÂÂ56.721370][ÂÂÂC16] RAX: 0000000000000000 RBX: ffff888205b27c90 RCX:
>> ffffffffb74c9dc1
>> [ÂÂÂ56.731370][ÂÂÂC16] RDX: 0000000000000003 RSI: dffffc0000000000 RDI:
>> ffff8888774ec3e0
>> [ÂÂÂ56.741371][ÂÂÂC16] RBP: ffff888205b27cf8 R08: ffffed1040a7ac28 R09:
>> ffffed1040a7ac27
>> [ÂÂÂ56.751335][ÂÂÂC16] R10: ffffed1040a7ac27 R11: ffff8882053d613b R12:
>> 0000000000085c1b
>> [ÂÂÂ56.761334][ÂÂÂC16] R13: 1ffff11040b64f8e R14: ffff888450de4a20 R15:
>> ffff8888774ec040
>> [ÂÂÂ56.761372][ÂÂÂC16] FS:ÂÂ0000000000000000(0000) GS:ffff888454500000(0000)
>> knlGS:0000000000000000
>> [ÂÂÂ56.771374][ÂÂÂC16] CS:ÂÂ0010 DS: 0000 ES: 0000 CR0: 0000000080050033
>> [ÂÂÂ56.781370][ÂÂÂC16] CR2: 0000000000000000 CR3: 00000007c9012000 CR4:
>> 00000000001406a0
>> [ÂÂÂ56.791373][ÂÂÂC16] Call Trace:
>> [ÂÂÂ56.791373][ÂÂÂC16]ÂÂ? bus_find_device_by_name+0x20/0x20
>> [ÂÂÂ56.801334][ÂÂÂC16]ÂÂ? kobject_put+0x23/0x250
>> [ÂÂÂ56.801334][ÂÂÂC16]ÂÂwalk_memory_blocks+0x6c/0xb8
>> [ÂÂÂ56.811333][ÂÂÂC16]ÂÂ? write_policy_show+0x40/0x40
>> [ÂÂÂ56.811353][ÂÂÂC16]ÂÂlink_mem_sections+0x7e/0xa0
>> [ÂÂÂ56.811353][ÂÂÂC16]ÂÂ? unregister_memory_block_under_nodes+0x210/0x210
>> [ÂÂÂ56.821333][ÂÂÂC16]ÂÂ? __register_one_node+0x3bd/0x600
>> [ÂÂÂ56.831333][ÂÂÂC16]ÂÂtopology_init+0xbf/0x126
>> [ÂÂÂ56.831355][ÂÂÂC16]ÂÂ? enable_cpu0_hotplug+0x1a/0x1a
>> [ÂÂÂ56.841334][ÂÂÂC16]ÂÂdo_one_initcall+0xfe/0x45a
>> [ÂÂÂ56.841334][ÂÂÂC16]ÂÂ? initcall_blacklisted+0x150/0x150
>> [ÂÂÂ56.851333][ÂÂÂC16]ÂÂ? kasan_check_write+0x14/0x20
>> [ÂÂÂ56.851354][ÂÂÂC16]ÂÂ? up_write+0x75/0x140
>> [ÂÂÂ56.861333][ÂÂÂC16]ÂÂkernel_init_freeable+0x619/0x6ac
>> [ÂÂÂ56.861333][ÂÂÂC16]ÂÂ? rest_init+0x188/0x188
>> [ÂÂÂ56.861369][ÂÂÂC16]ÂÂkernel_init+0x11/0x138
>> [ÂÂÂ56.871333][ÂÂÂC16]ÂÂ? rest_init+0x188/0x188
>> [ÂÂÂ56.871354][ÂÂÂC16]ÂÂret_from_fork+0x22/0x40
>> [ÂÂÂ64.601362][ÂÂÂC16] rcu: INFO: rcu_sched self-detected stall on CPU
>> [ÂÂÂ64.611335][ÂÂÂC16] rcu:Â 16-....: (5958 ticks this GP)
>> idle=37e/1/0x4000000000000002 softirq=27/27 fqs=3000Â
>> [ÂÂÂ64.621334][ÂÂÂC16]Â (t=6002 jiffies g=-1079 q=25)
>> [ÂÂÂ64.621334][ÂÂÂC16] NMI backtrace for cpu 16
>> [ÂÂÂ64.621374][ÂÂÂC16] CPU: 16 PID: 1 Comm: swapper/0 Tainted:
>> GÂÂÂÂÂÂÂÂÂÂÂÂÂLÂÂÂÂ5.2.0-rc5-next-20190621+ #1
>> [ÂÂÂ64.631372][ÂÂÂC16] Hardware name: HPE ProLiant DL385 Gen10/ProLiant DL385
>> Gen10, BIOS A40 03/09/2018
>> [ÂÂÂ64.641371][ÂÂÂC16] Call Trace:
>> [ÂÂÂ64.651337][ÂÂÂC16]ÂÂ<IRQ>
>> [ÂÂÂ64.651376][ÂÂÂC16]ÂÂdump_stack+0x62/0x9a
>> [ÂÂÂ64.651376][ÂÂÂC16]ÂÂnmi_cpu_backtrace.cold.0+0x2e/0x33
>> [ÂÂÂ64.661337][ÂÂÂC16]ÂÂ? nmi_cpu_backtrace_handler+0x20/0x20
>> [ÂÂÂ64.661337][ÂÂÂC16]ÂÂnmi_trigger_cpumask_backtrace+0x1a6/0x1b9
>> [ÂÂÂ64.671353][ÂÂÂC16]ÂÂarch_trigger_cpumask_backtrace+0x19/0x20
>> [ÂÂÂ64.681366][ÂÂÂC16]ÂÂrcu_dump_cpu_stacks+0x18b/0x1d6
>> [ÂÂÂ64.681366][ÂÂÂC16]ÂÂrcu_sched_clock_irq.cold.64+0x368/0x791
>> [ÂÂÂ64.691336][ÂÂÂC16]ÂÂ? kasan_check_read+0x11/0x20
>> [ÂÂÂ64.691354][ÂÂÂC16]ÂÂ? __raise_softirq_irqoff+0x66/0x150
>> [ÂÂÂ64.701336][ÂÂÂC16]ÂÂupdate_process_times+0x2f/0x60
>> [ÂÂÂ64.701362][ÂÂÂC16]ÂÂtick_periodic+0x38/0xe0
>> [ÂÂÂ64.711334][ÂÂÂC16]ÂÂtick_handle_periodic+0x2e/0x80
>> [ÂÂÂ64.711353][ÂÂÂC16]ÂÂsmp_apic_timer_interrupt+0xfb/0x370
>> [ÂÂÂ64.721367][ÂÂÂC16]ÂÂapic_timer_interrupt+0xf/0x20
>> [ÂÂÂ64.721367][ÂÂÂC16]ÂÂ</IRQ>
>> [ÂÂÂ64.721367][ÂÂÂC16] RIP: 0010:_raw_spin_unlock_irqrestore+0x2f/0x40
>> [ÂÂÂ64.731370][ÂÂÂC16] Code: 55 48 89 e5 41 54 49 89 f4 be 01 00 00 00 53Â
>>
>
> @Qian Cai, unfortunately I can't reproduce.
>
> If you get the chance, it would be great if you could retry with
>
> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
> index 972c5336bebf..742f99ddd148 100644
> --- a/drivers/base/memory.c
> +++ b/drivers/base/memory.c
> @@ -868,6 +868,9 @@ int walk_memory_blocks(unsigned long start, unsigned
> long size,
> unsigned long block_id;
> int ret = 0;
>
> + if (!size)
> + return;
> +
> for (block_id = start_block_id; block_id <= end_block_id;
> block_id++) {
> mem = find_memory_block_by_id(block_id);
> if (!mem)
>
>
>
> If both, start and size are 0, we would get a veeeery long loop. This
> would mean that we have an online node that does not span any pages at
> all (pgdat->node_start_pfn = 0, start_pfn + pgdat->node_spanned_pages = 0).
>


...trying to reproduce with QEMU (setting 0MB for the second node):

qemu-system-x86_64 --enable-kvm -m 4G,maxmem=20G,slots=2 \
-smp sockets=2,cores=1 \
-numa node,nodeid=0,cpus=0,mem=4G \
-numa node,nodeid=1,cpus=1,mem=0 ...

I can indeed see that the node is online and
"pgdat->node_start_pfn == 0 && start_pfn + pgdat->node_spanned_pages == 0".

However, the kernel segfaults in an unrelated code path, so I can't
verify if this solves this problem:

[ 0.313284] BUG: kernel NULL pointer dereference, address: 00000000000000a0
[ 0.313479] #PF: supervisor read access in kernel mode
[ 0.313479] #PF: error_code(0x0000) - not-present page
[ 0.313479] PGD 0 P4D 0
[ 0.313479] Oops: 0000 [#1] SMP PTI
[ 0.313479] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.2.0-rc5-next-20190620+ #56
[ 0.313479] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.12.1-0-ga5cab58e9a3f-prebuilt.qemu.4
[ 0.313479] RIP: 0010:bus_add_device+0x59/0x110
[ 0.313479] Code: 20 48 89 df e8 f8 b4 ff ff 41 89 c4 85 c0 0f 85 81 00 00 00 48 8b 53 50 48 85 d2 75 03 48 8b 135
[ 0.313479] RSP: 0000:ffffb4a6c0013e20 EFLAGS: 00010246
[ 0.313479] RAX: 0000000000000000 RBX: ffff8b61bac23800 RCX: 0000000000000000
[ 0.313479] RDX: ffff8b61bac29038 RSI: ffff8b61bac23800 RDI: ffff8b61bac23800
[ 0.313479] RBP: ffffffff9d2f4500 R08: 0000000000000000 R09: 0000000000000001
[ 0.313479] R10: 0000000000000000 R11: ffff8b61bad20878 R12: 0000000000000000
[ 0.313479] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
[ 0.313479] FS: 0000000000000000(0000) GS:ffff8b61bba00000(0000) knlGS:0000000000000000
[ 0.313479] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 0.313479] CR2: 00000000000000a0 CR3: 0000000013c24000 CR4: 00000000000006f0
[ 0.313479] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 0.313479] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 0.313479] Call Trace:
[ 0.313479] device_add+0x304/0x660
[ 0.313479] ? __init_waitqueue_head+0x31/0x50
[ 0.313479] __register_one_node+0x67/0x170
[ 0.313479] __try_online_node.cold+0x3e/0x78
[ 0.313479] try_online_node+0x25/0x40
[ 0.313479] do_cpu_up+0x36/0xc0
[ 0.313479] smp_init+0x59/0xb3
[ 0.313479] kernel_init_freeable+0x11a/0x247
[ 0.313479] ? rest_init+0x23f/0x23f
[ 0.313479] kernel_init+0x5/0xf1
[ 0.313479] ret_from_fork+0x3a/0x50
[ 0.313479] Modules linked in:

Figuring out what goes wrong here (maybe QEMU creating a weird
system configuration) is a different journey :)

--

Thanks,

David / dhildenb