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 8BD628002A for ; Mon, 23 Nov 2026 19:14:38 +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 6ANJDLex008990; Mon, 23 Nov 2026 22:13:22 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6ANJDLex008990 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=default; t=1795461204; bh=hJyGAXByJ0kA7QPLC0uUyld/dwS2S+TkKCpvMbyqS4Q=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe; b=L1HPe1qnNnEwIXYerbf0vHrMife/SR5JXtuOT2y1e4+mKWii8wTWHR9lk46dTSuZM 9qJoNvuK2Zgv2pZIXb5vbfv1voDc6lTpFbqcpGVSks+Mq9zeNmMQOXBjm76SdsZbp7 ZIRUzaxpOSOoO62yBlFWBHfm4ql9VuSY5UwPkUms3Ln0aGyqftKMGzkFhqsvD8kjFU TWo0cD8l0x4vrYzBQCEz34BGP6Y3RHtiMrP7NZ8Dh5w9yuIHb6VkdTaDyRS9+5n3Vd cr+yiNEw/kfqMrZisq0lg5pKu2JJXSczPbosNUK18hWDlgE3rBZYNbaSmfYjr8QdHo nLbE6EDrL7vEg== Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6ANJDKCx008983 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 23 Nov 2026 22:13:20 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6ANJDKCx008983 Authentication-Results: mail.openvz.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b="KfQJs8W1" Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4ad3d35e899so30259735e9.1 for ; Mon, 23 Nov 2026 11:13:20 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErECkgdmZ/n/C5ASzkHIZLIHF4EDiIxhHeg7jgX6H9XvKjy1mPwpT5TXAo8jcWD4AyffnXlemQ==@openvz.org X-Gm-Message-State: APuU4Z87CMMLOJIC19V+OfCArTHkpPzasur/1biIEMcKHVQy+UpzWUK5 l/yH5DIfs6jEBLhcaL/7tURw2EetlK82Cqzwig/8NPyE9Ee+nE0SOqnJBRu9zrvOLJdHOmbQl0m YY1Smrv8tfxO4/XwUP5ir3blEqPIc9qecZO8uevVkr646UBq9tWF60Q== X-Gm-Gg: AZFdTZdghYOxzB1LZNWWZt+0q3IxR83hd96m2wGIT9vqo7ETZ0+Q9Siv2UUfKzcYYoM ckTjBviNXY4+bWwIXevL3r0q/qDMFPN4j9f5rDwKT/VvcTTJykYy/ONPq1YElu7Li8aXFjxpCDq uNBmM9hfncHlx6PE3378fayusmHQhOoabLtFSfdC+YQ/x7CTZC3zWWgsk0a/L4MbC7WNKucrGH1 Ec9Cyy8815zvJ892FgM9ae89J3fUEFEVMNWFCeWqoN/SWh9Rg7+rd7mzduGWQH1nyCOvs28MpBS j/8LcP52/w== X-Received: by 2002:a05:600c:3b8a:b0:4ba:761:c0c5 with SMTP id 5b1f17b1804b1-4bb8880f0e0mr261584095e9.5.1795461200416; Mon, 23 Nov 2026 11:13:20 -0800 (PST) X-Received: by 2002:a05:600c:3b8a:b0:4ba:761:c0c5 with SMTP id 5b1f17b1804b1-4bb8880f0e0mr261583715e9.5.1795461199993; Mon, 23 Nov 2026 11:13:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795461199; cv=none; d=google.com; s=arc-20260327; b=UNCosKJC6RM3Jzv0iDcCqag0RkMoyRVBAo6y1dFqo1evK63cFgF8+CQRPn1P93tRM1 aQLCWEs+KHp/ClBaD9JxJiVeW9kRSLMjo9RZfP4g5TkaJ64GPCxg1dEZBehCDWoeM0ry fSCymSFP/+feTaTOqDJ648TJHsbiBWFOCY9wxL9EUPnEF2YEbQFw+U+VpmxJ2bPa3OUO +2gygHlWEArMZF6qXuazu9b3fP4/N+F5QQx6oP+yUUR7oB0U3DretmoQa0MK5LTrgat2 f9yZDZuZQib0Mu/jd1r4aDaiFlnWyOZU0wRvINPXJciw4y1Wfvu0ud8LeyLZdWdmVRmP fXjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=U6PhAAAbovNaQJEBxru/Du630NGow/6WThInBQ0Kiqk=; fh=odWsP1Soz9XgFXgklbFqMQOXvgY7U9WQKrSyGz2PKko=; b=e2UkjGkx5YM24lS0H+ShbMSMpuVLKwuu2safzXNWdoh7qhfBz3B1dkV9lMWt4Fi68k Rf9LxB7i7aYrZSzB1XLOnSU2S3KIHUJ0O0AkAWpgGAi/W9X4Sa2fnUshL8eVpkE+eoA2 4k/ombqFjyAl+DQC+VPN8OPLGmQA9csV9SlbAQ+K3kJKUPYL4nEVBuQOw5OPD4NR3hkM JmkGB2GlFBJpQyTBTTKXHjUAfgtPyU3aJo5CLRiASAeu+zHEke+OUDNzF+P07VbYxK/p ANh6DLNn/Bdz9J13RysBDDLMb0UYnmJncgalMeztNexXw5BdV+9uO3rfdLQch/FxbmRJ 1mZQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=KfQJs8W1; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:62d2:2eda:8655:4219 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 5b1f17b1804b1-4bb88463b61sor26776325e9.3.2026.11.23.11.13.19 for (Google Transport Security); Mon, 23 Nov 2026 11:13:19 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:62d2:2eda:8655:4219 as permitted sender) client-ip=2a06:5b06:b600:300:62d2:2eda:8655:4219; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=KfQJs8W1; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:62d2:2eda:8655:4219 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=1795461199; x=1796065999; darn=openvz.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=U6PhAAAbovNaQJEBxru/Du630NGow/6WThInBQ0Kiqk=; b=KfQJs8W1e2pHqie34rIGqCn2PXK2UWu2Q1GtT+NMt0DNvEsor9Tzn2hekSgsY/t06k AqdmEl8UeGP+UpwDUjxkNtJ9ANERc/BTss350uDbyqVdP78tK6Dv2AqkVTEYYp9yUoxh 6bDpVlItGqyjWLP1uAEgJMcj5oRHeJ9ElRyyoStCQBD/Y5CWTvx1XPo/k10QX1Rqie3L oyaVb/Wrux9BYCPVb+5Xdy3XLzv28Ju7nHfJIQXJcbd6vqv+qk6Nd58GY7CHhui//2+O TScg+4i2xU6C/B9zWiJHHJqklFVg6wHq0ldha+4CiEB95d/nP6bq1jKFfOCtZNDr9LYA ZYMA== X-Forwarded-Encrypted: i=1; AL+hErGr/FdPiq3zFXELrJITENu+nFAqwXqchbWRDpJOfE+Sc4CEL866j4uj0jSx6VeXdhb9WK6nKg==@openvz.org X-Received: by 2002:a05:600c:530f:b0:4a2:677:ad8e with SMTP id 5b1f17b1804b1-4bb8892a21amr238286065e9.34.1795461199477; Mon, 23 Nov 2026 11:13:19 -0800 (PST) Received: from artemis.sw.ru ([2a06:5b06:b600:300:62d2:2eda:8655:4219]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb853c9170sm435681405e9.14.2026.11.23.11.13.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2026 11:13:19 -0800 (PST) From: "Denis V. Lunev" To: andrey.zhadchenko@virtuozzo.com, alexander.ivanov@virtuozzo.com, vasileios.almpanis@virtuozzo.com Date: Mon, 23 Nov 2026 20:13:17 +0100 Message-ID: <20261123191317.199611-1-den@openvz.org> X-Mailer: git-send-email 2.55.0 MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2] dm-qcow2: fix stale host data showing in a zero cluster after a write 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 An L2 entry with the zero flag may keep its host cluster, and a zero subcluster of an extended L2 entry keeps its part of the host cluster. Their host blocks may hold stale data: qemu leaves it there after a zero write without unmap. A write that covers such a unit only in part drops the zero flag or bit but writes only its own range, so the rest of the unit reads back the stale data instead of zeroes. prepare_l1l2_allocation() reuses the host cluster as it is, and the backing file COW of a write whose other border is in an unallocated subcluster copies only that subcluster. Send such a write through the sliced COW, as a write with a border in an unallocated unit over a backing image already goes. The slices of a zero unit come from the map as zeroes, with no read from disk, and are written into the host cluster in place together with the data, so the cluster stays where it is. map->backing_file_cow becomes sliced_cow, and qio_ext gets cow_in_place for the non-extended case, where the L2 entry is still rewritten. The first partial write into such a unit now writes the whole unit; writes into other units take the path they did. https://virtuozzo.atlassian.net/browse/VSTOR-156774 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 --- drivers/md/dm-qcow2-map.c | 69 +++++++++++++++++++++++++++++++-------- drivers/md/dm-qcow2.h | 1 + 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c index 853e7a1230ee..f603ac9158e2 100644 --- a/drivers/md/dm-qcow2-map.c +++ b/drivers/md/dm-qcow2-map.c @@ -56,7 +56,7 @@ struct qcow2_map { * read" or "sublu is not allocated" may be set). */ bool data_clu_alloced:1; - bool backing_file_cow:1; + bool sliced_cow:1; u32 compressed_sectors; u32 subclus_mask; @@ -1784,6 +1784,43 @@ static bool qio_border_is_inside_unmapped_unit(struct qcow2 *qcow2, return ret; } +/* Zero subclusters with a border of @qio inside, which keep host blocks */ +static u32 qio_border_zero_subclus_mask(struct qcow2 *qcow2, struct qio *qio, + struct qcow2_map *map) +{ + u64 start_off = bytes_off_in_cluster(qcow2, qio); + u64 end_off = start_off + qio->bi_iter.bi_size; + u32 zeroes = map->ext_l2 >> 32, mask = 0; + u8 start_bit, end_bit; + + if (!map->data_clu_alloced || map->clu_is_cow) + return 0; + + start_bit = qio_subclu_indexes(qcow2, qio, &end_bit); + if (SUBCLU_OFF(qcow2, start_off) && (zeroes & (1 << start_bit))) + mask |= 1 << start_bit; + if (SUBCLU_OFF(qcow2, end_off) && (zeroes & (1 << end_bit))) + mask |= 1 << end_bit; + return mask; +} + +/* + * A zero cluster or subcluster may keep host blocks with stale data. + * A write that does not cover it entirely must zero the rest. + */ +static bool qio_border_is_inside_zero_unit(struct qcow2 *qcow2, + struct qio *qio, + struct qcow2_map *map) +{ + if (qio->bi_iter.bi_size == qcow2->clu_size) + return false; + + if (!qcow2->ext_l2) + return map->prealloced; + + return qio_border_zero_subclus_mask(qcow2, qio, map) != 0; +} + static bool qio_is_fully_alloced(struct qcow2 *qcow2, struct qio *qio, struct qcow2_map *map) { @@ -3559,19 +3596,23 @@ static void submit_read_sliced_clu(struct qcow2_map *map, struct qio *qio, static void submit_read_sliced_cow_clu(struct qcow2_map *map, struct qio *qio) { struct qcow2 *qcow2 = map->qcow2; + struct qio_ext *ext = qio->ext; u64 mask = 0; WARN_ON_ONCE(!(map->level & L2_LEVEL)); + if (map->data_clu_alloced && !map->clu_is_cow) { + ext->cow_in_place = true; + ext->allocated_clu_pos = map->data_clu_pos; + } + if (qcow2->ext_l2) { mask = map->ext_l2 & ~((u64)map->subclus_mask << 32); - qio->ext->new_ext_l2 = mask | map->subclus_mask; - if (map->data_clu_alloced && !map->clu_is_cow) { - qio->ext->only_set_ext_l2 = true; - qio->ext->allocated_clu_pos = map->data_clu_pos; - } - qio->ext->cow_mask = calc_cow_mask(qcow2, map->ext_l2, qio, - true, map->clu_is_cow, false); + ext->new_ext_l2 = mask | map->subclus_mask; + ext->only_set_ext_l2 = ext->cow_in_place; + ext->cow_mask = calc_cow_mask(qcow2, map->ext_l2, qio, + true, map->clu_is_cow, false); + ext->cow_mask |= qio_border_zero_subclus_mask(qcow2, qio, map); } submit_read_sliced_clu(map, qio, sliced_cow_read_complete); @@ -3785,14 +3826,16 @@ static int handle_metadata(struct qcow2 *qcow2, struct qio **qio, /* COW to compressed or shared with snapshot cluster */ ret = prepare_l1l2_replace(qcow2, *qio, map); } else if ((map->level & L2_LEVEL) && - qio_border_is_inside_unmapped_unit(qcow2, *qio, map) && - maybe_mapped_in_lower_delta(qcow2, *qio)) { + ((qio_border_is_inside_unmapped_unit(qcow2, *qio, map) && + maybe_mapped_in_lower_delta(qcow2, *qio)) || + qio_border_is_inside_zero_unit(qcow2, *qio, map))) { /* * Backing file is about data COW, and it is * never about metadata COW (unlike internal * snapshots). Here is data COW on L2_LEVEL. + * A zero unit COWs zeroes over its host blocks. */ - map->backing_file_cow = true; + map->sliced_cow = true; if (delay_if_l2_dirty(qcow2, map, qio)) ret = 0; else @@ -3937,7 +3980,7 @@ static void process_one_qio(struct qcow2 *qcow2, struct qio *qio) } else { /* write */ if (unlikely(map.clu_is_cow && !(map.level & L2_LEVEL))) submit_read_whole_cow_clu(&map, qio); - else if (unlikely(map.clu_is_cow || map.backing_file_cow)) + else if (unlikely(map.clu_is_cow || map.sliced_cow)) submit_read_sliced_cow_clu(&map, qio); else perform_rw_mapped(&map, qio); @@ -4375,7 +4418,7 @@ static void process_cow_data_write(struct qcow2 *qcow2, struct list_head *cow_li break; ext = qio->ext; - if (ext->only_set_ext_l2) { + if (ext->cow_in_place) { WARN_ON_ONCE(ext->lx_level != L2_LEVEL); pos = ext->allocated_clu_pos; goto submit; diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h index 4acddbe7c95f..c2460c2bea06 100644 --- a/drivers/md/dm-qcow2.h +++ b/drivers/md/dm-qcow2.h @@ -325,6 +325,7 @@ struct qio_ext { u64 new_ext_l2; u32 cow_mask; bool only_set_ext_l2:1; + bool cow_in_place:1; bool set_all_zeroes:1; bool wait_writers:1; -- 2.55.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel