Skip to content

Conversation

@blktests-ci
Copy link

@blktests-ci blktests-ci bot commented Nov 20, 2025

Pull request for series with
subject: blk-mq: use array manage hctx map instead of xarray
version: 1
url: https://patchwork.kernel.org/project/linux-block/list/?series=1025620

@blktests-ci
Copy link
Author

blktests-ci bot commented Nov 20, 2025

Upstream branch: 8b69055
series: https://patchwork.kernel.org/project/linux-block/list/?series=1025620
version: 1

@blktests-ci
Copy link
Author

blktests-ci bot commented Nov 21, 2025

Upstream branch: fd95357
series: https://patchwork.kernel.org/project/linux-block/list/?series=1025620
version: 1

Fengnan Chang added 2 commits November 21, 2025 18:54
After commit 4e5cc99 ("blk-mq: manage hctx map via xarray"), we use
an xarray instead of array to store hctx, but in poll mode, each time
in blk_mq_poll, we need use xa_load to find corresponding hctx, this
introduce some costs. In my test, xa_load may cost 3.8% cpu.

This patch revert previous change, eliminates the overhead of xa_load
and can result in a 3% performance improvement.

use-after-free on q->queue_hw_ctx can be fixed by use rcu to avoid in
next patch, same as Yu Kuai did in [1],

[1] https://lore.kernel.org/all/[email protected]/

Signed-off-by: Fengnan Chang <[email protected]>
This is just apply Kuai's patch in [1].

blk_mq_realloc_hw_ctxs() will free the 'queue_hw_ctx'(e.g. undate
submit_queues through configfs for null_blk), while it might still be
used from other context(e.g. switch elevator to none):

t1					t2
elevator_switch
 blk_mq_unquiesce_queue
  blk_mq_run_hw_queues
   queue_for_each_hw_ctx
    // assembly code for hctx = (q)->queue_hw_ctx[i]
    mov    0x48(%rbp),%rdx -> read old queue_hw_ctx

					__blk_mq_update_nr_hw_queues
					 blk_mq_realloc_hw_ctxs
					  hctxs = q->queue_hw_ctx
					  q->queue_hw_ctx = new_hctxs
					  kfree(hctxs)
    movslq %ebx,%rax
    mov    (%rdx,%rax,8),%rdi ->uaf

This problem was found by code review, and I comfirmed that the concurrent
scenario do exist(specifically 'q->queue_hw_ctx' can be changed during
blk_mq_run_hw_queues()), however, the uaf problem hasn't been repoduced yet
without hacking the kernel.

Sicne the queue is freezed in __blk_mq_update_nr_hw_queues(), fix the
problem by protecting 'queue_hw_ctx' through rcu where it can be accessed
without grabbing 'q_usage_counter'.

[1] https://lore.kernel.org/all/[email protected]/

Signed-off-by: Yu Kuai <[email protected]>
Signed-off-by: Fengnan Chang <[email protected]>
@blktests-ci blktests-ci bot force-pushed the series/1025620=>linus-master branch from 5e5954e to 3689420 Compare November 21, 2025 09:54
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.

1 participant