diff mbox

[v2,03/15] crypto: add cryptoLegacyHW stuff

Message ID 1473738741-220600-4-git-send-email-arei.gonglei@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

Gonglei (Arei) Sept. 13, 2016, 3:52 a.m. UTC
In previous patch, we define CryptoLegacyHWOptions in
qapi-schema.json. we introduce the new/delete funciton
about crypto legacy hardware device.

Note: legacy cryptographic device support muliple queue.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 crypto/crypto.c         | 74 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/crypto/crypto.h | 29 +++++++++++++++++++
 2 files changed, 103 insertions(+)

Comments

Daniel P. Berrangé Sept. 13, 2016, 9:22 a.m. UTC | #1
On Tue, Sep 13, 2016 at 11:52:09AM +0800, Gonglei wrote:
> In previous patch, we define CryptoLegacyHWOptions in
> qapi-schema.json. we introduce the new/delete funciton
> about crypto legacy hardware device.

Isn't virtio-crypto / cryptodev an entirely new specification ?
I'm surprised to be seeing something completely new described
as "legacy". Can you explain this in more detail.

Regards,
Daniel
Gonglei (Arei) Sept. 13, 2016, 10:05 a.m. UTC | #2
> -----Original Message-----

> From: Daniel P. Berrange [mailto:berrange@redhat.com]

> Sent: Tuesday, September 13, 2016 5:23 PM

> To: Gonglei (Arei)

> Cc: qemu-devel@nongnu.org; virtio-dev@lists.oasis-open.org; Huangpeng

> (Peter); Luonengjun; mst@redhat.com; stefanha@redhat.com;

> pbonzini@redhat.com; Huangweidong (C); mike.caraman@nxp.com;

> agraf@suse.de; xin.zeng@intel.com; Claudio Fontana; nmorey@kalray.eu;

> vincent.jardin@6wind.com

> Subject: Re: [PATCH v2 03/15] crypto: add cryptoLegacyHW stuff

> 

> On Tue, Sep 13, 2016 at 11:52:09AM +0800, Gonglei wrote:

> > In previous patch, we define CryptoLegacyHWOptions in

> > qapi-schema.json. we introduce the new/delete funciton

> > about crypto legacy hardware device.

> 

> Isn't virtio-crypto / cryptodev an entirely new specification ?


Yes, it's an complete new device.

> I'm surprised to be seeing something completely new described

> as "legacy". Can you explain this in more detail.

> 

Because there are two kind of crypto device, one is virtio-crypto which is
a virtual crypto device (And virtio-crypto device is a real crypto device seen by the guest). 
The other is cryptodev backend device.  I have no good idea to name the kind
of virtio-crypto device, so named to legacy crypto device refer to Net stuff.

Do you have any suggestion? Thanks!

Regards,
-Gonglei

> Regards,

> Daniel

> --

> |: http://berrange.com      -o-

> http://www.flickr.com/photos/dberrange/ :|

> |: http://libvirt.org              -o-

> http://virt-manager.org :|

> |: http://autobuild.org       -o-

> http://search.cpan.org/~danberr/ :|

> |: http://entangle-photo.org       -o-

> http://live.gnome.org/gtk-vnc :|
Daniel P. Berrangé Sept. 13, 2016, 10:08 a.m. UTC | #3
On Tue, Sep 13, 2016 at 10:05:01AM +0000, Gonglei (Arei) wrote:
> 
> 
> > -----Original Message-----
> > From: Daniel P. Berrange [mailto:berrange@redhat.com]
> > Sent: Tuesday, September 13, 2016 5:23 PM
> > To: Gonglei (Arei)
> > Cc: qemu-devel@nongnu.org; virtio-dev@lists.oasis-open.org; Huangpeng
> > (Peter); Luonengjun; mst@redhat.com; stefanha@redhat.com;
> > pbonzini@redhat.com; Huangweidong (C); mike.caraman@nxp.com;
> > agraf@suse.de; xin.zeng@intel.com; Claudio Fontana; nmorey@kalray.eu;
> > vincent.jardin@6wind.com
> > Subject: Re: [PATCH v2 03/15] crypto: add cryptoLegacyHW stuff
> > 
> > On Tue, Sep 13, 2016 at 11:52:09AM +0800, Gonglei wrote:
> > > In previous patch, we define CryptoLegacyHWOptions in
> > > qapi-schema.json. we introduce the new/delete funciton
> > > about crypto legacy hardware device.
> > 
> > Isn't virtio-crypto / cryptodev an entirely new specification ?
> 
> Yes, it's an complete new device.
> 
> > I'm surprised to be seeing something completely new described
> > as "legacy". Can you explain this in more detail.
> > 
> Because there are two kind of crypto device, one is virtio-crypto which is
> a virtual crypto device (And virtio-crypto device is a real crypto device seen by the guest). 
> The other is cryptodev backend device.  I have no good idea to name the kind
> of virtio-crypto device, so named to legacy crypto device refer to Net stuff.
> 
> Do you have any suggestion? Thanks!

How about just calling it 'Backend' instead of 'Legacy' then ?

Regards,
Daniel
Gonglei (Arei) Sept. 13, 2016, 10:14 a.m. UTC | #4
> -----Original Message-----

> From: Daniel P. Berrange [mailto:berrange@redhat.com]

> Sent: Tuesday, September 13, 2016 6:09 PM

> To: Gonglei (Arei)

> Subject: Re: [PATCH v2 03/15] crypto: add cryptoLegacyHW stuff

> 

> On Tue, Sep 13, 2016 at 10:05:01AM +0000, Gonglei (Arei) wrote:

> >

> >

> > > -----Original Message-----

> > > From: Daniel P. Berrange [mailto:berrange@redhat.com]

> > > Sent: Tuesday, September 13, 2016 5:23 PM

> > > To: Gonglei (Arei)

> > > Cc: qemu-devel@nongnu.org; virtio-dev@lists.oasis-open.org; Huangpeng

> > > (Peter); Luonengjun; mst@redhat.com; stefanha@redhat.com;

> > > pbonzini@redhat.com; Huangweidong (C); mike.caraman@nxp.com;

> > > agraf@suse.de; xin.zeng@intel.com; Claudio Fontana; nmorey@kalray.eu;

> > > vincent.jardin@6wind.com

> > > Subject: Re: [PATCH v2 03/15] crypto: add cryptoLegacyHW stuff

> > >

> > > On Tue, Sep 13, 2016 at 11:52:09AM +0800, Gonglei wrote:

> > > > In previous patch, we define CryptoLegacyHWOptions in

> > > > qapi-schema.json. we introduce the new/delete funciton

> > > > about crypto legacy hardware device.

> > >

> > > Isn't virtio-crypto / cryptodev an entirely new specification ?

> >

> > Yes, it's an complete new device.

> >

> > > I'm surprised to be seeing something completely new described

> > > as "legacy". Can you explain this in more detail.

> > >

> > Because there are two kind of crypto device, one is virtio-crypto which is

> > a virtual crypto device (And virtio-crypto device is a real crypto device seen by

> the guest).

> > The other is cryptodev backend device.  I have no good idea to name the

> kind

> > of virtio-crypto device, so named to legacy crypto device refer to Net stuff.

> >

> > Do you have any suggestion? Thanks!

> 

> How about just calling it 'Backend' instead of 'Legacy' then ?

> 

It sounds reasonable I think. Because the virtio specification usually say
The backend device.... and The frontend driver....

So let's:

s/cryptoLegacyHW/cryptoBackendHW/g


Regards,
-Gonglei
diff mbox

Patch

diff --git a/crypto/crypto.c b/crypto/crypto.c
index a0e4a34..3f760fd 100644
--- a/crypto/crypto.c
+++ b/crypto/crypto.c
@@ -197,3 +197,77 @@  int qemu_send_crypto_packet_async(CryptoClientState *sender,
     return qemu_crypto_queue_send(queue, flags, sender,
                                   opaque, sent_cb);
 }
+
+CryptoLegacyHWState *
+qemu_new_crypto_legacy_hw(CryptoClientInfo *info,
+                           CryptoLegacyHWConf *conf,
+                           const char *model,
+                           const char *name,
+                           void *opaque)
+{
+    CryptoLegacyHWState *crypto;
+    CryptoClientState **peers = conf->peers.ccs;
+    int i, queues = MAX(1, conf->peers.queues);
+
+    assert(info->type == CRYPTO_CLIENT_OPTIONS_KIND_LEGACY_HW);
+    assert(info->size >= sizeof(CryptoLegacyHWState));
+
+    crypto = g_malloc0(info->size + sizeof(CryptoClientState) * queues);
+    crypto->ccs = (void *)crypto + info->size;
+    crypto->opaque = opaque;
+    crypto->conf = conf;
+
+    for (i = 0; i < queues; i++) {
+        crypto_client_setup(&crypto->ccs[i], info, peers[i], model, name,
+                              NULL);
+        crypto->ccs[i].queue_index = i;
+        crypto->ccs[i].ready = true;
+    }
+
+    return crypto;
+}
+
+static void qemu_cleanup_crypto_client(CryptoClientState *cc)
+{
+    QTAILQ_REMOVE(&crypto_clients, cc, next);
+
+    if (cc->info->cleanup) {
+        cc->info->cleanup(cc);
+    }
+}
+
+static void qemu_free_crypto_client(CryptoClientState *cc)
+{
+    if (cc->incoming_queue) {
+        qemu_del_crypto_queue(cc->incoming_queue);
+    }
+    if (cc->peer) {
+        cc->peer->peer = NULL;
+    }
+    g_free(cc->model);
+    g_free(cc->name);
+
+    if (cc->destructor) {
+        cc->destructor(cc);
+    }
+}
+
+CryptoClientState *
+qemu_get_crypto_subqueue(CryptoLegacyHWState *crypto, int queue_index)
+{
+    return crypto->ccs + queue_index;
+}
+
+void qemu_del_crypto_legacy_hw(CryptoLegacyHWState *crypto)
+{
+    int i, queues = MAX(crypto->conf->peers.queues, 1);
+
+    for (i = queues - 1; i >= 0; i--) {
+        CryptoClientState *cc = qemu_get_crypto_subqueue(crypto, i);
+
+        qemu_cleanup_crypto_client(cc);
+        qemu_free_crypto_client(cc);
+    }
+
+    g_free(crypto);
+}
diff --git a/include/crypto/crypto.h b/include/crypto/crypto.h
index 46b3b9e..4f0efb7 100644
--- a/include/crypto/crypto.h
+++ b/include/crypto/crypto.h
@@ -31,6 +31,7 @@ 
 #include "qapi-types.h"
 #include "crypto/crypto-queue.h"
 
+#define MAX_CRYPTO_QUEUE_NUM  64
 
 typedef void (CryptoPoll)(CryptoClientState *, bool);
 typedef void (CryptoCleanup) (CryptoClientState *);
@@ -59,6 +60,24 @@  struct CryptoClientState {
     CryptoClientDestructor *destructor;
 };
 
+/* qdev crypto legacy hardware properties */
+
+typedef struct CryptoLegacyHWPeers {
+    CryptoClientState *ccs[MAX_CRYPTO_QUEUE_NUM];
+    int32_t queues;
+} CryptoLegacyHWPeers;
+
+typedef struct CryptoLegacyHWConf {
+    CryptoLegacyHWPeers peers;
+} CryptoLegacyHWConf;
+
+typedef struct CryptoLegacyHWState {
+    CryptoClientState *ccs;
+    void *opaque;
+    CryptoLegacyHWConf *conf;
+    bool peer_deleted;
+} CryptoLegacyHWState;
+
 int crypto_client_init(QemuOpts *opts, Error **errp);
 int crypto_init_clients(void);
 
@@ -74,5 +93,15 @@  int qemu_send_crypto_packet_async(CryptoClientState *sender,
                                 unsigned flags,
                                 void *opaque,
                                 CryptoPacketSent *sent_cb);
+CryptoLegacyHWState *
+qemu_new_crypto_legacy_hw(CryptoClientInfo *info,
+                           CryptoLegacyHWConf *conf,
+                           const char *model,
+                           const char *name,
+                           void *opaque);
+void qemu_del_crypto_legacy_hw(CryptoLegacyHWState *crypto);
+
+CryptoClientState *
+qemu_get_crypto_subqueue(CryptoLegacyHWState *crypto, int queue_index);
 
 #endif /* QCRYPTO_CRYPTO_H__ */