zloop: protect state check with zloop_ctl_mutex locked in zloop_queue_rq
Subsystems (2)
PATCH 1/1 zloop: protect state check with zloop_ctl_mutex locked in zloop_queue_rq
From: Yongpeng Yang <[email protected]>
zlo->state is not an atomic variable, so checking 'zlo->state == Zlo_deleting' must be done under zloop_ctl_mutex.
--- drivers/block/zloop.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/block/zloop.c +5 -2
@@ -697,9 +697,12 @@ static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx,struct zloop_cmd *cmd =blk_mq_rq_to_pdu (rq);struct zloop_device *zlo = rq->q->queuedata; -if (zlo->state == Zlo_deleting) +mutex_lock (&zloop_ctl_mutex); +if (zlo->state == Zlo_deleting) { +mutex_unlock (&zloop_ctl_mutex);return BLK_STS_IOERR ; - + } +mutex_unlock (&zloop_ctl_mutex);/* * If we need to strongly order zone append operations, set the request * sector to the zone write pointer location now instead of when the
Signature · 1 line
2.43.0
Jens Axboe
maintainerQuoted 16 lines · Yongpeng Yang
From: Yongpeng Yang <[email protected]>
zlo->stateis not an atomic variable, so checking 'zlo->state==Zlo_deleting' must be done underzloop_ctl_mutex.Signed-off-by Yongpeng Yang <[email protected]>--- drivers/block/zloop.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/block/zloop.c +0
-0@@ -697,9 +697,12 @@ static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx,struct zloop_cmd *cmd =blk_mq_rq_to_pdu (rq);
drivers/block/zloop.c static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx, · line 705
Quoted 10 lines
drivers/block/zloop.c +5
-2struct zloop_device *zlo = rq->q->queuedata; -if (zlo->state == Zlo_deleting) +mutex_lock (&zloop_ctl_mutex); +if (zlo->state == Zlo_deleting) { +mutex_unlock (&zloop_ctl_mutex);return BLK_STS_IOERR ; - + } +mutex_unlock (&zloop_ctl_mutex);
Probably a better idea to make the state checking atomic, and avoid the mutex in the queue_rq path.
Signature · 1 line
Jens Axboe
Quoted 19 lines · Jens Axboe
Quoted 18 lines · Yongpeng Yang
From: Yongpeng Yang <[email protected]>
zlo->stateis not an atomic variable, so checking 'zlo->state==Zlo_deleting' must be done underzloop_ctl_mutex.Signed-off-by Yongpeng Yang <[email protected]>--- drivers/block/zloop.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/block/zloop.c +0
-0@@ -697,9 +697,12 @@ static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx,struct zloop_cmd *cmd =blk_mq_rq_to_pdu (rq);struct zloop_device *zlo = rq->q->queuedata;
Quoted 12 lines
drivers/block/zloop.c static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx, · line 705
Quoted 8 lines
drivers/block/zloop.c +5
-2-if (zlo->state == Zlo_deleting) +mutex_lock (&zloop_ctl_mutex); +if (zlo->state == Zlo_deleting) { +mutex_unlock (&zloop_ctl_mutex);return BLK_STS_IOERR ; - + } +mutex_unlock (&zloop_ctl_mutex);Probably a better idea to make the state checking atomic, and avoid the mutex in the
queue_rqpath.
It is more reasonable, I'll fix this in v2.
Thanks
Yongpeng,
Damien Le Moal
maintainerQuoted 33 lines · Yongpeng Yang
Quoted 19 lines · Jens Axboe
Quoted 18 lines · Yongpeng Yang
From: Yongpeng Yang <[email protected]>
zlo->stateis not an atomic variable, so checking 'zlo->state==Zlo_deleting' must be done underzloop_ctl_mutex.Signed-off-by Yongpeng Yang <[email protected]>--- drivers/block/zloop.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/block/zloop.c +0
-0@@ -697,9 +697,12 @@ static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx,struct zloop_cmd *cmd =blk_mq_rq_to_pdu (rq);struct zloop_device *zlo = rq->q->queuedata;Quoted 12 lines
drivers/block/zloop.c static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx, · line 705
Quoted 8 lines
drivers/block/zloop.c +5
-2-if (zlo->state == Zlo_deleting) +mutex_lock (&zloop_ctl_mutex); +if (zlo->state == Zlo_deleting) { +mutex_unlock (&zloop_ctl_mutex);return BLK_STS_IOERR ; - + } +mutex_unlock (&zloop_ctl_mutex);Probably a better idea to make the state checking atomic, and avoid the mutex in the
queue_rqpath.
Quoted 1 line
It is more reasonable, I'll fix this in v2.
Either what Jens proposed, or move the check to zloop_handle_cmd(), since that is run in work item context, we can block there.
Of note, is that the loop driver does the same thing in loop_queue_rq(): the device state is checked without the loop device mutex held. So a similar fix there may also be nice to have.
Quoted 3 lines
Thanks
Yongpeng,
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 34 lines · Damien Le Moal
Quoted 33 lines · Yongpeng Yang
Quoted 31 lines · Jens Axboe
Quoted 16 lines · Yongpeng Yang
From: Yongpeng Yang <[email protected]>
zlo->stateis not an atomic variable, so checking 'zlo->state==Zlo_deleting' must be done underzloop_ctl_mutex.Signed-off-by Yongpeng Yang <[email protected]>--- drivers/block/zloop.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/block/zloop.c +0
-0@@ -697,9 +697,12 @@ static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx,struct zloop_cmd *cmd =blk_mq_rq_to_pdu (rq);drivers/block/zloop.c static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx, · line 705
Quoted 10 lines
drivers/block/zloop.c +5
-2struct zloop_device *zlo = rq->q->queuedata; -if (zlo->state == Zlo_deleting) +mutex_lock (&zloop_ctl_mutex); +if (zlo->state == Zlo_deleting) { +mutex_unlock (&zloop_ctl_mutex);return BLK_STS_IOERR ; - + } +mutex_unlock (&zloop_ctl_mutex);Probably a better idea to make the state checking atomic, and avoid the mutex in the
queue_rqpath.
Quoted 4 lines
Quoted 1 line
It is more reasonable, I'll fix this in v2.
Either what Jens proposed, or move the check to
zloop_handle_cmd(), since that is run in work item context, we can block there.
Yes, both approaches are fine. The zloop driver has only 3 states, using an atomic variable seems more concise.
Quoted 4 lines
Of note, is that the loop driver does the same thing in
loop_queue_rq(): the device state is checked without the loop device mutex held. So a similar fix there may also be nice to have.
Yes, the loop driver has a similar issue, and I will attempt to fix it as well.
Thanks
Yongpeng,
Quoted 6 lines
Quoted 4 lines
Thanks
Yongpeng,