From patchwork Wed Jan 23 19:10:07 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: 10777753 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 2B3FF913 for ; Wed, 23 Jan 2019 19:10:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A86C2DA7B for ; Wed, 23 Jan 2019 19:10:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E8012DAAB; Wed, 23 Jan 2019 19:10:48 +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 75D642DAB6 for ; Wed, 23 Jan 2019 19:10:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726385AbfAWTKp (ORCPT ); Wed, 23 Jan 2019 14:10:45 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:53083 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726365AbfAWTKp (ORCPT ); Wed, 23 Jan 2019 14:10:45 -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=PqCGadbQmWwq 8YcY8NquIBqFmmqwaclTEbhKRzFqlmTKqYs+sNowXlpT25fqBZktje//CizZHnP/Gtn1pX0/wri0l Ou5NhopRzE7nJBVa+wxSXzLmud9JqxFWyG/UGYmDSMJ6T5Rqid54oZO4CjSa/5WBiXvZjjeEtEECG L99vB65X5YFz6yD4qQLIH0OJKZxqSDUTrLqTDMkTJS/WEncp6qsnixYVxdB12L1UN34GYyqLGkSjL PGgsXc5zq0QSBd66nfQvzWUW332Z0r6a/asPiU2sPmb/yFB+mhJoEveOI30l+pQ/rw2YuLeNrzKnN 3D5qW99eJ1MhIhfABdRkfQ==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gmNuv-00096O-6a; Wed, 23 Jan 2019 20:10:29 +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 AB439C04F4; Wed, 23 Jan 2019 20:10:22 +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 v2 1/7] Introduce the bidi_supported flag in the host template structure Date: Wed, 23 Jan 2019 11:10:07 -0800 Message-Id: <20190123191013.119684-2-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190123191013.119684-1-bvanassche@acm.org> References: <20190123191013.119684-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 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: EX5BVjFpneJeBchSMxfU5nWTMwdjp26FgC9aHXUQSeh602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTZnx3upumnqWBHj0/Vmi/pASQQA8gPlICyOXF4VQA3r681n IyHanrMzYl1QUFnGrJlGZdzQSLJYSD89hpteF8v30ykPg8qyrdUV98WGlbOjhJdwZpOImhB57vlA Ovnv7bTFlefH5GZB2zKlxrpPWIK2tjx4n/PrYhB5hmGmQxMVYWnHvICDYD9SQrIEZQE6N1QHEh+f s39AlHh/KIPZhbuodfJjMWPIXjc0x0NFCtEYVLfAvZjgXTjXZ7MYLJNQ9qfhbYcYggf7p7NmsDw6 ItvQTK4Fa/XwmuDIvtxopef6PA9J5o1R01sERb9f7DCQBCBmqxPaW/sUreE8koAI7QAr9yM+mb6Z vHD0JwDcJA0OQe0MPvKbYZEQYQFDvNZo0pTGqqLq1mqfP4rTv5j2D5aOq+q1XPjSgYCrnIBvTFe8 mnNVJBqo7HIsiC3qxMPBVxZwvSfE38dBQz1AyVOSufEGax/4hIM385pzFwSMDKHj6FhglsI+ED3B 4E2jgjU8D6JidZP1v8P5PHdq9TQMmv1Hak1m4yXZGkWsX85EIGofsQa2lXR+hQvtqLwVKWonezm8 s3vbwjHFkNsOIjv5GdFjTvnsqJRjOJfK5cbhn4VPt/ZnkWZmJiHnOufpI+hmVJRWpm9YZvwUuXgA Nn9PGzZKxHJSIxXRsnn1qpt+57eLz/jU/69xsc5gy1kJQrdxO8HkILQHQ3gYNfC2Ka63BMOaMOm0 o6Im0PeOoIXGPB683E+9iMzGwDy6fgdZpPw9lXhFnVGhJwM6yrY9qtuFA6G9QUae8pUmcVBBoCcO Jxc4HcSPOvDOk4TmbCAR191ijgP68fXQp5/v+hqOLv5XS6YJsF7OlZMJymAw1S3dgf338tEyvDkN 3AfUBddcu9g0UhwU2XntZ3CGZOwArNSiB4L0+yX0k6ai+P2s98lTN7TpmFI5gTrpIWFPo1WtBP+l YOfrvgrw9R4RW8N3EtXlChZgJQkN3vyyLOLYs4URXlosmbGYXd3ZFm+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 Wed Jan 23 19:10:08 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: 10777747 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 12BD86C2 for ; Wed, 23 Jan 2019 19:10:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 024432DA87 for ; Wed, 23 Jan 2019 19:10:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EAD3D2DA98; Wed, 23 Jan 2019 19:10:39 +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 576512DA9A for ; Wed, 23 Jan 2019 19:10:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726385AbfAWTKj (ORCPT ); Wed, 23 Jan 2019 14:10:39 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:58137 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbfAWTKi (ORCPT ); Wed, 23 Jan 2019 14:10:38 -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=HJMPTpLv/obS i75laazu1lUlnizsQkucIp2GG6TKJkh8uvybZG81RHwfxe8YUXXCOn+AmWyQ1tVFi9/Msa1V7Fw4D 2FPeDCpaeYHxMCrJLQrCDAH30/G4Qo5wweAagEioCTUzZH3QpaUfu9YgEvwrTMRwXmsatvBDkoQbH CQBzX+099UiIE9UJBcbCucxPrLmmX/t0x9y3niPYdMgk2IRVFelr2BivD0FLny7SK+SH+aJJCblhp Rw+nGbAaAOCi2NCaDqV4gt7c6zYPHzM0QYQ8b+7gLh3ACodp/LV/hq3eH6Mqrj8KEOvuyoXHZl7el TRVG7hY9dZF5xA4sJ9r75w==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gmNuw-0000Zg-Da; Wed, 23 Jan 2019 20:10:31 +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 13799C0517; Wed, 23 Jan 2019 20:10:24 +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 v2 2/7] Change scsi_cmnd.prot_sdb from a pointer into a regular member Date: Wed, 23 Jan 2019 11:10:08 -0800 Message-Id: <20190123191013.119684-3-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190123191013.119684-1-bvanassche@acm.org> References: <20190123191013.119684-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 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: EX5BVjFpneJeBchSMxfU5thLe+OASNgDG3JdONnpsd5602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTZnx3upumnqWBHj0/Vmi/pASQQA8gPlICyOXF4VQA3r681n IyHanrMzYl1QUFnGrJlGZdzQSLJYSD89hpteF8v30ykPg8qyrdUV98WGlbOjhJdwZpOImhB57vlA Ovnv7bRi5a8LLfqBhzJbqPiIMA+NOnrCrjOMG+XIApsj4flbNpUCGeLmhx53FRJAP1Ea5ASWYHcP 06zXqyXOojRJS4zk8SkYUVMlM10GRnszbZ7xJQTJsjWw5+0eZIpQIcK9yrRZBI4MtpSGpU9W4FdB tQesEelBF7Ngqas1fLSi+EsXiO7J//0XCxCMJn8bXo41UD3u+ZQGpXspg4TOqv23+spbzJ3vJBBY vcIXZcvdbj7fjbZn+1a2iCCdPFy3WGiBkBZc+BBb+UeYFBhPAZQ65C2d4vB6Mmh6nzlzGKK4CNTd FmC4kGAnKNZdqPIYy5/0C0oKEgxQF7G4ajroXShVPl5s3ZvBSOdcZaQYlKee2Vxut4iZ5ZA89caf AqxM+VvJzb/lgTl6fJxyntEfhZCKje4ZQ0jUIEfcq3/8iFZW9aviZrI0q854skGDr1SFWz9TrEbL my3uPSE9vyN9HoGBpQQMs9mOAuVGeNoxAGUS1QpH0KIcRmoNU2oljXXErZz3MdU5SJeoVHj5h7lL 06fEAVxIzKeWFsL83KrakodIBOvGMUyeAC+56yw1+v2L6yfd9ex2aQoAWsdBJx1H7VXTg1rRUoks aCfSH23JFY6Md8TPjYHoRQJhikEW6KsZ+zue7BC3AMAEl0rnf3CZyCzXyHvANPJxkPHiWBBpWvV/ D/1d7+l+PmxJCFvdxzgiQpciHL7m0tbh53ymoHabC27dTg89vvpqle4pv+yrEhrJOC+BNtdGNXBU Df/Mjgl31sUAuSYeujkNDaI1BZL4xlheqFLWgStYx12aCdmJgllbwzHk4lhd7+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 Wed Jan 23 19:10:09 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: 10777751 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 07E4F913 for ; Wed, 23 Jan 2019 19:10:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBD732DA7B for ; Wed, 23 Jan 2019 19:10:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFF682DAA4; Wed, 23 Jan 2019 19:10:42 +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 616242DA9C for ; Wed, 23 Jan 2019 19:10:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726418AbfAWTKm (ORCPT ); Wed, 23 Jan 2019 14:10:42 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:34239 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726365AbfAWTKl (ORCPT ); Wed, 23 Jan 2019 14:10:41 -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=kahWysBLpakRynoS9Yu14qVtbsQiQq3uYbgzI7AkWbk=; b=ZfqK2Ru//UlU EtCRs7J/xxL0XqmrTwYiSffR0IGxJA6EmK+C4gpMU+OhV3eR+orPTLZAudO8RDG66oCssm2um5gpR 76pAwG8CZ2hjX+c2cMxlbrZyiVT0gXPOslkiNCbEQ7CsH9TkPdWZp3DC5ZirGi347ttK9gg/F9AEl 8osx2BjQhJVdP6ZhQ2rS3kSKvLXeBqmVxPUdvgE/Z9qhnlume9HKlK90BjX5keUi1aQzZmAMXoYOf aplac9PjT73kGcoUt6stplbHCyV1Xl+e7du1fPzoi3aR++xzkcDWWTP/p9iP21ymBuSMs8xL4zCQA PLxqlCm+tX+8oU0TnuF31w==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gmNux-00096N-Ss; Wed, 23 Jan 2019 20:10:32 +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 477A9C04F4; Wed, 23 Jan 2019 20:10:27 +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 v2 3/7] Fix bidi handling Date: Wed, 23 Jan 2019 11:10:09 -0800 Message-Id: <20190123191013.119684-4-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190123191013.119684-1-bvanassche@acm.org> References: <20190123191013.119684-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 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: EX5BVjFpneJeBchSMxfU5phO+h2sDQt1JCL9ht7Wz49602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTZnx3upumnqWBHj0/Vmi/pASQQA8gPlICyOXF4VQA3r681n IyHanrMzYl1QUFnGrJlGZdzQSLJYSD89hpteF8v30ykPg8qyrdUV98WGlbOjhJdwZpOImhB57vlA Ovnv7bRi5a8LLfqBhzJbqPiIMA+NOnrCrjOMG+XIApsj4flbNpUCGeLmhx53FRJAP1Ea5ASWYHcP 06zXqyXOojRJS4zkb/990+k58JhyOxgsBpuyJgTJsjWw5+0eZIpQIcK9yrRZBI4MtpSGpU9W4FdB tQesEelBF7Ngqas1fLSi+EsXiGRbN4cS9m3JKQpYnU+jEObu+ZQGpXspg4TOqv23+spbzJ3vJBBY vcIXZcvdbj7fjbZn+1a2iCCdPFy3WGiBkBZc+BBb+UeYFBhPAZQ65C2d4vB6Mmh6nzlzGKK4CNTd FmC4kGAnKNZdqPIYy5/0C0oKEgxQF7G4ajroXShVPl5s3ZvBSOdcZaQYlKee2Vxut4iZ5ZA89caf AqxM+VvJzb/lgTl6fJxyntEfhZCKje4ZQ0jUIEfcq3/8iFZW9aviZrI0q854skGDr1SFWz9TrEbL my3uPSE9vyN9HoGBpQQMs9mOAuVGeNoxAGUS1QpH0KIcRmoNU2oljXXErZz3MdU5SJeoVHj5h7lL 06fEAVxIuI4woYdcsisZprERKCJ/DkyeAC+56yw1+v2L6yfd9ewBVsBW3b/nActkIYPJJfuOUoks aCfSH23JFY6Md8TPjYHoRQJhikEW6KsZ+zue7BC3AMAEl0rnf3CZyCzXyHvANPJxkPHiWBBpWvV/ D/1d7+l+PmxJCFvdxzgiQpciHL7m0tbh53ymoHabC27dTg89DC5i0aYrX3CEliNHuhrNF60+avvg /+bRlKSBrZtGAsEeujkNDaI1BZL4xlheqFLWgStYx12aCdmJgllbwzHk4lhd7+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..bcbf266e4172 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_Host *shost, struct scsi_cmnd *cmd) +{ + cmd->sdb.table.sgl = (void *)cmd + sizeof(struct scsi_cmnd) + + shost->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(shost, 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(shost, 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 Wed Jan 23 19:10:10 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: 10777749 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 2D0CB6C2 for ; Wed, 23 Jan 2019 19:10:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EE582DA6D for ; Wed, 23 Jan 2019 19:10:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D2532DA87; Wed, 23 Jan 2019 19:10:42 +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 2FB772DA9F for ; Wed, 23 Jan 2019 19:10:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726398AbfAWTKl (ORCPT ); Wed, 23 Jan 2019 14:10:41 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:55413 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbfAWTKk (ORCPT ); Wed, 23 Jan 2019 14:10:40 -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=RcICJjwNP9A0 D+pqRQ5s0lR5Uak+A9FCRz8ZC8HlXEkLmeQhbGJzRPruH/mD01pLVzIC1FUk5BSYb1KEibmFJW7Cz SuP2n1TuOgg80zT3pEJd9m2eoVAfRnxAT0ba7krHYh2LyTfmCZCBqHxoAprgttxG4dxMYTrVbYCf7 q2FyGI8h8PWvl0kKwskO6GVINMcg7+yW0RXHc1F/S9Sb+/foJclk47vb5m0cUYmeV3Bs7Xoll8ADH yEjjZaSw/jenTng2+8QCC98svPzwV153Oc2WLLJc0CS/P3X7rPQbam0I0L5xzmX9AVJDk/yGaC4iT l1lKl1NhThN3+lWe8F1IHg==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gmNuz-00096N-KI; Wed, 23 Jan 2019 20:10:33 +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 81C9EC0517; Wed, 23 Jan 2019 20:10:29 +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 v2 4/7] Introduce scsi_out_cmd() Date: Wed, 23 Jan 2019 11:10:10 -0800 Message-Id: <20190123191013.119684-5-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190123191013.119684-1-bvanassche@acm.org> References: <20190123191013.119684-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 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: EX5BVjFpneJeBchSMxfU5sLXEQdOx38H4Wn1GbOlrkd602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTZnx3upumnqWBHj0/Vmi/pASQQA8gPlICyOXF4VQA3r681n IyHanrMzYl1QUFnGrJlGZdzQSLJYSD89hpteF8v30ykPg8qyrdUV98WGlbOjhJdwZpOImhB57vlA Ovnv7bRi5a8LLfqBhzJbqPiIMA+NOnrCrjOMG+XIApsj4flbNpUCGeLmhx53FRJAP1Ea5ASWYHcP 06zXqyXOojRJS4zk9d/Xzc14W3a8feMt9YGckQTJsjWw5+0eZIpQIcK9yrRZBI4MtpSGpU9W4FdB tQesEelBF7Ngqas1fLSi+EsXiGRbN4cS9m3JKQpYnU+jEObu+ZQGpXspg4TOqv23+spbzJ3vJBBY vcIXZcvdbj7fjbZn+1a2iCCdPFy3WGiBkBZc+BBb+UeYFBhPAZQ65C2d4vB6Mmh6nzlzGKK4CNTd FmC4kGAnKNZdqPIYy5/0C0oKEgxQF7G4ajroXShVPl5s3ZvBSOdcZaQYlKee2Vxut4iZ5ZA89caf AqxM+VvJzb/lgTl6fJxyntEfhZCKje4ZQ0jUIEfcq3/8iFZW9aviZrI0q854skGDr1SFWz9TrEbL my3uPSE9vyN9HoGBpQQMs9mOAuVGeNoxAGUS1QpH0KIcRmoNU2oljXXErZz3MdU5SJeoVHj5h7lL 06fEAVxIuI4woYdcsisZprERKCJ/DkyeAC+56yw1+v2L6yfd9exU3kG2zVfCPBmG8seK4g/xUoks aCfSH23JFY6Md8TPjYHoRQJhikEW6KsZ+zue7BC3AMAEl0rnf3CZyCzXyHvANPJxkPHiWBBpWvV/ D/1d7+l+PmxJCFvdxzgiQpciHL7m0tbh53ymoHabC27dTg898jZx9MeHLfFwG4mrbU9atHWBfE+D 4SW331B/a3tIWmceujkNDaI1BZL4xlheqFLWgStYx12aCdmJgllbwzHk4lhd7+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 Wed Jan 23 19:10:11 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: 10777755 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 9A1F46C2 for ; Wed, 23 Jan 2019 19:10:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CFBB2DAC1 for ; Wed, 23 Jan 2019 19:10:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B41F2DAC8; Wed, 23 Jan 2019 19:10:51 +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 0AC562DAC1 for ; Wed, 23 Jan 2019 19:10:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726648AbfAWTKu (ORCPT ); Wed, 23 Jan 2019 14:10:50 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:42655 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726432AbfAWTKr (ORCPT ); Wed, 23 Jan 2019 14:10:47 -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=g5n8YAkFG98Y DVB9qvuYys3pLDFxYF7jDIiZu4hcPs+54qpbIDcBqeFhqFDTPAMAgJvDtJSuYdbmyRNKYuUfaPQeo mPISSbeDuDm1iyuYdYmHTNHa8RbmRyPqJu8y6FU6mV6iP6aHAgwqmCS+KnHCA8n045Wc4qssfNRW+ /a08K0TdDc2UJOiGCQSI+SJc1NPJKOxJbnXDz9I+76RUioRbAZxraKqkWGv3yJXZka3rK30ui4YL/ iJ495t06LtwPswgm9ULN5U/vKYZkRN7MT2NYBPoOa9LEuN+kcIAmD2NSJF+3LyuopDOxeHPgq5g+J 91Zqn9wIGH2xDja/PeNUPw==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gmNv1-00098M-ON; Wed, 23 Jan 2019 20:10:36 +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 4836CC04F4; Wed, 23 Jan 2019 20:10:31 +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 v2 5/7] Move several function definitions in Date: Wed, 23 Jan 2019 11:10:11 -0800 Message-Id: <20190123191013.119684-6-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190123191013.119684-1-bvanassche@acm.org> References: <20190123191013.119684-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 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.00271027283697) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5ufEH0XZNt19ZrI2yVHTLod602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTZnx3upumnqWBHj0/Vmi/pASQQA8gPlICyOXF4VQA3r681n IyHanrMzYl1QUFnGrJlGZdzQSLJYSD89hpteF8v30ykPg8qyrdUV98WGlbOjhJdwZpOImhB57vlA Ovnv7bRi5a8LLfqBhzJbqPiIMA+NOnrCrjOMG+XIApsj4flbNpUCGeLmhx53FRJAP1Ea5ASWYHcP 06zXqyXOojRJS4zkilCys0g8fRWcTXOmvCa0EATJsjWw5+0eZIpQIcK9yrRZBI4MtpSGpU9W4FdB tQesEelBF7Ngqas1fLSi+EsXiGRbN4cS9m3JKQpYnU+jEObu+ZQGpXspg4TOqv23+spbzJ3vJBBY vcIXZcvdbj7fjbZn+1a2iCCdPFy3WGiBkBZc+BBb+UeYFBhPAZQ65C2d4vB6Mmh6nzlzGKK4CNTd FmC4kGAnKNZdqPIYy5/0C0oKEgxQF7G4ajroXShVPl5s3ZvBSOdcZaQYlKee2Vxut+excQEBokpi mN+IpZsSCXc5abhTdeMRIGIFGG7eQynS17NirEYyqwqMBGrw8ELiqFSHA33y5Mb3HyPilJ6ZEZbN sFlW4xzv3KSabGJbxYTP9L1EoXi+CD9t4odUMDuXpq4Dt0gTEK9vOlOvpFXXjOyucj735mFcFqoc 4yysvQM8ASJFC/49WOPBr5nlEUI4xK39jKJ12NRmh/QKxJLghohhspljkOhpjzwdmRUuxUAkqPXL +0TQW2AlART5MskpktMqpQY/wTdSn/KmmRPQe1WngoWueOlSkfQrrNQ0YaVuKF0zwGgxiH5VYpT1 74cN8FvxDejqc1gSvA2YxCROcMK2BmRxGQKegzOmzXDxmXJaDPc+rUuIsEwVJ+BZMX32wjqOMN8v ravqDSvXmAO+8z0BwQwfsNJ3VhMvRBozUVixUV8ShebT8U8Xw9HTDfreWRYYPDOuh+QYnmwzDWDO +6sK1dZiHRd2NnuhNCjR/8or/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 Wed Jan 23 19:10:12 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: 10777757 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 628A76C2 for ; Wed, 23 Jan 2019 19:10:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51C502DAAE for ; Wed, 23 Jan 2019 19:10:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 465AA2DA57; Wed, 23 Jan 2019 19:10:57 +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 A1E192DAA4 for ; Wed, 23 Jan 2019 19:10:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726682AbfAWTK4 (ORCPT ); Wed, 23 Jan 2019 14:10:56 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:53893 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726432AbfAWTK4 (ORCPT ); Wed, 23 Jan 2019 14:10:56 -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=DMKkx24F0EFr NY7pB/hXiR+v+7psEw5PmBHkvagSGCV3oxnjfnPzhPvN/NkLjCOL4fjCCp5hvwSkQY3sEkiYo9atK uJv6EzrTiSYT648ErxSRxMRP6aZgPH7xbnhTHrhI6zAvoLMda5USJE2uUbV1wLCzCD6SLm02vVuVf ySsfH7BmhGGC8I6zw3XnS8GBwb8gHLI6v/e8S1qDxmST7KegahowBeQL99ongruwtySx98hE1QHgd SFl9qBbBOyyHQqAPmKRusdmjvGw1X++fMbMmx8aFxHyM6wf9BWjWvhOKGFhEXiPhkE5ar9SldO8E4 h8SzLgN6q6E5dZCUhBsVBQ==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gmNv3-00098S-V4; Wed, 23 Jan 2019 20:10:38 +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 53686C06CF; Wed, 23 Jan 2019 20:10: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 , Paolo Bonzini Subject: [PATCH v2 6/7] Introduce scsi_in_[sg]et_resid() and scsi_out_[sg]et_resid() Date: Wed, 23 Jan 2019 11:10:12 -0800 Message-Id: <20190123191013.119684-7-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190123191013.119684-1-bvanassche@acm.org> References: <20190123191013.119684-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 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.00688924767148) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5jlGbQKxrEWlyjvxo5xl4tV602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTZnx3upumnqWBHj0/Vmi/pASQQA8gPlICyOXF4VQA3r681n IyHanrMzYl1QUFnGrJlGZdzQSLJYSD89hpteF8v30ykPg8qyrdUV98WGlbOjhJdwZpOImhB57vlA Ovnv7bTFlefH5GZB2zKlxrpPWIK2tjx4n/PrYhB5hmGmQxMVYVAKkEeH4f3QNjnZQsMBDjH4MJg9 YHIdz0Dl6O7ob5t7s0JmTITK6nc3QbOK5CoO7BGsr2YkQf6GHRtGGbpACH6VAhni5ocedxUSQD9R GuQEjZ892PEyNw69vEzsu606q8ky4a3/MztZ7vqRH8PZ304EybI1sOftHmSKUCHCvcq0UIIqcWW4 ifKaEwthyP1VxRXFlYuWrE0vLapFlbaWqJhkWzeHEvZtySkKWJ1PoxDmbTkFsvCGkPVV+auVjHwB H0RhAta0pIzMTTnbIXymD5ebG0Xni7XCo6ehBw6KaJm7DIXqP5P5X1d0cf7YNeX80Mi/IFb8H9P2 UweQHsd5pwaJ7YxW+jLD3ZDBACJzg6v8ChIMUBexuGo66F0oVT5ebO9n9zqkM12Y+COJLnC0ol3n sXEBAaJKYpjfiKWbEgl3w5gS4D3X4kVivwz4Sz4qStezYqxGMqsKjARq8PBC4qj1z+8KP1/w7Nvd xY9bKBxJzbBZVuMc79ykmmxiW8WEz0sosrzI3EdRChAJhsbcCJAeMzveq5eJrexBvOsP5AjXM0S3 Ej9wK9U6T08uj1LhgQEiRQv+PVjjwa+Z5RFCOMSZfk3b/DP9BNeqNi5dZ/sbxeALkH8Xtdz0W8sw tWz8lkVs4KaTJPJDLESW3MY/ixSExp8sAqOQvlCFhGLiUy48iLgMlCvTtx4+HGatF9xp2t6YDkhi 6kKHWGhsE+ciTYPnC9kU8EzzPWXPJewIpRuRtgZkcRkCnoMzps1w8ZlyWoBR0RG0hPasLKXprlc7 I3gk547AXrTppRdk/qhQlgOPX3CDcVaGCa2SgjbONEFb0FFfEoXm0/FPF8PR0w363lmbp5/Z9/y8 d6CkJRuULLE0x14FaF/O9kw7F86OEywXamB1eQxePet6exctZLANANtQvy23SZXSfMZ7RzHGH1l2 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 Wed Jan 23 19:10:13 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: 10777761 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 7CA68913 for ; Wed, 23 Jan 2019 19:11:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F3172DA9F for ; Wed, 23 Jan 2019 19:11:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6397C2DAD0; Wed, 23 Jan 2019 19:11:00 +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=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C6992DAC8 for ; Wed, 23 Jan 2019 19:10:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726684AbfAWTK5 (ORCPT ); Wed, 23 Jan 2019 14:10:57 -0500 Received: from out002.mailprotect.be ([83.217.72.86]:52577 "EHLO out002.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726365AbfAWTK4 (ORCPT ); Wed, 23 Jan 2019 14:10:56 -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=/Ej4F9EG7X3OaU+MusGyj72M3Z81HHa5kjp3jsQWVok=; b=WY82zA/e0RVI 0wV2EYNb+U+LJwIEIySkhK95eUFfncUMRQVz3kx+9QPpf52nrpcyY0mIWi/eNQgDZVKvnQadQlxqB 7cZyAp/XiDmVGhwNcWEXMRSQkscs3DLjW9nS6EneKxNL6SIlFDdRUTziPrvUqnqGAlhMilZxMajCv m8HFO4uFOfI4WQ1l1RysBE5oGWZz2q4S7OUK/iPz4HBMRNXNEPmqf9zs6pGs4SlOw13vm0iLj6QGi 4oPZJtCWsXsxBIjUL9TsFJSNgvoCjXW+q6cXCelP53Sd4S8t2r5IHpZJfQl8qc5nwmFAuVVjELuum aB254SsC6o509l2MuAUmgw==; Received: from smtp-auth.mailprotect.be ([178.208.39.155]) by com-mpt-out002.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gmNv6-00099X-3Q; Wed, 23 Jan 2019 20:10:40 +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 92374C04F4; Wed, 23 Jan 2019 20:10:35 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Oliver Neukum , Douglas Gilbert , Hannes Reinecke , Christoph Hellwig , linux-usb@vger.kernel.org Subject: [PATCH v2 7/7] Move the resid member from struct scsi_data_buffer into struct scsi_cmnd Date: Wed, 23 Jan 2019 11:10:13 -0800 Message-Id: <20190123191013.119684-8-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190123191013.119684-1-bvanassche@acm.org> References: <20190123191013.119684-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.155 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: EX5BVjFpneJeBchSMxfU5krwn43559XFYeTz+eDPpSV602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTZnx3upumnqWBHj0/Vmi/pASQQA8gPlICyOXF4VQA3r681n IyHanrMzYl1QUFnGrJlGZdzQSLJYSD89hpteF8v30ykPg8qyrdUV98WGlbOjhJdwZpOImhB57vlA Ovnv7bRi5a8LLfqBhzJbqPiIMA+NwvuNfDLiANscU/nS1UXm73USUhwJiA5feVp4LFxEdpdB3ylJ Dm+BpEBBclKFyxopKHb4vPmSIbdfueR6G1BiAPiWAoh64PO5p3svaPBDMwtjBMLLaM2KtLCkia0v MuKlxYBvuVF2Z+Bct0um2wwqxOKVse1sVhWabI0/+PN3sILfno2VGCQBTzV5700QuyS2nB91/WsJ i78ADPGYDhYdq5Txl/4H2pIk/NKx9kdZyuRMs3x71t5DHCETMYRS4C1JUuIF2yn03s7TS3ghm2vg Bpb5Pn6ftQZVK9K8EAjn37sUg69eDYNe2itClT3S7bjQUCo5PZJsLcY5FmNhp+JDxmImhzCOs+Do i9A98MTofQFPXMPn2jxw9gqzj3gEGJhZPn1u8Aa0teCaL50mskfArty8vJm3Q5aLHZ2GtrfzOwDf X8TdqEXkwxwMjsp2mNApsBWz8AU2Nk3qXE8st8jJti8/3bImoUNQxaBiRh+ELzS72ayHXNa7vYhj SP/fYtnzQX37JU+j2xceOC41WdirPFUt6Nn24V/0KlBUenwzWPTonV+E7OMXRvgtdyMlnmWiBWCH OalfrqeuAeh0nF8OVU9Tfz3bky3mmnWsMBVelwFiCKATxN+BYK4nmvlAmRWn2lv5QJ9vfU3IU72h POd4zx5xoUKlcleRNY2IgcugHFfrBp6xGXFNG/RaqueR+OkdBTlhpmV1p9BzLNTsJlzkQcoBMMMF nt8VzQUPDSXZuD4gcpX9yUWXReSxyvmkjs27/gwoEA3kOiKB/0U8Qy7Tf9/UCyUvn8EiIZr2I4hk tOAqUxd6+fjolVFMnEligJLyfmYqJZjirICi9MqwuAqImlPfZ9m3/W0Ujjhn8ztlwD0seGxvsutB 5vCqx+3Xa4gI0TK8OQ3cB9QF11y72DRSHL77YW8ojGTgH7yY8C/ODDttMOlXJu+mEAJiKefYDz+P zbBZVuMc79ykmmxiW8WEz5AuKs375es6QRgEpoHtxKbyD5f007X1blRae6svbWKKombdVSqNouI1 tb6Q9ERYlA== 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: Oliver Neukum Cc: Douglas Gilbert Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: linux-usb@vger.kernel.org Signed-off-by: Bart Van Assche --- drivers/scsi/scsi_lib.c | 2 -- drivers/usb/storage/uas.c | 8 +++++--- include/scsi/scsi_cmnd.h | 9 ++++----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index bcbf266e4172..4feba3b5aff1 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/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c index 36742e8e7edc..ea40fd78e6ff 100644 --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c @@ -365,7 +365,7 @@ static void uas_stat_cmplt(struct urb *urb) static void uas_data_cmplt(struct urb *urb) { - struct scsi_cmnd *cmnd = urb->context; + struct scsi_cmnd *cmnd = urb->context, *cmpl_cmd = NULL; struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp; struct uas_dev_info *devinfo = (void *)cmnd->device->hostdata; struct scsi_data_buffer *sdb = NULL; @@ -375,10 +375,12 @@ static void uas_data_cmplt(struct urb *urb) spin_lock_irqsave(&devinfo->lock, flags); if (cmdinfo->data_in_urb == urb) { + cmpl_cmd = scsi_in_cmd(cmnd); sdb = scsi_in(cmnd); cmdinfo->state &= ~DATA_IN_URB_INFLIGHT; cmdinfo->data_in_urb = NULL; } else if (cmdinfo->data_out_urb == urb) { + cmpl_cmd = scsi_out_cmd(cmnd); sdb = scsi_out(cmnd); cmdinfo->state &= ~DATA_OUT_URB_INFLIGHT; cmdinfo->data_out_urb = NULL; @@ -401,9 +403,9 @@ static void uas_data_cmplt(struct urb *urb) if (status != -ENOENT && status != -ECONNRESET && status != -ESHUTDOWN) uas_log_cmd_state(cmnd, "data cmplt err", status); /* error: no data transfered */ - sdb->resid = sdb->length; + cmpl_cmd->req.resid_len = sdb->length; } else { - sdb->resid = sdb->length - urb->actual_length; + cmpl_cmd->req.resid_len = sdb->length - urb->actual_length; } uas_try_complete(cmnd, __func__); out: 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)