mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-12-28 00:35:01 +00:00
block: avoid to reuse hctx
not removed from cpuhp callback list
If the 'hctx' isn't removed from cpuhp callback list, we can't reuse it,
otherwise use-after-free may be triggered.
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202412172217.b906db7c-lkp@intel.com
Tested-by: kernel test robot <oliver.sang@intel.com>
Fixes: 22465bbac5
("blk-mq: move cpuhp callback registering out of q->sysfs_lock")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20241218101617.3275704-3-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
224749be6c
commit
85672ca9ce
@ -4412,6 +4412,15 @@ struct gendisk *blk_mq_alloc_disk_for_queue(struct request_queue *q,
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL(blk_mq_alloc_disk_for_queue);
|
EXPORT_SYMBOL(blk_mq_alloc_disk_for_queue);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Only hctx removed from cpuhp list can be reused
|
||||||
|
*/
|
||||||
|
static bool blk_mq_hctx_is_reusable(struct blk_mq_hw_ctx *hctx)
|
||||||
|
{
|
||||||
|
return hlist_unhashed(&hctx->cpuhp_online) &&
|
||||||
|
hlist_unhashed(&hctx->cpuhp_dead);
|
||||||
|
}
|
||||||
|
|
||||||
static struct blk_mq_hw_ctx *blk_mq_alloc_and_init_hctx(
|
static struct blk_mq_hw_ctx *blk_mq_alloc_and_init_hctx(
|
||||||
struct blk_mq_tag_set *set, struct request_queue *q,
|
struct blk_mq_tag_set *set, struct request_queue *q,
|
||||||
int hctx_idx, int node)
|
int hctx_idx, int node)
|
||||||
@ -4421,7 +4430,7 @@ static struct blk_mq_hw_ctx *blk_mq_alloc_and_init_hctx(
|
|||||||
/* reuse dead hctx first */
|
/* reuse dead hctx first */
|
||||||
spin_lock(&q->unused_hctx_lock);
|
spin_lock(&q->unused_hctx_lock);
|
||||||
list_for_each_entry(tmp, &q->unused_hctx_list, hctx_list) {
|
list_for_each_entry(tmp, &q->unused_hctx_list, hctx_list) {
|
||||||
if (tmp->numa_node == node) {
|
if (tmp->numa_node == node && blk_mq_hctx_is_reusable(tmp)) {
|
||||||
hctx = tmp;
|
hctx = tmp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user