All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-2.9 0/3] cryptodev: prepare works for hotplug
@ 2016-12-05  3:27 Gonglei
  2016-12-05  3:27 ` [Qemu-devel] [PATCH for-2.9 1/3] cryptodev: introduce a new is_used property Gonglei
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Gonglei @ 2016-12-05  3:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, wu.wubin, longpeng2, Gonglei

The patch set make the cryptodev object can be hot plugging
in safety, and which are preparing works for virtio-crypto
device hotpulgging.

Gonglei (3):
  cryptodev: introduce a new is_used property
  cryptodev: wrap the ready flag
  virtio-crypto: avoid one cryptodev device is used by multiple virtio
    crypto devices

 backends/cryptodev-builtin.c |  4 ++++
 backends/cryptodev.c         | 34 ++++++++++++++++++++++++++++++----
 hw/virtio/virtio-crypto.c    | 22 +++++++++++++++++++---
 include/sysemu/cryptodev.h   | 42 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+), 7 deletions(-)

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH for-2.9 1/3] cryptodev: introduce a new is_used property
  2016-12-05  3:27 [Qemu-devel] [PATCH for-2.9 0/3] cryptodev: prepare works for hotplug Gonglei
@ 2016-12-05  3:27 ` Gonglei
  2016-12-05  3:27 ` [Qemu-devel] [PATCH for-2.9 2/3] cryptodev: wrap the ready flag Gonglei
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Gonglei @ 2016-12-05  3:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, wu.wubin, longpeng2, Gonglei

This property is used to Tag the cryptodev backend
is used by virtio-crypto or not. Making cryptodev
can't be hot unplugged when it's in use. Cleanup
resources when cryptodev is finalized.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 backends/cryptodev.c       | 19 +++++++++++++++++++
 hw/virtio/virtio-crypto.c  |  2 ++
 include/sysemu/cryptodev.h | 23 +++++++++++++++++++++++
 3 files changed, 44 insertions(+)

diff --git a/backends/cryptodev.c b/backends/cryptodev.c
index 4a49f97..6a66c27 100644
--- a/backends/cryptodev.c
+++ b/backends/cryptodev.c
@@ -197,6 +197,22 @@ out:
     error_propagate(errp, local_err);
 }
 
+void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used)
+{
+    backend->is_used = used;
+}
+
+bool cryptodev_backend_is_used(CryptoDevBackend *backend)
+{
+    return backend->is_used;
+}
+
+static bool
+cryptodev_backend_can_be_deleted(UserCreatable *uc, Error **errp)
+{
+    return !cryptodev_backend_is_used(CRYPTODEV_BACKEND(uc));
+}
+
 static void cryptodev_backend_instance_init(Object *obj)
 {
     object_property_add(obj, "queues", "int",
@@ -209,7 +225,9 @@ static void cryptodev_backend_instance_init(Object *obj)
 
 static void cryptodev_backend_finalize(Object *obj)
 {
+    CryptoDevBackend *backend = CRYPTODEV_BACKEND(obj);
 
+    cryptodev_backend_cleanup(backend, NULL);
 }
 
 static void
@@ -218,6 +236,7 @@ cryptodev_backend_class_init(ObjectClass *oc, void *data)
     UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
 
     ucc->complete = cryptodev_backend_complete;
+    ucc->can_be_deleted = cryptodev_backend_can_be_deleted;
 
     QTAILQ_INIT(&crypto_clients);
 }
diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 2f2467e..117f55a 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -799,6 +799,7 @@ static void virtio_crypto_device_realize(DeviceState *dev, Error **errp)
     }
 
     virtio_crypto_init_config(vdev);
+    cryptodev_backend_set_used(vcrypto->cryptodev, true);
 }
 
 static void virtio_crypto_device_unrealize(DeviceState *dev, Error **errp)
@@ -818,6 +819,7 @@ static void virtio_crypto_device_unrealize(DeviceState *dev, Error **errp)
     g_free(vcrypto->vqs);
 
     virtio_cleanup(vdev);
+    cryptodev_backend_set_used(vcrypto->cryptodev, false);
 }
 
 static const VMStateDescription vmstate_virtio_crypto = {
diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h
index 84526c0..461389d 100644
--- a/include/sysemu/cryptodev.h
+++ b/include/sysemu/cryptodev.h
@@ -202,6 +202,8 @@ struct CryptoDevBackend {
     Object parent_obj;
 
     bool ready;
+    /* Tag the cryptodev backend is used by virtio-crypto or not */
+    bool is_used;
     CryptoDevBackendConf conf;
 };
 
@@ -295,4 +297,25 @@ int cryptodev_backend_crypto_operation(
                  void *opaque,
                  uint32_t queue_index, Error **errp);
 
+/**
+ * cryptodev_backend_set_used:
+ * @backend: the cryptodev backend object
+ * @used: ture or false
+ *
+ * Set the cryptodev backend is used by virtio-crypto or not
+ */
+void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used);
+
+/**
+ * cryptodev_backend_is_used:
+ * @backend: the cryptodev backend object
+ *
+ * Return the status that the cryptodev backend is used
+ * by virtio-crypto or not
+ *
+ * Returns: true on used, or false on not used
+ */
+bool cryptodev_backend_is_used(CryptoDevBackend *backend);
+
+
 #endif /* CRYPTODEV_H */
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH for-2.9 2/3] cryptodev: wrap the ready flag
  2016-12-05  3:27 [Qemu-devel] [PATCH for-2.9 0/3] cryptodev: prepare works for hotplug Gonglei
  2016-12-05  3:27 ` [Qemu-devel] [PATCH for-2.9 1/3] cryptodev: introduce a new is_used property Gonglei
@ 2016-12-05  3:27 ` Gonglei
  2016-12-05  3:27 ` [Qemu-devel] [PATCH for-2.9 3/3] virtio-crypto: avoid one cryptodev device is used by multiple virtio crypto devices Gonglei
  2016-12-11  3:38 ` [Qemu-devel] [PATCH for-2.9 0/3] cryptodev: prepare works for hotplug Michael S. Tsirkin
  3 siblings, 0 replies; 6+ messages in thread
From: Gonglei @ 2016-12-05  3:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, wu.wubin, longpeng2, Gonglei

The ready flag should be set by the children of
cryptodev backend interface. Warp the setter/getter
functions for it.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 backends/cryptodev-builtin.c |  4 ++++
 backends/cryptodev.c         | 15 +++++++++++----
 hw/virtio/virtio-crypto.c    |  4 ++--
 include/sysemu/cryptodev.h   | 19 +++++++++++++++++++
 4 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/backends/cryptodev-builtin.c b/backends/cryptodev-builtin.c
index eda954b..7b90586 100644
--- a/backends/cryptodev-builtin.c
+++ b/backends/cryptodev-builtin.c
@@ -94,6 +94,8 @@ static void cryptodev_builtin_init(
     backend->conf.max_size = LONG_MAX - sizeof(CryptoDevBackendSymOpInfo);
     backend->conf.max_cipher_key_len = CRYPTODEV_BUITLIN_MAX_CIPHER_KEY_LEN;
     backend->conf.max_auth_key_len = CRYPTODEV_BUITLIN_MAX_AUTH_KEY_LEN;
+
+    cryptodev_backend_set_ready(backend, true);
 }
 
 static int
@@ -331,6 +333,8 @@ static void cryptodev_builtin_cleanup(
             backend->conf.peers.ccs[i] = NULL;
         }
     }
+
+    cryptodev_backend_set_ready(backend, false);
 }
 
 static void
diff --git a/backends/cryptodev.c b/backends/cryptodev.c
index 6a66c27..832f056 100644
--- a/backends/cryptodev.c
+++ b/backends/cryptodev.c
@@ -73,8 +73,6 @@ void cryptodev_backend_cleanup(
     if (bc->cleanup) {
         bc->cleanup(backend, errp);
     }
-
-    backend->ready = false;
 }
 
 int64_t cryptodev_backend_sym_create_session(
@@ -189,11 +187,10 @@ cryptodev_backend_complete(UserCreatable *uc, Error **errp)
             goto out;
         }
     }
-    backend->ready = true;
+
     return;
 
 out:
-    backend->ready = false;
     error_propagate(errp, local_err);
 }
 
@@ -207,6 +204,16 @@ bool cryptodev_backend_is_used(CryptoDevBackend *backend)
     return backend->is_used;
 }
 
+void cryptodev_backend_set_ready(CryptoDevBackend *backend, bool ready)
+{
+    backend->ready = ready;
+}
+
+bool cryptodev_backend_is_ready(CryptoDevBackend *backend)
+{
+    return backend->ready;
+}
+
 static bool
 cryptodev_backend_can_be_deleted(UserCreatable *uc, Error **errp)
 {
diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 117f55a..ffaac9d 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -732,7 +732,7 @@ static void virtio_crypto_reset(VirtIODevice *vdev)
     VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev);
     /* multiqueue is disabled by default */
     vcrypto->curr_queues = 1;
-    if (!vcrypto->cryptodev->ready) {
+    if (!cryptodev_backend_is_ready(vcrypto->cryptodev)) {
         vcrypto->status &= ~VIRTIO_CRYPTO_S_HW_READY;
     } else {
         vcrypto->status |= VIRTIO_CRYPTO_S_HW_READY;
@@ -792,7 +792,7 @@ static void virtio_crypto_device_realize(DeviceState *dev, Error **errp)
     }
 
     vcrypto->ctrl_vq = virtio_add_queue(vdev, 64, virtio_crypto_handle_ctrl);
-    if (!vcrypto->cryptodev->ready) {
+    if (!cryptodev_backend_is_ready(vcrypto->cryptodev)) {
         vcrypto->status &= ~VIRTIO_CRYPTO_S_HW_READY;
     } else {
         vcrypto->status |= VIRTIO_CRYPTO_S_HW_READY;
diff --git a/include/sysemu/cryptodev.h b/include/sysemu/cryptodev.h
index 461389d..a9d0d1e 100644
--- a/include/sysemu/cryptodev.h
+++ b/include/sysemu/cryptodev.h
@@ -317,5 +317,24 @@ void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used);
  */
 bool cryptodev_backend_is_used(CryptoDevBackend *backend);
 
+/**
+ * cryptodev_backend_set_ready:
+ * @backend: the cryptodev backend object
+ * @ready: ture or false
+ *
+ * Set the cryptodev backend is ready or not, which is called
+ * by the children of the cryptodev banckend interface.
+ */
+void cryptodev_backend_set_ready(CryptoDevBackend *backend, bool ready);
+
+/**
+ * cryptodev_backend_is_ready:
+ * @backend: the cryptodev backend object
+ *
+ * Return the status that the cryptodev backend is ready or not
+ *
+ * Returns: true on ready, or false on not ready
+ */
+bool cryptodev_backend_is_ready(CryptoDevBackend *backend);
 
 #endif /* CRYPTODEV_H */
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH for-2.9 3/3] virtio-crypto: avoid one cryptodev device is used by multiple virtio crypto devices
  2016-12-05  3:27 [Qemu-devel] [PATCH for-2.9 0/3] cryptodev: prepare works for hotplug Gonglei
  2016-12-05  3:27 ` [Qemu-devel] [PATCH for-2.9 1/3] cryptodev: introduce a new is_used property Gonglei
  2016-12-05  3:27 ` [Qemu-devel] [PATCH for-2.9 2/3] cryptodev: wrap the ready flag Gonglei
@ 2016-12-05  3:27 ` Gonglei
  2016-12-11  3:38 ` [Qemu-devel] [PATCH for-2.9 0/3] cryptodev: prepare works for hotplug Michael S. Tsirkin
  3 siblings, 0 replies; 6+ messages in thread
From: Gonglei @ 2016-12-05  3:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: mst, wu.wubin, longpeng2, Gonglei

Add the check condition for cryptodev device in order
to avoid one cryptodev device is used by multiple
virtio crypto devices.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/virtio/virtio-crypto.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index ffaac9d..4f11fee 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -877,6 +877,20 @@ static void virtio_crypto_class_init(ObjectClass *klass, void *data)
     vdc->reset = virtio_crypto_reset;
 }
 
+static void
+virtio_crypto_check_cryptodev_is_used(Object *obj, const char *name,
+                                      Object *val, Error **errp)
+{
+    if (cryptodev_backend_is_used(CRYPTODEV_BACKEND(val))) {
+        char *path = object_get_canonical_path_component(val);
+        error_setg(errp,
+            "can't use already used cryptodev backend: %s", path);
+        g_free(path);
+    } else {
+        qdev_prop_allow_set_link_before_realize(obj, name, val, errp);
+    }
+}
+
 static void virtio_crypto_instance_init(Object *obj)
 {
     VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(obj);
@@ -890,7 +904,7 @@ static void virtio_crypto_instance_init(Object *obj)
     object_property_add_link(obj, "cryptodev",
                              TYPE_CRYPTODEV_BACKEND,
                              (Object **)&vcrypto->conf.cryptodev,
-                             qdev_prop_allow_set_link_before_realize,
+                             virtio_crypto_check_cryptodev_is_used,
                              OBJ_PROP_LINK_UNREF_ON_RELEASE, NULL);
 }
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.9 0/3] cryptodev: prepare works for hotplug
  2016-12-05  3:27 [Qemu-devel] [PATCH for-2.9 0/3] cryptodev: prepare works for hotplug Gonglei
                   ` (2 preceding siblings ...)
  2016-12-05  3:27 ` [Qemu-devel] [PATCH for-2.9 3/3] virtio-crypto: avoid one cryptodev device is used by multiple virtio crypto devices Gonglei
@ 2016-12-11  3:38 ` Michael S. Tsirkin
  2016-12-12  3:16   ` Gonglei (Arei)
  3 siblings, 1 reply; 6+ messages in thread
From: Michael S. Tsirkin @ 2016-12-11  3:38 UTC (permalink / raw)
  To: Gonglei; +Cc: qemu-devel, wu.wubin, longpeng2

On Mon, Dec 05, 2016 at 11:27:09AM +0800, Gonglei wrote:
> The patch set make the cryptodev object can be hot plugging
> in safety, and which are preparing works for virtio-crypto
> device hotpulgging.


Thanks, pls remember to ping after 2.8 is out.

> Gonglei (3):
>   cryptodev: introduce a new is_used property
>   cryptodev: wrap the ready flag
>   virtio-crypto: avoid one cryptodev device is used by multiple virtio
>     crypto devices
> 
>  backends/cryptodev-builtin.c |  4 ++++
>  backends/cryptodev.c         | 34 ++++++++++++++++++++++++++++++----
>  hw/virtio/virtio-crypto.c    | 22 +++++++++++++++++++---
>  include/sysemu/cryptodev.h   | 42 ++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 95 insertions(+), 7 deletions(-)
> 
> -- 
> 1.8.3.1
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH for-2.9 0/3] cryptodev: prepare works for hotplug
  2016-12-11  3:38 ` [Qemu-devel] [PATCH for-2.9 0/3] cryptodev: prepare works for hotplug Michael S. Tsirkin
