From patchwork Mon Jul 24 20:08:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 706899 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B00D9C001B0 for ; Mon, 24 Jul 2023 20:09:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229505AbjGXUJW (ORCPT ); Mon, 24 Jul 2023 16:09:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230429AbjGXUJU (ORCPT ); Mon, 24 Jul 2023 16:09:20 -0400 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 479DA10EC for ; Mon, 24 Jul 2023 13:09:20 -0700 (PDT) Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6726d5d92afso3782220b3a.1 for ; Mon, 24 Jul 2023 13:09:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690229360; x=1690834160; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6zmVElk4V6/0P8yn/quCuVnpnhtsVZ3Lp51ih5wasWI=; b=GrcLz7rFhjlLnuRo1o1BD8vD5iEVoG4olWGJmQYDqPOPtvpTdgApUPbTwYAy4AqpTq bxEpLQUk5vlX8u2INwuR4cEM/UgGEBdrO5K7V9Wi9X5GBG+ZCb7yN6zvWEU5uH5g4V0W Sk90UrAnEQpx2DQj6ubi0ToDWBIdF/dZE6PSw+RdzeuhUN+lhQ2v4077J/OAYLrXHI8S wtN1AsxhC+FHQEMK6Sol58vwf7vS+Vv2aSThfYCgFoILlhCH24MSjzl/Sn1jbnoRBMPR ZBD/eozo4zpxD/A+/fyBtc4gEiNck+iZBF0hRHvOSuawmF0TX7xWWVyqhx+xoEZGrSNr nz4w== X-Gm-Message-State: ABy/qLbEk7dcPAQUgM3RCirs0BFuiAsTu5rszM2c0OvUoeChZ24Or4QF VMP9Qyu60GtZfC+UvQPt8B0= X-Google-Smtp-Source: APBJJlFeWy7Qc0qGn3JGh6uhX4UmrypG7fjjZsZcNaYObyWcEVjU8T37GyKIqbe+plebRqe3I87AuA== X-Received: by 2002:a17:90b:4b05:b0:268:1911:a1d1 with SMTP id lx5-20020a17090b4b0500b002681911a1d1mr337805pjb.4.1690229359633; Mon, 24 Jul 2023 13:09:19 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:bda6:6519:2a73:345e]) by smtp.gmail.com with ESMTPSA id e23-20020a17090ab39700b002609cadc56esm6726861pjr.11.2023.07.24.13.09.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 13:09:19 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Avri Altman , Adrian Hunter , Bart Van Assche , "James E.J. Bottomley" , Stanley Chu , Can Guo , Asutosh Das , "Bao D. Nguyen" , Bean Huo , Arthur Simchaev Subject: [PATCH v2 1/2] scsi: ufs: Fix residual handling Date: Mon, 24 Jul 2023 13:08:29 -0700 Message-ID: <20230724200843.3376570-2-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230724200843.3376570-1-bvanassche@acm.org> References: <20230724200843.3376570-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Only call scsi_set_resid() in case of an underflow. Do not call scsi_set_resid() in case of an overflow. Cc: Avri Altman Cc: Adrian Hunter Fixes: cb38845d90fc ("scsi: ufs: core: Set the residual byte count") Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 12 ++++++++++-- include/ufs/ufs.h | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index c394dc50504a..27e1a4914837 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -5222,9 +5222,17 @@ ufshcd_transfer_rsp_status(struct ufs_hba *hba, struct ufshcd_lrb *lrbp, int result = 0; int scsi_status; enum utp_ocs ocs; + u8 upiu_flags; + u32 resid; - scsi_set_resid(lrbp->cmd, - be32_to_cpu(lrbp->ucd_rsp_ptr->sr.residual_transfer_count)); + upiu_flags = be32_to_cpu(lrbp->ucd_rsp_ptr->header.dword_0) >> 16; + resid = be32_to_cpu(lrbp->ucd_rsp_ptr->sr.residual_transfer_count); + /* + * Test !overflow instead of underflow to support UFS devices that do + * not set either flag. + */ + if (resid && !(upiu_flags & UPIU_RSP_FLAG_OVERFLOW)) + scsi_set_resid(lrbp->cmd, resid); /* overall command status of utrd */ ocs = ufshcd_get_tr_ocs(lrbp, cqe); diff --git a/include/ufs/ufs.h b/include/ufs/ufs.h index 0dd546a20503..c789252b5fad 100644 --- a/include/ufs/ufs.h +++ b/include/ufs/ufs.h @@ -104,6 +104,12 @@ enum { UPIU_CMD_FLAGS_READ = 0x40, }; +/* UPIU response flags */ +enum { + UPIU_RSP_FLAG_UNDERFLOW = 0x20, + UPIU_RSP_FLAG_OVERFLOW = 0x40, +}; + /* UPIU Task Attributes */ enum { UPIU_TASK_ATTR_SIMPLE = 0x00, From patchwork Mon Jul 24 20:08:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 706068 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13A1EC41513 for ; Mon, 24 Jul 2023 20:09:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230147AbjGXUJX (ORCPT ); Mon, 24 Jul 2023 16:09:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229929AbjGXUJW (ORCPT ); Mon, 24 Jul 2023 16:09:22 -0400 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF26F10D9 for ; Mon, 24 Jul 2023 13:09:21 -0700 (PDT) Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-517ab9a4a13so3353425a12.1 for ; Mon, 24 Jul 2023 13:09:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690229361; x=1690834161; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=khmFSi//VDGaMV5tP25J15l0jgygMFTCGaN0qRY+97s=; b=GaSBuXfa8iOvbznLWeDO4hyCAySkF/RsfgdYNIkga5LWqSuNdHbo3fmFseNriZpTR7 d+lDYmvytqPWSPSiJmAmRquCIzNdojNN7OawswoZyIJ3YKOsqzDd8EK6LOKWZ9QDH82r f/DrCmlEpPhlNa4i6Bg35hBhGKrj03AI50umltYfGaf05UVg82X3R8/FPI2hONfDnREy 3y3DxAue9I+I5c+3Qf5eXxsNyzukzlFlO+eiUH38jfRoauHzSy5B3LD5Ugiy2Cdpry+M 2e6L+PBb0Tyowuo1UiISIox8zTZ/cWK8tzgEdZsepBUJ5ETUZ3g8IXAIPMobFxKzlWPA UZpg== X-Gm-Message-State: ABy/qLYYA3B/8ym+L599ct8HrmfLEeVX+cuY1tzBdOMZ9CpiyNnhF3Nb RbnFK2/PVVrIqZJeyGpDZKg= X-Google-Smtp-Source: APBJJlFYrxqkyhRmDy68/6v4h0WFmhkoHylw144XOXBKHM2A2O/8xsl3nSCaFcSv2mA+CrA+Yvbc5Q== X-Received: by 2002:a17:90a:9c09:b0:263:f583:a6a1 with SMTP id h9-20020a17090a9c0900b00263f583a6a1mr10696721pjp.34.1690229361076; Mon, 24 Jul 2023 13:09:21 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:bda6:6519:2a73:345e]) by smtp.gmail.com with ESMTPSA id e23-20020a17090ab39700b002609cadc56esm6726861pjr.11.2023.07.24.13.09.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 13:09:20 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Avri Altman , Adrian Hunter , Bart Van Assche , Leon Romanovsky , Jason Gunthorpe , Jason Gunthorpe , Damien Le Moal , Sagi Grimberg , David Dillow , Roland Dreier Subject: [PATCH v2 2/2] RDMA/srp: Fix residual handling Date: Mon, 24 Jul 2023 13:08:30 -0700 Message-ID: <20230724200843.3376570-3-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230724200843.3376570-1-bvanassche@acm.org> References: <20230724200843.3376570-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Although the code for residual handling in the SRP initiator follows the SCSI documentation, that documentation has never been correct. Because scsi_finish_command() starts from the data buffer length and subtracts the residual, scsi_set_resid() must not be called if a residual overflow occurs. Hence remove the scsi_set_resid() calls from the SRP initiator if a residual overflow occurrs. Cc: Leon Romanovsky Cc: Jason Gunthorpe Fixes: 9237f04e12cc ("scsi: core: Fix scsi_get/set_resid() interface") Fixes: e714531a349f ("IB/srp: Fix residual handling") Signed-off-by: Bart Van Assche Acked-by: Leon Romanovsky --- drivers/infiniband/ulp/srp/ib_srp.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c index 0e513a7e5ac8..1574218764e0 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -1979,12 +1979,8 @@ static void srp_process_rsp(struct srp_rdma_ch *ch, struct srp_rsp *rsp) if (unlikely(rsp->flags & SRP_RSP_FLAG_DIUNDER)) scsi_set_resid(scmnd, be32_to_cpu(rsp->data_in_res_cnt)); - else if (unlikely(rsp->flags & SRP_RSP_FLAG_DIOVER)) - scsi_set_resid(scmnd, -be32_to_cpu(rsp->data_in_res_cnt)); else if (unlikely(rsp->flags & SRP_RSP_FLAG_DOUNDER)) scsi_set_resid(scmnd, be32_to_cpu(rsp->data_out_res_cnt)); - else if (unlikely(rsp->flags & SRP_RSP_FLAG_DOOVER)) - scsi_set_resid(scmnd, -be32_to_cpu(rsp->data_out_res_cnt)); srp_free_req(ch, req, scmnd, be32_to_cpu(rsp->req_lim_delta));