From patchwork Tue Apr 2 19:58: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: 10882279 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 122CE139A for ; Tue, 2 Apr 2019 19:58:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F03A22875F for ; Tue, 2 Apr 2019 19:58:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E462F288D7; Tue, 2 Apr 2019 19:58:38 +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.9 required=2.0 tests=BAYES_00,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 81C392875F for ; Tue, 2 Apr 2019 19:58:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726399AbfDBT6i (ORCPT ); Tue, 2 Apr 2019 15:58:38 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:36506 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726157AbfDBT6i (ORCPT ); Tue, 2 Apr 2019 15:58:38 -0400 Received: by mail-pg1-f196.google.com with SMTP id 85so7086624pgc.3 for ; Tue, 02 Apr 2019 12:58:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xbUWwWu9HBJ8Pwz1lj3z2Zy0bcYkUyecgACjBL+avEA=; b=n3Mr1akW/LFoMGkRQBAHBtWF+OKmn8JuBH8X0zH4bCesalxWg9nDRxMSdTQ5yCMMc8 uZzg0lkFHcixp0v1mL9qmYXh0V9QyyPkMKeCXtaD+fGvS1ZfTIhrabpnhoD3IUJYfCIF 6cAlLgzbqV04sV/G/kUvfnY8BxjWuPvX670DsIr6Tax3DwtfgnEdpd4ll5eTViHr/EmR 5ePb4QfXjdBP45g/L6rsSW+1BFqM7PAM5uYOIfJxDSOtN8Xafrj1xXoOg+p2bKyu6evB GfqqVcMB8kUsJnEyaFSGDV2G+ipPc+Hf5d7N4QuAHKo9UlfwkQdnMecoQUtOFspO9eHD eS7A== X-Gm-Message-State: APjAAAXyUCsuChFmlChMxF6/LKCMtgFlS4n+L4UR81sGNKPqKTpS+3hZ 0AfLzuE0qoY1O/lfeJPmrU8= X-Google-Smtp-Source: APXvYqx4AB/z/T4NeZgl19x/cx7G3JFVKV/NWBPsqWNY3SrEeAGO46AIEbT+mTGxXXidmUhGrRNEFA== X-Received: by 2002:a63:e10b:: with SMTP id z11mr64509946pgh.46.1554235117226; Tue, 02 Apr 2019 12:58:37 -0700 (PDT) Received: from desktop-bart.svl.corp.google.com ([2620:15c:2cd:203:5cdc:422c:7b28:ebb5]) by smtp.gmail.com with ESMTPSA id o5sm49055490pfa.135.2019.04.02.12.58.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 12:58:36 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: Mike Christie , Christoph Hellwig , target-devel@vger.kernel.org, Bart Van Assche , Mike Christie , Hannes Reinecke , Nicholas Bellinger Subject: [PATCH 08/11] target/iscsi: Only send R2T if needed Date: Tue, 2 Apr 2019 12:58:12 -0700 Message-Id: <20190402195815.254796-9-bvanassche@acm.org> X-Mailer: git-send-email 2.20.GIT In-Reply-To: <20190402195815.254796-1-bvanassche@acm.org> References: <20190402195815.254796-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If an initiator submits more immediate data than the size derived from the SCSI CDB, do not send any R2T to the initiator. This scenario is triggered by the libiscsi test ALL.iSCSIResiduals.WriteVerify16Residuals if the iSCSI target driver is modified to discard too large immediate data buffers instead of trying to parse these as an iSCSI PDU. This patch avoids that a negative xfer_len value is passed to iscsit_add_r2t_to_list() if too large immediate data buffers are handled correctly. Cc: Mike Christie Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Nicholas Bellinger Signed-off-by: Bart Van Assche --- drivers/target/iscsi/iscsi_target.c | 6 ++++++ drivers/target/iscsi/iscsi_target_util.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 5ce6e2a40e00..828697015759 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -3121,6 +3121,12 @@ int iscsit_build_r2ts_for_cmd( else xfer_len = conn->sess->sess_ops->MaxBurstLength; } + + if ((s32)xfer_len < 0) { + cmd->cmd_flags |= ICF_SENT_LAST_R2T; + break; + } + cmd->r2t_offset += xfer_len; if (cmd->r2t_offset == cmd->se_cmd.data_length) diff --git a/drivers/target/iscsi/iscsi_target_util.c b/drivers/target/iscsi/iscsi_target_util.c index 3da062ccd2ab..5b26bc23016a 100644 --- a/drivers/target/iscsi/iscsi_target_util.c +++ b/drivers/target/iscsi/iscsi_target_util.c @@ -67,6 +67,8 @@ int iscsit_add_r2t_to_list( lockdep_assert_held(&cmd->r2t_lock); + WARN_ON_ONCE((s32)xfer_len < 0); + r2t = kmem_cache_zalloc(lio_r2t_cache, GFP_ATOMIC); if (!r2t) { pr_err("Unable to allocate memory for struct iscsi_r2t.\n");