Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp139294ybc; Mon, 18 Nov 2019 22:02:00 -0800 (PST) X-Google-Smtp-Source: APXvYqwuf7R6RDZW4Ch4ydYkAySpCu3UnAhA56oglhisd7rKG9hkS58kkc1j7DoiSfeEWG5A5uca X-Received: by 2002:a7b:c408:: with SMTP id k8mr3551629wmi.67.1574143320335; Mon, 18 Nov 2019 22:02:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574143320; cv=none; d=google.com; s=arc-20160816; b=MY7JgrDhcAmTy1SaYiJULND/urlN70d25fgBzaIrMA7SlUo9+1vBr6XdODwJyxX1A9 CSYGwEa0Vb2u7dfc81cmQhRZ5v6IGyyGa/oYI60u7NhFrZT/c3tXKMOHEIZdslH+hOYD zZBLYMj2MZux1exwlvs3ucdgCSc6Bxla2FWQUpbdoIqfBYbtWQfR1VPUd2qdu6WxjkFW tMR+8A5aH5+7YAcI6OWHdJbPzYvj7waqTm9nYzAdaMp3iC8aAvNBbuD+tLtKmtcp27sa DQZzLOVXqiQ44syU2T9JmofSVG/KH1WLsn8EjfEO5T2E0Hzd1ftkjzgKLKut3xtL9/pJ vUXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=yMGtMdxbEHiuEnlrlyYsYmUJK09Br78eDGz11eMtpvk=; b=v0dv5IPj+CGu4L1hJqKLkJRHTMGBfKAVzI544/4Ou8L+A/wcdoHStFWtfKI6fyd5qo dJMpFQcgjIN7oC22N1aiaAA8wIWhbfo4YVdmiNmYqz2s8cuxuMRHGqgEClbcC8Jqt03J Y4XgMYfu1Bhq91dzVdHgVJGyjV09gTrZ/Vv44u9nkxYHSTUUxzhOKa/e3BFZklgjEZ6m avOHds1G05J+kvkh6d/7KBtDsdB+oyb3Jrlx50puVSrMY46lPpD7OHYGBqrk23ODIGzW IYwHn8+UAuDEvYL+0oj3ninUgJkbm75rxHL30MVc+kn+1SZ2Zow6jLYT/Xz9U7gIKy6p oc3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g13si15277621eda.292.2019.11.18.22.01.29; Mon, 18 Nov 2019 22:02:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726170AbfKSGAG (ORCPT + 99 others); Tue, 19 Nov 2019 01:00:06 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:54742 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730030AbfKSFqa (ORCPT ); Tue, 19 Nov 2019 00:46:30 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 9AFCD65D2B03D8D3F7A3; Tue, 19 Nov 2019 13:46:29 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Tue, 19 Nov 2019 13:46:23 +0800 From: Zhou Wang To: Herbert Xu , "David S. Miller" CC: , , Jonathan Cameron , Zhou Wang Subject: [PATCH 1/3] crypto: hisilicon - Fix issue with wrong number of sg elements after dma map Date: Tue, 19 Nov 2019 13:42:56 +0800 Message-ID: <1574142178-76514-2-git-send-email-wangzhou1@hisilicon.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1574142178-76514-1-git-send-email-wangzhou1@hisilicon.com> References: <1574142178-76514-1-git-send-email-wangzhou1@hisilicon.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Jonathan Cameron We fill the hardware scatter gather list assuming it will need the same number of elements at the original scatterlist. If an IOMMU is involved, then it may well need fewer. The return value of dma_map_sg tells us how many. Probably never caused visible problems as the hardware won't get to the elements that are incorrect before it finds enough space. Fixes: dfed0098ab91 (crypto: hisilicon - add hardware SGL support) Signed-off-by: Jonathan Cameron Signed-off-by: Zhou Wang --- drivers/crypto/hisilicon/sgl.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/hisilicon/sgl.c b/drivers/crypto/hisilicon/sgl.c index 012023c..1e153a0 100644 --- a/drivers/crypto/hisilicon/sgl.c +++ b/drivers/crypto/hisilicon/sgl.c @@ -202,18 +202,21 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev, dma_addr_t curr_sgl_dma = 0; struct acc_hw_sge *curr_hw_sge; struct scatterlist *sg; - int i, ret, sg_n; + int i, sg_n, sg_n_mapped; if (!dev || !sgl || !pool || !hw_sgl_dma) return ERR_PTR(-EINVAL); sg_n = sg_nents(sgl); - if (sg_n > pool->sge_nr) + + sg_n_mapped = dma_map_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL); + if (!sg_n_mapped) return ERR_PTR(-EINVAL); - ret = dma_map_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL); - if (!ret) + if (sg_n_mapped > pool->sge_nr) { + dma_unmap_sg(dev, sgl, sg_n, DMA_BIDIRECTIONAL); return ERR_PTR(-EINVAL); + } curr_hw_sgl = acc_get_sgl(pool, index, &curr_sgl_dma); if (IS_ERR(curr_hw_sgl)) { @@ -224,7 +227,7 @@ hisi_acc_sg_buf_map_to_hw_sgl(struct device *dev, curr_hw_sgl->entry_length_in_sgl = cpu_to_le16(pool->sge_nr); curr_hw_sge = curr_hw_sgl->sge_entries; - for_each_sg(sgl, sg, sg_n, i) { + for_each_sg(sgl, sg, sg_n_mapped, i) { sg_map_to_hw_sg(sg, curr_hw_sge); inc_hw_sgl_sge(curr_hw_sgl); curr_hw_sge++; -- 2.8.1