From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72C81C43381 for ; Sat, 16 Feb 2019 03:01:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3DB4A222D0 for ; Sat, 16 Feb 2019 03:01:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="A7DkWhe5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390357AbfBPDBB (ORCPT ); Fri, 15 Feb 2019 22:01:01 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:40028 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727509AbfBPDBB (ORCPT ); Fri, 15 Feb 2019 22:01:01 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x1G2tRcV122840; Sat, 16 Feb 2019 03:00:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : cc : subject : from : references : date : in-reply-to : message-id : mime-version : content-type; s=corp-2018-07-02; bh=OvNm1VvH8LJ40VaIvozgCZVJnbd5QhZP/whhV0ExDAM=; b=A7DkWhe5ieVchR0LM5PpeXhA6/rBH5V+zB72dbaxbvYJtgLPRgyH96QdR45+ZY7VXS/+ 8GeB5u36tufVMLOoxAQZqQ8jhEPVlLrXKqdqfPVTSfNQdBGriYSCEplTzlWm6DIFhnHr WXf07fbsku6jfpvopbGxtqYO02bZM6daKtoZKu5FLzVR49FL3W4YpMW15lJD8INKV5GY OHN4nZlZ1UWny8lHlpq5AsfzqipTSKo1soN/LTDVFJHSymaefwVCt2l+wvUbwvan8pyR XIZsRwn222o7KtGNYaLJDoXAUFcFqheCCK360PwZIlmtrhhnZH/4FY60ll1Vvo8JRRoT +A== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2qp81dr67b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 16 Feb 2019 03:00:56 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x1G30ujU024403 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 16 Feb 2019 03:00:56 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x1G30t6p026778; Sat, 16 Feb 2019 03:00:55 GMT Received: from ca-mkp.ca.oracle.com (/10.159.214.123) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 16 Feb 2019 03:00:55 +0000 To: Christoph Hellwig Cc: linux-scsi@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2] scsi: sd: Optimal I/O size should be a multiple of physical block size From: "Martin K. Petersen" Organization: Oracle Corporation References: <20190212080409.GB10547@infradead.org> <20190212212105.17522-1-martin.petersen@oracle.com> Date: Fri, 15 Feb 2019 22:00:53 -0500 In-Reply-To: <20190212212105.17522-1-martin.petersen@oracle.com> (Martin K. Petersen's message of "Tue, 12 Feb 2019 16:21:05 -0500") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9168 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902160018 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Christoph? > 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 > Signed-off-by: Martin K. Petersen > > --- > > v2: > - Added warnings as requested by hch > - Moved the checks to a helper function > > Before: > > NAME ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED RQ-SIZE RA WSAME > sda 0 4096 33553920 4096 512 0 mq-deadline 256 128 32M > > After: > > NAME ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED RQ-SIZE RA WSAME > sda 0 4096 0 4096 512 0 mq-deadline 256 4096 32M > --- > drivers/scsi/sd.c | 59 +++++++++++++++++++++++++++++++++++++++-------- > 1 file changed, 50 insertions(+), 9 deletions(-) > > diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c > index 9aa409b38765..5dfe37b08d3b 100644 > --- a/drivers/scsi/sd.c > +++ b/drivers/scsi/sd.c > @@ -3048,6 +3048,55 @@ static void sd_read_security(struct scsi_disk *sdkp, unsigned char *buffer) > 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. > @@ -3117,15 +3166,7 @@ static int sd_revalidate_disk(struct gendisk *disk) > 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 -- Martin K. Petersen Oracle Linux Engineering