* [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
* Re: [Devel] [PATCH hci-8.2] dm-qcow2: fix a short image read resubmitted at the wrong sector
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
2 siblings, 0 replies; 4+ messages in thread
From: Alexander Ivanov @ 2026-11-19 16:11 UTC (permalink / raw)
To: Denis V. Lunev, vasileios.almpanis; +Cc: devel
LGTM
Reviewed-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Devel] [PATCH hci-8.2] dm-qcow2: fix a short image read resubmitted at the wrong sector
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
2 siblings, 0 replies; 4+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 16:39 UTC (permalink / raw)
To: Denis V. Lunev; +Cc: devel
Applying, after the read livelock v2 series, with these fixes on my
side:
- "A read-only image whose file ends inside a sector" -> "A truncated
or otherwise damaged read-only image whose file ends inside a sector".
- "which would rewrite good bytes at the rounded-down offset" -> "whose
resubmit would put the rest of the data below where it belongs".
On Thu, 19 Nov 2026 15:29:56 +0100, Denis V. Lunev wrote:
> 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
A well-formed image never gets there: a compressed cluster at EOF is
read up to the next page, so less than a page is missing and it is
zero-filled; a plain cluster ends on a sector. Only an L2 entry that
points past the end of a truncated file does it.
> which would rewrite good bytes at the rounded-down offset, instead of
> resubmitting it.
The resubmitted write puts buf[ret..] at pos + round_down(ret, 512):
every remaining byte lands (ret & 511) bytes too low, and the last
(ret & 511) bytes of the range are never written.
Separate patches, not needed for this one. I created a task:
1. A write that returns 0 bytes still hits WARN_ON_ONCE() and is
resubmitted unchanged, forever if a FUSE daemon keeps answering 0;
it should fail with -EIO as a read does.
https://virtuozzo.atlassian.net/browse/VSTOR-156109
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Devel] [PATCH hci-8.2] dm-qcow2: fix a short image read resubmitted at the wrong sector
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
2 siblings, 0 replies; 4+ messages in thread
From: Konstantin Khorenko @ 2026-11-19 16:39 UTC (permalink / raw)
To: alexander.ivanov, vasileios.almpanis, Denis V. Lunev; +Cc: devel
On Thu, 19 Nov 2026 15:29:56 +0100, Denis V. Lunev wrote:
> dm-qcow2: fix a short image read resubmitted at the wrong sector
Applied to branch-rh10-6.12.0-211.75.1.26.x.vz10-ovz, will be released in rh10-6.12.0-211.75.1.26.4.vz10, thanks!
[1/1] dm-qcow2: fix a short image read resubmitted at the wrong sector
https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/635d72b3303e
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
_______________________________________________
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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox