Skip to contentSkip to conversation

xen-blkfront: fix mq start/stop race

PATCH Superseded Junxiao Bi 4 participants 9 messages Jun 22, 2017 – Jul 20, 2017

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Junxiao Bi

author
#0 lore raw

PATCH 1/1 xen-blkfront: fix mq start/stop race

When ring buf full, hw queue will be stopped. While blkif interrupt consume request and make free space in ring buf, hw queue will be started again. But since start queue is protected by spin lock while stop not, that will cause a race.

interrupt: process:
blkif_interrupt() blkif_queue_rq()
kick_pending_request_queues_locked()
blk_mq_start_stopped_hw_queues()
clear_bit(BLK_MQ_S_STOPPED, &hctx->state)
blk_mq_stop_hw_queue(hctx)
blk_mq_run_hw_queue(hctx, async)

If ring buf is made empty in this case, interrupt will never come, then the hw queue will be stopped forever, all processes waiting for the pending io in the queue will hung.

---
 drivers/block/xen-blkfront.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/xen-blkfront.c +1 -1
index 8bb160cd00e1..4767b82b2cf6 100644
@@ -912,8 +912,8 @@ out_err:
 	return BLK_MQ_RQ_QUEUE_ERROR;
 
 out_busy:
-	spin_unlock_irqrestore(&rinfo->ring_lock, flags);
 	blk_mq_stop_hw_queue(hctx);
+	spin_unlock_irqrestore(&rinfo->ring_lock, flags);
 	return BLK_MQ_RQ_QUEUE_BUSY;
 }
 
Signature · 7 lines
1.7.9.5


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author
#1 lore raw

Hi Boris & Juergen,

Could you help review this patch? This is a race and will cause the io hung.

Thanks,
Junxiao.

Quoted 29 lines · Junxiao Bi

When ring buf full, hw queue will be stopped. While blkif interrupt consume request and make free space in ring buf, hw queue will be started again. But since start queue is protected by spin lock while stop not, that will cause a race.

interrupt: process:
blkif_interrupt() blkif_queue_rq()
kick_pending_request_queues_locked()
blk_mq_start_stopped_hw_queues()
clear_bit(BLK_MQ_S_STOPPED, &hctx->state)
blk_mq_stop_hw_queue(hctx)
blk_mq_run_hw_queue(hctx, async)

If ring buf is made empty in this case, interrupt will never come, then the hw queue will be stopped forever, all processes waiting for the pending io in the queue will hung.

---
 drivers/block/xen-blkfront.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/xen-blkfront.c +0 -0
index 8bb160cd00e1..4767b82b2cf6 100644

drivers/block/xen-blkfront.c out_err: · line 919

Quoted 9 lines
drivers/block/xen-blkfront.c +1 -1
@@ -912,8 +912,8 @@ out_err:
 	return BLK_MQ_RQ_QUEUE_ERROR;
 
 out_busy:
-	spin_unlock_irqrestore(&rinfo->ring_lock, flags);
 	blk_mq_stop_hw_queue(hctx);
+	spin_unlock_irqrestore(&rinfo->ring_lock, flags);
 	return BLK_MQ_RQ_QUEUE_BUSY;
 }
 

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by
#2 lore raw
Quoted 27 lines · Junxiao Bi

Hi Boris & Juergen,

Could you help review this patch? This is a race and will cause the io hung.

Thanks,
Junxiao.

Quoted 19 lines · Junxiao Bi

When ring buf full, hw queue will be stopped. While blkif interrupt consume request and make free space in ring buf, hw queue will be started again. But since start queue is protected by spin lock while stop not, that will cause a race.

interrupt: process:
blkif_interrupt() blkif_queue_rq()
kick_pending_request_queues_locked()
blk_mq_start_stopped_hw_queues()

    clear_bit(BLK_MQ_S_STOPPED, &hctx->state)
                                                  blk_mq_stop_hw_queue(hctx)
    blk_mq_run_hw_queue(hctx, async)

If ring buf is made empty in this case, interrupt will never come, then the hw queue will be stopped forever, all processes waiting for the pending io in the queue will hung.

but I think Roger (copied) needs to Ack it.

-boris

Quoted 11 lines
Quoted 11 lines
---
  drivers/block/xen-blkfront.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/xen-blkfront.c +0 -0
index 8bb160cd00e1..4767b82b2cf6 100644
@@ -912,8 +912,8 @@ out_err:
  	return BLK_MQ_RQ_QUEUE_ERROR;
 
Quoted 9 lines

drivers/block/xen-blkfront.c out_err: · line 919

Quoted 8 lines
drivers/block/xen-blkfront.c +1 -1
  out_busy:
-	spin_unlock_irqrestore(&rinfo->ring_lock, flags);
  	blk_mq_stop_hw_queue(hctx);
+	spin_unlock_irqrestore(&rinfo->ring_lock, flags);
  	return BLK_MQ_RQ_QUEUE_BUSY;
  }
 

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Acked-by on v1 1/1
#3 lore raw
In reply to Junxiao Bi
Quoted 13 lines · Junxiao Bi

When ring buf full, hw queue will be stopped. While blkif interrupt consume request and make free space in ring buf, hw queue will be started again. But since start queue is protected by spin lock while stop not, that will cause a race.

interrupt: process:
blkif_interrupt() blkif_queue_rq()
kick_pending_request_queues_locked()
blk_mq_start_stopped_hw_queues()
clear_bit(BLK_MQ_S_STOPPED, &hctx->state)
blk_mq_stop_hw_queue(hctx)
blk_mq_run_hw_queue(hctx, async)

Quoted 6 lines

If ring buf is made empty in this case, interrupt will never come, then the hw queue will be stopped forever, all processes waiting for the pending io in the queue will hung.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#4 lore raw

Hi Roger,

Quoted 14 lines · Roger Pau Monné
Quoted 13 lines · Junxiao Bi

When ring buf full, hw queue will be stopped. While blkif interrupt consume request and make free space in ring buf, hw queue will be started again. But since start queue is protected by spin lock while stop not, that will cause a race.

interrupt: process:
blkif_interrupt() blkif_queue_rq()
kick_pending_request_queues_locked()
blk_mq_start_stopped_hw_queues()
clear_bit(BLK_MQ_S_STOPPED, &hctx->state)
blk_mq_stop_hw_queue(hctx)
blk_mq_run_hw_queue(hctx, async)

Quoted 8 lines
Quoted 6 lines

If ring buf is made empty in this case, interrupt will never come, then the hw queue will be stopped forever, all processes waiting for the pending io in the queue will hung.

Looks patch not in mainline. Can you please help merge it?

Thanks,
Junxiao.

Quoted 8 lines

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
Quoted 21 lines · Junxiao Bi

Hi Roger,

Quoted 18 lines · Roger Pau Monné
Quoted 17 lines · Junxiao Bi

When ring buf full, hw queue will be stopped. While blkif interrupt consume request and make free space in ring buf, hw queue will be started again. But since start queue is protected by spin lock while stop not, that will cause a race.

interrupt: process:
blkif_interrupt() blkif_queue_rq()
kick_pending_request_queues_locked()
blk_mq_start_stopped_hw_queues()
clear_bit(BLK_MQ_S_STOPPED, &hctx->state)
blk_mq_stop_hw_queue(hctx)
blk_mq_run_hw_queue(hctx, async)

If ring buf is made empty in this case, interrupt will never come, then the hw queue will be stopped forever, all processes waiting for the pending io in the queue will hung.

Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

Looks patch not in mainline. Can you please help merge it?

I'm afraid this needs to be done by Konrad or one of the Linux maintainers, I don't have an account on kernel.org in order to send pull requests to Jens.

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#6 lore raw

Hi Konrad,

Quoted 25 lines · Roger Pau Monné
Quoted 24 lines · Junxiao Bi

Hi Roger,

Quoted 21 lines · Roger Pau Monné
Quoted 19 lines · Junxiao Bi

When ring buf full, hw queue will be stopped. While blkif interrupt consume request and make free space in ring buf, hw queue will be started again. But since start queue is protected by spin lock while stop not, that will cause a race.

interrupt: process:
blkif_interrupt() blkif_queue_rq()
kick_pending_request_queues_locked()
blk_mq_start_stopped_hw_queues()
clear_bit(BLK_MQ_S_STOPPED, &hctx->state)
blk_mq_stop_hw_queue(hctx)
blk_mq_run_hw_queue(hctx, async)

