From patchwork Sun Sep 6 07:40:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 11759457 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 E20D914F9 for ; Sun, 6 Sep 2020 07:40:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BAD4F2080A for ; Sun, 6 Sep 2020 07:40:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SpcZs44d" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726362AbgIFHk3 (ORCPT ); Sun, 6 Sep 2020 03:40:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725306AbgIFHk2 (ORCPT ); Sun, 6 Sep 2020 03:40:28 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 642FCC061573; Sun, 6 Sep 2020 00:40:28 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id s2so4967833pjr.4; Sun, 06 Sep 2020 00:40:28 -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=D+V027+/ctA7JUz0jifuXRcZVHBqu+BrNTXODX6KOBU=; b=SpcZs44dUnM0I6Ex0rGS3paRaq9yUGuIdh5VeZOM3HyO3SE7pRi6DHXXgEkOLIHkHD 0U2yTuRaLdDvg1IRVVgKbFlTxoGYFPR1ieitntNSCyvMzKGC8Y2BZD7jhdYeHBzIux+w 7QrfFovjY981ZVQYavI8rKKI6QkBh+5l4eUMGDRuymh0uAR/W0PhZTaAXDa+WhtFo74S TJS1GbWRXRWQsLByw1KXhvl1RmYS4bIOjLAlWiCIimA4ReCoaIIKniX8syKOxLe82JwS NZ4J3O1llkDvoURsUyQtrJPEf0QnXU7AOH29mWytGK1AC9nRcwCR+n1loVOzH3+n1iMc /2Pw== 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=D+V027+/ctA7JUz0jifuXRcZVHBqu+BrNTXODX6KOBU=; b=eM2QRGezq498VtL9rcA5LsAeczwwpoO+9WYjFcJT/1G6gq6j9yJ5R4xIDEWVij41H6 ZQUU9203zbwXo8L71tyUOq6BDocUd6vmnqICE4P1B9qLAex0ZxvPXWHVJLaT3VaXB7c7 WYgUF2egM/vc0lxqwsXROHwHIjiyaWgjjZXDvcPbo2Tq3b1Wqf0U7I514FE1ES4N12AM ljRZh5cFfHw6RTbwXXstt8Z4a9RlhXphyZrdLmdP4FXZ0zfk7GvmJnoUWbRrETDyeBa2 PxVlY3LsjencIn+mDTrUqwD+B6XLq8+NgXw/WQcw7OmiUfCrqFsM34q15ZvxFtHPYcMB fgRw== X-Gm-Message-State: AOAM530e9EG/uRwdE/nG1x+Fvf/EWbmLJYQ8cKKymISYAgwyFn8NRhv9 d4fR7EDWFf7Cp2Ke7hLh92WUAd6a0wM= X-Google-Smtp-Source: ABdhPJzs9EboHcdDk/UxTT3SAtB6NhBJDGphm0tfGYiV/kmmv3uvbN0b/ngmsCkP92qlGJ89lNrzzQ== X-Received: by 2002:a17:902:a581:b029:cf:9367:8d9d with SMTP id az1-20020a170902a581b02900cf93678d9dmr13784746plb.0.1599378026083; Sun, 06 Sep 2020 00:40:26 -0700 (PDT) Received: from localhost.localdomain ([161.81.62.213]) by smtp.gmail.com with ESMTPSA id f28sm11634243pfq.191.2020.09.06.00.40.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2020 00:40:25 -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 v2 1/4] scsi: sg: fix BLKSECTGET ioctl Date: Sun, 6 Sep 2020 15:40:15 +0800 Message-Id: <20200906074018.2370-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 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:40:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 11759459 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 5FAA714F9 for ; Sun, 6 Sep 2020 07:40:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 45209208B3 for ; Sun, 6 Sep 2020 07:40:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IohpRBUS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726732AbgIFHkb (ORCPT ); Sun, 6 Sep 2020 03:40:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725306AbgIFHka (ORCPT ); Sun, 6 Sep 2020 03:40:30 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6763C061573; Sun, 6 Sep 2020 00:40:30 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id mm21so5157368pjb.4; Sun, 06 Sep 2020 00:40:30 -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=IohpRBUSjpKYerGmxviqQ2AOFnyqoDZrqXiBIggLrX3WkU1AatImH+tf9g5CLN5dcZ I2oh+Jm+JCF5rS1ei/EMkPk63YWn07A5Cpw93XKzSYn720bkiuAfzprkN2P3AzmEAh8d ykicYd0urFPifbLW/y9AjoxzFwcC4Dd6tPzhkluFuQebBX1S095+ZcI2lRmkqf9/zHeX 0EDp9SY9EIYqeIsdcCKJ7L4xH79IZm2MXEpshfwYw47uiuo2plXgMwHyHippLH/M0SAz yue1et+gYVXLahYzNjxYzKd2qmFX/oP6AMwwFeTEjoulamlPFa/Prcz711fIWMcZ0p8R KEMw== 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=cnKYPVuEkp2WSY2pdhsQTUbgoiNMkiOlzI03d3C2YVKET/fQ4m737dTAUrhQauwBek NfDIiQka65LGGYbftIqMMvEUJxJQ7ONT2CeibGk1ehHPdMhsNc8r88yB7yiXxZps2d32 Q33yxeEtdL12twC4xw0OHnVI9WjL7FaSbauk5aWoC+R3Wo+dXipyrvX/na7NlFzMF+cT qg/u1A3JpBgjzDOQOB/vVgnxoKFevX8zY+or7XXPbVXyI/QctCmcSNOfav0v9AffUhoN YHM1nsx16MAPukLeOjf+UmPMcDRwQpBBtq8txTjkmiKv3AZY1XIuC20a+jGF0TAiWYr3 XAow== X-Gm-Message-State: AOAM533Lo1Gyev5EU34q++Z6bWgVJ7X2Y9I6kdgPuDXWs5mr9M8BQ+N0 OVZML9mBc0IKkv8TuvEgJzyQpZorw/0= X-Google-Smtp-Source: ABdhPJwdG+z97JBo7a5OGlRBcgyEe2Ft55o0W8p1ezDgaFRP07eCmTWEcTzi510thMVSbSS0HDbmag== X-Received: by 2002:a17:902:bd06:: with SMTP id p6mr15330599pls.255.1599378029657; Sun, 06 Sep 2020 00:40:29 -0700 (PDT) Received: from localhost.localdomain ([161.81.62.213]) by smtp.gmail.com with ESMTPSA id f28sm11634243pfq.191.2020.09.06.00.40.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2020 00:40:29 -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 v2 2/4] scsi: sg: implement BLKSSZGET Date: Sun, 6 Sep 2020 15:40:16 +0800 Message-Id: <20200906074018.2370-2-tom.ty89@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200906074018.2370-1-tom.ty89@gmail.com> References: <20200906074018.2370-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:40:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 11759461 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 6BC5314F9 for ; Sun, 6 Sep 2020 07:40:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4FA8B2083E for ; Sun, 6 Sep 2020 07:40:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MpAs3l0w" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728199AbgIFHkh (ORCPT ); Sun, 6 Sep 2020 03:40:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725306AbgIFHkf (ORCPT ); Sun, 6 Sep 2020 03:40:35 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AAF9C061573; Sun, 6 Sep 2020 00:40:34 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id b17so2830492pji.1; Sun, 06 Sep 2020 00:40:34 -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=MpAs3l0w1+wcX7e0Gaqvv8jXvighKbG5rSnwmXEeOooDUiZJMNmz6afh8PAI+rCdZX j3wdxS29KwxtMp8Lw3/ORNsSif6DmYTjy0kChfdJ6Xwl5w9lSa99pi7ug1nYrh+EDoz4 0aiXfTsgs+iRh+Q2jCd4UsMrBznD+BDPI+JVNxDgH3lLU4NGMn7uSgYc+azTQKbeq4q8 nC4BvJfiF4bymlhw4SzQsc8xp1VmCDPyaE3Vo5IsFmol4uqCFFB4m5lvo2V2SCL6IljU qITOQSWeZ9ErYExN1GRRdbs1+CmdxQDnfWLzePEdzyRgkMTEu6zdY42ArMPGOqhVva6p FAFA== 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=M/1k6iIVripwLt8Rwn1KIq4o7NHJahDueOU4iezaL8BlW89sC3utvPxNz6213gTL5h KV9aGhoBwsrxBdnbyEWi7CMvNk/hxh6767PZB29GcIwRJJOu1ItePsqsbMcX4slfJNRC +Kkv/ItkcjzFsVY46Hwvf9pc0Oo1GEKqkuSmH5js2UXemA8soswDNW/naQOfpxOFumNq 1g8eOfzg1icBl8q66k6JaboSP6Uf8GJfFotGOYdJJ1AiIWWXvxeumTnZ8+rVUwNSvc1Y rbAUsSCZeNFueX3BG3EUertP0AoPU+xCM1OONMdb/tsuPQZRuWZ6+cjmUITplVBl5qyL AIZw== X-Gm-Message-State: AOAM530GvLfVeqI9ExFL282SMhNr+GoeJ8TmMBZHS6CsHhMmJ9+WEkBc tA5Q2/fJaf8Amd64ZC6z3v1uwm3Iaso= X-Google-Smtp-Source: ABdhPJxESf1OLMoAjgaIBGPG/SKXTIXL82JgyfvIoyooDsbw1amrYne3wKSsG2jgBPnCiZqk++LuRQ== X-Received: by 2002:a17:90b:360a:: with SMTP id ml10mr14889917pjb.198.1599378033460; Sun, 06 Sep 2020 00:40:33 -0700 (PDT) Received: from localhost.localdomain ([161.81.62.213]) by smtp.gmail.com with ESMTPSA id f28sm11634243pfq.191.2020.09.06.00.40.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2020 00:40:32 -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 v2 3/4] scsi: sg: use queue_logical_sector_size() in max_sectors_bytes() Date: Sun, 6 Sep 2020 15:40:17 +0800 Message-Id: <20200906074018.2370-3-tom.ty89@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200906074018.2370-1-tom.ty89@gmail.com> References: <20200906074018.2370-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:40:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 11759463 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 2CAA714F9 for ; Sun, 6 Sep 2020 07:40:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1147C208C7 for ; Sun, 6 Sep 2020 07:40:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BSlDNWvM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728257AbgIFHkk (ORCPT ); Sun, 6 Sep 2020 03:40:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725306AbgIFHki (ORCPT ); Sun, 6 Sep 2020 03:40:38 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B18EC061573; Sun, 6 Sep 2020 00:40:37 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id o68so6955236pfg.2; Sun, 06 Sep 2020 00:40:37 -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=Ayb3Up2Q6+b+eLmNUc0tgAqbzpNo/tgv5jEUsoMm/U4=; b=BSlDNWvMtF3qqwSlDIoXIljkIOF60ZUstGi3KbbbT3ib8XqseezF7QEiuVJkVKq8tZ mrbgV4f03TWbqUcMPgCo326rr2KwSzb2Nwnuj2PnTyCHOACykiUvWDdCkHBRs88vhHU0 57spo2yBQyyT7xhmpUbfjZzvIPeuM9UBwQZEXgADur8oqX2au1ZIU7KIFI+lCE7MPZWn Pw3LnwnS5ezLUyyKBKGyBgz+eAY1/vRJSipHWzzFml3m4bOiHWIwy+ShT8M3oM2TqKLa h0rcMDwp5jx7QiwgWtm372VQ2lHIT6DK0UbabZ3tLWN4b3/PRNs/Dn0QEnlQ6Zxb4ych W1BA== 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=Ayb3Up2Q6+b+eLmNUc0tgAqbzpNo/tgv5jEUsoMm/U4=; b=MlCU8Ex6cL5xkEUXrs75jNrQ3M4Z2LDfCJcWRf60221YfhSQjAgeuX7wBT15zMfAIr fNO5kHyEDMY7M4RUAPiEbMCeOFT93QpGKJ6hhm8E1jvSoflwEemQHax0kK1Zvvf8jwx3 odKSwSVROI1CEjS4/+4sDypYfAydkprjfxI44FIMx24e0M9cet3aNZWjf95D6t1rWnjF BzJgZb9+PqQPQaHOTC1tjcXY9oWrSvEwUpJkrGW9x4MuqcVD5Xap1+/pgdYzJ4WNQoQ/ 2Jqbt6tONU3x/WoQfK/T73HEL6hOQLMKqf9sZyPWuHD1m30NluAnJs6RZR3GVv/lu8W8 5y5g== X-Gm-Message-State: AOAM53098uVMdG8EC1GaamAVgBS7Yn/geqygJS2n3cGpOwjXOMLvmfBu 3EvqSlyywBVTpjXLEu9vS+Sag0TAdEY= X-Google-Smtp-Source: ABdhPJy/+qBXn7/I6RjmouOt15BBXWpX1lP/qCQd0RXbUSttMoAoIqh0KltfvVu4tjVGD0mkZzGBzQ== X-Received: by 2002:a63:5c5c:: with SMTP id n28mr12804595pgm.198.1599378036669; Sun, 06 Sep 2020 00:40:36 -0700 (PDT) Received: from localhost.localdomain ([161.81.62.213]) by smtp.gmail.com with ESMTPSA id f28sm11634243pfq.191.2020.09.06.00.40.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2020 00:40:36 -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 v2 4/4] block/scsi_ioctl.c: use queue_logical_sector_size() in max_sectors_bytes() Date: Sun, 6 Sep 2020 15:40:18 +0800 Message-Id: <20200906074018.2370-4-tom.ty89@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200906074018.2370-1-tom.ty89@gmail.com> References: <20200906074018.2370-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 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)