Skip to content

Commit

Permalink
[PATCH] blk_queue_start_tag() shared map race fix
Browse files Browse the repository at this point in the history
If we share the tag map between two or more queues, then we cannot
use __set_bit() to set the bit. In fact we need to make sure we
atomically acquire this tag, so loop using test_and_set_bit() to
protect from that.

Noticed by Mike Christie <[email protected]>

Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe authored and Jens Axboe committed Sep 30, 2006
1 parent 0fe2347 commit 059af49
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions block/ll_rw_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1171,11 +1171,16 @@ int blk_queue_start_tag(request_queue_t *q, struct request *rq)
BUG();
}

tag = find_first_zero_bit(bqt->tag_map, bqt->max_depth);
if (tag >= bqt->max_depth)
return 1;
/*
* Protect against shared tag maps, as we may not have exclusive
* access to the tag map.
*/
do {
tag = find_first_zero_bit(bqt->tag_map, bqt->max_depth);
if (tag >= bqt->max_depth)
return 1;

__set_bit(tag, bqt->tag_map);
} while (test_and_set_bit(tag, bqt->tag_map));

rq->cmd_flags |= REQ_QUEUED;
rq->tag = tag;
Expand Down

0 comments on commit 059af49

Please sign in to comment.