All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Fix residual handling in two SCSI LLDs
@ 2023-07-24 20:08 Bart Van Assche
  2023-07-24 20:08 ` [PATCH v2 1/2] scsi: ufs: Fix residual handling Bart Van Assche
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Bart Van Assche @ 2023-07-24 20:08 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: linux-scsi, Avri Altman, Adrian Hunter, Bart Van Assche

Hi Martin,

This patch series fixes the documentation of scsi_set_resid() and also fixes
residual handling in two SCSI LLDs. Please consider this patch series for the
next merge window.

Thanks,

Bart.

Changes compared to v1:
- Left out a patch that has already been queued.
- Left out the device conformance checks.

Bart Van Assche (2):
  scsi: ufs: Fix residual handling
  RDMA/srp: Fix residual handling

 drivers/infiniband/ulp/srp/ib_srp.c |  4 ----
 drivers/ufs/core/ufshcd.c           | 12 ++++++++++--
 include/ufs/ufs.h                   |  6 ++++++
 3 files changed, 16 insertions(+), 6 deletions(-)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/2] scsi: ufs: Fix residual handling
  2023-07-24 20:08 [PATCH v2 0/2] Fix residual handling in two SCSI LLDs Bart Van Assche
@ 2023-07-24 20:08 ` Bart Van Assche
  2023-07-24 20:51   ` Avri Altman
  2023-07-25 12:02   ` Adrian Hunter
  2023-07-24 20:08 ` [PATCH v2 2/2] RDMA/srp: " Bart Van Assche
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 8+ messages in thread
From: Bart Van Assche @ 2023-07-24 20:08 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: linux-scsi, Avri Altman, Adrian Hunter, Bart Van Assche,
	James E.J. Bottomley, Stanley Chu, Can Guo, Asutosh Das,
	Bao D. Nguyen, Bean Huo, Arthur Simchaev

Only call scsi_set_resid() in case of an underflow. Do not call
scsi_set_resid() in case of an overflow.

Cc: Avri Altman <avri.altman@wdc.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Fixes: cb38845d90fc ("scsi: ufs: core: Set the residual byte count")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 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,

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/2] RDMA/srp: Fix residual handling
  2023-07-24 20:08 [PATCH v2 0/2] Fix residual handling in two SCSI LLDs Bart Van Assche
  2023-07-24 20:08 ` [PATCH v2 1/2] scsi: ufs: Fix residual handling Bart Van Assche
@ 2023-07-24 20:08 ` Bart Van Assche
  2023-07-25  6:51   ` Leon Romanovsky
  2023-07-26  1:34 ` [PATCH v2 0/2] Fix residual handling in two SCSI LLDs Martin K. Petersen
  2023-07-31 19:45 ` Martin K. Petersen
  3 siblings, 1 reply; 8+ messages in thread
From: Bart Van Assche @ 2023-07-24 20:08 UTC (permalink / raw)
  To: Martin K . Petersen
  Cc: linux-scsi, Avri Altman, Adrian Hunter, Bart Van Assche,
	Leon Romanovsky, Jason Gunthorpe, Jason Gunthorpe,
	Damien Le Moal, Sagi Grimberg, David Dillow, Roland Dreier

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 <leon@kernel.org>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Fixes: 9237f04e12cc ("scsi: core: Fix scsi_get/set_resid() interface")
Fixes: e714531a349f ("IB/srp: Fix residual handling")
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 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));

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* RE: [PATCH v2 1/2] scsi: ufs: Fix residual handling
  2023-07-24 20:08 ` [PATCH v2 1/2] scsi: ufs: Fix residual handling Bart Van Assche
@ 2023-07-24 20:51   ` Avri Altman
  2023-07-25 12:02   ` Adrian Hunter
  1 sibling, 0 replies; 8+ messages in thread
From: Avri Altman @ 2023-07-24 20:51 UTC (permalink / raw)
  To: Bart Van Assche, Martin K . Petersen
  Cc: linux-scsi, Adrian Hunter, James E.J. Bottomley, Stanley Chu,
	Can Guo, Asutosh Das, Bao D. Nguyen, Bean Huo, Arthur Simchaev

> 
> Only call scsi_set_resid() in case of an underflow. Do not call
> scsi_set_resid() in case of an overflow.
> 
> Cc: Avri Altman <avri.altman@wdc.com>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Fixes: cb38845d90fc ("scsi: ufs: core: Set the residual byte count")
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Avri Altman <avri.altman@wdc.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 2/2] RDMA/srp: Fix residual handling
  2023-07-24 20:08 ` [PATCH v2 2/2] RDMA/srp: " Bart Van Assche
