All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Konstantin Khorenko <khorenko@virtuozzo.com>
To: "Denis V. Lunev" <den@openvz.org>
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH hci-8.1 v2 1/3] dm-qcow2: fix a failed refcount table relocation leaking md pages
Date: Wed, 04 Nov 2026 17:59:49 +0100	[thread overview]
Message-ID: <179381158915.2686233.14965545339589766845.b4-review@b4> (raw)
In-Reply-To: <20261103090813.166986-2-den@openvz.org>

I won't apply this version, please send v2 with the changes below.

On 11/3/26 10:08, Denis V. Lunev wrote:
>  err_free_r2_pages:
> -	for (i = end; i < r2_end; i += clu_size) {
> +	for (i = new_md_start; i < new_md_end; i += PAGE_SIZE) {
>  		ret = handle_md_page(qcow2, i >> PAGE_SHIFT, NULL, &md);
>  		if (ret <= 0)
>  			break;

Item 1 of the cover letter reply: after a successful header write, do
not free the new md pages in this loop. Send the gotos that follow the
header write to a label after the loop that only returns -EIO, and
update the "Note for a future reader" to match.

This version should not go in as is: it trades one rare failure for a
worse one.

  +------------------------+----------------------+--------------------+
  |                        | without this patch   | with this patch    |
  +------------------------+----------------------+--------------------+
  | a page allocation or   | every write past the | fixed              |
  | the header write fails | old refcount         |                    |
  | during the relocation  | coverage gets EIO    |                    |
  |                        | until suspend/resume |                    |
  +------------------------+----------------------+--------------------+
  | an image with 4K       | WARN + EIO           | use-after-free: a  |
  | clusters and           |                      | page still on the  |
  | refcount_bits=64 grows |                      | writeback list is  |
  | to about 511G          |                      | freed, memory gets |
  | (refcount_bits=32: 2T) |                      | corrupted          |
  +------------------------+----------------------+--------------------+

EIO is visible and suspend/resume cures it. Memory corruption can crash
the node or silently damage someone else's data. Both cases are rare,
but the second one is normal work with a valid image, no failure needed.

How the second row happens: one of the gotos after the header write is
reachable on a valid image, and by then this loop frees a dirty page.
With 4K clusters and refcount_bits=64 the relocation at about 511G makes
the new reftable fill a whole refcount group, so that group gets no
refblock and the mark-used loop fails at i = pos (refcount_bits=32 gets
there at about 2T).

The connect loop has already dirtied the page at new_md_start and queued
it for writeback. Before this patch that page leaked and the device got
EIO. With the patch it is freed while still on the writeback list, and
the slow writeback timer then works on freed memory.

Item 6 of the cover letter reply, a separate patch: the missing refblock
for the group of pos is a bug of its own, there since the driver was
added. The connect loop gives a refblock only to the groups the new
refblocks sit in.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

  parent reply	other threads:[~2026-11-04 17:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03  9:08 [Devel] [PATCH hci-8.1 v2 0/3] dm-qcow2: fix merges not stopping the users of the images they change Denis V. Lunev
2026-11-03  9:08 ` [Devel] [PATCH hci-8.1 v2 1/3] dm-qcow2: fix a failed refcount table relocation leaking md pages Denis V. Lunev
2026-11-03  9:13   ` no-reply
2026-11-03  9:27     ` Denis V. Lunev
2026-11-04 16:59   ` Konstantin Khorenko [this message]
2026-11-03  9:08 ` [Devel] [PATCH hci-8.1 v2 2/3] dm-qcow2: fix backward merge of an inner image racing its reads Denis V. Lunev
2026-11-03  9:13   ` no-reply
2026-11-04 16:59   ` Konstantin Khorenko
2026-11-03  9:08 ` [Devel] [PATCH hci-8.1 v2 3/3] dm-qcow2: fix SEEK_HOLE/SEEK_DATA using an image freed by a merge Denis V. Lunev
2026-11-03  9:15   ` no-reply
2026-11-04 16:59   ` Konstantin Khorenko
2026-11-04 13:15 ` [Devel] [PATCH hci-8.1 v2 0/3] dm-qcow2: fix merges not stopping the users of the images they change Andrey Zhadchenko
2026-11-04 16:59 ` 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=179381158915.2686233.14965545339589766845.b4-review@b4 \
    --to=khorenko@virtuozzo.com \
    --cc=den@openvz.org \
    --cc=devel@openvz.org \
    /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 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.