DIO submission on underlying file may fail because of unaligned buffer or start_sector & sector_length, fallback to buffered IO when that happens, this way will make loop dio mode more reliable. Signed-off-by: Ming Lei <ming.lei@xxxxxxxxxx> --- drivers/block/loop.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index d1784f825b6b..fee78a640f75 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -590,6 +590,7 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, cmd->iocb.ki_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 0); if (!cmd->use_dio) { atomic_set(&cmd->ref, 1); +buffered_io: cmd->iocb.ki_flags = 0; cmd->ret = lo_call_backing_rw_iter(file, &cmd->iocb, &iter, rw); lo_rw_aio_do_completion(cmd); @@ -603,8 +604,13 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, lo_rw_aio_do_completion(cmd); - if (ret != -EIOCBQUEUED) + if (ret != -EIOCBQUEUED) { + if (ret < 0) { + cmd->use_dio = false; + goto buffered_io; + } cmd->iocb.ki_complete(&cmd->iocb, ret, 0); + } return 0; } -- 2.31.1