From nobody Sat Apr 11 17:09:15 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=1775730854; cv=none; d=zohomail.com; s=zohoarc; b=LN/grMRqwbgzNzL18UJArWzIUWnj/7uh2GLTsxCte8tCpW39F6c2iPDPJehAfx5CWkDfLbXzqN5JoWyxRR961kzRrH2XbgQq9+HuayDVsUytW8F5+MSzmzmmdlI64xjf3BxRiMBKwDYacdV1S3iC7u6QWVzWGAloxnA7fmAi7C0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775730854; 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=K6wVzzxEUdru13XNf+9PuoXL/B9TF0wuj0LinPwBVT4=; b=N/54vKNk60KUjoq/Z8/yDvcqElHKjWX/dt6GnYAENtqPX0l5INYC9PosDvUFQJ0JYFA9deosj+q0ynQ8XWccTxY4RAz7QVIzPL8QP0BpOQnP7gftJBAUvI9JrBrARYNpFmh7ZzarWrA5ex0FHJoV1G25SPTPxuS5Eeo68MNbiGA= 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 (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775730854138359.10779159046433; Thu, 9 Apr 2026 03:34:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wAmhP-00019D-Bx; Thu, 09 Apr 2026 06:33: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 1wAmhN-00018l-Tp for qemu-devel@nongnu.org; Thu, 09 Apr 2026 06:33:21 -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 1wAmhL-00009C-7t for qemu-devel@nongnu.org; Thu, 09 Apr 2026 06:33:21 -0400 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-ppFr4BtKPbGkmnyQTzf2ag-1; Thu, 09 Apr 2026 06:33:15 -0400 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-43cff5bc312so694200f8f.1 for ; Thu, 09 Apr 2026 03:33:15 -0700 (PDT) Received: from [192.168.122.1] ([151.49.85.67]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488cd23058dsm64871575e9.13.2026.04.09.03.33.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Apr 2026 03:33:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775730797; 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=K6wVzzxEUdru13XNf+9PuoXL/B9TF0wuj0LinPwBVT4=; b=XoLOGds/gbKs6otu4FCAEnPFGCEPndOALLcUCtNMupJKj9HTluW7gR6R7sO+ztz3Mv2Tai eFVgxadHjfV9jduYVYCSmdYq5m18ykSzKsn3QlcX64+/ElXc6ynvh811o7KtuF7yPOKyhF DVk1NXi3GL0k+3R/om+6itQ5QqlxV5c= X-MC-Unique: ppFr4BtKPbGkmnyQTzf2ag-1 X-Mimecast-MFC-AGG-ID: ppFr4BtKPbGkmnyQTzf2ag_1775730794 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1775730793; x=1776335593; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=K6wVzzxEUdru13XNf+9PuoXL/B9TF0wuj0LinPwBVT4=; b=N29H4NAvPyYPjTxjdQiHlPxxfc8/jJZMgQU0G+efNSOZAVGGuGlxcqM5OtwWkAcgiM sHCIsMUMzJ6/p4CEAXhSlMwQj05o1C5gnvKLUMhKGclKNdFWVzq2HK672wOI2XXUtccr P7B4SbiMsv44/h98r2CZMD9DUmNIWc8TKOzYT/aPglQUMBYYJL06csT6uGQ1Yx1DlO0t yPEd/rHuDt/mIbUts3/nBSYGcFUZUVdwv0Snp3n/XPXjC4LX8gW7RxGPP4iTQ3QHqXrV sEbBrnViHm+iCp1nlLKGhv6h2wA/HAS2QoflH9Qt0EnZmwtIqQxTjK6ISGKqhEhFTO5R /aGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775730793; x=1776335593; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=K6wVzzxEUdru13XNf+9PuoXL/B9TF0wuj0LinPwBVT4=; b=fqOwX9f2u4/2YbsYCsSlYtJr5jKqhoDHCWMpT+hZ2KogwroPwgd4F/8gkZ35h1UJ/m ix74NzD7see4EeDRmYhx+STRP0FS8fKavFOfxh0bSP+zWnVqsLWMc4Gc2SAMCsTWQt40 xJOgQLat4oyAMWWFtrwgZy9cgH2qe0I6alMMnReb5T9y4mBsJCTJaBe3dvedlkzCNtPd +/HRhJW8DFHJKUGnbCNOTClHRyj9WcGGqfxtyWZdfQt1GcAoXviBtuCjbnFXoXJcsuCI W0uBfc9ndcKqSBpnph2CIhatWZeK4VfgIAd4EF5NSYI4t607wNE7SaqCbjjlWmo0wEgo b6Cw== X-Gm-Message-State: AOJu0Yx1+8a9CcOMlKG65IrAjQzh087sOxxQLLvSVIwEK+WYChNrapFJ f46obLy/UnEanUsFyqf3KNA22xVMUN3AdO4udxGyxZa+3a9dEMebA3To44Hw/CMQCcU+jjtxEbf MZBmNdzFQT0ErgTGfZMd9Lio1f0NtHk2Sh2lOBUGJj5P5JB/OAbGSqoBmSBtJOKNpp3w26YYXn6 31AYLVnWPpkaYJmBqBdVnSlmU5uvac46RCdL5jsh7P X-Gm-Gg: AeBDieskMTLz3dchhgBFJlSoTYk+n0IcrkUYISoj7lzDv4Lv8co4566PoZOmb6qIf2K fuhGF/n+Bulkx8gG5IpH1SVI+nXwRJwnvRQFGbH7ARBDcdR3D1GIkuY91lrOsMsTeJCb+as5eO5 1M3HNipWbWvOgbjMmEIJiGr0vfT5aDL2vgNgPDsyyQb9SeZqXe1X278d9jXMFWhftkVdPfGFjhJ l94N/TyIqLGknQkncM+U54KwssM0gTnKgJcAvZcGXd3/TP2Nb/pMlbwpHUl3YoaDskwMhnhaqEB 9yfryChdcsp3gefsPQ9UMPjawTcv0H4NK+IQWDF6aSKM6yD/kNujJV/9Va6cReWnzH/SisdLj+Q lsyDt0GvdrpXkvPYS5Xg688bezWZmkc4Y2mS426G4FDfg+DfnYJcNK3SiuQnzWDdgb1NRZ4P8sB 6YLGMn4nL/m+L41lCPmgIM4J/v X-Received: by 2002:a05:600c:314d:b0:488:bc6a:5285 with SMTP id 5b1f17b1804b1-488bc6a538bmr150325595e9.30.1775730793115; Thu, 09 Apr 2026 03:33:13 -0700 (PDT) X-Received: by 2002:a05:600c:314d:b0:488:bc6a:5285 with SMTP id 5b1f17b1804b1-488bc6a538bmr150324965e9.30.1775730792543; Thu, 09 Apr 2026 03:33:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Jihe Wang , Stefan Hajnoczi Subject: [PULL 1/1] virtio-scsi: pass the same cdb_size to virtio_scsi_pop_req and virtio_scsi_handle_cmd_req_prepare Date: Thu, 9 Apr 2026 12:33:09 +0200 Message-ID: <20260409103310.1884968-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260409103310.1884968-1-pbonzini@redhat.com> References: <20260409103310.1884968-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.54, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 1775730857179154100 Content-Type: text/plain; charset="utf-8" Ensure that there is no allocation/usage mismatch when requests are processed in virtio_scsi_handle_cmd_vq. To do this, retrieve the value once and pass it to both functions. For other calls to virtio_scsi_pop_req the extra size can be 0, because control and event requests fit entirely in VirtIOSCSIReq. Reported-by: Jihe Wang Tested-by: Jihe Wang Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini --- hw/scsi/virtio-scsi.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 774968d8c70..6c737680119 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -227,16 +227,16 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req, return 0; } =20 -static VirtIOSCSIReq *virtio_scsi_pop_req(VirtIOSCSI *s, VirtQueue *vq, Qe= muMutex *vq_lock) +static VirtIOSCSIReq *virtio_scsi_pop_req(VirtIOSCSI *s, VirtQueue *vq, si= ze_t extra_req_size, + QemuMutex *vq_lock) { - VirtIOSCSICommon *vs =3D (VirtIOSCSICommon *)s; VirtIOSCSIReq *req; =20 if (vq_lock) { qemu_mutex_lock(vq_lock); } =20 - req =3D virtqueue_pop(vq, sizeof(VirtIOSCSIReq) + vs->cdb_size); + req =3D virtqueue_pop(vq, sizeof(VirtIOSCSIReq) + extra_req_size); =20 if (vq_lock) { qemu_mutex_unlock(vq_lock); @@ -682,7 +682,7 @@ static void virtio_scsi_handle_ctrl_vq(VirtIOSCSI *s, V= irtQueue *vq) { VirtIOSCSIReq *req; =20 - while ((req =3D virtio_scsi_pop_req(s, vq, &s->ctrl_lock))) { + while ((req =3D virtio_scsi_pop_req(s, vq, 0, &s->ctrl_lock))) { virtio_scsi_handle_ctrl_req(s, req); } } @@ -850,13 +850,14 @@ static void virtio_scsi_fail_cmd_req(VirtIOSCSIReq *r= eq) virtio_scsi_complete_cmd_req(req); } =20 -static int virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq= *req) +static int virtio_scsi_handle_cmd_req_prepare(VirtIOSCSI *s, VirtIOSCSIReq= *req, + size_t cdb_size) { VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(s); SCSIDevice *d; int rc; =20 - rc =3D virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + vs->cdb_s= ize, + rc =3D virtio_scsi_parse_req(req, sizeof(VirtIOSCSICmdReq) + cdb_size, sizeof(VirtIOSCSICmdResp) + vs->sense_size); if (rc < 0) { if (rc =3D=3D -ENOTSUP) { @@ -878,7 +879,7 @@ static int virtio_scsi_handle_cmd_req_prepare(VirtIOSCS= I *s, VirtIOSCSIReq *req) } req->sreq =3D scsi_req_new(d, req->req.cmd.tag, virtio_scsi_get_lun(req->req.cmd.lun), - req->req.cmd.cdb, vs->cdb_size, req); + req->req.cmd.cdb, cdb_size, req); =20 if (req->sreq->cmd.mode !=3D SCSI_XFER_NONE && (req->sreq->cmd.mode !=3D req->mode || @@ -913,12 +914,15 @@ static void virtio_scsi_handle_cmd_vq(VirtIOSCSI *s, = VirtQueue *vq) QTAILQ_HEAD(, VirtIOSCSIReq) reqs =3D QTAILQ_HEAD_INITIALIZER(reqs); =20 do { + VirtIOSCSICommon *vs =3D (VirtIOSCSICommon *)s; + size_t cdb_size =3D qatomic_read(&vs->cdb_size); + if (suppress_notifications) { virtio_queue_set_notification(vq, 0); } =20 - while ((req =3D virtio_scsi_pop_req(s, vq, NULL))) { - ret =3D virtio_scsi_handle_cmd_req_prepare(s, req); + while ((req =3D virtio_scsi_pop_req(s, vq, cdb_size, NULL))) { + ret =3D virtio_scsi_handle_cmd_req_prepare(s, req, cdb_size); if (!ret) { QTAILQ_INSERT_TAIL(&reqs, req, next); } else if (ret =3D=3D -EINVAL) { @@ -989,7 +993,7 @@ static void virtio_scsi_set_config(VirtIODevice *vdev, } =20 vs->sense_size =3D virtio_ldl_p(vdev, &scsiconf->sense_size); - vs->cdb_size =3D virtio_ldl_p(vdev, &scsiconf->cdb_size); + qatomic_set(&vs->cdb_size, virtio_ldl_p(vdev, &scsiconf->cdb_size)); } =20 static uint64_t virtio_scsi_get_features(VirtIODevice *vdev, @@ -1050,7 +1054,7 @@ static void virtio_scsi_push_event(VirtIOSCSI *s, return; } =20 - req =3D virtio_scsi_pop_req(s, vs->event_vq, &s->event_lock); + req =3D virtio_scsi_pop_req(s, vs->event_vq, 0, &s->event_lock); WITH_QEMU_LOCK_GUARD(&s->event_lock) { if (!req) { s->events_dropped =3D true; --=20 2.53.0