Skip to content

Commit 149a051

Browse files
author
Jens Axboe
committed
as-iosched: fix double locking bug in as_merged_requests()
If the two requests belong to the same io context, we will attempt to lock the same lock twice. But swapping contexts is pointless in that case, so just check for rioc == nioc before doing the double lock and copy. Tested-by: Olof Johansson <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 5b10ca1 commit 149a051

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

block/as-iosched.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,9 +1275,13 @@ static void as_merged_requests(struct request_queue *q, struct request *req,
12751275
* Don't copy here but swap, because when anext is
12761276
* removed below, it must contain the unused context
12771277
*/
1278-
double_spin_lock(&rioc->lock, &nioc->lock, rioc < nioc);
1279-
swap_io_context(&rioc, &nioc);
1280-
double_spin_unlock(&rioc->lock, &nioc->lock, rioc < nioc);
1278+
if (rioc != nioc) {
1279+
double_spin_lock(&rioc->lock, &nioc->lock,
1280+
rioc < nioc);
1281+
swap_io_context(&rioc, &nioc);
1282+
double_spin_unlock(&rioc->lock, &nioc->lock,
1283+
rioc < nioc);
1284+
}
12811285
}
12821286
}
12831287

0 commit comments

Comments
 (0)