OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: alexander.ivanov@virtuozzo.com, vasileios.almpanis@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.2] dm-qcow2: fix a short image read resubmitted at the wrong sector
Date: Thu, 19 Nov 2026 15:29:56 +0100	[thread overview]
Message-ID: <20261119142956.998039-1-den@openvz.org> (raw)

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

             reply	other threads:[~2026-11-19 14:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 14:29 Denis V. Lunev [this message]
2026-11-19 16:11 ` Alexander Ivanov
2026-11-19 16:39 ` Konstantin Khorenko
2026-11-19 16:39 ` Konstantin Khorenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119142956.998039-1-den@openvz.org \
    --to=den@openvz.org \
    --cc=alexander.ivanov@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=vasileios.almpanis@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox