From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 953DB8017D for ; Tue, 3 Nov 2026 09:09:39 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6A398ONC003095; Tue, 3 Nov 2026 12:08:25 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A398ONC003095 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=default; t=1793696908; bh=GovbD7Tf/OZjhI6sPHRwG9LmUw710Sm0ljIOI0OfsQ4=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe; b=wTAQPvOsbp9s62BZbwqJlZ+CHenfrFuU4y/qpRpMZd0QUZrc4jTtwe10pJRdEqVX1 RQLFSwxWj9t3fo3+wTevdpfVMC23YSLp53pJiQSYrXMrwL4h5wjmWNNLjvG5ToVuT2 w3EbwREyGvdfPuq3Hcv9oaWUevuta8tGykKJbvUJ5Cu0g1Gcw0p1p9jeJkEQnAkLBU 8BglDSFIgxmbw4DI+dnoMu2DXEL0uZwxTupAMdCt+7DXNdmunofSnqXwdJcqV784o9 Y82/R+Tk2JiGZ/avJqm+EDAJ0wdHO55F+EiF/CufvLK2ChT1zNEFriiDNoT3G4FirQ 0T5Zp0i3R4Wsg== Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6A398IJt003076 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 3 Nov 2026 12:08:18 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A398IJt003076 Authentication-Results: mail.openvz.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b="nFdC2Q/i" Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-48e0461e040so3277642f8f.0 for ; Tue, 03 Nov 2026 01:08:18 -0800 (PST) X-Forwarded-Encrypted: i=2; AKwUvBzO6x6xX5Si6wLzPSZl89sKjV7HK98fsCLv105UhqnhpXEVlRjryMu70isobcBP9qpkAohZWg==@openvz.org X-Gm-Message-State: APuU4Z8WsUd63LorVTGfJQn4gG9TlJ2j1iEzsQq89ZVAo1MMs28EYl+3 bQzELTtnZAoasscO9hUgpGAv85xZOm625uRJ5+JfO2zlRh/0AWRNNomzimFCPMiJ7myX8nwWpQn ZjbYHmB+e/jqYnHW8RbQiXw4qTbOjgeH/L5yAQfz2URr3EH2o0zpXkA== X-Gm-Gg: AYBFou1iBumcBmoGsHxLLo/+nYQ3ThERfFMddyW/JLDXEwXBnBugQpnEOIjikJ0fsZE uewFo6cZkY/jzNv8GnH3CFbMer4eWU61lc+xxkKwpDEXYeEdWf9vLyiDN0rnddxR/0wU5OPgx19 j5Vv256NwPZ+WKkWH99b3raJ/YYV5rPUdQfBLKX2EQ7xwDk0qko6TIEYW94ZADYsvvLLsjgQmPZ 7IqwB2141CWgIgq32qyoQYh9wE56DC04ezVPEPtpHVaZJid11mwQQ90MNQH+q1B+mWjfccqv+1y cFMfpQpErA== X-Received: by 2002:a05:6000:22c7:b0:485:8cc8:1f5f with SMTP id ffacd0b85a97d-48e6e5087edmr28901851f8f.42.1793696898166; Tue, 03 Nov 2026 01:08:18 -0800 (PST) X-Received: by 2002:a05:6000:22c7:b0:485:8cc8:1f5f with SMTP id ffacd0b85a97d-48e6e5087edmr28901806f8f.42.1793696897689; Tue, 03 Nov 2026 01:08:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1793696897; cv=none; d=google.com; s=arc-20260327; b=MwasFmDErQVIZ1PQ0C8eQvYNMI0QhtXheUioVvJdnramiRWak67+GicmOy7AbcKz36 VjtRmtQGuaqEmVoOs/edvUVFm0wrZDDF2Dn//81KigsSbW72xGTwduEBE73K8UGUwEMq KMuqqFbUrsBCs+MfNYQXjLknb90yFKE8hIgHnmDcHa0LUrRbIVcoPwtQJ5nKCGEnJ3hj SI+1iAI6LnzkYKlHw8WtQiaIEbBNBzeHUga3lXYzNSSZL3PA1vTEeZRfaY07VshwSJZ+ siFnToRzsp5UHph9nbi80Y0VLX9kCDSZKdWwpGzCj/XdRqKciJB5w5KTxVZ+bi+RZoiI PwkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=tDvI89Q+k1ClZ3h6aR0fHecxJghgxu2ZHGLw36QiqfY=; fh=81heBpmNcZ+RuMrLLzs0J3J9LqvpUyTAYbMeOXnj1Dk=; b=ZqjEanTCn2qTt5BUXZauUepkJJeoWFO/eFNEjcdBoHv04jgdd8+f+2k78Yk8eTtwLK EXsMdrCWPP/lLitD10Jtgt8aP8uwOt3/2bWBDCSNCCW8Kn5TBpMQBOOd0Ia8KOWhBzzy ENhTklqutEb0IfBp2kOCHzO9jF8RvEHnEa8WOiCP63pp3iUitTWGNWsMh5SwxKPv3Qei gzZLh701PqJx1SRNo1ts6dAV2h0/TUqLunrpeywtRf5axTJ+DolQwdsVxKvlbnsyzSTV bupte8R7HRn1tAyygbHjtlVHCdGR/tt2c2iMKZ6Ad0liBv/jnalA+sWmbVAfCdD7JzL2 BWfw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b="nFdC2Q/i"; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:c789:8bc5:fa8e:d502 as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id ffacd0b85a97d-48e6ebc3d8dsor2179289f8f.11.2026.11.03.01.08.17 for (Google Transport Security); Tue, 03 Nov 2026 01:08:17 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:c789:8bc5:fa8e:d502 as permitted sender) client-ip=2a06:5b06:b600:300:c789:8bc5:fa8e:d502; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b="nFdC2Q/i"; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:c789:8bc5:fa8e:d502 as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1793696897; x=1794301697; darn=openvz.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=tDvI89Q+k1ClZ3h6aR0fHecxJghgxu2ZHGLw36QiqfY=; b=nFdC2Q/iZfWFQiivE2Nxf8pXO1SB8IgWCKkV7LowGCjoggl3uqbbHHoCG8i17KYCSo q96Q+GMIBecaIgM12Dp9fmbcJkS16odpdLYxqCfvwekgD+Ze63C1c7aWa0TJTBNtA4ia Qgi+jtDQeo7EDJWPmUXnGl9OCRf4AsDhCGor1ALiqwgZEynM+a/Y0muR7Kn+ZYuBXp6n YRND1zaU1EzAqJPejsfCGv6rRa4k7BJ0xerTshz4BeIXRfv8pfb4HBPnjMO6PWWgI7v3 hn3Sshovmk747qXSpGgR12WELL9gAFKOGiGVGhy0sCYO4IZ4HQBnyoAkbuKXWyyVhEhT 48HQ== X-Forwarded-Encrypted: i=1; AKwUvBzZVsyya8qw+HuxbZNC5GQq1RJKavvfcesuEMj00rxlFIu7w0NPf2w5m5eNDtbV00P9a5L+gw==@openvz.org X-Received: by 2002:a05:600c:5306:b0:4a2:14af:1ead with SMTP id 5b1f17b1804b1-4ac183d2093mr289188345e9.25.1793696897153; Tue, 03 Nov 2026 01:08:17 -0800 (PST) Received: from athena.sw.ru ([2a06:5b06:b600:300:c789:8bc5:fa8e:d502]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4b2a96fc933sm45453365e9.11.2026.11.03.01.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2026 01:08:16 -0800 (PST) From: "Denis V. Lunev" To: andrey.zhadchenko@virtuozzo.com Date: Tue, 3 Nov 2026 10:08:11 +0100 Message-ID: <20261103090813.166986-2-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261103090813.166986-1-den@openvz.org> References: <20261103090813.166986-1-den@openvz.org> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v2 1/3] dm-qcow2: fix a failed refcount table relocation leaking md pages X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Denis V. Lunev relocate_refcount_table() inserts md pages for the last cluster of the new reftable and for the new refblocks, one page at a time from pos + old_clus * clu_size up to r2_end. On error it frees pages from end only, one per cluster, so the pages of the new reftable cluster and all but the first page of each refblock cluster bigger than a page stay in md_pages. The header is rolled back, so the next allocation past the old refcount coverage relocates the table again. Its first insert finds a leaked page and fails with -EEXIST, the relocation returns -EIO, and every allocating write beyond the old coverage fails with an I/O error until the device is suspended and resumed or the table is reloaded. A failed page allocation or a failed header write is enough to get there. Free exactly the pages the allocation loop inserted. Note for a future reader: the pages are freed without being unlinked from the writeback lists. That is safe for the failures above, which happen before any page in the range is dirtied. Pages get dirty only after the header write, and the gotos after it are WARN_ON_ONCE() branches that leave the on-disk header pointing at the new table. Those want the image switched to read-only, as the TODO there says, not more cleanup. Fixes: 222b6f1291c1 ("dm-qcow2: Introduce driver to create block devices over QCOW2 files") https://virtuozzo.atlassian.net/browse/VSTOR-153051 Feature: dm-qcow2: block device over QCOW2 files driver Signed-off-by: Denis V. Lunev --- drivers/md/dm-qcow2-map.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c index 78ee7cf5e881..8ab7cb472560 100644 --- a/drivers/md/dm-qcow2-map.c +++ b/drivers/md/dm-qcow2-map.c @@ -2279,6 +2279,7 @@ static void set_reftable_in_raw_hdr(struct page *page0, loff_t pos, loff_t clus) static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio) { loff_t i, old_pos, old_end, pos, end, r2_end, delta; + loff_t new_md_start, new_md_end; u32 old_clus, clus, clu_size = qcow2->clu_size; u32 r2_clus, bits = qcow2->refblock_bits; unsigned long nr_pages, index; @@ -2342,8 +2343,9 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio) return ret; /* Alloc R1/R2 pages covering clusters of new R1 and new R2 */ - for (i = pos + (u64)old_clus * clu_size; i < r2_end; i += PAGE_SIZE) { - ret = qcow2_alloc_and_insert_md_page(qcow2, i >> PAGE_SHIFT, &md); + new_md_start = pos + (u64)old_clus * clu_size; + for (new_md_end = new_md_start; new_md_end < r2_end; new_md_end += PAGE_SIZE) { + ret = qcow2_alloc_and_insert_md_page(qcow2, new_md_end >> PAGE_SHIFT, &md); if (ret < 0) goto err_free_r2_pages; spin_lock_irq(&qcow2->md_pages_lock); @@ -2419,7 +2421,7 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio) return 1; 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; -- 2.53.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel