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 E1B41803F6 for ; Tue, 10 Nov 2026 11:52: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 6AABpQwk014519; Tue, 10 Nov 2026 14:51:27 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AABpQwk014519 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="d/ggX4da" Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AABoxLw014444 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 10 Nov 2026 14:50:59 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AABoxLw014444 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-48e0461e040so1543868f8f.0 for ; Tue, 10 Nov 2026 03:50:59 -0800 (PST) X-Gm-Message-State: APuU4Z+l54B88Ls7UnegLdYbndb33smmRtZqXCmpz8oaeBROfIyRUTev WVlanR7vNHIB3j+rkb66ZDxRMnfXp2o9YWiw5vPEBl/szlCl3vEDqK9S5CVXWfu9sGWnOP88LVw 7al4uYE/u7jj25MLvHtoWJ0r1kt1zuN9uUsMM9cbhxAoof5U3y8EeXw== X-Gm-Gg: AYBFou3T160366zBPhSfaLwpm/jE8/GyZxX+4hbKZfvocdKkQZgcM4/A8T6KORplsMV 3fQp4hM2YCZH7iKN1TXjSZj0WgGYn4xUHGvof4lDTQJ9w7dJaRh+4JbsKrNyzEeUXxmKKK7vCxc P6hMY0XCNs3cKYhSfFp82Y/J1CeyFtkzb20F3vHhkxWZbR1QvXeBAHbrosWDwZm9OF8/ql8jQ6R DDHgcAThRn+LEjKVVfTyZSY6d7VtvBe+64Cwz9T1Js2XxY7YjJyzA2XNoJ+ItArCSSA9xTlnVZi p4g9jJA1p0MHogRzihvlRCMICQ7pBxpWYvfctffafTq7l5phie450WM29Ut+9hNpxWxE2ewvzlp vRKL+fooeZgMgPr3CyfeoW1KAtHsn X-Received: by 2002:a05:6000:25f1:b0:48d:c186:dcc6 with SMTP id ffacd0b85a97d-49831806920mr4065498f8f.57.1794311458997; Tue, 10 Nov 2026 03:50:58 -0800 (PST) X-Received: by 2002:a05:6000:25f1:b0:48d:c186:dcc6 with SMTP id ffacd0b85a97d-49831806920mr4065474f8f.57.1794311458503; Tue, 10 Nov 2026 03:50:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794311458; cv=none; d=google.com; s=arc-20260327; b=ozfSnCSTO3JGrssYJ4kx9e5hAEmmgjfw6EMsReCAA4hl5h8rUIhVWe/WJCBsN1EAZL o5Cn+HHe9T90VQL5mBNXC7Bz0B0mr6OIjSDyxUoH+p2dzwBEdGMtT4cKI5r3ZDvfpcjM pI7/cAWHXBeU0ogB2hE1TQmo01pA+3WBBWo/smes7YXbvJ3dZAclkj3PTmdAD3z4c1JZ IRNhKa6kL5zGFv0+iJy3X0Gub4j8TIZy3TX6NKpSUuhTWbi7MGwU7/LkjXI2oAtc+gCz kBSmrDTs+ayaLZ6ej8UJKcThswKNIXpDGxe9gqLkl9Yo7PzpTfHub3TrUDD9i8F0aXfk pqhQ== 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=4qacOv4mKG78LFcKGG5npdeI7BzYeHUM2RovdlCNI70=; fh=ElTTnnNtphHTCCOZ+58STyaWac7y7ytLDJZIF4HMMJ4=; b=b5wAVMMY8sEhtwxDjHNTj+7WpA9DntydSRYTsc0ajG4xZVkIVwLyMdCgbiLpOx3T+r eSuSb/GvXGYcBLpMXfEOR3shnTd8YkNHJD7eGk9YgNMpdIWQ1aUyqKGmCviDCmmNQJEl /aGw0sXYq/3Hxxnpf6IvJZKHzwkE4hMnoz8wdNd7XcnmX8yCaxysuqS4mdcv56lJdkuq b53qbVhAuYiVxdl1D6+5VA6ldrEWG+j0tgYFfqjoVavrAWs/Q7BTNpYbB3cjCRpIlODT IxKw7CMfdcDhG1Gw1NY+JVSDakjyjptroK9ouuPpv5VNmqjrOCO4bZlrTfeNPWzN/UXQ 3ycw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b="d/ggX4da"; 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-498375233easi4615132f8f.353.2026.11.10.03.50.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2026 03:50:58 -0800 (PST) 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="d/ggX4da"; 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=4qacOv4mKG78LFcKGG5npdeI7BzYeHUM2RovdlCNI70=; b=d/ggX4daOhLC Aezd00sh3kOOS+k1fQOFHQWZOiz6edx1onB8hZRVeuVfHaJHMsYhY2yTmKHDsi1DsLOG1JEBr2LE9 1Hb16/dsqj50R/NLRAs7/P0Ju2YivAhO6kbtcY3gSuN0UGTgGeTN+eLT0qY5oWWGsfyNcPQOvx9+3 YEBGe3o69GOaCtd4p+uE+DWaW3Qe5GOC+M4uqaklag+Z9UywBq8941BON6rDTrIaoQh1QJXk+Sglt zH2T+pQn8pgLLM1uE1sqSbHTiFecw/PFLKyJISMEIdNcm85SXDIJ/EJ1Zv5BAlNdGHoZRgAJ5Xt37 xb+zRO4J0A60em3rq5FHsw==; 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 1xQkJI-00DBlM-1B; Tue, 10 Nov 2026 12:50:48 +0100 From: Andrey Zhadchenko To: khorenko@virtuozzo.com, alexander.ivanov@virtuozzo.com Date: Tue, 10 Nov 2026 14:46:24 +0300 Message-ID: <20261110114629.416695-3-andrey.zhadchenko@virtuozzo.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20261110114629.416695-1-andrey.zhadchenko@virtuozzo.com> References: <20261110114629.416695-1-andrey.zhadchenko@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v2 2/7] dm-qcow2: wait for L2 writeback in perform_rw_mapped() 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 perform_rw_mapped() reads md->status and md->wbd without md_pages_lock, relying on dm-qcow2 sequential nature: L1/L2 pages become dirty, go to writeback and drop md->wbd from main kwork only. Expand md_pages_lock to also cover the check, so it can be called from the per-qio fast path in parallel with main kwork. The lock alone is not enough. parse_l2() does not delay a write to a changed index of a DIRTY L2 page, as perform_rw_mapped() is going to attach the write to md->wbd. Main kwork does parse, submit and the DIRTY -> WRITEBACK switch in one do_qcow2_work() pass, so the page is still DIRTY there. The fast path parses and submits under separate lock holds, and main kwork may switch the page to WRITEBACK in between: main kwork fast worker allocates cluster X, L2 page DIRTY parse_l2(): write to X, page DIRTY, not delayed, unlock submit_metadata_writeback(): DIRTY -> WRITEBACK perform_rw_mapped(): no MD_DIRTY, qio->data = NULL, submit The write is then acked as soon as its data is written, before the L2 entry mapping it is on disk. A FLUSH after it finds QLIST_COMPLETED_WB empty and only calls vfs_fsync(), so it does not wait for the L2 write in flight, and a crash loses a write that was acked and flushed. If the L2 write fails instead, the entry is reverted and X freed while the write already returned success. So, when the page is under writeback and the index is changed, park the qio on md->wait_list, as parse_l2() does. It is redispatched to main kwork when the writeback ends and parsed again. Do not attach it to the wbd under writeback: after a failed writeback complete_wbd() reverts the indexes and frees the wbd. This changes nothing for main kwork, where parse_l2() has already delayed such writes in the same pass. https://virtuozzo.atlassian.net/browse/VSTOR-95494 Feature: dm-qcow2: block device over QCOW2 files driver Signed-off-by: Andrey Zhadchenko --- v2: renamed from "check MD_DIRTY and md->wbd under lock in perform_rw_mapped()"; park a write on md->wait_list if its L2 page went to writeback after parse_l2(), instead of acking it before its L2 entry is on disk; commit message describes the race drivers/md/dm-qcow2-map.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c index 21d1c8975af99..49dc3e8119e76 100644 --- a/drivers/md/dm-qcow2-map.c +++ b/drivers/md/dm-qcow2-map.c @@ -2912,14 +2912,28 @@ static void perform_rw_mapped(struct qcow2_map *map, struct qio *qio) * wait for md writeback completion. * * L1/L2 pages become set and unset dirty from main work only, - * so lock is not needed for MD_DIRTY/changed_indexes visibility. + * but this may be called from per-qio fast path in parallel + * with main work submitting the writeback and with its completion + * dropping md->wbd. + * + * So md may have gone DIRTY -> WRITEBACK after parse_l2() decided + * the qio need not wait. Then the qio must wait for writeback end + * the way parse_l2() makes it. It can't be attached to wbd: after + * a failed writeback, complete_wbd() reverts the indexes and frees + * the wbd without looking at qios attached in the meantime. */ index_in_page = map->l2.index_in_page + !!(qcow2->ext_l2); - if (rw == WRITE && (md->status & MD_DIRTY) && - test_bit(index_in_page, md->wbd->changed_indexes)) { + if (rw == WRITE) { spin_lock_irqsave(&qcow2->md_pages_lock, flags); - md->wbd->nr_submitted++; - qio->data = md->wbd; + if (__delay_if_writeback(qcow2, md, index_in_page, &qio, false)) { + spin_unlock_irqrestore(&qcow2->md_pages_lock, flags); + return; + } + if ((md->status & MD_DIRTY) && + test_bit(index_in_page, md->wbd->changed_indexes)) { + md->wbd->nr_submitted++; + qio->data = md->wbd; + } spin_unlock_irqrestore(&qcow2->md_pages_lock, flags); } -- 2.43.5 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel