On Mon, Mar 07, 2022 at 02:44:01PM +0800, Ming Lei wrote: > Firstly code becomes more clean by switching to xarray from plain array. > > Secondly use-after-free on q->queue_hw_ctx can be fixed because Not a native speaker, but shouldn't this read First and Second? > mutex_lock(&q->sysfs_lock); > for (i = 0; i < set->nr_hw_queues; i++) { > int old_node; > int node = blk_mq_get_hctx_node(set, i); > - struct blk_mq_hw_ctx *old_hctx = hctxs[i]; > + struct blk_mq_hw_ctx *old_hctx = xa_load(&q->hctx_table, i); This should cand can xa_for_each_range. > for (; j < end; j++) { > - struct blk_mq_hw_ctx *hctx = hctxs[j]; > + struct blk_mq_hw_ctx *hctx = xa_load(&q->hctx_table, j); > > - if (hctx) { > + if (hctx) > blk_mq_exit_hctx(q, set, hctx, j); > - hctxs[j] = NULL; > - } Same here.