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) \