Skip to content

fix sbitmap initialization and null_blk tagset setup - #44

Closed
ghost wants to merge 3 commits into
linus-master_basefrom
series/984084=>linus-master
Closed

ghost wants to merge 3 commits into
linus-master_basefrom
series/984084=>linus-master

Conversation

@ghost

@ghost ghost commented Jul 23, 2025

Copy link
Copy Markdown

Pull request for series with
subject: fix sbitmap initialization and null_blk tagset setup
version: 1
url: https://patchwork.kernel.org/project/linux-block/list/?series=984340

@ghost

ghost commented Jul 23, 2025

Copy link
Copy Markdown
Author

@ghost
ghost force-pushed the linus-master_base branch from 81f31a4 to 87bbbbc Compare July 24, 2025 05:40
@ghost

ghost commented Jul 24, 2025

Copy link
Copy Markdown
Author

@ghost
ghost force-pushed the series/984084=>linus-master branch from 4cc8be2 to af24d2a Compare July 24, 2025 05:41
@ghost ghost added the V1-ci-pass label Jul 24, 2025
@ghost
ghost force-pushed the linus-master_base branch 2 times, most recently from 6637119 to f092a9b Compare July 31, 2025 04:25
@ghost

ghost commented Jul 31, 2025

Copy link
Copy Markdown
Author

@ghost
ghost force-pushed the series/984084=>linus-master branch from af24d2a to 66b032c Compare July 31, 2025 04:35
@ghost
ghost force-pushed the linus-master_base branch from f092a9b to 0b59764 Compare July 31, 2025 17:58
@ghost

ghost commented Jul 31, 2025

Copy link
Copy Markdown
Author

@ghost
ghost force-pushed the series/984084=>linus-master branch from 66b032c to ddf0ba1 Compare July 31, 2025 18:08
@ghost
ghost force-pushed the linus-master_base branch from 0b59764 to aee5bd3 Compare July 31, 2025 19:11
@ghost

ghost commented Jul 31, 2025

Copy link
Copy Markdown
Author

@ghost
ghost force-pushed the series/984084=>linus-master branch from ddf0ba1 to 4ced250 Compare July 31, 2025 19:21
@ghost
ghost force-pushed the linus-master_base branch from aee5bd3 to ef18525 Compare July 31, 2025 20:07
@ghost

ghost commented Jul 31, 2025

Copy link
Copy Markdown
Author

@ghost
ghost force-pushed the series/984084=>linus-master branch from 4ced250 to c81ac97 Compare July 31, 2025 20:17
@ghost
ghost force-pushed the linus-master_base branch from ef18525 to 3851b3f Compare July 31, 2025 20:55
@ghost

ghost commented Jul 31, 2025

Copy link
Copy Markdown
Author

@ghost
ghost force-pushed the series/984084=>linus-master branch from c81ac97 to f1d1184 Compare July 31, 2025 21:05
@ghost
ghost force-pushed the linus-master_base branch from 3851b3f to 28b3384 Compare July 31, 2025 23:42
@ghost

ghost commented Jul 31, 2025

Copy link
Copy Markdown
Author

@ghost
ghost force-pushed the series/984084=>linus-master branch from f1d1184 to ff9a3a1 Compare July 31, 2025 23:52
@ghost
ghost force-pushed the linus-master_base branch from 28b3384 to 8ab9be5 Compare August 1, 2025 00:45
@ghost

ghost commented Aug 1, 2025

Copy link
Copy Markdown
Author

@ghost
ghost force-pushed the series/984084=>linus-master branch from ff9a3a1 to 66f0e52 Compare August 1, 2025 00:55
@ghost
ghost force-pushed the series/984084=>linus-master branch from dc096ab to eef7f79 Compare August 9, 2025 06:04
@ghost
ghost force-pushed the linus-master_base branch from 4c26e9a to 1356209 Compare August 9, 2025 06:05
@ghost

ghost commented Aug 9, 2025

Copy link
Copy Markdown
Author

@ghost
ghost force-pushed the series/984084=>linus-master branch from eef7f79 to 48abc46 Compare August 9, 2025 06:19
@ghost
ghost force-pushed the linus-master_base branch from 1356209 to ae9bce3 Compare August 9, 2025 06:21
@ghost

ghost commented Aug 9, 2025

Copy link
Copy Markdown
Author

@ghost
ghost force-pushed the series/984084=>linus-master branch from 48abc46 to 7041731 Compare August 9, 2025 06:34
@ghost
ghost force-pushed the linus-master_base branch from ae9bce3 to e263d6e Compare August 9, 2025 15:26
@ghost

ghost commented Aug 9, 2025

Copy link
Copy Markdown
Author

@ghost
ghost force-pushed the series/984084=>linus-master branch from 7041731 to 2dc1a60 Compare August 9, 2025 15:40
@ghost
ghost force-pushed the linus-master_base branch from e263d6e to 77110f5 Compare August 10, 2025 05:58
@ghost

ghost commented Aug 10, 2025

Copy link
Copy Markdown
Author

@ghost
ghost force-pushed the series/984084=>linus-master branch from 2dc1a60 to 3890e49 Compare August 10, 2025 06:12
@ghost
ghost force-pushed the linus-master_base branch from 77110f5 to a2e0474 Compare August 10, 2025 06:39
@ghost