@ 2023-07-25  6:51   ` Leon Romanovsky
  0 siblings, 0 replies; 8+ messages in thread
From: Leon Romanovsky @ 2023-07-25  6:51 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Martin K . Petersen, linux-scsi, Avri Altman, Adrian Hunter,
	Jason Gunthorpe, Jason Gunthorpe, Damien Le Moal, Sagi Grimberg,
	David Dillow, Roland Dreier

On Mon, Jul 24, 2023 at 01:08:30PM -0700, Bart Van Assche wrote:
> 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 <leon@kernel.org>
> Cc: Jason Gunthorpe <jgg@nvidia.com>
> Fixes: 9237f04e12cc ("scsi: core: Fix scsi_get/set_resid() interface")
> Fixes: e714531a349f ("IB/srp: Fix residual handling")
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
>  drivers/infiniband/ulp/srp/ib_srp.c | 4 ----
>  1 file changed, 4 deletions(-)
> 

Thanks,
Acked-by: Leon Romanovsky <leon@kernel.org>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/2] scsi: ufs: Fix residual handling
  2023-07-24 20:08 ` [PATCH v2 1/2] scsi: ufs: Fix residual handling Bart Van Assche
  2023-07-24 20:51   ` Avri Altman
@ 2023-07-25 12:02   ` Adrian Hunter
  1 sibling, 0 replies; 8+ messages in thread
From: Adrian Hunter @ 2023-07-25 12:02 UTC (permalink / raw)
  To: Bart Van Assche, Martin K . Petersen
  Cc: linux-scsi, Avri Altman, James E.J. Bottomley, Stanley Chu,
	Can Guo, Asutosh Das, Bao D. Nguyen, Bean Huo, Arthur Simchaev

On 24/07/23 23:08, Bart Van Assche wrote:
> Only call scsi_set_resid() in case of an underflow. Do not call
> scsi_set_resid() in case of an overflow.
> 
> Cc: Avri Altman <avri.altman@wdc.com>
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Fixes: cb38845d90fc ("scsi: ufs: core: Set the residual byte count")
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  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,


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/2] Fix residual handling in two SCSI LLDs
  2023-07-24 20:08 [PATCH v2 0/2] Fix residual handling in two SCSI LLDs Bart Van Assche
  2023-07-24 20:08 ` [PATCH v2 1/2] scsi: ufs: Fix residual handling Bart Van Assche
  2023-07-24 20:08 ` [PATCH v2 2/2] RDMA/srp: " Bart Van Assche
@ 2023-07-26  1:34 ` Martin K. Petersen
  2023-07-31 19:45 ` Martin K. Petersen
  3 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2023-07-26  1:34 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Martin K . Petersen, linux-scsi, Avri Altman, Adrian Hunter


Bart,

> This patch series fixes the documentation of scsi_set_resid() and also
> fixes residual handling in two SCSI LLDs. Please consider this patch
> series for the next merge window.

Applied to 6.6/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/2] Fix residual handling in two SCSI LLDs
  2023-07-24 20:08 [PATCH v2 0/2] Fix residual handling in two SCSI LLDs Bart Van Assche
                   ` (2 preceding siblings ...)
  2023-07-26  1:34 ` [PATCH v2 0/2] Fix residual handling in two SCSI LLDs Martin K. Petersen
@ 2023-07-31 19:45 ` Martin K. Petersen
  3 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2023-07-31 19:45 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Martin K . Petersen, linux-scsi, Avri Altman, Adrian Hunter

On Mon, 24 Jul 2023 13:08:28 -0700, Bart Van Assche wrote:

> This patch series fixes the documentation of scsi_set_resid() and also fixes
> residual handling in two SCSI LLDs. Please consider this patch series for the
> next merge window.
> 
> Thanks,
> 
> Bart.
> 
> [...]

Applied to 6.6/scsi-queue, thanks!

[1/2] scsi: ufs: Fix residual handling
      https://git.kernel.org/mkp/scsi/c/2903265e27bf
[2/2] RDMA/srp: Fix residual handling
      https://git.kernel.org/mkp/scsi/c/89e637c19b24

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-07-31 19:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-24 20:08 [PATCH v2 0/2] Fix residual handling in two SCSI LLDs Bart Van Assche
2023-07-24 20:08 ` [PATCH v2 1/2] scsi: ufs: Fix residual handling Bart Van Assche
2023-07-24 20:51   ` Avri Altman
2023-07-25 12:02   ` Adrian Hunter
2023-07-24 20:08 ` [PATCH v2 2/2] RDMA/srp: " Bart Van Assche
2023-07-25  6:51   ` Leon Romanovsky
2023-07-26  1:34 ` [PATCH v2 0/2] Fix residual handling in two SCSI LLDs Martin K. Petersen
2023-07-31 19:45 ` Martin K. Petersen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.