blk-mq: Avoid race condition with uninitialized requests
Subsystems (4)
PATCH 1/1 blk-mq: Avoid race condition with uninitialized requests
This patch should fix the bug reported in https://lkml.org/lkml/2014/9/11/249.
Test is still pending.
David Hildenbrand (1):
blk-mq: Avoid race condition with uninitialized requests
block/blk-mq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.5.5
PATCH 1/1 blk-mq: Avoid race condition with uninitialized requests
This patch should fix the bug reported in https://lkml.org/lkml/2014/9/11/249.
We have to initialize at least the atomic_flags and the cmd_flags when allocating storage for the requests.
Otherwise blk_mq_timeout_check() might dereference uninitialized pointers when racing with the creation of a request.
Also move the reset of cmd_flags for the initializing code to the point where a request is freed. So we will never end up with pending flush request indicators that might trigger dereferences of invalid pointers in blk_mq_timeout_check().
--- block/blk-mq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
block/blk-mq.c +3 -1
@@ -203,7 +203,6 @@ __blk_mq_alloc_request(struct blk_mq_alloc_data *data, int rw)if (tag !=BLK_MQ_TAG_FAIL ) { rq = data->hctx->tags->rqs[tag]; - rq->cmd_flags =0 ;if (blk_mq_tag_busy (data->hctx)) { rq->cmd_flags =REQ_MQ_INFLIGHT ;atomic_inc (&data->hctx->nr_active);
@@ -258,6 +257,7 @@ static void __blk_mq_free_request(struct blk_mq_hw_ctx *hctx,if (rq->cmd_flags &REQ_MQ_INFLIGHT )atomic_dec (&hctx->nr_active); + rq->cmd_flags =0 ;clear_bit (REQ_ATOM_STARTED , &rq->atomic_flags);blk_mq_put_tag (hctx, tag, &ctx->last_tag);
@@ -1404,6 +1404,8 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set, left -= to_do * rq_size;for (j =0 ; j < to_do; j++) { tags->rqs[i] = p; + tags->rqs[i]->atomic_flags =0 ; + tags->rqs[i]->cmd_flags =0 ;if (set->ops->init_request) { if (set->ops->init_request(set->driver_data, tags->rqs[i], hctx_idx, i,
Signature · 1 line
1.8.5.5
Quoted 8 lines · David Hildenbrand
This patch should fix the bug reported in https://lkml.org/lkml/2014/9/11/249.
We have to initialize at least the
atomic_flagsand thecmd_flagswhen allocating storage for the requests.Otherwise
blk_mq_timeout_check()might dereference uninitialized pointers when racing with the creation of a request.
Quoted 6 lines
Also move the reset of
cmd_flagsfor the initializing code to the point where a request is freed. So we will never end up with pending flush request indicators that might trigger dereferences of invalid pointers inblk_mq_timeout_check().Signed-off-by David Hildenbrand <[email protected]>
So far our testers were not able to reproduce the problem with this patch applied, we will continue testing over weekend. I will give an ACK/NACK on monday then.
Thanks
Quoted 34 lines
--- block/blk-mq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)block/blk-mq.c +3
-1@@ -203,7 +203,6 @@ __blk_mq_alloc_request(struct blk_mq_alloc_data *data, int rw)if (tag !=BLK_MQ_TAG_FAIL ) { rq = data->hctx->tags->rqs[tag]; - rq->cmd_flags =0 ;if (blk_mq_tag_busy (data->hctx)) { rq->cmd_flags =REQ_MQ_INFLIGHT ;atomic_inc (&data->hctx->nr_active);@@ -258,6 +257,7 @@ static void __blk_mq_free_request(struct blk_mq_hw_ctx *hctx,if (rq->cmd_flags &REQ_MQ_INFLIGHT )atomic_dec (&hctx->nr_active); + rq->cmd_flags =0 ;clear_bit (REQ_ATOM_STARTED , &rq->atomic_flags);blk_mq_put_tag (hctx, tag, &ctx->last_tag);@@ -1404,6 +1404,8 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set, left -= to_do * rq_size;for (j =0 ; j < to_do; j++) { tags->rqs[i] = p; + tags->rqs[i]->atomic_flags =0 ; + tags->rqs[i]->cmd_flags =0 ;if (set->ops->init_request) { if (set->ops->init_request(set->driver_data, tags->rqs[i], hctx_idx, i,
Quoted 8 lines · David Hildenbrand
This patch should fix the bug reported in https://lkml.org/lkml/2014/9/11/249.
We have to initialize at least the
atomic_flagsand thecmd_flagswhen allocating storage for the requests.Otherwise
blk_mq_timeout_check()might dereference uninitialized pointers when racing with the creation of a request.
Quoted 6 lines
Also move the reset of
cmd_flagsfor the initializing code to the point where a request is freed. So we will never end up with pending flush request indicators that might trigger dereferences of invalid pointers inblk_mq_timeout_check().Signed-off-by David Hildenbrand <[email protected]>
So far our testers were not able to reproduce the problem with this patch applied, we will continue testing over weekend. I will give an ACK/NACK on monday then.
Thanks
Quoted 34 lines
--- block/blk-mq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)block/blk-mq.c +3
-1@@ -203,7 +203,6 @@ __blk_mq_alloc_request(struct blk_mq_alloc_data *data, int rw)if (tag !=BLK_MQ_TAG_FAIL ) { rq = data->hctx->tags->rqs[tag]; - rq->cmd_flags =0 ;if (blk_mq_tag_busy (data->hctx)) { rq->cmd_flags =REQ_MQ_INFLIGHT ;atomic_inc (&data->hctx->nr_active);@@ -258,6 +257,7 @@ static void __blk_mq_free_request(struct blk_mq_hw_ctx *hctx,if (rq->cmd_flags &REQ_MQ_INFLIGHT )atomic_dec (&hctx->nr_active); + rq->cmd_flags =0 ;clear_bit (REQ_ATOM_STARTED , &rq->atomic_flags);blk_mq_put_tag (hctx, tag, &ctx->last_tag);@@ -1404,6 +1404,8 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set, left -= to_do * rq_size;for (j =0 ; j < to_do; j++) { tags->rqs[i] = p; + tags->rqs[i]->atomic_flags =0 ; + tags->rqs[i]->cmd_flags =0 ;if (set->ops->init_request) { if (set->ops->init_request(set->driver_data, tags->rqs[i], hctx_idx, i,
Quoted 8 lines · David Hildenbrand
This patch should fix the bug reported in https://lkml.org/lkml/2014/9/11/249.
We have to initialize at least the
atomic_flagsand thecmd_flagswhen allocating storage for the requests.Otherwise
blk_mq_timeout_check()might dereference uninitialized pointers when racing with the creation of a request.
Quoted 6 lines
Also move the reset of
cmd_flagsfor the initializing code to the point where a request is freed. So we will never end up with pending flush request indicators that might trigger dereferences of invalid pointers inblk_mq_timeout_check().Signed-off-by David Hildenbrand <[email protected]>
Can you please add
as Paulo did the testing work?
We thing this patch is fine and should go upstream.
Christian
Quoted 34 lines
--- block/blk-mq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)block/blk-mq.c +3
-1@@ -203,7 +203,6 @@ __blk_mq_alloc_request(struct blk_mq_alloc_data *data, int rw)if (tag !=BLK_MQ_TAG_FAIL ) { rq = data->hctx->tags->rqs[tag]; - rq->cmd_flags =0 ;if (blk_mq_tag_busy (data->hctx)) { rq->cmd_flags =REQ_MQ_INFLIGHT ;atomic_inc (&data->hctx->nr_active);@@ -258,6 +257,7 @@ static void __blk_mq_free_request(struct blk_mq_hw_ctx *hctx,if (rq->cmd_flags &REQ_MQ_INFLIGHT )atomic_dec (&hctx->nr_active); + rq->cmd_flags =0 ;clear_bit (REQ_ATOM_STARTED , &rq->atomic_flags);blk_mq_put_tag (hctx, tag, &ctx->last_tag);@@ -1404,6 +1404,8 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set, left -= to_do * rq_size;for (j =0 ; j < to_do; j++) { tags->rqs[i] = p; + tags->rqs[i]->atomic_flags =0 ; + tags->rqs[i]->cmd_flags =0 ;if (set->ops->init_request) { if (set->ops->init_request(set->driver_data, tags->rqs[i], hctx_idx, i,
Jens Axboe
maintainerQuoted 18 lines · Christian Borntraeger
Quoted 8 lines · David Hildenbrand
This patch should fix the bug reported in https://lkml.org/lkml/2014/9/11/249.
We have to initialize at least the
atomic_flagsand thecmd_flagswhen allocating storage for the requests.Otherwise
blk_mq_timeout_check()might dereference uninitialized pointers when racing with the creation of a request.Quoted 6 lines
Also move the reset of
cmd_flagsfor the initializing code to the point where a request is freed. So we will never end up with pending flush request indicators that might trigger dereferences of invalid pointers inblk_mq_timeout_check().Signed-off-by David Hildenbrand <[email protected]>
Quoted 7 lines
Can you please add
Reported-by Paulo De Rezende Pinatti <[email protected]>as Paulo did the testing work?
We thing this patch is fine and should go upstream.
I might have to pick'n rebase the series, in which case I'll add it. But I already queued it up last week, so if I don't, then I can't easily add it. I wish the git notes wasn't such a horrible and unusable hack, so we had a chance to annotate commits without having to rewrite history...
Signature · 1 line
Jens Axboe
Quoted 8 lines · David Hildenbrand
This patch should fix the bug reported in https://lkml.org/lkml/2014/9/11/249.
We have to initialize at least the
atomic_flagsand thecmd_flagswhen allocating storage for the requests.Otherwise
blk_mq_timeout_check()might dereference uninitialized pointers when racing with the creation of a request.
Quoted 6 lines
Also move the reset of
cmd_flagsfor the initializing code to the point where a request is freed. So we will never end up with pending flush request indicators that might trigger dereferences of invalid pointers inblk_mq_timeout_check().Signed-off-by David Hildenbrand <[email protected]>
Can you please add
as Paulo did the testing work?
We thing this patch is fine and should go upstream.
Christian
Quoted 34 lines
--- block/blk-mq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)block/blk-mq.c +3
-1@@ -203,7 +203,6 @@ __blk_mq_alloc_request(struct blk_mq_alloc_data *data, int rw)if (tag !=BLK_MQ_TAG_FAIL ) { rq = data->hctx->tags->rqs[tag]; - rq->cmd_flags =0 ;if (blk_mq_tag_busy (data->hctx)) { rq->cmd_flags =REQ_MQ_INFLIGHT ;atomic_inc (&data->hctx->nr_active);@@ -258,6 +257,7 @@ static void __blk_mq_free_request(struct blk_mq_hw_ctx *hctx,if (rq->cmd_flags &REQ_MQ_INFLIGHT )atomic_dec (&hctx->nr_active); + rq->cmd_flags =0 ;clear_bit (REQ_ATOM_STARTED , &rq->atomic_flags);blk_mq_put_tag (hctx, tag, &ctx->last_tag);@@ -1404,6 +1404,8 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set, left -= to_do * rq_size;for (j =0 ; j < to_do; j++) { tags->rqs[i] = p; + tags->rqs[i]->atomic_flags =0 ; + tags->rqs[i]->cmd_flags =0 ;if (set->ops->init_request) { if (set->ops->init_request(set->driver_data, tags->rqs[i], hctx_idx, i,
PATCH 1/1 blk-mq: Avoid race condition with uninitialized requests
In reply to David HildenbrandThis patch should fix the bug reported in https://lkml.org/lkml/2014/9/11/249.
We have to initialize at least the atomic_flags and the cmd_flags when allocating storage for the requests.
Otherwise blk_mq_timeout_check() might dereference uninitialized pointers when racing with the creation of a request.
Also move the reset of cmd_flags for the initializing code to the point where a request is freed. So we will never end up with pending flush request indicators that might trigger dereferences of invalid pointers in blk_mq_timeout_check().
--- block/blk-mq.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
block/blk-mq.c +3 -1
@@ -203,7 +203,6 @@ __blk_mq_alloc_request(struct blk_mq_alloc_data *data, int rw)if (tag !=BLK_MQ_TAG_FAIL ) { rq = data->hctx->tags->rqs[tag]; - rq->cmd_flags =0 ;if (blk_mq_tag_busy (data->hctx)) { rq->cmd_flags =REQ_MQ_INFLIGHT ;atomic_inc (&data->hctx->nr_active);
@@ -258,6 +257,7 @@ static void __blk_mq_free_request(struct blk_mq_hw_ctx *hctx,if (rq->cmd_flags &REQ_MQ_INFLIGHT )atomic_dec (&hctx->nr_active); + rq->cmd_flags =0 ;clear_bit (REQ_ATOM_STARTED , &rq->atomic_flags);blk_mq_put_tag (hctx, tag, &ctx->last_tag);
@@ -1404,6 +1404,8 @@ static struct blk_mq_tags *blk_mq_init_rq_map(struct blk_mq_tag_set *set, left -= to_do * rq_size;for (j =0 ; j < to_do; j++) { tags->rqs[i] = p; + tags->rqs[i]->atomic_flags =0 ; + tags->rqs[i]->cmd_flags =0 ;if (set->ops->init_request) { if (set->ops->init_request(set->driver_data, tags->rqs[i], hctx_idx, i,
Signature · 1 line
1.8.5.5