Re: [PATCH V4 1/7] blk-mq: grab .q_usage_counter when queuing request from plug code path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2019-04-04 at 16:43 +-0800, Ming Lei wrote:
+AD4 Just like aio/io+AF8-uring, we need to grab 2 refcount for queuing one
+AD4 request, one is for submission, another is for completion.
+AD4 
+AD4 If the request isn't queued from plug code path, the refcount grabbed
+AD4 in generic+AF8-make+AF8-request() serves for submission. In theroy, this
+AD4 refcount should have been released after the sumission(async run queue)
+AD4 is done. blk+AF8-freeze+AF8-queue() works with blk+AF8-sync+AF8-queue() together
+AD4 for avoiding race between cleanup queue and IO submission, given async
+AD4 run queue activities are canceled because hctx-+AD4-run+AF8-work is scheduled with
+AD4 the refcount held, so it is fine to not hold the refcount when
+AD4 running the run queue work function for dispatch IO.
+AD4 
+AD4 However, if request is staggered into plug list, and finally queued
+AD4 from plug code path, the refcount in submission side is actually missed.
+AD4 And we may start to run queue after queue is removed because the queue's
+AD4 kobject refcount isn't guaranteed to be grabbed in flushing plug list
+AD4 context, then kernel oops is triggered, see the following race:
+AD4 
+AD4 blk+AF8-mq+AF8-flush+AF8-plug+AF8-list():
+AD4         blk+AF8-mq+AF8-sched+AF8-insert+AF8-requests()
+AD4                 insert requests to sw queue or scheduler queue
+AD4                 blk+AF8-mq+AF8-run+AF8-hw+AF8-queue
+AD4 
+AD4 Because of concurrent run queue, all requests inserted above may be
+AD4 completed before calling the above blk+AF8-mq+AF8-run+AF8-hw+AF8-queue. Then queue can
+AD4 be freed during the above blk+AF8-mq+AF8-run+AF8-hw+AF8-queue().
+AD4 
+AD4 Fixes the issue by grab .q+AF8-usage+AF8-counter before calling
+AD4 blk+AF8-mq+AF8-sched+AF8-insert+AF8-requests() in blk+AF8-mq+AF8-flush+AF8-plug+AF8-list(). This way is
+AD4 safe because the queue is absolutely alive before inserting request.

Reviewed-by: Bart Van Assche +ADw-bvanassche+AEA-acm.org+AD4-



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux