Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp632570img; Fri, 22 Mar 2019 05:33:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqweKRQJuRmshHQsCMNfE6ZUTjA9WlzrrjFGdOzrQmDQqf3FxpCbqY+ttpbLkHVB9cn1eqyl X-Received: by 2002:aa7:83cb:: with SMTP id j11mr8893846pfn.117.1553258015057; Fri, 22 Mar 2019 05:33:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553258015; cv=none; d=google.com; s=arc-20160816; b=DmoDQG08H9GfphTAGEAVM+4M/FFUCglr4+UkYdGPH0VN51lQWSH4YYiKfcvKGLsAPX GvpW590aio/ZHbjUz2Z6TQxJJnKrkuZiWvICsw530O8vjliUHumub02RMmiT22QvdpGS xBcO1OnoSi+uiLpO/VCCV23uNSd4OqyFc2P1jI3864DJ35S2oC95bKzDykJYaBoILyLE vVa37WCCI1OTzxvV75jgYT4E4LQJBkwIANZAOFIS4Iuf5mf/2iJBPxT3LBqQ+23xax1H 1QVWTaM4qlrSO+4ySNxhD8E5J79e05oozpMqpJHvlvLd8BM437T7dBCIYu9Dj0EtuQPJ aC2Q== 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=o9EqvMg8GQ5Ab2PZeG/KaiMLjdyQxmhrxyTb7Dwzp/E=; b=iluso9FFn03xKSKxTZY/mOCYhlUuJScR1tVwdB8j9D/OaccAHFd7k0/GieJew0lGbd LkdVBi9PV1U/ersf+zOxaiFDlmiAAgirpfTyWBmKoaNh8DSGXmkgZvUxNG+Iyzqjx32e ZiY1x7G5ZqkoLBZHXwdKsYvD2uqBeWSvpsxggcQIjZre8nyhVuTondqrNryQSmW/7u/7 xllDVTMm1fmDKOtIL7dy3RHq3yM3bTLcf/r7THWnEJf+2GRVppN2LerX/HqTu33/1xxt X12m9hjuyz+YYNjPOniEjuKSePKHaDWHwHc16+xuJLfyO8MwtSLpWBzlkpxBru9zjD8D zVsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VFWvuI6R; 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 d21si6674038pll.437.2019.03.22.05.33.19; Fri, 22 Mar 2019 05:33:35 -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=VFWvuI6R; 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 S2389616AbfCVMPi (ORCPT + 99 others); Fri, 22 Mar 2019 08:15:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:54102 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388977AbfCVMPg (ORCPT ); Fri, 22 Mar 2019 08:15:36 -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 77D372082C; Fri, 22 Mar 2019 12:15:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553256936; bh=nhdkVoDvq+EZKMYtEgmR1yrlfjEbkr7w5BKISJsAMlA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VFWvuI6RHB/gnoPxSysb5Au3lV0QRY0E4Qk/TZ+1jTNo5zWZQVoqHffIQrjpQ0sXN ZV9UbxaugxIgjZvtbs/uEvqrB/dA4KAlhY3XWbJc4R1DYKa8F10vjsZfWR8Ii1SQEz 1gpijgGah60LldTu4xqpQ8PhB3KP7N7LsU6jiBc8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Anton Mitterer , Christoph Hellwig , "Martin K. Petersen" Subject: [PATCH 5.0 081/238] scsi: sd: Optimal I/O size should be a multiple of physical block size Date: Fri, 22 Mar 2019 12:15:00 +0100 Message-Id: <20190322111303.371848976@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111258.383569278@linuxfoundation.org> References: <20190322111258.383569278@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: Martin K. Petersen commit a83da8a4509d3ebfe03bb7fffce022e4d5d4764f upstream. It was reported that some devices report an OPTIMAL TRANSFER LENGTH of 0xFFFF blocks. That looks bogus, especially for a device with a 4096-byte physical block size. Ignore OPTIMAL TRANSFER LENGTH if it is not a multiple of the device's reported physical block size. To make the sanity checking conditionals more readable--and to facilitate printing warnings--relocate the checking to a helper function. No functional change aside from the printks. Cc: Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=199759 Reported-by: Christoph Anton Mitterer Reviewed-by: Christoph Hellwig Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/sd.c | 59 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 9 deletions(-) --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3047,6 +3047,55 @@ static void sd_read_security(struct scsi sdkp->security = 1; } +/* + * Determine the device's preferred I/O size for reads and writes + * unless the reported value is unreasonably small, large, not a + * multiple of the physical block size, or simply garbage. + */ +static bool sd_validate_opt_xfer_size(struct scsi_disk *sdkp, + unsigned int dev_max) +{ + struct scsi_device *sdp = sdkp->device; + unsigned int opt_xfer_bytes = + logical_to_bytes(sdp, sdkp->opt_xfer_blocks); + + if (sdkp->opt_xfer_blocks > dev_max) { + sd_first_printk(KERN_WARNING, sdkp, + "Optimal transfer size %u logical blocks " \ + "> dev_max (%u logical blocks)\n", + sdkp->opt_xfer_blocks, dev_max); + return false; + } + + if (sdkp->opt_xfer_blocks > SD_DEF_XFER_BLOCKS) { + sd_first_printk(KERN_WARNING, sdkp, + "Optimal transfer size %u logical blocks " \ + "> sd driver limit (%u logical blocks)\n", + sdkp->opt_xfer_blocks, SD_DEF_XFER_BLOCKS); + return false; + } + + if (opt_xfer_bytes < PAGE_SIZE) { + sd_first_printk(KERN_WARNING, sdkp, + "Optimal transfer size %u bytes < " \ + "PAGE_SIZE (%u bytes)\n", + opt_xfer_bytes, (unsigned int)PAGE_SIZE); + return false; + } + + if (opt_xfer_bytes & (sdkp->physical_block_size - 1)) { + sd_first_printk(KERN_WARNING, sdkp, + "Optimal transfer size %u bytes not a " \ + "multiple of physical block size (%u bytes)\n", + opt_xfer_bytes, sdkp->physical_block_size); + return false; + } + + sd_first_printk(KERN_INFO, sdkp, "Optimal transfer size %u bytes\n", + opt_xfer_bytes); + return true; +} + /** * sd_revalidate_disk - called the first time a new disk is seen, * performs disk spin up, read_capacity, etc. @@ -3125,15 +3174,7 @@ static int sd_revalidate_disk(struct gen dev_max = min_not_zero(dev_max, sdkp->max_xfer_blocks); q->limits.max_dev_sectors = logical_to_sectors(sdp, dev_max); - /* - * Determine the device's preferred I/O size for reads and writes - * unless the reported value is unreasonably small, large, or - * garbage. - */ - if (sdkp->opt_xfer_blocks && - sdkp->opt_xfer_blocks <= dev_max && - sdkp->opt_xfer_blocks <= SD_DEF_XFER_BLOCKS && - logical_to_bytes(sdp, sdkp->opt_xfer_blocks) >= PAGE_SIZE) { + 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