Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1923287pxa; Thu, 6 Aug 2020 20:59:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqfxl1QC2/fWb3kHA8WvUw+DXqqy18nSggro1SeVobbm1+Ipblm+L9rprdWpf4+fXzIo/B X-Received: by 2002:a05:6402:e:: with SMTP id d14mr7183302edu.262.1596772745737; Thu, 06 Aug 2020 20:59:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596772745; cv=none; d=google.com; s=arc-20160816; b=eau3H4v9xrezqlxb6W+xE+Zegu6oHiGJLP/AINbFgQ0Dj+Hf6/TmLcV3+c3QEd43h2 AOus5kcpj9cgVVTLqGdlWDGJX1AbrRVNT/ob5WJ25WCBsG5j01Kqkd4gupdKL9MicAfO HRKOWQEK5XqFOLhml7sS6FwDC4E3eJebOG99mysQaPh94mm5LoAZm5lRQZrrIbe7Beh7 u7TVUU/cegh1FrxIlbTxYnQVYV9MppVdCbbBIx3SlN8QygKo2JSpK2UBbKxCwwZOkvdm YyRzWikqjGCopTKdiNbGs3djmpG0PBn9djwvb2d1aSMqVowLJn2c/QfeTmeiffmOYhxb RxlQ== 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:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=eESe55ezr1iZ1Zy18wXrGfKQc6TZR0V9xDdXszQdu9c=; b=rdjWv86V5kWhx8gSwRgTOn//uXAQ9K9Wed+FYEy854FNxD06ZBXnHgXNAufkw4Gvlz geW0KduCRkrDh3GAeB7RKYfQARY5VAPluMdjsBr3mU0g/lzxF0d449iQRyNu8McVBN5Y Xnk8PtsidmBvGasDoxtFF+VwVF+DRwnEA1oNBeNQ7wtT/gnKo2+sjqE1qZJcCb2JHqgE tfmWsV8CX3m1eIkR2w1SZGaygMZWHgql1ZrKJ53QVKchH2HpohZrJOKDqG3LxF6TuQUY 05trUgGnjBMYmVfwZj30VSwaPPX1x2DbkImKVnQeVzcAD/KSiICpaCtY0gj+DLm6Q0YM Iapw== 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 bw6si4556333ejb.653.2020.08.06.20.58.28; Thu, 06 Aug 2020 20:59:05 -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 S1726078AbgHGD60 (ORCPT + 99 others); Thu, 6 Aug 2020 23:58:26 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:43942 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726038AbgHGD6Z (ORCPT ); Thu, 6 Aug 2020 23:58:25 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id DF065B935D0C3FADCEE4; Fri, 7 Aug 2020 11:58:23 +0800 (CST) Received: from [10.63.139.185] (10.63.139.185) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Fri, 7 Aug 2020 11:58:22 +0800 Subject: Re: [BUG] crypto: hisilicon: accessing the data mapped to streaming DMA To: Jia-Ju Bai , , References: <361fa200-479c-e1ef-b7d6-e666a256660f@tsinghua.edu.cn> <5F276491.8060409@hisilicon.com> CC: , From: Zhou Wang Message-ID: <5F2CD15E.6060508@hisilicon.com> Date: Fri, 7 Aug 2020 11:58:22 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.63.139.185] X-CFilter-Loop: Reflected Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On 2020/8/3 9:29, Jia-Ju Bai wrote: > > > On 2020/8/3 9:12, Zhou Wang wrote: >> On 2020/8/2 22:52, Jia-Ju Bai wrote: >>> In qm_qp_ctx_cfg(), "sqc" and "aeqc" are mapped to streaming DMA: >>> eqc_dma = dma_map_single(..., eqc, ...); >>> ...... >>> aeqc_dma = dma_map_single(..., aeqc, ...); >> Only sqc, cqc will be configured in qm_qp_ctx_cfg. >> >>> Then "sqc" and "aeqc" are accessed at many places, such as: >>> eqc->base_l = cpu_to_le32(lower_32_bits(qm->eqe_dma)); >>> eqc->base_h = cpu_to_le32(upper_32_bits(qm->eqe_dma)); >>> ...... >>> aeqc->base_l = cpu_to_le32(lower_32_bits(qm->aeqe_dma)); >>> aeqc->base_h = cpu_to_le32(upper_32_bits(qm->aeqe_dma)); >> There are sqc, cqc, eqc, aeqc, you seems misunderstand them. >> >>> These accesses may cause data inconsistency between CPU cache and hardware. >>> >>> I am not sure how to properly fix this problem, and thus I only report it. >> In qm_qp_ctx_cfg, sqc/cqc memory will be allocated and related mailbox will be sent >> to hardware. In qm_eq_ctx_cfg, eqc/aeqc related operations will be done. >> >> So there is no problem here :) > > Ah, sorry, I misunderstood qm_eq_ctx_cfg() and qm_qp_ctx_cfg(), because their names are quite similar. > Now, I re-organize this report as follows: > > In qm_eq_ctx_cfg(), "eqc" and "aeqc" are mapped to streaming DMA: > eqc_dma = dma_map_single(..., eqc, ...); > ...... > aeqc_dma = dma_map_single(..., aeqc, ...); > > Then "sqc" and "aeqc" are accessed at some places in qm_eq_ctx_cfg(), such as: > eqc->base_l = cpu_to_le32(lower_32_bits(qm->eqe_dma)); > eqc->base_h = cpu_to_le32(upper_32_bits(qm->eqe_dma)); > ...... > aeqc->base_l = cpu_to_le32(lower_32_bits(qm->aeqe_dma)); > aeqc->base_h = cpu_to_le32(upper_32_bits(qm->aeqe_dma)); > > These accesses may cause data inconsistency between CPU cache and hardware. > > Besides, in qm_qp_ctx_cfg(), "sqc" and "cqc" are mapped to streaming DMA: > sqc_dma = dma_map_single(..., sqc, ...); > ...... > cqc_dma = dma_map_single(..., cqc, ...); > > > Then "sqc" and "cqc" are at some places in qm_qp_ctx_cfg(), such as: > sqc->cq_num = cpu_to_le16(qp_id); > sqc->w13 = cpu_to_le16(QM_MK_SQC_W13(0, 1, qp->alg_type)); > ...... > cqc->dw3 = cpu_to_le32(QM_MK_CQC_DW3_V2(4)); > cqc->w8 = 0; > > These accesses may cause data inconsistency between CPU cache and hardware. > > I think such problems (if they are real) can be fixed by finishing data assignment before DMA mapping. Sorry for late. I got your idea, from the semantics of dma_map_single/dma_unmap_single, we should not mix CPU and device DMA accessing here. The reason of working well is our hardware is hardware CC. Will fix this later. Thanks, Zhou > > > Best wishes, > Jia-Ju Bai > > . >