From nobody Sun Feb 8 09:44:43 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=1747938788; cv=none; d=zohomail.com; s=zohoarc; b=VcYH33wLBugdW7brKiVGbZANnWsYSZZDcHtAcglccuIGkxNM7JOdtnebNWdhttbZpmS03X0XTz2qHC1es5yBkChd0KEmZk3WK1m7G+HCVJeMClYz1F3/YWDfwx4BfWcHgoxh8p0OvrheIn6xyvtwC7M33LJZlWXFaeR65kQlUyM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747938788; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pIIUmeq3SsuUrR0s6flEjVPGyKgwiNYPLT8pE4mayd0=; b=WlDecPMHjMgUTwCqXtNcidt6TwX7U58t612i5oYT/82WP/PQgJBza/+CvEMlaNCGBjaE3+YDzujnWN/dOmsQbV0181bp2SUWRi2X5DmAnRN8/JjSgyNKSz0r3WNByqxUm5bQC+dqM3oMR7z+6pecCNC9oMSagU+qCL4ZJtGqxqE= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747938788216714.46975522737; Thu, 22 May 2025 11:33:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uIAho-0005nR-Uz; Thu, 22 May 2025 14:31:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uIAhZ-0005lX-Ls for qemu-devel@nongnu.org; Thu, 22 May 2025 14:31:33 -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 1uIAhR-0000MP-FU for qemu-devel@nongnu.org; Thu, 22 May 2025 14:31:33 -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-55-yus4JLCVPJuVJN73w8GvvQ-1; Thu, 22 May 2025 14:31:22 -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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 643B91956080; Thu, 22 May 2025 18:31:21 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.45.226.76]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 208CB1944DFF; Thu, 22 May 2025 18:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747938684; 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=pIIUmeq3SsuUrR0s6flEjVPGyKgwiNYPLT8pE4mayd0=; b=O2wSIJdQM3X4ijz8TpecgLW1GS8z5e92pTnOfxdGc9H51RYsdBjXxyf2tlAg66hXJfXmTf m8T26VH/f/fKklQhwjteOY8kTfcd0sbiFhe0ZWeI3c6gbz6F7LPtN8j4bPDEoHNBepC1mr DnYJXmnU5clTdcw5UmNPjf9gr/4/Zks= X-MC-Unique: yus4JLCVPJuVJN73w8GvvQ-1 X-Mimecast-MFC-AGG-ID: yus4JLCVPJuVJN73w8GvvQ_1747938681 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 1/5] scsi-disk: Add native FUA write support Date: Thu, 22 May 2025 20:31:11 +0200 Message-ID: <20250522183115.246746-2-kwolf@redhat.com> In-Reply-To: <20250522183115.246746-1-kwolf@redhat.com> References: <20250522183115.246746-1-kwolf@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=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.275, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747938800698116600 Content-Type: text/plain; charset="utf-8" From: Alberto Faria Simply propagate the FUA flag on write requests to the driver. The block layer will emulate it if necessary. Signed-off-by: Alberto Faria Message-ID: <20250502121115.3613717-2-afaria@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- hw/scsi/scsi-disk.c | 53 +++++++++++++-------------------------------- 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index cb4af1b715..738d8df8ec 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -74,7 +74,7 @@ struct SCSIDiskClass { */ DMAIOFunc *dma_readv; DMAIOFunc *dma_writev; - bool (*need_fua_emulation)(SCSICommand *cmd); + bool (*need_fua)(SCSICommand *cmd); void (*update_sense)(SCSIRequest *r); }; =20 @@ -85,7 +85,7 @@ typedef struct SCSIDiskReq { uint32_t sector_count; uint32_t buflen; bool started; - bool need_fua_emulation; + bool need_fua; struct iovec iov; QEMUIOVector qiov; BlockAcctCookie acct; @@ -389,24 +389,6 @@ static bool scsi_is_cmd_fua(SCSICommand *cmd) } } =20 -static void scsi_write_do_fua(SCSIDiskReq *r) -{ - SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); - - assert(r->req.aiocb =3D=3D NULL); - assert(!r->req.io_canceled); - - if (r->need_fua_emulation) { - block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, 0, - BLOCK_ACCT_FLUSH); - r->req.aiocb =3D blk_aio_flush(s->qdev.conf.blk, scsi_aio_complete= , r); - return; - } - - scsi_req_complete(&r->req, GOOD); - scsi_req_unref(&r->req); -} - static void scsi_dma_complete_noio(SCSIDiskReq *r, int ret) { assert(r->req.aiocb =3D=3D NULL); @@ -416,12 +398,7 @@ static void scsi_dma_complete_noio(SCSIDiskReq *r, int= ret) =20 r->sector +=3D r->sector_count; r->sector_count =3D 0; - if (r->req.cmd.mode =3D=3D SCSI_XFER_TO_DEV) { - scsi_write_do_fua(r); - return; - } else { - scsi_req_complete(&r->req, GOOD); - } + scsi_req_complete(&r->req, GOOD); =20 done: scsi_req_unref(&r->req); @@ -564,7 +541,7 @@ static void scsi_read_data(SCSIRequest *req) =20 first =3D !r->started; r->started =3D true; - if (first && r->need_fua_emulation) { + if (first && r->need_fua) { block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, 0, BLOCK_ACCT_FLUSH); r->req.aiocb =3D blk_aio_flush(s->qdev.conf.blk, scsi_do_read_cb, = r); @@ -589,8 +566,7 @@ static void scsi_write_complete_noio(SCSIDiskReq *r, in= t ret) r->sector +=3D n; r->sector_count -=3D n; if (r->sector_count =3D=3D 0) { - scsi_write_do_fua(r); - return; + scsi_req_complete(&r->req, GOOD); } else { scsi_init_iovec(r, SCSI_DMA_BUF_SIZE); trace_scsi_disk_write_complete_noio(r->req.tag, r->qiov.size); @@ -623,6 +599,7 @@ static void scsi_write_data(SCSIRequest *req) SCSIDiskReq *r =3D DO_UPCAST(SCSIDiskReq, req, req); SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); SCSIDiskClass *sdc =3D (SCSIDiskClass *) object_get_class(OBJECT(s)); + BlockCompletionFunc *cb; =20 /* No data transfer may already be in progress */ assert(r->req.aiocb =3D=3D NULL); @@ -648,11 +625,10 @@ static void scsi_write_data(SCSIRequest *req) =20 if (r->req.cmd.buf[0] =3D=3D VERIFY_10 || r->req.cmd.buf[0] =3D=3D VER= IFY_12 || r->req.cmd.buf[0] =3D=3D VERIFY_16) { - if (r->req.sg) { - scsi_dma_complete_noio(r, 0); - } else { - scsi_write_complete_noio(r, 0); - } + block_acct_start(blk_get_stats(s->qdev.conf.blk), &r->acct, 0, + BLOCK_ACCT_FLUSH); + cb =3D r->req.sg ? scsi_dma_complete : scsi_write_complete; + r->req.aiocb =3D blk_aio_flush(s->qdev.conf.blk, cb, r); return; } =20 @@ -2391,7 +2367,7 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req= , uint8_t *buf) scsi_check_condition(r, SENSE_CODE(LBA_OUT_OF_RANGE)); return 0; } - r->need_fua_emulation =3D sdc->need_fua_emulation(&r->req.cmd); + r->need_fua =3D sdc->need_fua(&r->req.cmd); if (r->sector_count =3D=3D 0) { scsi_req_complete(&r->req, GOOD); } @@ -3137,7 +3113,8 @@ BlockAIOCB *scsi_dma_writev(int64_t offset, QEMUIOVec= tor *iov, { SCSIDiskReq *r =3D opaque; SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); - return blk_aio_pwritev(s->qdev.conf.blk, offset, iov, 0, cb, cb_opaque= ); + int flags =3D r->need_fua ? BDRV_REQ_FUA : 0; + return blk_aio_pwritev(s->qdev.conf.blk, offset, iov, flags, cb, cb_op= aque); } =20 static char *scsi_property_get_loadparm(Object *obj, Error **errp) @@ -3186,7 +3163,7 @@ static void scsi_disk_base_class_initfn(ObjectClass *= klass, const void *data) device_class_set_legacy_reset(dc, scsi_disk_reset); sdc->dma_readv =3D scsi_dma_readv; sdc->dma_writev =3D scsi_dma_writev; - sdc->need_fua_emulation =3D scsi_is_cmd_fua; + sdc->need_fua =3D scsi_is_cmd_fua; } =20 static const TypeInfo scsi_disk_base_info =3D { @@ -3338,7 +3315,7 @@ static void scsi_block_class_initfn(ObjectClass *klas= s, const void *data) sdc->dma_readv =3D scsi_block_dma_readv; sdc->dma_writev =3D scsi_block_dma_writev; sdc->update_sense =3D scsi_block_update_sense; - sdc->need_fua_emulation =3D scsi_block_no_fua; + sdc->need_fua =3D scsi_block_no_fua; dc->desc =3D "SCSI block device passthrough"; device_class_set_props(dc, scsi_block_properties); dc->vmsd =3D &vmstate_scsi_disk_state; --=20 2.49.0 From nobody Sun Feb 8 09:44:43 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=1747938813; cv=none; d=zohomail.com; s=zohoarc; b=T7R/lWN4hU83jkRiJH+IxTQdHwri4HSMGdvlOgB6D5tcKzhkzcUUEV1U6sfmfQHWSBYBceGc/STC53BezxP6aFJXBBzzDZYIKduWnnAez3KZgJAKSrXj8C4lDWinBYrUMjaBUM9lrhdYOzSUioWThorfEUaipAy4WPPhmueKxgI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747938813; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sUaTgO2vTys8H4ViTayW5yivwWSc1BhR5TJhH22T7z0=; b=cTAOm+3il7MtccxL60qcgEAKqYaqoEqRag1u4cGjJr+OpTzkjjVeCAZwfYdfg/1CPRgJV9dfVf37TpXirpJf8RvuZrBWmCnqDTISxb366sC1xm64sM7ZAIgH6Z6j1TM3kAve/ulKR52CYUIfUn55EeNYj2QHLgFyxUzoOfTRXxY= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747938812942637.9238121744493; Thu, 22 May 2025 11:33:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uIAhX-0005kY-Of; Thu, 22 May 2025 14:31:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uIAhW-0005k3-Na for qemu-devel@nongnu.org; Thu, 22 May 2025 14:31:30 -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 1uIAhU-0000N1-MN for qemu-devel@nongnu.org; Thu, 22 May 2025 14:31:30 -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-341-UVIFQtojPNW7pZi49kk_oA-1; Thu, 22 May 2025 14:31:24 -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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 71B4018004AD; Thu, 22 May 2025 18:31:23 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.45.226.76]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0C70E1944DFF; Thu, 22 May 2025 18:31:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747938687; 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=sUaTgO2vTys8H4ViTayW5yivwWSc1BhR5TJhH22T7z0=; b=Mbj+/CT56TFjul3dTaQFLf6Fx5r/DXiEGVCcc/yUjM6QJFT++9eQtjG12dr8sqLlzGudrf 9K71pWeYC5ENzOZRRo2BI6mwnEDT/l5kz0akMLzEugHZMLY0ja8SIfdsgocyff1ssqB/YO HaZhyXqXNJ588KXxN6yjDFm0j6RfjXE= X-MC-Unique: UVIFQtojPNW7pZi49kk_oA-1 X-Mimecast-MFC-AGG-ID: UVIFQtojPNW7pZi49kk_oA_1747938683 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 2/5] scsi-disk: Advertise FUA support by default Date: Thu, 22 May 2025 20:31:12 +0200 Message-ID: <20250522183115.246746-3-kwolf@redhat.com> In-Reply-To: <20250522183115.246746-1-kwolf@redhat.com> References: <20250522183115.246746-1-kwolf@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=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.275, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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: 1747938814637116600 Content-Type: text/plain; charset="utf-8" From: Alberto Faria Allow the guest to submit FUA requests directly, instead of forcing it to emulate them using a regular flush. Signed-off-by: Alberto Faria Message-ID: <20250502121115.3613717-3-afaria@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- hw/core/machine.c | 4 +++- hw/scsi/scsi-disk.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index b8ae155dfa..c3f3a5020d 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -37,7 +37,9 @@ #include "hw/virtio/virtio-iommu.h" #include "audio/audio.h" =20 -GlobalProperty hw_compat_10_0[] =3D {}; +GlobalProperty hw_compat_10_0[] =3D { + { "scsi-hd", "dpofua", "off" }, +}; const size_t hw_compat_10_0_len =3D G_N_ELEMENTS(hw_compat_10_0); =20 GlobalProperty hw_compat_9_2[] =3D { diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 738d8df8ec..b4782c6248 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -3192,7 +3192,7 @@ static const Property scsi_hd_properties[] =3D { DEFINE_PROP_BIT("removable", SCSIDiskState, features, SCSI_DISK_F_REMOVABLE, false), DEFINE_PROP_BIT("dpofua", SCSIDiskState, features, - SCSI_DISK_F_DPOFUA, false), + SCSI_DISK_F_DPOFUA, true), DEFINE_PROP_UINT64("wwn", SCSIDiskState, qdev.wwn, 0), DEFINE_PROP_UINT64("port_wwn", SCSIDiskState, qdev.port_wwn, 0), DEFINE_PROP_UINT16("port_index", SCSIDiskState, port_index, 0), --=20 2.49.0 From nobody Sun Feb 8 09:44:43 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=1747938757; cv=none; d=zohomail.com; s=zohoarc; b=hox2brSAjWtgCd3Ts+BPBnX0DhOCfctjdm/GdgflSWqhhtskqBvRT6oYNROlbXdf/QHdtMpn1zR/dx6jIM0ppWPs7mcGzI+AluGzzUAzLTAH/+CfkGlpnS8sewHYOGEQISYSPnnZvN8Hol1MuTgzoTwStGW6HlXj8myzhkucR2Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747938757; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hjuYirBkwph/WiIGkgU7D8925XkGSUPnaUZ8PN66ITk=; b=Wvku2JAI8JGXafFCVTUyOoL+nWhdKsFmjyCUVy5Ul16nMwV21pqBoPi+6pSFk5vJ9lDOi4sxz/fKCLTPvdVJWDFbWopMH8e7j4u+48ZNWswpuCJ8N1549wOCIcoGxXwxPlaNrK93to8i81b1AlgIj0RcibzGFSJkK1PYNaeKCls= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747938757081102.56703639813225; Thu, 22 May 2025 11:32:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uIAhj-0005nL-7I; Thu, 22 May 2025 14:31:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uIAhZ-0005lO-6W for qemu-devel@nongnu.org; Thu, 22 May 2025 14:31: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 1uIAhW-0000Nx-T1 for qemu-devel@nongnu.org; Thu, 22 May 2025 14:31:32 -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-210-bWT-2s-COa-NtK3JM93YfQ-1; Thu, 22 May 2025 14:31:26 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 16BA9195609F; Thu, 22 May 2025 18:31:25 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.45.226.76]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C76A51944DFF; Thu, 22 May 2025 18:31:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747938690; 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=hjuYirBkwph/WiIGkgU7D8925XkGSUPnaUZ8PN66ITk=; b=evTZ9C2M5HchUrSw4PCFoFvbw/ZfMaOVeLUT7GCeTlmsxjKQiNrC94An5sqtlRIX5z1zE6 C6DJ+L8q8a2+wt1N64v2+lwnKCHlFL687Mz3CDCyhYn0nbluCYb7HaZ6ttAqv4x0QLveOU Q1lYr5LqrhTgQdOFwITBjdhAz4d2gMk= X-MC-Unique: bWT-2s-COa-NtK3JM93YfQ-1 X-Mimecast-MFC-AGG-ID: bWT-2s-COa-NtK3JM93YfQ_1747938685 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 3/5] qemu-img: fix offset calculation in bench Date: Thu, 22 May 2025 20:31:13 +0200 Message-ID: <20250522183115.246746-4-kwolf@redhat.com> In-Reply-To: <20250522183115.246746-1-kwolf@redhat.com> References: <20250522183115.246746-1-kwolf@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=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.275, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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: 1747938758238116600 Content-Type: text/plain; charset="utf-8" From: Denis Rastyogin This error was discovered by fuzzing qemu-img. The current offset calculation leads to an EIO error in block/block-backend.c: blk_check_byte_request(): if (offset > len || len - offset < bytes) { return -EIO; } This triggers the error message: "qemu-img: Failed request: Input/output error". Example of the issue: offset: 260076 len: 260096 bytes: 4096 This fix ensures that offset remains within a valid range. Signed-off-by: Denis Rastyogin Message-ID: <20250506141410.100119-1-gerben@altlinux.org> [kwolf: Fixed up integer overflow] Signed-off-by: Kevin Wolf --- qemu-img.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 76ac5d3028..139eeb5039 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4488,10 +4488,10 @@ static void bench_cb(void *opaque, int ret) */ b->in_flight++; b->offset +=3D b->step; - if (b->image_size =3D=3D 0) { + if (b->image_size <=3D b->bufsize) { b->offset =3D 0; } else { - b->offset %=3D b->image_size; + b->offset %=3D b->image_size - b->bufsize; } if (b->write) { acb =3D blk_aio_pwritev(b->blk, offset, b->qiov, 0, bench_cb, = b); --=20 2.49.0 From nobody Sun Feb 8 09:44:43 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=1747938756; cv=none; d=zohomail.com; s=zohoarc; b=Gc+npo5fcl1Y/4RtpluKvXa2SsnRGaT784CQD5FiUEPhuizvH7tY3HAaDnLCdd58T/8fx8weuk9hsB63lOaXNR6lGEwJU/UA24LX2uE4Goa9hklpMaMCEM7sGH1dA/2k4tNQ/XLZjK4V1Qy94dGp/rQ34JCtSTMAHIEFW911Fp0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747938756; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=EoG2vVF1mLkEop2GmLcTYDfoevSG58BUGG0ufuqbsyE=; b=Q0y+akVlYeEJk5ukY7arWmJTnXpOKJ1EYsw4to0X3caSnzcGclEpfFjxxRQxBFs0FInqxZN0R2qpk8a8bbNuGYO9Jv5zw1+oK6AXsTr9ZaqcknaEywPhizsEZlci0oSztjrw8HzF1BhXdXMVdqSOxeepbJ25fV1wPw4ZhBqKfV0= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174793875689046.26312281990113; Thu, 22 May 2025 11:32:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uIAhz-0005oT-Vi; Thu, 22 May 2025 14:32:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uIAhf-0005nA-5t for qemu-devel@nongnu.org; Thu, 22 May 2025 14:31:40 -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 1uIAhX-0000OI-WC for qemu-devel@nongnu.org; Thu, 22 May 2025 14:31:38 -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-596-2gpnAbIzNp6LiGBWBt2ggQ-1; Thu, 22 May 2025 14:31:27 -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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D147F180036F; Thu, 22 May 2025 18:31:26 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.45.226.76]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8DE0D1944DFF; Thu, 22 May 2025 18:31:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747938691; 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=EoG2vVF1mLkEop2GmLcTYDfoevSG58BUGG0ufuqbsyE=; b=dU/1U5h8QpiwMrt5lc4HqYnyBScxKTUVWiK4PETMgyRgTykBMzDPnz0PXiiFYsT8DU88+n CBvUjkhj32uWbQad+CvdNC5rGFrLPYUfJDwiYW7qLyzs/TFJrmkZ5kAi7I2LrOi+vhkmOS xfAOsvuWgDOJR8VxkiZcOah9hVCTAf8= X-MC-Unique: 2gpnAbIzNp6LiGBWBt2ggQ-1 X-Mimecast-MFC-AGG-ID: 2gpnAbIzNp6LiGBWBt2ggQ_1747938686 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 4/5] file-posix: allow BLKZEROOUT with -t writeback Date: Thu, 22 May 2025 20:31:14 +0200 Message-ID: <20250522183115.246746-5-kwolf@redhat.com> In-Reply-To: <20250522183115.246746-1-kwolf@redhat.com> References: <20250522183115.246746-1-kwolf@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=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.275, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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: 1747938758255116600 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi The Linux BLKZEROOUT ioctl is only invoked when BDRV_O_NOCACHE is set because old kernels did not invalidate the page cache. In that case mixing BLKZEROOUT with buffered I/O could lead to corruption. However, Linux 4.9 commit 22dd6d356628 ("block: invalidate the page cache when issuing BLKZEROOUT") made BLKZEROOUT coherent with the page cache. I have checked that Linux 4.9+ kernels are shipped at least as far back as Debian 10 (buster), openSUSE Leap 15.2, and RHEL/CentOS 8. Use BLKZEROOUT with buffered I/O, mostly so `qemu-img ... -t writeback` can offload write zeroes. Cc: Paolo Bonzini Cc: Christoph Hellwig Signed-off-by: Stefan Hajnoczi Message-ID: <20250417211053.98700-1-stefanha@redhat.com> Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/file-posix.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index ec95b74869..5a3532e40b 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -785,17 +785,6 @@ static int raw_open_common(BlockDriverState *bs, QDict= *options, } #endif =20 - if (S_ISBLK(st.st_mode)) { -#ifdef __linux__ - /* On Linux 3.10, BLKDISCARD leaves stale data in the page cache. = Do - * not rely on the contents of discarded blocks unless using O_DIR= ECT. - * Same for BLKZEROOUT. - */ - if (!(bs->open_flags & BDRV_O_NOCACHE)) { - s->has_write_zeroes =3D false; - } -#endif - } #ifdef __FreeBSD__ if (S_ISCHR(st.st_mode)) { /* --=20 2.49.0 From nobody Sun Feb 8 09:44:43 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=1747938760; cv=none; d=zohomail.com; s=zohoarc; b=YmT2uwUQaWanhgjoa+ztINnWkOeQSq1UC6DOg57ag+h9uJdZXg8q2abkdbTaBeSMVHE5sKrX7RG3Ilso1DP87+7vb2D35oUalrJi13qImKfpAnmbmWs/5rwuat1vuPyOgNeOnuMDjQ9PHlnwzU08jMdWNEUXldIpgfE9FwNKy7Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747938760; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5PEAZpbs5TWoCFtJJ9kIYanvD3S/LIcCEWPEtqoAb7E=; b=Ck7OZnlL2NSUQ8cEU25AtyvRNEiNwM/EMwDrRP7FcyWuyqyEIgCpVmAF+e+tmkTSZpis35asYHVughIFY1DedBVfMERGYzQiLryk1k3PXmE38xNSteDUjL03wacH1KBWpcRwpdVxoydUp46T1nq4IRQnx71r+QLqS596DEby2Fs= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747938760941380.46104801040667; Thu, 22 May 2025 11:32:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uIAiK-000631-1F; Thu, 22 May 2025 14:32:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uIAhd-0005mu-AO for qemu-devel@nongnu.org; Thu, 22 May 2025 14:31:38 -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 1uIAha-0000Ov-5g for qemu-devel@nongnu.org; Thu, 22 May 2025 14:31:35 -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-479-jd_Vwr9xNxuIaxhV5ckzhw-1; Thu, 22 May 2025 14:31:29 -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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A34D01956089; Thu, 22 May 2025 18:31:28 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.45.226.76]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 554621944DFF; Thu, 22 May 2025 18:31:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747938693; 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=5PEAZpbs5TWoCFtJJ9kIYanvD3S/LIcCEWPEtqoAb7E=; b=BCEeuyWNZLNFqG0Pg4uTvzlqk6lBKngEOcCOdCUCSqqwy22hERAOnCX2VHzIQ9jnPMvS51 ZRFTSHtxrL0cC94mzBgSOukolJnHEsUxtsqIMFwdAghzWazA5ZqQGZI37aDYqjQl6BDA4u /cc1r9Cy/q5b11hPtBoQnEmqN2I8Mfg= X-MC-Unique: jd_Vwr9xNxuIaxhV5ckzhw-1 X-Mimecast-MFC-AGG-ID: jd_Vwr9xNxuIaxhV5ckzhw_1747938688 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 5/5] file-posix: Probe paths and retry SG_IO on potential path errors Date: Thu, 22 May 2025 20:31:15 +0200 Message-ID: <20250522183115.246746-6-kwolf@redhat.com> In-Reply-To: <20250522183115.246746-1-kwolf@redhat.com> References: <20250522183115.246746-1-kwolf@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=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.275, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1747938762356116600 Content-Type: text/plain; charset="utf-8" When scsi-block is used on a host multipath device, it runs into the problem that the kernel dm-mpath doesn't know anything about SCSI or SG_IO and therefore can't decide if a SG_IO request returned an error and needs to be retried on a different path. Instead of getting working failover, an error is returned to scsi-block and handled according to the configured error policy. Obviously, this is not what users want, they want working failover. QEMU can parse the SG_IO result and determine whether this could have been a path error, but just retrying the same request could just send it to the same failing path again and result in the same error. With a kernel that supports the DM_MPATH_PROBE_PATHS ioctl on dm-mpath block devices (queued in the device mapper tree for Linux 6.16), we can tell the kernel to probe all paths and tell us if any usable paths remained. If so, we can now retry the SG_IO ioctl and expect it to be sent to a working path. Signed-off-by: Kevin Wolf Message-ID: <20250522130803.34738-1-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi Reviewed-by: Hanna Czenczek Signed-off-by: Kevin Wolf --- block/file-posix.c | 115 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/block/file-posix.c b/block/file-posix.c index 5a3532e40b..9b5f08ccb2 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -41,6 +41,7 @@ =20 #include "scsi/pr-manager.h" #include "scsi/constants.h" +#include "scsi/utils.h" =20 #if defined(__APPLE__) && (__MACH__) #include @@ -72,6 +73,7 @@ #include #endif #include +#include #include #include #include @@ -138,6 +140,22 @@ #define RAW_LOCK_PERM_BASE 100 #define RAW_LOCK_SHARED_BASE 200 =20 +/* + * Multiple retries are mostly meant for two separate scenarios: + * + * - DM_MPATH_PROBE_PATHS returns success, but before SG_IO completes, ano= ther + * path goes down. + * + * - DM_MPATH_PROBE_PATHS failed all paths in the current path group, so w= e have + * to send another SG_IO to switch to another path group to probe the pa= ths in + * it. + * + * Even if each path is in a separate path group (path_grouping_policy set= to + * failover), it's rare to have more than eight path groups - and even then + * pretty unlikely that only bad path groups would be chosen in eight retr= ies. + */ +#define SG_IO_MAX_RETRIES 8 + typedef struct BDRVRawState { int fd; bool use_lock; @@ -165,6 +183,7 @@ typedef struct BDRVRawState { bool use_linux_aio:1; bool has_laio_fdsync:1; bool use_linux_io_uring:1; + bool use_mpath:1; int page_cache_inconsistent; /* errno from fdatasync failure */ bool has_fallocate; bool needs_alignment; @@ -4253,15 +4272,105 @@ hdev_open_Mac_error: /* Since this does ioctl the device must be already opened */ bs->sg =3D hdev_is_sg(bs); =20 + /* sg devices aren't even block devices and can't use dm-mpath */ + s->use_mpath =3D !bs->sg; + return ret; } =20 #if defined(__linux__) +#if defined(DM_MPATH_PROBE_PATHS) +static bool coroutine_fn sgio_path_error(int ret, sg_io_hdr_t *io_hdr) +{ + if (ret < 0) { + switch (ret) { + case -ENODEV: + return true; + case -EAGAIN: + /* + * The device is probably suspended. This happens while the dm= table + * is reloaded, e.g. because a path is added or removed. This = is an + * operation that should complete within 1ms, so just wait a b= it and + * retry. + * + * If the device was suspended for another reason, we'll wait = and + * retry SG_IO_MAX_RETRIES times. This is a tolerable delay be= fore + * we return an error and potentially stop the VM. + */ + qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 1000000); + return true; + default: + return false; + } + } + + if (io_hdr->host_status !=3D SCSI_HOST_OK) { + return true; + } + + switch (io_hdr->status) { + case GOOD: + case CONDITION_GOOD: + case INTERMEDIATE_GOOD: + case INTERMEDIATE_C_GOOD: + case RESERVATION_CONFLICT: + case COMMAND_TERMINATED: + return false; + case CHECK_CONDITION: + return !scsi_sense_buf_is_guest_recoverable(io_hdr->sbp, + io_hdr->mx_sb_len); + default: + return true; + } +} + +static bool coroutine_fn hdev_co_ioctl_sgio_retry(RawPosixAIOData *acb, in= t ret) +{ + BDRVRawState *s =3D acb->bs->opaque; + RawPosixAIOData probe_acb; + + if (!s->use_mpath) { + return false; + } + + if (!sgio_path_error(ret, acb->ioctl.buf)) { + return false; + } + + probe_acb =3D (RawPosixAIOData) { + .bs =3D acb->bs, + .aio_type =3D QEMU_AIO_IOCTL, + .aio_fildes =3D s->fd, + .aio_offset =3D 0, + .ioctl =3D { + .buf =3D NULL, + .cmd =3D DM_MPATH_PROBE_PATHS, + }, + }; + + ret =3D raw_thread_pool_submit(handle_aiocb_ioctl, &probe_acb); + if (ret =3D=3D -ENOTTY) { + s->use_mpath =3D false; + } else if (ret =3D=3D -EAGAIN) { + /* The device might be suspended for a table reload, worth retryin= g */ + return true; + } + + return ret =3D=3D 0; +} +#else +static bool coroutine_fn hdev_co_ioctl_sgio_retry(RawPosixAIOData *acb, in= t ret) +{ + return false; +} +#endif /* DM_MPATH_PROBE_PATHS */ + static int coroutine_fn hdev_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) { BDRVRawState *s =3D bs->opaque; RawPosixAIOData acb; + int retries =3D SG_IO_MAX_RETRIES; int ret; =20 ret =3D fd_open(bs); @@ -4289,7 +4398,11 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long in= t req, void *buf) }, }; =20 - return raw_thread_pool_submit(handle_aiocb_ioctl, &acb); + do { + ret =3D raw_thread_pool_submit(handle_aiocb_ioctl, &acb); + } while (req =3D=3D SG_IO && retries-- && hdev_co_ioctl_sgio_retry(&ac= b, ret)); + + return ret; } #endif /* linux */ =20 --=20 2.49.0