From nobody Mon Feb 9 05:55:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1767960677519797.5903861876525; Fri, 9 Jan 2026 04:11:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1veBJf-00066F-Qa; Fri, 09 Jan 2026 07:10:07 -0500 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 1veBIW-0005ad-D7; Fri, 09 Jan 2026 07:08:59 -0500 Received: from proxmox-new.maurer-it.com ([94.136.29.106]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1veBIT-00017F-Lk; Fri, 09 Jan 2026 07:08:56 -0500 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6A23548FBB; Fri, 09 Jan 2026 13:08:42 +0100 (CET) From: Fiona Ebner To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, fam@euphon.net, stefanha@redhat.com Subject: [PATCH 1/6] block/io: pass alignment to bdrv_init_padding() Date: Fri, 9 Jan 2026 13:08:28 +0100 Message-ID: <20260109120837.2772961-2-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260109120837.2772961-1-f.ebner@proxmox.com> References: <20260109120837.2772961-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1767960482239 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 (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=94.136.29.106; envelope-from=f.ebner@proxmox.com; helo=proxmox-new.maurer-it.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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-ZM-MESSAGEID: 1767960678507158500 Content-Type: text/plain; charset="utf-8" Currently, all callers use bs->bl.request_alignment. This will change in the next commit when making bdrv_co_do_zero_pwritev() honor the block driver's pwrite_zeroes_alignment. uint64_t is chosen as the type, because that is more common in other functions already and in particular, in the bdrv_co_do_zero_pwritev() caller. Signed-off-by: Fiona Ebner --- block/io.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/block/io.c b/block/io.c index cace297f22..e80aecf194 100644 --- a/block/io.c +++ b/block/io.c @@ -1474,10 +1474,9 @@ typedef struct BdrvRequestPadding { =20 static bool bdrv_init_padding(BlockDriverState *bs, int64_t offset, int64_t bytes, - bool write, + uint64_t align, bool write, BdrvRequestPadding *pad) { - int64_t align =3D bs->bl.request_alignment; int64_t sum; =20 bdrv_check_request(offset, bytes, &error_abort); @@ -1716,6 +1715,7 @@ static int bdrv_pad_request(BlockDriverState *bs, struct iovec *sliced_iov; int sliced_niov; size_t sliced_head, sliced_tail; + uint64_t align =3D bs->bl.request_alignment; =20 /* Should have been checked by the caller already */ ret =3D bdrv_check_request32(*offset, *bytes, *qiov, *qiov_offset); @@ -1723,7 +1723,7 @@ static int bdrv_pad_request(BlockDriverState *bs, return ret; } =20 - if (!bdrv_init_padding(bs, *offset, *bytes, write, pad)) { + if (!bdrv_init_padding(bs, *offset, *bytes, align, write, pad)) { if (padded) { *padded =3D false; } @@ -2161,7 +2161,7 @@ bdrv_co_do_zero_pwritev(BdrvChild *child, int64_t off= set, int64_t bytes, /* This flag doesn't make sense for padding or zero writes */ flags &=3D ~BDRV_REQ_REGISTERED_BUF; =20 - padding =3D bdrv_init_padding(bs, offset, bytes, true, &pad); + padding =3D bdrv_init_padding(bs, offset, bytes, align, true, &pad); if (padding) { assert(!(flags & BDRV_REQ_NO_WAIT)); bdrv_make_request_serialising(req, align); --=20 2.47.3 From nobody Mon Feb 9 05:55:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1767960620829782.5728309147613; Fri, 9 Jan 2026 04:10:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1veBJQ-0005qU-FV; Fri, 09 Jan 2026 07:09:52 -0500 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 1veBIV-0005aZ-8R; Fri, 09 Jan 2026 07:08:57 -0500 Received: from proxmox-new.maurer-it.com ([94.136.29.106]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1veBIT-00017H-AS; Fri, 09 Jan 2026 07:08:55 -0500 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id BFE8F476DB; Fri, 09 Jan 2026 13:08:42 +0100 (CET) From: Fiona Ebner To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, fam@euphon.net, stefanha@redhat.com Subject: [PATCH 2/6] block/io: add 'bytes' parameter to bdrv_padding_rmw_read() Date: Fri, 9 Jan 2026 13:08:29 +0100 Message-ID: <20260109120837.2772961-3-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260109120837.2772961-1-f.ebner@proxmox.com> References: <20260109120837.2772961-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1767960482305 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 (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=94.136.29.106; envelope-from=f.ebner@proxmox.com; helo=proxmox-new.maurer-it.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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-ZM-MESSAGEID: 1767960622231158500 Content-Type: text/plain; charset="utf-8" Currently, all callers use bs->bl.request_alignment. This will change when making bdrv_co_do_zero_pwritev() honor the block driver's pwrite_zeroes_alignment. Note that the alignment for reading is not necessarily the alignment for the request. In particular with qcow2 images, the total image length is not necessarily aligned to pwrite_zeroes_alignment, and in such cases, a request with that bigger alignment would cause an assertion failure. Signed-off-by: Fiona Ebner --- block/io.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/block/io.c b/block/io.c index e80aecf194..403a45f91d 100644 --- a/block/io.c +++ b/block/io.c @@ -1511,7 +1511,7 @@ static bool bdrv_init_padding(BlockDriverState *bs, } =20 static int coroutine_fn GRAPH_RDLOCK -bdrv_padding_rmw_read(BdrvChild *child, BdrvTrackedRequest *req, +bdrv_padding_rmw_read(BdrvChild *child, BdrvTrackedRequest *req, int64_t b= ytes, BdrvRequestPadding *pad, bool zero_middle) { QEMUIOVector local_qiov; @@ -1522,7 +1522,9 @@ bdrv_padding_rmw_read(BdrvChild *child, BdrvTrackedRe= quest *req, assert(req->serialising && pad->buf); =20 if (pad->head || pad->merge_reads) { - int64_t bytes =3D pad->merge_reads ? pad->buf_len : align; + if (pad->merge_reads) { + bytes =3D pad->buf_len; + } =20 qemu_iovec_init_buf(&local_qiov, pad->buf, bytes); =20 @@ -1550,13 +1552,13 @@ bdrv_padding_rmw_read(BdrvChild *child, BdrvTracked= Request *req, } =20 if (pad->tail) { - qemu_iovec_init_buf(&local_qiov, pad->tail_buf, align); + qemu_iovec_init_buf(&local_qiov, pad->tail_buf, bytes); =20 bdrv_co_debug_event(bs, BLKDBG_PWRITEV_RMW_TAIL); ret =3D bdrv_aligned_preadv( child, req, - req->overlap_offset + req->overlap_bytes - align, - align, align, &local_qiov, 0, 0); + req->overlap_offset + req->overlap_bytes - bytes, + bytes, align, &local_qiov, 0, 0); if (ret < 0) { return ret; } @@ -2166,7 +2168,7 @@ bdrv_co_do_zero_pwritev(BdrvChild *child, int64_t off= set, int64_t bytes, assert(!(flags & BDRV_REQ_NO_WAIT)); bdrv_make_request_serialising(req, align); =20 - bdrv_padding_rmw_read(child, req, &pad, true); + bdrv_padding_rmw_read(child, req, align, &pad, true); =20 if (pad.head || pad.merge_reads) { int64_t aligned_offset =3D offset & ~(align - 1); @@ -2302,7 +2304,7 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *chil= d, */ assert(!(flags & BDRV_REQ_NO_WAIT)); bdrv_make_request_serialising(&req, align); - bdrv_padding_rmw_read(child, &req, &pad, false); + bdrv_padding_rmw_read(child, &req, align, &pad, false); } =20 ret =3D bdrv_aligned_pwritev(child, &req, offset, bytes, align, --=20 2.47.3 From nobody Mon Feb 9 05:55:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1767960677555228.5697240057758; Fri, 9 Jan 2026 04:11:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1veBJb-0005wS-9N; Fri, 09 Jan 2026 07:10:03 -0500 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 1veBIW-0005af-LL; Fri, 09 Jan 2026 07:09:00 -0500 Received: from proxmox-new.maurer-it.com ([94.136.29.106]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1veBIT-00017I-Me; Fri, 09 Jan 2026 07:08:56 -0500 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 0FD4C48FAE; Fri, 09 Jan 2026 13:08:43 +0100 (CET) From: Fiona Ebner To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, fam@euphon.net, stefanha@redhat.com Subject: [PATCH 3/6] block/io: honor pwrite_zeroes_alignment in bdrv_co_do_zero_pwritev() Date: Fri, 9 Jan 2026 13:08:30 +0100 Message-ID: <20260109120837.2772961-4-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260109120837.2772961-1-f.ebner@proxmox.com> References: <20260109120837.2772961-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1767960482368 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 (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=94.136.29.106; envelope-from=f.ebner@proxmox.com; helo=proxmox-new.maurer-it.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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-ZM-MESSAGEID: 1767960678493158500 Content-Type: text/plain; charset="utf-8" Commit 5634622bcb ("file-posix: allow BLKZEROOUT with -t writeback") enables the BLKZEROOUT ioctl when using 'writeback' cache, regressing certain 'qemu-img convert' invocations, because of a pre-existing issue. Namely, the BLKZEROOUT ioctl might fail with errno EINVAL when the request is shorter than the block size of the block device. Ensure that bdrv_co_do_zero_pwritev() only issues requests respecting the block driver's pwrite_zeroes_alignment. The file-posix host_device block driver already initializes that value. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3257 Resolves: https://bugzilla.proxmox.com/show_bug.cgi?id=3D7197 Cc: qemu-stable@nongnu.org Suggested-by: Stefan Hajnoczi Signed-off-by: Fiona Ebner --- This breaks the following iotests with qcow2: 154 177 179 204 271 See the following commits for details. If we decide to go with the current approach, I will re-order in the next version to avoid the temporary breakage, but I felt like it would be easier to look at the issues with this patch order here. block/io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/io.c b/block/io.c index 403a45f91d..12dc153573 100644 --- a/block/io.c +++ b/block/io.c @@ -2155,7 +2155,8 @@ bdrv_co_do_zero_pwritev(BdrvChild *child, int64_t off= set, int64_t bytes, { BlockDriverState *bs =3D child->bs; QEMUIOVector local_qiov; - uint64_t align =3D bs->bl.request_alignment; + uint64_t align =3D MAX(bs->bl.pwrite_zeroes_alignment, + bs->bl.request_alignment); int ret =3D 0; bool padding; BdrvRequestPadding pad; --=20 2.47.3 From nobody Mon Feb 9 05:55:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1767960683436802.3059052562335; Fri, 9 Jan 2026 04:11:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1veBJj-0006AV-VU; Fri, 09 Jan 2026 07:10:12 -0500 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 1veBIV-0005aY-77; Fri, 09 Jan 2026 07:08:56 -0500 Received: from proxmox-new.maurer-it.com ([94.136.29.106]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1veBIT-00017G-Bg; Fri, 09 Jan 2026 07:08:54 -0500 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id B561448FC1; Fri, 09 Jan 2026 13:08:42 +0100 (CET) From: Fiona Ebner To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, fam@euphon.net, stefanha@redhat.com Subject: [PATCH 4/6] block/io: safeguard max transfer calculation in bdrv_aligned_pwritev() Date: Fri, 9 Jan 2026 13:08:31 +0100 Message-ID: <20260109120837.2772961-5-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260109120837.2772961-1-f.ebner@proxmox.com> References: <20260109120837.2772961-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1767960482432 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 (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=94.136.29.106; envelope-from=f.ebner@proxmox.com; helo=proxmox-new.maurer-it.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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-ZM-MESSAGEID: 1767960684669158500 Content-Type: text/plain; charset="utf-8" This partially fixes iotest 177 with qcow2, where max_transfer is 64KiB, but the cluster size and thus pwrite_zeroes_alignment is 1MiB. Previously, max_transfer would be calculated as 0, triggering an assertion later. Signed-off-by: Fiona Ebner --- block/io.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/block/io.c b/block/io.c index 12dc153573..233b2617ea 100644 --- a/block/io.c +++ b/block/io.c @@ -2087,8 +2087,10 @@ bdrv_aligned_pwritev(BdrvChild *child, BdrvTrackedRe= quest *req, assert(is_power_of_2(align)); assert((offset & (align - 1)) =3D=3D 0); assert((bytes & (align - 1)) =3D=3D 0); - max_transfer =3D QEMU_ALIGN_DOWN(MIN_NON_ZERO(bs->bl.max_transfer, INT= _MAX), - align); + max_transfer =3D MIN_NON_ZERO(bs->bl.max_transfer, INT_MAX); + if (max_transfer > align) { + max_transfer =3D QEMU_ALIGN_DOWN(max_transfer, align); + } =20 ret =3D bdrv_co_write_req_prepare(child, offset, bytes, req, flags); =20 --=20 2.47.3 From nobody Mon Feb 9 05:55:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 176796061778672.25369012849308; Fri, 9 Jan 2026 04:10:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1veBJQ-0005qW-KY; Fri, 09 Jan 2026 07:09:54 -0500 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 1veBIY-0005al-12; Fri, 09 Jan 2026 07:09:00 -0500 Received: from proxmox-new.maurer-it.com ([94.136.29.106]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1veBIW-00018H-Fz; Fri, 09 Jan 2026 07:08:57 -0500 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6201D48FBA; Fri, 09 Jan 2026 13:08:43 +0100 (CET) From: Fiona Ebner To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, fam@euphon.net, stefanha@redhat.com Subject: [PATCH 5/6] block/io: handle image length not aligned to write zeroes alignment in bdrv_co_do_zero_pwritev() Date: Fri, 9 Jan 2026 13:08:32 +0100 Message-ID: <20260109120837.2772961-6-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260109120837.2772961-1-f.ebner@proxmox.com> References: <20260109120837.2772961-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1767960482537 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 (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=94.136.29.106; envelope-from=f.ebner@proxmox.com; helo=proxmox-new.maurer-it.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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-ZM-MESSAGEID: 1767960620999158500 Content-Type: text/plain; charset="utf-8" When making the request shorter, use bl.request_alignment as the alignment. This partially fixes iotests 154 and 271 with qcow2. Signed-off-by: Fiona Ebner --- block/io.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/block/io.c b/block/io.c index 233b2617ea..d92b30bce5 100644 --- a/block/io.c +++ b/block/io.c @@ -2162,6 +2162,7 @@ bdrv_co_do_zero_pwritev(BdrvChild *child, int64_t off= set, int64_t bytes, int ret =3D 0; bool padding; BdrvRequestPadding pad; + uint64_t total_length =3D bs->total_sectors * BDRV_SECTOR_SIZE; =20 /* This flag doesn't make sense for padding or zero writes */ flags &=3D ~BDRV_REQ_REGISTERED_BUF; @@ -2177,10 +2178,21 @@ bdrv_co_do_zero_pwritev(BdrvChild *child, int64_t o= ffset, int64_t bytes, int64_t aligned_offset =3D offset & ~(align - 1); int64_t write_bytes =3D pad.merge_reads ? pad.buf_len : align; =20 - qemu_iovec_init_buf(&local_qiov, pad.buf, write_bytes); - ret =3D bdrv_aligned_pwritev(child, req, aligned_offset, write= _bytes, - align, &local_qiov, 0, - flags & ~BDRV_REQ_ZERO_WRITE); + if (total_length >=3D aligned_offset + write_bytes) { + qemu_iovec_init_buf(&local_qiov, pad.buf, write_bytes); + ret =3D bdrv_aligned_pwritev(child, req, aligned_offset, + write_bytes, align, &local_qiov= , 0, + flags & ~BDRV_REQ_ZERO_WRITE); + } else { + write_bytes =3D total_length - aligned_offset; + qemu_iovec_init_buf(&local_qiov, pad.buf, write_bytes); + ret =3D bdrv_aligned_pwritev(child, req, aligned_offset, + write_bytes, + bs->bl.request_alignment, + &local_qiov, 0, + flags & ~BDRV_REQ_ZERO_WRITE); + } + if (ret < 0 || pad.merge_reads) { /* Error or all work is done */ goto out; @@ -2205,12 +2217,20 @@ bdrv_co_do_zero_pwritev(BdrvChild *child, int64_t o= ffset, int64_t bytes, =20 assert(!bytes || (offset & (align - 1)) =3D=3D 0); if (bytes) { - assert(align =3D=3D pad.tail + bytes); + if (total_length >=3D offset + align) { + assert(align =3D=3D pad.tail + bytes); =20 - qemu_iovec_init_buf(&local_qiov, pad.tail_buf, align); - ret =3D bdrv_aligned_pwritev(child, req, offset, align, align, - &local_qiov, 0, - flags & ~BDRV_REQ_ZERO_WRITE); + qemu_iovec_init_buf(&local_qiov, pad.tail_buf, align); + ret =3D bdrv_aligned_pwritev(child, req, offset, align, align, + &local_qiov, 0, + flags & ~BDRV_REQ_ZERO_WRITE); + } else { + int64_t write_bytes =3D total_length - offset; + qemu_iovec_init_buf(&local_qiov, pad.tail_buf, write_bytes); + ret =3D bdrv_aligned_pwritev(child, req, offset, write_bytes, + bs->bl.request_alignment, &local_qi= ov, 0, + flags & ~BDRV_REQ_ZERO_WRITE); + } } =20 out: --=20 2.47.3 From nobody Mon Feb 9 05:55:23 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1767960652417722.2106977922062; Fri, 9 Jan 2026 04:10:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1veBJk-0006DA-Ft; Fri, 09 Jan 2026 07:10:12 -0500 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 1veBIY-0005ap-2u; Fri, 09 Jan 2026 07:09:00 -0500 Received: from proxmox-new.maurer-it.com ([94.136.29.106]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1veBIW-00018J-GB; Fri, 09 Jan 2026 07:08:57 -0500 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 523AA48FB3; Fri, 09 Jan 2026 13:08:43 +0100 (CET) From: Fiona Ebner To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, fam@euphon.net, stefanha@redhat.com Subject: [PATCH 6/6] block/io: keep zero flag for head/tail parts of misaligned zero write when possible Date: Fri, 9 Jan 2026 13:08:33 +0100 Message-ID: <20260109120837.2772961-7-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260109120837.2772961-1-f.ebner@proxmox.com> References: <20260109120837.2772961-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1767960482599 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 (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=94.136.29.106; envelope-from=f.ebner@proxmox.com; helo=proxmox-new.maurer-it.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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-ZM-MESSAGEID: 1767960654485158500 Content-Type: text/plain; charset="utf-8" This fixes io-test 179 with qcow2. Otherwise, there would be more 'data' sectors. Signed-off-by: Fiona Ebner --- Not sure if we should even attempt this without considering detect-zeroes. While it does keep 179 working, it is a change in behavior, since it could turn previously data sectors (with zeroes) into zero sectors when they are part of the head or tail of a zero write. Would it even be tolerable from a performance perspective? Remaining test failures after this patch are: 154 177 204 271 177 and 204 use opt-write-zero=3D15M with blkdebug, making an is_power_of_2(align) assertion fail. Changes in the output of 154 and 271 might be expected, but I didn't look into it in detail yet, as I wanted to discuss everything first. block/io.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/block/io.c b/block/io.c index d92b30bce5..34b523c951 100644 --- a/block/io.c +++ b/block/io.c @@ -2179,10 +2179,14 @@ bdrv_co_do_zero_pwritev(BdrvChild *child, int64_t o= ffset, int64_t bytes, int64_t write_bytes =3D pad.merge_reads ? pad.buf_len : align; =20 if (total_length >=3D aligned_offset + write_bytes) { + BdrvRequestFlags head_flags =3D + buffer_is_zero(pad.buf, write_bytes) ? + flags : flags & ~BDRV_REQ_ZERO_WRITE; + qemu_iovec_init_buf(&local_qiov, pad.buf, write_bytes); ret =3D bdrv_aligned_pwritev(child, req, aligned_offset, write_bytes, align, &local_qiov= , 0, - flags & ~BDRV_REQ_ZERO_WRITE); + head_flags); } else { write_bytes =3D total_length - aligned_offset; qemu_iovec_init_buf(&local_qiov, pad.buf, write_bytes); @@ -2220,10 +2224,13 @@ bdrv_co_do_zero_pwritev(BdrvChild *child, int64_t o= ffset, int64_t bytes, if (total_length >=3D offset + align) { assert(align =3D=3D pad.tail + bytes); =20 + BdrvRequestFlags tail_flags =3D + buffer_is_zero(pad.tail_buf + bytes, pad.tail) ? + flags : flags & ~BDRV_REQ_ZERO_WRITE; + qemu_iovec_init_buf(&local_qiov, pad.tail_buf, align); ret =3D bdrv_aligned_pwritev(child, req, offset, align, align, - &local_qiov, 0, - flags & ~BDRV_REQ_ZERO_WRITE); + &local_qiov, 0, tail_flags); } else { int64_t write_bytes =3D total_length - offset; qemu_iovec_init_buf(&local_qiov, pad.tail_buf, write_bytes); --=20 2.47.3