Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2738124pxv; Mon, 12 Jul 2021 00:19:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwC3S6mECC9rQ9jRF1fxHtOUhVUvrC66ODZHD5jEwqINam8+9tTWhALQGA4Ax5neL8kc817 X-Received: by 2002:a02:ca41:: with SMTP id i1mr24420508jal.70.1626074381434; Mon, 12 Jul 2021 00:19:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626074381; cv=none; d=google.com; s=arc-20160816; b=y4dJcPMyvCm21xKpXHpb6UBrDuIAr1rwqAKS9rWFVpNPhab3idQoWnLnhGbuT9XH7Z cOJJG9X0TAx5zFsfUJv5rYdWrGRorV+R29LvqkzMRykej3gRTud0B++8vDCDGTMpzIKb R1vwsSp+XJo5WPK6Y+uRLpc7oFTD/QN1KsrJc2MJxh49+sXDrM/89q+bHBuAYROhKpAf J/5uMeaJqSjlTESHXUCjLDIz+ePLwzCaJGuSL3peYZzmWBeiG2g+KdwpPp4oPZjhryZd 6wax2nsvJeyuRiujo4B1Fh8sm7k0wDK7rDwAYIB/pDpnUbxH9m1boe3JnxnLlkAq1pqc GtSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mDeqe4gR8KzrBdPPCyl6UtdvDh3jEYq3yrSqLxiuL0M=; b=ohzpDoYxExDNqicHBebtnXgvjvQGIc4OK+sPcqA3UAS8Yl1q8pp6/NWkRbDS/y7WEe jXRe+snRCGOVQIBSA0I1ywKoMsYwxe1ensFuoDkshunWl1Ubp3uXX79ls56j81SE1MGs FUMEehDX01s5s1ettXICvJQhmr7ygtYpZ2YasUvMQlyd0LLFOHvyUB1CAPF/D1Ueh2bZ srsUF/nRzBt8QuDzGNQMErXXsRwcSvzyifrDDwR5h2xK4oRKU1aWlFMfGYbDW7wzb5CW bMYyEz3n8mqzYEVhu8LCZoK6MeIwl+z6Dn+2mfsNv8ej3JHcgaRC5hydyzhES7kGCVxb meXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NtBIOc23; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m9si6445551jaj.89.2021.07.12.00.19.28; Mon, 12 Jul 2021 00:19:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NtBIOc23; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245032AbhGLHTU (ORCPT + 99 others); Mon, 12 Jul 2021 03:19:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:53698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240973AbhGLGyX (ORCPT ); Mon, 12 Jul 2021 02:54:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A6367611B0; Mon, 12 Jul 2021 06:51:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626072688; bh=VrPXUm0PKzWrgMxxobE5j99PE4NAJHQyapS/YeWsxBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NtBIOc23Z4byUamIv2j+DVSRwkXEVm9vo44q6/3epHGq5vKj0Hwjl5P6K9AEXaYlX Fnj16znaD1qh2xCtoHiM9WIE/v2GTYAGnnMnABNGTuUh8BTp3QAWoTtmWpuPyQcOis 6+W1FNMd9aHgLVB0q/GlnJXU8AsSEkaQThxCrW4Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Varun Prakash , "Martin K. Petersen" Subject: [PATCH 5.10 582/593] scsi: target: cxgbit: Unmap DMA buffer before calling target_execute_cmd() Date: Mon, 12 Jul 2021 08:12:22 +0200 Message-Id: <20210712060959.242606314@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Varun Prakash commit 6ecdafaec79d4b3388a5b017245f23a0ff9d852d upstream. Instead of calling dma_unmap_sg() after completing WRITE I/O, call dma_unmap_sg() before calling target_execute_cmd() to sync the DMA buffer. Link: https://lore.kernel.org/r/1618403949-3443-1-git-send-email-varun@chelsio.com Cc: # 5.4+ Signed-off-by: Varun Prakash Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/target/iscsi/cxgbit/cxgbit_ddp.c | 19 ++++++++++--------- drivers/target/iscsi/cxgbit/cxgbit_target.c | 21 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 12 deletions(-) --- a/drivers/target/iscsi/cxgbit/cxgbit_ddp.c +++ b/drivers/target/iscsi/cxgbit/cxgbit_ddp.c @@ -265,12 +265,13 @@ void cxgbit_unmap_cmd(struct iscsi_conn struct cxgbit_cmd *ccmd = iscsit_priv_cmd(cmd); if (ccmd->release) { - struct cxgbi_task_tag_info *ttinfo = &ccmd->ttinfo; - - if (ttinfo->sgl) { + if (cmd->se_cmd.se_cmd_flags & SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC) { + put_page(sg_page(&ccmd->sg)); + } else { struct cxgbit_sock *csk = conn->context; struct cxgbit_device *cdev = csk->com.cdev; struct cxgbi_ppm *ppm = cdev2ppm(cdev); + struct cxgbi_task_tag_info *ttinfo = &ccmd->ttinfo; /* Abort the TCP conn if DDP is not complete to * avoid any possibility of DDP after freeing @@ -280,14 +281,14 @@ void cxgbit_unmap_cmd(struct iscsi_conn cmd->se_cmd.data_length)) cxgbit_abort_conn(csk); + if (unlikely(ttinfo->sgl)) { + dma_unmap_sg(&ppm->pdev->dev, ttinfo->sgl, + ttinfo->nents, DMA_FROM_DEVICE); + ttinfo->nents = 0; + ttinfo->sgl = NULL; + } cxgbi_ppm_ppod_release(ppm, ttinfo->idx); - - dma_unmap_sg(&ppm->pdev->dev, ttinfo->sgl, - ttinfo->nents, DMA_FROM_DEVICE); - } else { - put_page(sg_page(&ccmd->sg)); } - ccmd->release = false; } } --- a/drivers/target/iscsi/cxgbit/cxgbit_target.c +++ b/drivers/target/iscsi/cxgbit/cxgbit_target.c @@ -997,17 +997,18 @@ static int cxgbit_handle_iscsi_dataout(s struct scatterlist *sg_start; struct iscsi_conn *conn = csk->conn; struct iscsi_cmd *cmd = NULL; + struct cxgbit_cmd *ccmd; + struct cxgbi_task_tag_info *ttinfo; struct cxgbit_lro_pdu_cb *pdu_cb = cxgbit_rx_pdu_cb(csk->skb); struct iscsi_data *hdr = (struct iscsi_data *)pdu_cb->hdr; u32 data_offset = be32_to_cpu(hdr->offset); - u32 data_len = pdu_cb->dlen; + u32 data_len = ntoh24(hdr->dlength); int rc, sg_nents, sg_off; bool dcrc_err = false; if (pdu_cb->flags & PDUCBF_RX_DDP_CMP) { u32 offset = be32_to_cpu(hdr->offset); u32 ddp_data_len; - u32 payload_length = ntoh24(hdr->dlength); bool success = false; cmd = iscsit_find_cmd_from_itt_or_dump(conn, hdr->itt, 0); @@ -1022,7 +1023,7 @@ static int cxgbit_handle_iscsi_dataout(s cmd->data_sn = be32_to_cpu(hdr->datasn); rc = __iscsit_check_dataout_hdr(conn, (unsigned char *)hdr, - cmd, payload_length, &success); + cmd, data_len, &success); if (rc < 0) return rc; else if (!success) @@ -1060,6 +1061,20 @@ static int cxgbit_handle_iscsi_dataout(s cxgbit_skb_copy_to_sg(csk->skb, sg_start, sg_nents, skip); } + ccmd = iscsit_priv_cmd(cmd); + ttinfo = &ccmd->ttinfo; + + if (ccmd->release && ttinfo->sgl && + (cmd->se_cmd.data_length == (cmd->write_data_done + data_len))) { + struct cxgbit_device *cdev = csk->com.cdev; + struct cxgbi_ppm *ppm = cdev2ppm(cdev); + + dma_unmap_sg(&ppm->pdev->dev, ttinfo->sgl, ttinfo->nents, + DMA_FROM_DEVICE); + ttinfo->nents = 0; + ttinfo->sgl = NULL; + } + check_payload: rc = iscsit_check_dataout_payload(cmd, hdr, dcrc_err);