From patchwork Tue Jun 23 16:22:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Martin K. Petersen" X-Patchwork-Id: 6662471 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 91C229F1C1 for ; Tue, 23 Jun 2015 16:22:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AD7512065A for ; Tue, 23 Jun 2015 16:22:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C10FA205B4 for ; Tue, 23 Jun 2015 16:22:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933629AbbFWQWd (ORCPT ); Tue, 23 Jun 2015 12:22:33 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:44585 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932883AbbFWQWc (ORCPT ); Tue, 23 Jun 2015 12:22:32 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t5NGMUfw013400 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 23 Jun 2015 16:22:31 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id t5NGMU4i032569 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 23 Jun 2015 16:22:30 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id t5NGMUT6009422; Tue, 23 Jun 2015 16:22:30 GMT Received: from ca-mkp.ca.oracle.com (/10.156.108.201) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 23 Jun 2015 09:22:30 -0700 From: "Martin K. Petersen" To: linux-scsi@vger.kernel.org Cc: "Martin K. Petersen" , stable@vger.kernel.org Subject: [PATCH 1/2] sd: Sanity check the optimal I/O size Date: Tue, 23 Jun 2015 12:22:20 -0400 Message-Id: <1435076541-27253-1-git-send-email-martin.petersen@oracle.com> X-Mailer: git-send-email 2.4.3 X-Source-IP: userv0021.oracle.com [156.151.31.71] Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We have come across a couple of devices that report unreasonable values in the optimal I/O size in the Block Limits VPD page. Since this is a 32-bit entity that gets multiplied by the logical block size we can get disproportionately large values reported to the block layer. Cap io_opt at 256 MB. Signed-off-by: Martin K. Petersen Reported-by: Chris Friesen Cc: stable@vger.kernel.org --- drivers/scsi/sd.c | 3 ++- drivers/scsi/sd.h | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index a20da8c25b4f..118b336e0ddf 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -2560,7 +2560,8 @@ static void sd_read_block_limits(struct scsi_disk *sdkp) blk_queue_io_min(sdkp->disk->queue, get_unaligned_be16(&buffer[6]) * sector_sz); blk_queue_io_opt(sdkp->disk->queue, - get_unaligned_be32(&buffer[12]) * sector_sz); + min_t(unsigned int, SD_MAX_IO_OPT_BYTES, + get_unaligned_be32(&buffer[12]) * sector_sz)); if (buffer[3] == 0x3c) { unsigned int lba_count, desc_count; diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h index 63ba5ca7f9a1..f175a3f2944a 100644 --- a/drivers/scsi/sd.h +++ b/drivers/scsi/sd.h @@ -44,10 +44,11 @@ enum { }; enum { - SD_DEF_XFER_BLOCKS = 0xffff, - SD_MAX_XFER_BLOCKS = 0xffffffff, - SD_MAX_WS10_BLOCKS = 0xffff, - SD_MAX_WS16_BLOCKS = 0x7fffff, + SD_DEF_XFER_BLOCKS = 0xffff, + SD_MAX_XFER_BLOCKS = 0xffffffff, + SD_MAX_WS10_BLOCKS = 0xffff, + SD_MAX_WS16_BLOCKS = 0x7fffff, + SD_MAX_IO_OPT_BYTES = 256 * 1024 * 1024, }; enum {