From patchwork Sun Sep 6 07:51:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 11759465 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D824138E for ; Sun, 6 Sep 2020 07:52:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1DB372083E for ; Sun, 6 Sep 2020 07:52:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aNwMmcx7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725803AbgIFHwD (ORCPT ); Sun, 6 Sep 2020 03:52:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725306AbgIFHwC (ORCPT ); Sun, 6 Sep 2020 03:52:02 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43D48C061573; Sun, 6 Sep 2020 00:52:02 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id v15so6519726pgh.6; Sun, 06 Sep 2020 00:52:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T7hGBsOfVo5X/7XA6pc2U0kl3lXbMQ3BKQNeoxFE7fQ=; b=aNwMmcx7pQM+tiCu11lAmsLkmC9wDVMPlLj94UZykCj442RefBlcbBofzR8QW+fLq4 hOdCNyyPWp2pKY78WSRTp+UZNXf0ZJZNIDJllyZ2vZvgy+rpVXf5qMu7UHoKc5IowPah P6Ic0MRhDHtMLz8dkeUgua3pxyckkuA1NyheihdDV6f6CU2mKjw6Fio425p/HSPiqBm3 OuWGiYiDgLMQVjokxNB+DMQHUijIaZiEtDOfwl2/HvgkGg/A63DqY6jyK1bCQXKWTKsm jwnm8K36FvBQ+oLoBa3rvLnaXk4/Ziv4iiI1Uxqe3vrKB+c4+X6P5sAkt9v7gbjDvj39 9yiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T7hGBsOfVo5X/7XA6pc2U0kl3lXbMQ3BKQNeoxFE7fQ=; b=KovfgqqN46D16LBPc6B3WDMoYgMKRZQq6Z5dz9a7KwhYPKcttjMFIZ4tBasRXswfZd oy6l7dvzRYDGkzXuHOTnwqY3e85nMjsVopVdb7oa3DGXbwovhtdp0uQ/aYOzNKy8OwK6 B5l6aVf70FDG5nSZz8KVyTAVJXOGeqVlSNCQUzbfObMwAsioNFf/ErcJJSE7/WKrMtLx 0p9aP8g3mKa+YEmH5M4PKLhbRN66eTCM28jLb/CyoFlqIOzMnrNJZqaef+v9D5xwSl8W 7cvO4r5xIqV/GvXE6OkNYCl1SOqkEuzlAoyybSfLg0noJY4OTXWSdxZyxqSjzIXLOvrw uZNA== X-Gm-Message-State: AOAM53348HSZtEf+qPgeQpjmeEz9p1XqM99KRqRPyVlVdQwUbPtBwsyn LUnYM8Y+eDm+zaOjfZ8e2C8MDW3Jb9E= X-Google-Smtp-Source: ABdhPJxomWPcRasSHTQSD45V/CFcrv4rTL9dILEpEpCJ7HvW9/fm0v5JZbg6U0iOgTgpACNF5w0nmQ== X-Received: by 2002:a63:d918:: with SMTP id r24mr12683465pgg.158.1599378720676; Sun, 06 Sep 2020 00:52:00 -0700 (PDT) Received: from localhost.localdomain ([161.81.62.213]) by smtp.gmail.com with ESMTPSA id 67sm11799041pfv.173.2020.09.06.00.51.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2020 00:52:00 -0700 (PDT) From: Tom Yan To: linux-scsi@vger.kernel.org, dgilbert@interlog.com, bvanassche@acm.org, gregkh@linuxfoundation.org Cc: stern@rowland.harvard.edu, akinobu.mita@gmail.com, hch@lst.de, linux-api@vger.kernel.org, Tom Yan Subject: [PATCH v3 1/4] scsi: sg: fix BLKSECTGET ioctl Date: Sun, 6 Sep 2020 15:51:49 +0800 Message-Id: <20200906075152.2927-1-tom.ty89@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org It should give out the maximum number of sectors per request instead of maximum number of bytes, as that is what its equivalence in the block layer does (that is also the reason for the USHRT_MAX clamp; they should always have identical behaviour when possbile). Signed-off-by: Tom Yan --- v2: add more details in commit messages v3: add a missed line back to the commit message of the last patch drivers/scsi/sg.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 20472aaaf630..e57831910228 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -922,6 +922,7 @@ sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp, int result, val, read_only; Sg_request *srp; unsigned long iflags; + unsigned int max_sectors; SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, "sg_ioctl: cmd=0x%x\n", (int) cmd_in)); @@ -1114,8 +1115,9 @@ sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp, sdp->sgdebug = (char) val; return 0; case BLKSECTGET: - return put_user(max_sectors_bytes(sdp->device->request_queue), - ip); + max_sectors = min_t(unsigned int, USHRT_MAX, + queue_max_sectors(sdp->device->request_queue)); + return put_user(max_sectors, ip); case BLKTRACESETUP: return blk_trace_setup(sdp->device->request_queue, sdp->disk->disk_name, From patchwork Sun Sep 6 07:51:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 11759467 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 71C33138E for ; Sun, 6 Sep 2020 07:52:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5272E2083E for ; Sun, 6 Sep 2020 07:52:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YFjd+HTS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726342AbgIFHwI (ORCPT ); Sun, 6 Sep 2020 03:52:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725306AbgIFHwG (ORCPT ); Sun, 6 Sep 2020 03:52:06 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FCC8C061573; Sun, 6 Sep 2020 00:52:05 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id bh1so3038539plb.12; Sun, 06 Sep 2020 00:52:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EcapTIGFf+31wVMqsHZgBSE+2BUv5P+WBgtFpuHKTB4=; b=YFjd+HTSz6raCDdy5XvT4J9i6sD2sdLHRKRDVnjCL4Y1WGQrTTF00s8vKPNjBWivsp xGD6BQE9UWaPw3yLgVNnV81fPTaM9RXH6w9uL8/eKne7auworWDacgrAjGrKiz6mp6rv QL+tHU4pZTxHim+oR5UQFbAPzTDfMX5wRR2XZbUrVMS1ourpVyaSAFI5GPXPqyhGeISc YPsVx20udk4dHLIjZDwy8UD+9WaSF6goVMDvtaJwqKGhC7+E4wI6xhbtDlmkIhm+b2+k Uj9UP1BrCSWghOpWIewyDGWtLkINQf7WdClgckmjJk8j7TsBwN8K7Z7QV2eTkiKHs0VJ aHxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EcapTIGFf+31wVMqsHZgBSE+2BUv5P+WBgtFpuHKTB4=; b=UZvX9981uWeMQSR3VLs6aMCCxcQ3JUGEhjErIQPQFJi2fDQydrUhUXhMPKcqnX6gvY 9eHoIuE91DS0Pv3mPtfxgOa6bgVtYhvbApeKW6krSr5xn2h5AktLhjOJqJBaI9EPv7rC HNZtFagHYdhPZNsWvqsSi0oFRtiGsqWaLHZoHskAU/T/AEo1A0u1gOUfclBDakWL0Frm qNaQWjsX3zzGjjTTZ2kcXmmu8jwy/j941//MpXaNawfH6xP78lNgIVtTtjpBR/zR6659 mUkKPCt5+cagCg1skCmvCEugFAMURziV2bl9fGZRgh8P93M0zAYC0qVs65bEbbCFq8eY 7Stw== X-Gm-Message-State: AOAM530gU2cLICOR1yEomzkiG08SzVE82RZJE1yyWoJN4nPbn4kPmwc1 bBtIBvNZDtZT7RoTgPjmrClYVjOidcw= X-Google-Smtp-Source: ABdhPJx7HtV0DF+cz3hk5GNGTkaZ0+qLQa46gn5/nhufSJPq7lev0O1/vfNs6t5mWdB17BYSjCT5tg== X-Received: by 2002:a17:902:b48b:: with SMTP id y11mr15251313plr.185.1599378724602; Sun, 06 Sep 2020 00:52:04 -0700 (PDT) Received: from localhost.localdomain ([161.81.62.213]) by smtp.gmail.com with ESMTPSA id 67sm11799041pfv.173.2020.09.06.00.52.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2020 00:52:03 -0700 (PDT) From: Tom Yan To: linux-scsi@vger.kernel.org, dgilbert@interlog.com, bvanassche@acm.org, gregkh@linuxfoundation.org Cc: stern@rowland.harvard.edu, akinobu.mita@gmail.com, hch@lst.de, linux-api@vger.kernel.org, Tom Yan Subject: [PATCH v3 2/4] scsi: sg: implement BLKSSZGET Date: Sun, 6 Sep 2020 15:51:50 +0800 Message-Id: <20200906075152.2927-2-tom.ty89@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200906075152.2927-1-tom.ty89@gmail.com> References: <20200906075152.2927-1-tom.ty89@gmail.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Provide an ioctl to get the logical sector size so that the maximum bytes per request can be derived. Follow-up of the BLKSECTGET fix. Signed-off-by: Tom Yan --- drivers/scsi/sg.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index e57831910228..0e3f084141a3 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -1118,6 +1118,8 @@ sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp, max_sectors = min_t(unsigned int, USHRT_MAX, queue_max_sectors(sdp->device->request_queue)); return put_user(max_sectors, ip); + case BLKSSZGET: + return put_user(queue_logical_block_size(sdp->device->request_queue), ip); case BLKTRACESETUP: return blk_trace_setup(sdp->device->request_queue, sdp->disk->disk_name, From patchwork Sun Sep 6 07:51:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 11759469 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9C34D1599 for ; Sun, 6 Sep 2020 07:52:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F54D208C7 for ; Sun, 6 Sep 2020 07:52:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AZUF4Nrr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726422AbgIFHwL (ORCPT ); Sun, 6 Sep 2020 03:52:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbgIFHwI (ORCPT ); Sun, 6 Sep 2020 03:52:08 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80C23C061573; Sun, 6 Sep 2020 00:52:08 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id z15so3057485plo.7; Sun, 06 Sep 2020 00:52:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qj4opLuq3e/N7o34LR+3zc1SZci2d/YmQKRZk0FXSNg=; b=AZUF4Nrr+Db/5US5Ly8GMIzCt/6nLXu2iVEHdaeUqWAdwMaLg7bJGkU2mCO/HaeHIi 53yWJk/hO7EyiSoaScNy0BLhFn5zzcLr8VjhQegyByDq+FuaA9AC4Dt/v0URAB/L5cgC V/1SmYoM0FeiMpleYi0jlCmqLCCu/3F1n+4SCrUNg2R7PEzN6qSnBcNBYyfs+LiorEoK Djom2bvDzrZVA+w5KdKkkw6ZgtsU0klrLuAp1LrYrvmP3CbJhIU9YxThEqAJS0hlbkI7 3QJZ3sNtHd9GYtqKZ35pXAyEjEP3FGxvpghg8H4T6MtVtRXUPUJphi4YXmnCUByMv+QA Q2dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qj4opLuq3e/N7o34LR+3zc1SZci2d/YmQKRZk0FXSNg=; b=c0i+VhuySrBI9GbBI1/ImTfanDRpxSv6Tm5joRjow4kRN6Ng9bGQnsdXhZno6UJq3s pSY5Ex9/OcMa/SJ+L99jcBV8iuM2JvK7Z6rTZKnrXFo5bHeQSAQFsGLjPL9S16EzPZzz s1AQyz9fdWahHjaC8u6qjvPM9J6QbzbZRcMDYCfoAsO0Jh0CF7/d+6yOg/q/MGhzu/kh yoHmM0WFHaJ9YZdTSvRBMd8RrQz32JQOYUnNGb3THgumF3SUtd9zR/XSJMjBpOSxpJAv cEKqgYjeRzXypT8Ji7Nco61olXNmYCZ5HjxZ4B0/nhaH6YSrXcTRcWl8hAv9325DN4AV jWQA== X-Gm-Message-State: AOAM533IsCiAMR4auMYa7bJchg7wY1ag1vaBgh6muJDsirXSqo52yP0W vnX1B6FpQY5wozEzAwp9vYY3IC9wr5w= X-Google-Smtp-Source: ABdhPJw7i17kqk54QUPxW800mGhk7g/kiOjMhfIM7L9QmAQ/VpQaUgOOQWok8HBmb0g6yxD+WFS8+w== X-Received: by 2002:a17:902:a982:: with SMTP id bh2mr15066452plb.182.1599378727745; Sun, 06 Sep 2020 00:52:07 -0700 (PDT) Received: from localhost.localdomain ([161.81.62.213]) by smtp.gmail.com with ESMTPSA id 67sm11799041pfv.173.2020.09.06.00.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2020 00:52:07 -0700 (PDT) From: Tom Yan To: linux-scsi@vger.kernel.org, dgilbert@interlog.com, bvanassche@acm.org, gregkh@linuxfoundation.org Cc: stern@rowland.harvard.edu, akinobu.mita@gmail.com, hch@lst.de, linux-api@vger.kernel.org, Tom Yan Subject: [PATCH v3 3/4] scsi: sg: use queue_logical_sector_size() in max_sectors_bytes() Date: Sun, 6 Sep 2020 15:51:51 +0800 Message-Id: <20200906075152.2927-3-tom.ty89@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200906075152.2927-1-tom.ty89@gmail.com> References: <20200906075152.2927-1-tom.ty89@gmail.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Logical sector size was never / is no longer necessarily 512. Programatically speaking it may not be necessary for us to clamp max_sectors to USHRT_MAX here, but since such clamping is used in BLKSECTGET, it's probably a good idea to have it here too, so that what the function returns is consistent to what the ioctl reports. Alternatively we can clamp (max_sectors * logical_block_size) to INT_MAX instead, or maybe even not clamping it at all. P.S. sg_reserved_size is initially set to INT_MAX by blk_mq_init_allocated_queue(). Signed-off-by: Tom Yan --- drivers/scsi/sg.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 0e3f084141a3..deeab4855172 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -848,10 +848,11 @@ static int srp_done(Sg_fd *sfp, Sg_request *srp) static int max_sectors_bytes(struct request_queue *q) { unsigned int max_sectors = queue_max_sectors(q); + unsigned int logical_block_size = queue_logical_block_size(q); - max_sectors = min_t(unsigned int, max_sectors, INT_MAX >> 9); + max_sectors = min_t(unsigned int, max_sectors, USHRT_MAX); - return max_sectors << 9; + return max_sectors * logical_block_size; } static void From patchwork Sun Sep 6 07:51:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 11759471 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E4FAF1599 for ; Sun, 6 Sep 2020 07:52:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C6AA52083E for ; Sun, 6 Sep 2020 07:52:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QCWiMBSX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726642AbgIFHwN (ORCPT ); Sun, 6 Sep 2020 03:52:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbgIFHwM (ORCPT ); Sun, 6 Sep 2020 03:52:12 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0784BC061573; Sun, 6 Sep 2020 00:52:12 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id x18so3058554pll.6; Sun, 06 Sep 2020 00:52:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I9t8W0xVBTzwntMqKUpY1JXn7OO0PXlgWGrbZCcekzk=; b=QCWiMBSXxOiFqPRm/S3oHCU1UwC6vISk97TuwUqHGKbRhgz09bIOyBGgaxVcUzKLSZ 2oILRokktUQWBa19hIXHYGRYbKpFrAUunjGQezHw61xxBZEYObDElBNyzVrDzq4CG4K2 kP/3qF2knW4/yVK2MluGtKZqYzMTM1wddX8aUsoGHp5TPLatd0rHVvLvzQN6qXO/xAfW mlwcyfc2/3Oufm6hFTtwzXyCH0tLgADGVUoRiDlP/647NTZHbKkgCzYEdMkmh0sV9F0i ISIzjVFNE73qqrqgZBRuvnxd57NB+S82ihclZeZQk7KkGRkfPfzMmyFQscGcEHx7n9VG L8QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I9t8W0xVBTzwntMqKUpY1JXn7OO0PXlgWGrbZCcekzk=; b=dRTxJstVIkkHcSFRMTxpwOiNPWDRpe6pEep8zI0idnPtu1NW7F1i4AAqPuS2L4yrqt LNAjPwgJ8iUi2goBgF7xpf1edqPoqwMs3rOnjy7AQ21J1/Jg6gWbaOdt2vAEsdkbKZo1 pt4tcxm48QCIiaIYBRBgqE7IsbnOfc5z2BIi7DrPBXvKS8N7LU3kSh1KEt+JNmOydVks aUyfDYEtteYhHU9EH/FV10DgPSZn2OjpFwW2cbD0O/yoyZfDdRBvs9PfAsyR/cXAhsDp USk/JRCvXPZJ80/kM+49ft07Rqj1hN6eUUbhrLlvJ5g+aKuTEWbHX/lOAi0+AaM525jG H3Qw== X-Gm-Message-State: AOAM531z8zLiKFnRH0KjQb9g+M7J6v9ta25Jw1qWgC0ebcEMQcX05rdD sw8rpavdlvwK7drUB2PdtXaNtk8wNCc= X-Google-Smtp-Source: ABdhPJyOBLQESxnGoxA9oMoaqKyYfQ1sfeaIaA5R0C2j+A4Qjdxc4NcKH9EtQnCFzDqk1WeeSVyjkg== X-Received: by 2002:a17:90a:c288:: with SMTP id f8mr4029734pjt.123.1599378731213; Sun, 06 Sep 2020 00:52:11 -0700 (PDT) Received: from localhost.localdomain ([161.81.62.213]) by smtp.gmail.com with ESMTPSA id 67sm11799041pfv.173.2020.09.06.00.52.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2020 00:52:10 -0700 (PDT) From: Tom Yan To: linux-scsi@vger.kernel.org, dgilbert@interlog.com, bvanassche@acm.org, gregkh@linuxfoundation.org Cc: stern@rowland.harvard.edu, akinobu.mita@gmail.com, hch@lst.de, linux-api@vger.kernel.org, Tom Yan Subject: [PATCH v3 4/4] block/scsi_ioctl.c: use queue_logical_sector_size() in max_sectors_bytes() Date: Sun, 6 Sep 2020 15:51:52 +0800 Message-Id: <20200906075152.2927-4-tom.ty89@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200906075152.2927-1-tom.ty89@gmail.com> References: <20200906075152.2927-1-tom.ty89@gmail.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Logical sector size was never / is no longer necessarily 512. Programatically speaking it may not be necessary for us to clamp max_sectors to USHRT_MAX here, but since such clamping is used in BLKSECTGET, it's probably a good idea to have it here too, so that what the function returns is consistent to what the ioctl reports. Alternatively we can clamp (max_sectors * logical_block_size) to INT_MAX instead, or maybe even not clamping it at all. P.S. sg_reserved_size is initially set to INT_MAX by blk_mq_init_allocated_queue(). Signed-off-by: Tom Yan --- block/scsi_ioctl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index ef722f04f88a..ae6aae40a8b6 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c @@ -73,10 +73,11 @@ static int sg_set_timeout(struct request_queue *q, int __user *p) static int max_sectors_bytes(struct request_queue *q) { unsigned int max_sectors = queue_max_sectors(q); + unsigned int logical_block_size = queue_logical_block_size(q); - max_sectors = min_t(unsigned int, max_sectors, INT_MAX >> 9); + max_sectors = min_t(unsigned int, max_sectors, USHRT_MAX); - return max_sectors << 9; + return max_sectors * logical_block_size; } static int sg_get_reserved_size(struct request_queue *q, int __user *p)