ghost commented Aug 10, 2025

Copy link
Copy Markdown
Author

@ghost
ghost force-pushed the series/984084=>linus-master branch from 3890e49 to b9ffed3 Compare August 10, 2025 06:52
@ghost

ghost commented Aug 10, 2025

Copy link
Copy Markdown
Author

@ghost

ghost commented Aug 12, 2025

Copy link
Copy Markdown
Author

@ghost

ghost commented Aug 12, 2025

Copy link
Copy Markdown
Author

@ghost

ghost commented Aug 12, 2025

Copy link
Copy Markdown
Author

@ghost

ghost commented Aug 13, 2025

Copy link
Copy Markdown
Author

@ghost

ghost commented Aug 13, 2025

Copy link
Copy Markdown
Author

@ghost

ghost commented Aug 13, 2025

Copy link
Copy Markdown
Author

@ghost

ghost commented Aug 14, 2025

Copy link
Copy Markdown
Author

@ghost

ghost commented Aug 14, 2025

Copy link
Copy Markdown
Author

kawasaki and others added 3 commits August 15, 2025 11:29
We observed a kernel crash when the I/O scheduler allocates an sbitmap
for a hardware queue (hctx) that has no associated software queues (ctx),
and later attempts to free it. When no software queues are mapped to a
hardware queue, the sbitmap is initialized with a depth of zero. In such
cases, the sbitmap_init_node() function should set sb->alloc_hint to NULL.
However, if this is not done, sb->alloc_hint may contain garbage, and
calling sbitmap_free() will pass this invalid pointer to free_percpu(),
resulting in a kernel crash.

Example crash trace:
==================================================================
Kernel attempted to read user page (28) - exploit attempt? (uid: 0)
BUG: Kernel NULL pointer dereference on read at 0x00000028
Faulting instruction address: 0xc000000000708f88
Oops: Kernel access of bad area, sig: 11 [#1]
LE PAGE_SIZE=64K MMU=Radix  SMP NR_CPUS=2048 NUMA pSeries
[...]
CPU: 5 UID: 0 PID: 5491 Comm: mk_nullb_shared Kdump: loaded Tainted: G    B               6.16.0-rc5+ #294 VOLUNTARY
Tainted: [B]=BAD_PAGE
Hardware name: IBM,9043-MRX POWER10 (architected) 0x800200 0xf000006 of:IBM,FW1060.00 (NM1060_028) hv:phyp pSeries
[...]
NIP [c000000000708f88] free_percpu+0x144/0xba8
LR [c000000000708f84] free_percpu+0x140/0xba8
Call Trace:
    free_percpu+0x140/0xba8 (unreliable)
    kyber_exit_hctx+0x94/0x124
    blk_mq_exit_sched+0xe4/0x214
    elevator_exit+0xa8/0xf4
    elevator_switch+0x3b8/0x5d8
    elv_update_nr_hw_queues+0x14c/0x300
    blk_mq_update_nr_hw_queues+0x5cc/0x670
    nullb_update_nr_hw_queues+0x118/0x1f8 [null_blk]
    nullb_device_submit_queues_store+0xac/0x170 [null_blk]
    configfs_write_iter+0x1dc/0x2d0
    vfs_write+0x5b0/0x77c
    ksys_write+0xa0/0x180
    system_call_exception+0x1b0/0x4f0
    system_call_vectored_common+0x15c/0x2ec

If the sbitmap depth is zero, sb->alloc_hint memory is NOT allocated, but
the pointer is not explicitly set to NULL. Later, during sbitmap_free(),
the kernel attempts to free sb->alloc_hint, which is a per cpu pointer
variable, regardless of whether it was valid, leading to a crash.

This patch ensures that sb->alloc_hint is explicitly set to NULL in
sbitmap_init_node() when the requested depth is zero. This prevents
free_percpu() from freeing sb->alloc_hint and thus avoids the observed
crash.

Reviewed-by: Damien Le Moal <[email protected]>
Reviewed-by: Hannes Reinecke <[email protected]>
Signed-off-by: Nilay Shroff <[email protected]>
When setting up a null block device, we initialize a tagset that
includes a driver_data field—typically used by block drivers to
store a pointer to driver-specific data. In the case of null_blk,
this should point to the struct nullb instance.

However, due to recent tagset refactoring in the null_blk driver, we
missed initializing driver_data when creating a shared tagset. As a
result, software queues (ctx) fail to map correctly to new hardware
queues (hctx). For example, increasing the number of submit queues
triggers an nr_hw_queues update, which invokes null_map_queues() to
remap queues. Since set->driver_data is unset, null_map_queues()
fails to map any ctx to the new hctxs, leading to hctx->nr_ctx == 0,
effectively making the hardware queues unusable for I/O.

This patch fixes the issue by ensuring that set->driver_data is properly
initialized to point to the struct nullb during tagset setup.

Fixes: 72ca287 ("null_blk: refactor tag_set setup")
Reviewed-by: Hannes Reinecke <[email protected]>
Signed-off-by: Nilay Shroff <[email protected]>
@ghost

ghost commented Aug 15, 2025

Copy link
Copy Markdown
Author

@ghost

ghost commented Aug 20, 2025

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants