Re: [RFC v3 6/8] vhost-backend: export the vhost backend helper

2020-06-16 Thread Cindy Lu
On Tue, Jun 16, 2020 at 4:17 PM Laurent Vivier  wrote:
>
> On 29/05/2020 16:06, Cindy Lu wrote:
> > export the helper then we can reuse some of them in vhost-vdpa
> >
> > Signed-off-by: Cindy Lu 
> > ---
> >  hw/virtio/vhost-backend.c | 34 ++-
> >  include/hw/virtio/vhost-backend.h | 28 +
> >  2 files changed, 48 insertions(+), 14 deletions(-)
> >
> > diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
> > index 48905383f8..42efb4967b 100644
> > --- a/hw/virtio/vhost-backend.c
> > +++ b/hw/virtio/vhost-backend.c
> > @@ -14,7 +14,7 @@
> >  #include "qemu/error-report.h"
> >  #include "qemu/main-loop.h"
> >  #include "standard-headers/linux/vhost_types.h"
> > -
> > +#include "hw/virtio/vhost-vdpa.h"
>
> You can't include this file because it is created in the next patch.
>
> >  #ifdef CONFIG_VHOST_KERNEL
> >  #include 
> >  #include 
> > @@ -22,10 +22,16 @@
> >  static int vhost_kernel_call(struct vhost_dev *dev, unsigned long int 
> > request,
> >   void *arg)
> >  {
> > -int fd = (uintptr_t) dev->opaque;
> > -
> > -assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL);
> > -
> > +int fd = -1;
> > +struct vhost_vdpa *v = NULL;
> > +if (dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL) {
> > +fd  = (uintptr_t) dev->opaque;
> > +}
> > +if (dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA) {
> > +v = dev->opaque;
> > +fd = v->device_fd;
> > +}
> > +assert(fd != -1);
>
> A switch would be cleaner:
>
> switch (dev->vhost_ops->backend_type) {
> case VHOST_BACKEND_TYPE_KERNEL:
> fd  = (uintptr_t)dev->opaque;
> break;
> case VHOST_BACKEND_TYPE_VDPA:
> fd = ((struct vhost_vdpa *)dev->opaque)->device_fd;
> break;
> default:
> g_assert_not_reached()
> }
>
> >  return ioctl(fd, request, arg);
> >  }
> >
>
Thanks Laurent , will fix this
> Thanks,
> Laurent
>




Re: [RFC v3 6/8] vhost-backend: export the vhost backend helper

2020-06-16 Thread Laurent Vivier
On 29/05/2020 16:06, Cindy Lu wrote:
> export the helper then we can reuse some of them in vhost-vdpa
> 
> Signed-off-by: Cindy Lu 
> ---
>  hw/virtio/vhost-backend.c | 34 ++-
>  include/hw/virtio/vhost-backend.h | 28 +
>  2 files changed, 48 insertions(+), 14 deletions(-)
> 
> diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
> index 48905383f8..42efb4967b 100644
> --- a/hw/virtio/vhost-backend.c
> +++ b/hw/virtio/vhost-backend.c
> @@ -14,7 +14,7 @@
>  #include "qemu/error-report.h"
>  #include "qemu/main-loop.h"
>  #include "standard-headers/linux/vhost_types.h"
> -
> +#include "hw/virtio/vhost-vdpa.h"

You can't include this file because it is created in the next patch.

>  #ifdef CONFIG_VHOST_KERNEL
>  #include 
>  #include 
> @@ -22,10 +22,16 @@
>  static int vhost_kernel_call(struct vhost_dev *dev, unsigned long int 
> request,
>   void *arg)
>  {
> -int fd = (uintptr_t) dev->opaque;
> -
> -assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL);
> -
> +int fd = -1;
> +struct vhost_vdpa *v = NULL;
> +if (dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL) {
> +fd  = (uintptr_t) dev->opaque;
> +}
> +if (dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA) {
> +v = dev->opaque;
> +fd = v->device_fd;
> +}
> +assert(fd != -1);

A switch would be cleaner:

switch (dev->vhost_ops->backend_type) {
case VHOST_BACKEND_TYPE_KERNEL:
fd  = (uintptr_t)dev->opaque;
break;
case VHOST_BACKEND_TYPE_VDPA:
fd = ((struct vhost_vdpa *)dev->opaque)->device_fd;
break;
default:
g_assert_not_reached()
}

>  return ioctl(fd, request, arg);
>  }
>  

Thanks,
Laurent




[RFC v3 6/8] vhost-backend: export the vhost backend helper

2020-05-29 Thread Cindy Lu
export the helper then we can reuse some of them in vhost-vdpa

Signed-off-by: Cindy Lu 
---
 hw/virtio/vhost-backend.c | 34 ++-
 include/hw/virtio/vhost-backend.h | 28 +
 2 files changed, 48 insertions(+), 14 deletions(-)

diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
index 48905383f8..42efb4967b 100644
--- a/hw/virtio/vhost-backend.c
+++ b/hw/virtio/vhost-backend.c
@@ -14,7 +14,7 @@
 #include "qemu/error-report.h"
 #include "qemu/main-loop.h"
 #include "standard-headers/linux/vhost_types.h"
-
+#include "hw/virtio/vhost-vdpa.h"
 #ifdef CONFIG_VHOST_KERNEL
 #include 
 #include 
@@ -22,10 +22,16 @@
 static int vhost_kernel_call(struct vhost_dev *dev, unsigned long int request,
  void *arg)
 {
-int fd = (uintptr_t) dev->opaque;
-
-assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL);
-
+int fd = -1;
+struct vhost_vdpa *v = NULL;
+if (dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_KERNEL) {
+fd  = (uintptr_t) dev->opaque;
+}
+if (dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA) {
+v = dev->opaque;
+fd = v->device_fd;
+}
+assert(fd != -1);
 return ioctl(fd, request, arg);
 }
 
@@ -89,7 +95,7 @@ static int vhost_kernel_scsi_get_abi_version(struct vhost_dev 
*dev, int *version
 return vhost_kernel_call(dev, VHOST_SCSI_GET_ABI_VERSION, version);
 }
 
-static int vhost_kernel_set_log_base(struct vhost_dev *dev, uint64_t base,
+int vhost_kernel_set_log_base(struct vhost_dev *dev, uint64_t base,
  struct vhost_log *log)
 {
 return vhost_kernel_call(dev, VHOST_SET_LOG_BASE, );
@@ -101,7 +107,7 @@ static int vhost_kernel_set_mem_table(struct vhost_dev *dev,
 return vhost_kernel_call(dev, VHOST_SET_MEM_TABLE, mem);
 }
 
-static int vhost_kernel_set_vring_addr(struct vhost_dev *dev,
+int vhost_kernel_set_vring_addr(struct vhost_dev *dev,
struct vhost_vring_addr *addr)
 {
 return vhost_kernel_call(dev, VHOST_SET_VRING_ADDR, addr);
@@ -113,31 +119,31 @@ static int vhost_kernel_set_vring_endian(struct vhost_dev 
*dev,
 return vhost_kernel_call(dev, VHOST_SET_VRING_ENDIAN, ring);
 }
 
-static int vhost_kernel_set_vring_num(struct vhost_dev *dev,
+int vhost_kernel_set_vring_num(struct vhost_dev *dev,
   struct vhost_vring_state *ring)
 {
 return vhost_kernel_call(dev, VHOST_SET_VRING_NUM, ring);
 }
 
-static int vhost_kernel_set_vring_base(struct vhost_dev *dev,
+int vhost_kernel_set_vring_base(struct vhost_dev *dev,
struct vhost_vring_state *ring)
 {
 return vhost_kernel_call(dev, VHOST_SET_VRING_BASE, ring);
 }
 
-static int vhost_kernel_get_vring_base(struct vhost_dev *dev,
+int vhost_kernel_get_vring_base(struct vhost_dev *dev,
struct vhost_vring_state *ring)
 {
 return vhost_kernel_call(dev, VHOST_GET_VRING_BASE, ring);
 }
 
-static int vhost_kernel_set_vring_kick(struct vhost_dev *dev,
+int vhost_kernel_set_vring_kick(struct vhost_dev *dev,
struct vhost_vring_file *file)
 {
 return vhost_kernel_call(dev, VHOST_SET_VRING_KICK, file);
 }
 
-static int vhost_kernel_set_vring_call(struct vhost_dev *dev,
+int vhost_kernel_set_vring_call(struct vhost_dev *dev,
struct vhost_vring_file *file)
 {
 return vhost_kernel_call(dev, VHOST_SET_VRING_CALL, file);
@@ -155,13 +161,13 @@ static int vhost_kernel_set_features(struct vhost_dev 
*dev,
 return vhost_kernel_call(dev, VHOST_SET_FEATURES, );
 }
 
-static int vhost_kernel_get_features(struct vhost_dev *dev,
+int vhost_kernel_get_features(struct vhost_dev *dev,
  uint64_t *features)
 {
 return vhost_kernel_call(dev, VHOST_GET_FEATURES, features);
 }
 
-static int vhost_kernel_set_owner(struct vhost_dev *dev)
+int vhost_kernel_set_owner(struct vhost_dev *dev)
 {
 return vhost_kernel_call(dev, VHOST_SET_OWNER, NULL);
 }
diff --git a/include/hw/virtio/vhost-backend.h 
b/include/hw/virtio/vhost-backend.h
index 6f6670783f..300b59c172 100644
--- a/include/hw/virtio/vhost-backend.h
+++ b/include/hw/virtio/vhost-backend.h
@@ -172,4 +172,32 @@ int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev,
 
 int vhost_user_gpu_set_socket(struct vhost_dev *dev, int fd);
 
+
+int vhost_kernel_set_log_base(struct vhost_dev *dev, uint64_t base,
+ struct vhost_log *log);
+
+int vhost_kernel_set_vring_addr(struct vhost_dev *dev,
+   struct vhost_vring_addr *addr);
+
+int vhost_kernel_set_vring_num(struct vhost_dev *dev,
+  struct vhost_vring_state *ring);
+
+int vhost_kernel_set_vring_base(struct vhost_dev *dev,
+