Skip to content

Commit 6961cd4

Browse files
committed
ubd: fix missing lock around request issue
We need to hold the device lock (and disable interrupts) while writing new commands, or we could be interrupted while that is happening and read invalid requests in the completion path. Fixes: 4e6da0f ("um: Convert ubd driver to blk-mq") Tested-by: Richard Weinberger <richard@nod.at> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent df376b2 commit 6961cd4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

arch/um/drivers/ubd_kern.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,11 +1341,14 @@ static int ubd_queue_one_vec(struct blk_mq_hw_ctx *hctx, struct request *req,
13411341
static blk_status_t ubd_queue_rq(struct blk_mq_hw_ctx *hctx,
13421342
const struct blk_mq_queue_data *bd)
13431343
{
1344+
struct ubd *ubd_dev = hctx->queue->queuedata;
13441345
struct request *req = bd->rq;
13451346
int ret = 0;
13461347

13471348
blk_mq_start_request(req);
13481349

1350+
spin_lock_irq(&ubd_dev->lock);
1351+
13491352
if (req_op(req) == REQ_OP_FLUSH) {
13501353
ret = ubd_queue_one_vec(hctx, req, 0, NULL);
13511354
} else {
@@ -1361,9 +1364,11 @@ static blk_status_t ubd_queue_rq(struct blk_mq_hw_ctx *hctx,
13611364
}
13621365
}
13631366
out:
1364-
if (ret < 0) {
1367+
spin_unlock_irq(&ubd_dev->lock);
1368+
1369+
if (ret < 0)
13651370
blk_mq_requeue_request(req, true);
1366-
}
1371+
13671372
return BLK_STS_OK;
13681373
}
13691374

0 commit comments

Comments
 (0)