From patchwork Thu Oct 18 20:31:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 986305 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Dfkr5M9q"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42bhYP1Q7Gz9s5c for ; Fri, 19 Oct 2018 08:11:21 +1100 (AEDT) Received: from localhost ([::1]:44721 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFZe-0006ek-OY for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2018 17:11:18 -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) 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) 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) 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 error, 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 = scsi_sense_buf_to_errno(r->req.sense, sizeof(r->req.sense)); + if (error == ECANCELED || error == EAGAIN || error == ENOTCONN || + error == 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 error, bool acct_failed) break; } } - if (!error) { - assert(r->status && *r->status); - error = scsi_sense_buf_to_errno(r->req.sense, sizeof(r->req.sense)); - - if (error == ECANCELED || error == EAGAIN || error == ENOTCONN || - error == 0) { - /* These errors are handled by guest. */ - scsi_req_complete(&r->req, *r->status); - return true; - } - } blk_error_action(s->qdev.conf.blk, action, is_read, error); if (action == BLOCK_ERROR_ACTION_STOP) {