From patchwork Mon Apr 13 14:21:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 6209901 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 E05B99F1AC for ; Mon, 13 Apr 2015 14:22:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F289D2021F for ; Mon, 13 Apr 2015 14:22:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F39CF201D3 for ; Mon, 13 Apr 2015 14:22:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932216AbbDMOWS (ORCPT ); Mon, 13 Apr 2015 10:22:18 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:32797 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932131AbbDMOWQ (ORCPT ); Mon, 13 Apr 2015 10:22:16 -0400 Received: by paboj16 with SMTP id oj16so103796680pab.0; Mon, 13 Apr 2015 07:22:16 -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=9Qzf/vuFVMgyCSnHS3suBcvS9HWR+YzY1k2B0HzneTQ=; b=hFj+uohZZJTeJ1shoScDoOJYvJ5qtnyd1pnuAeKbfDIfI9zdK+bNq9PydqhT5j0zjU 3Wl9EySe42mwTyn/tYNRmBCacNRnT3VaAGUpxo2ZQXxZx/GQ4pXVwAlLqXjz5PGV5nCD 9wICMjrQKjQw845gzk4oHFlTEJDHXpI2XnnN8zyEuIJnaLpveZO+9vpT616c7wYxNvBu YTAiAMrPZYii8nZ4EQVq6hs71yxUHU6FzW6EX/xKaYXAZv9nOSHhfXJ0RR+gvN5l46Yq MrEHogd7wwl4aBVe4azrpwmfS6DO/gmwWU/ezlm8jNYLGWQ9HwQj40uH4+KzZg+eEl1c t6Bw== X-Received: by 10.66.186.142 with SMTP id fk14mr27234684pac.74.1428934935941; Mon, 13 Apr 2015 07:22:15 -0700 (PDT) Received: from localhost.localdomain (KD106168100169.ppp-bb.dion.ne.jp. [106.168.100.169]) by mx.google.com with ESMTPSA id op4sm7454078pbb.77.2015.04.13.07.22.12 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Apr 2015 07:22:14 -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/3] target/file: Fix SG table for prot_buf initialization Date: Mon, 13 Apr 2015 23:21:57 +0900 Message-Id: <1428934918-4004-2-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1428934918-4004-1-git-send-email-akinobu.mita@gmail.com> References: <1428934918-4004-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 In fd_do_prot_rw(), it allocates prot_buf which is used to copy from se_cmd->t_prot_sg by sbc_dif_copy_prot(). The SG table for prot_buf is also initialized by allocating 'se_cmd->t_prot_nents' entries of scatterlist and setting the data length of each entry to PAGE_SIZE at most. However if se_cmd->t_prot_sg contains a clustered entry (i.e. sg->length > PAGE_SIZE), the SG table for prot_buf can't be initialized correctly and sbc_dif_copy_prot() can't copy to prot_buf. (This actually happened with TCM loopback fabric module) As prot_buf is allocated by kzalloc() and it's physically contiguous, we only need a single scatterlist entry. 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_file.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c index 8ca1883..4c7a6c8 100644 --- a/drivers/target/target_core_file.c +++ b/drivers/target/target_core_file.c @@ -264,11 +264,10 @@ static int fd_do_prot_rw(struct se_cmd *cmd, struct fd_prot *fd_prot, struct se_device *se_dev = cmd->se_dev; struct fd_dev *dev = FD_DEV(se_dev); struct file *prot_fd = dev->fd_prot_file; - struct scatterlist *sg; loff_t pos = (cmd->t_task_lba * se_dev->prot_length); unsigned char *buf; - u32 prot_size, len, size; - int rc, ret = 1, i; + u32 prot_size; + int rc, ret = 1; prot_size = (cmd->data_length / se_dev->dev_attrib.block_size) * se_dev->prot_length; @@ -281,24 +280,16 @@ static int fd_do_prot_rw(struct se_cmd *cmd, struct fd_prot *fd_prot, } buf = fd_prot->prot_buf; - fd_prot->prot_sg_nents = cmd->t_prot_nents; - fd_prot->prot_sg = kzalloc(sizeof(struct scatterlist) * - fd_prot->prot_sg_nents, GFP_KERNEL); + fd_prot->prot_sg_nents = 1; + fd_prot->prot_sg = kzalloc(sizeof(struct scatterlist), + GFP_KERNEL); if (!fd_prot->prot_sg) { pr_err("Unable to allocate fd_prot->prot_sg\n"); kfree(fd_prot->prot_buf); return -ENOMEM; } sg_init_table(fd_prot->prot_sg, fd_prot->prot_sg_nents); - size = prot_size; - - for_each_sg(fd_prot->prot_sg, sg, fd_prot->prot_sg_nents, i) { - - len = min_t(u32, PAGE_SIZE, size); - sg_set_buf(sg, buf, len); - size -= len; - buf += len; - } + sg_set_buf(fd_prot->prot_sg, buf, prot_size); } if (is_write) {