From nobody Tue Feb 10 20:08:40 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1710343823; cv=none; d=zohomail.com; s=zohoarc; b=RiuAvkzPOdE9BtLPZWf1Yjx4d+kWHNX4jf0btx19+D3gcPBicEPFEekBIXjoFhEHR41Ea9wevIgpjjZU/ayzvx4GlA6DrTdZfYrDjduxVYrm7lp4r76/FV+lSCKY6/kfsFjnQi27b8T/L8QOf+P5/8nRQeAd+egvKniUQ5zsDRU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710343823; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Beqqvkr9H2C67AWO4YL7VkuxAYFA36Y2edAiukFs7/A=; b=HIsz57vLWXb7c6CrAFYAGIwbZtAuphDLgFNk4+xR6z3uQ5THm7PV1YKVMFoA+m0gyXfZFOiSDDZMH64oxYjBqJFatcPVX91JtmS85HuC1022YlOhKFnJhXUAhLiVDpZbl5ONRdNWsO8WUh9VnrzYcTyHFMTyQMkbwguEMeHO7lM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1710343823539969.4458841847204; Wed, 13 Mar 2024 08:30:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkQXE-0003mX-EL; Wed, 13 Mar 2024 11:28:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkQX6-0003j6-Ac; Wed, 13 Mar 2024 11:28:44 -0400 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkQWz-0002kX-Sn; Wed, 13 Mar 2024 11:28:42 -0400 Received: from mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2a:3dc:0:640:1e66:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 1103660C43; Wed, 13 Mar 2024 18:28:32 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6b8:b081:7318::1:20]) by mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id OSpDOX0Xl4Y0-cthBkX4m; Wed, 13 Mar 2024 18:28:31 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1710343711; bh=Beqqvkr9H2C67AWO4YL7VkuxAYFA36Y2edAiukFs7/A=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=itFsvP3req0fNiEgVrtrBAxHSHJQE/se7qn4a+Cve+iQxdCbuWOgRaBp+nV8u4C5G J9Vdg0wAmgK5QR10YZaOGrGndZT7GA7fi+nuRhvu7qkzwl/fIbs1963TX11zgFVlhX jENEENoVeJxdbbBwcr01VuL86OEy3+qYxIECqsRM= Authentication-Results: mail-nwsmtp-smtp-corp-main-69.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, armbru@redhat.com, eblake@redhat.com, xiechanglong.d@gmail.com, wencongyang2@huawei.com, hreitz@redhat.com, kwolf@redhat.com, vsementsov@yandex-team.ru, jsnow@redhat.com, f.ebner@proxmox.com Subject: [PATCH v4 2/5] block/copy-before-write: support unligned snapshot-discard Date: Wed, 13 Mar 2024 18:28:19 +0300 Message-Id: <20240313152822.626493-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240313152822.626493-1-vsementsov@yandex-team.ru> References: <20240313152822.626493-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1710343823838100001 Content-Type: text/plain; charset="utf-8" First thing that crashes on unligned access here is bdrv_reset_dirty_bitmap(). Correct way is to align-down the snapshot-discard request. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fiona Ebner Tested-by: Fiona Ebner --- block/copy-before-write.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/block/copy-before-write.c b/block/copy-before-write.c index 3e3af30c08..6d89af0b29 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -325,14 +325,24 @@ static int coroutine_fn GRAPH_RDLOCK cbw_co_pdiscard_snapshot(BlockDriverState *bs, int64_t offset, int64_t byt= es) { BDRVCopyBeforeWriteState *s =3D bs->opaque; + uint32_t cluster_size =3D block_copy_cluster_size(s->bcs); + int64_t aligned_offset =3D QEMU_ALIGN_UP(offset, cluster_size); + int64_t aligned_end =3D QEMU_ALIGN_DOWN(offset + bytes, cluster_size); + int64_t aligned_bytes; + + if (aligned_end <=3D aligned_offset) { + return 0; + } + aligned_bytes =3D aligned_end - aligned_offset; =20 WITH_QEMU_LOCK_GUARD(&s->lock) { - bdrv_reset_dirty_bitmap(s->access_bitmap, offset, bytes); + bdrv_reset_dirty_bitmap(s->access_bitmap, aligned_offset, + aligned_bytes); } =20 - block_copy_reset(s->bcs, offset, bytes); + block_copy_reset(s->bcs, aligned_offset, aligned_bytes); =20 - return bdrv_co_pdiscard(s->target, offset, bytes); + return bdrv_co_pdiscard(s->target, aligned_offset, aligned_bytes); } =20 static void GRAPH_RDLOCK cbw_refresh_filename(BlockDriverState *bs) --=20 2.34.1