Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756049AbcK2Gs0 convert rfc822-to-8bit (ORCPT ); Tue, 29 Nov 2016 01:48:26 -0500 Received: from dggrg03-dlp ([45.249.212.189]:2427 "EHLO dggrg03-dlp.huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1754300AbcK2GsY (ORCPT ); Tue, 29 Nov 2016 01:48:24 -0500 From: "Gonglei (Arei)" To: "Gonglei (Arei)" , "Michael S. Tsirkin" , Stefan Hajnoczi CC: "linux-kernel@vger.kernel.org" , "qemu-devel@nongnu.org" , "virtio-dev@lists.oasis-open.org" , "virtualization@lists.linux-foundation.org" , "linux-crypto@vger.kernel.org" , Luonengjun , "Huangweidong (C)" , "Wubin (H)" , "xin.zeng@intel.com" , "Claudio Fontana" , "herbert@gondor.apana.org.au" , "pasic@linux.vnet.ibm.com" , "davem@davemloft.net" , "Zhoujian (jay, Euler)" , "Hanweidong (Randy)" , "arei.gonglei@hotmail.com" , "cornelia.huck@de.ibm.com" , "Xuquan (Quan Xu)" , longpeng , "salvatore.benedetto@intel.com" Subject: RE: [PATCH v3] crypto: add virtio-crypto driver Thread-Topic: [PATCH v3] crypto: add virtio-crypto driver Thread-Index: AQHSSXApGZSK+H+na06W6uimRRCgiKDuDc2AgAAQdYCAARH2sIAAVLbA Date: Tue, 29 Nov 2016 06:47:52 +0000 Message-ID: <33183CC9F5247A488A2544077AF19020DA14A720@DGGEMA505-MBX.china.huawei.com> References: <1480334903-6672-1-git-send-email-arei.gonglei@huawei.com> <1480334903-6672-2-git-send-email-arei.gonglei@huawei.com> <20161128162055.GB11196@stefanha-x1.localdomain> <20161128185747-mutt-send-email-mst@kernel.org> Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.177.18.62] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020202.583D24A6.03BD,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=169.254.1.226, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 326622b31b3e3051586072eba3dc645e Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1250 Lines: 35 > > > > > + > > > > +/* Note: kernel crypto API realization */ > > > > +static int virtio_crypto_ablkcipher_setkey(struct crypto_ablkcipher *tfm, > > > > + const uint8_t *key, > > > > + unsigned int keylen) > > > > +{ > > > > + struct virtio_crypto_ablkcipher_ctx *ctx = > > crypto_ablkcipher_ctx(tfm); > > > > + int ret; > > > > + > > > > + spin_lock(&ctx->lock); > > > > + > > > > + if (!ctx->vcrypto) { > > > > + /* New key */ > > > > + int node = virtio_crypto_get_current_node(); > > > > + struct virtio_crypto *vcrypto = > > > > + virtcrypto_get_dev_node(node); > > > > + if (!vcrypto) { > > > > + vcrypto = virtcrypto_devmgr_get_first(); > > > > Is this the standard way to do this? How does this work with > > multiple crypto devices (e.g. with different capabilities)? > > > Actually there is a simple schedule algorithms in virtcrypto_get_dev_node(), > which return the device used fewest on the node. > > If we don't find a device in the node, select the first on as default. > But I forgot to check the first devices whether the device has started here. > Oh, the virtcrypto_get_dev_node() had done this work, the calling of virtcrypto_devmgr_get_first() here is superfluous. Will remove it. Regards, -Gonglei