Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp250943ybk; Sat, 9 May 2020 01:43:16 -0700 (PDT) X-Google-Smtp-Source: APiQypK3Y3dkKhG28S851nZprj/KZSJYQEcg2obQrQ5b546HkPv7YNos7auiILZVPXP0OeDjLWn/ X-Received: by 2002:a05:6402:1694:: with SMTP id a20mr5266445edv.322.1589013796703; Sat, 09 May 2020 01:43:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589013796; cv=none; d=google.com; s=arc-20160816; b=VWB36ULrcjLISg0VFi8hy3KY8eITXoqwGsEmN3NDXfWR+eFo9ybPGxPBFvsoqNvU1A D3mCCX0UjcT+uE56YQWHihIl03LaDd7fDlDkl7YdeKiduHHpvVRKM2y3GKgn82yButH2 oVeoU1mzmjQR6Fj5fnWfto2CfNRxGmjXFpZyB7X2irJ9V6SBmyzXBVw9/osjpr9Ya4wD M+9EtOm+e3xpqCg9t/Iwm4QCm4oLfS4r1fW4A/yXX/uZLNW+LyX5QfIIEHaPWMFFm9ld p3KKhKSgiyGgGcQdhpIXob6L+EuO7v+Ny199NmBuaEygLtPx3RbidgdkCnmJix+6nSOb IWig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=1Z9TiE2pBN9ngIPl0E6i2aQiJIwBoohSZNOU1xjjFZk=; b=kgdReC1nyEWXikPtFIVza3R4zmL4+SXa52R8kE93d7x4xzLM8mEUKTCxv8K7HH83xN VO0OuS/tfUxroqawY9xYTfzaGTbMPBBP0K6ymrgEO6pxSydGnAQhM6j41doGZEfL4RAL GSPZ0o6wptZleyYZq3+sKTSw20ZqkPSZsVzh9718F22ZEZMub9ZgQjHpBBH/ouktKyOd Qi1TYujtQAhuuKym96VdDNgHr1fv6XxPXv9DN13t8MeL81yQw7IGqviaCqnyH81fkpY6 m+j9ENvohh/m8s7yp9T8NAz4fVUTwPjKtQtTeJZ2FI234tlQuJnWd1dhAWQgkza+tA7d +raA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u10si2682113edl.591.2020.05.09.01.42.42; Sat, 09 May 2020 01:43:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726013AbgEIImm convert rfc822-to-8bit (ORCPT + 99 others); Sat, 9 May 2020 04:42:42 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:2501 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725930AbgEIIml (ORCPT ); Sat, 9 May 2020 04:42:41 -0400 Received: from dggemi403-hub.china.huawei.com (unknown [172.30.72.54]) by Forcepoint Email with ESMTP id 9F5EEA5F07300B0ECC05; Sat, 9 May 2020 16:42:35 +0800 (CST) Received: from DGGEMI423-HUB.china.huawei.com (10.1.199.152) by dggemi403-hub.china.huawei.com (10.3.17.136) with Microsoft SMTP Server (TLS) id 14.3.487.0; Sat, 9 May 2020 16:42:35 +0800 Received: from DGGEMI525-MBS.china.huawei.com ([169.254.6.251]) by dggemi423-hub.china.huawei.com ([10.1.199.152]) with mapi id 14.03.0487.000; Sat, 9 May 2020 16:42:27 +0800 From: Song Bao Hua To: "Wangzhou (B)" , "tanshukun (A)" , "herbert@gondor.apana.org.au" , "davem@davemloft.net" CC: "linux-crypto@vger.kernel.org" , Xu Zaibo Subject: RE: [PATCH 12/13] crypto: hisilicon/zip - Use temporary sqe when doing work Thread-Topic: [PATCH 12/13] crypto: hisilicon/zip - Use temporary sqe when doing work Thread-Index: AQHWJQZAcAZApu4+hkePZFWlj8fJQ6ifGvTA//+wygCAAKPTMA== Date: Sat, 9 May 2020 08:42:26 +0000 Message-ID: References: <1588921068-20739-1-git-send-email-tanshukun1@huawei.com> <1588921068-20739-13-git-send-email-tanshukun1@huawei.com> <5EB6526A.20804@hisilicon.com> In-Reply-To: <5EB6526A.20804@hisilicon.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.126.201.87] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-CFilter-Loop: Reflected Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org > > > >> From: Zhou Wang > > > >> Currently zip sqe is stored in hisi_zip_qp_ctx, which will bring corruption with multiple parallel users of the crypto tfm. > > > >> This patch removes the zip_sqe in hisi_zip_qp_ctx and uses a temporary sqe instead. > > > > This looks like a quite correct fix as in the old code, the 2nd request will overwrite the zip_sqe of the 1st request if we send the 2nd request before the 1st one is completed. > > So this will lead to the mistakes of both request1 and request2. > Yes. > > > > unfortunately, it seems the hang issue can still be reproduced with this patch applied if we ask multi-threads running on multi-cores to send requests in parallel. Maybe something more needs fix? > Currently we do not support multi-threads using one crypto_acomp in this driver. > If you tested like this, it may go wrong, as we do not protect queue which is in zip ctx. Zhou, Thanks for clarification. I'm ok with this patch as it is definitely going to the right direction and removing some race conditions. Maybe we need a follow-up patch to address the parallel problem later. > Best, > Zhou Barry > > > >> Signed-off-by: Zhou Wang > >> Signed-off-by: Jonathan Cameron > >> Signed-off-by: Shukun Tan > >> --- > >> drivers/crypto/hisilicon/zip/zip_crypto.c | 11 +++++------ > >> 1 file changed, 5 insertions(+), 6 deletions(-) > > > >> diff --git a/drivers/crypto/hisilicon/zip/zip_crypto.c > >> b/drivers/crypto/hisilicon/zip/zip_crypto.c > >> index 369ec32..5fb9d4b 100644 > >> --- a/drivers/crypto/hisilicon/zip/zip_crypto.c > >> +++ b/drivers/crypto/hisilicon/zip/zip_crypto.c > >> @@ -64,7 +64,6 @@ struct hisi_zip_req_q { > >> > >> struct hisi_zip_qp_ctx { > >> struct hisi_qp *qp; > >> - struct hisi_zip_sqe zip_sqe; > >> struct hisi_zip_req_q req_q; > >> struct hisi_acc_sgl_pool *sgl_pool; > >> struct hisi_zip *zip_dev; > >> @@ -484,11 +483,11 @@ static struct hisi_zip_req *hisi_zip_create_req(struct acomp_req *req, static int hisi_zip_do_work(struct hisi_zip_req *req, > >> struct hisi_zip_qp_ctx *qp_ctx) { > >> - struct hisi_zip_sqe *zip_sqe = &qp_ctx->zip_sqe; > >> struct acomp_req *a_req = req->req; > >> struct hisi_qp *qp = qp_ctx->qp; > >> struct device *dev = &qp->qm->pdev->dev; > >> struct hisi_acc_sgl_pool *pool = qp_ctx->sgl_pool; > >> + struct hisi_zip_sqe zip_sqe; > >> dma_addr_t input; > >> dma_addr_t output; > >> int ret; > >> @@ -511,13 +510,13 @@ static int hisi_zip_do_work(struct hisi_zip_req *req, > >> } > >> req->dma_dst = output; > >> > >> - hisi_zip_fill_sqe(zip_sqe, qp->req_type, input, output, a_req->slen, > >> + hisi_zip_fill_sqe(&zip_sqe, qp->req_type, input, output, > >> +a_req->slen, > >> a_req->dlen, req->sskip, req->dskip); > >> - hisi_zip_config_buf_type(zip_sqe, HZIP_SGL); > >> - hisi_zip_config_tag(zip_sqe, req->req_id); > >> + hisi_zip_config_buf_type(&zip_sqe, HZIP_SGL); > >> + hisi_zip_config_tag(&zip_sqe, req->req_id); > >> > >> /* send command to start a task */ > >> - ret = hisi_qp_send(qp, zip_sqe); > >> + ret = hisi_qp_send(qp, &zip_sqe); > >> if (ret < 0) > >> goto err_unmap_output; > >>