@ 2016-12-12  3:16   ` Gonglei (Arei)
  0 siblings, 0 replies; 6+ messages in thread
From: Gonglei (Arei) @ 2016-12-12  3:16 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: qemu-devel, Wubin (H), longpeng

>
> From: Michael S. Tsirkin [mailto:mst@redhat.com]
> Sent: Sunday, December 11, 2016 11:38 AM
> To: Gonglei (Arei)
> Cc: qemu-devel@nongnu.org; Wubin (H); longpeng
> Subject: Re: [PATCH for-2.9 0/3] cryptodev: prepare works for hotplug
> 
> On Mon, Dec 05, 2016 at 11:27:09AM +0800, Gonglei wrote:
> > The patch set make the cryptodev object can be hot plugging
> > in safety, and which are preparing works for virtio-crypto
> > device hotpulgging.
> 
> 
> Thanks, pls remember to ping after 2.8 is out.
> 
OK, the v2 will be posted with virtio-crypto device hotplugging function.


Regards,
-Gonglei

> > Gonglei (3):
> >   cryptodev: introduce a new is_used property
> >   cryptodev: wrap the ready flag
> >   virtio-crypto: avoid one cryptodev device is used by multiple virtio
> >     crypto devices
> >
> >  backends/cryptodev-builtin.c |  4 ++++
> >  backends/cryptodev.c         | 34
> ++++++++++++++++++++++++++++++----
> >  hw/virtio/virtio-crypto.c    | 22 +++++++++++++++++++---
> >  include/sysemu/cryptodev.h   | 42
> ++++++++++++++++++++++++++++++++++++++++++
> >  4 files changed, 95 insertions(+), 7 deletions(-)
> >
> > --
> > 1.8.3.1
> >

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-12-12  3:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-05  3:27 [Qemu-devel] [PATCH for-2.9 0/3] cryptodev: prepare works for hotplug Gonglei
2016-12-05  3:27 ` [Qemu-devel] [PATCH for-2.9 1/3] cryptodev: introduce a new is_used property Gonglei
2016-12-05  3:27 ` [Qemu-devel] [PATCH for-2.9 2/3] cryptodev: wrap the ready flag Gonglei
2016-12-05  3:27 ` [Qemu-devel] [PATCH for-2.9 3/3] virtio-crypto: avoid one cryptodev device is used by multiple virtio crypto devices Gonglei
2016-12-11  3:38 ` [Qemu-devel] [PATCH for-2.9 0/3] cryptodev: prepare works for hotplug Michael S. Tsirkin
2016-12-12  3:16   ` Gonglei (Arei)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.