From patchwork Tue Jan 22 18:57:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10776121 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B17071399 for ; Tue, 22 Jan 2019 18:57:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F6AA2B881 for ; Tue, 22 Jan 2019 18:57:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91F352B885; Tue, 22 Jan 2019 18:57:53 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 02C512B945 for ; Tue, 22 Jan 2019 18:57:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726156AbfAVS5w (ORCPT ); Tue, 22 Jan 2019 13:57:52 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:34405 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726118AbfAVS5v (ORCPT ); Tue, 22 Jan 2019 13:57:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=LgS9cLFGOLqma+qpB8cK+aBMBM34pgVacKITrFxyYFo=; b=S+HQ9Crr9swi PpkmlRnFo9f41Ex7pfKJAoqsxY4OMw8VgRYHBffGFiRa844XUv/O+c4ZtIl1b8l+SD2+dzYCR6a2z ijSAOUOqyA1HzadbsNaROEZcB2uLg9xaOUN31igh9dt1FrIeZwhj0T5OSpIR4HnTH3ipzilahVTxc qQwKYzYRwAgNCHjRDnVkkdSruzUf5CvEd5NZSlFKssthsoiK19R0elZYTW6F0vdojkpglHmZ64Sdb raGUEsDjxTdVE3UWm9acVz7FuERAmbfFnQ+gEPcQFdEBc1JiPSHxduYXl5W1ZXVm4Vdp73ZTSBaRl kIM9FOQcFj1dwRix7YT33A==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gm1F0-00037j-5L; Tue, 22 Jan 2019 19:57:43 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 59DC4C0690; Tue, 22 Jan 2019 19:57:33 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Douglas Gilbert , Hannes Reinecke , Christoph Hellwig , Lee Duncan , Chris Leech Subject: [PATCH 1/7] Introduce the bidi_supported flag in the host template structure Date: Tue, 22 Jan 2019 10:57:18 -0800 Message-Id: <20190122185724.71598-2-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190122185724.71598-1-bvanassche@acm.org> References: <20190122185724.71598-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.01) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5qvyq3MUNdApNEY9l6CEVqx602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTZnx3upumnqWBHj0/Vmi/pASQQA8gPlICyOXF4VQA3r681n IyHanrMzYl1QUFnGrJlGZdzQSLJYSD89hpteF8v30ykPg8qyrdUV98WGlbOjhJdwZpOImhB57vlA Ovnv7bTFlefH5GZB2zKlxrpPWIK2tjx4n/PrYhB5hmGmQxMVYWnHvICDYD9SQrIEZQE6N1QHEh+f s39AlHh/KIPZhbuodfJjMWPIXjc0x0NFCtEYVLfAvZjgXTjXZ7MYLJNQ9qfhbYcYggf7p7NmsDw6 ItvQVSQcIoiM9VMtIDkLSaAvTQ9J5o1R01sERb9f7DCQBCBmqxPaW/sUreE8koAI7QArsBVXHLAg GdnciOQwEan5Ge0MPvKbYZEQYQFDvNZo0pTGqqLq1mqfP4rTv5j2D5aOq+q1XPjSgYCrnIBvTFe8 mnNVJBqo7HIsiC3qxMPBVxZwvSfE38dBQz1AyVOSufEGax/4hIM385pzFwSMDKHj6FhglsI+ED3B 4E2jgjU8D6JidZP1v8P5PHdq9TQMmv1Hak1m4yXZGkWsX85EIGofsQa2lXR+hQvtqLwVKWonezm8 s3vbwjHFkNsOIjv5GdFjTvnsqJRjOJfK5cbhn4VPt/ZnkWZmJiHnOufpI+hmVJRWpm9YZvwUuXgA Nn9PGzZKxHJSIxXRsnn1qpt+57eLz/jU/69xsc5gy1kJQrdxO8HkILQHQ3gYNfC2Ka63BMOa9OmY 6SQ8oDrOBu0RQp/RXAg2BiqCK3fhlA58k3TUIexFnVGhJwM6yrY9qtuFA6G9QUae8pUmcVBBoCcO Jxc4HcSPOvDOk4TmbCAR191ijgP68fXQp5/v+hqOLv5XS6YJsF7OlZMJymAw1S3dgf338tEyvDkN 3AfUBddcu9g0UhwU2XntZ3CGZOwArNSiB4L0vPnoxTr2NWH36ha3twj2plI5gTrpIWFPo1WtBP+l YOfrvgrw9R4RW8N3EtXlChZgHiRPxf1pRjt2NivWaiBMRrGYXd3ZFm+pQz9zA2G4QI7KATDDBZ7f Fc0FDw0l2bg+7PRloQfgRqAA9B7uKdyotKn0Gzq8V/T/GRLZ7+h41mukASe0zzIoSVH5jzhBWWlj x6RjnCXhDec8Nvp7LFExktCJZimPMqz9/aWLyMB36IKko0xWPtUy+4U2/JBiKNi6 X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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 This patch does not change any functionality but makes the drivers that support bidirectional commands more compact. Cc: Douglas Gilbert Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: Lee Duncan Cc: Chris Leech Signed-off-by: Bart Van Assche --- drivers/scsi/iscsi_tcp.c | 8 +------- drivers/scsi/scsi_debug.c | 11 +---------- drivers/scsi/scsi_lib.c | 2 ++ drivers/target/loopback/tcm_loop.c | 8 +------- include/scsi/scsi_host.h | 2 ++ 5 files changed, 7 insertions(+), 24 deletions(-) diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c index cae6368ebb98..8c09e9e45a62 100644 --- a/drivers/scsi/iscsi_tcp.c +++ b/drivers/scsi/iscsi_tcp.c @@ -952,12 +952,6 @@ static umode_t iscsi_sw_tcp_attr_is_visible(int param_type, int param) return 0; } -static int iscsi_sw_tcp_slave_alloc(struct scsi_device *sdev) -{ - blk_queue_flag_set(QUEUE_FLAG_BIDI, sdev->request_queue); - return 0; -} - static int iscsi_sw_tcp_slave_configure(struct scsi_device *sdev) { struct iscsi_sw_tcp_host *tcp_sw_host = iscsi_host_priv(sdev->host); @@ -985,7 +979,7 @@ static struct scsi_host_template iscsi_sw_tcp_sht = { .eh_device_reset_handler= iscsi_eh_device_reset, .eh_target_reset_handler = iscsi_eh_recover_target, .dma_boundary = PAGE_SIZE - 1, - .slave_alloc = iscsi_sw_tcp_slave_alloc, + .bidi_supported = true, .slave_configure = iscsi_sw_tcp_slave_configure, .target_alloc = iscsi_target_alloc, .proc_name = "iscsi_tcp", diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 661512bec3ac..e253c0129b40 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -3948,15 +3948,6 @@ static struct sdebug_dev_info *find_build_dev_info(struct scsi_device *sdev) return open_devip; } -static int scsi_debug_slave_alloc(struct scsi_device *sdp) -{ - if (sdebug_verbose) - pr_info("slave_alloc <%u %u %u %llu>\n", - sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); - blk_queue_flag_set(QUEUE_FLAG_BIDI, sdp->request_queue); - return 0; -} - static int scsi_debug_slave_configure(struct scsi_device *sdp) { struct sdebug_dev_info *devip = @@ -5834,7 +5825,7 @@ static struct scsi_host_template sdebug_driver_template = { .proc_name = sdebug_proc_name, .name = "SCSI DEBUG", .info = scsi_debug_info, - .slave_alloc = scsi_debug_slave_alloc, + .bidi_supported = true, .slave_configure = scsi_debug_slave_configure, .slave_destroy = scsi_debug_slave_destroy, .ioctl = scsi_debug_ioctl, diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 00cd365fb7d2..94842b104bcc 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1881,6 +1881,8 @@ struct request_queue *scsi_mq_alloc_queue(struct scsi_device *sdev) sdev->request_queue->queuedata = sdev; __scsi_init_queue(sdev->host, sdev->request_queue); blk_queue_flag_set(QUEUE_FLAG_SCSI_PASSTHROUGH, sdev->request_queue); + if (sdev->host->hostt->bidi_supported) + blk_queue_flag_set(QUEUE_FLAG_BIDI, sdev->request_queue); return sdev->request_queue; } diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c index 7bd7c0c0db6f..e54a5c57a8bb 100644 --- a/drivers/target/loopback/tcm_loop.c +++ b/drivers/target/loopback/tcm_loop.c @@ -304,12 +304,6 @@ static int tcm_loop_target_reset(struct scsi_cmnd *sc) return FAILED; } -static int tcm_loop_slave_alloc(struct scsi_device *sd) -{ - blk_queue_flag_set(QUEUE_FLAG_BIDI, sd->request_queue); - return 0; -} - static struct scsi_host_template tcm_loop_driver_template = { .show_info = tcm_loop_show_info, .proc_name = "tcm_loopback", @@ -325,7 +319,7 @@ static struct scsi_host_template tcm_loop_driver_template = { .cmd_per_lun = 1024, .max_sectors = 0xFFFF, .dma_boundary = PAGE_SIZE - 1, - .slave_alloc = tcm_loop_slave_alloc, + .bidi_supported = true, .module = THIS_MODULE, .track_queue_depth = 1, }; diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h index 6ca954e9f752..384b50992a56 100644 --- a/include/scsi/scsi_host.h +++ b/include/scsi/scsi_host.h @@ -430,6 +430,8 @@ struct scsi_host_template { /* True if the low-level driver supports blk-mq only */ unsigned force_blk_mq:1; + unsigned bidi_supported:1; + /* * Countdown for host blocking with no commands outstanding. */ From patchwork Tue Jan 22 18:57:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10776117 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 45BBC139A for ; Tue, 22 Jan 2019 18:57:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33F412B948 for ; Tue, 22 Jan 2019 18:57:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 276362B965; Tue, 22 Jan 2019 18:57:53 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 011CE2B881 for ; Tue, 22 Jan 2019 18:57:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726125AbfAVS5v (ORCPT ); Tue, 22 Jan 2019 13:57:51 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:52275 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725973AbfAVS5v (ORCPT ); Tue, 22 Jan 2019 13:57:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=frGw6BtLrRXqtf68jN/FY7N/SYt7ggqcquqJAI/hdO8=; b=KN3Ud+la+fJ9 sGkwbmt7tqQ/xvlvZnlHzmw2QcUqgQPJKOW+AQqQ+/d7I2uxfCWf0S0koZHrqkm/k98M32vueGk4M 4BC89ghjJSEGy0L9zjYFoRHsVBpzHKp9lVOzKvyF8CSeZYvtFH6NSMS1JLwNo1xb9NmA7tQ9rnOb7 IPJ5Zo4ojPLc9XD/hwM4FrYbZ7x6BC0dCMchiaDn+tzY21Meoc5p0GSjwwvJFkdn6GDQ/xVwQAnnJ vGS5h3E8H/mEEfS3jbfCrwgTG11YH4HjWbivBZQj3VeAuBWL3Pvukn8bmlRanNfAP2iyYdkqSCt+s yY12Udqx4XTZT58HJ0wClg==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gm1F0-0007tf-48; Tue, 22 Jan 2019 19:57:43 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 41CE1C03A4; Tue, 22 Jan 2019 19:57:36 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Douglas Gilbert , Hannes Reinecke , Christoph Hellwig Subject: [PATCH 2/7] Change scsi_cmnd.prot_sdb from a pointer into a regular member Date: Tue, 22 Jan 2019 10:57:19 -0800 Message-Id: <20190122185724.71598-3-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190122185724.71598-1-bvanassche@acm.org> References: <20190122185724.71598-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.02) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5spzpXhxXEsLLxGVGSV2Lhx602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTZnx3upumnqWBHj0/Vmi/pASQQA8gPlICyOXF4VQA3r681n IyHanrMzYl1QUFnGrJlGZdzQSLJYSD89hpteF8v30ykPg8qyrdUV98WGlbOjhJdwZpOImhB57vlA Ovnv7bRi5a8LLfqBhzJbqPiIMA+NOnrCrjOMG+XIApsj4flbNpUCGeLmhx53FRJAP1Ea5ASWYHcP 06zXqyXOojRJS4zkyuN79ijOJ9Wkc9fESwXowATJsjWw5+0eZIpQIcK9yrRZBI4MtpSGpU9W4FdB tQesEelBF7Ngqas1fLSi+EsXiGRbN4cS9m3JKQpYnU+jEObu+ZQGpXspg4TOqv23+spbzJ3vJBBY vcIXZcvdbj7fjbZn+1a2iCCdPFy3WGiBkBZc+BBb+UeYFBhPAZQ65C2d4vB6Mmh6nzlzGKK4CNTd FmC4kGAnKNZdqPIYy5/0C0oKEgxQF7G4ajroXShVPl5s3ZvBSOdcZaQYlKee2Vxut4iZ5ZA89caf AqxM+VvJzb/lgTl6fJxyntEfhZCKje4ZQ0jUIEfcq3/8iFZW9aviZrI0q854skGDr1SFWz9TrEbL my3uPSE9vyN9HoGBpQQMs9mOAuVGeNoxAGUS1QpH0KIcRmoNU2oljXXErZz3MdU5SJeoVHj5h7lL 06fEAVxIuI4woYdcsisZprERKCJ/DvnsRHe+Pt9t+Eh/Rnkbg1ebB7wNnr0OT6lR90krruHQUoks aCfSH23JFY6Md8TPjYHoRQJhikEW6KsZ+zue7BC3AMAEl0rnf3CZyCzXyHvANPJxkPHiWBBpWvV/ D/1d7+l+PmxJCFvdxzgiQpciHL7m0tbh53ymoHabC27dTg89WgJaW/G0kE3yNq7EjGY4RUfwaLrL D5IbOw/tQxqtiIkeujkNDaI1BZL4xlheqFLWBRCKDV/xyIgf7xGwA25MeVhd7+Z3ohEuqbhw2IGi K9BLVundUFjc1iJ5Hl/Q7TeMzDg6HYuTCyYgL61SIkBTYQaaIIEsvvc4Hs2Al+JCBW+Rho4Ph4F7 35SUHIxrP601Lz/dsiahQ1DFoGJGH4QvNEG2z3H+DG8i/+nwAPUMRDNTlQhcPtKTIltiNXw4wYHH 9itV4zOHtaDgH2x2DZDqYQ== X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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 This patch slightly increases the size of struct scsi_cmnd if data protection is disabled, decreases the size of the data appended at the end of struct scsi_cmnd if data protection is enabled and simplifies the SCSI core. Cc: Douglas Gilbert Cc: Hannes Reinecke Cc: Christoph Hellwig Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 33 ++++++++++++--------------------- include/scsi/scsi_cmnd.h | 8 ++++---- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 94842b104bcc..6bfbe50ef38e 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -566,7 +566,7 @@ static void scsi_mq_free_sgtables(struct scsi_cmnd *cmd) sg_free_table_chained(&sdb->table, true); } if (scsi_prot_sg_count(cmd)) - sg_free_table_chained(&cmd->prot_sdb->table, true); + sg_free_table_chained(&cmd->prot_sdb.table, true); } static void scsi_mq_uninit_cmd(struct scsi_cmnd *cmd) @@ -1065,10 +1065,10 @@ blk_status_t scsi_init_io(struct scsi_cmnd *cmd) } if (blk_integrity_rq(rq)) { - struct scsi_data_buffer *prot_sdb = cmd->prot_sdb; + struct scsi_data_buffer *prot_sdb = &cmd->prot_sdb; int ivecs, count; - if (WARN_ON_ONCE(!prot_sdb)) { + if (WARN_ON_ONCE(!scsi_host_get_prot(cmd->device->host))) { /* * This can happen if someone (e.g. multipath) * queues a command to a device on an adapter @@ -1091,8 +1091,7 @@ blk_status_t scsi_init_io(struct scsi_cmnd *cmd) BUG_ON(count > ivecs); BUG_ON(count > queue_max_integrity_segments(rq->q)); - cmd->prot_sdb = prot_sdb; - cmd->prot_sdb->table.nents = count; + prot_sdb->table.nents = count; } return BLK_STS_OK; @@ -1156,7 +1155,6 @@ void scsi_del_cmd_from_list(struct scsi_cmnd *cmd) void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd) { void *buf = cmd->sense_buffer; - void *prot = cmd->prot_sdb; struct request *rq = blk_mq_rq_from_pdu(cmd); unsigned int flags = cmd->flags & SCMD_PRESERVED_FLAGS; unsigned long jiffies_at_alloc; @@ -1175,7 +1173,6 @@ void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd) cmd->device = dev; cmd->sense_buffer = buf; - cmd->prot_sdb = prot; cmd->flags = flags; INIT_DELAYED_WORK(&cmd->abort_work, scmd_eh_abort_handler); cmd->jiffies_at_alloc = jiffies_at_alloc; @@ -1617,12 +1614,13 @@ static blk_status_t scsi_mq_prep_fn(struct request *req) sg = (void *)cmd + sizeof(struct scsi_cmnd) + shost->hostt->cmd_size; cmd->sdb.table.sgl = sg; - if (scsi_host_get_prot(shost)) { - memset(cmd->prot_sdb, 0, sizeof(struct scsi_data_buffer)); - - cmd->prot_sdb->table.sgl = - (struct scatterlist *)(cmd->prot_sdb + 1); - } + /* + * Always initialize cmd->prot_sdb.nents such that + * scsi_prot_sg_count() does not have to call scsi_host_get_prot(). + */ + memset(&cmd->prot_sdb, 0, sizeof(struct scsi_data_buffer)); + if (scsi_host_get_prot(shost)) + cmd->prot_sdb.table.sgl = (void *)&sg + scsi_mq_sgl_size(shost); if (blk_bidi_rq(req)) { struct request *next_rq = req->next_rq; @@ -1781,7 +1779,6 @@ static int scsi_mq_init_request(struct blk_mq_tag_set *set, struct request *rq, struct Scsi_Host *shost = set->driver_data; const bool unchecked_isa_dma = shost->unchecked_isa_dma; struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); - struct scatterlist *sg; if (unchecked_isa_dma) cmd->flags |= SCMD_UNCHECKED_ISA_DMA; @@ -1791,12 +1788,6 @@ static int scsi_mq_init_request(struct blk_mq_tag_set *set, struct request *rq, return -ENOMEM; cmd->req.sense = cmd->sense_buffer; - if (scsi_host_get_prot(shost)) { - sg = (void *)cmd + sizeof(struct scsi_cmnd) + - shost->hostt->cmd_size; - cmd->prot_sdb = (void *)sg + scsi_mq_sgl_size(shost); - } - return 0; } @@ -1893,7 +1884,7 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost) sgl_size = scsi_mq_sgl_size(shost); cmd_size = sizeof(struct scsi_cmnd) + shost->hostt->cmd_size + sgl_size; if (scsi_host_get_prot(shost)) - cmd_size += sizeof(struct scsi_data_buffer) + sgl_size; + cmd_size += sgl_size; memset(&shost->tag_set, 0, sizeof(shost->tag_set)); shost->tag_set.ops = &scsi_mq_ops; diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index d85e6befa26b..0406c0fbee3e 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -108,7 +108,7 @@ struct scsi_cmnd { /* These elements define the operation we ultimately want to perform */ struct scsi_data_buffer sdb; - struct scsi_data_buffer *prot_sdb; + struct scsi_data_buffer prot_sdb; unsigned underflow; /* Return error if less than this amount is transferred */ @@ -318,17 +318,17 @@ static inline unsigned int scsi_prot_interval(struct scsi_cmnd *scmd) static inline unsigned scsi_prot_sg_count(struct scsi_cmnd *cmd) { - return cmd->prot_sdb ? cmd->prot_sdb->table.nents : 0; + return cmd->prot_sdb.table.nents; } static inline struct scatterlist *scsi_prot_sglist(struct scsi_cmnd *cmd) { - return cmd->prot_sdb ? cmd->prot_sdb->table.sgl : NULL; + return cmd->prot_sdb.table.sgl; } static inline struct scsi_data_buffer *scsi_prot(struct scsi_cmnd *cmd) { - return cmd->prot_sdb; + return &cmd->prot_sdb; } #define scsi_for_each_prot_sg(cmd, sg, nseg, __i) \ From patchwork Tue Jan 22 18:57:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10776119 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5AEB41575 for ; Tue, 22 Jan 2019 18:57:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49F862B881 for ; Tue, 22 Jan 2019 18:57:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E8F42B977; Tue, 22 Jan 2019 18:57:53 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 A9BF92B885 for ; Tue, 22 Jan 2019 18:57:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726143AbfAVS5w (ORCPT ); Tue, 22 Jan 2019 13:57:52 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:33947 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725971AbfAVS5v (ORCPT ); Tue, 22 Jan 2019 13:57:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=DuBwAtsmsZt5v6ryC2Dpj5Cj2kVHJBGhEbgi/wnEoJ8=; b=X+54EgWjXerT VutmRNfQD926WORlf7UbigtcG46vykMPLgQN2YZK3i+tXi9HyLiSDdJ6lxzMSYNZi39JnrluW/93o o1y0f12SnJZf4kahubfbsE0SQdxA1WEbCKmQjJB3DGdfmYu1fPGlt/86vWF0SbxV6iey8ts+K3s/+ w1NDk2v81tkp4MMsOuQ+XUpvWq4LE4pnHrYh/LSCvnkS9QkxMpmwM9KGxJ7EJqMbjLfSqmZOj2rvV m3A70fhyh9YI6B7GRrEAtY3qLByUSsWJKcfGq8uRtQO8gMCRbs2Ha7/lGKg5BJQ/eBLX9koIKricd ST+zZDDcTdGedIx2bVqAUg==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gm1F0-00038L-I4; Tue, 22 Jan 2019 19:57:43 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 2BC3DC060F; Tue, 22 Jan 2019 19:57:38 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Douglas Gilbert , Hannes Reinecke , Christoph Hellwig Subject: [PATCH 3/7] Fix bidi handling Date: Tue, 22 Jan 2019 10:57:20 -0800 Message-Id: <20190122185724.71598-4-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190122185724.71598-1-bvanassche@acm.org> References: <20190122185724.71598-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.02) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5vv/HCFcD/W/pHvaDzazPZh602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTZnx3upumnqWBHj0/Vmi/pASQQA8gPlICyOXF4VQA3r681n IyHanrMzYl1QUFnGrJlGZdzQSLJYSD89hpteF8v30ykPg8qyrdUV98WGlbOjhJdwZpOImhB57vlA Ovnv7bRi5a8LLfqBhzJbqPiIMA+NOnrCrjOMG+XIApsj4flbNpUCGeLmhx53FRJAP1Ea5ASWYHcP 06zXqyXOojRJS4zkVbgBn+Q0GuNjx7gc4jPUyATJsjWw5+0eZIpQIcK9yrRZBI4MtpSGpU9W4FdB tQesEelBF7Ngqas1fLSi+EsXiO7J//0XCxCMJn8bXo41UD3u+ZQGpXspg4TOqv23+spbzJ3vJBBY vcIXZcvdbj7fjbZn+1a2iCCdPFy3WGiBkBZc+BBb+UeYFBhPAZQ65C2d4vB6Mmh6nzlzGKK4CNTd FmC4kGAnKNZdqPIYy5/0C0oKEgxQF7G4ajroXShVPl5s3ZvBSOdcZaQYlKee2Vxut4iZ5ZA89caf AqxM+VvJzb/lgTl6fJxyntEfhZCKje4ZQ0jUIEfcq3/8iFZW9aviZrI0q854skGDr1SFWz9TrEbL my3uPSE9vyN9HoGBpQQMs9mOAuVGeNoxAGUS1QpH0KIcRmoNU2oljXXErZz3MdU5SJeoVHj5h7lL 06fEAVxIzKeWFsL83KrakodIBOvGMfnsRHe+Pt9t+Eh/Rnkbg1c9JV9/yDT3tDsqMHnaDdezUoks aCfSH23JFY6Md8TPjYHoRQJhikEW6KsZ+zue7BC3AMAEl0rnf3CZyCzXyHvANPJxkPHiWBBpWvV/ D/1d7+l+PmxJCFvdxzgiQpciHL7m0tbh53ymoHabC27dTg89WgJaW/G0kE3yNq7EjGY4RXAE5Rz5 XwbE7oPRMo0rGRQeujkNDaI1BZL4xlheqFLWBRCKDV/xyIgf7xGwA25MeVhd7+Z3ohEuqbhw2IGi K9BLVundUFjc1iJ5Hl/Q7TeMzDg6HYuTCyYgL61SIkBTYQaaIIEsvvc4Hs2Al+JCBW+Rho4Ph4F7 35SUHIxrP601Lz/dsiahQ1DFoGJGH4QvNEG2z3H+DG8i/+nwAPUMRDNTlQhcPtKTIltiNXw4wYHH 9itV4zOHtaDgH2x2DZDqYQ== X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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 Some code in the SCSI core interprets blk_mq_rq_to_pdu(cmd->request->next_rq) as a struct scsi_data_buffer, e.g. scsi_mq_prep_fn(). Other code in the SCSI core interprets the same data structure as a struct scsi_request, e.g. scsi_io_completion(). Avoid this confusion by using the SCSI data buffer associated with "next_rq" for bidi requests. This patch avoids that submitting a bidi command triggers a NULL pointer dereference. Reported-by: Douglas Gilbert Cc: Douglas Gilbert Cc: Hannes Reinecke Cc: Christoph Hellwig Fixes: d285203cf647 ("scsi: add support for a blk-mq based I/O path.") # v3.17 Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 35 +++++++++++++++-------------------- include/scsi/scsi_cmnd.h | 13 +++++++++---- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 6bfbe50ef38e..54902afb8d94 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -556,15 +556,10 @@ static void scsi_uninit_cmd(struct scsi_cmnd *cmd) static void scsi_mq_free_sgtables(struct scsi_cmnd *cmd) { - struct scsi_data_buffer *sdb; - if (cmd->sdb.table.nents) sg_free_table_chained(&cmd->sdb.table, true); - if (cmd->request->next_rq) { - sdb = cmd->request->next_rq->special; - if (sdb) - sg_free_table_chained(&sdb->table, true); - } + if (scsi_bidi_cmnd(cmd)) + sg_free_table_chained(&scsi_in(cmd)->table, true); if (scsi_prot_sg_count(cmd)) sg_free_table_chained(&cmd->prot_sdb.table, true); } @@ -1059,7 +1054,7 @@ blk_status_t scsi_init_io(struct scsi_cmnd *cmd) return ret; if (blk_bidi_rq(rq)) { - ret = scsi_init_sgtable(rq->next_rq, rq->next_rq->special); + ret = scsi_init_sgtable(rq->next_rq, scsi_in(cmd)); if (ret) goto out_free_sgtables; } @@ -1595,12 +1590,17 @@ static unsigned int scsi_mq_sgl_size(struct Scsi_Host *shost) sizeof(struct scatterlist); } +static void scsi_init_sdb(struct scsi_cmnd *cmd) +{ + cmd->sdb.table.sgl = (void *)cmd + sizeof(struct scsi_cmnd) + + cmd->device->host->hostt->cmd_size; +} + static blk_status_t scsi_mq_prep_fn(struct request *req) { struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); struct scsi_device *sdev = req->q->queuedata; struct Scsi_Host *shost = sdev->host; - struct scatterlist *sg; scsi_init_command(sdev, cmd); @@ -1611,8 +1611,7 @@ static blk_status_t scsi_mq_prep_fn(struct request *req) cmd->tag = req->tag; cmd->prot_op = SCSI_PROT_NORMAL; - sg = (void *)cmd + sizeof(struct scsi_cmnd) + shost->hostt->cmd_size; - cmd->sdb.table.sgl = sg; + scsi_init_sdb(cmd); /* * Always initialize cmd->prot_sdb.nents such that @@ -1620,17 +1619,13 @@ static blk_status_t scsi_mq_prep_fn(struct request *req) */ memset(&cmd->prot_sdb, 0, sizeof(struct scsi_data_buffer)); if (scsi_host_get_prot(shost)) - cmd->prot_sdb.table.sgl = (void *)&sg + scsi_mq_sgl_size(shost); + cmd->prot_sdb.table.sgl = (void *)&cmd->sdb + + scsi_mq_sgl_size(shost); if (blk_bidi_rq(req)) { - struct request *next_rq = req->next_rq; - struct scsi_data_buffer *bidi_sdb = blk_mq_rq_to_pdu(next_rq); - - memset(bidi_sdb, 0, sizeof(struct scsi_data_buffer)); - bidi_sdb->table.sgl = - (struct scatterlist *)(bidi_sdb + 1); - - next_rq->special = bidi_sdb; + memset(&scsi_in_cmd(cmd)->sdb, 0, + sizeof(scsi_in_cmd(cmd)->sdb)); + scsi_init_sdb(scsi_in_cmd(cmd)); } blk_mq_start_request(req); diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index 0406c0fbee3e..78183e851a0d 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -215,14 +215,19 @@ static inline int scsi_get_resid(struct scsi_cmnd *cmd) static inline int scsi_bidi_cmnd(struct scsi_cmnd *cmd) { - return blk_bidi_rq(cmd->request) && - (cmd->request->next_rq->special != NULL); + return blk_bidi_rq(cmd->request); +} + +static inline struct scsi_cmnd *scsi_in_cmd(struct scsi_cmnd *cmd) +{ + if (likely(!scsi_bidi_cmnd(cmd))) + return cmd; + return blk_mq_rq_to_pdu(cmd->request->next_rq); } static inline struct scsi_data_buffer *scsi_in(struct scsi_cmnd *cmd) { - return scsi_bidi_cmnd(cmd) ? - cmd->request->next_rq->special : &cmd->sdb; + return &scsi_in_cmd(cmd)->sdb; } static inline struct scsi_data_buffer *scsi_out(struct scsi_cmnd *cmd) From patchwork Tue Jan 22 18:57:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10776123 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 59340139A for ; Tue, 22 Jan 2019 18:57:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 484952B881 for ; Tue, 22 Jan 2019 18:57:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C54E2B945; Tue, 22 Jan 2019 18:57:54 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 DACF92B881 for ; Tue, 22 Jan 2019 18:57:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726167AbfAVS5x (ORCPT ); Tue, 22 Jan 2019 13:57:53 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:36649 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725973AbfAVS5w (ORCPT ); Tue, 22 Jan 2019 13:57:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=GJk5WbJ6z077w6cyJB3NsBznYGn7AkP4gFgqZYAGhRw=; b=jpP8N11OeWDs dPNi9S1xnyjLlLw4JsIuap8HkImlBsPqAKxp7hfY5cuGEyPo2t5GwHDMGHbi3A2UL8Bl6E7fefw+d qJuwJeQS95hDlJlvAoZHKqUMAAfn/zOt7c3r5nmxI+eUHXfBywzAuA61oMqYwRolDAkGag4dm5iwf CB2/oItMbbD8i+a8i8U1vdW48wGnWpBcoeAu118VK3NgowMyJSUV0F9Q36TzcyFR4Mu89zD01whiC IdO9B/nT05mo7OqFxw8479D9JAsCxYdq/EJvLoQNFehmMmHhMcYabctTgryHD3D7bc7yduTBiN9S1 Lrx1KxrPKg5VLhBpFvO1qQ==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gm1F2-0007tn-NO; Tue, 22 Jan 2019 19:57:44 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 207E4C0AED; Tue, 22 Jan 2019 19:57:39 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Douglas Gilbert , Hannes Reinecke , Christoph Hellwig Subject: [PATCH 4/7] Introduce scsi_out_cmd() Date: Tue, 22 Jan 2019 10:57:21 -0800 Message-Id: <20190122185724.71598-5-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190122185724.71598-1-bvanassche@acm.org> References: <20190122185724.71598-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.04) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5m7UtobRTGEnsGSv7j4Yzad602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTZnx3upumnqWBHj0/Vmi/pASQQA8gPlICyOXF4VQA3r681n IyHanrMzYl1QUFnGrJlGZdzQSLJYSD89hpteF8v30ykPg8qyrdUV98WGlbOjhJdwZpOImhB57vlA Ovnv7bRi5a8LLfqBhzJbqPiIMA+NOnrCrjOMG+XIApsj4flbNpUCGeLmhx53FRJAP1Ea5ASWYHcP 06zXqyXOojRJS4zk5E1aXB5cTkSFdc9E7Pg4+gTJsjWw5+0eZIpQIcK9yrRZBI4MtpSGpU9W4FdB tQesEelBF7Ngqas1fLSi+EsXiGRbN4cS9m3JKQpYnU+jEObu+ZQGpXspg4TOqv23+spbzJ3vJBBY vcIXZcvdbj7fjbZn+1a2iCCdPFy3WGiBkBZc+BBb+UeYFBhPAZQ65C2d4vB6Mmh6nzlzGKK4CNTd FmC4kGAnKNZdqPIYy5/0C0oKEgxQF7G4ajroXShVPl5s3ZvBSOdcZaQYlKee2Vxut4iZ5ZA89caf AqxM+VvJzb/lgTl6fJxyntEfhZCKje4ZQ0jUIEfcq3/8iFZW9aviZrI0q854skGDr1SFWz9TrEbL my3uPSE9vyN9HoGBpQQMs9mOAuVGeNoxAGUS1QpH0KIcRmoNU2oljXXErZz3MdU5SJeoVHj5h7lL 06fEAVxIuI4woYdcsisZprERKCJ/DvnsRHe+Pt9t+Eh/Rnkbg1f7nPK3lA4H4OBmhIEmuil2Uoks aCfSH23JFY6Md8TPjYHoRQJhikEW6KsZ+zue7BC3AMAEl0rnf3CZyCzXyHvANPJxkPHiWBBpWvV/ D/1d7+l+PmxJCFvdxzgiQpciHL7m0tbh53ymoHabC27dTg89xPTZeSbMJIq+jp826TueZK8c2WZc DPkJlAeXMLh3BnAeujkNDaI1BZL4xlheqFLWBRCKDV/xyIgf7xGwA25MeVhd7+Z3ohEuqbhw2IGi K9BLVundUFjc1iJ5Hl/Q7TeMzDg6HYuTCyYgL61SIkBTYQaaIIEsvvc4Hs2Al+JCBW+Rho4Ph4F7 35SUHIxrP601Lz/dsiahQ1DFoGJGH4QvNEG2z3H+DG8i/+nwAPUMRDNTlQhcPtKTIltiNXw4wYHH 9itV4zOHtaDgH2x2DZDqYQ== X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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 This patch does not change any functionality. Cc: Douglas Gilbert Cc: Hannes Reinecke Cc: Christoph Hellwig Signed-off-by: Bart Van Assche --- include/scsi/scsi_cmnd.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index 78183e851a0d..213404163993 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -230,9 +230,14 @@ static inline struct scsi_data_buffer *scsi_in(struct scsi_cmnd *cmd) return &scsi_in_cmd(cmd)->sdb; } +static inline struct scsi_cmnd *scsi_out_cmd(struct scsi_cmnd *cmd) +{ + return cmd; +} + static inline struct scsi_data_buffer *scsi_out(struct scsi_cmnd *cmd) { - return &cmd->sdb; + return &scsi_out_cmd(cmd)->sdb; } static inline int scsi_sg_copy_from_buffer(struct scsi_cmnd *cmd, From patchwork Tue Jan 22 18:57:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10776125 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BA5AF1399 for ; Tue, 22 Jan 2019 18:57:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A97AF2B881 for ; Tue, 22 Jan 2019 18:57:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DCC82B945; Tue, 22 Jan 2019 18:57:55 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 269B22B881 for ; Tue, 22 Jan 2019 18:57:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726191AbfAVS5y (ORCPT ); Tue, 22 Jan 2019 13:57:54 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:46731 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726118AbfAVS5y (ORCPT ); Tue, 22 Jan 2019 13:57:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=S6v0RikNLVSH1Mdy7HmMBWrG3Q7N7Jr/xheS3I0F0kQ=; b=v3esdPJMijm0 9ivUT/A7ktTDxLET/hOmpymaXx8insCCSpgj/bmbDLIaBVCbL+Tyiyj3U6H08+3owB5WZVH4V2ymc bpHCflncibFvcD2/hY5tGpzvxGbj8u0CPSeJL3Z5TXHsTAkDz2y7ErD9VogRlDGBpzChArM8zRqS8 SUuBqu8FZAk9ALJ+XCvzsPTmk6lvKLbQA0aateMLXt9cS9cmuNbX4M2/vWZfdZSTlhMoAeB33aKzq x71svX3SnclBttVjDUb4JtEqcxWMrtuHVkbT9HujFqSe/VcoOt8gcf6MJTXYXbrgajYP6yuPjupwc 4FWMJbDqf2z7g92wdUBsWw==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gm1F4-00039L-JU; Tue, 22 Jan 2019 19:57:47 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 54202C03A4; Tue, 22 Jan 2019 19:57:42 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Douglas Gilbert , Hannes Reinecke , Christoph Hellwig Subject: [PATCH 5/7] Move several function definitions in Date: Tue, 22 Jan 2019 10:57:22 -0800 Message-Id: <20190122185724.71598-6-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190122185724.71598-1-bvanassche@acm.org> References: <20190122185724.71598-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00268726139331) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5oR9/KNgQnrhgL8RBtstnDJ602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTZnx3upumnqWBHj0/Vmi/pASQQA8gPlICyOXF4VQA3r681n IyHanrMzYl1QUFnGrJlGZdzQSLJYSD89hpteF8v30ykPg8qyrdUV98WGlbOjhJdwZpOImhB57vlA Ovnv7bRi5a8LLfqBhzJbqPiIMA+NOnrCrjOMG+XIApsj4flbNpUCGeLmhx53FRJAP1Ea5ASWYHcP 06zXqyXOojRJS4zkVrKVPIbdaOl1Fe3hzZsK4gTJsjWw5+0eZIpQIcK9yrRZBI4MtpSGpU9W4FdB tQesEelBF7Ngqas1fLSi+EsXiO7J//0XCxCMJn8bXo41UD3u+ZQGpXspg4TOqv23+spbzJ3vJBBY vcIXZcvdbj7fjbZn+1a2iCCdPFy3WGiBkBZc+BBb+UeYFBhPAZQ65C2d4vB6Mmh6nzlzGKK4CNTd FmC4kGAnKNZdqPIYy5/0C0oKEgxQF7G4ajroXShVPl5s3ZvBSOdcZaQYlKee2Vxut+excQEBokpi mN+IpZsSCXc5abhTdeMRIGIFGG7eQynS17NirEYyqwqMBGrw8ELiqFSHA33y5Mb3HyPilJ6ZEZbN sFlW4xzv3KSabGJbxYTP9L1EoXi+CD9t4odUMDuXpq4Dt0gTEK9vOlOvpFXXjOyucj735mFcFqoc 4yysvQM8ASJFC/49WOPBr5nlEUI4xIoCyX1J9mISBKtKiIG9rsVhspljkOhpjzwdmRUuxUAkyXqC tfrztZu1+QjPVsBXsdMqpQY/wTdSn/KmmRPQe1WngoWueOlSkfQrrNQ0YaVuKF0zwGgxiH5VYpT1 74cN8FvxDejqc1gSvA2YxCROcMK2BmRxGQKegzOmzXDxmXJaDPc+rUuIsEwVJ+BZMX32wpPG3Dyp f2R754l46ZdvINjq87XJdI/MD0YfeC5i3/+cUV8ShebT8U8Xw9HTDfreWRYYPDOuh+QYnmwzDWDO +6vF+qi4JhiyJsp7oQFHICv3/5BQ64Vz3kPXuj5BYP5ioVC/LbdJldJ8xntHMcYfWXZf0dFZX9FP 4Sdv0y+AiR3/grHo9BntmBzD6tps2qyeMO7J//0XCxCMJn8bXo41UD2nJ33TKG1BQebqdAt2Cyon bEaUvgji2bemCFdq6WVPktdpl4o13pcoUjSBRABE8Sc= X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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 Since the next patch will call scsi_out_cmd() from scsi_[gs]et_resid(), reorder the function definitions in . Cc: Douglas Gilbert Cc: Hannes Reinecke Cc: Christoph Hellwig Signed-off-by: Bart Van Assche --- include/scsi/scsi_cmnd.h | 50 ++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index 213404163993..673980ed7db6 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -185,61 +185,61 @@ static inline int scsi_dma_map(struct scsi_cmnd *cmd) { return -ENOSYS; } static inline void scsi_dma_unmap(struct scsi_cmnd *cmd) { } #endif /* !CONFIG_SCSI_DMA */ -static inline unsigned scsi_sg_count(struct scsi_cmnd *cmd) +static inline int scsi_bidi_cmnd(struct scsi_cmnd *cmd) { - return cmd->sdb.table.nents; + return blk_bidi_rq(cmd->request); } -static inline struct scatterlist *scsi_sglist(struct scsi_cmnd *cmd) +static inline struct scsi_cmnd *scsi_in_cmd(struct scsi_cmnd *cmd) { - return cmd->sdb.table.sgl; + if (likely(!scsi_bidi_cmnd(cmd))) + return cmd; + return blk_mq_rq_to_pdu(cmd->request->next_rq); } -static inline unsigned scsi_bufflen(struct scsi_cmnd *cmd) +static inline struct scsi_data_buffer *scsi_in(struct scsi_cmnd *cmd) { - return cmd->sdb.length; + return &scsi_in_cmd(cmd)->sdb; } -static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid) +static inline struct scsi_cmnd *scsi_out_cmd(struct scsi_cmnd *cmd) { - cmd->sdb.resid = resid; + return cmd; } -static inline int scsi_get_resid(struct scsi_cmnd *cmd) +static inline struct scsi_data_buffer *scsi_out(struct scsi_cmnd *cmd) { - return cmd->sdb.resid; + return &scsi_out_cmd(cmd)->sdb; } -#define scsi_for_each_sg(cmd, sg, nseg, __i) \ - for_each_sg(scsi_sglist(cmd), sg, nseg, __i) - -static inline int scsi_bidi_cmnd(struct scsi_cmnd *cmd) +static inline unsigned scsi_sg_count(struct scsi_cmnd *cmd) { - return blk_bidi_rq(cmd->request); + return cmd->sdb.table.nents; } -static inline struct scsi_cmnd *scsi_in_cmd(struct scsi_cmnd *cmd) +static inline struct scatterlist *scsi_sglist(struct scsi_cmnd *cmd) { - if (likely(!scsi_bidi_cmnd(cmd))) - return cmd; - return blk_mq_rq_to_pdu(cmd->request->next_rq); + return cmd->sdb.table.sgl; } -static inline struct scsi_data_buffer *scsi_in(struct scsi_cmnd *cmd) +static inline unsigned scsi_bufflen(struct scsi_cmnd *cmd) { - return &scsi_in_cmd(cmd)->sdb; + return cmd->sdb.length; } -static inline struct scsi_cmnd *scsi_out_cmd(struct scsi_cmnd *cmd) +static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid) { - return cmd; + cmd->sdb.resid = resid; } -static inline struct scsi_data_buffer *scsi_out(struct scsi_cmnd *cmd) +static inline int scsi_get_resid(struct scsi_cmnd *cmd) { - return &scsi_out_cmd(cmd)->sdb; + return cmd->sdb.resid; } +#define scsi_for_each_sg(cmd, sg, nseg, __i) \ + for_each_sg(scsi_sglist(cmd), sg, nseg, __i) + static inline int scsi_sg_copy_from_buffer(struct scsi_cmnd *cmd, void *buf, int buflen) { From patchwork Tue Jan 22 18:57:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10776127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5EF22139A for ; Tue, 22 Jan 2019 18:58:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DEAD2B885 for ; Tue, 22 Jan 2019 18:58:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 422E42B948; Tue, 22 Jan 2019 18:58:20 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 C364F2B885 for ; Tue, 22 Jan 2019 18:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726143AbfAVS6S (ORCPT ); Tue, 22 Jan 2019 13:58:18 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:39991 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726125AbfAVS6S (ORCPT ); Tue, 22 Jan 2019 13:58:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=LYG3fEq6CRjAFQucH6Dvzcckp8brakJ66kK0yb6Cp3k=; b=YIvxoS9QlFa1 eQHQGWUtiRkl953986vRvaGZOkkh2iHPgHt4OCFDXETK9y36ZAzaePbVubyQV/eaxxcY1gb5L9fPo lzRC7/CQxzSclpbO4UMFDNynCpShJo51+RU/3xLM+mEHaBQcc15Bc+25KYK3mn8EDkzqCThjoGNxX ndQcbaGt3vcWrHFURTCOEKFR3zJmvcJqqMz9ZlYZ3xyZ6hKxoMc1lgFVMohq5Ic9rEalqeD9ijWJL XnKqKUOwECffxWFKfAsPraEBdpGtnigRH9YKAvHqWXCvawldcZPW+/Kn3uhliB2CepsUDaxPwOeJM luIxMftH/7BqrtiLbvV/Lg==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gm1F6-00039L-LS; Tue, 22 Jan 2019 19:57:48 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 2C29FC0AED; Tue, 22 Jan 2019 19:57:44 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Douglas Gilbert , Hannes Reinecke , Christoph Hellwig , Lee Duncan , Chris Leech , Paolo Bonzini Subject: [PATCH 6/7] Introduce scsi_in_[sg]et_resid() and scsi_out_[sg]et_resid() Date: Tue, 22 Jan 2019 10:57:23 -0800 Message-Id: <20190122185724.71598-7-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190122185724.71598-1-bvanassche@acm.org> References: <20190122185724.71598-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00682732845345) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5lTU/ZTpJvbiUZIgNPv3kIx602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTZnx3upumnqWBHj0/Vmi/pASQQA8gPlICyOXF4VQA3r681n IyHanrMzYl1QUFnGrJlGZdzQSLJYSD89hpteF8v30ykPg8qyrdUV98WGlbOjhJdwZpOImhB57vlA Ovnv7bTFlefH5GZB2zKlxrpPWIK2tjx4n/PrYhB5hmGmQxMVYVAKkEeH4f3QNjnZQsMBDjH4MJg9 YHIdz0Dl6O7ob5t7s0JmTITK6nc3QbOK5CoO7BGsr2YkQf6GHRtGGbpACH6VAhni5ocedxUSQD9R GuQEjZ892PEyNw69vEzsu606q67x2Ua3T1Mc1WaTf4bbLVYEybI1sOftHmSKUCHCvcq0UIIqcWW4 ifKaEwthyP1VxRXFlYuWrE0vLapFlbaWqJjuyf/9FwsQjCZ/G16ONVA9bTkFsvCGkPVV+auVjHwB H0RhAta0pIzMTTnbIXymD5ebG0Xni7XCo6ehBw6KaJm7DIXqP5P5X1d0cf7YNeX80Mi/IFb8H9P2 UweQHsd5pwaJ7YxW+jLD3ZDBACJzg6v8ChIMUBexuGo66F0oVT5ebO9n9zqkM12Y+COJLnC0ol3n sXEBAaJKYpjfiKWbEgl3w5gS4D3X4kVivwz4Sz4qStezYqxGMqsKjARq8PBC4qj1z+8KP1/w7Nvd xY9bKBxJzbBZVuMc79ykmmxiW8WEz0sosrzI3EdRChAJhsbcCJAeMzveq5eJrexBvOsP5AjXM0S3 Ej9wK9U6T08uj1LhgQEiRQv+PVjjwa+Z5RFCOMRJIinr7MdK9bPW4qgtLAMsxeALkH8Xtdz0W8sw tWz8lpn1AtJbOzlWxsgX2Vgf2jSExp8sAqOQvlCFhGLiUy48iLgMlCvTtx4+HGatF9xp2t6YDkhi 6kKHWGhsE+ciTYPnC9kU8EzzPWXPJewIpRuRtgZkcRkCnoMzps1w8ZlyWoBR0RG0hPasLKXprlc7 I3hAA1Te9AzAvsB5ebmx67gSNSuEgaravxjr32HVMX+LlVFfEoXm0/FPF8PR0w363lmbp5/Z9/y8 d6CkJRuULLE0yNHTe7SA/QklbN9cnl0KNGB1eQxePet6exctZLANANtQvy23SZXSfMZ7RzHGH1l2 3yp/yWvJqZN6SAs+Uz/r0K7dceGa8Ws4pCIiEvrIES7uyf/9FwsQjCZ/G16ONVA9xvkcs7W/3UH1 4Wz64pf2HuQC6llR+qFCQs6UaJKpbflnrkIDSWXgqeBI79lSWqTU X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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 This patch does not change any functionality. Cc: Douglas Gilbert Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: Lee Duncan Cc: Chris Leech Cc: Paolo Bonzini Signed-off-by: Bart Van Assche --- drivers/scsi/libiscsi.c | 12 ++++++------ drivers/scsi/scsi_debug.c | 9 +++++---- drivers/scsi/sd.c | 4 ++-- drivers/scsi/virtio_scsi.c | 4 ++-- include/scsi/scsi_cmnd.h | 24 ++++++++++++++++++++++-- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index b8d325ce8754..fe5b3371553c 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -650,8 +650,8 @@ static void fail_scsi_task(struct iscsi_task *task, int err) if (!scsi_bidi_cmnd(sc)) scsi_set_resid(sc, scsi_bufflen(sc)); else { - scsi_out(sc)->resid = scsi_out(sc)->length; - scsi_in(sc)->resid = scsi_in(sc)->length; + scsi_out_set_resid(sc, scsi_out(sc)->length); + scsi_in_set_resid(sc, scsi_in(sc)->length); } /* regular RX path uses back_lock */ @@ -912,7 +912,7 @@ static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr, if (scsi_bidi_cmnd(sc) && res_count > 0 && (rhdr->flags & ISCSI_FLAG_CMD_BIDI_OVERFLOW || res_count <= scsi_in(sc)->length)) - scsi_in(sc)->resid = res_count; + scsi_in_set_resid(sc, res_count); else sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status; } @@ -962,7 +962,7 @@ iscsi_data_in_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr, if (res_count > 0 && (rhdr->flags & ISCSI_FLAG_CMD_OVERFLOW || res_count <= scsi_in(sc)->length)) - scsi_in(sc)->resid = res_count; + scsi_in_set_resid(sc, res_count); else sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status; } @@ -1807,8 +1807,8 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) if (!scsi_bidi_cmnd(sc)) scsi_set_resid(sc, scsi_bufflen(sc)); else { - scsi_out(sc)->resid = scsi_out(sc)->length; - scsi_in(sc)->resid = scsi_in(sc)->length; + scsi_out_set_resid(sc, scsi_out(sc)->length); + scsi_in_set_resid(sc, scsi_in(sc)->length); } sc->scsi_done(sc); return 0; diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index e253c0129b40..822aed12ca31 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -1019,7 +1019,7 @@ static int fill_from_dev_buffer(struct scsi_cmnd *scp, unsigned char *arr, act_len = sg_copy_from_buffer(sdb->table.sgl, sdb->table.nents, arr, arr_len); - sdb->resid = scsi_bufflen(scp) - act_len; + scsi_in_set_resid(scp, scsi_bufflen(scp) - act_len); return 0; } @@ -1044,9 +1044,10 @@ static int p_fill_from_dev_buffer(struct scsi_cmnd *scp, const void *arr, act_len = sg_pcopy_from_buffer(sdb->table.sgl, sdb->table.nents, arr, arr_len, skip); pr_debug("%s: off_dst=%u, scsi_bufflen=%u, act_len=%u, resid=%d\n", - __func__, off_dst, scsi_bufflen(scp), act_len, sdb->resid); + __func__, off_dst, scsi_bufflen(scp), act_len, + scsi_in_get_resid(scp)); n = (int)scsi_bufflen(scp) - ((int)off_dst + act_len); - sdb->resid = min(sdb->resid, n); + scsi_in_set_resid(scp, min(scsi_in_get_resid(scp), n)); return 0; } @@ -2774,7 +2775,7 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) if (unlikely(ret == -1)) return DID_ERROR << 16; - scsi_in(scp)->resid = scsi_bufflen(scp) - ret; + scsi_in_set_resid(scp, scsi_bufflen(scp) - ret); if (unlikely(sqcp)) { if (sqcp->inj_recovered) { diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index b0eb83526c54..2219ba81f0b3 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -844,7 +844,7 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd) cmd->allowed = SD_MAX_RETRIES; cmd->transfersize = data_len; rq->timeout = SD_TIMEOUT; - scsi_req(rq)->resid_len = data_len; + scsi_set_resid(cmd, data_len); return scsi_init_io(cmd); } @@ -908,7 +908,7 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd, cmd->allowed = SD_MAX_RETRIES; cmd->transfersize = data_len; rq->timeout = unmap ? SD_TIMEOUT : SD_WRITE_SAME_TIMEOUT; - scsi_req(rq)->resid_len = data_len; + scsi_set_resid(cmd, data_len); return scsi_init_io(cmd); } diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c index 772b976e4ee4..47888649f6b8 100644 --- a/drivers/scsi/virtio_scsi.c +++ b/drivers/scsi/virtio_scsi.c @@ -108,8 +108,8 @@ static void virtscsi_compute_resid(struct scsi_cmnd *sc, u32 resid) return; } - scsi_in(sc)->resid = min(resid, scsi_in(sc)->length); - scsi_out(sc)->resid = resid - scsi_in(sc)->resid; + scsi_in_set_resid(sc, min(resid, scsi_in(sc)->length)); + scsi_out_set_resid(sc, resid - scsi_in_get_resid(sc)); } /** diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index 673980ed7db6..8f3ed55a5ee5 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -227,16 +227,36 @@ static inline unsigned scsi_bufflen(struct scsi_cmnd *cmd) return cmd->sdb.length; } -static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid) +static inline void scsi_in_set_resid(struct scsi_cmnd *cmd, int resid) +{ + scsi_in_cmd(cmd)->sdb.resid = resid; +} + +static inline int scsi_in_get_resid(struct scsi_cmnd *cmd) +{ + return scsi_in_cmd(cmd)->sdb.resid; +} + +static inline void scsi_out_set_resid(struct scsi_cmnd *cmd, int resid) { cmd->sdb.resid = resid; } -static inline int scsi_get_resid(struct scsi_cmnd *cmd) +static inline int scsi_out_get_resid(struct scsi_cmnd *cmd) { return cmd->sdb.resid; } +static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid) +{ + return scsi_out_set_resid(cmd, resid); +} + +static inline int scsi_get_resid(struct scsi_cmnd *cmd) +{ + return scsi_out_get_resid(cmd); +} + #define scsi_for_each_sg(cmd, sg, nseg, __i) \ for_each_sg(scsi_sglist(cmd), sg, nseg, __i) From patchwork Tue Jan 22 18:57:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10776133 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 77E5F139A for ; Tue, 22 Jan 2019 19:00:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 661B12B61E for ; Tue, 22 Jan 2019 19:00:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A4B52B67C; Tue, 22 Jan 2019 19:00:12 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 DB7C72B61E for ; Tue, 22 Jan 2019 19:00:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726069AbfAVTAL (ORCPT ); Tue, 22 Jan 2019 14:00:11 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:53649 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725973AbfAVTAL (ORCPT ); Tue, 22 Jan 2019 14:00:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=BGQmiYJsJ0Q9zl8Y1yq5tF9Bx0g7fGLkworC9WuFQzE=; b=ZE2G7mSiJ829 dM1XtGPqpJSWNShr55r9S2pCmumrsig2fDZIML3WclOQy+F8S1lTxFjn/8gSK2mKp7OLpsOojhyy7 r/MzTC67FqihB0Jfb/NzJc3CPzumFu0YLqEzpDZRE0PksQsR2f03Uqz45MeEhmGadf6hFEnid5x34 jMVkIAfTGYH5JabIPdlVmwTVfX/Ylzdjs+dAoHk086UFHkBS60ehOKDesKf/6P6G/VoejnYaffdHe t+jcWjBwAHOnZ6BmAwneuFSGco2pYwZdQFkFf3IH2bBfKyCyxjhpPSXetqbABQ1RH1LyIxL0OYS5p 0WUq4IySuV51U5sH1MO5Tg==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gm1F8-00039A-QZ; Tue, 22 Jan 2019 19:57:51 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 4B057C060F; Tue, 22 Jan 2019 19:57:46 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Douglas Gilbert , Hannes Reinecke , Christoph Hellwig Subject: [PATCH 7/7] Move the resid member from struct scsi_data_buffer into struct scsi_cmnd Date: Tue, 22 Jan 2019 10:57:24 -0800 Message-Id: <20190122185724.71598-8-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190122185724.71598-1-bvanassche@acm.org> References: <20190122185724.71598-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: Combined (0.03) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5urE+BuEqyfORbbWqGQ2n7N602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTZnx3upumnqWBHj0/Vmi/pASQQA8gPlICyOXF4VQA3r681n IyHanrMzYl1QUFnGrJlGZdzQSLJYSD89hpteF8v30ykPg8qyrdUV98WGlbOjhJdwZpOImhB57vlA Ovnv7bRi5a8LLfqBhzJbqPiIMA+NOnrCrjOMG+XIApsj4flbNpUCGeLmhx53FRJAP1Ea5ASWYHcP 06zXqyXOojRJS4zkgaNaHUHryZB7iGtuYW8wUQTJsjWw5+0eZIpQIcK9yrRZBI4MtpSGpU9W4FdB tQesEelBF7Ngqas1fLSi+EsXiO7J//0XCxCMJn8bXo41UD3u+ZQGpXspg4TOqv23+spbzJ3vJBBY vcIXZcvdbj7fjbZn+1a2iCCdPFy3WGiBkBZc+BBb+UeYFBhPAZQ65C2d4vB6Mmh6nzlzGKK4CNTd FmC4kGAnKNZdqPIYy5/0C0oKEgxQF7G4ajroXShVPl5s3ZvBSOdcZaQYlKee2Vxut4iZ5ZA89caf AqxM+VvJzb/lgTl6fJxyntEfhZCKje4ZQ0jUIEfcq3/8iFZW9aviZrI0q854skGDr1SFWz9TrEbL my3uPSE9vyN9HoGBpQQMs9mOAuVGeNoxAGUS1QpH0KIcRmoNU2oljXXErZz3MdU5SJeoVHj5h7lL 06fEAVxIzKeWFsL83KrakodIBOvGMfnsRHe+Pt9t+Eh/Rnkbg1dYVJVhC0Mo1cUrwhwamYY6Uoks aCfSH23JFY6Md8TPjYHoRQJhikEW6KsZ+zue7BC3AMAEl0rnf3CZyCzXyHvANPJxkPHiWBBpWvV/ D/1d7+l+PmxJCFvdxzgiQpciHL7m0tbh53ymoHabC27dTg89Y6F8hU3e3Vw2TKDXeJHsGbLEtgE/ vdayFhJeaoF0+yEeujkNDaI1BZL4xlheqFLWBRCKDV/xyIgf7xGwA25MeVhd7+Z3ohEuqbhw2IGi K9BLVundUFjc1iJ5Hl/Q7TeMzDg6HYuTCyYgL61SIkBTYQaaIIEsvvc4Hs2Al+JCBW+Rho4Ph4F7 35SUHIxrP601Lz/dsiahQ1DFoGJGH4QvNEG2z3H+DG8i/+nwAPUMRDNTlQhcPtKTIltiNXw4wYHH 9itV4zOHtaDgH2x2DZDqYQ== X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be 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 This patch does not change any functionality but reduces the size of struct scsi_cmnd. Cc: Douglas Gilbert Cc: Hannes Reinecke Cc: Christoph Hellwig Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 2 -- include/scsi/scsi_cmnd.h | 9 ++++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 54902afb8d94..af648b93f9b3 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -945,14 +945,12 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) * scsi_result_to_blk_status may have reset the host_byte */ scsi_req(req)->result = cmd->result; - scsi_req(req)->resid_len = scsi_get_resid(cmd); if (unlikely(scsi_bidi_cmnd(cmd))) { /* * Bidi commands Must be complete as a whole, * both sides at once. */ - scsi_req(req->next_rq)->resid_len = scsi_in(cmd)->resid; if (scsi_end_request(req, BLK_STS_OK, blk_rq_bytes(req), blk_rq_bytes(req->next_rq))) WARN_ONCE(true, diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index 8f3ed55a5ee5..9035c760cae0 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -35,7 +35,6 @@ struct scsi_driver; struct scsi_data_buffer { struct sg_table table; unsigned length; - int resid; }; /* embedded in scsi_cmnd */ @@ -229,22 +228,22 @@ static inline unsigned scsi_bufflen(struct scsi_cmnd *cmd) static inline void scsi_in_set_resid(struct scsi_cmnd *cmd, int resid) { - scsi_in_cmd(cmd)->sdb.resid = resid; + scsi_in_cmd(cmd)->req.resid_len = resid; } static inline int scsi_in_get_resid(struct scsi_cmnd *cmd) { - return scsi_in_cmd(cmd)->sdb.resid; + return scsi_in_cmd(cmd)->req.resid_len; } static inline void scsi_out_set_resid(struct scsi_cmnd *cmd, int resid) { - cmd->sdb.resid = resid; + cmd->req.resid_len = resid; } static inline int scsi_out_get_resid(struct scsi_cmnd *cmd) { - return cmd->sdb.resid; + return cmd->req.resid_len; } static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid)