From nobody Mon Feb 9 20:10:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539897162616543.0051042270387; Thu, 18 Oct 2018 14:12:42 -0700 (PDT) Received: from localhost ([::1]:44725 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFaz-0007nS-C7 for importer@patchew.org; Thu, 18 Oct 2018 17:12:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyO-0007Pq-6b for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyL-0006Oe-B2 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:46 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:36668) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyJ-0006Lt-OC for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:45 -0400 Received: by mail-wm1-x331.google.com with SMTP id a8-v6so1627157wmf.1 for ; Thu, 18 Oct 2018 13:32:42 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=XSiDpnE8bYM/w7cuyzvbLsyMuqjABwgLix3HENtrn2Y=; b=Dfkr5M9qSaG0fCkBkKjr78KHHeFd6DJy9g5MT3jTmfYrWc6gnsDpUM5GIvbhPeiUm6 83sS2/6OMS5S5b6w521bauBPeHlax20XiBG6iHL8/y/LhUfV0pR2OzssKV04bRVxXLed f5HJ/sO15b2IC8pa990/92hSYPhUYbGfp4Ep5kgj5RFODdx9Zv5fxI3KMw7Ss8TuLHqZ PNm7fK8qQ9lv1XoUN9RyBokG+lxqAYnUrDsrYb+crOb428FveyXKqKW66nLx8ZEevTKZ VnVqbqy7ejqWZycVajQtrk95n/KInXOm0K3xPsFTzewrEM0LLKxooQv9zG1+63fhyriX gqQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=XSiDpnE8bYM/w7cuyzvbLsyMuqjABwgLix3HENtrn2Y=; b=sdv2bxfuzTQmXg42HcAAxzp8o6xI8PUS+SA8p2Ld6V7Fbe71Rs+B+oeHXQm6QBIv3C fOqJrSY05LOI1/ZTmz4bn65fq2O5DqSnnkZY4hT/1HDmA+hJpLpY7tZnt9xs9G/gFQxN KyXiFdZTRja0EWwAjKEmBuA9YorwhQByREZhDoV51PumEBOXoOY5RYBnlsIjiDav4XZB hwFcNB8ZGqyrU+zY27ELUNdRZjy9oWjU/EyxNhAwWkXiAc+a9rjVgns1f/d1V+pndl9g f1pv4uM78YEiCobSoKoDhaiM39CGa7XZtsHDEVmPKSNpUJ1B1a2seMFAEnA6Jmj7ydDn ysDA== X-Gm-Message-State: ABuFfoh2XQdVy5C0om0UTMzG0GpB5vjYdHo6pj6t1Vv9Ydy8r0Ei/gc1 R4pBB7ET5/nEocTuFXEUHUXaYiwD X-Google-Smtp-Source: ACcGV60t2O4Trk+iFFgCOXkzBGNAfJRAV3ndFZE6TvAtQOtxRCes2ykbtKbvtArUAvNAECVJqJU1bw== X-Received: by 2002:a1c:af07:: with SMTP id y7-v6mr1939118wme.33.1539894761625; Thu, 18 Oct 2018 13:32:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:49 +0200 Message-Id: <1539894735-14232-23-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::331 Subject: [Qemu-devel] [PULL 22/48] scsi-disk: fix double completion of failing passthrough requests X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If a command fails with a sense that scsi_sense_buf_to_errno converts to ECANCELED/EAGAIN/ENOTCONN or with a unit attention, scsi_req_complete is called twice. This caused a crash. Reported-by: Wangguang Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-disk.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index c43163c..4074d7c 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -441,9 +441,18 @@ static bool scsi_handle_rw_error(SCSIDiskReq *r, int e= rror, bool acct_failed) } switch (error) { case 0: - /* The command has run, no need to fake sense. */ + /* A passthrough command has run and has produced sense data; = check + * whether the error has to be handled by the guest or should = rather + * pause the host. + */ assert(r->status && *r->status); - scsi_req_complete(&r->req, *r->status); + error =3D scsi_sense_buf_to_errno(r->req.sense, sizeof(r->req.= sense)); + if (error =3D=3D ECANCELED || error =3D=3D EAGAIN || error =3D= =3D ENOTCONN || + error =3D=3D 0) { + /* These errors are handled by guest. */ + scsi_req_complete(&r->req, *r->status); + return true; + } break; case ENOMEDIUM: scsi_check_condition(r, SENSE_CODE(NO_MEDIUM)); @@ -462,17 +471,6 @@ static bool scsi_handle_rw_error(SCSIDiskReq *r, int e= rror, bool acct_failed) break; } } - if (!error) { - assert(r->status && *r->status); - error =3D scsi_sense_buf_to_errno(r->req.sense, sizeof(r->req.sens= e)); - - if (error =3D=3D ECANCELED || error =3D=3D EAGAIN || error =3D=3D = ENOTCONN || - error =3D=3D 0) { - /* These errors are handled by guest. */ - scsi_req_complete(&r->req, *r->status); - return true; - } - } =20 blk_error_action(s->qdev.conf.blk, action, is_read, error); if (action =3D=3D BLOCK_ERROR_ACTION_STOP) { --=20 1.8.3.1