All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.2] dm-qcow2: fix a short image read resubmitted at the wrong sector
@ 2026-11-19 14:29 Denis V. Lunev
  2026-11-19 16:11 ` Alexander Ivanov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Denis V. Lunev @ 2026-11-19 14:29 UTC (permalink / raw)
  To: alexander.ivanov, vasileios.almpanis; +Cc: devel

From: Denis V. Lunev <den@openvz.org>

data_rw_complete() resubmits the rest of a short image transfer through
qio_advance(), which moves the buffer by ret bytes but bi_sector only by
ret >> 9. When ret is not a multiple of 512, the resubmit rereads from
below where the transfer stopped into the buffer past it.

A read-only image whose file ends inside a sector and a page or more
short of the read gets such a read. On ext4 or xfs the O_DIRECT
resubmit fails with -EINVAL. On a file system that takes unaligned
O_DIRECT reads, such as NFS or FUSE, the same tail bytes are read again
and again into the buffer, and the read completes with wrong data and
no error.

A short read that ends at EOF of a read-only image cannot make
progress, as the file does not grow: zero-fill it when less than a page
is missing, as before, and fail it with -EIO otherwise. Fail any other
short transfer that is not a multiple of 512 bytes, including a write,
which would rewrite good bytes at the rounded-down offset, instead of
resubmitting it.

https://virtuozzo.atlassian.net/browse/VSTOR-156059

Fixes: 222b6f1291c1 ("dm-qcow2: Introduce driver to create block devices over QCOW2 files")
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Denis V. Lunev <den@openvz.org>
---

Applies on top of the series "dm-qcow2: fix a read livelock at EOF of a
read-only image" v2.

 drivers/md/dm-qcow2-map.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index cf66b9a98085..c0aaff8815ad 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -3013,11 +3013,14 @@ static void data_rw_complete(struct qio *qio)
 
 	if (unlikely(qio->ret != qio->bi_iter.bi_size)) {
 		if (!write && qio->ret > 0 && !qcow2_file_is_writable(qcow2) &&
-		    to_bytes(qio->bi_iter.bi_sector) + qio->ret == qcow2->file_size &&
-		    qio->bi_iter.bi_size - qio->ret < PAGE_SIZE) {
+		    to_bytes(qio->bi_iter.bi_sector) + qio->ret == qcow2->file_size) {
 			/* Read near EOF, same as md_page_read_complete() */
-			zero_fill_qio(qio, qio->ret, qio->bi_iter.bi_size - qio->ret);
-		} else if (!write && qio->ret == 0) {
+			if (qio->bi_iter.bi_size - qio->ret < PAGE_SIZE)
+				zero_fill_qio(qio, qio->ret, qio->bi_iter.bi_size - qio->ret);
+			else
+				bi_status = BLK_STS_IOERR;
+		} else if ((!write && qio->ret == 0) ||
+			   (qio->ret > 0 && (qio->ret & (SECTOR_SIZE - 1)))) {
 			bi_status = BLK_STS_IOERR;
 		} else if (qio->ret >= 0) {
 			WARN_ON_ONCE(qio->ret == 0);
-- 
2.55.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-19 16:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 14:29 [Devel] [PATCH hci-8.2] dm-qcow2: fix a short image read resubmitted at the wrong sector Denis V. Lunev
2026-11-19 16:11 ` Alexander Ivanov
2026-11-19 16:39 ` Konstantin Khorenko
2026-11-19 16:39 ` Konstantin Khorenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.