[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v9 11/12] virtio-crypto: using bh to handle dataq's
From: |
Gonglei |
Subject: |
[Qemu-devel] [PATCH v9 11/12] virtio-crypto: using bh to handle dataq's requests |
Date: |
Thu, 20 Oct 2016 19:45:56 +0800 |
Make crypto operations are executed asynchronously,
so that other QEMU threads and monitor couldn't
be blocked at the virtqueue handling context.
Signed-off-by: Gonglei <address@hidden>
---
hw/virtio/virtio-crypto.c | 55 +++++++++++++++++++++++++++++++++++++--
include/hw/virtio/virtio-crypto.h | 8 +++++-
2 files changed, 60 insertions(+), 3 deletions(-)
diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 7fe1128..47a25cd 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -667,6 +667,41 @@ static void virtio_crypto_handle_dataq(VirtIODevice *vdev,
VirtQueue *vq)
}
}
+static void virtio_crypto_dataq_bh(void *opaque)
+{
+ VirtIOCryptoQueue *q = opaque;
+ VirtIOCrypto *vcrypto = q->vcrypto;
+ VirtIODevice *vdev = VIRTIO_DEVICE(vcrypto);
+
+ /* This happens when device was stopped but BH wasn't. */
+ if (!vdev->vm_running) {
+ return;
+ }
+
+ /* Just in case the driver is not ready on more */
+ if (unlikely(!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK))) {
+ return;
+ }
+
+ virtio_crypto_handle_dataq(vdev, q->dataq);
+ virtio_queue_set_notification(q->dataq, 1);
+}
+
+static void
+virtio_crypto_handle_dataq_bh(VirtIODevice *vdev, VirtQueue *vq)
+{
+ VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev);
+ VirtIOCryptoQueue *q =
+ &vcrypto->vqs[virtio_crypto_vq2q(virtio_get_queue_index(vq))];
+
+ /* This happens when device was stopped but VCPU wasn't. */
+ if (!vdev->vm_running) {
+ return;
+ }
+ virtio_queue_set_notification(vq, 0);
+ qemu_bh_schedule(q->dataq_bh);
+}
+
static uint64_t virtio_crypto_get_features(VirtIODevice *vdev,
uint64_t features,
Error **errp)
@@ -724,9 +759,13 @@ static void virtio_crypto_device_realize(DeviceState *dev,
Error **errp)
virtio_init(vdev, "virtio-crypto", VIRTIO_ID_CRYPTO, vcrypto->config_size);
vcrypto->curr_queues = 1;
-
+ vcrypto->vqs = g_malloc0(sizeof(VirtIOCryptoQueue) * vcrypto->max_queues);
for (i = 0; i < vcrypto->max_queues; i++) {
- virtio_add_queue(vdev, 1024, virtio_crypto_handle_dataq);
+ vcrypto->vqs[i].dataq =
+ virtio_add_queue(vdev, 1024, virtio_crypto_handle_dataq_bh);
+ vcrypto->vqs[i].dataq_bh =
+ qemu_bh_new(virtio_crypto_dataq_bh, &vcrypto->vqs[i]);
+ vcrypto->vqs[i].vcrypto = vcrypto;
}
vcrypto->ctrl_vq = virtio_add_queue(vdev, 64, virtio_crypto_handle_ctrl);
@@ -742,6 +781,18 @@ static void virtio_crypto_device_realize(DeviceState *dev,
Error **errp)
static void virtio_crypto_device_unrealize(DeviceState *dev, Error **errp)
{
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+ VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(dev);
+ VirtIOCryptoQueue *q;
+ int i, max_queues;
+
+ max_queues = vcrypto->multiqueue ? vcrypto->max_queues : 1;
+ for (i = 0; i < max_queues; i++) {
+ virtio_del_queue(vdev, i);
+ q = &vcrypto->vqs[i];
+ qemu_bh_delete(q->dataq_bh);
+ }
+
+ g_free(vcrypto->vqs);
virtio_cleanup(vdev);
}
diff --git a/include/hw/virtio/virtio-crypto.h
b/include/hw/virtio/virtio-crypto.h
index 2628056..e15d694 100644
--- a/include/hw/virtio/virtio-crypto.h
+++ b/include/hw/virtio/virtio-crypto.h
@@ -69,11 +69,17 @@ typedef struct VirtIOCryptoReq {
} u;
} VirtIOCryptoReq;
+typedef struct VirtIOCryptoQueue {
+ VirtQueue *dataq;
+ QEMUBH *dataq_bh;
+ struct VirtIOCrypto *vcrypto;
+} VirtIOCryptoQueue;
+
typedef struct VirtIOCrypto {
VirtIODevice parent_obj;
VirtQueue *ctrl_vq;
-
+ VirtIOCryptoQueue *vqs;
VirtIOCryptoConf conf;
CryptoDevBackend *cryptodev;
--
1.8.3.1
- [Qemu-devel] [PATCH v9 00/12] virtio-crypto: introduce framework and device emulation, Gonglei, 2016/10/20
- [Qemu-devel] [PATCH v9 04/12] cryptodev: introduce a new cryptodev backend, Gonglei, 2016/10/20
- [Qemu-devel] [PATCH v9 11/12] virtio-crypto: using bh to handle dataq's requests,
Gonglei <=
- [Qemu-devel] [PATCH v9 03/12] virtio-crypto: introduce virtio_crypto.h, Gonglei, 2016/10/20
- [Qemu-devel] [PATCH v9 07/12] virtio-crypto: set capacity of algorithms supported, Gonglei, 2016/10/20
- [Qemu-devel] [PATCH v9 08/12] virtio-crypto: add control queue handler, Gonglei, 2016/10/20
- [Qemu-devel] [PATCH v9 01/12] cryptodev: introduce cryptodev backend interface, Gonglei, 2016/10/20
- [Qemu-devel] [PATCH v9 09/12] virtio-crypto: add data queue processing handler, Gonglei, 2016/10/20
- [Qemu-devel] [PATCH v9 02/12] cryptodev: add symmetric algorithm operation stuff, Gonglei, 2016/10/20
- [Qemu-devel] [PATCH v9 06/12] virtio-crypto-pci: add virtio crypto pci support, Gonglei, 2016/10/20
- [Qemu-devel] [PATCH v9 12/12] virtio-crypto: add myself as virtio-crypto and cryptodev backends maintainer, Gonglei, 2016/10/20