Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3688843ybv; Mon, 10 Feb 2020 04:45:01 -0800 (PST) X-Google-Smtp-Source: APXvYqz5m4Ld1h5O6wfOEfBH/9NwR4FZSAwNSC+RbugPoDhsV1vlT1E5HzcMVRP72LdHo9s6YECx X-Received: by 2002:a9d:6212:: with SMTP id g18mr961253otj.187.1581338701699; Mon, 10 Feb 2020 04:45:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581338701; cv=none; d=google.com; s=arc-20160816; b=0iS7xwmaUOGNKygEAv/hwqiDawFODlmWx+auVzHbbxK5zyJTGqDaNpnVp6IK1uNe+R yZnzk3yRDAWe0rM3BwtUcaibl+pkwAyzPCX8ixtaoGd+l8rXD6WdZtx2dvy6+yHWCrGW REhcA1APvYlLhrvhuikvL4xsra6sGKUfF9Ep6S2MYGQ/MFQrwLR0UCzK8p8zkDtqQ7as b25YCe9tMf67l31cMN4XXpJWNDUBEMCeucva17XuEzmWNxXd9A15+rwPl3DHZAkT8ybf FqpJeAYnNqObmUod8U9Z0NxBkgW9lU2XaL3uzjvto48pYnlACtYgTVsSglCRcYOaoG9G DkIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cktocQNJAVpoT3rzSskrTK6eCFzBb8Qf52EYvvYEXFs=; b=NGYS8wS6tev/xQB7RFP4DKhL+jvYbiD6lpBqs5EFsOcm0yAt4JqGtlgZg8+1o9gCKo z6MkVks9YP2wQFNO+1M94Y1+5MsenIa7re6prTr7jKT6j1Ka+4zt8FnewprIoYr93yNj 3tfwgxr7V4uhuXjVeGWwsi8senwX8jPz8G9W2jonKkoPAPwPAxUpbXhp1qKfr8whAC8N JhwAnRSAU2fId/uvWlz4EjqNxzoX/JUHK1/BWMKreNyVVVU1dj2ntHkHWhHWmdBR/qdm z/RDWNUt6DpFbaIu4Krm1tJEQ2Z2bYMwTIUZAqrz3kiM93osZ/q/IId8dXdTo+PPe4og mJOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XFFU2n03; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 i194si135642oib.73.2020.02.10.04.44.50; Mon, 10 Feb 2020 04:45:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XFFU2n03; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730681AbgBJMoh (ORCPT + 99 others); Mon, 10 Feb 2020 07:44:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:40998 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728177AbgBJMkl (ORCPT ); Mon, 10 Feb 2020 07:40:41 -0500 Received: from localhost (unknown [209.37.97.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F21A424681; Mon, 10 Feb 2020 12:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338441; bh=NgxN8rk0oEyiDL59DR9toPD4TH1Hq4BjSOhDPYlVWUg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XFFU2n03AK0XvJEz9wYsm1JOe6nF2TDYMti+zkZZiVNR602DD/qxnpx3Y+pIFclqu 0yE4V0evOvgJahpYpnYVBQhV3vblaos40MwWB9Dwg7xaCniT5tmKHDm1vVTshX4TQr PaCIHGj9XpBdfjnw3WXcyfojhpXS1luXt2kRmdto= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jonathan Cameron , Zhou Wang , Herbert Xu Subject: [PATCH 5.5 178/367] crypto: hisilicon - Fix issue with wrong number of sg elements after dma map Date: Mon, 10 Feb 2020 04:31:31 -0800 Message-Id: <20200210122441.223289189@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jonathan Cameron commit 8debacd60c69beab80736d4af4feca47c2e2bd9e upstream. 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 Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/hisilicon/sgl.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- 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 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 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++;