Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp977468ybt; Wed, 17 Jun 2020 19:42:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxMHy8CWlxn/Ha2PXGS/goqM9tTN2lRCR+Kex6c8TXApTZG1eShINkaSFEcDpYJiJFlnn2e X-Received: by 2002:a05:6402:221b:: with SMTP id cq27mr1958532edb.302.1592448178112; Wed, 17 Jun 2020 19:42:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592448178; cv=none; d=google.com; s=arc-20160816; b=C4GWQ2ZECqxrigD7hmmEeDO9xa2879HpkevmgtKUKnV0oXRqFQMWBoLD53ysYrzT2u 2FuGlosIIjHzswJNG8GspamTnxRUJuB18jrKKy9UisiV2f4UGxYHPu/3FYzrr8p903Sp eYy/L1ELAZs8LY39w+PQsLX3X+zTSGLjkXbZVI9SvMS7x9BIcvPed89t8UCL8NwCMKuY Ld93/6NMKBiAFsFKhwGLTLowm9OEtpCo/BwYu59kcnnFzcAAhmCP9IEoWPF3KrT5uxCn QU0a1tbNJR0Gfn0PojDCb/diOwuZa7joON8kFIiPBmRoCmJoET7sUDkU912sDc3AFeyD qzIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=//gMPZe5Knb5OzdbQyiCBGnB8pR4el/eySlQCMgpgAc=; b=f1yhuzmE7B7i55y7dYqMK4ePh5PUscwEO95bDqPYr18VOuEXv65AVR0aOF66myqRYQ UjgncP1b04czZDf8/ZAl9ZV3184FFW/SQMclM0A62t6NMg1glgEQypOqSuecCXwS2vuv HJaujsk5QFe843o98AwJLpqfl+oheBVcttcTqkSHRnR2CV4cKcLM5qwkt0bTejkE/mks sLtUN1U+Kr3sv3m3F7hrIzA+HWiho14Ji4REJWCSBpVfOQCsKKNDZ4WKAO1sgIZ793Ux InFl4QWhCLY31aSo0FsateZWqYj1+m9BfHSLRuxEDN449FAsJk5R3vgnMGT5VKEF2ymr tQkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BBWMPVsH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id si26si1100460ejb.151.2020.06.17.19.42.36; Wed, 17 Jun 2020 19:42:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BBWMPVsH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729055AbgFRBNL (ORCPT + 99 others); Wed, 17 Jun 2020 21:13:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:40638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728003AbgFRBML (ORCPT ); Wed, 17 Jun 2020 21:12:11 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6EDC121974; Thu, 18 Jun 2020 01:12:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592442730; bh=n77+mRGJzhZkF3sMpgr1Vq43gLpGDv+qKc9vyAuvuic=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BBWMPVsHr1befN8TNPY2htXhwn39vqM1E8in6+14n/O7J62tMis8TlDOK63IkWzc3 M6U4VtpyoVw65dB4ouG9pqRClewh1mtf/o4KnuDbN0CjiaZDQ/c/35plLzoYlWoG4q 7JVzVMIe9cky9fMEJEtEIQA0ppV3fJ+mO8T4JxEQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Bodo Stroesser , "Martin K . Petersen" , Sasha Levin , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 186/388] scsi: target: loopback: Fix READ with data and sensebytes Date: Wed, 17 Jun 2020 21:04:43 -0400 Message-Id: <20200618010805.600873-186-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200618010805.600873-1-sashal@kernel.org> References: <20200618010805.600873-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bodo Stroesser [ Upstream commit c68a56736c129f5dd1632856956f9c3e04bae200 ] We use tcm_loop with tape emulations running on tcmu. In case application reads a short tape block with a longer READ, or a long tape block with a short READ, according to SCC spec data has to be tranferred _and_ sensebytes with ILI set and information field containing the residual count. Similar problem also exists when using fixed block size in READ. Up to now tcm_loop is not prepared to handle sensebytes if input data is provided, as in tcm_loop_queue_data_in() it only sets SAM_STAT_GOOD and, if necessary, the residual count. To fix the bug, the same handling for sensebytes as present in tcm_loop_queue_status() must be done in tcm_loop_queue_data_in() also. After adding this handling, the two function now are nearly identical, so I created a single function with two wrappers. Link: https://lore.kernel.org/r/20200428182617.32726-1-bstroesser@ts.fujitsu.com Signed-off-by: Bodo Stroesser Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/target/loopback/tcm_loop.c | 36 +++++++++++++----------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c index 3305b47fdf53..16d5a4e117a2 100644 --- a/drivers/target/loopback/tcm_loop.c +++ b/drivers/target/loopback/tcm_loop.c @@ -545,32 +545,15 @@ static int tcm_loop_write_pending(struct se_cmd *se_cmd) return 0; } -static int tcm_loop_queue_data_in(struct se_cmd *se_cmd) +static int tcm_loop_queue_data_or_status(const char *func, + struct se_cmd *se_cmd, u8 scsi_status) { struct tcm_loop_cmd *tl_cmd = container_of(se_cmd, struct tcm_loop_cmd, tl_se_cmd); struct scsi_cmnd *sc = tl_cmd->sc; pr_debug("%s() called for scsi_cmnd: %p cdb: 0x%02x\n", - __func__, sc, sc->cmnd[0]); - - sc->result = SAM_STAT_GOOD; - set_host_byte(sc, DID_OK); - if ((se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) || - (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT)) - scsi_set_resid(sc, se_cmd->residual_count); - sc->scsi_done(sc); - return 0; -} - -static int tcm_loop_queue_status(struct se_cmd *se_cmd) -{ - struct tcm_loop_cmd *tl_cmd = container_of(se_cmd, - struct tcm_loop_cmd, tl_se_cmd); - struct scsi_cmnd *sc = tl_cmd->sc; - - pr_debug("%s() called for scsi_cmnd: %p cdb: 0x%02x\n", - __func__, sc, sc->cmnd[0]); + func, sc, sc->cmnd[0]); if (se_cmd->sense_buffer && ((se_cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) || @@ -581,7 +564,7 @@ static int tcm_loop_queue_status(struct se_cmd *se_cmd) sc->result = SAM_STAT_CHECK_CONDITION; set_driver_byte(sc, DRIVER_SENSE); } else - sc->result = se_cmd->scsi_status; + sc->result = scsi_status; set_host_byte(sc, DID_OK); if ((se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) || @@ -591,6 +574,17 @@ static int tcm_loop_queue_status(struct se_cmd *se_cmd) return 0; } +static int tcm_loop_queue_data_in(struct se_cmd *se_cmd) +{ + return tcm_loop_queue_data_or_status(__func__, se_cmd, SAM_STAT_GOOD); +} + +static int tcm_loop_queue_status(struct se_cmd *se_cmd) +{ + return tcm_loop_queue_data_or_status(__func__, + se_cmd, se_cmd->scsi_status); +} + static void tcm_loop_queue_tm_rsp(struct se_cmd *se_cmd) { struct tcm_loop_cmd *tl_cmd = container_of(se_cmd, -- 2.25.1