Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4988123ybv; Wed, 26 Feb 2020 06:31:59 -0800 (PST) X-Google-Smtp-Source: APXvYqx7TvbVFZcS8nAvEUwX6yFOBdV5eiuDERYmNhT787fdYIlOFup1O7iul35MXiISE9xW93bh X-Received: by 2002:aca:3114:: with SMTP id x20mr3402281oix.121.1582727519325; Wed, 26 Feb 2020 06:31:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582727519; cv=none; d=google.com; s=arc-20160816; b=DjhddjFodnOfviJru9m5jVXF3rGQKWI3lZwjCaUW8EPAtWCvQtLv2hO9yow30z7DuE gpRCqN8rWbKDGzHqMHIZxM/9FodqeOl237si8UqEP8tSfS7kmVHjkA8pbz6x0EmrsM2h /SWlbwduJ5y34gnafrlvq74fPyVmKkvCWmbRdG05BdiWXypY6ETwARO1BJZDqoquxo1G bKzHDVYOcQ3wSu4kWEPFi7ll9Oge1RxWp25VDDF8X3/+YPzwhqSa++aVSgZff0GHBNjQ uI4LbAbJJdqUIjmc5bslRoiRcZYTdoqOdSwKntv8tdXIMaXfoQjJjCrelZl/dzY5IGux 9i1A== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=wfJMfG0AWUAYejg04kFH6FbpsxD+QorWxIijxUHPKXg=; b=p1RpDZj51lgSRERGYigBE6wteVtbsbwfauCVislNJ4YPVnKiNfq2VBMlmqRrfOD4GZ DOQ3HU7e0uORQfQNXGXLQrHSpCSziKM/9K5RPURBCL8kviGsKzK6uz2oICDO87U13hgK mMt6XGPdN3seNEXAIUi4Ipx4sHaeR4MaZLDOW/pRzWWskJ/v0FSoufVQOe/SGc86O8vF d14vDoT0fKjg/j+PmhMs04qXOIAHA5zpE1WvB3Phhc6JQi+2AhTNSL/WzETACBd8g/nx PwRxYziykApbJBLL4zwLddOVnwMExUkNQUL2cB9mb7yhbB8aR0KRhwH0MNcsK9ljG3OY cvrA== 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 w18si1523580otl.54.2020.02.26.06.31.33; Wed, 26 Feb 2020 06:31:59 -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 S1727426AbgBZOal (ORCPT + 99 others); Wed, 26 Feb 2020 09:30:41 -0500 Received: from lhrrgout.huawei.com ([185.176.76.210]:2469 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727112AbgBZOal (ORCPT ); Wed, 26 Feb 2020 09:30:41 -0500 Received: from lhreml706-cah.china.huawei.com (unknown [172.18.7.106]) by Forcepoint Email with ESMTP id 2E299AFDB37F24ADCAC6; Wed, 26 Feb 2020 14:30:40 +0000 (GMT) Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by lhreml706-cah.china.huawei.com (10.201.108.47) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 26 Feb 2020 14:30:40 +0000 Received: from localhost (10.202.227.76) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 26 Feb 2020 14:30:39 +0000 Date: Wed, 26 Feb 2020 14:30:37 +0000 From: Jonathan Cameron To: Xu Zaibo CC: , , , , , , , , , Subject: Re: [PATCH 4/4] crypto: hisilicon/sec2 - Add pbuffer mode for SEC driver Message-ID: <20200226143037.00007ab0@Huawei.com> In-Reply-To: <1fa85493-0e56-745e-2f24-5a12c2fec496@huawei.com> References: <1582189495-38051-1-git-send-email-xuzaibo@huawei.com> <1582189495-38051-5-git-send-email-xuzaibo@huawei.com> <20200224140154.00005967@Huawei.com> <80ab5da7-eceb-920e-dc36-1d411ad57a09@huawei.com> <20200225151426.000009f5@Huawei.com> <1fa85493-0e56-745e-2f24-5a12c2fec496@huawei.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.227.76] X-ClientProxiedBy: lhreml742-chm.china.huawei.com (10.201.108.192) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, 26 Feb 2020 19:18:51 +0800 Xu Zaibo wrote: > Hi, > On 2020/2/25 23:14, Jonathan Cameron wrote: > > On Tue, 25 Feb 2020 11:16:52 +0800 > > Xu Zaibo wrote: > > > >> Hi, > >> > >> > >> On 2020/2/24 22:01, Jonathan Cameron wrote: > >>> On Thu, 20 Feb 2020 17:04:55 +0800 > >>> Zaibo Xu wrote: > >>> > >>> > [...] > >>>> > >>>> +static void sec_free_pbuf_resource(struct device *dev, struct sec_alg_res *res) > >>>> +{ > >>>> + if (res->pbuf) > >>>> + dma_free_coherent(dev, SEC_TOTAL_PBUF_SZ, > >>>> + res->pbuf, res->pbuf_dma); > >>>> +} > >>>> + > >>>> +/* > >>>> + * To improve performance, pbuffer is used for > >>>> + * small packets (< 576Bytes) as IOMMU translation using. > >>>> + */ > >>>> +static int sec_alloc_pbuf_resource(struct device *dev, struct sec_alg_res *res) > >>>> +{ > >>>> + int pbuf_page_offset; > >>>> + int i, j, k; > >>>> + > >>>> + res->pbuf = dma_alloc_coherent(dev, SEC_TOTAL_PBUF_SZ, > >>>> + &res->pbuf_dma, GFP_KERNEL); > >>> Would it make more sense perhaps to do this as a DMA pool and have > >>> it expand on demand? > >> Since there exist all kinds of buffer length, I think dma_alloc_coherent > >> may be better? > > As it currently stands we allocate a large buffer in one go but ensure > > we only have a single dma map that occurs at startup. > > > > If we allocate every time (don't use pbuf) performance is hit by > > the need to set up the page table entries and flush for every request. > > > > A dma pool with a fixed size element would at worst (for small messages) > > mean you had to do a dma map / unmap every time 6 ish buffers. > > This would only happen if you filled the whole queue. Under normal operation > > you will have a fairly steady number of buffers in use at a time, so mostly > > it would be reusing buffers that were already mapped from a previous request. > Agree, dma pool may give a smaller range of mapped memory, which may > increase hits > of IOMMU TLB. > > > > You could implement your own allocator on top of dma_alloc_coherent but it'll > > probably be a messy and cost you more than using fixed size small elements. > > > > So a dmapool here would give you a mid point between using lots of memory > > and never needing to map/unmap vs map/unmap every time. > > > My concern is the spinlock of DMA pool, which adds an exclusion between > sending requests > and receiving responses, since DMA blocks are allocated as sending and > freed at receiving. Agreed. That may be a bottleneck. Not clear to me whether that would be a significant issue or not. Jonathan > > Thanks, > Zaibo > > . > >>> > >>>> + if (!res->pbuf) > >>>> + return -ENOMEM; > >>>> + > >>>> + /* > >>>> + * SEC_PBUF_PKG contains data pbuf, iv and > >>>> + * out_mac : > >>>> + * Every PAGE contains six SEC_PBUF_PKG > >>>> + * The sec_qp_ctx contains QM_Q_DEPTH numbers of SEC_PBUF_PKG > >>>> + * So we need SEC_PBUF_PAGE_NUM numbers of PAGE > >>>> + * for the SEC_TOTAL_PBUF_SZ > >>>> + */ > >>>> + for (i = 0; i <= SEC_PBUF_PAGE_NUM; i++) { > >>>> + pbuf_page_offset = PAGE_SIZE * i; > >>>> + for (j = 0; j < SEC_PBUF_NUM; j++) { > >>>> + k = i * SEC_PBUF_NUM + j; > >>>> + if (k == QM_Q_DEPTH) > >>>> + break; > >>>> + res[k].pbuf = res->pbuf + > >>>> + j * SEC_PBUF_PKG + pbuf_page_offset; > >>>> + res[k].pbuf_dma = res->pbuf_dma + > >>>> + j * SEC_PBUF_PKG + pbuf_page_offset; > >>>> + } > >>>> + } > >>>> + return 0; > >>>> +} > >>>> + > [...] >