WARNING: CPU: 3 PID: 1 at block/blk-mq-cpumap.c:90 blk_mq_map_hw_queues+0xf3/0x100
I hit this WARN_ON on both my 32 bit test VM and my 64 bit one:
[ 1.861456] ------------[ cut here ]------------ [ 1.862394] WARNING: CPU: 3 PID: 1 at block/blk-mq-cpumap.c:90 blk_mq_map_hw_queues+0xf3/0x100 [ 1.864100] Modules linked in: [ 1.864785] CPU: 3 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.13.0-test-01253-g66611c047570-dirty #128 [ 1.866545] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 [ 1.868320] EIP: blk_mq_map_hw_queues+0xf3/0x100 [ 1.869254] Code: 0c 3a b4 db 25 ff 00 00 00 74 17 f3 0f bc c0 83 f8 07 77 0e 8b 0e c7 04 81 00 00 00 00 8d 48 01 75 d6 83 c4 08 5b 5e 5f 5d c3 <0f> 0b eb c5 90 2e 8d b4 26 00 00 00 00 3e 8d 74 26 00 55 31 c9 89 [ 1.872620] EAX: 00000000 EBX: 00000000 ECX: 00000000 EDX: 00000000 [ 1.873812] ESI: c1c2bc20 EDI: c130dc10 EBP: c116dcbc ESP: c116dca8 [ 1.875002] DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068 EFLAGS: 00010206 [ 1.878621] CR0: 80050033 CR2: 00000000 CR3: 1bdf8000 CR4: 000006f0 [ 1.879854] Call Trace: [ 1.880441] ? show_regs.cold+0x14/0x1d [ 1.881245] ? __warn.cold+0x42/0xe8 [ 1.882011] ? blk_mq_map_hw_queues+0xf3/0x100 [ 1.882837] ? report_bug+0x101/0x140 [ 1.883497] ? blk_mq_map_hw_queues+0xf4/0x100 [ 1.884238] ? exc_overflow+0x40/0x40 [ 1.884866] ? handle_bug+0x46/0x70 [ 1.885467] ? exc_invalid_op+0x18/0x60 [ 1.886116] ? handle_exception+0x133/0x133 [ 1.886814] ? vp_modern_probe+0x5b8/0x620 [ 1.887514] ? exc_overflow+0x40/0x40 [ 1.888148] ? blk_mq_map_hw_queues+0xf3/0x100 [ 1.888904] ? vp_modern_probe+0x5b8/0x620 [ 1.889586] ? exc_overflow+0x40/0x40 [ 1.890208] ? blk_mq_map_hw_queues+0xf3/0x100 [ 1.890939] virtblk_map_queues+0x55/0x80 [ 1.891642] blk_mq_update_queue_map+0x77/0xb0 [ 1.892382] blk_mq_alloc_tag_set+0x16b/0x390 [ 1.893103] virtblk_probe+0x158/0xe40 [ 1.893740] ? idr_alloc_cyclic+0x46/0xa0 [ 1.894414] virtio_dev_probe+0x281/0x370 [ 1.895084] really_probe+0xc2/0x310 [ 1.896168] __driver_probe_device+0x71/0x150 [ 1.896887] ? kernfs_create_dir_ns+0x46/0x70 [ 1.897612] driver_probe_device+0x1f/0xa0 [ 1.898314] __driver_attach+0xa7/0x1a0 [ 1.898957] ? __device_attach_driver+0x100/0x100 [ 1.899749] bus_for_each_dev+0x70/0xc0 [ 1.900406] driver_attach+0x19/0x20 [ 1.901020] ? __device_attach_driver+0x100/0x100 [ 1.901777] bus_add_driver+0xe6/0x1c0 [ 1.902416] driver_register+0x6d/0xc0 [ 1.903051] __register_virtio_driver+0x1e/0x30 [ 1.903816] virtio_blk_init+0x4d/0x74 [ 1.904467] ? regmap_initcall+0x14/0x14 [ 1.905134] do_one_initcall+0x4b/0x2c0 [ 1.905796] ? parse_args+0x1db/0x3e0 [ 1.906431] kernel_init_freeable+0x186/0x1c4 [ 1.907148] ? rest_init+0xb0/0xb0 [ 1.907812] kernel_init+0x17/0x110 [ 1.908533] ret_from_fork+0x38/0x50 [ 1.909301] ? rest_init+0xb0/0xb0 [ 1.910028] ret_from_fork_asm+0x12/0x18 [ 1.910902] entry_INT80_32+0xf0/0xf0 [ 1.913755] ---[ end trace 0000000000000000 ]---
Seems introduced by: 1452e9b470c90 ("blk-mq: introduce blk_mq_map_hw_queues")
Config for x86_64 attached.
-- Steve
Quoted 8 lines · Steven Rostedt
I hit this
WARN_ONon both my 32 bit test VM and my 64 bit one:[ 1.861456] ------------[ cut here ]------------ [ 1.862394] WARNING: CPU: 3 PID: 1 at block/blk-mq-cpumap.c:90 blk_mq_map_hw_queues+0xf3/0x100 [ 1.864100] Modules linked in: [ 1.864785] CPU: 3 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.13.0-test-01253-g66611c047570-dirty #128 [ 1.866545] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 [ 1.868320] EIP: blk_mq_map_hw_queues+0xf3/0x100
[...]
Quoted 3 lines
Seems introduced by:
1452e9b470c90("blk-mq: introduceblk_mq_map_hw_queues")Config for
x86_64attached.
Thanks I was able to reproduce it and was able to figure out that vp_get_vq_affinity returns a NULL CPU mask which makes blk_mq_map_hw_queues call the fallback code path with the WARN_ON_ONCE from above.
The blk_mq_virtio_map_queues used blk_mq_map_queues for creating a map:
blk_mq_virtio_map_queues(...)
{
[...]
for (;;) {
mask = vdev->config->get_vq_affinity(...);
if (!mask)
goto fallback;
[...]
}
return;fallback:
blk_mq_map_queues(...); }
blk_mq_map_hw_queues(...)
{
for (;;) {
mask = dev->bus->irq_get_affinity(...);
if (!mask)
goto fallback;
[...]
}
returnfallback:
WARN_ON_ONCE(qmap->nr_queues > 1); blk_mq_clear_mq_map(...) }
I was where blk_mq_clear_mq_map is coming from. The origin is from blk_mq_pci_map_queues
c00539037495 ("blk-mq-pci: add a fallback when pci_irq_get_affinity returns NULL")
blk-mq-pci: add a fallback when pci_irq_get_affinity returns NULL
While pci_irq_get_affinity should never fail for SMP kernel that implement the affinity mapping, it will always return NULL in the UP case, so provide a fallback mapping of all queues to CPU 0 in that case.
What about using blk_mq_mp_queues instead of blk_mq_clear_mq_map, it should give the same mapping as with blk_mq_clear_mq_map. And obviously removing the WARN_ON_ONCE. Basically use the version from blk_mq_virtio_map_queues for the fallback code path.
Christoph, would this be acceptable?
Daniel
Quoted 4 lines · On Wed, 22 Jan 2025 18:08:35 +0100 Daniel Wagner <[email protected]> wrote:
fallback:
WARN_ON_ONCE(qmap->nr_queues > 1); blk_mq_clear_mq_map(...) }
I commented out the WARN_ON_ONCE() to see if I could finish my testing, but it now triggered this, but much later on in the tests:
[ 813.092038] BUG: kernel NULL pointer dereference, address: 0000000000000090 [ 813.094136] #PF: supervisor read access in kernel mode [ 813.095643] #PF: error_code(0x0000) - not-present page [ 813.095643] PGD 0 P4D 0 [ 813.095643] Oops: Oops: 0000 [#1] PREEMPT SMP PTI [ 813.095643] CPU: 1 UID: 0 PID: 22 Comm: cpuhp/1 Not tainted 6.13.0-test-01253-g66611c047570-dirty #27 [ 813.095643] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 [ 813.095643] RIP: 0010:blk_mq_all_tag_iter+0x1a/0x270 [ 813.095643] Code: 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 66 0f 1f 00 0f 1f 44 00 00 41 57 41 56 41 55 49 89 fd 41 54 55 53 48 83 ec 50 <48> 8b 87 90 00 00 00 65 4c 8b 04 25 28 00 00 00 4c 89 44 24 48 49 [ 813.095643] RSP: 0018:ffffb668400d3da0 EFLAGS: 00010286 [ 813.095643] RAX: 0000000000000000 RBX: ffffa1f0408e7200 RCX: 0000000000000000 [ 813.095643] RDX: ffffb668400d3e28 RSI: ffffffffa1511d30 RDI: 0000000000000000 [ 813.095643] RBP: ffffb668400d3e28 R08: ffffa1f0bbc9c528 R09: 0000000000000001 [ 813.095643] R10: ffffa1f0408ec600 R11: 0000000000000001 R12: 0000000000000003 [ 813.095643] R13: 0000000000000000 R14: 0000000000000000 R15: ffffa1f0bbc9c528 [ 813.095643] FS: 0000000000000000(0000) GS:ffffa1f0bbc80000(0000) knlGS:0000000000000000 [ 813.095643] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 813.095643] CR2: 0000000000000090 CR3: 0000000104d42004 CR4: 0000000000170ef0 [ 813.095643] Call Trace: [ 813.095643] <TASK> [ 813.095643] ? __die+0x56/0x97 [ 813.095643] ? page_fault_oops+0xbe/0x250 [ 813.095643] ? search_extable+0x26/0x30 [ 813.095643] ? blk_mq_all_tag_iter+0x1a/0x270 [ 813.095643] ? search_module_extables+0x19/0x60 [ 813.095643] ? exc_page_fault+0x227/0x6d0 [ 813.095643] ? affine_move_task+0x26f/0x510 [ 813.095643] ? asm_exc_page_fault+0x26/0x30 [ 813.095643] ? __pfx_blk_mq_has_request+0x10/0x10 [ 813.095643] ? blk_mq_all_tag_iter+0x1a/0x270 [ 813.095643] ? xas_load+0xd/0xd0 [ 813.095643] ? xa_load+0x7b/0xb0 [ 813.095643] blk_mq_hctx_notify_offline+0xf1/0x1a0 [ 813.095643] ? __pfx_blk_mq_hctx_notify_offline+0x10/0x10 [ 813.095643] cpuhp_invoke_callback+0x214/0x420 [ 813.095643] ? __pfx_smpboot_thread_fn+0x10/0x10 [ 813.095643] cpuhp_thread_fun+0x98/0x150 [ 813.095643] smpboot_thread_fn+0xdd/0x1d0 [ 813.095643] kthread+0xd2/0x100 [ 813.095643] ? __pfx_kthread+0x10/0x10 [ 813.095643] ret_from_fork+0x34/0x50 [ 813.095643] ? __pfx_kthread+0x10/0x10 [ 813.095643] ret_from_fork_asm+0x1a/0x30 [ 813.095643] </TASK> [ 813.095643] Modules linked in: [ 813.095643] CR2: 0000000000000090 [ 813.095643] ---[ end trace 0000000000000000 ]---
It triggered after doing the mmiotrace which shuts down and brings up CPUs.
Not sure its related. I can see how reproducible this is, and if it is, I can try to bisect it.
-- Steve
Quoted 2 lines · On Wed, 22 Jan 2025 12:54:45 -0500 Steven Rostedt <[email protected]> wrote:
Not sure its related. I can see how reproducible this is, and if it is, I can try to bisect it.
I bisected it down to: a5665c3d150c98 ("virtio: blk/scsi: replace blk_mq_virtio_map_queues with blk_mq_map_hw_queues")
And reverting that as well as:
9bc1e897a821f ("blk-mq: remove unused queue mapping helpers")
It booted fine.
-- Steve
Quoted 6 lines · Steven Rostedt
Quoted 2 lines · On Wed, 22 Jan 2025 12:54:45 -0500 Steven Rostedt <[email protected]> wrote:
Not sure its related. I can see how reproducible this is, and if it is, I can try to bisect it.
Quoted 8 lines
I bisected it down to:
a5665c3d150c98("virtio: blk/scsi: replaceblk_mq_virtio_map_queueswithblk_mq_map_hw_queues")And reverting that as well as:
9bc1e897a821f("blk-mq: remove unused queue mapping helpers")It booted fine.
In the previous tests you just comment out the WARN_ON_ONCE or did you also replace blk_mq_clear_mq_map with blk_mq_map_queues? The blk_mq_clear_mq_map will map all queues to CPU 0 and if you offline CPU 0, there is nothing left to serve the hctx. I'll try to reproduce your test and see if I my idea works.
Thanks,
Daniel
Quoted 14 lines · Daniel Wagner
Quoted 13 lines · Steven Rostedt
Quoted 2 lines · On Wed, 22 Jan 2025 12:54:45 -0500 Steven Rostedt <[email protected]> wrote:
Not sure its related. I can see how reproducible this is, and if it is, I can try to bisect it.
I bisected it down to:
a5665c3d150c98("virtio: blk/scsi: replaceblk_mq_virtio_map_queueswithblk_mq_map_hw_queues")And reverting that as well as:
9bc1e897a821f("blk-mq: remove unused queue mapping helpers")
Quoted 7 lines
Quoted 1 line
It booted fine.
In the previous tests you just comment out the
WARN_ON_ONCEor did you also replaceblk_mq_clear_mq_mapwithblk_mq_map_queues? Theblk_mq_clear_mq_mapwill map all queues to CPU 0 and if you offline CPU 0, there is nothing left to serve the hctx. I'll try to reproduce your test and see if I my idea works.
I've reproduced the second crash as well using your good old stress-cpu-hotplug script. blk_mq_clear_mq_map the CPUs are mapped to the first hctx and when offline a CPU blk_mq_hctx_notify_offline is not happy about not finding any CPU mapped to the hctx.
The patch below should fix your problem. I've tested the different setups and all looked good to me.
From ad6e1bd1705e127c191caf2d3becc6ce989e8d96 Mon Sep 17 00:00:00 2001
From: Daniel Wagner <[email protected]>
Date: Thu, 23 Jan 2025 12:59:58 +0100
Subject: [PATCH] blk-mq: create correct map for fallback case
The fallback code in blk_mq_map_hw_queues is original from blk_mq_pci_map_queues and was added to handle the case where pci_irq_get_affinity will return NULL for !SMP configuration.
blk_mq_map_hw_queues replaces besides blk_mq_pci_map_queues also blk_mq_virtio_map_queues which used to use blk_mq_map_queues for the fallback.
It's possible to use blk_mq_map_queues for both cases though. blk_mq_map_queues creates the same map as blk_mq_clear_mq_map for !SMP that is CPU 0 will be mapped to hctx 0.
The WARN_ON_ONCE has to be dropped for virtio as the fallback is also taken for certain configuration on default. Though there is still a WARN_ON_ONCE check in lib/group_cpus.c:
WARN_ON(nr_present + nr_others < numgrps);
which will trigger if the caller tries to create more hardware queues than CPUs. It tests the same as the WARN_ON_ONCE in blk_mq_pci_map_queues did.
--- block/blk-mq-cpumap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
block/blk-mq-cpumap.c +1 -2
@@ -87,7 +87,6 @@ void blk_mq_map_hw_queues(struct blk_mq_queue_map *qmap,return ; fallback: -WARN_ON_ONCE (qmap->nr_queues >1 ); -blk_mq_clear_mq_map (qmap); +blk_mq_map_queues (qmap); }EXPORT_SYMBOL_GPL (blk_mq_map_hw_queues);
--
2.48.1