Received: by 2002:a17:90a:1609:0:0:0:0 with SMTP id n9csp854144pja; Wed, 1 Apr 2020 09:53:27 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtqWOIRLNzFl3o8V/qsH1jRkVNJXN8Vq82cagQWhIUc3kYkEclvXYGdQ/pPq5kia90FnEe3 X-Received: by 2002:a4a:4505:: with SMTP id y5mr17699489ooa.29.1585760007688; Wed, 01 Apr 2020 09:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585760007; cv=none; d=google.com; s=arc-20160816; b=dZ644ppncV6DTVUr1yrMRdfSv5pr7OeWgStGCHhaP3yJZGduN6XSWevLjaERolW/k9 gHiYEL37PZgBD3NB/y53nj5tVwmGE+ZbXaorGKeOiROxXgmWlMLPA+PuR2YswV6rLIJb siNBoaN4Baqr/V8n4SADauptKCvI0HqdVKaV5/AOSs8DlreDoQhJEf6zH7uGd8YLyLnz rH90Gp5ZYvdigwsV6LmzBaos42oN9yLC3miigmuOBxfMPsb97SLopbSQ5oVg72Bm8oZj X8tUX6P/5boQFPipddvg7dsd2c61TohMk+H5D5SCk77OKqDCHLDOf9cq2wVttP1hF5k7 xfHg== 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=kUxOooNupopoS0wpYy7jjP1yHw0yr1lCal/UK/YqhRw=; b=oFj4pWn/KO9iCffjiBQFZrgq1+W0pW+75YOXciwjxQlm0Iw32mc+2AmhxphFWMHt+S 49MUpi9aCIH6XRvPh9ephi6lLnR9KvyraC2xAFXwLgQkJin89jdDuFHNasdaUmp+x++k 3y3lJmXrSD71ERLFXEGDqFN2M7pLB0Nk6cpftw6/VNXjsztXK78UURFArvXTJSlLiV9O qZtrdtsT97fAF0tm/PgDkVjXGi/f+/8f2qCUGvPkZvS1c72U1Eg8zF98n8rJyZmQ6Lyb rd/o+Uz6svtAlOg467DaXOxgTn77y2KYmdZoQFbdzMGZfMIidcFgfxPIhcPrtbmzoS+1 HXng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mqPbKACs; 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 q196si1096440oic.143.2020.04.01.09.53.14; Wed, 01 Apr 2020 09:53:27 -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=mqPbKACs; 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 S2389002AbgDAQhp (ORCPT + 99 others); Wed, 1 Apr 2020 12:37:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:36796 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388743AbgDAQhi (ORCPT ); Wed, 1 Apr 2020 12:37:38 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 F2BB820BED; Wed, 1 Apr 2020 16:37:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585759054; bh=NgluBSrlV5CcAMMvqcf9f58XWpFgyEC29/0bh+iSYgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mqPbKACs9C5lwxxYK5cJSt+XE9oRTtLcVWe1CeAorZ5YJx9GZbyQgcXY/QhUioJ9L Yuf4RnnTf4Br/PjmasFJJtLbTYH3JIY0M9evZMq4jmo7/SXzbMUuzm20QJgaD8sRuy FnojySjJQWyLUJFX0C7DeP7404fOPeBow1HitJgU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bryan Gurney , Bernhard Sulzer , "Martin K. Petersen" Subject: [PATCH 4.9 062/102] scsi: sd: Fix optimal I/O size for devices that change reported values Date: Wed, 1 Apr 2020 18:18:05 +0200 Message-Id: <20200401161543.454644273@linuxfoundation.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200401161530.451355388@linuxfoundation.org> References: <20200401161530.451355388@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: Martin K. Petersen commit ea697a8bf5a4161e59806fab14f6e4a46dc7dcb0 upstream. Some USB bridge devices will return a default set of characteristics during initialization. And then, once an attached drive has spun up, substitute the actual parameters reported by the drive. According to the SCSI spec, the device should return a UNIT ATTENTION in case any reported parameters change. But in this case the change is made silently after a small window where default values are reported. Commit a83da8a4509d ("scsi: sd: Optimal I/O size should be a multiple of physical block size") validated the reported optimal I/O size against the physical block size to overcome problems with devices reporting nonsensical transfer sizes. However, this validation did not account for the fact that aforementioned devices will return default values during a brief window during spin-up. The subsequent change in reported characteristics would invalidate the checking that had previously been performed. Unset a previously configured optimal I/O size should the sanity checking fail on subsequent revalidate attempts. Link: https://lore.kernel.org/r/33fb522e-4f61-1b76-914f-c9e6a3553c9b@gmail.com Cc: Bryan Gurney Cc: Reported-by: Bernhard Sulzer Tested-by: Bernhard Sulzer Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/sd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -2949,9 +2949,11 @@ static int sd_revalidate_disk(struct gen if (sd_validate_opt_xfer_size(sdkp, dev_max)) { q->limits.io_opt = logical_to_bytes(sdp, sdkp->opt_xfer_blocks); rw_max = logical_to_sectors(sdp, sdkp->opt_xfer_blocks); - } else + } else { + q->limits.io_opt = 0; rw_max = min_not_zero(logical_to_sectors(sdp, dev_max), (sector_t)BLK_DEF_MAX_SECTORS); + } /* Do not exceed controller limit */ rw_max = min(rw_max, queue_max_hw_sectors(q));