From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (unknown [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 3404080024 for ; Thu, 27 Aug 2026 16:10: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 67RG9MtH001626; Thu, 27 Aug 2026 19:09:23 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 67RG9MtH001626 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="xtQp2vyp" Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 67RG9BmB001575 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 27 Aug 2026 19:09:11 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 67RG9BmB001575 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-47f81362fb1so551636f8f.1 for ; Thu, 27 Aug 2026 09:09:11 -0700 (PDT) X-Gm-Message-State: AFuF++mWoFqkUzcU2xnFfZXDbK8ucWcrGP7Ikelal0hju8SqyHsccdqQ W0kibwH5DdSCqXsZs22wz8DJK1perll2erwgH4P+DXQq3SMlKL0hqybykZ+Lk0IdiyyDA6Gbg37 J8xxaw7gE4Yoo+sKrSBlpfwL44lfX9I4AL2jbQzmm4f8+HMp3S7lfGw== X-Gm-Gg: AR+sD10AMR65kECFp935GYuWYkLyNZDDNjfZ6tOvKKQt/CQof/GBmgLeRlxqzsOxwE0 dSzk8uwt4k/jLN36whoemDjoU4Th3feb5aFobBFOSvp3fBVmrhRGOa38yuoboNeC5POCVhPTMW7 SeyKeoC5XqLadSfwbie2ZLgqDyOCJrFZo1BphPv3oprjHl1ryhZHREUIEQpDQUf7PQ7RWJgGam2 RO8fUWeksZWSrLfChiZ8yGtsSaif70gsJZbrV2LzSYzbKMLLw35kP23xOJjcrbvyPQLBRu1ArmX i4g12mLtyFJHB+KWglQ11X07wjuk9Og8EDgP3wf2y6BlFnTAwAloB/opYQZmc3PsMoqjIgja23M lVgFX+uc7yyK5jxcj1rtSSujm2rwZ2A== X-Received: by 2002:a05:6000:645:b0:481:5b58:c589 with SMTP id ffacd0b85a97d-482e26b380amr19697631f8f.10.1787846951394; Thu, 27 Aug 2026 09:09:11 -0700 (PDT) X-Received: by 2002:a05:6000:645:b0:481:5b58:c589 with SMTP id ffacd0b85a97d-482e26b380amr19697516f8f.10.1787846950853; Thu, 27 Aug 2026 09:09:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1787846950; cv=none; d=google.com; s=arc-20260327; b=eA239t3PcrEPp/ue1BSEQ7zIvaFzjzKoHHrTY0j5MWpxmWzKDe8Kq6tFridum8+UTc 2BNlB3SnrRzsigqPMxyQwY20ozwXzu4Xch16hBE/YJP8ZQz7AAL2dV7DmrwDCrsk5VmU iRE6lIFOX0Y3UJCgjwfP4FL1ygMLXh9fdGG/OE9kYcYF/a5h3Aa56f6oSN8CURyVGkzC eLk8jtbUc1oeSTxMic8cdSeE+VReYjy65FLr41ke1Of4Nbi++vccQ/lRkOvtKU+wp4/f otdZMJNJyb+yXETsnYhKS8qmb5L3Tu9dFl6ztKA9bfGJj6dYvEZG2OTMlcfJMplLexTr YH2Q== 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=2yd+5t8o00ijfbzJmPszjfcE20WxtQVedlTZuB/SLCk=; fh=0/brz1B8ohImS2ERrXZY0dPGpSEyX2H6iLC7bneXJkE=; b=YmUTwJJJBMi2LODgxM1FPt7qI79OI1QsHx9s1Kb81kqP1pq5SLYssnsQNHI6tu3SMl fhW48782j8h2vVXHxyY6etXkzODSOzG5SJ/l+V2KdqsUD9DV5TIkaIIHaWpkvBCEMh1A Q0CuRh2ZEH1XvtoS6l/Ec1/W/Z+L8uRdMFT/6jtugItQQYOKoIraT3pAhNgjx3siWByj 1o1XfKC5Lvn7ofBymJFuCTCkPYh4EdAFOioyKiTAfx2Xo2DVdEtRLMb2mMrViR1VJ+Rb bCw2eBJMJnMgoZxECLCJT3i6c02cg41d3plgxDmiDCKfMglhqM6nmRw7BEp7boRu3yss 05Sw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=xtQp2vyp; spf=pass (google.com: domain of andrey.zhadchenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=andrey.zhadchenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-482e2787dc2si8784439f8f.25.2026.08.27.09.09.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Aug 2026 09:09:10 -0700 (PDT) Received-SPF: pass (google.com: domain of andrey.zhadchenko@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=xtQp2vyp; spf=pass (google.com: domain of andrey.zhadchenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=andrey.zhadchenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=2yd+5t8o00ijfbzJmPszjfcE20WxtQVedlTZuB/SLCk=; b=xtQp2vypl3UP c1VIPT4oMzGyoIp41TLLAS5Epfx63diLaMMubKULVCQIyISbNfkPoyeloyDuiIOTiRvkJTifl3zrb dOYXiRrIDPz/br8lUDzHR+CLkKDo4cUWDipb6mimw39Hi6gOEjghEeIwZXP23hoGJc7Tuuaiq2/JJ jDu9oePVP6IvIL3SixRPaLpTgY6rjWe0zIRxG4nWQAndF4xtReeHSmIMNv6tIyy9tmX3z2saC/bbw BMOBuLqeLfXpnVUgJqPJ37mtqFDzk320IAZhE9pBzVPItbJahTM/cJMIhDKlT+/UfjGyYMVEZuO5A dsuZOneHdtdQt6Ydzw5Y+g==; Received: from [130.117.225.5] (helo=vz9-demens-1.aci.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1wzccs-00FHQJ-19; Thu, 27 Aug 2026 18:09:08 +0200 From: Andrey Zhadchenko To: ptikhomirov@virtuozzo.com, vasileios.almpanis@virtuozzo.com Date: Thu, 27 Aug 2026 19:06:14 +0300 Message-ID: <20260827160619.303398-7-andrey.zhadchenko@virtuozzo.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20260827160619.303398-1-andrey.zhadchenko@virtuozzo.com> References: <20260827160619.303398-1-andrey.zhadchenko@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH VZ10 v4 06/11] drivers/md/dm-qcow2: set L2_READS_ALL_ZEROES after some discards 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 Discard does not guarantee zero data. Therefore, to safely erase data, users may write zeroes and then discard. Imagine we have a backing file. If we write zeroes and do the discard, next read will give the stale data from backing image. Probably this is rather an edge case, but to be sure let's just set L2 entry to L2_READS_ALL_ZEROES so the device looks more consistent to users. Feature: dm-qcow2: block device over QCOW2 files driver https://virtuozzo.atlassian.net/browse/VSTOR-139406 Signed-off-by: Andrey Zhadchenko --- v2: - expand qio_discard_updates_metadata() condition to return true when backing file is present and fully covered sublcu zero bit isn't already set v4: - set new_ext_l2 value as 0. If we clear a full cluster, we also need to clear all ext_l2, except the case with backing (handled separately) drivers/md/dm-qcow2-map.c | 24 +++++++++++++++++++++--- drivers/md/dm-qcow2.h | 1 + 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c index a2e5c37adb7b9..52a630685518b 100644 --- a/drivers/md/dm-qcow2-map.c +++ b/drivers/md/dm-qcow2-map.c @@ -1309,6 +1309,7 @@ static void revert_l_entries_update(struct qcow2 *qcow2, struct wb_desc *wbd) struct page *pe_page; bool skip_odd; u64 pos, old; + bool cleared; int i, ret; skip_odd = qcow2->ext_l2 && wbd->lx_level == L2_LEVEL; @@ -1317,6 +1318,8 @@ static void revert_l_entries_update(struct qcow2 *qcow2, struct wb_desc *wbd) for_each_set_bit(i, wbd->changed_indexes, LX_INDEXES_PER_PAGE) { pos = get_u64_from_be_page(wbd->md->page, i); + cleared = !(pos & ~(u64)L2_READS_ALL_ZEROES); + /* Here we restore prealloced and compressed clu mappings */ pe_page = wbd->pe_page; if (pe_page) { /* Only L2 has this. */ @@ -1330,7 +1333,7 @@ static void revert_l_entries_update(struct qcow2 *qcow2, struct wb_desc *wbd) set_u64_to_be_page(wbd->md->page, i, 0); if (skip_odd && (i & 1)) continue; /* pos contains ext_l2 part of L2 entry */ - if (!pos) + if (cleared) continue; /* no cluster was allocated */ spin_unlock(&qcow2->md_pages_lock); @@ -3368,14 +3371,18 @@ static bool qio_discard_updates_metadata(struct qcow2 *qcow2, struct qio *qio, * * Discard covering the whole cluster replaces the entry and unuses * the discarded (or COW source) cluster. + * If the backing is present, set 'reads as zeroes' to avoid exposing + * stale data. */ static int prepare_cluster_discard(struct qcow2 *qcow2, struct qio **qio, struct qcow2_map *map) { + bool zeroes = maybe_mapped_in_lower_delta(qcow2, *qio); u32 index_in_page = map->l2.index_in_page; struct md_page *md = map->l2.md; loff_t unuse_pos, unuse_end; struct qio_ext *ext; + u64 new_ext_l2 = 0; int ret; WARN_ON_ONCE(!(map->level & L2_LEVEL) || !map->data_clu_alloced); @@ -3399,6 +3406,8 @@ static int prepare_cluster_discard(struct qcow2 *qcow2, struct qio **qio, unuse_pos = map->data_clu_pos; unuse_end = map->data_clu_pos + qcow2->clu_size; } + if (zeroes && qcow2->ext_l2) + new_ext_l2 = (u64)U32_MAX << 32; ret = prepare_l_entry_replace(qcow2, map, *qio, md, index_in_page, unuse_pos, unuse_end, L2_LEVEL); @@ -3408,6 +3417,10 @@ static int prepare_cluster_discard(struct qcow2 *qcow2, struct qio **qio, ext = (*qio)->ext; ext->lx_md = md; + ext->new_ext_l2 = new_ext_l2; + if (zeroes && !qcow2->ext_l2) + ext->set_all_zeroes = true; + (*qio)->flags |= QIO_IS_DISCARD_FL; return 1; } @@ -4053,6 +4066,7 @@ static void process_indexes_write(struct qcow2 *qcow2, struct qio *qio; bool discard; u32 arg_mask; + u64 entry; int ret; while (1) { @@ -4076,11 +4090,15 @@ static void process_indexes_write(struct qcow2 *qcow2, goto set_ext_l2; } + entry = ext->allocated_clu_pos; + if (unlikely(ext->set_all_zeroes)) + entry = L2_READS_ALL_ZEROES; + /* XXX: check prealloced_pos ==> revert */ ret = prepare_l_entry_update(qcow2, qio, lx_md, ext->lx_index_in_page, - &ext->allocated_clu_pos, - arg_mask, ext->lx_level); + &entry, arg_mask, + ext->lx_level); if (ret < 0) { qio->bi_status = errno_to_blk_status(ret); qio_endio(qio); diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h index 8a24e04130e4d..0f006f1ae48cc 100644 --- a/drivers/md/dm-qcow2.h +++ b/drivers/md/dm-qcow2.h @@ -312,6 +312,7 @@ struct qio_ext { u64 new_ext_l2; u32 cow_mask; bool only_set_ext_l2:1; + bool set_all_zeroes:1; u8 lx_level; -- 2.43.5 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel