From nobody Mon Nov 23 04:26: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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793133816; cv=none; d=zohomail.com; s=zohoarc; b=dxs7RZbUSxT3525XD9Rr0hWUhwR5pRVdhrZnnBBsiWGs55fVwCbe3Aw3oq5Jw0uE7fQifVabjRUvs98i0KzC6YWIIfEposw5EpGzXSfl2ryDuqO9lJmlrSa3bf/bXaaAunKJn71+hhlCY+py/gcsrEDKXqHkFbPCHjbvpDFop8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793133816; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FuqqbT/Qb7zoiD/kCKmaVZ0FPJac9h+BFWocoh4j6KA=; b=K+qGrkUaPW06h2cla+V6mpx7Yt0JgeGDwbWH+GG7VRQhulx4zNR8+hRAuui00ZJTFMhKS+9AsBlJhsqabaFd7ZEWNmM+g4OmbwYm55q2POf61/CS0CV5Z5v9gBoWAFgt0hg9kSDtqaJn9LkRpVHEjpCmsI+tKBd+6Gll6rm77ag= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793133816776260.6720861116829; Tue, 27 Oct 2026 13:43:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLnyD-0000p4-82; Tue, 27 Oct 2026 16:40:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxS-0000lG-Q6 for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:39:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxQ-0001KE-V6 for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:39:46 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-164-k-8CfBwiODK--VoMTFc4vA-1; Tue, 27 Oct 2026 16:39:40 -0400 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 585C31805A22; Tue, 27 Oct 2026 20:39:38 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5AFF8410; Tue, 27 Oct 2026 20:39:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793133584; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FuqqbT/Qb7zoiD/kCKmaVZ0FPJac9h+BFWocoh4j6KA=; b=hWFxfrWPlMaHv8vVsFQPkC4pSPp+2l22SXI1EmJ/jP8wLd9QNdmOAeIQcnVpDCmCz8Eecr MjlyE1CUJMTMiT/xBwqCKBy4pQJZsP4E5stKCHk3DLKEEG4aUZXosfG43F4ZwRLwmdl9TK zht82dULK27rjFtLL8bD8wUUDqlPHw4= X-MC-Unique: k-8CfBwiODK--VoMTFc4vA-1 X-Mimecast-MFC-AGG-ID: k-8CfBwiODK--VoMTFc4vA_1793133578 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, John Snow , Kevin Wolf , Fam Zheng , Hanna Reitz , Paolo Bonzini , Richard Henderson , Stefan Hajnoczi , "Denis V. Lunev" , "Michael S. Tsirkin" , Zhao Liu , Sam Li , Niklas Cassel , Damien Le Moal Subject: [PULL 01/15] block: widen BlockLimits.zone_size to uint64_t Date: Tue, 27 Oct 2026 16:39:19 -0400 Message-ID: <20261027203933.1066759-2-stefanha@redhat.com> In-Reply-To: <20261027203933.1066759-1-stefanha@redhat.com> References: <20261027203933.1066759-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1793133820395154100 Content-Type: text/plain; charset="utf-8" From: Sam Li The zone-size field in BlockLimits is currently uint32_t, capping expressible zone sizes at 4 GiB. Real zoned-device protocols like NVMe ZNS allow larger zones. Widen BlockLimits.zone_size to uint64_t to match. Signed-off-by: Sam Li Reviewed-by: Niklas Cassel Reviewed-by: Damien Le Moal Reviewed-by: Stefan Hajnoczi Signed-off-by: Niklas Cassel Message-id: 20260921142819.2916043-2-cassel@kernel.org Signed-off-by: Stefan Hajnoczi --- include/block/block_int-common.h | 2 +- block/file-posix.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 46428b034de..b227ff34a18 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -902,7 +902,7 @@ typedef struct BlockLimits { BlockZoneModel zoned; =20 /* zone size expressed in bytes */ - uint32_t zone_size; + uint64_t zone_size; =20 /* total number of zones */ uint32_t nr_zones; diff --git a/block/file-posix.c b/block/file-posix.c index df117f35d48..df8ca4e88fa 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3617,7 +3617,7 @@ raw_co_zone_append(BlockDriverState *bs, =20 if (*offset & zone_size_mask) { error_report("sector offset %" PRId64 " is not aligned to zone siz= e " - "%" PRId32 "", *offset / 512, bs->bl.zone_size / 512); + "%" PRId64 "", *offset / 512, bs->bl.zone_size / 512); return -EINVAL; } =20 --=20 2.56.0 From nobody Mon Nov 23 04:26: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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793133724; cv=none; d=zohomail.com; s=zohoarc; b=BPjMRNsrAQ2sWNrXrHSXu6Q8KwR63TZkQmO7A9rogNu81sMY4j2v/1AG7DiZM4codih1P8bFgIWQH+0nDZWvvMYay/lagtdAweqcFnb8LaGICz7SoEWqBBMb2ICKTF7Py/oLnmzpbwEcq2mNKtQaMJ1vWR9Hr1FIXDMes132JDg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793133724; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=192uo9pJRsKjpc3lV3ag5nABiqacxI3OK+S+aFEHGMg=; b=fPJebicgzL/k9Aap9asZBE3KudTxeCTH1O3tPFGn6C/VG3FfA/87nWBIIQiabnkRlbHXVCx3zDdndgUVBq2pGDNF8FNNVppFVbKUpmdcEabSQtTodaZWNfs9Aubm5A+YdjEvTZxPbSbkxbFoq76b/icDARVfDZTWP5qavIa/47k= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793133724758364.33100340259364; Tue, 27 Oct 2026 13:42:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLnyz-0001PV-Jz; Tue, 27 Oct 2026 16:41:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxY-0000m5-V7 for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:39:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxV-0001Kq-Ir for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:39:52 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-462-4wOZ0eNvMqOUKG_8mIO4tw-1; Tue, 27 Oct 2026 16:39:43 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2C51A180063B; Tue, 27 Oct 2026 20:39:41 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2C2C41955F01; Tue, 27 Oct 2026 20:39:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793133588; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=192uo9pJRsKjpc3lV3ag5nABiqacxI3OK+S+aFEHGMg=; b=QjaNQwMi39LUqtl4pvVLwZbzQCiZ3meMZTtsDAYfXx9xJq8q9mOWdbl83c3xlcQS5CnNtX eX1e52VdCbUhqodpJ2+2ab+VupYsVaU/vY63TlwoYufwHqv+yBZWdZSmbNnepA56lRgM5j xz/QcfVl1yuPm/9KZon1iPlmgJZBQJs= X-MC-Unique: 4wOZ0eNvMqOUKG_8mIO4tw-1 X-Mimecast-MFC-AGG-ID: 4wOZ0eNvMqOUKG_8mIO4tw_1793133581 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, John Snow , Kevin Wolf , Fam Zheng , Hanna Reitz , Paolo Bonzini , Richard Henderson , Stefan Hajnoczi , "Denis V. Lunev" , "Michael S. Tsirkin" , Zhao Liu , Sam Li , Damien Le Moal , Niklas Cassel Subject: [PULL 02/15] virtio-blk: do not merge requests across a zone boundary Date: Tue, 27 Oct 2026 16:39:20 -0400 Message-ID: <20261027203933.1066759-3-stefanha@redhat.com> In-Reply-To: <20261027203933.1066759-1-stefanha@redhat.com> References: <20261027203933.1066759-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1793133814025158500 Content-Type: text/plain; charset="utf-8" From: Sam Li virtio_blk_submit_multireq() fuses adjacent in-zone requests into a single request. On a zoned backend, a merged zone append request that straddles a zone boundary is rejected by the device because each write/read must stay within a single zone (virtio 1.4, 5.2.6.1). Add a bail condition to the merge coalescer: if combining the candidate request into the current batch would cross a zone boundary, flush the current batch and start a new one. Signed-off-by: Sam Li Reviewed-by: Damien Le Moal Reviewed-by: Stefan Hajnoczi Reviewed-by: Niklas Cassel Signed-off-by: Niklas Cassel Message-id: 20260921142819.2916043-3-cassel@kernel.org Signed-off-by: Stefan Hajnoczi --- include/system/block-backend-io.h | 1 + block/block-backend.c | 11 +++++++++++ hw/block/virtio-blk.c | 22 +++++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/system/block-backend-io.h b/include/system/block-backe= nd-io.h index fd84723d9d0..78d410b8df0 100644 --- a/include/system/block-backend-io.h +++ b/include/system/block-backend-io.h @@ -121,6 +121,7 @@ uint32_t blk_get_request_alignment(BlockBackend *blk); uint32_t blk_get_pwrite_zeroes_alignment(BlockBackend *blk); uint32_t blk_get_max_transfer(BlockBackend *blk); uint64_t blk_get_max_hw_transfer(BlockBackend *blk); +uint64_t blk_get_zone_size(BlockBackend *blk); =20 int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, BlockBackend *blk_out, int64_t off_out, diff --git a/block/block-backend.c b/block/block-backend.c index ab837fac921..656c0aed679 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2327,6 +2327,17 @@ uint32_t blk_get_request_alignment(BlockBackend *blk) return bs ? bs->bl.request_alignment : BDRV_SECTOR_SIZE; } =20 +/* + * Returns the zone size in bytes for a zoned backend, or 0 if @blk does + * not present zoned geometry. + */ +uint64_t blk_get_zone_size(BlockBackend *blk) +{ + BlockDriverState *bs =3D blk_bs(blk); + IO_CODE(); + return bs ? bs->bl.zone_size : 0; +} + /* Returns the optimal write zeroes alignment, in bytes; guaranteed nonzer= o */ uint32_t blk_get_pwrite_zeroes_alignment(BlockBackend *blk) { diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 61c341ce2c9..1b93364b241 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -288,6 +288,9 @@ static void virtio_blk_submit_multireq(VirtIOBlock *s, = MultiReqBuffer *mrb) int i =3D 0, start =3D 0, num_reqs =3D 0, niov =3D 0, nb_sectors =3D 0; uint32_t max_transfer; int64_t sector_num =3D 0; + uint64_t zone_size =3D blk_get_zone_size(s->blk); + bool zone_cross; + int64_t zone_nr_sectors, end_sector; =20 if (mrb->num_reqs =3D=3D 1) { submit_requests(s, mrb, 0, 1, -1); @@ -303,17 +306,34 @@ static void virtio_blk_submit_multireq(VirtIOBlock *s= , MultiReqBuffer *mrb) for (i =3D 0; i < mrb->num_reqs; i++) { VirtIOBlockReq *req =3D mrb->reqs[i]; if (num_reqs > 0) { + /* + * On zoned backends, a single backend write/read must not span + * a zone boundary. Bail out of merging if combining req into + * the current batch would straddle a zone. + */ + if (zone_size > 0) { + zone_nr_sectors =3D zone_size / BDRV_SECTOR_SIZE; + end_sector =3D req->sector_num + + req->qiov.size / BDRV_SECTOR_SIZE - 1; + zone_cross =3D (sector_num / zone_nr_sectors) !=3D + (end_sector / zone_nr_sectors); + } else { + zone_cross =3D false; + } + /* * NOTE: We cannot merge the requests in below situations: * 1. requests are not sequential * 2. merge would exceed maximum number of IOVs * 3. merge would exceed maximum transfer length of backend de= vice + * 4. merge would cross a zone boundary on a zoned backend */ if (sector_num + nb_sectors !=3D req->sector_num || niov > blk_get_max_iov(s->blk) - req->qiov.niov || req->qiov.size > max_transfer || nb_sectors > (max_transfer - - req->qiov.size) / BDRV_SECTOR_SIZE) { + req->qiov.size) / BDRV_SECTOR_SIZE || + zone_cross) { submit_requests(s, mrb, start, num_reqs, niov); num_reqs =3D 0; } --=20 2.56.0 From nobody Mon Nov 23 04:26: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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793133753; cv=none; d=zohomail.com; s=zohoarc; b=MphA6GMPvQdt1sjT9hMHIsqE7OoU2MmqIBMW/MM/xLgNiyHqOVVFnaJcMy8u0pH0y4omqIlF261xGk8nSYNizrJ5dZCTiDUCH1rvLCzH3yw+Q11C4vqqYCb/KqS0SGoCDfvKLvzBimtIXGioQkhHs/64Ho4ERbShS6+Dv2J9z5o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793133753; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eLSSlJ1CgpTt9MxuxIIYC5FXdpNjI621JSB6rwqUW9k=; b=DOQsyt3RGyzHp2sn6MzZLI6S3Sray9OrtnllOsiEemi/5haGiDN/2bRwzI3q0/fbuisx16GPPFW3PRRicgCVxo/kvCQpxQJ74ZZmORGoN65BUCGgt/MMi5rZbNFbRetbFGyeoLT9sgW4CKvsj3sylJb+VNV4ZLqGtWwSD/KkMpQ= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793133753818835.1731735396562; Tue, 27 Oct 2026 13:42:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLnz1-0001Ul-7b; Tue, 27 Oct 2026 16:41:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLny4-0000rf-Uv for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLny0-0001Z4-QF for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:24 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-452-BM-rGxJIPVyaagOsaoygnw-1; Tue, 27 Oct 2026 16:39:52 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A549919541B4; Tue, 27 Oct 2026 20:39:42 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2B31C19560AB; Tue, 27 Oct 2026 20:39:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793133608; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eLSSlJ1CgpTt9MxuxIIYC5FXdpNjI621JSB6rwqUW9k=; b=ZW89oBnWbjG2Gfly91FvcUg7p2A4eSiUaUrrUC+lZEc+3xdTQokdhgfW2G/ZwTuJxTzD85 B7qNAtEI2871P7KnXoLyrLcsPw9GlJxqUGrvloE0Gj6YUhnf+QZKihlRq5oU9NyIV7qY0E 7XXwlS/nTJIQZteJ9UQGUlqICvg5Jjo= X-MC-Unique: BM-rGxJIPVyaagOsaoygnw-1 X-Mimecast-MFC-AGG-ID: BM-rGxJIPVyaagOsaoygnw_1793133583 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, John Snow , Kevin Wolf , Fam Zheng , Hanna Reitz , Paolo Bonzini , Richard Henderson , Stefan Hajnoczi , "Denis V. Lunev" , "Michael S. Tsirkin" , Zhao Liu , Niklas Cassel , Damien Le Moal Subject: [PULL 03/15] block: add a helper for the index of the zone an offset falls in Date: Tue, 27 Oct 2026 16:39:21 -0400 Message-ID: <20261027203933.1066759-4-stefanha@redhat.com> In-Reply-To: <20261027203933.1066759-1-stefanha@redhat.com> References: <20261027203933.1066759-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1793133755450154100 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel Deriving the zone that an offset belongs to is open coded in five places, in two files, as a division of the offset by BlockLimits.zone_size. The zone size of a zoned device is always a power of two. Linux requires that of every zoned device it accepts, in blk_revalidate_disk_zones() and in each of the drivers that report one, and qcow2 rejects an image whose header says otherwise. So the division is a shift, and the shift is worth deriving once rather than at every use: record it in BlockLimits as zone_size_bits, next to the size it comes from, and assert the property that it relies on where it is computed. Add bdrv_zone_index() and use it. No functional change; the count of zones that a management operation spans stays a division, since it is a length rather than an offset. Reviewed-by: Damien Le Moal Reviewed-by: Stefan Hajnoczi Signed-off-by: Niklas Cassel Message-id: 20260921142819.2916043-4-cassel@kernel.org Signed-off-by: Stefan Hajnoczi --- include/block/block-io.h | 2 ++ include/block/block_int-common.h | 7 +++++++ block/file-posix.c | 8 ++++---- block/io.c | 12 ++++++++++++ hw/block/virtio-blk.c | 2 +- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index d34d846bb2a..9d1c0eb7fbc 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -126,6 +126,8 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_append(Block= DriverState *bs, int64_t *offset, QEMUIOVector *qiov, BdrvRequestFlags flags); +/* The index of the zone that @offset falls in. */ +uint32_t bdrv_zone_index(BlockDriverState *bs, uint64_t offset); =20 bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); =20 diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index b227ff34a18..3b18020b0e2 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -904,6 +904,13 @@ typedef struct BlockLimits { /* zone size expressed in bytes */ uint64_t zone_size; =20 + /* + * log2 of zone_size, derived by bdrv_refresh_limits(). A zoned device + * always has a zone size that is a power of two, so the zone an offset + * falls in is a shift rather than a division. See bdrv_zone_index(). + */ + uint32_t zone_size_bits; + /* total number of zones */ uint32_t nr_zones; =20 diff --git a/block/file-posix.c b/block/file-posix.c index df8ca4e88fa..48ae785639e 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1379,7 +1379,7 @@ static int get_zones_wp(BlockDriverState *bs, int fd,= int64_t offset, size_t rep_size; uint64_t sector =3D offset >> BDRV_SECTOR_BITS; BlockZoneWps *wps =3D bs->wps; - unsigned int j =3D offset / bs->bl.zone_size; + unsigned int j =3D bdrv_zone_index(bs, offset); unsigned int n =3D 0, i =3D 0; int ret; rep_size =3D sizeof(struct blk_zone_report) + nrz * sizeof(struct blk_= zone); @@ -2579,7 +2579,7 @@ raw_co_prw(BlockDriverState *bs, int64_t *offset_ptr,= uint64_t bytes, bs->bl.zoned !=3D BLK_Z_NONE) { qemu_co_mutex_lock(&bs->wps->colock); if (type & QEMU_AIO_ZONE_APPEND) { - int index =3D offset / bs->bl.zone_size; + int index =3D bdrv_zone_index(bs, offset); offset =3D bs->wps->wp[index]; } } @@ -2634,7 +2634,7 @@ out: bs->bl.zoned !=3D BLK_Z_NONE) { BlockZoneWps *wps =3D bs->wps; if (ret =3D=3D 0) { - uint64_t *wp =3D &wps->wp[offset / bs->bl.zone_size]; + uint64_t *wp =3D &wps->wp[bdrv_zone_index(bs, offset)]; if (!BDRV_ZT_IS_CONV(*wp)) { if (type & QEMU_AIO_ZONE_APPEND) { *offset_ptr =3D *wp; @@ -3532,7 +3532,7 @@ static int coroutine_fn raw_co_zone_mgmt(BlockDriverS= tate *bs, BlockZoneOp op, return -EINVAL; } =20 - uint32_t i =3D offset / bs->bl.zone_size; + uint32_t i =3D bdrv_zone_index(bs, offset); uint32_t nrz =3D len / bs->bl.zone_size; uint64_t *wp =3D &wps->wp[i]; if (BDRV_ZT_IS_CONV(*wp) && len !=3D capacity) { diff --git a/block/io.c b/block/io.c index 1c05dd106d6..8ba0b3c9626 100644 --- a/block/io.c +++ b/block/io.c @@ -230,6 +230,11 @@ void bdrv_refresh_limits(BlockDriverState *bs, Transac= tion *tran, Error **errp) } } =20 + if (bs->bl.zone_size) { + assert(is_power_of_2(bs->bl.zone_size)); + bs->bl.zone_size_bits =3D ctz64(bs->bl.zone_size); + } + if (bs->bl.request_alignment > BDRV_MAX_ALIGNMENT) { error_setg(errp, "Driver requires too large request alignment"); } @@ -3366,6 +3371,13 @@ out: return co.ret; } =20 +uint32_t bdrv_zone_index(BlockDriverState *bs, uint64_t offset) +{ + IO_CODE(); + + return offset >> bs->bl.zone_size_bits; +} + void *qemu_blockalign(BlockDriverState *bs, size_t size) { IO_CODE(); diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 1b93364b241..6e4a7a4076c 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -523,7 +523,7 @@ static bool check_zoned_request(VirtIOBlock *s, int64_t= offset, int64_t len, } } =20 - index =3D offset / bs->bl.zone_size; + index =3D bdrv_zone_index(bs, offset); if (BDRV_ZT_IS_CONV(bs->wps->wp[index])) { *status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; return false; --=20 2.56.0 From nobody Mon Nov 23 04:26: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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793133669; cv=none; d=zohomail.com; s=zohoarc; b=aEuW8qJsMEE2RFpWpivxXK+GiBzD3vAXilwmvx4KVEe/PuMuJSlCs3/+G9C2akZFHUWotcSbxd13qAQjsp2qlFh+5bw49oLSRwygeL1qWoEM/ce6utiT6m+M2gfXIceKQWCRkTmUlrZ4ghJTf72aTFYgmeTwCP+dqSbFf9wwuuw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793133669; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Lk5+7UNA+reYS/eYjIEoN9VAHU4As+vDYwlwHo+VTic=; b=ehJD150jGPxfoOB93LjsJVos+yFXBMagIZspRZ5kOhepBt/spyH9RHp8z9y15mlT6dTYifJUfwhBHY1i7HGsRUg+mePzOPiw8Kr23xwR2pCwLXtVlIyxHTzoPCK48FPLNES05KPQMyKYkcQRz+4UzYPHgreCrMjzzq96fSn8VtY= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793133669095749.7156047881225; Tue, 27 Oct 2026 13:41:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLnyM-000137-Sb; Tue, 27 Oct 2026 16:40:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxa-0000mF-HV for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:39:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxW-0001Kx-JL for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:39:53 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-84-v_lb7_pKPsuXyGKIxjZzSw-1; Tue, 27 Oct 2026 16:39:45 -0400 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EC6D1180058F; Tue, 27 Oct 2026 20:39:43 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8759E410; Tue, 27 Oct 2026 20:39:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793133589; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lk5+7UNA+reYS/eYjIEoN9VAHU4As+vDYwlwHo+VTic=; b=OnwcWIkfvp4ZJp3TLiLGx4AWZl3un+4ZX6QVRWYwgzuv/b1nwOi5C8Rm9ixzWchgrL34Lx esqkTKTxON2ve58JsAEkWR0TcBNUVgKAgk+DypKmEq7odqbpppB68au4nXOHIA0eQ/7xoX fedMCDDIgYELAKn7MjwG38wAmmfjN9I= X-MC-Unique: v_lb7_pKPsuXyGKIxjZzSw-1 X-Mimecast-MFC-AGG-ID: v_lb7_pKPsuXyGKIxjZzSw_1793133584 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, John Snow , Kevin Wolf , Fam Zheng , Hanna Reitz , Paolo Bonzini , Richard Henderson , Stefan Hajnoczi , "Denis V. Lunev" , "Michael S. Tsirkin" , Zhao Liu , Niklas Cassel Subject: [PULL 04/15] block: add a helper to check if a zone is conventional Date: Tue, 27 Oct 2026 16:39:22 -0400 Message-ID: <20261027203933.1066759-5-stefanha@redhat.com> In-Reply-To: <20261027203933.1066759-1-stefanha@redhat.com> References: <20261027203933.1066759-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1793133783848158500 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel Whether a zone is conventional is encoded in the most significant bit of the write pointer that the block layer keeps for it, so a caller that wants to know has to reach into bs->wps->wp[] and apply BDRV_ZT_IS_CONV() to the raw value. virtio-blk does that, which means a device model both knows how a block driver stores its write pointers and knows what one of the bits of a write pointer means. Add an accessor next to bdrv_zone_index() and use it there, so that the encoding stays with the code that chose it. Unlike bdrv_zone_is_full(), this does not need the write pointer lock. get_zones_wp() only ever sets the bit for a conventional zone and never clears it, and a zone does not change type, so the answer cannot become stale. The rest of the word does change, on every write, which is what the lock is there for. Signed-off-by: Niklas Cassel Reviewed-by: Stefan Hajnoczi Message-id: 20260921142819.2916043-5-cassel@kernel.org Signed-off-by: Stefan Hajnoczi --- include/block/block-io.h | 6 ++++++ block/io.c | 7 +++++++ hw/block/virtio-blk.c | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 9d1c0eb7fbc..e469df70610 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -128,6 +128,12 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_zone_append(Bloc= kDriverState *bs, BdrvRequestFlags flags); /* The index of the zone that @offset falls in. */ uint32_t bdrv_zone_index(BlockDriverState *bs, uint64_t offset); +/* + * True if the zone at @index is a conventional zone, which can be written + * anywhere in any order. The type of a zone does not change, so unlike + * bdrv_zone_is_full() this does not need the write pointer lock. + */ +bool bdrv_zone_is_conv(BlockDriverState *bs, uint32_t index); =20 bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); =20 diff --git a/block/io.c b/block/io.c index 8ba0b3c9626..d08956105c2 100644 --- a/block/io.c +++ b/block/io.c @@ -3378,6 +3378,13 @@ uint32_t bdrv_zone_index(BlockDriverState *bs, uint6= 4_t offset) return offset >> bs->bl.zone_size_bits; } =20 +bool bdrv_zone_is_conv(BlockDriverState *bs, uint32_t index) +{ + IO_CODE(); + + return BDRV_ZT_IS_CONV(bs->wps->wp[index]); +} + void *qemu_blockalign(BlockDriverState *bs, size_t size) { IO_CODE(); diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 6e4a7a4076c..dd69d81532b 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -524,7 +524,7 @@ static bool check_zoned_request(VirtIOBlock *s, int64_t= offset, int64_t len, } =20 index =3D bdrv_zone_index(bs, offset); - if (BDRV_ZT_IS_CONV(bs->wps->wp[index])) { + if (bdrv_zone_is_conv(bs, index)) { *status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; return false; } --=20 2.56.0 From nobody Mon Nov 23 04:26: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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793133842; cv=none; d=zohomail.com; s=zohoarc; b=AVYZ4Y78kLf+8vFCq8ML8SIE4TewCcWjXQcLaMK6y+xZDRqgexcv+DlNazxCkmVqzZLBs1O4WAY1xUyo9WBPhD2u0xjCK11fR3OKAbqhVRvAiZDuqwBiFvvcoADIkaW60CbxjfTxhz8ad3Ku0cF5+QioNLyHz0lC3cjONuUKHAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793133842; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KcIFDcxpLOa3PWGu17Hawki8OcyS3NYrE1SmCG+JiY4=; b=FwKysCcArNev75LXjG2vl74rE2p4zYpQHfiqPYS0JPpnrsJNywweqziZaPd+eB/QwZStgPopHVOyfoDQlv7OuFKa0Lc6fj7p/kjrFTadp2mg5+ZUGkroiaRxFBo8owt5dUgrATpkerxnWD01BDIrybZANObBvxpCeiLtU+2Fm/s= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793133841922758.0503152002541; Tue, 27 Oct 2026 13:44:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLnyy-0001Kx-0j; Tue, 27 Oct 2026 16:41:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxg-0000n8-Bb for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxa-0001LU-Bf for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:39:59 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-UZeXVWDrN9eYswMQxrSMcg-1; Tue, 27 Oct 2026 16:39:47 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B56FE1805A11; Tue, 27 Oct 2026 20:39:45 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 07B2E1803A55; Tue, 27 Oct 2026 20:39:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793133592; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KcIFDcxpLOa3PWGu17Hawki8OcyS3NYrE1SmCG+JiY4=; b=WYowhQQ327kvFJjpNTgkXMpVl9+xxVZQqezz+L9zufKdpeYlfYIVYnakzB3X+bdWKyGpw1 gDlx4/LTOq3U6y67AM3TnN82SFvaiXCB8frVxEao+7BUCv9zU/ByTBDUowyKRxGM7k03yb IT/vwmabU2ZF95x5NlOqoQ4rY4OtXuI= X-MC-Unique: UZeXVWDrN9eYswMQxrSMcg-1 X-Mimecast-MFC-AGG-ID: UZeXVWDrN9eYswMQxrSMcg_1793133586 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, John Snow , Kevin Wolf , Fam Zheng , Hanna Reitz , Paolo Bonzini , Richard Henderson , Stefan Hajnoczi , "Denis V. Lunev" , "Michael S. Tsirkin" , Zhao Liu , Niklas Cassel Subject: [PULL 05/15] hw/block: derive the zone write granularity from the block sizes Date: Tue, 27 Oct 2026 16:39:23 -0400 Message-ID: <20261027203933.1066759-6-stefanha@redhat.com> In-Reply-To: <20261027203933.1066759-1-stefanha@redhat.com> References: <20261027203933.1066759-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1793134088157158500 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel For ZBC/ZAC devices the write granularity is the physical block size, so a 512e SMR disk exposed through a host_device backend has a logical block size of 512 and a zone write granularity of 4096. We told the guest driver 512 while raw_co_zone_append() rejects anything that is not 4096 byte aligned, so the driver saw a plain I/O error for a request it had been told was valid. Report the larger of the logical and the physical block size instead. Both are properties of the device model, so the value that a guest is given does not change when it is migrated to a host whose disks differ, which a value taken from BlockLimits would. It is also what a guest derives for itself: blk_validate_zoned_limits() raises zone_write_granularity to the logical block size, and for a SCSI disk sd_zbc_read_zones() takes it from the physical block size. blkconf_blocksizes() rejects a logical block size larger than the physical block size, so this is the physical block size in practice. It is expressed as the larger of the two because that is the constraint which applies: a guest cannot issue a write finer than the logical block size, and the medium cannot take one finer than the physical block size. Add it as a helper next to blkconf_blocksizes(), since it is derived from a BlockConf, and use it for the zone append offset check in check_zoned_request(), which validated against bs->bl.write_granularity. The value reported to the driver and the value that requests are validated against then cannot drift apart. The helper cannot return zero because blkconf_blocksizes() always leaves a logical block size behind, so the check no longer needs to guard against an unset granularity. Fixes: 4f7366506a96 ("virtio-blk: add zoned storage emulation for zoned dev= ices") Signed-off-by: Niklas Cassel Reviewed-by: Stefan Hajnoczi Message-id: 20260921142819.2916043-6-cassel@kernel.org Signed-off-by: Stefan Hajnoczi --- include/block/block_int-common.h | 7 +++++++ include/hw/block/block.h | 13 +++++++++++++ hw/block/block.c | 5 +++++ hw/block/virtio-blk.c | 13 +++++++------ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 3b18020b0e2..6bfdcbfe86b 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -923,6 +923,13 @@ typedef struct BlockLimits { /* maximum number of active zones */ uint32_t max_active_zones; =20 + /* + * The granularity that the backend requires of a write to a sequential + * zone, in bytes, or zero if it has none. This describes the host, so= it + * must not be reported to a guest: a frontend reports + * blkconf_zone_write_granularity() and checks this against it when the + * device is realized. + */ uint32_t write_granularity; } BlockLimits; =20 diff --git a/include/hw/block/block.h b/include/hw/block/block.h index df941df19f2..c769b1297d0 100644 --- a/include/hw/block/block.h +++ b/include/hw/block/block.h @@ -114,6 +114,19 @@ bool blkconf_geometry(BlockConf *conf, int *trans, unsigned cyls_max, unsigned heads_max, unsigned secs= _max, Error **errp); bool blkconf_blocksizes(BlockConf *conf, Error **errp); +/* + * The alignment constraint that applies to writes to a sequential zone. A= guest + * cannot issue a write finer than the logical block size, and the medium = cannot + * take one finer than the physical block size, so the constraint that app= lies + * is the larger of the two. A frontend must report this value to its gues= t and + * validate requests against it. + * + * It is derived from the configuration and not from the backend, so that a + * guest is not given a property of the host, which would differ after + * migration. blkconf_blocksizes() rejects a logical block size larger tha= n the + * physical block size, so this is the physical block size in practice. + */ +uint32_t blkconf_zone_write_granularity(BlockConf *conf); bool blkconf_apply_backend_options(BlockConf *conf, bool readonly, bool resizable, Error **errp); =20 diff --git a/hw/block/block.c b/hw/block/block.c index f187fa025d0..79b0a67ceac 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -201,6 +201,11 @@ bool blkconf_blocksizes(BlockConf *conf, Error **errp) return true; } =20 +uint32_t blkconf_zone_write_granularity(BlockConf *conf) +{ + return MAX(conf->logical_block_size, conf->physical_block_size); +} + bool blkconf_apply_backend_options(BlockConf *conf, bool readonly, bool resizable, Error **errp) { diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index dd69d81532b..6bf1049aea3 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -516,11 +516,11 @@ static bool check_zoned_request(VirtIOBlock *s, int64= _t offset, int64_t len, } =20 if (append) { - if (bs->bl.write_granularity) { - if ((offset % bs->bl.write_granularity) !=3D 0) { - *status =3D VIRTIO_BLK_S_ZONE_UNALIGNED_WP; - return false; - } + uint32_t wg_mask =3D blkconf_zone_write_granularity(&s->conf.conf)= - 1; + + if (offset & wg_mask) { + *status =3D VIRTIO_BLK_S_ZONE_UNALIGNED_WP; + return false; } =20 index =3D bdrv_zone_index(bs, offset); @@ -1276,7 +1276,8 @@ static void virtio_blk_update_config(VirtIODevice *vd= ev, uint8_t *config) bs->bl.max_active_zones); virtio_stl_p(vdev, &blkcfg.zoned.max_open_zones, bs->bl.max_open_zones); - virtio_stl_p(vdev, &blkcfg.zoned.write_granularity, blk_size); + virtio_stl_p(vdev, &blkcfg.zoned.write_granularity, + blkconf_zone_write_granularity(conf)); virtio_stl_p(vdev, &blkcfg.zoned.max_append_sectors, bs->bl.max_append_sectors); } else { --=20 2.56.0 From nobody Mon Nov 23 04:26: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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793133709; cv=none; d=zohomail.com; s=zohoarc; b=LOczVBbphb6GED853DrJevtlwikASuMou9faqMvcoT3eoZJbju+0Ym6nGCbZjVdsph2To03Acogk8oCjCnRk1/cpiPojwWqTnKRHZ6QKEtrvdD9rd9N3UGpc1Qx1UnI/igdl0/Zkr0243vvgaLF4X+YQ6CvAlyvoWe2NbN9ultQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793133709; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=m9vo9JBWvkfZydeW5K4/98B6rpXrEYde1ttFxKhgWPM=; b=CZ5e+1E3QvGnsNfse2K224yvXfOFIPNZxN+aLV0/9Vrpubmt1p5Dh0swMn7RWs/zw9K69lHChd6bsX97EVDODIBWsgwgJwEl/02z52lntSfmZuGkRZdw5GrfAWvZB5xyJ1/Rw2SNpfzz1WO+cg8trn6t7mhV04qPhHAff7MSGBE= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793133709230543.6485203434544; Tue, 27 Oct 2026 13:41:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLnz2-0001X3-Sl; Tue, 27 Oct 2026 16:41:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxg-0000n7-9I for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxa-0001LK-Az for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:39:59 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-PN6aLR7cP8m6QIRLwzUBjg-1; Tue, 27 Oct 2026 16:39:48 -0400 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3A0CE1953945; Tue, 27 Oct 2026 20:39:47 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AF825410; Tue, 27 Oct 2026 20:39:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793133592; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m9vo9JBWvkfZydeW5K4/98B6rpXrEYde1ttFxKhgWPM=; b=U9C1hSAPYNKc3lNutcp7Xxt1+k8mA4zlBPrbKX3ZWhDKyXzsO1jTxX4ZGBZFRHv18yK7aA GQsNo2L/XTFVGsvbhflXBArRnOzRgkZY+VSVDNByA7jyqvFHwmqR5UH30TYz/4zEvl7opZ 2bNBEHTZT8eLSwD5RyZBjCtqYGtL5mI= X-MC-Unique: PN6aLR7cP8m6QIRLwzUBjg-1 X-Mimecast-MFC-AGG-ID: PN6aLR7cP8m6QIRLwzUBjg_1793133587 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, John Snow , Kevin Wolf , Fam Zheng , Hanna Reitz , Paolo Bonzini , Richard Henderson , Stefan Hajnoczi , "Denis V. Lunev" , "Michael S. Tsirkin" , Zhao Liu , Niklas Cassel , Damien Le Moal Subject: [PULL 06/15] virtio-blk: check the write granularity of writes to sequential zones Date: Tue, 27 Oct 2026 16:39:24 -0400 Message-ID: <20261027203933.1066759-7-stefanha@redhat.com> In-Reply-To: <20261027203933.1066759-1-stefanha@redhat.com> References: <20261027203933.1066759-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1793133710849154100 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel All VIRTIO_BLK_T_OUT requests issued to sequential zones and all VIRTIO_BLK_T_ZONE_APPEND requests must have an offset and a data size that are multiples of the write granularity reported by the device (virtio 1.4, 5.2.6.1), and a violation is reported as VIRTIO_BLK_S_ZONE_UNALIGNED_WP (virtio 1.4, 5.2.6). Neither request type was fully checked. Zone appends validated only the offset, while writes were not checked at all. Check the size of the appended data, and both the offset and the size of a write, against blkconf_zone_write_granularity(), so that every request the device accepts is one that the guest driver was told is valid. Writes to conventional zones keep no alignment constraint beyond the logical block size. The write path performs the check after virtio_blk_sect_range_ok() so that the zone index derived from the guest supplied sector is known to be in range. Reviewed-by: Damien Le Moal Reviewed-by: Stefan Hajnoczi Signed-off-by: Niklas Cassel Message-id: 20260921142819.2916043-7-cassel@kernel.org Signed-off-by: Stefan Hajnoczi --- hw/block/virtio-blk.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 6bf1049aea3..449de307b48 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -392,6 +392,33 @@ static bool virtio_blk_sect_range_ok(VirtIOBlock *dev, return true; } =20 +/* + * Both the offset and the size of a write to a sequential zone must be a + * multiple of the write granularity that the device reports. Conventional + * zones are not constrained. The zone index is derived from a guest suppl= ied + * sector, so this must only be called once virtio_blk_sect_range_ok() has + * bounded it. + */ +static bool virtio_blk_zone_write_granularity_ok(VirtIOBlock *dev, + uint64_t sector, size_t s= ize) +{ + BlockDriverState *bs =3D blk_bs(dev->blk); + uint64_t offset =3D sector << BDRV_SECTOR_BITS; + uint32_t wg_mask; + + if (bs->bl.zoned =3D=3D BLK_Z_NONE) { + return true; + } + + if (bdrv_zone_is_conv(bs, bdrv_zone_index(bs, offset))) { + return true; + } + + wg_mask =3D blkconf_zone_write_granularity(&dev->conf.conf) - 1; + + return !(offset & wg_mask) && !(size & wg_mask); +} + static uint8_t virtio_blk_handle_discard_write_zeroes(VirtIOBlockReq *req, struct virtio_blk_discard_write_zeroes *dwz_hdr, bool is_write_zeroes) { @@ -518,7 +545,7 @@ static bool check_zoned_request(VirtIOBlock *s, int64_t= offset, int64_t len, if (append) { uint32_t wg_mask =3D blkconf_zone_write_granularity(&s->conf.conf)= - 1; =20 - if (offset & wg_mask) { + if (offset & wg_mask || len & wg_mask) { *status =3D VIRTIO_BLK_S_ZONE_UNALIGNED_WP; return false; } @@ -913,6 +940,15 @@ static int virtio_blk_handle_request(VirtIOBlockReq *r= eq, MultiReqBuffer *mrb) return 0; } =20 + if (is_write && + !virtio_blk_zone_write_granularity_ok(s, req->sector_num, + req->qiov.size)) { + virtio_blk_req_complete(req, VIRTIO_BLK_S_ZONE_UNALIGNED_WP); + block_acct_invalid(blk_get_stats(s->blk), BLOCK_ACCT_WRITE); + g_free(req); + return 0; + } + block_acct_start(blk_get_stats(s->blk), &req->acct, req->qiov.size, is_write ? BLOCK_ACCT_WRITE : BLOCK_ACCT_READ); =20 --=20 2.56.0 From nobody Mon Nov 23 04:26: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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793133764; cv=none; d=zohomail.com; s=zohoarc; b=I+ZL7eiNGzFzCZ3c7PPxlxkEcfWbaqaPG6WOHcG5o+IvY8JeFOxiFkszcU33zCeZuWkhNpLbt5keTX3SVWFQh01s7qHWVcRV5X+phXyvv3JZwJ7RxWvjNtXM4Qvheg50+mHKaN7BZZ4omoUriOqAcqpK4F8teFT0Cknroj658TA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793133764; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yl1/L+LrMZiPUlKrujB3h30/6c8TEokqGisM1A3PNRQ=; b=WaNPAm7TsLN4Ck5dHlikkSgiM1G3+fAX470MWb72Z+sXpPnMq6nIZ5zajzUu3IUPYnGANy5+aRPzJc9yqE3pQtM6V8eL0e5JNnZ7Ha68Hd5Scb/FOwp/EvVhrRAU2QKqbXPDUGgsdkVZHZoknflhHrKQ1GADUkRPVqhPJnJ6UyQ= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793133764203885.4343221738707; Tue, 27 Oct 2026 13:42:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLnyz-0001PT-FI; Tue, 27 Oct 2026 16:41:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxr-0000pI-Ti for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxe-0001Ll-4Z for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:00 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-686-3EWI2mV5OdmlAzK3pM7abA-1; Tue, 27 Oct 2026 16:39:50 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3660B195421E; Tue, 27 Oct 2026 20:39:49 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4BD00300019F; Tue, 27 Oct 2026 20:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793133594; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yl1/L+LrMZiPUlKrujB3h30/6c8TEokqGisM1A3PNRQ=; b=QZSWoXRVLvA93Ia5JWC3/eKSqrIrCVlf9N3N/l2x1NQ5jF3x6A37QIOV5XxM0+hJ1Z9MRT VqK67iI4Z4ixpwHKLGLCofQwB0AxLcOCAcwaVBuMYQs993bpMGyDE19GxNtpj0+ktOZaT1 tesRc7t5z/fPkDgT6LBoWIoq6fo1eLw= X-MC-Unique: 3EWI2mV5OdmlAzK3pM7abA-1 X-Mimecast-MFC-AGG-ID: 3EWI2mV5OdmlAzK3pM7abA_1793133589 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, John Snow , Kevin Wolf , Fam Zheng , Hanna Reitz , Paolo Bonzini , Richard Henderson , Stefan Hajnoczi , "Denis V. Lunev" , "Michael S. Tsirkin" , Zhao Liu , Niklas Cassel Subject: [PULL 07/15] hw/block: reject a zoned device that the block sizes cannot address Date: Tue, 27 Oct 2026 16:39:25 -0400 Message-ID: <20261027203933.1066759-8-stefanha@redhat.com> In-Reply-To: <20261027203933.1066759-1-stefanha@redhat.com> References: <20261027203933.1066759-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1793133767585154100 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel The write granularity that a frontend reports is derived from the logical and the physical block size, which are properties of the device model, while the granularity that the medium requires and the write pointers that it holds belong to the backend. Nothing ties them together, and where they disagree a guest is told about a device it cannot use. A backend can require a coarser granularity than the block sizes express. A 512e host managed disk has a logical block size of 512 and requires writes to a sequential zone to be a multiple of 4096, so attaching it with a finer physical block size reports a granularity that the disk will not accept, and the guest is given a plain I/O error for a request that it was told was valid. The write pointers can disagree in the same way. They outlive any particular use of the device, while the block sizes are chosen afresh every time it is attached, so a zone written with logical_block_size=3D512 leaves a write pointer that logical_block_size=3D4096 cannot address. A zone report expresses it in 512 byte sectors, so the guest is told about a position that does not fall on a logical block boundary, which it can neither read nor write, and the zone can then only be recovered by resetting it. The reverse is harmless: a pointer laid down with a larger logical block size is still a multiple of a smaller one. Check both at realize time, along with the zone size and the zone capacity, and refuse to start otherwise. The write pointers are already held in memory by the driver, so this costs no I/O. The check uses blkconf_zone_write_granularity(), the same value that a frontend reports to its guest and validates requests against, so the three cannot disagree. Signed-off-by: Niklas Cassel Reviewed-by: Stefan Hajnoczi Message-id: 20260921142819.2916043-8-cassel@kernel.org Signed-off-by: Stefan Hajnoczi --- include/hw/block/block.h | 1 + hw/block/block.c | 63 ++++++++++++++++++++++++++++++++++++++++ hw/block/virtio-blk.c | 4 +++ 3 files changed, 68 insertions(+) diff --git a/include/hw/block/block.h b/include/hw/block/block.h index c769b1297d0..c0a8b84df1f 100644 --- a/include/hw/block/block.h +++ b/include/hw/block/block.h @@ -127,6 +127,7 @@ bool blkconf_blocksizes(BlockConf *conf, Error **errp); * physical block size, so this is the physical block size in practice. */ uint32_t blkconf_zone_write_granularity(BlockConf *conf); +bool blkconf_check_zoned_geometry(BlockConf *conf, Error **errp); bool blkconf_apply_backend_options(BlockConf *conf, bool readonly, bool resizable, Error **errp); =20 diff --git a/hw/block/block.c b/hw/block/block.c index 79b0a67ceac..3bb8121e9e4 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -206,6 +206,69 @@ uint32_t blkconf_zone_write_granularity(BlockConf *con= f) return MAX(conf->logical_block_size, conf->physical_block_size); } =20 +bool blkconf_check_zoned_geometry(BlockConf *conf, Error **errp) +{ + BlockDriverState *bs =3D blk_bs(conf->blk); + uint32_t wg; + + if (bs->bl.zoned =3D=3D BLK_Z_NONE) { + return true; + } + + wg =3D blkconf_zone_write_granularity(conf); + + /* + * A backend that requires a coarser granularity than the one that is = about + * to be reported would reject writes that the guest has been told are + * valid, leaving it with a plain I/O error. + */ + if (bs->bl.write_granularity > wg) { + error_setg(errp, "the backend requires writes to sequential zones = to " + "be a multiple of %" PRIu32 " bytes, which is coarser t= han " + "the zone write granularity %" PRIu32 " that would be " + "reported", bs->bl.write_granularity, wg); + error_append_hint(errp, "Set physical_block_size=3D%" PRIu32 ".\n", + bs->bl.write_granularity); + return false; + } + + if (!QEMU_IS_ALIGNED(bs->bl.zone_size, wg)) { + error_setg(errp, "zone size %" PRIu64 " is not a multiple of the z= one " + "write granularity %" PRIu32, bs->bl.zone_size, wg); + return false; + } + + /* + * A write pointer that is not a multiple of the write granularity doe= s not + * fall on a logical block boundary, so the guest can neither read nor= write + * at it and the zone can only be recovered by resetting it. A backend= that + * records its write pointers, rather than reading them back from a de= vice, + * can hand us such a pointer when the zones were written while the de= vice + * was configured with a smaller logical block size. + */ + for (uint32_t i =3D 0; i < bs->bl.nr_zones; i++) { + uint64_t wp; + + if (bdrv_zone_is_conv(bs, i)) { + continue; + } + + wp =3D bs->wps->wp[i]; + if (!QEMU_IS_ALIGNED(wp, wg)) { + error_setg(errp, "write pointer 0x%" PRIx64 " of zone %" PRIu32 + " is not a multiple of the zone write granularity %" + PRIu32, wp, i, wg); + error_append_hint(errp, "The zones were written with a finer z= one " + "write granularity. Reset them, or attach th= e " + "device with the block sizes that they were " + "written with.\n"); + return false; + } + } + + return true; +} + bool blkconf_apply_backend_options(BlockConf *conf, bool readonly, bool resizable, Error **errp) { diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 449de307b48..74bd08b0ec1 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -1840,6 +1840,10 @@ static void virtio_blk_device_realize(DeviceState *d= ev, Error **errp) return; } =20 + if (!blkconf_check_zoned_geometry(&conf->conf, errp)) { + return; + } + bs =3D blk_bs(conf->conf.blk); if (bs->bl.zoned !=3D BLK_Z_NONE) { virtio_add_feature(&s->host_features, VIRTIO_BLK_F_ZONED); --=20 2.56.0 From nobody Mon Nov 23 04:26: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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793133806; cv=none; d=zohomail.com; s=zohoarc; b=HXuWaGzSSNh9sc23i8pp2iTFxldkhw+aVy6v5yfMUhnM0CFw5Ps1ZOvIfdHBYABm4XBTbZdBcYI6oJ6jkoN1aNYHgj7/D2R0WJareVNjNM7aCsHdCZY4o7yT9UklB9xIK+dtI5wYXJVhzWcxBDTI+0dhimXBpgP+CC5/G+eMdek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793133806; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=G2vzvwuHxGQYdBj3J31fcTuztNmOOkaMldS/Bb8poG0=; b=HgMzEK8ePEwolgZ4qmZtuf9kWN0t9ww0vyAjyyEs+hCfA5Yhsptzb5IVvphgvUfnNrVbGFHMrXol5U151rN2Fl42XikIWUFUXn5phkg+PDNfhw7k4E8/M/H8RlNtTLqDAYNv/e+FJ2BdfK5+Mj+pN9smhasSuMeuQJrng6+8V88= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793133806209397.9763199470664; Tue, 27 Oct 2026 13:43:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLnz1-0001UG-80; Tue, 27 Oct 2026 16:41:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxy-0000q8-Jn for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxc-0001Ld-EP for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:00 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-676-U7DiufsqPGO3FzCX_p7psA-1; Tue, 27 Oct 2026 16:39:52 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CFF15195422F; Tue, 27 Oct 2026 20:39:50 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3C6031800586; Tue, 27 Oct 2026 20:39:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793133593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G2vzvwuHxGQYdBj3J31fcTuztNmOOkaMldS/Bb8poG0=; b=N2UFch7jm7l0ddZojj+59uwEX1DuiFjsAcNT7DvUQdlCUI0UBv6RYN1ROoySwXxQn8nYtR Ps/+Xn2RCBm5Kjv8NxD5f9RKP5wRlgP4KGzJ8i63Ovxyq/C9Ynj2yyRUrAKLO4T8H0HkXC ISU9hEYoNT6v3emSqFtVNBvOcGxCgHs= X-MC-Unique: U7DiufsqPGO3FzCX_p7psA-1 X-Mimecast-MFC-AGG-ID: U7DiufsqPGO3FzCX_p7psA_1793133590 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, John Snow , Kevin Wolf , Fam Zheng , Hanna Reitz , Paolo Bonzini , Richard Henderson , Stefan Hajnoczi , "Denis V. Lunev" , "Michael S. Tsirkin" , Zhao Liu , Niklas Cassel , Damien Le Moal Subject: [PULL 08/15] block: reject zone appends that are not a multiple of the sector size Date: Tue, 27 Oct 2026 16:39:26 -0400 Message-ID: <20261027203933.1066759-9-stefanha@redhat.com> In-Reply-To: <20261027203933.1066759-1-stefanha@redhat.com> References: <20261027203933.1066759-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1793133817079158500 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel Zone write pointers are tracked and reported in units of BDRV_SECTOR_SIZE, so an append whose data size is not a multiple of it would leave a write pointer that cannot be represented, neither in a BlockZoneDescriptor nor in the virtio and NVMe zone reports derived from one. Nothing states that invariant. file-posix, the only driver that carries out an append itself, does enforce it, but only as a side effect of checking each iovec against BlockLimits.write_granularity, which is never smaller than the sector size. That conflates two constraints: the sector granularity holds for every driver, whereas write_granularity describes a coarser requirement of the medium below a driver, and only a driver that has such a medium should express it. Check the invariant once in bdrv_co_zone_append(), so that it no longer rests on a driver that happens to have a granularity of its own to report. This is a lower bound, not the alignment that a guest has to observe. The block layer cannot know that one, because it also depends on the logical block size the device is configured with, which is a property of the frontend. The alignment that applies to a guest is the larger of the two, and it is the frontend that reports it, that validates requests against it, and that has to refuse a device whose write pointers do not satisfy it. Reviewed-by: Damien Le Moal Reviewed-by: Stefan Hajnoczi Signed-off-by: Niklas Cassel Message-id: 20260921142819.2916043-9-cassel@kernel.org Signed-off-by: Stefan Hajnoczi --- block/io.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/block/io.c b/block/io.c index d08956105c2..f6de0588868 100644 --- a/block/io.c +++ b/block/io.c @@ -3360,6 +3360,16 @@ int coroutine_fn bdrv_co_zone_append(BlockDriverStat= e *bs, int64_t *offset, return ret; } =20 + /* + * Zone write pointers are kept and reported in units of BDRV_SECTOR_S= IZE, + * so an append that would leave a write pointer at a finer granularity + * cannot be represented. Drivers may impose a coarser granularity of = their + * own, see BlockLimits.write_granularity. + */ + if (!QEMU_IS_ALIGNED(qiov->size, BDRV_SECTOR_SIZE)) { + return -EINVAL; + } + bdrv_inc_in_flight(bs); if (!drv || !drv->bdrv_co_zone_append || bs->bl.zoned =3D=3D BLK_Z_NON= E) { co.ret =3D -ENOTSUP; --=20 2.56.0 From nobody Mon Nov 23 04:26: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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793133743; cv=none; d=zohomail.com; s=zohoarc; b=e8YoMTVVbhsc9PvJRSulYW+v+HvxguG0Nk4Ppsvh3XFN01gXU7H0Q35PRdTgRsBqJkvZ295VYCxMtOaMCxb4z/n2CGtXr2f3hun0IbtiFBcarMZaSRj2enqQqfoyNnRIZJGsUgFAhJu8QYPLUuOFKVBZS35qK5qjQWJVSV04Gd4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793133743; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gzc4yJnLMxv0rqRnpa6vbRfcQJ6xJOM52g37zaoLQ1w=; b=gSBnTGoBvkLb8QvvTNo1P20xDampDCc1zEkEuifyGxucGUN9iMhRt4CHi+/1p6ZwEbiV5rg4tHu0GUtDtLmgPMOphIi9R5AX45jK6f/xDWw6rnp0crphc/nX0LkNYR33arxAPTAjHomX9EGohnJh+W4ljRkM2g50JicnjnJTXgA= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179313374348148.42072388534666; Tue, 27 Oct 2026 13:42:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLnz6-0001kJ-P2; Tue, 27 Oct 2026 16:41:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLny1-0000qY-8O for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxg-0001MG-2F for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:02 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-534-oYHP6Ci7P0K6nnpE7WhVFQ-1; Tue, 27 Oct 2026 16:39:53 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 242F71955BF9; Tue, 27 Oct 2026 20:39:52 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B6E2118005B7; Tue, 27 Oct 2026 20:39:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793133597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gzc4yJnLMxv0rqRnpa6vbRfcQJ6xJOM52g37zaoLQ1w=; b=UNfGpUmtww3R9A6dRF9Z+/OnAuHxL0iWGxwGvkUo5qZbKcjnNWtNxq3nnzO+QNGk5uuWcZ p8Eo1TVmGqCce1IF/JnmILUFAYlUFE6PU2p52zT8OJNrllICoJ5HJSYWA3erzqPQtq6Tw7 NSCat6MX3C9zrobLrkpczM3uLgkRBdQ= X-MC-Unique: oYHP6Ci7P0K6nnpE7WhVFQ-1 X-Mimecast-MFC-AGG-ID: oYHP6Ci7P0K6nnpE7WhVFQ_1793133592 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, John Snow , Kevin Wolf , Fam Zheng , Hanna Reitz , Paolo Bonzini , Richard Henderson , Stefan Hajnoczi , "Denis V. Lunev" , "Michael S. Tsirkin" , Zhao Liu , Niklas Cassel Subject: [PULL 09/15] block: reject a zone append that is larger than a zone Date: Tue, 27 Oct 2026 16:39:27 -0400 Message-ID: <20261027203933.1066759-10-stefanha@redhat.com> In-Reply-To: <20261027203933.1066759-1-stefanha@redhat.com> References: <20261027203933.1066759-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1793133816130158500 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel A zone append cannot cross a zone boundary, so a request larger than a zone can never be carried out. Nothing rejects one. The block layer does not look at the length at all, and raw_co_zone_append() writes qiov->size bytes at the write pointer once it has validated the offset, so the write runs past the end of the zone: on a disk with 8 MiB zones, an append of 8 MiB plus one block fills the zone and advances the write pointer of the zone after it. virtio-blk does compare the length, but against BlockLimits.max_append_sectors, which is how much the backend takes in one command and not how large a zone is. For a Linux block device that value is never larger than a zone, so virtio-blk is protected by what the backend happens to report rather than by the check it makes. Check the length in bdrv_co_zone_append(), next to the check that an append is a multiple of the sector size. Both are conditions of the operation rather than of a medium, so the block layer is where they hold for every caller and where no driver has to repeat them. The exact bound is tighter: a request also has to fit in the part of the zone that is still writable, which depends on the write pointer and so stays with the drivers. Signed-off-by: Niklas Cassel Reviewed-by: Stefan Hajnoczi Message-id: 20260921142819.2916043-10-cassel@kernel.org Signed-off-by: Stefan Hajnoczi --- block/io.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/block/io.c b/block/io.c index f6de0588868..eaca8850d01 100644 --- a/block/io.c +++ b/block/io.c @@ -3370,6 +3370,18 @@ int coroutine_fn bdrv_co_zone_append(BlockDriverStat= e *bs, int64_t *offset, return -EINVAL; } =20 + /* + * An append cannot cross a zone boundary, so one that is larger than a + * zone can never be carried out, wherever the write pointer of the zo= ne + * is. The exact bound is the part of the zone that is still writable, + * which only a driver can check, as only it holds the write pointer. + * zone_size is zero when the device is not zoned, which is reported as + * unsupported below. + */ + if (bs->bl.zone_size && qiov->size > bs->bl.zone_size) { + return -EINVAL; + } + bdrv_inc_in_flight(bs); if (!drv || !drv->bdrv_co_zone_append || bs->bl.zoned =3D=3D BLK_Z_NON= E) { co.ret =3D -ENOTSUP; --=20 2.56.0 From nobody Mon Nov 23 04:26: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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793133723; cv=none; d=zohomail.com; s=zohoarc; b=baA8d9HQv/0+WlZq/gZeKrUyHRhYMjA5PsqgQCwOU5fD8iCIden8LcT5Tifa2UCWqblU8v5cmgtFKIaNY8+fE1m3MGY1g2/yvtN0OTlHEdbpH56JtCn3Z1dFMl/t9aLK02vQnE9mIr0BXxABa8gRje+43xDd8T5DAgeFRqkW9BE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793133723; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pI13v8K1NV9+OoZdtuZMTcUEL0RdLi1V+8XfoQvaFNg=; b=Z49dUYMHeWhXuYLUpUvuZL5+QLX4dvDaz0J3FI2++O+dMbBP5WFaFdiNIWECIkPUS1BeQEVLcXtngBO1c12t+f5JHAV4OBNzyGdveD00xP0d1a6G9jpB2UPuWbdsN9mdieMJfIk4UabWz5nCHoX5iEtw/YHkvXF74zPzCmX/TL0= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793133723834590.9558703245594; Tue, 27 Oct 2026 13:42:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLnym-00017W-SZ; Tue, 27 Oct 2026 16:41:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLny1-0000qW-8R for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxg-0001MY-EM for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:03 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-261-PHFbgJAqO2iJydzeHLw2aA-1; Tue, 27 Oct 2026 16:39:54 -0400 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 400C61954B23; Tue, 27 Oct 2026 20:39:53 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EA44F410; Tue, 27 Oct 2026 20:39:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793133599; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pI13v8K1NV9+OoZdtuZMTcUEL0RdLi1V+8XfoQvaFNg=; b=GIecTTVocetaPaUwoqc/vMVKU08a6GhOS4ILOC+lqY1DpZjE8d0XEphLiMaafuMZPagM0V BcD8lazP6lzTvgJ47lMpaKAwaajyRlqqfSg34MFDQ/jbpzafWV0g9bPmH8YSZXw+hZyjuy fOLh3XDNVph04VvRbfUTRAvS4K6f8Dw= X-MC-Unique: PHFbgJAqO2iJydzeHLw2aA-1 X-Mimecast-MFC-AGG-ID: PHFbgJAqO2iJydzeHLw2aA_1793133593 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, John Snow , Kevin Wolf , Fam Zheng , Hanna Reitz , Paolo Bonzini , Richard Henderson , Stefan Hajnoczi , "Denis V. Lunev" , "Michael S. Tsirkin" , Zhao Liu , Niklas Cassel , Damien Le Moal Subject: [PULL 10/15] file-posix: remove the zone append write granularity check Date: Tue, 27 Oct 2026 16:39:28 -0400 Message-ID: <20261027203933.1066759-11-stefanha@redhat.com> In-Reply-To: <20261027203933.1066759-1-stefanha@redhat.com> References: <20261027203933.1066759-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1793133809799158500 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel The check rejects a zone append whose individual iovec lengths are not multiples of the zone write granularity. That is stricter than the constraint it is meant to enforce, which applies to the size of the request as a whole. A request whose total is properly aligned but which is split across, say, a 512 byte and a 3584 byte iovec is refused here, even though the iovec boundaries do not survive into the scatter gather list that reaches the device. Nor is the driver the right place to enforce it. The granularity that holds for every backend is the sector granularity, which is now checked once in bdrv_co_zone_append(). The coarser granularity that a guest has to observe depends on the logical block size that the device was configured with, so only a frontend can know it, and a frontend both reports it to its guest and validates requests against it. Drop the check. BlockLimits.write_granularity is then set in one place, by this driver from the zone_write_granularity queue attribute, and read in one place, where a device whose granularity the configured block sizes cannot express is refused. Reviewed-by: Damien Le Moal Reviewed-by: Stefan Hajnoczi Signed-off-by: Niklas Cassel Message-id: 20260921142819.2916043-11-cassel@kernel.org Signed-off-by: Stefan Hajnoczi --- block/file-posix.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 48ae785639e..703ec686a35 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3612,8 +3612,6 @@ raw_co_zone_append(BlockDriverState *bs, BdrvRequestFlags flags) { assert(flags =3D=3D 0); int64_t zone_size_mask =3D bs->bl.zone_size - 1; - int64_t iov_len =3D 0; - int64_t len =3D 0; =20 if (*offset & zone_size_mask) { error_report("sector offset %" PRId64 " is not aligned to zone siz= e " @@ -3621,20 +3619,8 @@ raw_co_zone_append(BlockDriverState *bs, return -EINVAL; } =20 - int64_t wg =3D bs->bl.write_granularity; - int64_t wg_mask =3D wg - 1; - for (int i =3D 0; i < qiov->niov; i++) { - iov_len =3D qiov->iov[i].iov_len; - if (iov_len & wg_mask) { - error_report("len of IOVector[%d] %" PRId64 " is not aligned t= o " - "block size %" PRId64 "", i, iov_len, wg); - return -EINVAL; - } - len +=3D iov_len; - } - trace_zbd_zone_append(bs, *offset >> BDRV_SECTOR_BITS); - return raw_co_prw(bs, offset, len, qiov, QEMU_AIO_ZONE_APPEND, 0); + return raw_co_prw(bs, offset, qiov->size, qiov, QEMU_AIO_ZONE_APPEND, = 0); } #endif =20 --=20 2.56.0 From nobody Mon Nov 23 04:26: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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793133720; cv=none; d=zohomail.com; s=zohoarc; b=niPdf7eJji3/Q3Pxu0Nq9tvp/Z3hf9tt7KYqAMDUn6tZv7ucc7ClgOun/4Ca0AECyiW+vkaGbVJquyXwKWfMzobeqWW4kzqq3pk8fYTFkFAJ0cT7M11HKoAXrYD4VKvT71EHGr7H+9b9GGLO+dNpM4+LqrvDG8GLUrpizOYuQls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793133720; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CawP+jicTemyhB4Ih2BygFVKp4RXXazB1bImzxuDm3g=; b=S/KvGG4o1KbS2Gj1tZajGLJ/fCyBxRcc6NZRVhD0BWAu1wDxrrfNg47MEwNdFfQZ5q9JCkQND2Ek4DzdL+TwZuu6u1JcacnIcecci40STmpffX10k/cFXXXTPxYiIus+w5G0UUhvgziLL/gciCsx+Rw/rXEvqtlgwhDEh5k7zr4= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793133720198430.5645109433376; Tue, 27 Oct 2026 13:42:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLnyW-00015c-Ph; Tue, 27 Oct 2026 16:40:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLny1-0000qQ-5e for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxg-0001ME-1M for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:02 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-202-ViNnSGD6MhqUa_Bsy-782Q-1; Tue, 27 Oct 2026 16:39:56 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B92B71955BF9; Tue, 27 Oct 2026 20:39:54 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4446A300019F; Tue, 27 Oct 2026 20:39:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793133597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CawP+jicTemyhB4Ih2BygFVKp4RXXazB1bImzxuDm3g=; b=Gjkko1tDdyihOxhYtcOW9Sptv+fF1ZE2gz+LQOiv1n+6fHoWX/VaeHmOz6bpoHm6+7ym5H fO0w4ePaPBU3RUvtOTroAW2XneuaenM7aOBHgNzih9AZ4LfabZ6Mykokq4QlwjKtmgmuKA PHYEImhaLvWk85p8LM3GyJ6jYb9LOVA= X-MC-Unique: ViNnSGD6MhqUa_Bsy-782Q-1 X-Mimecast-MFC-AGG-ID: ViNnSGD6MhqUa_Bsy-782Q_1793133594 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, John Snow , Kevin Wolf , Fam Zheng , Hanna Reitz , Paolo Bonzini , Richard Henderson , Stefan Hajnoczi , "Denis V. Lunev" , "Michael S. Tsirkin" , Zhao Liu , Niklas Cassel Subject: [PULL 11/15] virtio-blk: add a max-append-sectors property Date: Tue, 27 Oct 2026 16:39:29 -0400 Message-ID: <20261027203933.1066759-12-stefanha@redhat.com> In-Reply-To: <20261027203933.1066759-1-stefanha@redhat.com> References: <20261027203933.1066759-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1793133721040154100 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel The maximum zone append size that the device reports to its driver was taken from BlockLimits.max_append_sectors, a limit of the host disk that the backend happens to sit on. A guest reads it out of the configuration space, so it becomes part of what the guest has been told about its device, and migrating that guest to a host whose disks report something smaller leaves it appending more than the device accepts. Make it a property, as max-discard-sectors and max-write-zeroes-sectors already are, so that the value a guest is given is part of the device model and does not change under it. Nothing from BlockLimits reaches the configuration space any more. Zero is a valid value here, unlike for those two. There is no feature bit for zone append, and a maximum of zero is how the specification has a device say that it does not support the operation (virtio 1.4, 5.2.5.2). It is also what a ZBC or ZAC disk is: such a disk has no zone append command at all, and Linux emulates one in its block layer. What is reported is capped by the size of a zone. The specification asks for the largest append that can be carried out, and one larger than a zone never can be, so the default would otherwise advertise a size that the block layer refuses. The cap tells a guest nothing about the host that zone_sectors has not already told it. Signed-off-by: Niklas Cassel Reviewed-by: Stefan Hajnoczi Message-id: 20260921142819.2916043-12-cassel@kernel.org Signed-off-by: Stefan Hajnoczi --- include/hw/virtio/virtio-blk.h | 1 + hw/block/virtio-blk.c | 67 ++++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 3d8dee7ec15..0070ca6ba9c 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -47,6 +47,7 @@ struct VirtIOBlkConf bool report_discard_granularity; uint32_t max_discard_sectors; uint32_t max_write_zeroes_sectors; + uint32_t max_append_sectors; bool x_enable_wce_if_config_wce; }; =20 diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 74bd08b0ec1..536d71a91ad 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -521,6 +521,24 @@ typedef struct ZoneCmdData { }; } ZoneCmdData; =20 +/* + * The maximum zone append size that the device reports to its driver, in = 512 + * byte sectors. + * + * An append cannot cross a zone boundary, so the configured maximum is ca= pped + * by the size of a zone: the specification asks for the largest append th= at + * can be carried out, and a larger one never can be. The zone size is alr= eady + * reported to the driver as zone_sectors, so this tells it nothing new ab= out + * the host. + */ +static uint32_t virtio_blk_max_append_sectors(VirtIOBlock *s) +{ + BlockDriverState *bs =3D blk_bs(s->blk); + + return MIN(s->conf.max_append_sectors, + bs->bl.zone_size >> BDRV_SECTOR_BITS); +} + /* * check zoned_request: error checking before issuing requests. If all che= cks * passed, return true. @@ -556,12 +574,13 @@ static bool check_zoned_request(VirtIOBlock *s, int64= _t offset, int64_t len, return false; } =20 - if (len / 512 > bs->bl.max_append_sectors) { - if (bs->bl.max_append_sectors =3D=3D 0) { - *status =3D VIRTIO_BLK_S_UNSUPP; - } else { - *status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; - } + if (!s->conf.max_append_sectors) { + *status =3D VIRTIO_BLK_S_UNSUPP; + return false; + } + + if ((len >> BDRV_SECTOR_BITS) > virtio_blk_max_append_sectors(s)) { + *status =3D VIRTIO_BLK_S_ZONE_INVALID_CMD; return false; } } @@ -1315,7 +1334,7 @@ static void virtio_blk_update_config(VirtIODevice *vd= ev, uint8_t *config) virtio_stl_p(vdev, &blkcfg.zoned.write_granularity, blkconf_zone_write_granularity(conf)); virtio_stl_p(vdev, &blkcfg.zoned.max_append_sectors, - bs->bl.max_append_sectors); + virtio_blk_max_append_sectors(s)); } else { blkcfg.zoned.model =3D VIRTIO_BLK_Z_NONE; } @@ -1852,6 +1871,34 @@ static void virtio_blk_device_realize(DeviceState *d= ev, Error **errp) } } =20 + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_ZONED)) { + uint32_t wg =3D blkconf_zone_write_granularity(&conf->conf); + + /* + * Checked before the granularity below, so that a driver can shif= t the + * value that it reads into a byte count without overflowing. + */ + if (conf->max_append_sectors > BDRV_REQUEST_MAX_SECTORS) { + error_setg(errp, "invalid max-append-sectors property (%" PRIu= 32 + "), must not exceed %d", conf->max_append_sectors, + (int)BDRV_REQUEST_MAX_SECTORS); + return; + } + + /* + * Zero is allowed, and says that zone append is not supported, wh= ich + * is what a ZBC or ZAC disk is. Anything else has to be able to + * express a single write. + */ + if (conf->max_append_sectors && + (conf->max_append_sectors << BDRV_SECTOR_BITS) < wg) { + error_setg(errp, "invalid max-append-sectors property (%" PRIu= 32 + "), must be zero or at least the zone write granula= rity " + "(%" PRIu32 " bytes)", conf->max_append_sectors, wg= ); + return; + } + } + if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_DISCARD) && (!conf->max_discard_sectors || conf->max_discard_sectors > BDRV_REQUEST_MAX_SECTORS)) { @@ -1986,6 +2033,12 @@ static const Property virtio_blk_properties[] =3D { conf.max_discard_sectors, BDRV_REQUEST_MAX_SECTORS), DEFINE_PROP_UINT32("max-write-zeroes-sectors", VirtIOBlock, conf.max_write_zeroes_sectors, BDRV_REQUEST_MAX_SEC= TORS), + /* + * Zero is valid, and says that the device does not support zone appen= d, + * as a ZBC or ZAC disk does not. + */ + DEFINE_PROP_UINT32("max-append-sectors", VirtIOBlock, + conf.max_append_sectors, BDRV_REQUEST_MAX_SECTORS), DEFINE_PROP_BOOL("x-enable-wce-if-config-wce", VirtIOBlock, conf.x_enable_wce_if_config_wce, true), }; --=20 2.56.0 From nobody Mon Nov 23 04:26: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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793133702; cv=none; d=zohomail.com; s=zohoarc; b=VaGTyoR3gVvASdNJsGvbEsV7nhxBqU7finNFR0XapW8uw0cpordnA7c+tT5+DKJSkcqTUSHH4k/+HRjt1x40ktUwZvZ9jX7CH9HJFw1DnV4VMYQXYv/5F0D7f0mIjWugzjeHljHF3aZUUotL/8Ker7iY4UTl2WLGFQsfA4g6tlk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793133702; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PqkQQvp/vNM9bI0E0N8gi3g2ERwb+7178kZaVEn8CJE=; b=KJQWjRBbo5NhrSpsNvFI/QKweQ0ZitOzUS2EKxhnctzv6uv5rPlr4ekzqdS3Gb0vcAp70Y6WU7G7psWNF+p+Pkylv9LhxrecV2+S9lxaFgvwFJ4TVcBgn1cZGHsjYF0yY3aDn/wrNbTSS4o5R0Qm9p36EB+5wujdbneCJ09jXXw= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793133702350176.8105887739266; Tue, 27 Oct 2026 13:41:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLnyP-00013J-0d; Tue, 27 Oct 2026 16:40:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLny1-0000qS-66 for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxg-0001Mf-3c for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:02 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-449-f1eRO3YRMnu2sKmVpCmtTQ-1; Tue, 27 Oct 2026 16:39:57 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BB36E195411E; Tue, 27 Oct 2026 20:39:55 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 70C2F1800586; Tue, 27 Oct 2026 20:39:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793133599; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PqkQQvp/vNM9bI0E0N8gi3g2ERwb+7178kZaVEn8CJE=; b=hBxWB/AO0iQaaPuTUUv9g3MKFJAaYA09UwbthVgREgrvIXZ+8F4P/MMACeKcdbyTpeQ+jA k8dmWoEIpB5d781ecYEX6fLVYa8yw9xJHmyeQLCFLndJ4JJ19Ij3CQOlsCNQesJr0j3GTj ghBkqJZ7X9CdmCGIHK0vN/ZUbvfVY5I= X-MC-Unique: f1eRO3YRMnu2sKmVpCmtTQ-1 X-Mimecast-MFC-AGG-ID: f1eRO3YRMnu2sKmVpCmtTQ_1793133595 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, John Snow , Kevin Wolf , Fam Zheng , Hanna Reitz , Paolo Bonzini , Richard Henderson , Stefan Hajnoczi , "Denis V. Lunev" , "Michael S. Tsirkin" , Zhao Liu , Niklas Cassel Subject: [PULL 12/15] block: remove BlockLimits.max_append_sectors Date: Tue, 27 Oct 2026 16:39:30 -0400 Message-ID: <20261027203933.1066759-13-stefanha@redhat.com> In-Reply-To: <20261027203933.1066759-1-stefanha@redhat.com> References: <20261027203933.1066759-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1793133704776154100 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel The field described the largest zone append that a backend accepts. It had one writer and one reader, and neither is left. file-posix filled it from the zone_append_max_bytes queue attribute, which bounds REQ_OP_ZONE_APPEND, an operation it never issues: Linux has no userspace interface for one, so raw_co_zone_append() substitutes the write pointer of the zone for the offset and the request reaches the host as a plain pwritev(). The transfer limit does not apply either, no more than it does to an ordinary write. This driver reports max_hw_transfer but never sets BlockLimits.max_transfer, which is what bdrv_aligned_pwritev() splits by, so a request of any size goes to the host kernel whole and is split there: on a null_blk device whose zone_append_max_bytes is 130560, a 16 MiB append completes and advances the write pointer by 16 MiB. That is safe for a sequential zone, as Linux issues the fragments of a split write in order, with zone write plugging since 6.10 and zone write locking before that. virtio-blk was the reader, and now takes what it reports to a guest from a property instead. Remove the field and the assignment that filled it. Keeping it would be worse than not having it: a driver that set it, believing something enforced it, would be silently ignored. Signed-off-by: Niklas Cassel Reviewed-by: Stefan Hajnoczi Message-id: 20260921142819.2916043-13-cassel@kernel.org Signed-off-by: Stefan Hajnoczi --- include/block/block_int-common.h | 3 --- block/file-posix.c | 5 ----- 2 files changed, 8 deletions(-) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 6bfdcbfe86b..0c7746a5441 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -914,9 +914,6 @@ typedef struct BlockLimits { /* total number of zones */ uint32_t nr_zones; =20 - /* maximum sectors of a zone append write operation */ - uint32_t max_append_sectors; - /* maximum number of open zones */ uint32_t max_open_zones; =20 diff --git a/block/file-posix.c b/block/file-posix.c index 703ec686a35..4749d965865 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1508,11 +1508,6 @@ static void raw_refresh_zoned_limits(BlockDriverStat= e *bs, struct stat *st, } bs->bl.nr_zones =3D ret; =20 - ret =3D get_sysfs_long_val(st, "zone_append_max_bytes"); - if (ret > 0) { - bs->bl.max_append_sectors =3D ret >> BDRV_SECTOR_BITS; - } - ret =3D get_sysfs_long_val(st, "zone_write_granularity"); if (ret >=3D 0) { bs->bl.write_granularity =3D ret; --=20 2.56.0 From nobody Mon Nov 23 04:26: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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793133754; cv=none; d=zohomail.com; s=zohoarc; b=kjacEUL29bdRveru94MjKF/bfNbpzkw5NB2pRxNvVLhIc/CpRNrmy6tO3ASzzSTKIhxOPqMguW5i12s9ik2pEOVHy8V7B18gXjkKufljU5s/ugshJiTiqkpQJxyyTFRhiObkRgHVZ0w8t4X4ZZbIthzrCtgzfy51AZ8TBbWK9Lc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793133754; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UNEaGhMzMG45HUZH7cB/WbS/zchDc6QOm5Qw7cyNxYY=; b=I6UqIjhPzeEEIu6SDFnDXD8RA8VT2COjA3GqlDcqT7gcXP3iANCMAH2Hb7Rgiub29Se4/27yLIIvj3sonxzdVT00t0P8Tir0Q//XNIha5RrlVi4t9Wgf+PesG0ePzmzVBSKWI1/D//FiDSbo9bjrtGk22vftg+y+0ovKOOkDHFY= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793133754632329.52547053062824; Tue, 27 Oct 2026 13:42:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLnyz-0001OJ-89; Tue, 27 Oct 2026 16:41:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLny6-0000tY-Ok for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLny0-0001Ns-Th for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:25 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-408-y9An_H1OP1mhLCiSvIkpCg-1; Tue, 27 Oct 2026 16:39:58 -0400 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 66DE31954107; Tue, 27 Oct 2026 20:39:57 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A2DBF433; Tue, 27 Oct 2026 20:39:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793133604; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UNEaGhMzMG45HUZH7cB/WbS/zchDc6QOm5Qw7cyNxYY=; b=cuUY2pOaicztjJlU4ayk9h5u/bBna9rYFvmk0N/0wIKKUtrBslEGYr19YhoucZvHeVh5Gw VQ2XWhFC7st/I9bmLxnvfuS8aB7W99gghb4FU9FR5OnzrXX2Ji8TWAaC2x9bbjwMwOQGVw xlRtVgcyd7PRExzfanTzFoTRP5V6Fs0= X-MC-Unique: y9An_H1OP1mhLCiSvIkpCg-1 X-Mimecast-MFC-AGG-ID: y9An_H1OP1mhLCiSvIkpCg_1793133597 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, John Snow , Kevin Wolf , Fam Zheng , Hanna Reitz , Paolo Bonzini , Richard Henderson , Stefan Hajnoczi , "Denis V. Lunev" , "Michael S. Tsirkin" , Zhao Liu , Niklas Cassel , Damien Le Moal Subject: [PULL 13/15] file-posix: reject a zone append past the device capacity Date: Tue, 27 Oct 2026 16:39:31 -0400 Message-ID: <20261027203933.1066759-14-stefanha@redhat.com> In-Reply-To: <20261027203933.1066759-1-stefanha@redhat.com> References: <20261027203933.1066759-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1793133817081158500 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel raw_co_zone_append() checks that the offset it is given is aligned to the zone size, but not that it names a zone of the device. raw_co_prw() then derives a zone index from it and reads that entry of the write pointer array, so an offset past the end of the device reads past the end of the array. bdrv_co_zone_append() does not catch it either: bdrv_check_qiov_request() bounds the request against BDRV_MAX_LENGTH, which has nothing to do with the size of this device. A guest cannot reach it, because check_zoned_request() in virtio-blk rejects an out of range offset first, but qemu-io and any other caller of blk_co_zone_append() can: $ qemu-io --image-opts -n driver=3Dhost_device,filename=3D/dev/nullb0 \ -c "zap -p 0x100000000000 0x1000" Segmentation fault On a null_blk device with 1000 zones of 256 MiB, that offset yields zone index 65536 and reads 512 KiB beyond an 8000 byte allocation. Reject an offset that lies outside the device. That also bounds the zone index that raw_co_prw() derives from it, so its write pointer lookup stays inside the array. Fixes: 4751d09adcc3 ("block: introduce zone append write for zoned devices") Reviewed-by: Damien Le Moal Reviewed-by: Stefan Hajnoczi Signed-off-by: Niklas Cassel Message-id: 20260921142819.2916043-14-cassel@kernel.org Signed-off-by: Stefan Hajnoczi --- block/file-posix.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 4749d965865..f87afffa40d 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3606,8 +3606,15 @@ raw_co_zone_append(BlockDriverState *bs, QEMUIOVector *qiov, BdrvRequestFlags flags) { assert(flags =3D=3D 0); + int64_t capacity =3D bs->total_sectors << BDRV_SECTOR_BITS; int64_t zone_size_mask =3D bs->bl.zone_size - 1; =20 + if (*offset >=3D capacity) { + error_report("*offset %" PRId64 " is equal to or greater than the " + "device capacity %" PRId64 "", *offset, capacity); + return -ENOSPC; + } + if (*offset & zone_size_mask) { error_report("sector offset %" PRId64 " is not aligned to zone siz= e " "%" PRId64 "", *offset / 512, bs->bl.zone_size / 512); --=20 2.56.0 From nobody Mon Nov 23 04:26: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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793133723; cv=none; d=zohomail.com; s=zohoarc; b=ZDnUlAz2KJMnJbHPTQBr2vhx/THwP5usrQtyjFOXPyg4vbJm8G9W2xctHq30ZTV0xDg8BHQR29C/33UtVTi5gW6XoGmPDghyJ7bLdYj5ZKY76/lErAT9b9Kb8KK1CVvTOFNZUsfNDAnQ9UQSCTG8TluK9tOzvpbr44lkbZQjHEo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793133723; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dmqnVsaVzUez9WDXuytLRKh1lphInebJt2AXIrdlFoo=; b=djfZ7kMK3D2QV1n/Ph1nDuWGcVJWMVaHV/qMhFIMINMqxVhu6XODV+Q02u+FFPD7Fnmy3lVSGn2tFEqgBWDB/LL4dUdvx5qH6QKLEaKvLZAiZ+Mr3ouGvmO++dFqehxUjYV1+IlQqI7cDrHOu1qqbSoQNO300CYlgeVunKoeF/0= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793133723585204.72497102933085; Tue, 27 Oct 2026 13:42:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLnyR-000141-87; Tue, 27 Oct 2026 16:40:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLny4-0000rg-VQ for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLnxs-0001Na-2G for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:24 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-639-sCnYy63CNVKDYnArV4932w-1; Tue, 27 Oct 2026 16:40:00 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E132018005B2; Tue, 27 Oct 2026 20:39:58 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3688D1955F01; Tue, 27 Oct 2026 20:39:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793133602; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dmqnVsaVzUez9WDXuytLRKh1lphInebJt2AXIrdlFoo=; b=bwnh8EDCD2zGpmXCMToQdebmq0pU9Cb8Bt8Tg/AOTuLrlZ+unAPBNxJ9jOrL0sSm3pmlVw 4e0324RVOBtyWwSciKYd7QjxY3wgwoH0DwWKkD/mfWrKWppXAaTH5wrhxPPz7pw1JayiH5 jDx8r/00kp63HCN9A3Y+Gn9vfixEvNA= X-MC-Unique: sCnYy63CNVKDYnArV4932w-1 X-Mimecast-MFC-AGG-ID: sCnYy63CNVKDYnArV4932w_1793133599 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, John Snow , Kevin Wolf , Fam Zheng , Hanna Reitz , Paolo Bonzini , Richard Henderson , Stefan Hajnoczi , "Denis V. Lunev" , "Michael S. Tsirkin" , Zhao Liu , Niklas Cassel , Damien Le Moal Subject: [PULL 14/15] file-posix: reject a zone append to a full or conventional zone Date: Tue, 27 Oct 2026 16:39:32 -0400 Message-ID: <20261027203933.1066759-15-stefanha@redhat.com> In-Reply-To: <20261027203933.1066759-1-stefanha@redhat.com> References: <20261027203933.1066759-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-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: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1793133726893154100 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel raw_co_prw() replaces the offset of a zone append with the write pointer of the addressed zone, which assumes that the stored value names a position inside that zone. It does not in two cases. A full zone has its write pointer recorded at the end of the zone, since get_zones_wp() stores start + len for BLK_ZONE_COND_FULL. That is the first sector of the following zone, so the append is submitted there. The kernel accepts it whenever that zone is empty, because it is a legal write at its write pointer, and the completion path advances the wrong zone because it recomputes the zone index from the replaced offset. The data is written to a zone that was never addressed and success is returned: zone 2 finished, then a 4 KiB append to zone 2: After zap done, the append sector is 0x180000 <- zone 3 zone 2: wptr 0x180000, zcond:14 (full) zone 3: wptr 0x180008 <- advanced A conventional zone has no write pointer at all, and its array entry carries only the type marker in the top bit, so the offset becomes negative and the write fails with EINVAL. That is harmless but it reports nothing about the actual mistake. Reject both while the write pointer lock is held, since the state has to be read and acted on atomically. check_zoned_request() in virtio-blk refuses an append to a conventional zone, so that case needs a caller that goes to the driver directly, but nothing there examines whether a zone is full, so a guest can reach the misdirected write. Fixes: 4751d09adcc3 ("block: introduce zone append write for zoned devices") Reviewed-by: Damien Le Moal Reviewed-by: Stefan Hajnoczi Signed-off-by: Niklas Cassel Message-id: 20260921142819.2916043-15-cassel@kernel.org Signed-off-by: Stefan Hajnoczi --- include/block/block-io.h | 6 ++++++ block/file-posix.c | 23 ++++++++++++++++++++++- block/io.c | 9 +++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index e469df70610..f671476f08a 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -134,6 +134,12 @@ uint32_t bdrv_zone_index(BlockDriverState *bs, uint64_= t offset); * bdrv_zone_is_full() this does not need the write pointer lock. */ bool bdrv_zone_is_conv(BlockDriverState *bs, uint32_t index); +/* + * True when the write pointer of a zone has reached the end of the writab= le + * part of that zone, so that nothing more can be written to it until it is + * reset. The write pointer lock must be held when called. + */ +bool bdrv_zone_is_full(BlockDriverState *bs, uint32_t index); =20 bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); =20 diff --git a/block/file-posix.c b/block/file-posix.c index f87afffa40d..bad7ccdb733 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2574,7 +2574,28 @@ raw_co_prw(BlockDriverState *bs, int64_t *offset_ptr= , uint64_t bytes, bs->bl.zoned !=3D BLK_Z_NONE) { qemu_co_mutex_lock(&bs->wps->colock); if (type & QEMU_AIO_ZONE_APPEND) { - int index =3D bdrv_zone_index(bs, offset); + uint32_t index =3D bdrv_zone_index(bs, offset); + + /* + * The write pointer of the addressed zone becomes the offset = of + * the write, so it has to name a position inside that zone. A + * conventional zone has no write pointer, and the pointer of a + * full zone is reported at the end of the zone. Either would = send + * the data to a zone that was never addressed. + */ + if (bdrv_zone_is_conv(bs, index)) { + error_report("zone append at offset 0x%" PRIx64 " addresse= s a " + "conventional zone", offset); + qemu_co_mutex_unlock(&bs->wps->colock); + return -EINVAL; + } + if (bdrv_zone_is_full(bs, index)) { + error_report("zone append at offset 0x%" PRIx64 " addresse= s a " + "full zone", offset); + qemu_co_mutex_unlock(&bs->wps->colock); + return -ENOSPC; + } + offset =3D bs->wps->wp[index]; } } diff --git a/block/io.c b/block/io.c index eaca8850d01..c86f96bd612 100644 --- a/block/io.c +++ b/block/io.c @@ -3407,6 +3407,15 @@ bool bdrv_zone_is_conv(BlockDriverState *bs, uint32_= t index) return BDRV_ZT_IS_CONV(bs->wps->wp[index]); } =20 +bool bdrv_zone_is_full(BlockDriverState *bs, uint32_t index) +{ + uint64_t zone_end =3D MIN((uint64_t)(index + 1) * bs->bl.zone_size, + (uint64_t)bs->total_sectors << BDRV_SECTOR_BIT= S); + IO_CODE(); + + return bs->wps->wp[index] >=3D zone_end; +} + void *qemu_blockalign(BlockDriverState *bs, size_t size) { IO_CODE(); --=20 2.56.0 From nobody Mon Nov 23 04:26: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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1793133744; cv=none; d=zohomail.com; s=zohoarc; b=c10Q1Qv2KYKL8oUbH12RoJ8piiH9f41rqO+4RjMeK6DYpAmTaiVpxt4JnQoFWKcYnw6jIa5/YfIU8Odof/IRAd8ApjhaY8C1nYcQYW/yMFIGZ2fnA0zgeVEDE6tflLDjXJj+NgYBbn1tKuXUbsp/hfMcBuy5X06/Y3AtewFELWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793133744; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8K+grF7NHxQmwden51rqzd/5a+Fq+kZE7nG0xxS+Yi0=; b=jnnypT53nS/Nd5MZ4cA+44Z3aeMs1RYWL59hGN27VLqnettNFix3fwZl6IIiREjv/3cXfbjde1myPON9d7DIHMMSDOsD8VscbYiWUWpFzuOrZO5gI8pG3lmQ4aMSV4Hs2Kj8aZ2BjGpGyJ5vIzdggTqUb5a6rlHRhUra31AqTPk= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793133743811168.86704565348623; Tue, 27 Oct 2026 13:42:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLnyW-00015p-VC; Tue, 27 Oct 2026 16:40:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLny6-0000tT-Ma for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLny0-0001Pn-Th for qemu-devel@nongnu.org; Tue, 27 Oct 2026 16:40:25 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-256-1CAS6er4PWGOLRjZEir7Tw-1; Tue, 27 Oct 2026 16:40:01 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2316F1805A24; Tue, 27 Oct 2026 20:40:00 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CDF20300019F; Tue, 27 Oct 2026 20:39:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793133605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8K+grF7NHxQmwden51rqzd/5a+Fq+kZE7nG0xxS+Yi0=; b=c/Yjlzts3qUkEE9+L33/AOEKZMNdqHpmmliPw0dBEQl3mrmg2vp631NnFYL31tjMcGHEeq /mdfFhdPSKErVi5cHeGsLBJuTA0vtUJLHxzDXR9QDizWSQRnP3oqXNFFMe7vlPCvMg0gY+ ZSdkEO2uYdyLyfwv4ms7R+nRx/Kj/Vk= X-MC-Unique: 1CAS6er4PWGOLRjZEir7Tw-1 X-Mimecast-MFC-AGG-ID: 1CAS6er4PWGOLRjZEir7Tw_1793133600 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, John Snow , Kevin Wolf , Fam Zheng , Hanna Reitz , Paolo Bonzini , Richard Henderson , Stefan Hajnoczi , "Denis V. Lunev" , "Michael S. Tsirkin" , Zhao Liu , Niklas Cassel Subject: [PULL 15/15] block: do not use CoroutineIOCompletion to hold a return value Date: Tue, 27 Oct 2026 16:39:33 -0400 Message-ID: <20261027203933.1066759-16-stefanha@redhat.com> In-Reply-To: <20261027203933.1066759-1-stefanha@redhat.com> References: <20261027203933.1066759-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @redhat.com) X-ZM-MESSAGEID: 1793133816874158500 Content-Type: text/plain; charset="utf-8" From: Niklas Cassel bdrv_co_zone_report(), bdrv_co_zone_mgmt() and bdrv_co_zone_append() each declare a CoroutineIOCompletion in order to use its ret field, and never touch the coroutine field that the rest of the structure exists for. That structure is for a request which completes through bdrv_co_io_em_complete(), where the callback has to store the result somewhere and wake the coroutine that is waiting for it. These three call into the driver directly and are already running in the coroutine that wants the result, so there is nothing to wake and nowhere else for the value to live. Use a plain int. bdrv_co_zone_append() already has one. Suggested-by: Stefan Hajnoczi Signed-off-by: Niklas Cassel Message-id: 20260921142819.2916043-16-cassel@kernel.org Signed-off-by: Stefan Hajnoczi --- block/io.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/block/io.c b/block/io.c index c86f96bd612..06b1fc13b9f 100644 --- a/block/io.c +++ b/block/io.c @@ -3308,40 +3308,36 @@ int coroutine_fn bdrv_co_zone_report(BlockDriverSta= te *bs, int64_t offset, BlockZoneDescriptor *zones) { BlockDriver *drv =3D bs->drv; - CoroutineIOCompletion co =3D { - .coroutine =3D qemu_coroutine_self(), - }; + int ret; IO_CODE(); =20 bdrv_inc_in_flight(bs); if (!drv || !drv->bdrv_co_zone_report || bs->bl.zoned =3D=3D BLK_Z_NON= E) { - co.ret =3D -ENOTSUP; + ret =3D -ENOTSUP; goto out; } - co.ret =3D drv->bdrv_co_zone_report(bs, offset, nr_zones, zones); + ret =3D drv->bdrv_co_zone_report(bs, offset, nr_zones, zones); out: bdrv_dec_in_flight(bs); - return co.ret; + return ret; } =20 int coroutine_fn bdrv_co_zone_mgmt(BlockDriverState *bs, BlockZoneOp op, int64_t offset, int64_t len) { BlockDriver *drv =3D bs->drv; - CoroutineIOCompletion co =3D { - .coroutine =3D qemu_coroutine_self(), - }; + int ret; IO_CODE(); =20 bdrv_inc_in_flight(bs); if (!drv || !drv->bdrv_co_zone_mgmt || bs->bl.zoned =3D=3D BLK_Z_NONE)= { - co.ret =3D -ENOTSUP; + ret =3D -ENOTSUP; goto out; } - co.ret =3D drv->bdrv_co_zone_mgmt(bs, op, offset, len); + ret =3D drv->bdrv_co_zone_mgmt(bs, op, offset, len); out: bdrv_dec_in_flight(bs); - return co.ret; + return ret; } =20 int coroutine_fn bdrv_co_zone_append(BlockDriverState *bs, int64_t *offset, @@ -3350,9 +3346,6 @@ int coroutine_fn bdrv_co_zone_append(BlockDriverState= *bs, int64_t *offset, { int ret; BlockDriver *drv =3D bs->drv; - CoroutineIOCompletion co =3D { - .coroutine =3D qemu_coroutine_self(), - }; IO_CODE(); =20 ret =3D bdrv_check_qiov_request(*offset, qiov->size, qiov, 0, NULL); @@ -3384,13 +3377,13 @@ int coroutine_fn bdrv_co_zone_append(BlockDriverSta= te *bs, int64_t *offset, =20 bdrv_inc_in_flight(bs); if (!drv || !drv->bdrv_co_zone_append || bs->bl.zoned =3D=3D BLK_Z_NON= E) { - co.ret =3D -ENOTSUP; + ret =3D -ENOTSUP; goto out; } - co.ret =3D drv->bdrv_co_zone_append(bs, offset, qiov, flags); + ret =3D drv->bdrv_co_zone_append(bs, offset, qiov, flags); out: bdrv_dec_in_flight(bs); - return co.ret; + return ret; } =20 uint32_t bdrv_zone_index(BlockDriverState *bs, uint64_t offset) --=20 2.56.0