From patchwork Tue Apr 21 23:46:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 6254341 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 011999F1BE for ; Tue, 21 Apr 2015 23:46:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EB8D52034E for ; Tue, 21 Apr 2015 23:46:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB7F220328 for ; Tue, 21 Apr 2015 23:46:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965279AbbDUXqn (ORCPT ); Tue, 21 Apr 2015 19:46:43 -0400 Received: from mail-pd0-f174.google.com ([209.85.192.174]:35029 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965273AbbDUXqm (ORCPT ); Tue, 21 Apr 2015 19:46:42 -0400 Received: by pdbqd1 with SMTP id qd1so256696800pdb.2; Tue, 21 Apr 2015 16:46:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uwZ/cy9Rt3t9yh3ZcW4fmaF7g5fNr4+ISKM6Z28dEpw=; b=OvHQrOt3rLL0W+bUuoQdwzaOvCDTR7Sq2wmt9p/U7DEhfa9Nr6mRDYJjefyKSFU+RU bzV9IA4kSMIBa2QFZzAWmy3IkhSV4nvH+ODN92QsnmlBtVK0xc+njASOS2kbu110w75k FdjzQexp/2FHs1AjVLKDYIPHagsykUBUgt4eG/i50w6jqoPfqYcWTXbi3UikSLWRscll cILJWDidthvR7Froz4bvowgkUxsG/rcenxdNb9leBcuRLbIBLUttGmK64uLtpHKQPVhr Od6wUFEMHdkxJFvdp+fokaBKazjNe94A5KpKm0Bld66u+mPpMbfgouKMf/4cltMKq0ut XnmA== X-Received: by 10.66.254.39 with SMTP id af7mr42672480pad.15.1429660002311; Tue, 21 Apr 2015 16:46:42 -0700 (PDT) Received: from localhost.localdomain (KD106168100169.ppp-bb.dion.ne.jp. [106.168.100.169]) by mx.google.com with ESMTPSA id wh6sm3060643pbc.96.2015.04.21.16.46.38 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Apr 2015 16:46:41 -0700 (PDT) From: Akinobu Mita To: target-devel@vger.kernel.org Cc: Akinobu Mita , Nicholas Bellinger , Sagi Grimberg , "Martin K. Petersen" , Christoph Hellwig , "James E.J. Bottomley" , linux-scsi@vger.kernel.org Subject: [PATCH v2 2/4] target: Abandon odd SG mapping for data transfer memory Date: Wed, 22 Apr 2015 08:46:15 +0900 Message-Id: <1429659977-7156-3-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1429659977-7156-1-git-send-email-akinobu.mita@gmail.com> References: <1429659977-7156-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP sbc_dif_generate() and sbc_dif_verify() assume that each SG element for data transfer memory doesn't straddle the block size boundary. However, when using SG_IO ioctl, we can choose the data transfer memory which doesn't satisfy that alignment requirement. This change detects such cases and makes those functions return failure to stop continuing the operation. Signed-off-by: Akinobu Mita Cc: Nicholas Bellinger Cc: Sagi Grimberg Cc: "Martin K. Petersen" Cc: Christoph Hellwig Cc: "James E.J. Bottomley" Cc: target-devel@vger.kernel.org Cc: linux-scsi@vger.kernel.org --- * Changes from v1: - Reduce code duplication a bit in target_read_prot_action() drivers/target/target_core_sbc.c | 10 +++++++++- drivers/target/target_core_transport.c | 23 +++++++++++------------ include/target/target_core_backend.h | 2 +- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c index edba39f..982836b 100644 --- a/drivers/target/target_core_sbc.c +++ b/drivers/target/target_core_sbc.c @@ -1177,7 +1177,7 @@ err: } EXPORT_SYMBOL(sbc_execute_unmap); -void +sense_reason_t sbc_dif_generate(struct se_cmd *cmd) { struct se_device *dev = cmd->se_dev; @@ -1188,6 +1188,9 @@ sbc_dif_generate(struct se_cmd *cmd) int i, j, offset = 0; for_each_sg(cmd->t_data_sg, dsg, cmd->t_data_nents, i) { + if (dsg->length % dev->dev_attrib.block_size) + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; + daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; paddr = kmap_atomic(sg_page(psg)) + psg->offset; @@ -1221,6 +1224,8 @@ sbc_dif_generate(struct se_cmd *cmd) kunmap_atomic(paddr); kunmap_atomic(daddr); } + + return 0; } static sense_reason_t @@ -1323,6 +1328,9 @@ sbc_dif_verify(struct se_cmd *cmd, sector_t start, unsigned int sectors, sense_reason_t rc; for_each_sg(cmd->t_data_sg, dsg, cmd->t_data_nents, i) { + if (dsg->length % dev->dev_attrib.block_size) + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; + daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; paddr = kmap_atomic(sg_page(psg)) + psg->offset; diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index fe52883..fd89f57 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1760,7 +1760,7 @@ static int target_write_prot_action(struct se_cmd *cmd) switch (cmd->prot_op) { case TARGET_PROT_DOUT_INSERT: if (!(cmd->se_sess->sup_prot_ops & TARGET_PROT_DOUT_INSERT)) - sbc_dif_generate(cmd); + cmd->pi_err = sbc_dif_generate(cmd); break; case TARGET_PROT_DOUT_STRIP: if (cmd->se_sess->sup_prot_ops & TARGET_PROT_DOUT_STRIP) @@ -1769,18 +1769,19 @@ static int target_write_prot_action(struct se_cmd *cmd) sectors = cmd->data_length >> ilog2(cmd->se_dev->dev_attrib.block_size); cmd->pi_err = sbc_dif_verify(cmd, cmd->t_task_lba, sectors, 0, cmd->t_prot_sg, 0); - if (unlikely(cmd->pi_err)) { - spin_lock_irq(&cmd->t_state_lock); - cmd->transport_state &= ~CMD_T_BUSY|CMD_T_SENT; - spin_unlock_irq(&cmd->t_state_lock); - transport_generic_request_failure(cmd, cmd->pi_err); - return -1; - } break; default: break; } + if (unlikely(cmd->pi_err)) { + spin_lock_irq(&cmd->t_state_lock); + cmd->transport_state &= ~CMD_T_BUSY|CMD_T_SENT; + spin_unlock_irq(&cmd->t_state_lock); + transport_generic_request_failure(cmd, cmd->pi_err); + return -1; + } + return 0; } @@ -2002,21 +2003,19 @@ static bool target_read_prot_action(struct se_cmd *cmd) cmd->pi_err = sbc_dif_verify(cmd, cmd->t_task_lba, sectors, 0, cmd->t_prot_sg, 0); - if (cmd->pi_err) - return true; } break; case TARGET_PROT_DIN_INSERT: if (cmd->se_sess->sup_prot_ops & TARGET_PROT_DIN_INSERT) break; - sbc_dif_generate(cmd); + cmd->pi_err = sbc_dif_generate(cmd); break; default: break; } - return false; + return cmd->pi_err ? true : false; } static void target_complete_ok_work(struct work_struct *work) diff --git a/include/target/target_core_backend.h b/include/target/target_core_backend.h index ab8ed4c..41dfde0 100644 --- a/include/target/target_core_backend.h +++ b/include/target/target_core_backend.h @@ -85,7 +85,7 @@ sense_reason_t sbc_execute_unmap(struct se_cmd *cmd, sense_reason_t (*do_unmap_fn)(struct se_cmd *cmd, void *priv, sector_t lba, sector_t nolb), void *priv); -void sbc_dif_generate(struct se_cmd *); +sense_reason_t sbc_dif_generate(struct se_cmd *); sense_reason_t sbc_dif_verify(struct se_cmd *, sector_t, unsigned int, unsigned int, struct scatterlist *, int); void sbc_dif_copy_prot(struct se_cmd *, unsigned int, bool,