If ring buf is made empty in this case, interrupt will never come, then the hw queue will be stopped forever, all processes waiting for the pending io in the queue will hung.

Quoted 6 lines
Quoted 2 lines
Quoted 1 line

Looks patch not in mainline. Can you please help merge it?

I'm afraid this needs to be done by Konrad or one of the Linux maintainers, I don't have an account on kernel.org in order to send pull requests to Jens.

Can you pls help merge it?

Thanks,
Junxiao.

Quoted 3 lines

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#7 lore raw
Quoted 28 lines · Junxiao Bi

Hi Konrad,

Quoted 25 lines · Roger Pau Monné
Quoted 24 lines · Junxiao Bi

Hi Roger,

Quoted 21 lines · Roger Pau Monné
Quoted 19 lines · Junxiao Bi

When ring buf full, hw queue will be stopped. While blkif interrupt consume request and make free space in ring buf, hw queue will be started again. But since start queue is protected by spin lock while stop not, that will cause a race.

interrupt: process:
blkif_interrupt() blkif_queue_rq()
kick_pending_request_queues_locked()
blk_mq_start_stopped_hw_queues()
clear_bit(BLK_MQ_S_STOPPED, &hctx->state)
blk_mq_stop_hw_queue(hctx)
blk_mq_run_hw_queue(hctx, async)

If ring buf is made empty in this case, interrupt will never come, then the hw queue will be stopped forever, all processes waiting for the pending io in the queue will hung.

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
Quoted 1 line

Looks patch not in mainline. Can you please help merge it?

I'm afraid this needs to be done by Konrad or one of the Linux maintainers, I don't have an account on kernel.org in order to send pull requests to Jens.

Can you pls help merge it?

Could you kindly repost it with the updated tags _and_ against Linus's latest branch?

I get:
[konrad@char linux]$ git am -s < /tmp/a
Applying: xen-blkfront: fix mq start/stop race
error: patch failed: drivers/block/xen-blkfront.c:912
error: drivers/block/xen-blkfront.c: patch does not apply Patch failed at 0001 xen-blkfront: fix mq start/stop race The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".

Quoted 7 lines

Thanks,
Junxiao.

Quoted 3 lines

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author
#8 lore raw
Quoted 32 lines · Konrad Rzeszutek Wilk
Quoted 31 lines · Junxiao Bi

Hi Konrad,

Quoted 28 lines · Roger Pau Monné
Quoted 26 lines · Junxiao Bi

Hi Roger,

Quoted 14 lines · Roger Pau Monné
Quoted 13 lines · Junxiao Bi

When ring buf full, hw queue will be stopped. While blkif interrupt consume request and make free space in ring buf, hw queue will be started again. But since start queue is protected by spin lock while stop not, that will cause a race.

interrupt: process:
blkif_interrupt() blkif_queue_rq()
kick_pending_request_queues_locked()
blk_mq_start_stopped_hw_queues()
clear_bit(BLK_MQ_S_STOPPED, &hctx->state)
blk_mq_stop_hw_queue(hctx)
blk_mq_run_hw_queue(hctx, async)

Quoted 8 lines
Quoted 6 lines

If ring buf is made empty in this case, interrupt will never come, then the hw queue will be stopped forever, all processes waiting for the pending io in the queue will hung.

Looks patch not in mainline. Can you please help merge it?

Quoted 7 lines
Quoted 4 lines
Quoted 3 lines

I'm afraid this needs to be done by Konrad or one of the Linux maintainers, I don't have an account on kernel.org in order to send pull requests to Jens.

Can you pls help merge it?

Could you kindly repost it with the updated tags _and_ against Linus's latest branch?

Sure, v2 sent. Please check.

Thanks,
Junxiao.

Quoted 20 lines

I get:
[konrad@char linux]$ git am -s < /tmp/a
Applying: xen-blkfront: fix mq start/stop race
error: patch failed: drivers/block/xen-blkfront.c:912
error: drivers/block/xen-blkfront.c: patch does not apply Patch failed at 0001 xen-blkfront: fix mq start/stop race The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".

Quoted 7 lines

Thanks,
Junxiao.

Quoted 3 lines

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel