Re: [PATCH V3 6/6] blk-mq: manage hctx map via xarray

Ming Lei
2022-03-07T07:45:22Z

On Mon, Mar 07, 2022 at 08:13:17AM +0100, Christoph Hellwig wrote:
> 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?

OK, will fix it in next version.

>
> > 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.

It may not work here since xa_for_each_range() breaks if NULL entry is
found. Even two loops can't work too because we need old numa node
for reallocation.

>
> > 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;
> > - }

This one can be converted directly.

Thanks,
Ming