From: zhenwei pi <pizhenwei@bytedance.com>
To: "Gonglei (Arei)" <arei.gonglei@huawei.com>
Cc: "jasowang@redhat.com" <jasowang@redhat.com>,
"mst@redhat.com" <mst@redhat.com>,
"virtualization@lists.linux-foundation.org"
<virtualization@lists.linux-foundation.org>,
"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"helei.sig11@bytedance.com" <helei.sig11@bytedance.com>,
"herbert@gondor.apana.org.au" <herbert@gondor.apana.org.au>,
kernel test robot <lkp@intel.com>
Subject: Re: [PATCH v2 3/3] virtio-crypto: implement RSA algorithm
Date: Wed, 23 Feb 2022 18:17:21 +0800 [thread overview]
Message-ID: <bc2bbc3b-8a34-2f09-41f5-60f1568a6bef@bytedance.com> (raw)
In-Reply-To: <8ef2f660-bd84-de70-1539-402c73795dfe@bytedance.com>
On 2/18/22 11:12 AM, zhenwei pi wrote:
>>> +void virtio_crypto_akcipher_algs_unregister(struct virtio_crypto
>>> +*vcrypto) {
>>> + int i = 0;
>>> +
>>> + mutex_lock(&algs_lock);
>>> +
>>> + for (i = 0; i < ARRAY_SIZE(virtio_crypto_akcipher_algs); i++) {
>>> + uint32_t service = virtio_crypto_akcipher_algs[i].service;
>>> + uint32_t algonum = virtio_crypto_akcipher_algs[i].algonum;
>>> +
>>> + if (virtio_crypto_akcipher_algs[i].active_devs == 0 ||
>>> + !virtcrypto_algo_is_supported(vcrypto, service, algonum))
>>> + continue;
>>> +
>>> + if (virtio_crypto_akcipher_algs[i].active_devs == 1)
>>> +
>>> crypto_unregister_akcipher(&virtio_crypto_akcipher_algs[i].algo);
>>> +
>>> + virtio_crypto_akcipher_algs[i].active_devs--;
>>> + }
>>> +
>>> + mutex_unlock(&algs_lock);
>>> +}
>>
>> Why don't you reuse the virtio_crypto_algs_register/unregister functions?
>> The current code is too repetitive. Maybe we don't need create the new
>> file virtio_crypto_akcipher_algo.c
>> because we had virtio_crypto_algs.c which includes all algorithms.
>>
>
> Yes, this looks similar to virtio_crypto_algs_register/unregister.
>
> Let's look at the difference:
> struct virtio_crypto_akcipher_algo {
> uint32_t algonum;
> uint32_t service;
> unsigned int active_devs;
> struct akcipher_alg algo;
> };
>
> struct virtio_crypto_algo {
> uint32_t algonum;
> uint32_t service;
> unsigned int active_devs;
> struct skcipher_alg algo; /* akcipher_alg VS skcipher_alg */
> };
>
> If reusing virtio_crypto_algs_register/unregister, we need to modify the
> data structure like this:
> struct virtio_crypto_akcipher_algo {
> uint32_t algonum;
> uint32_t service; /* use service to distinguish
> akcipher/skcipher */
> unsigned int active_devs;
> union {
> struct skcipher_alg skcipher;
> struct akcipher_alg akcipher;
> } alg;
> };
>
> int virtio_crypto_akcipher_algs_register(struct virtio_crypto *vcrypto)
> {
> ...
> for (i = 0; i < ARRAY_SIZE(virtio_crypto_akcipher_algs); i++) {
> uint32_t service = virtio_crypto_akcipher_algs[i].service;
> ...
> /* test service type then call
> crypto_register_akcipher/crypto_register_skcipher */
> if (service == VIRTIO_CRYPTO_SERVICE_AKCIPHER)
>
> crypto_register_akcipher(&virtio_crypto_akcipher_algs[i].algo.akcipher);
> else
>
> crypto_register_skcipher(&virtio_crypto_skcipher_algs[i].algo.skcipher);
> ...
> }
> ...
> }
>
> Also test service type and call
> crypto_unregister_skcipher/crypto_unregister_akcipher.
>
> This gets unclear from current v2 version.
>
> On the other hand, the kernel side prefers to separate skcipher and
> akcipher(separated header files and implementations).
>
Hi, Lei
I also take a look at other crypto drivers at qat/ccp/hisilicon, they
separate akcipher/skcipher algo. If you consider that reusing
virtio_crypto_algs_register/unregister seems better, I will try to merge
them into a single function.
--
zhenwei pi
next prev parent reply other threads:[~2022-02-23 10:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-11 8:41 [PATCH v2 0/3] Introduce akcipher service for virtio-crypto zhenwei pi
2022-02-11 8:41 ` [PATCH v2 1/3] virtio_crypto: Introduce VIRTIO_CRYPTO_NOSPC zhenwei pi
2022-02-11 8:41 ` [PATCH v2 2/3] virtio-crypto: introduce akcipher service zhenwei pi
2022-02-17 12:08 ` Gonglei (Arei)
2022-02-11 8:41 ` [PATCH v2 3/3] virtio-crypto: implement RSA algorithm zhenwei pi
2022-02-17 12:07 ` Gonglei (Arei)
2022-02-18 3:12 ` zhenwei pi
2022-02-23 10:17 ` zhenwei pi [this message]
2022-03-01 10:25 ` PING: " zhenwei pi
2022-03-01 11:13 ` Gonglei (Arei)
2022-02-16 1:36 ` PING: [PATCH v2 0/3] Introduce akcipher service for virtio-crypto zhenwei pi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bc2bbc3b-8a34-2f09-41f5-60f1568a6bef@bytedance.com \
--to=pizhenwei@bytedance.com \
--cc=arei.gonglei@huawei.com \
--cc=helei.sig11@bytedance.com \
--cc=herbert@gondor.apana.org.au \
--cc=jasowang@redhat.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=mst@redhat.com \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®