From patchwork Fri Jul 21 16:01:32 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: 705572 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 1B921C001DC for ; Fri, 21 Jul 2023 16:02:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232437AbjGUQCj (ORCPT ); Fri, 21 Jul 2023 12:02:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232434AbjGUQCX (ORCPT ); Fri, 21 Jul 2023 12:02:23 -0400 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE2323A90; Fri, 21 Jul 2023 09:02:16 -0700 (PDT) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1b8a462e0b0so13399065ad.3; Fri, 21 Jul 2023 09:02:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689955336; x=1690560136; 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=zyAlTrXUN+hI+1p5Q65ZUZ9TvfaGx2yL/aNs/62Y+S8=; b=VsyDJtBVVf8M6+oKkRXevXwgk0DSTTowOpz7Nd1HQ8qy+GgGSRqNdcfugOdNeNgMnt fFir+txJB7nFcp6ZXv+1t9Z6imbuOtxM6OlnkgplIBmpw1FlraDeYOfWyn7Yw9XPyBbK m7QVjF3eNOexmYMN3umSU/upGhyMbmL21y1C+k1XW+VOarrfoqsvWwtkGcMZU6xAH/Id AuadLp91YZoZDY3TYO37mJFSLVGDBSsu5xGER+IrOW2ziEP7JJXo8oXL+gOB6hMZ+vji ZEUPpZqacv6+zlzKZ6Dw3FaM3krspcqSwXJRiJLTxMvkBmcUQ1cjiru/N3kxT1EN5bA1 FBBg== X-Gm-Message-State: ABy/qLa2jXYlI8UXoAHfi+tBROu9cLeQkTZ4l1oJshvTDd6meH6amUYS kYyW1IzQEF89H4KtlEnTyRI= X-Google-Smtp-Source: APBJJlHODPzNU/VamsP21G56Ht8TKok12UYA9F2N0pHodabwqW+/xlg4SiSl6pqamACm87q8TlqRzw== X-Received: by 2002:a17:902:ce84:b0:1b8:6b17:9093 with SMTP id f4-20020a170902ce8400b001b86b179093mr2002048plg.1.1689955336125; Fri, 21 Jul 2023 09:02:16 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:5043:9124:70cb:43f9]) by smtp.gmail.com with ESMTPSA id s24-20020a170902a51800b001b890b3bbb1sm3652298plq.211.2023.07.21.09.02.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 09:02:15 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Damien Le Moal , Hannes Reinecke , Douglas Gilbert , stable@vger.kernel.org, Jonathan Corbet , John Garry , Benjamin Block Subject: [PATCH 1/3] scsi: core: Fix the scsi_set_resid() documentation Date: Fri, 21 Jul 2023 09:01:32 -0700 Message-ID: <20230721160154.874010-2-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230721160154.874010-1-bvanassche@acm.org> References: <20230721160154.874010-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Because scsi_finish_command() subtracts the residual from the buffer length, residual overflows must not be reported. Reflect this in the SCSI documentation. See also commit 9237f04e12cc ("scsi: core: Fix scsi_get/set_resid() interface") Cc: Damien Le Moal Cc: Hannes Reinecke Cc: Douglas Gilbert Cc: stable@vger.kernel.org Signed-off-by: Bart Van Assche --- Documentation/scsi/scsi_mid_low_api.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/scsi/scsi_mid_low_api.rst b/Documentation/scsi/scsi_mid_low_api.rst index 6fa3a6279501..022198c51350 100644 --- a/Documentation/scsi/scsi_mid_low_api.rst +++ b/Documentation/scsi/scsi_mid_low_api.rst @@ -1190,11 +1190,11 @@ Members of interest: - pointer to scsi_device object that this command is associated with. resid - - an LLD should set this signed integer to the requested + - an LLD should set this unsigned integer to the requested transfer length (i.e. 'request_bufflen') less the number of bytes that are actually transferred. 'resid' is preset to 0 so an LLD can ignore it if it cannot detect - underruns (overruns should be rare). If possible an LLD + underruns (overruns should not be reported). An LLD should set 'resid' prior to invoking 'done'. The most interesting case is data transfers from a SCSI target device (e.g. READs) that underrun. From patchwork Fri Jul 21 16:01:33 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: 705571 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 DFC21C001DC for ; Fri, 21 Jul 2023 16:03:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231815AbjGUQDK (ORCPT ); Fri, 21 Jul 2023 12:03:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232431AbjGUQCg (ORCPT ); Fri, 21 Jul 2023 12:02:36 -0400 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 844C22D7F for ; Fri, 21 Jul 2023 09:02:31 -0700 (PDT) Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1b8bd586086so15808095ad.2 for ; Fri, 21 Jul 2023 09:02:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689955351; x=1690560151; 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=zCam48Zy12ubzkeKJVe9IPNcRK9PBBPRsiE2hWsbUYw=; b=fBVn4OTF2lOqqo4K+NBO8Ehy+y/5+qptPGOwkYYTYdSu6u4z8dMxuNB0Zulasz2E3V 2tBzW4Ty/UB03kpe2z9BKJxBOALpVQEPC5SJjKU3xUV/6pOo2RcRWtNx54/iz/KIzwY6 0hPKUffqyrCW1YrKNP3WovmXXyDKo0BcbPjazGUBUtMb/OAc7wFrMVB0JLQ8M1nrRnNq Td9cISRztstEe4GxzhkN2kbEjxe9t9Mk5e+No1D2Mt5wa7cgtrrMmwY9BOY1hOd1hzcK MrwvT3nYl31aEuWb7ID+G000GzU/Wd5zoXaQfbkU3yBQBsZjqWEFj2i35BJZsZa1eaLR AYLg== X-Gm-Message-State: ABy/qLYWdhz6Vx48yRamFi5jxVsfMhWjIeBzSH95DDjV1k+W9czR1nKJ ZzOnBQBBYmjSVXxnVM65Ou0Ady9Mo8w= X-Google-Smtp-Source: APBJJlF0CMxEXcZSeJHQCu95Ry5GWpTLa6nvq9z2efezK7p83bOklNCacTYT6WgTyf4CscSdwGnbSA== X-Received: by 2002:a17:902:a986:b0:1b8:954c:1f6 with SMTP id bh6-20020a170902a98600b001b8954c01f6mr1950632plb.36.1689955350768; Fri, 21 Jul 2023 09:02:30 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:5043:9124:70cb:43f9]) by smtp.gmail.com with ESMTPSA id s24-20020a170902a51800b001b890b3bbb1sm3652298plq.211.2023.07.21.09.02.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 09:02:30 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Avri Altman , Adrian Hunter , "James E.J. Bottomley" , Stanley Chu , Can Guo , Asutosh Das , "Bao D. Nguyen" , Bean Huo , Arthur Simchaev , Manivannan Sadhasivam Subject: [PATCH 2/3] scsi: ufs: Fix residual handling Date: Fri, 21 Jul 2023 09:01:33 -0700 Message-ID: <20230721160154.874010-3-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230721160154.874010-1-bvanassche@acm.org> References: <20230721160154.874010-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 | 19 ++++++++++++++++--- include/ufs/ufs.h | 6 ++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index e31242fe0518..b27372f9b488 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -5241,12 +5241,25 @@ static inline int ufshcd_transfer_rsp_status(struct ufs_hba *hba, struct ufshcd_lrb *lrbp, struct cq_entry *cqe) { + bool overflow, underflow; + u8 upiu_flags; int result = 0; int scsi_status; enum utp_ocs ocs; - - scsi_set_resid(lrbp->cmd, - be32_to_cpu(lrbp->ucd_rsp_ptr->sr.residual_transfer_count)); + u32 resid; + + upiu_flags = be32_to_cpu(lrbp->ucd_rsp_ptr->header.dword_0) >> 16; + overflow = upiu_flags & UPIU_RSP_FLAG_OVERFLOW; + underflow = upiu_flags & UPIU_RSP_FLAG_UNDERFLOW; + resid = be32_to_cpu(lrbp->ucd_rsp_ptr->sr.residual_transfer_count); + WARN_ON_ONCE(overflow && underflow); + WARN_ON_ONCE(!overflow && !underflow && resid); + /* + * Test !overflow instead of underflow to support UFS devices that do + * not set either flag. + */ + if (!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 8316e2408ac3..bee5ccc6e7ce 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 Fri Jul 21 16:01:34 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: 705198 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 5A3B4EB64DC for ; Fri, 21 Jul 2023 16:03:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230013AbjGUQDJ (ORCPT ); Fri, 21 Jul 2023 12:03:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232460AbjGUQCh (ORCPT ); Fri, 21 Jul 2023 12:02:37 -0400 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 081E32D47 for ; Fri, 21 Jul 2023 09:02:33 -0700 (PDT) Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1b8ad9eede0so15788625ad.1 for ; Fri, 21 Jul 2023 09:02:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689955352; x=1690560152; 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=mCdn0wxoAOd/5kN6Rj7cJjXfquZCynL9QtjPE83cZs049QZrynVMS45ikR50hWLTun bW4t1NX/cWTCHxhuh4lucaAFIGneJtbaXkGvCMKxduPOq2VjqHYv1CfAFWBQRpQ1JaSH xZB1LmjCW2hm5ZrYszcvHJpksHrT22qgLapGuDKYTYPOSXp0OisUSfDkiUVj9bismzui NE6dR37z2ySGnLxsS/guHQT3bxAQmUXoomasM/Vy9HIEpEl1w2vqYzz8rK3VLKliRQF2 A4lSnEQIKgXpuFyBPB0VzIboBC9t8smxBuFgjZ2e2limF4H8Uh2fuIaAsNDhrjjFrFUX 5Gfw== X-Gm-Message-State: ABy/qLb2yHtkY6GFG2jsPdUODLlzkuQE0UErnVPBTV3yrUowxecgqTjv JJIvfcQneZedilmNendvjGKmjX1P4cw= X-Google-Smtp-Source: APBJJlGJCnceOKiitkUMC2jGEbltxlSYiFyMCItztzwIab1+/bZDrZ5oqOqJmH+djWjrbsu+qVvPUg== X-Received: by 2002:a17:902:e9cb:b0:1bb:3e35:6416 with SMTP id 11-20020a170902e9cb00b001bb3e356416mr2346311plk.56.1689955352316; Fri, 21 Jul 2023 09:02:32 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:5043:9124:70cb:43f9]) by smtp.gmail.com with ESMTPSA id s24-20020a170902a51800b001b890b3bbb1sm3652298plq.211.2023.07.21.09.02.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jul 2023 09:02:31 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Leon Romanovsky , Jason Gunthorpe , Jason Gunthorpe , Damien Le Moal , Sagi Grimberg , Roland Dreier , David Dillow Subject: [PATCH 3/3] RDMA/srp: Fix residual handling Date: Fri, 21 Jul 2023 09:01:34 -0700 Message-ID: <20230721160154.874010-4-bvanassche@acm.org> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog In-Reply-To: <20230721160154.874010-1-bvanassche@acm.org> References: <20230721160154.874010-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 --- 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));