From patchwork Mon Apr 20 23:36:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 6244981 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 4F7AB9F313 for ; Mon, 20 Apr 2015 23:36:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 59CDB2026C for ; Mon, 20 Apr 2015 23:36:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3CC502026D for ; Mon, 20 Apr 2015 23:36:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752761AbbDTXgr (ORCPT ); Mon, 20 Apr 2015 19:36:47 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:33865 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752741AbbDTXgq (ORCPT ); Mon, 20 Apr 2015 19:36:46 -0400 Received: by pacyx8 with SMTP id yx8so221875875pac.1; Mon, 20 Apr 2015 16:36:46 -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=Q/A1vnIoROETRRBpV6J6+PTETUmTQsgdPElfqNIE7Qo=; b=OnWtrDJHtb20wyqNOtw07Xf97lSgXLwC3MIZvcgH9htkCIMowxVpGnylK7mbuwdWHY ciCCv/YruCwoEhDZgOlwsSll2XfrZGMH8vFnZcPhNH6ECgeWhAgrQmhY2tTzYztoRb9E F2YBY6Uc3m/G2Ib7XEeJcxUFjnyxM5irtSSxudNpNcVFDFLYkLpWSBIusWF3OdDvmYfW 5IRtImwgwDmZb7FneQFatXWW7B1pbi7aOiZN2REYu9cPqwxJJ8+Tnel13J+mv/5pjCc/ mZg0A+thWCTX3x62FE7vnvvZDiAct37JScrwvzbwxa5FuUhqJVuqkchxja4IQIC2Cwtj y1qg== X-Received: by 10.68.106.101 with SMTP id gt5mr21148832pbb.60.1429573006187; Mon, 20 Apr 2015 16:36:46 -0700 (PDT) Received: from localhost.localdomain (KD106168100169.ppp-bb.dion.ne.jp. [106.168.100.169]) by mx.google.com with ESMTPSA id f4sm22995pdc.95.2015.04.20.16.36.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Apr 2015 16:36:45 -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 2/4] target: Abandon odd SG mapping for data transfer memory Date: Tue, 21 Apr 2015 08:36:20 +0900 Message-Id: <1429572982-6809-3-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1429572982-6809-1-git-send-email-akinobu.mita@gmail.com> References: <1429572982-6809-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 --- drivers/target/target_core_sbc.c | 10 +++++++++- drivers/target/target_core_transport.c | 21 ++++++++++++--------- include/target/target_core_backend.h | 2 +- 3 files changed, 22 insertions(+), 11 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..d96852e 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; } @@ -2010,7 +2011,9 @@ static bool target_read_prot_action(struct se_cmd *cmd) if (cmd->se_sess->sup_prot_ops & TARGET_PROT_DIN_INSERT) break; - sbc_dif_generate(cmd); + cmd->pi_err = sbc_dif_generate(cmd); + if (cmd->pi_err) + return true; break; default: break; 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,