mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 14:53:58 -04:00
crypto: virtio - support crypto engine framework
crypto engine was introduced since 'commit 735d37b542 ("crypto: engine
- Introduce the block request crypto engine framework")' which uses work
queue to realize the asynchronous processing for ablk_cipher and ahash.
For virtio-crypto device, I register an engine for each
data virtqueue so that we can use the capability of
multiple data queues in future.
Cc: Baolin Wang <baolin.wang@linaro.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
committed by
Herbert Xu
parent
1043c51468
commit
d79b5d0bbf
@@ -25,7 +25,7 @@
|
||||
#include "virtio_crypto_common.h"
|
||||
|
||||
|
||||
static void
|
||||
void
|
||||
virtcrypto_clear_request(struct virtio_crypto_request *vc_req)
|
||||
{
|
||||
if (vc_req) {
|
||||
@@ -66,12 +66,12 @@ static void virtcrypto_dataq_callback(struct virtqueue *vq)
|
||||
break;
|
||||
}
|
||||
ablk_req = vc_req->ablkcipher_req;
|
||||
virtcrypto_clear_request(vc_req);
|
||||
|
||||
spin_unlock_irqrestore(
|
||||
&vcrypto->data_vq[qid].lock, flags);
|
||||
/* Finish the encrypt or decrypt process */
|
||||
ablk_req->base.complete(&ablk_req->base, error);
|
||||
virtio_crypto_ablkcipher_finalize_req(vc_req,
|
||||
ablk_req, error);
|
||||
spin_lock_irqsave(
|
||||
&vcrypto->data_vq[qid].lock, flags);
|
||||
}
|
||||
@@ -87,6 +87,7 @@ static int virtcrypto_find_vqs(struct virtio_crypto *vi)
|
||||
int ret = -ENOMEM;
|
||||
int i, total_vqs;
|
||||
const char **names;
|
||||
struct device *dev = &vi->vdev->dev;
|
||||
|
||||
/*
|
||||
* We expect 1 data virtqueue, followed by
|
||||
@@ -128,6 +129,15 @@ static int virtcrypto_find_vqs(struct virtio_crypto *vi)
|
||||
for (i = 0; i < vi->max_data_queues; i++) {
|
||||
spin_lock_init(&vi->data_vq[i].lock);
|
||||
vi->data_vq[i].vq = vqs[i];
|
||||
/* Initialize crypto engine */
|
||||
vi->data_vq[i].engine = crypto_engine_alloc_init(dev, 1);
|
||||
if (!vi->data_vq[i].engine) {
|
||||
ret = -ENOMEM;
|
||||
goto err_engine;
|
||||
}
|
||||
|
||||
vi->data_vq[i].engine->cipher_one_request =
|
||||
virtio_crypto_ablkcipher_crypt_req;
|
||||
}
|
||||
|
||||
kfree(names);
|
||||
@@ -136,6 +146,7 @@ static int virtcrypto_find_vqs(struct virtio_crypto *vi)
|
||||
|
||||
return 0;
|
||||
|
||||
err_engine:
|
||||
err_find:
|
||||
kfree(names);
|
||||
err_names:
|
||||
@@ -269,6 +280,38 @@ static int virtcrypto_update_status(struct virtio_crypto *vcrypto)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int virtcrypto_start_crypto_engines(struct virtio_crypto *vcrypto)
|
||||
{
|
||||
int32_t i;
|
||||
int ret;
|
||||
|
||||
for (i = 0; i < vcrypto->max_data_queues; i++) {
|
||||
if (vcrypto->data_vq[i].engine) {
|
||||
ret = crypto_engine_start(vcrypto->data_vq[i].engine);
|
||||
if (ret)
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
while (--i >= 0)
|
||||
if (vcrypto->data_vq[i].engine)
|
||||
crypto_engine_exit(vcrypto->data_vq[i].engine);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void virtcrypto_clear_crypto_engines(struct virtio_crypto *vcrypto)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < vcrypto->max_data_queues; i++)
|
||||
if (vcrypto->data_vq[i].engine)
|
||||
crypto_engine_exit(vcrypto->data_vq[i].engine);
|
||||
}
|
||||
|
||||
static void virtcrypto_del_vqs(struct virtio_crypto *vcrypto)
|
||||
{
|
||||
struct virtio_device *vdev = vcrypto->vdev;
|
||||
@@ -355,14 +398,21 @@ static int virtcrypto_probe(struct virtio_device *vdev)
|
||||
dev_err(&vdev->dev, "Failed to initialize vqs.\n");
|
||||
goto free_dev;
|
||||
}
|
||||
|
||||
err = virtcrypto_start_crypto_engines(vcrypto);
|
||||
if (err)
|
||||
goto free_vqs;
|
||||
|
||||
virtio_device_ready(vdev);
|
||||
|
||||
err = virtcrypto_update_status(vcrypto);
|
||||
if (err)
|
||||
goto free_vqs;
|
||||
goto free_engines;
|
||||
|
||||
return 0;
|
||||
|
||||
free_engines:
|
||||
virtcrypto_clear_crypto_engines(vcrypto);
|
||||
free_vqs:
|
||||
vcrypto->vdev->config->reset(vdev);
|
||||
virtcrypto_del_vqs(vcrypto);
|
||||
@@ -398,6 +448,7 @@ static void virtcrypto_remove(struct virtio_device *vdev)
|
||||
virtcrypto_dev_stop(vcrypto);
|
||||
vdev->config->reset(vdev);
|
||||
virtcrypto_free_unused_reqs(vcrypto);
|
||||
virtcrypto_clear_crypto_engines(vcrypto);
|
||||
virtcrypto_del_vqs(vcrypto);
|
||||
virtcrypto_devmgr_rm_dev(vcrypto);
|
||||
kfree(vcrypto);
|
||||
@@ -420,6 +471,7 @@ static int virtcrypto_freeze(struct virtio_device *vdev)
|
||||
if (virtcrypto_dev_started(vcrypto))
|
||||
virtcrypto_dev_stop(vcrypto);
|
||||
|
||||
virtcrypto_clear_crypto_engines(vcrypto);
|
||||
virtcrypto_del_vqs(vcrypto);
|
||||
return 0;
|
||||
}
|
||||
@@ -433,14 +485,26 @@ static int virtcrypto_restore(struct virtio_device *vdev)
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = virtcrypto_start_crypto_engines(vcrypto);
|
||||
if (err)
|
||||
goto free_vqs;
|
||||
|
||||
virtio_device_ready(vdev);
|
||||
|
||||
err = virtcrypto_dev_start(vcrypto);
|
||||
if (err) {
|
||||
dev_err(&vdev->dev, "Failed to start virtio crypto device.\n");
|
||||
return -EFAULT;
|
||||
goto free_engines;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
free_engines:
|
||||
virtcrypto_clear_crypto_engines(vcrypto);
|
||||
free_vqs:
|
||||
vcrypto->vdev->config->reset(vdev);
|
||||
virtcrypto_del_vqs(vcrypto);
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user