Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2629815ybg; Sun, 27 Oct 2019 23:07:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqxl3+nkzFJxVVUPmrGyZeRen4X/VA+JLuJtFq0QpYn7oVwAQbAF1mn8R2N39cpW9d+UiEym X-Received: by 2002:a17:907:20f3:: with SMTP id rh19mr13647249ejb.289.1572242871842; Sun, 27 Oct 2019 23:07:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572242871; cv=none; d=google.com; s=arc-20160816; b=O88Q2lAuWAy/ijAL54yY72478ceE9/gIo9BPgsprVh6xe1+ZXfddsz0op2A0tlSfJU fo//pBx4Q29Tf23m7Oumz9F3UD+OaGJQfHfHHX9/Q+R9GBnBoj5XB4u4wvQjwtMODenl H+8tr8GJXWlAaZSqyM+Crbq37/AQX9XsFr/cKztlNz1SxwASVKFRN7utBVMDF3PedpMn WdB8CBCOmytsHpLbbZ4eGvI9RDn5RtIzOljT8RQPLBIAYumokqLkXFrWwFK0OSvkE2Uf oxo71OEkMVWPzlt9PYeJoVOzDiEWdHUIvezLt6oBLznWP3Mosd3eGHGEwQ9aR4jIUqjd 2/yw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7H/t6Ng5D5y0LUqgsoAbnHoQkh+PPTf9Etcv1zb8tyg=; b=y1eTDp9VarM8Jf0aCQ/kGYmtFSltSJFk6Y7QpcjtwP2/HseUbg6Rbq6oNRExExXlwY jP5F4z24Q4jPBdW7IXN+H8YV7BgB6RFvc7JagSnkLR3D0+AmbtMuvAVRxVIyn0vEvbXv mrc/M2ApF5wrosdWB55P/KGGSh3Kt8KK9wPQZBA6IyVrj/BWhv4zc5AZ8S589tAmvoaK iyB2pYQc0OFsEKzTudfezg+IL6slkYCCD7HrtlBE0xxHp6zEJo4pzC6ZpuofZ1qZh/TR gWj0R4Jp/hUue/KVLVoRDWZpjahNJBnoHrXwTK8OgD354L/i4mPyriwKI84qFbMmYQXS zx5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AgzEe5Jc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z31si7005503ede.236.2019.10.27.23.07.28; Sun, 27 Oct 2019 23:07:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AgzEe5Jc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730523AbfJ0VOr (ORCPT + 99 others); Sun, 27 Oct 2019 17:14:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:33748 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730514AbfJ0VOp (ORCPT ); Sun, 27 Oct 2019 17:14:45 -0400 Received: from localhost (100.50.158.77.rev.sfr.net [77.158.50.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 405FC205C9; Sun, 27 Oct 2019 21:14:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572210883; bh=bbvKfmQiBiYhnCpebJUu9fNk1IlOgQ8bUXjT4n+ai4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AgzEe5JcUYP8GJLqZC5S+U/JSvSbOQ6cYsyDv9QrLKFgz3CiVeb8u2tQkFWiBdvrS zylHY5YsubQDNUbhq0OjyG2psQVImwyu0uWsSbofwkHChVoePNlZMowp3pY4sVBbil kM5LZaks3fILI6Y1AJka8DX+P+8kcepvSjIyCsxU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Damien Le Moal , Bart Van Assche , "Martin K. Petersen" Subject: [PATCH 4.19 50/93] scsi: core: save/restore command resid for error handling Date: Sun, 27 Oct 2019 22:01:02 +0100 Message-Id: <20191027203300.858365936@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191027203251.029297948@linuxfoundation.org> References: <20191027203251.029297948@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Damien Le Moal commit 8f8fed0cdbbd6cdbf28d9ebe662f45765d2f7d39 upstream. When a non-passthrough command is terminated with CHECK CONDITION, request sense is executed by hijacking the command descriptor. Since scsi_eh_prep_cmnd() and scsi_eh_restore_cmnd() do not save/restore the original command resid, the value returned on failure of the original command is lost and replaced with the value set by the execution of the request sense command. This value may in many instances be unaligned to the device sector size, causing sd_done() to print a warning message about the incorrect unaligned resid before the command is retried. Fix this problem by saving the original command residual in struct scsi_eh_save using scsi_eh_prep_cmnd() and restoring it in scsi_eh_restore_cmnd(). In addition, to make sure that the request sense command is executed with a correctly initialized command structure, also reset the residual to 0 in scsi_eh_prep_cmnd() after saving the original command value in struct scsi_eh_save. Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20191001074839.1994-1-damien.lemoal@wdc.com Signed-off-by: Damien Le Moal Reviewed-by: Bart Van Assche Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/scsi_error.c | 3 +++ include/scsi/scsi_eh.h | 1 + 2 files changed, 4 insertions(+) --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -970,6 +970,7 @@ void scsi_eh_prep_cmnd(struct scsi_cmnd ses->sdb = scmd->sdb; ses->next_rq = scmd->request->next_rq; ses->result = scmd->result; + ses->resid_len = scmd->req.resid_len; ses->underflow = scmd->underflow; ses->prot_op = scmd->prot_op; ses->eh_eflags = scmd->eh_eflags; @@ -981,6 +982,7 @@ void scsi_eh_prep_cmnd(struct scsi_cmnd memset(&scmd->sdb, 0, sizeof(scmd->sdb)); scmd->request->next_rq = NULL; scmd->result = 0; + scmd->req.resid_len = 0; if (sense_bytes) { scmd->sdb.length = min_t(unsigned, SCSI_SENSE_BUFFERSIZE, @@ -1034,6 +1036,7 @@ void scsi_eh_restore_cmnd(struct scsi_cm scmd->sdb = ses->sdb; scmd->request->next_rq = ses->next_rq; scmd->result = ses->result; + scmd->req.resid_len = ses->resid_len; scmd->underflow = ses->underflow; scmd->prot_op = ses->prot_op; scmd->eh_eflags = ses->eh_eflags; --- a/include/scsi/scsi_eh.h +++ b/include/scsi/scsi_eh.h @@ -32,6 +32,7 @@ extern int scsi_ioctl_reset(struct scsi_ struct scsi_eh_save { /* saved state */ int result; + unsigned int resid_len; int eh_eflags; enum dma_data_direction data_direction; unsigned underflow;