diff mbox series

[v4,5/5] cryptodev-vhost-user: depend on CONFIG_VHOST_CRYPTO and CONFIG_VHOST_USER

Message ID 97c7a886a8569b785d9fec7d4d6b7c182a6b8421.1516277913.git.arei.gonglei@huawei.com
State New
Headers show
Series cryptodev: add vhost support | expand

Commit Message

Zhoujian (jay) Jan. 18, 2018, 12:25 p.m. UTC
From: Gonglei <arei.gonglei@huawei.com>

Signed-off-by: Jay Zhou <jianjay.zhou@huawei.com>
---
 backends/Makefile.objs     |  4 +++-
 backends/cryptodev-vhost.c | 57 +++++++++++++++++++++++++++++++++++++++++++---
 configure                  | 15 ++++++++++++
 vl.c                       |  2 ++
 4 files changed, 74 insertions(+), 4 deletions(-)

Comments

Michael S. Tsirkin Jan. 18, 2018, 8:49 p.m. UTC | #1
On Thu, Jan 18, 2018 at 08:25:36PM +0800, Jay Zhou wrote:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> Signed-off-by: Jay Zhou <jianjay.zhou@huawei.com>

Pls squash with the previous patch.

> ---
>  backends/Makefile.objs     |  4 +++-
>  backends/cryptodev-vhost.c | 57 +++++++++++++++++++++++++++++++++++++++++++---
>  configure                  | 15 ++++++++++++
>  vl.c                       |  2 ++
>  4 files changed, 74 insertions(+), 4 deletions(-)
> 
> diff --git a/backends/Makefile.objs b/backends/Makefile.objs
> index 9e1fb76..ea4f630 100644
> --- a/backends/Makefile.objs
> +++ b/backends/Makefile.objs
> @@ -10,5 +10,7 @@ common-obj-y += cryptodev.o
>  common-obj-y += cryptodev-builtin.o
>  
>  ifeq ($(CONFIG_VIRTIO),y)
> -common-obj-$(CONFIG_LINUX) += cryptodev-vhost.o cryptodev-vhost-user.o
> +common-obj-$(CONFIG_LINUX) += cryptodev-vhost.o
> +common-obj-$(call land,$(CONFIG_VHOST_CRYPTO),$(CONFIG_VHOST_USER)) += \
> +    cryptodev-vhost-user.o
>  endif
> diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c
> index 830fb53..ad1f415 100644
> --- a/backends/cryptodev-vhost.c
> +++ b/backends/cryptodev-vhost.c
> @@ -23,14 +23,18 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "hw/virtio/virtio-bus.h"
> +#include "sysemu/cryptodev-vhost.h"
> +
> +#ifdef CONFIG_VHOST_CRYPTO
>  #include "qapi/error.h"
>  #include "qapi/qmp/qerror.h"
>  #include "qemu/error-report.h"
> -#include "sysemu/cryptodev-vhost.h"
>  #include "hw/virtio/virtio-crypto.h"
> -#include "hw/virtio/virtio-bus.h"
> -#include "sysemu/cryptodev-vhost-user.h"
>  
> +#ifdef CONFIG_VHOST_USER
> +#include "sysemu/cryptodev-vhost-user.h"
> +#endif
>  
>  uint64_t
>  cryptodev_vhost_get_max_queues(
> @@ -123,9 +127,11 @@ cryptodev_get_vhost(CryptoDevBackendClient *cc,
>      }
>  
>      switch (cc->type) {
> +#ifdef CONFIG_VHOST_USER
>      case CRYPTODEV_BACKEND_TYPE_VHOST_USER:
>          vhost_crypto = cryptodev_vhost_user_get_vhost(cc, b, queue);
>          break;
> +#endif
>      default:
>          break;
>      }
> @@ -295,3 +301,48 @@ bool cryptodev_vhost_virtqueue_pending(VirtIODevice *dev,
>  
>      return vhost_virtqueue_pending(&vhost_crypto->dev, idx);
>  }
> +
> +#else
> +uint64_t
> +cryptodev_vhost_get_max_queues(CryptoDevBackendVhost *crypto)
> +{
> +    return 0;
> +}
> +
> +void cryptodev_vhost_cleanup(CryptoDevBackendVhost *crypto)
> +{
> +}
> +
> +struct CryptoDevBackendVhost *
> +cryptodev_vhost_init(CryptoDevBackendVhostOptions *options)
> +{
> +    return NULL;
> +}
> +
> +CryptoDevBackendVhost *
> +cryptodev_get_vhost(CryptoDevBackendClient *cc, CryptoDevBackend *b,
> +                    uint16_t queue)
> +{
> +    return NULL;
> +}
> +
> +int cryptodev_vhost_start(VirtIODevice *dev, int total_queues)
> +{
> +    return -1;
> +}
> +
> +void cryptodev_vhost_stop(VirtIODevice *dev, int total_queues)
> +{
> +}
> +
> +void cryptodev_vhost_virtqueue_mask(VirtIODevice *dev, int queue,
> +                                    int idx, bool mask)
> +{
> +}
> +
> +bool cryptodev_vhost_virtqueue_pending(VirtIODevice *dev,
> +                                       int queue, int idx)
> +{
> +    return false;
> +}
> +#endif
> diff --git a/configure b/configure
> index b272a03..e4cece3 100755
> --- a/configure
> +++ b/configure
> @@ -332,6 +332,7 @@ xfs=""
>  tcg="yes"
>  
>  vhost_net="no"
> +vhost_crypto="no"
>  vhost_scsi="no"
>  vhost_vsock="no"
>  vhost_user=""
> @@ -801,6 +802,7 @@ Linux)
>    linux_user="yes"
>    kvm="yes"
>    vhost_net="yes"
> +  vhost_crypto="yes"
>    vhost_scsi="yes"
>    vhost_vsock="yes"
>    QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QEMU_INCLUDES"
> @@ -1163,6 +1165,14 @@ for opt do
>    ;;
>    --enable-vhost-net) vhost_net="yes"
>    ;;
> +  --disable-vhost-crypto) vhost_crypto="no"
> +  ;;
> +  --enable-vhost-crypto)
> +      vhost_crypto="yes"
> +      if test "$mingw32" = "yes"; then
> +          error_exit "vhost-crypto isn't available on win32"
> +      fi
> +  ;;
>    --disable-vhost-scsi) vhost_scsi="no"
>    ;;
>    --enable-vhost-scsi) vhost_scsi="yes"
> @@ -1555,6 +1565,7 @@ disabled with --disable-FEATURE, default is enabled if available:
>    cap-ng          libcap-ng support
>    attr            attr and xattr support
>    vhost-net       vhost-net acceleration support
> +  vhost-crypto    vhost-crypto acceleration support
>    spice           spice
>    rbd             rados block device (rbd)
>    libiscsi        iscsi support
> @@ -5579,6 +5590,7 @@ echo "madvise           $madvise"
>  echo "posix_madvise     $posix_madvise"
>  echo "libcap-ng support $cap_ng"
>  echo "vhost-net support $vhost_net"
> +echo "vhost-crypto support $vhost_crypto"
>  echo "vhost-scsi support $vhost_scsi"
>  echo "vhost-vsock support $vhost_vsock"
>  echo "vhost-user support $vhost_user"
> @@ -6640,6 +6652,9 @@ if supported_kvm_target $target; then
>              echo "CONFIG_VHOST_USER_NET_TEST_$target_name=y" >> $config_host_mak
>          fi
>      fi
> +    if test "$vhost_crypto" = "yes"; then
> +        echo "CONFIG_VHOST_CRYPTO=y" >> $config_target_mak
> +    fi
>  fi
>  if supported_hax_target $target; then
>      echo "CONFIG_HAX=y" >> $config_target_mak
> diff --git a/vl.c b/vl.c
> index 3e9d86f..9f9727d 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2867,9 +2867,11 @@ static bool object_create_initial(const char *type)
>          return false;
>      }
>  
> +#if defined(CONFIG_VHOST_CRYPTO) && defined(CONFIG_VHOST_USER)
>      if (g_str_equal(type, "cryptodev-vhost-user")) {
>          return false;
>      }
> +#endif
>  
>      /*
>       * return false for concrete netfilters since
> -- 
> 1.8.3.1
>
diff mbox series

Patch

diff --git a/backends/Makefile.objs b/backends/Makefile.objs
index 9e1fb76..ea4f630 100644
--- a/backends/Makefile.objs
+++ b/backends/Makefile.objs
@@ -10,5 +10,7 @@  common-obj-y += cryptodev.o
 common-obj-y += cryptodev-builtin.o
 
 ifeq ($(CONFIG_VIRTIO),y)
-common-obj-$(CONFIG_LINUX) += cryptodev-vhost.o cryptodev-vhost-user.o
+common-obj-$(CONFIG_LINUX) += cryptodev-vhost.o
+common-obj-$(call land,$(CONFIG_VHOST_CRYPTO),$(CONFIG_VHOST_USER)) += \
+    cryptodev-vhost-user.o
 endif
diff --git a/backends/cryptodev-vhost.c b/backends/cryptodev-vhost.c
index 830fb53..ad1f415 100644
--- a/backends/cryptodev-vhost.c
+++ b/backends/cryptodev-vhost.c
@@ -23,14 +23,18 @@ 
  */
 
 #include "qemu/osdep.h"
+#include "hw/virtio/virtio-bus.h"
+#include "sysemu/cryptodev-vhost.h"
+
+#ifdef CONFIG_VHOST_CRYPTO
 #include "qapi/error.h"
 #include "qapi/qmp/qerror.h"
 #include "qemu/error-report.h"
-#include "sysemu/cryptodev-vhost.h"
 #include "hw/virtio/virtio-crypto.h"
-#include "hw/virtio/virtio-bus.h"
-#include "sysemu/cryptodev-vhost-user.h"
 
+#ifdef CONFIG_VHOST_USER
+#include "sysemu/cryptodev-vhost-user.h"
+#endif
 
 uint64_t
 cryptodev_vhost_get_max_queues(
@@ -123,9 +127,11 @@  cryptodev_get_vhost(CryptoDevBackendClient *cc,
     }
 
     switch (cc->type) {
+#ifdef CONFIG_VHOST_USER
     case CRYPTODEV_BACKEND_TYPE_VHOST_USER:
         vhost_crypto = cryptodev_vhost_user_get_vhost(cc, b, queue);
         break;
+#endif
     default:
         break;
     }
@@ -295,3 +301,48 @@  bool cryptodev_vhost_virtqueue_pending(VirtIODevice *dev,
 
     return vhost_virtqueue_pending(&vhost_crypto->dev, idx);
 }
+
+#else
+uint64_t
+cryptodev_vhost_get_max_queues(CryptoDevBackendVhost *crypto)
+{
+    return 0;
+}
+
+void cryptodev_vhost_cleanup(CryptoDevBackendVhost *crypto)
+{
+}
+
+struct CryptoDevBackendVhost *
+cryptodev_vhost_init(CryptoDevBackendVhostOptions *options)
+{
+    return NULL;
+}
+
+CryptoDevBackendVhost *
+cryptodev_get_vhost(CryptoDevBackendClient *cc, CryptoDevBackend *b,
+                    uint16_t queue)
+{
+    return NULL;
+}
+
+int cryptodev_vhost_start(VirtIODevice *dev, int total_queues)
+{
+    return -1;
+}
+
+void cryptodev_vhost_stop(VirtIODevice *dev, int total_queues)
+{
+}
+
+void cryptodev_vhost_virtqueue_mask(VirtIODevice *dev, int queue,
+                                    int idx, bool mask)
+{
+}
+
+bool cryptodev_vhost_virtqueue_pending(VirtIODevice *dev,
+                                       int queue, int idx)
+{
+    return false;
+}
+#endif
diff --git a/configure b/configure
index b272a03..e4cece3 100755
--- a/configure
+++ b/configure
@@ -332,6 +332,7 @@  xfs=""
 tcg="yes"
 
 vhost_net="no"
+vhost_crypto="no"
 vhost_scsi="no"
 vhost_vsock="no"
 vhost_user=""
@@ -801,6 +802,7 @@  Linux)
   linux_user="yes"
   kvm="yes"
   vhost_net="yes"
+  vhost_crypto="yes"
   vhost_scsi="yes"
   vhost_vsock="yes"
   QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QEMU_INCLUDES"
@@ -1163,6 +1165,14 @@  for opt do
   ;;
   --enable-vhost-net) vhost_net="yes"
   ;;
+  --disable-vhost-crypto) vhost_crypto="no"
+  ;;
+  --enable-vhost-crypto)
+      vhost_crypto="yes"
+      if test "$mingw32" = "yes"; then
+          error_exit "vhost-crypto isn't available on win32"
+      fi
+  ;;
   --disable-vhost-scsi) vhost_scsi="no"
   ;;
   --enable-vhost-scsi) vhost_scsi="yes"
@@ -1555,6 +1565,7 @@  disabled with --disable-FEATURE, default is enabled if available:
   cap-ng          libcap-ng support
   attr            attr and xattr support
   vhost-net       vhost-net acceleration support
+  vhost-crypto    vhost-crypto acceleration support
   spice           spice
   rbd             rados block device (rbd)
   libiscsi        iscsi support
@@ -5579,6 +5590,7 @@  echo "madvise           $madvise"
 echo "posix_madvise     $posix_madvise"
 echo "libcap-ng support $cap_ng"
 echo "vhost-net support $vhost_net"
+echo "vhost-crypto support $vhost_crypto"
 echo "vhost-scsi support $vhost_scsi"
 echo "vhost-vsock support $vhost_vsock"
 echo "vhost-user support $vhost_user"
@@ -6640,6 +6652,9 @@  if supported_kvm_target $target; then
             echo "CONFIG_VHOST_USER_NET_TEST_$target_name=y" >> $config_host_mak
         fi
     fi
+    if test "$vhost_crypto" = "yes"; then
+        echo "CONFIG_VHOST_CRYPTO=y" >> $config_target_mak
+    fi
 fi
 if supported_hax_target $target; then
     echo "CONFIG_HAX=y" >> $config_target_mak
diff --git a/vl.c b/vl.c
index 3e9d86f..9f9727d 100644
--- a/vl.c
+++ b/vl.c
@@ -2867,9 +2867,11 @@  static bool object_create_initial(const char *type)
         return false;
     }
 
+#if defined(CONFIG_VHOST_CRYPTO) && defined(CONFIG_VHOST_USER)
     if (g_str_equal(type, "cryptodev-vhost-user")) {
         return false;
     }
+#endif
 
     /*
      * return false for concrete netfilters since