From patchwork Tue Apr 4 23:35:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Martin K. Petersen" X-Patchwork-Id: 9662735 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8F23E60352 for ; Tue, 4 Apr 2017 23:35:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 823B9284DE for ; Tue, 4 Apr 2017 23:35:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76FD3284FE; Tue, 4 Apr 2017 23:35:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 254A5284DE for ; Tue, 4 Apr 2017 23:35:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752701AbdDDXfQ (ORCPT ); Tue, 4 Apr 2017 19:35:16 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:22946 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751177AbdDDXfP (ORCPT ); Tue, 4 Apr 2017 19:35:15 -0400 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v34NZAdm019064 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 4 Apr 2017 23:35:10 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.13.8/8.14.4) with ESMTP id v34NZ9xN032441 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 4 Apr 2017 23:35:09 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id v34NZ8Kj022939; Tue, 4 Apr 2017 23:35:09 GMT Received: from ca-mkp.ca.oracle.com (/10.159.214.123) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 04 Apr 2017 16:35:08 -0700 To: Bart Van Assche Cc: "jejb\@linux.vnet.ibm.com" , "steve.magnani\@digidescorp.com" , "martin.petersen\@oracle.com" , "linux-scsi\@vger.kernel.org" , "linux-kernel\@vger.kernel.org" , "steve\@digidescorp.com" Subject: Re: [PATCH] sd: close hole in > 2T device rejection when !CONFIG_LBDAF From: "Martin K. Petersen" Organization: Oracle Corporation References: <1488208949-3811-1-git-send-email-steve@digidescorp.com> <1488211985.2656.1.camel@sandisk.com> <3a6783ec-200d-5df5-2e1e-756c7e8b7c22@digidescorp.com> <1488221849.2656.8.camel@sandisk.com> Date: Tue, 04 Apr 2017 19:35:05 -0400 In-Reply-To: <1488221849.2656.8.camel@sandisk.com> (Bart Van Assche's message of "Mon, 27 Feb 2017 18:57:44 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Bart Van Assche writes: Hi Bart, > Sorry but I still don't understand why the two checks are > different. How about the (untested) patch below? The approach below > avoids that the check is duplicated and - at least in my opinion - > results in code that is easier to read. Just tripped over this issue in connection with something else. However, I had to make a few passes to convince myself that your proposed fix was correct. How about something like the following? Martin diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index fb9b4d29af0b..6084c415c070 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -2102,6 +2102,16 @@ static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp, #define READ_CAPACITY_RETRIES_ON_RESET 10 +static bool sd_addressable_capacity(u64 lba, unsigned int sector_size) +{ + u64 last_sector = lba + 1ULL << ilog2(sector_size) - 9; + + if (sizeof(sector_t) == 4 && last_sector > 0xffffffffULL) + return false; + + return true; +} + static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, unsigned char *buffer) { @@ -2167,7 +2177,7 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, return -ENODEV; } - if ((sizeof(sdkp->capacity) == 4) && (lba >= 0xffffffffULL)) { + if (!sd_addressable_capacity(lba, sector_size)) { sd_printk(KERN_ERR, sdkp, "Too big for this kernel. Use a " "kernel compiled with support for large block " "devices.\n"); @@ -2256,7 +2266,7 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp, return sector_size; } - if ((sizeof(sdkp->capacity) == 4) && (lba == 0xffffffff)) { + if (!sd_addressable_capacity(lba, sector_size)) { sd_printk(KERN_ERR, sdkp, "Too big for this kernel. Use a " "kernel compiled with support for large block " "devices.\n");