On 2019-11-15 23:17, Ming Lei wrote: > Now blk-mq takes a static queue mapping between CPU and hw queues, given > CPU hotplug may happen any time, so the specified hw queue may become > inactive any time. Hi Ming, I can trigger a race between blk_mq_alloc_request_hctx() and CPU-hotplugging by running blktests. The patch below fixes that race on my setup. Does this patch also fix the race(s) that you ran into? Thanks, Bart. Subject: [PATCH] blk-mq: Fix a race between blk_mq_alloc_request_hctx() and CPU hot-plugging --- block/blk-mq.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 20a71dcdc339..16057aa2307f 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -442,13 +442,15 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q, if (WARN_ON_ONCE(!(flags & BLK_MQ_REQ_NOWAIT))) return ERR_PTR(-EINVAL); - if (hctx_idx >= q->nr_hw_queues) - return ERR_PTR(-EIO); - ret = blk_queue_enter(q, flags); if (ret) return ERR_PTR(ret); + if (hctx_idx >= q->nr_hw_queues) { + blk_queue_exit(q); + return ERR_PTR(-EIO); + } + /* * Check if the hardware context is actually mapped to anything. * If not tell the caller that it should skip this queue.