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 3B3478017D for ; Wed, 4 Nov 2026 18:45:40 +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 6A4IiOsB026022; Wed, 4 Nov 2026 21:44:25 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A4IiOsB026022 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=default; t=1793817867; bh=ysn1Cqp8J89M+syLJ9L5mBzugXtVQ+KO1INJe+3NuVg=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe; b=r7DfSgGONV8Lql99VDp8k/Of4QMzQ9WEyEpkZQGd70VQoX8FOx5t+06VCcCgH1SKY dfx/84jpt/Srldk29tErDA4vvoO2x8HppFPjKwBJswXfVZBY2uV38R+vvZhdnAVWoV BlCrB0SXyp1rzJ3a8nY1Xghym1n0kn4jHQW+tm1EgjF224YUKkIV1y+RRF4kzty8gp 3YcihHyFIfuEA3IRkEKIyZSAgn6mVidinOzgmJsy9rJE84E1g7Q50xCA5iNgb9O2Jg VV33OGpgxqzoafFUpkRKVcQRlERSeERLQmBE10GnmALw+CsaSu8ZTQ6ST8jSUqjI1H hCZNBTqMF3byw== Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6A4IiMXP026018 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 4 Nov 2026 21:44:23 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A4IiMXP026018 Authentication-Results: mail.openvz.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b="slKPzt0P" Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-6b1eeef39a0so1238411a12.0 for ; Wed, 04 Nov 2026 10:44:23 -0800 (PST) X-Forwarded-Encrypted: i=2; AKwUvBzg8JFNYX4Ata7sEG3AJ0n63uwE7FYXp+jB6mQWesTDIYbiWSnPsBPtDZKIxqg0libxxJCHaw==@openvz.org X-Gm-Message-State: APuU4Z92ZC0+HQRiBvjDHbpmf/D0p/+ykmrAQArO5AJ9iHzanSDFQr9B Y5p13lmIhWOxmmbbEk6U0VwQLuAfIdFg6uRgFKbRaG1856eHFwsJjMURXESy6n92S/l5X84+ITG Xv6VFfb1FGouBrl7LdNN6+5GrzVZ6GGVK1phZ8SXwLoaqWhzsJA3e/w== X-Gm-Gg: AYBFou0PcAifmZZoDf7/P8uUOe6HVBJCpFzPD3bI8xpe3V+OfnxHWVm1QqNsRUiZPUi z7x/SVePAdzuHrqrX9aaF0cwtKtS2voEGcRagqlDTDlvVTttJRGaIs1q/4APoN5cGhEeZO2Dz1n 4YnMk8t8Uad8CNwi00s1h0LUIsllwJMqUobXj05RkRS4DacsQ+kUJwyHjCt8qIwrych+eDMepyJ ZXdLw0287JqQuUCUNwNEOW9eISwwoZ45DyBJpWI/QPbdXrpErMdsESrBo/sjsIAp3VCGanFosZD NgLI3j/w/Q== X-Received: by 2002:a5d:5f89:0:b0:48a:f0cd:8712 with SMTP id ffacd0b85a97d-48e6e5004c1mr35712661f8f.50.1793815270695; Wed, 04 Nov 2026 10:01:10 -0800 (PST) X-Received: by 2002:a5d:5f89:0:b0:48a:f0cd:8712 with SMTP id ffacd0b85a97d-48e6e5004c1mr35712587f8f.50.1793815270146; Wed, 04 Nov 2026 10:01:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1793815270; cv=none; d=google.com; s=arc-20260327; b=rHNHr7QlL0/Q4SILQpGczsxerTyCWxReAJfkXpVmcJkqNmeJ4MHS+Ebv2cO7HwJOSw lYCX67wDOroMQ4chMgzQ6ZTDdkJwpRwF/KY3Wcp6jBBDz0KcgZ5fy8qNHSS+nMOvK/rg j5Qk0WM5j5U/se3ksCvQkR8AHJuk2YosjUTZD792IB1lLEmruMIFlz/P+c37KifnUDYm ZeGvMmDENAjOSfoJFDLMoaeoorEELPes2XiSt6TMAOLHdCQZFwblvJvsOYpa3nT+Mr6h apNewLfutICpFIdIwiF8QnTgJzFtyk4AS780ccY5ae6UbA+uaVQ5o8LGa2+IQYbnL++6 iEqw== 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=HaGN4WKV57Khz2BT3vGMjTKBhidFE03ufW4VFrHWIlc=; fh=eTcevGYfDXe/BwrfXNlm5U4k/My0Bm6HKUrSuhfuUIk=; b=TTOHG/RqHml4TaHq3u/j4kog31yOMssKLzf1CPX42ySQ2Ey36KL2guofrueWcjn812 IrQoK+tjfa17u/icFbKbe7RXfiTuDBb6db9LZuw6PN6C4chDAB0Vc0nr2CVqlugUEcKd yBZcNFP2OLVs3btR5LtX/qB5a6AD4PWjyTsPngVvBBJf+B+NT3xRW0NflZYYa9g/fyd+ Cq4s3Kc7mdzwEkv1rBk+0h+GQsSfnTSRTgenZlDhD12B5ktDutY5PALqFWjlfzQC1RjU BhqYJlbHFxm1msZWrepg0bXHF+aEUyLmteVFK+boKGnN4O7ptHj/gaPhm7gyDjLVlwb8 6I6g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=slKPzt0P; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:162e:5a6e:fd46:18b7 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-48febe468e7sor527239f8f.3.2026.11.04.10.01.10 for (Google Transport Security); Wed, 04 Nov 2026 10:01:10 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:162e:5a6e:fd46:18b7 as permitted sender) client-ip=2a06:5b06:b600:300:162e:5a6e:fd46:18b7; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=slKPzt0P; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:162e:5a6e:fd46:18b7 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=1793815270; x=1794420070; 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=HaGN4WKV57Khz2BT3vGMjTKBhidFE03ufW4VFrHWIlc=; b=slKPzt0PDaWSXy7bd7yaf66mGGxAjHwTnrXZ/kwFuApb0fdg7srH2sodmPId86Niby E/+hohnvGIcTkCCRYvAAHRsoQQfOKnRqs5Vty5HwW5LnPTWoILksqJPjFW5TB+PIC7oR 1DfnEQYTItRBZg5NUAgog/QZ3xNyhPqr+9N/58cAazDAXTjJcgXfQ/91pVzXDRA5X6/6 HO7KIgzlaXzu1wzoSph+GXbukxZMqxTBLXJodwAq20NNbxd2VJIga6gSbEq8aeHib4NC lZFnFkI6+ZmKgdZaMHnd3AX4+0+jmqyFHFW5fV+RS27trgY+nY92Pq5FtEewv2vTpZhj 79xg== X-Forwarded-Encrypted: i=1; AKwUvByvG3/ZKpLayVqsiH0Xf6JGrJIqFhYlY9g65PAll9E39XnmtC8BUtnnYjpa++ArFajh0yFsoQ==@openvz.org X-Received: by 2002:a5d:5f89:0:b0:48a:f0cd:8712 with SMTP id ffacd0b85a97d-48e6e5004c1mr35712515f8f.50.1793815269516; Wed, 04 Nov 2026 10:01:09 -0800 (PST) Received: from athena.sw.ru ([2a06:5b06:b600:300:162e:5a6e:fd46:18b7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48feda20521sm5050716f8f.53.2026.11.04.10.01.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2026 10:01:09 -0800 (PST) From: "Denis V. Lunev" To: andrey.zhadchenko@virtuozzo.com Date: Wed, 4 Nov 2026 19:01:01 +0100 Message-ID: <20261104180105.1807820-2-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261104180105.1807820-1-den@openvz.org> References: <20261104180105.1807820-1-den@openvz.org> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v3 1/5] 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 when the relocation fails before the header write. Once the header write has succeeded, the error paths skip the freeing and only return -EIO: the header on disk already points at the new table, and its pages may be dirty and queued for writeback by then. 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 | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c index 1c269a78ad35..ac4dbe0623ea 100644 --- a/drivers/md/dm-qcow2-map.c +++ b/drivers/md/dm-qcow2-map.c @@ -2277,6 +2277,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; @@ -2340,8 +2341,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); @@ -2377,21 +2379,21 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio) if (!WARN_ON_ONCE(!md)) qcow2_md_make_dirty(qcow2, md, true); if (!md) - break; /* goto err_free_r2_pages */ + break; /* goto err_eio */ } spin_unlock_irq(&qcow2->md_pages_lock); if (i != nr_pages) - goto err_free_r2_pages; + goto err_eio; /* Connect new R2 to new R1 */ for (i = end; i < r2_end; i += clu_size) { if (calc_refcounters_map(qcow2, i, &r1, &r2) < 0) { WARN_ON_ONCE(1); - goto err_free_r2_pages; + goto err_eio; } ret = handle_md_page(qcow2, r1.page_id, NULL, &md); if (WARN_ON_ONCE(ret <= 0)) - goto err_free_r2_pages; + goto err_eio; spin_lock_irq(&qcow2->md_pages_lock); set_u64_to_be_page(md->page, r1.index_in_page, i); qcow2_md_make_dirty(qcow2, md, true); @@ -2402,7 +2404,7 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio) for (i = pos; i < r2_end; i += clu_size) { ret = qcow2_handle_r1r2_maps(qcow2, i, NULL, &r1, &r2, false); if (WARN_ON_ONCE(ret <= 0)) - goto err_free_r2_pages; + goto err_eio; mark_cluster_used(qcow2, r2.md, r2.index_in_page); } @@ -2410,14 +2412,14 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio) for (i = old_pos; i < old_end; i += clu_size) { ret = qcow2_handle_r1r2_maps(qcow2, i, NULL, &r1, &r2, false); if (WARN_ON_ONCE(ret <= 0)) - goto err_free_r2_pages; + goto err_eio; mark_cluster_unused(qcow2, r2.md, r2.index_in_page, i); } 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; @@ -2426,6 +2428,7 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio) spin_unlock_irq(&qcow2->md_pages_lock); qcow2_free_md_page(md); } +err_eio: /* TODO: switch to RO */ return -EIO; } -- 2.53.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel