Re: [Qemu-devel] [PATCH v8 1/4] vhost-user: add new vhost user messages to support virtio config space

2018-01-02 Thread Liu, Changpeng


> -Original Message-
> From: Marc-André Lureau [mailto:marcandre.lur...@gmail.com]
> Sent: Tuesday, January 2, 2018 11:20 PM
> To: Liu, Changpeng <changpeng@intel.com>
> Cc: QEMU <qemu-devel@nongnu.org>; Harris, James R <james.r.har...@intel.com>;
> Michael S. Tsirkin <m...@redhat.com>; Stefan Hajnoczi <stefa...@gmail.com>;
> Paolo Bonzini <pbonz...@redhat.com>; Felipe Franciosi <fel...@nutanix.com>
> Subject: Re: [Qemu-devel] [PATCH v8 1/4] vhost-user: add new vhost user 
> messages
> to support virtio config space
> 
>  Hi
> 
> On Tue, Jan 2, 2018 at 4:55 AM, Changpeng Liu <changpeng@intel.com> wrote:
> > Add VHOST_USER_GET_CONFIG/VHOST_USER_SET_CONFIG messages which can
> be
> > used for live migration of vhost user devices, also vhost user devices
> > can benefit from the messages to get/set virtio config space from/to the
> > I/O target. For the purpose to support virtio config space change,
> > VHOST_USER_SLAVE_CONFIG_CHANGE_MSG message is added as the event
> notifier
> > in case virtio config space change in the slave I/O target.
> >
> > Signed-off-by: Changpeng Liu <changpeng@intel.com>
> > ---
> >  docs/interop/vhost-user.txt   |  53 +
> >  hw/virtio/vhost-user.c| 118 
> > ++
> >  hw/virtio/vhost.c |  32 +++
> >  include/hw/virtio/vhost-backend.h |  12 
> >  include/hw/virtio/vhost.h |  15 +
> >  5 files changed, 230 insertions(+)
> >
> > diff --git a/docs/interop/vhost-user.txt b/docs/interop/vhost-user.txt
> > index 954771d..1788fff 100644
> > --- a/docs/interop/vhost-user.txt
> > +++ b/docs/interop/vhost-user.txt
> > @@ -116,6 +116,19 @@ Depending on the request type, payload can be:
> >  - 3: IOTLB invalidate
> >  - 4: IOTLB access fail
> >
> > + * Virtio device config space
> > +   ---
> > +   | offset | size | flags | payload |
> > +   ---
> > +
> > +   Offset: a 32-bit offset of virtio device's configuration space
> > +   Size: a 32-bit configuration space access size in bytes
> > +   Flags: a 32-bit value:
> > +- 0: Vhost master messages used for writeable fields
> > +- 1: Vhost master messages used for live migration
> > +   Payload: Size bytes array holding the contents of the virtio
> > +   device's configuration space
> > +
> >  In QEMU the vhost-user message is implemented with the following struct:
> >
> >  typedef struct VhostUserMsg {
> > @@ -129,6 +142,7 @@ typedef struct VhostUserMsg {
> >  VhostUserMemory memory;
> >  VhostUserLog log;
> >  struct vhost_iotlb_msg iotlb;
> > +VhostUserConfig config;
> >  };
> >  } QEMU_PACKED VhostUserMsg;
> >
> > @@ -596,6 +610,30 @@ Master message types
> >and expect this message once (per VQ) during device configuration
> >(ie. before the master starts the VQ).
> >
> > + * VHOST_USER_GET_CONFIG
> > +
> > +  Id: 24
> > +  Equivalent ioctl: N/A
> 
> Please document the Master payload. (msg.size != 0)
Ok, will add.
> 
> 
> > +  Slave payload: virtio device config space
> > +
> > +  Submitted by the vhost-user master to fetch the contents of the 
> > virtio
> > +  device configuration space, vhost-user slave's payload size MUST 
> > match
> > +  master's request, vhost-user slave uses zero length of payload to
> > +  indicate an error to vhost-user master. The vhost-user master may
> > +  cache the contents to avoid repeated VHOST_USER_GET_CONFIG calls.
> > +
> > +* VHOST_USER_SET_CONFIG
> > +
> > +  Id: 25
> > +  Equivalent ioctl: N/A
> 
> Same here
Ok.
> 
> > +  Master payload: virtio device config space
> > +
> > +  Submitted by the vhost-user master when the Guest changes the virtio
> > +  device configuration space and also can be used for live migration
> > +  on the destination host. The vhost-user slave must check the flags
> > +  field, and slaves MUST NOT accept SET_CONFIG for read-only
> > +  configuration space fields unless the live migration bit is set.
> > +
> >  Slave message types
> >  ---
> >
> > @@ -614,6 +652,21 @@ Slave message types
> >This request should be send only when VIRTIO_F_IOMMU_PLATFORM
> feature
> >has been successfully 

Re: [Qemu-devel] [PATCH v8 1/4] vhost-user: add new vhost user messages to support virtio config space

2018-01-02 Thread Marc-André Lureau
 Hi

On Tue, Jan 2, 2018 at 4:55 AM, Changpeng Liu  wrote:
> Add VHOST_USER_GET_CONFIG/VHOST_USER_SET_CONFIG messages which can be
> used for live migration of vhost user devices, also vhost user devices
> can benefit from the messages to get/set virtio config space from/to the
> I/O target. For the purpose to support virtio config space change,
> VHOST_USER_SLAVE_CONFIG_CHANGE_MSG message is added as the event notifier
> in case virtio config space change in the slave I/O target.
>
> Signed-off-by: Changpeng Liu 
> ---
>  docs/interop/vhost-user.txt   |  53 +
>  hw/virtio/vhost-user.c| 118 
> ++
>  hw/virtio/vhost.c |  32 +++
>  include/hw/virtio/vhost-backend.h |  12 
>  include/hw/virtio/vhost.h |  15 +
>  5 files changed, 230 insertions(+)
>
> diff --git a/docs/interop/vhost-user.txt b/docs/interop/vhost-user.txt
> index 954771d..1788fff 100644
> --- a/docs/interop/vhost-user.txt
> +++ b/docs/interop/vhost-user.txt
> @@ -116,6 +116,19 @@ Depending on the request type, payload can be:
>  - 3: IOTLB invalidate
>  - 4: IOTLB access fail
>
> + * Virtio device config space
> +   ---
> +   | offset | size | flags | payload |
> +   ---
> +
> +   Offset: a 32-bit offset of virtio device's configuration space
> +   Size: a 32-bit configuration space access size in bytes
> +   Flags: a 32-bit value:
> +- 0: Vhost master messages used for writeable fields
> +- 1: Vhost master messages used for live migration
> +   Payload: Size bytes array holding the contents of the virtio
> +   device's configuration space
> +
>  In QEMU the vhost-user message is implemented with the following struct:
>
>  typedef struct VhostUserMsg {
> @@ -129,6 +142,7 @@ typedef struct VhostUserMsg {
>  VhostUserMemory memory;
>  VhostUserLog log;
>  struct vhost_iotlb_msg iotlb;
> +VhostUserConfig config;
>  };
>  } QEMU_PACKED VhostUserMsg;
>
> @@ -596,6 +610,30 @@ Master message types
>and expect this message once (per VQ) during device configuration
>(ie. before the master starts the VQ).
>
> + * VHOST_USER_GET_CONFIG
> +
> +  Id: 24
> +  Equivalent ioctl: N/A

Please document the Master payload. (msg.size != 0)


> +  Slave payload: virtio device config space
> +
> +  Submitted by the vhost-user master to fetch the contents of the virtio
> +  device configuration space, vhost-user slave's payload size MUST match
> +  master's request, vhost-user slave uses zero length of payload to
> +  indicate an error to vhost-user master. The vhost-user master may
> +  cache the contents to avoid repeated VHOST_USER_GET_CONFIG calls.
> +
> +* VHOST_USER_SET_CONFIG
> +
> +  Id: 25
> +  Equivalent ioctl: N/A

Same here

> +  Master payload: virtio device config space
> +
> +  Submitted by the vhost-user master when the Guest changes the virtio
> +  device configuration space and also can be used for live migration
> +  on the destination host. The vhost-user slave must check the flags
> +  field, and slaves MUST NOT accept SET_CONFIG for read-only
> +  configuration space fields unless the live migration bit is set.
> +
>  Slave message types
>  ---
>
> @@ -614,6 +652,21 @@ Slave message types
>This request should be send only when VIRTIO_F_IOMMU_PLATFORM feature
>has been successfully negotiated.
>
> +* VHOST_USER_SLAVE_CONFIG_CHANGE_MSG
> +
> + Id: 2
> + Equivalent ioctl: N/A
> + Slave payload: N/A
> + Master payload: N/A
> +
> + Vhost-user slave sends such messages to notify that the virtio device's
> + configuration space has changed, for those host devices which can 
> support
> + such feature, host driver can send VHOST_USER_GET_CONFIG message to 
> slave
> + to get the latest content. If VHOST_USER_PROTOCOL_F_REPLY_ACK is
> + negotiated, and slave set the VHOST_USER_NEED_REPLY flag, master must
> + respond with zero when operation is successfully completed, or non-zero
> + otherwise.
> +
>  VHOST_USER_PROTOCOL_F_REPLY_ACK:
>  ---
>  The original vhost-user specification only demands replies for certain
> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> index 093675e..8b94688 100644
> --- a/hw/virtio/vhost-user.c
> +++ b/hw/virtio/vhost-user.c
> @@ -26,6 +26,11 @@
>  #define VHOST_MEMORY_MAX_NREGIONS8
>  #define VHOST_USER_F_PROTOCOL_FEATURES 30
>
> +/*
> + * Maximum size of virtio device config space
> + */
> +#define VHOST_USER_MAX_CONFIG_SIZE 256
> +
>  enum VhostUserProtocolFeature {
>  VHOST_USER_PROTOCOL_F_MQ = 0,
>  VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1,
> @@ -65,12 +70,15 @@ typedef enum VhostUserRequest {
>  VHOST_USER_SET_SLAVE_REQ_FD = 21,
>  

[Qemu-devel] [PATCH v8 1/4] vhost-user: add new vhost user messages to support virtio config space

2018-01-01 Thread Changpeng Liu
Add VHOST_USER_GET_CONFIG/VHOST_USER_SET_CONFIG messages which can be
used for live migration of vhost user devices, also vhost user devices
can benefit from the messages to get/set virtio config space from/to the
I/O target. For the purpose to support virtio config space change,
VHOST_USER_SLAVE_CONFIG_CHANGE_MSG message is added as the event notifier
in case virtio config space change in the slave I/O target.

Signed-off-by: Changpeng Liu 
---
 docs/interop/vhost-user.txt   |  53 +
 hw/virtio/vhost-user.c| 118 ++
 hw/virtio/vhost.c |  32 +++
 include/hw/virtio/vhost-backend.h |  12 
 include/hw/virtio/vhost.h |  15 +
 5 files changed, 230 insertions(+)

diff --git a/docs/interop/vhost-user.txt b/docs/interop/vhost-user.txt
index 954771d..1788fff 100644
--- a/docs/interop/vhost-user.txt
+++ b/docs/interop/vhost-user.txt
@@ -116,6 +116,19 @@ Depending on the request type, payload can be:
 - 3: IOTLB invalidate
 - 4: IOTLB access fail
 
+ * Virtio device config space
+   ---
+   | offset | size | flags | payload |
+   ---
+
+   Offset: a 32-bit offset of virtio device's configuration space
+   Size: a 32-bit configuration space access size in bytes
+   Flags: a 32-bit value:
+- 0: Vhost master messages used for writeable fields
+- 1: Vhost master messages used for live migration
+   Payload: Size bytes array holding the contents of the virtio
+   device's configuration space
+
 In QEMU the vhost-user message is implemented with the following struct:
 
 typedef struct VhostUserMsg {
@@ -129,6 +142,7 @@ typedef struct VhostUserMsg {
 VhostUserMemory memory;
 VhostUserLog log;
 struct vhost_iotlb_msg iotlb;
+VhostUserConfig config;
 };
 } QEMU_PACKED VhostUserMsg;
 
@@ -596,6 +610,30 @@ Master message types
   and expect this message once (per VQ) during device configuration
   (ie. before the master starts the VQ).
 
+ * VHOST_USER_GET_CONFIG
+
+  Id: 24
+  Equivalent ioctl: N/A
+  Slave payload: virtio device config space
+
+  Submitted by the vhost-user master to fetch the contents of the virtio
+  device configuration space, vhost-user slave's payload size MUST match
+  master's request, vhost-user slave uses zero length of payload to
+  indicate an error to vhost-user master. The vhost-user master may
+  cache the contents to avoid repeated VHOST_USER_GET_CONFIG calls.
+
+* VHOST_USER_SET_CONFIG
+
+  Id: 25
+  Equivalent ioctl: N/A
+  Master payload: virtio device config space
+
+  Submitted by the vhost-user master when the Guest changes the virtio
+  device configuration space and also can be used for live migration
+  on the destination host. The vhost-user slave must check the flags
+  field, and slaves MUST NOT accept SET_CONFIG for read-only
+  configuration space fields unless the live migration bit is set.
+
 Slave message types
 ---
 
@@ -614,6 +652,21 @@ Slave message types
   This request should be send only when VIRTIO_F_IOMMU_PLATFORM feature
   has been successfully negotiated.
 
+* VHOST_USER_SLAVE_CONFIG_CHANGE_MSG
+
+ Id: 2
+ Equivalent ioctl: N/A
+ Slave payload: N/A
+ Master payload: N/A
+
+ Vhost-user slave sends such messages to notify that the virtio device's
+ configuration space has changed, for those host devices which can support
+ such feature, host driver can send VHOST_USER_GET_CONFIG message to slave
+ to get the latest content. If VHOST_USER_PROTOCOL_F_REPLY_ACK is
+ negotiated, and slave set the VHOST_USER_NEED_REPLY flag, master must
+ respond with zero when operation is successfully completed, or non-zero
+ otherwise.
+
 VHOST_USER_PROTOCOL_F_REPLY_ACK:
 ---
 The original vhost-user specification only demands replies for certain
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 093675e..8b94688 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -26,6 +26,11 @@
 #define VHOST_MEMORY_MAX_NREGIONS8
 #define VHOST_USER_F_PROTOCOL_FEATURES 30
 
+/*
+ * Maximum size of virtio device config space
+ */
+#define VHOST_USER_MAX_CONFIG_SIZE 256
+
 enum VhostUserProtocolFeature {
 VHOST_USER_PROTOCOL_F_MQ = 0,
 VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1,
@@ -65,12 +70,15 @@ typedef enum VhostUserRequest {
 VHOST_USER_SET_SLAVE_REQ_FD = 21,
 VHOST_USER_IOTLB_MSG = 22,
 VHOST_USER_SET_VRING_ENDIAN = 23,
+VHOST_USER_GET_CONFIG = 24,
+VHOST_USER_SET_CONFIG = 25,
 VHOST_USER_MAX
 } VhostUserRequest;
 
 typedef enum VhostUserSlaveRequest {
 VHOST_USER_SLAVE_NONE = 0,
 VHOST_USER_SLAVE_IOTLB_MSG = 1,
+VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2,
 VHOST_USER_SLAVE_MAX
 }  VhostUserSlaveRequest;
 
@@ -92,6