*** Introduce a new vhost-user-blk host device to Qemu ***
v4 cover *** Introduce a new vhost-user-blk host device to Qemu ***
Although virtio scsi specification was designed as a replacement for virtio_blk, there are still many users using virtio_blk. Qemu 2.9 introduced a new device vhost user scsi which can process I/O in user space for virtio_scsi, this commit introduces a new vhost user block host device, which can support virtio_blk in Guest OS, and I/O processing in another I/O target.
Due to the limitation for virtio_blk specification, virtio_blk device cannot get block information such as capacity, block size etc via the specification, several new vhost user messages were added to deliver virtio config space information between Qemu and I/O target, VHOST_USER_GET_CONFIG/VHOST_USER_SET_CONFIG messages used for get/set config space from/to I/O target, VHOST_USER_SET_CONFIG_FD was added for event notifier in case the change of virtio config space. Also, those messages can be used for vhost device live migration as well.
v3-v4: refactoring the vhost user block example patch based on new libvhost-user library.
v2-v3: add new vhost user message to get/set virtio config space
Changpeng Liu (4):
vhost-user: add new vhost user messages to support virtio config space
vhost-user-blk: introduce a new vhost-user-blk host device contrib/libvhost-user: enable virtio config space messages contrib/vhost-user-blk: introduce a vhost-user-blk sample application
.gitignore | 1 + Makefile | 3 + Makefile.objs | 1 + configure | 11 + contrib/libvhost-user/libvhost-user.c | 75 +++++ contrib/libvhost-user/libvhost-user.h | 15 +- contrib/vhost-user-blk/Makefile.objs | 1 + contrib/vhost-user-blk/vhost-user-blk.c | 492 ++++++++++++++++++++++++++++++++ docs/interop/vhost-user.txt | 33 +++ hw/block/Makefile.objs | 3 + hw/block/vhost-user-blk.c | 360 +++++++++++++++++++++++ hw/virtio/vhost-user.c | 97 +++++++ hw/virtio/vhost.c | 63 ++++ hw/virtio/virtio-pci.c | 55 ++++ hw/virtio/virtio-pci.h | 18 ++ include/hw/virtio/vhost-backend.h | 8 + include/hw/virtio/vhost-user-blk.h | 40 +++ include/hw/virtio/vhost.h | 16 ++ 18 files changed, 1291 insertions(+), 1 deletion(-) create mode 100644 contrib/vhost-user-blk/Makefile.objs create mode 100644 contrib/vhost-user-blk/vhost-user-blk.c create mode 100644 hw/block/vhost-user-blk.c create mode 100644 include/hw/virtio/vhost-user-blk.h
Signature · 1 line
1.9.3
PATCH v4 1/4 vhost-user: add new vhost user messages to support virtio config space
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_SET_CONFIG_FD message is added as the event notifier in case virtio config space change in the I/O target.
--- docs/interop/vhost-user.txt | 33 +++++++++++++ hw/virtio/vhost-user.c | 97 +++++++++++++++++++++++++++++++++++++++ hw/virtio/vhost.c | 63 +++++++++++++++++++++++++ include/hw/virtio/vhost-backend.h | 8 ++++ include/hw/virtio/vhost.h | 16 +++++++ 5 files changed, 217 insertions(+)
docs/interop/vhost-user.txt +33 -0
@@ -116,6 +116,10 @@ Depending on the request type, payload can be: - 3: IOTLB invalidate - 4: IOTLB access fail + * Virtio device config space + + 256 Bytes static virito device config space + In QEMU the vhost-user message is implemented with the following struct: typedef struct VhostUserMsg {
@@ -129,6 +133,7 @@ typedef struct VhostUserMsg { VhostUserMemory memory; VhostUserLog log; struct vhost_iotlb_msg iotlb; + uint8_t config[256]; }; } QEMU_PACKED VhostUserMsg;
@@ -596,6 +601,34 @@ 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 + Master payload: virtio device config space + + Submitted by the vhost-user master to fetch the contents of the virtio + device config space. 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 config space and also can be used for live migration on the + destination host. + +* VHOST_USER_SET_CONFIG_FD + Id: 26 + Equivalent ioctl: N/A + Master payload: N/A + + Sets the notifier file descriptor, which is passed as ancillary data. + Vhost-user slave uses the file descriptor to notify vhost-user master + when the virtio config space changed. The vhost-user master can read + the virtio config space to get the latest update. + Slave message types -------------------
hw/virtio/vhost-user.c +97 -0
125 lines not on this page · raw message
hw/virtio/vhost.c +63 -0
75 lines not on this page · raw message
include/hw/virtio/vhost-backend.h +8 -0
@@ -84,6 +84,11 @@ typedef void (*vhost_set_iotlb_callback_op)(struct vhost_dev *dev, int enabled);typedef int (*vhost_send_device_iotlb_msg_op )(struct vhost_dev *dev,struct vhost_iotlb_msg *imsg); +typedef int (*vhost_set_config_op )(struct vhost_dev *dev,const uint8_t *config, +size_t config_len); +typedef int (*vhost_get_config_op )(struct vhost_dev *dev,uint8_t *config, +size_t config_len); +typedef int (*vhost_set_config_fd_op )(struct vhost_dev *dev,int fd); typedef struct VhostOps { VhostBackendType backend_type;
@@ -118,6 +123,9 @@ typedef struct VhostOps {vhost_vsock_set_running_op vhost_vsock_set_running;vhost_set_iotlb_callback_op vhost_set_iotlb_callback;vhost_send_device_iotlb_msg_op vhost_send_device_iotlb_msg; +vhost_get_config_op vhost_get_config; +vhost_set_config_op vhost_set_config; +vhost_set_config_fd_op vhost_set_config_fd; } VhostOps;extern const VhostOps user_ops;
include/hw/virtio/vhost.h +16 -0
@@ -46,6 +46,12 @@ struct vhost_iommu {QLIST_ENTRY (vhost_iommu) iommu_next; }; +typedef struct VhostDevConfigOps { +/* Vhost device config space changed callback +*/ +void (*vhost_dev_config_notifier)(struct vhost_dev *dev); +}VhostDevConfigOps ; +struct vhost_memory ;struct vhost_dev {VirtIODevice *vdev;
@@ -76,6 +82,8 @@ struct vhost_dev {QLIST_ENTRY (vhost_dev) entry; QLIST_HEAD(, vhost_iommu) iommu_list;IOMMUNotifier n; +EventNotifier config_notifier; +const VhostDevConfigOps *config_ops; }; int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
@@ -106,4 +114,12 @@ int vhost_net_set_backend(struct vhost_dev *hdev, struct vhost_vring_file *file);int vhost_device_iotlb_miss (struct vhost_dev *dev,uint64_t iova,int write); +int vhost_dev_get_config (struct vhost_dev *dev,uint8_t *config, +size_t config_len); +int vhost_dev_set_config (struct vhost_dev *dev,const uint8_t *config, +size_t config_len); +/* notifier callback in case vhost device config space changed +*/ +int vhost_dev_set_config_notifier (struct vhost_dev *dev, +const VhostDevConfigOps *ops);#endif
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config space
Quoted 21 lines · 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_SET_CONFIG_FDmessage is added as the event notifier in case virtio config space change in the I/O target.Signed-off-by Changpeng Liu <[email protected]>--- docs/interop/vhost-user.txt | 33 +++++++++++++ hw/virtio/vhost-user.c | 97 +++++++++++++++++++++++++++++++++++++++ hw/virtio/vhost.c | 63 +++++++++++++++++++++++++ include/hw/virtio/vhost-backend.h | 8 ++++ include/hw/virtio/vhost.h | 16 +++++++ 5 files changed, 217 insertions(+)docs/interop/vhost-user.txt +0
-0
docs/interop/vhost-user.txt Depending on the request type, payload can be: · line 121
Quoted 6 lines
docs/interop/vhost-user.txt +3
-0@@ -116,6 +116,10 @@ Depending on the request type, payload can be: - 3: IOTLB invalidate - 4: IOTLB access fail + * Virtio device config space + + 256 Bytes static virito device config space
"A 256-bytes array holding the contents of the virtio device's configuration space"
docs/interop/vhost-user.txt Master message types · line 628
Quoted 7 lines
docs/interop/vhost-user.txt +7
-0+* VHOST_USER_SET_CONFIG_FD + Id: 26 + Equivalent ioctl: N/A + Master payload: N/A + + Sets the notifier file descriptor, which is passed as ancillary data. + Vhost-user slave uses the file descriptor to notify vhost-user master
"The vhost-user slave uses the file descriptor to notify the vhost-user master of changes to the virtio configuration space."
Paolo
Quoted 287 lines
docs/interop/vhost-user.txt +3
-0+ when the virtio config space changed. The vhost-user master can read + the virtio config space to get the latest update. + Slave message types -------------------hw/virtio/vhost-user.c +97
-0@@ -26,6 +26,11 @@#define VHOST_MEMORY_MAX_NREGIONS 8#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,6 +70,9 @@ 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_SET_CONFIG_FD =26 , VHOST_USER_MAX } VhostUserRequest;@@ -109,6 +117,7 @@ typedef struct VhostUserMsg {VhostUserMemory memory;VhostUserLog log;struct vhost_iotlb_msg iotlb; +uint8_t config[VHOST_USER_MAX_CONFIG_SIZE ]; } payload; }QEMU_PACKED VhostUserMsg;@@ -922,6 +931,91 @@ static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled)/* No-op as the receive channel is not dedicated to IOTLB messages. */ } +static int vhost_user_get_config (struct vhost_dev *dev,uint8_t *config, +size_t config_len) +{ +VhostUserMsg msg = { + .request =VHOST_USER_GET_CONFIG , + .flags =VHOST_USER_VERSION , + .size = config_len, + }; + +if (config_len ==0 || config_len >VHOST_USER_PAYLOAD_SIZE ) { +error_report ("bad config length" ); +return -1 ; + } + +if (vhost_user_write (dev, &msg,NULL ,0 ) <0 ) { +return -1 ; + } + +if (vhost_user_read (dev, &msg) <0 ) { +return -1 ; + } + +if (msg.request !=VHOST_USER_GET_CONFIG ) { +error_report ("Received unexpected msg type. Expected %d received %d" , +VHOST_USER_GET_CONFIG , msg.request); +return -1 ; + } + +if (msg.size != config_len) { +error_report ("Received bad msg size." ); +return -1 ; + } + +memcpy (config, &msg.payload.config, config_len); + +return 0 ; +} + +static int vhost_user_set_config (struct vhost_dev *dev,const uint8_t *config, +size_t config_len) +{ +bool reply_supported =virtio_has_feature (dev->protocol_features, +VHOST_USER_PROTOCOL_F_REPLY_ACK ); + +VhostUserMsg msg = { + .request =VHOST_USER_SET_CONFIG , + .flags =VHOST_USER_VERSION , + .size = config_len, + }; + +if (reply_supported) { + msg.flags |=VHOST_USER_NEED_REPLY_MASK ; + } + +if (config_len ==0 || config_len >VHOST_USER_PAYLOAD_SIZE ) { +error_report ("bad config length" ); +return -1 ; + } + +memcpy (&msg.payload.config, config, config_len); +if (vhost_user_write (dev, &msg,NULL ,0 ) <0 ) { +return -1 ; + } + +if (reply_supported) { +return process_message_reply (dev, &msg); + } + +return 0 ; +} + +static int vhost_user_set_config_fd (struct vhost_dev *dev,int fd) +{ +VhostUserMsg msg = { + .request =VHOST_USER_SET_CONFIG_FD , + .flags =VHOST_USER_VERSION , + }; + +if (vhost_user_write (dev, &msg, &fd,1 ) <0 ) { +return -1 ; + } + +return 0 ; +} +const VhostOps user_ops = { .backend_type =VHOST_BACKEND_TYPE_USER , .vhost_backend_init = vhost_user_init,@@ -948,4 +1042,7 @@ const VhostOps user_ops = { .vhost_net_set_mtu = vhost_user_net_set_mtu, .vhost_set_iotlb_callback = vhost_user_set_iotlb_callback, .vhost_send_device_iotlb_msg = vhost_user_send_device_iotlb_msg, + .vhost_get_config = vhost_user_get_config, + .vhost_set_config = vhost_user_set_config, + .vhost_set_config_fd = vhost_user_set_config_fd, };hw/virtio/vhost.c +63
-0@@ -1354,6 +1354,9 @@ void vhost_dev_cleanup(struct vhost_dev *hdev)for (i =0 ; i < hdev->nvqs; ++i) {vhost_virtqueue_cleanup (hdev->vqs + i); } +if (hdev->config_ops) { +event_notifier_cleanup (&hdev->config_notifier); + }if (hdev->mem) {/* those are only safe after successful init */ memory_listener_unregister (&hdev->memory_listener);@@ -1501,6 +1504,66 @@ void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits, } } +int vhost_dev_get_config (struct vhost_dev *hdev,uint8_t *config, +size_t config_len) +{ +assert (hdev->vhost_ops); + +if (hdev->vhost_ops->vhost_get_config) { +return hdev->vhost_ops->vhost_get_config (hdev, config, config_len); + } + +return 0 ; +} + +int vhost_dev_set_config (struct vhost_dev *hdev,const uint8_t *config, +size_t config_len) +{ +assert (hdev->vhost_ops); + +if (hdev->vhost_ops->vhost_set_config) { +return hdev->vhost_ops->vhost_set_config (hdev, config, config_len); + } + +return 0 ; +} + +static void vhost_dev_config_notifier_read (EventNotifier *n) +{ + struct vhost_dev *hdev = container_of(n, struct vhost_dev, + config_notifier); + +if (event_notifier_test_and_clear (n)) { +if (hdev->config_ops) { + hdev->config_ops->vhost_dev_config_notifier (hdev); + } + } +} + +int vhost_dev_set_config_notifier (struct vhost_dev *hdev, +const VhostDevConfigOps *ops) +{ +int r, fd; + +assert (hdev->vhost_ops); + + r =event_notifier_init (&hdev->config_notifier,0 ); +if (r <0 ) { +return r; + } + + hdev->config_ops = ops; +event_notifier_set_handler (&hdev->config_notifier, + vhost_dev_config_notifier_read); + +if (hdev->vhost_ops->vhost_set_config_fd) { + fd =event_notifier_get_fd (&hdev->config_notifier); +return hdev->vhost_ops->vhost_set_config_fd (hdev, fd); + } + +return 0 ; +} +/* Host notifiers must be enabled at this point. */ int vhost_dev_start (struct vhost_dev *hdev,VirtIODevice *vdev) {include/hw/virtio/vhost-backend.h +8
-0@@ -84,6 +84,11 @@ typedef void (*vhost_set_iotlb_callback_op)(struct vhost_dev *dev, int enabled);typedef int (*vhost_send_device_iotlb_msg_op )(struct vhost_dev *dev,struct vhost_iotlb_msg *imsg); +typedef int (*vhost_set_config_op )(struct vhost_dev *dev,const uint8_t *config, +size_t config_len); +typedef int (*vhost_get_config_op )(struct vhost_dev *dev,uint8_t *config, +size_t config_len); +typedef int (*vhost_set_config_fd_op )(struct vhost_dev *dev,int fd); typedef struct VhostOps { VhostBackendType backend_type;@@ -118,6 +123,9 @@ typedef struct VhostOps {vhost_vsock_set_running_op vhost_vsock_set_running;vhost_set_iotlb_callback_op vhost_set_iotlb_callback;vhost_send_device_iotlb_msg_op vhost_send_device_iotlb_msg; +vhost_get_config_op vhost_get_config; +vhost_set_config_op vhost_set_config; +vhost_set_config_fd_op vhost_set_config_fd; } VhostOps;extern const VhostOps user_ops;include/hw/virtio/vhost.h +16
-0@@ -46,6 +46,12 @@ struct vhost_iommu {QLIST_ENTRY (vhost_iommu) iommu_next; }; +typedef struct VhostDevConfigOps { +/* Vhost device config space changed callback +*/ +void (*vhost_dev_config_notifier)(struct vhost_dev *dev); +}VhostDevConfigOps ; +struct vhost_memory ;struct vhost_dev {VirtIODevice *vdev;@@ -76,6 +82,8 @@ struct vhost_dev {QLIST_ENTRY (vhost_dev) entry; QLIST_HEAD(, vhost_iommu) iommu_list;IOMMUNotifier n; +EventNotifier config_notifier; +const VhostDevConfigOps *config_ops; }; int vhost_dev_init(struct vhost_dev *hdev, void *opaque,@@ -106,4 +114,12 @@ int vhost_net_set_backend(struct vhost_dev *hdev, struct vhost_vring_file *file);int vhost_device_iotlb_miss (struct vhost_dev *dev,uint64_t iova,int write); +int vhost_dev_get_config (struct vhost_dev *dev,uint8_t *config, +size_t config_len); +int vhost_dev_set_config (struct vhost_dev *dev,const uint8_t *config, +size_t config_len); +/* notifier callback in case vhost device config space changed +*/ +int vhost_dev_set_config_notifier (struct vhost_dev *dev, +const VhostDevConfigOps *ops);#endif
Re: [Qemu-devel] [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config space
In reply to Changpeng LiuQuoted 4 lines · Changpeng Liu
hw/virtio/vhost-user.c +0
-0@@ -922,6 +931,91 @@ static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled)/* No-op as the receive channel is not dedicated to IOTLB messages. */ }
hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled) · line 943
Quoted 10 lines
hw/virtio/vhost-user.c +10
-0+static int vhost_user_get_config (struct vhost_dev *dev,uint8_t *config, +size_t config_len) +{ +VhostUserMsg msg = { + .request =VHOST_USER_GET_CONFIG , + .flags =VHOST_USER_VERSION , + .size = config_len, + }; + +if (config_len ==0 || config_len >VHOST_USER_PAYLOAD_SIZE ) {
config_len should be limited to 256 bytes:
if (config_len == 0 || config_len > sizeof(msg.payload.config) {Quoted 14 lines
hw/virtio/vhost-user.c +14
-0+error_report ("bad config length" ); +return -1 ; + } + +if (vhost_user_write (dev, &msg,NULL ,0 ) <0 ) { +return -1 ; + } + +if (vhost_user_read (dev, &msg) <0 ) { +return -1 ; + } + +if (msg.request !=VHOST_USER_GET_CONFIG ) { + error_report("Received unexpected msg type. Expected %d received %d",
hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled) · line 967
Quoted 10 lines
hw/virtio/vhost-user.c +10
-0+ VHOST_USER_GET_CONFIG, msg.request); +return -1 ; + } + +if (msg.size != config_len) { +error_report ("Received bad msg size." ); +return -1 ; + } + +memcpy (config, &msg.payload.config, config_len);
There is some complexity here: different virtio devices use different amounts of config space. Devices may append new fields to the config space to support new features.
Therefore I think the simplest protocol is to always fetch the full 256-byte configuration space. This way the vhost-user slave process can implement feature bits that the master process does not know about.
In other words, I don't think the master process knows how much of the config space is used so it should always request 256 bytes.
Quoted 10 lines
hw/virtio/vhost-user.c +10
-0+return 0 ; +} + +static int vhost_user_set_config (struct vhost_dev *dev,const uint8_t *config, +size_t config_len) +{ +bool reply_supported =virtio_has_feature (dev->protocol_features, +VHOST_USER_PROTOCOL_F_REPLY_ACK ); + +VhostUserMsg msg = {
hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled) · line 988
Quoted 10 lines
hw/virtio/vhost-user.c +10
-0+ .request = VHOST_USER_SET_CONFIG, + .flags = VHOST_USER_VERSION, + .size = config_len, + }; + +if (reply_supported) { + msg.flags |=VHOST_USER_NEED_REPLY_MASK ; + } + +if (config_len ==0 || config_len >VHOST_USER_PAYLOAD_SIZE ) {
Same thing here: config_len > sizeof(msg.payload.config)
Re: [Qemu-devel] [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config space
Quoted 18 lines · Stefan Hajnoczi
Quoted 4 lines · Changpeng Liu
hw/virtio/vhost-user.c +0
-0@@ -922,6 +931,91 @@ static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled)/* No-op as the receive channel is not dedicated to IOTLB messages. */ }hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled) · line 943
Quoted 10 lines
hw/virtio/vhost-user.c +10
-0+static int vhost_user_get_config (struct vhost_dev *dev,uint8_t *config, +size_t config_len) +{ +VhostUserMsg msg = { + .request =VHOST_USER_GET_CONFIG , + .flags =VHOST_USER_VERSION , + .size = config_len, + }; + +if (config_len ==0 || config_len >VHOST_USER_PAYLOAD_SIZE ) {
config_lenshould be limited to 256 bytes:
Quoted 1 line
if (config_len == 0 || config_len > sizeof(msg.payload.config) {I would just limit it to a reasonable value, acceptable to both master and slave, not fail if it's bigger.
Quoted 29 lines
Quoted 14 lines
hw/virtio/vhost-user.c +14
-0+error_report ("bad config length" ); +return -1 ; + } + +if (vhost_user_write (dev, &msg,NULL ,0 ) <0 ) { +return -1 ; + } + +if (vhost_user_read (dev, &msg) <0 ) { +return -1 ; + } + +if (msg.request !=VHOST_USER_GET_CONFIG ) { + error_report("Received unexpected msg type. Expected %d received %d",hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled) · line 967
Quoted 10 lines
hw/virtio/vhost-user.c +10
-0+ VHOST_USER_GET_CONFIG, msg.request); +return -1 ; + } + +if (msg.size != config_len) { +error_report ("Received bad msg size." ); +return -1 ; + } + +memcpy (config, &msg.payload.config, config_len);There is some complexity here: different virtio devices use different amounts of config space. Devices may append new fields to the config space to support new features.
Quoted 6 lines
Therefore I think the simplest protocol is to always fetch the full 256-byte configuration space. This way the vhost-user slave process can implement feature bits that the master process does not know about.
In other words, I don't think the master process knows how much of the config space is used so it should always request 256 bytes.
Each device knows the max config space size.
vdev->config_len = config_size;
I don't think we need to hard-code 256 bytes in there.
Quoted 22 lines
Quoted 10 lines
hw/virtio/vhost-user.c +10
-0+return 0 ; +} + +static int vhost_user_set_config (struct vhost_dev *dev,const uint8_t *config, +size_t config_len) +{ +bool reply_supported =virtio_has_feature (dev->protocol_features, +VHOST_USER_PROTOCOL_F_REPLY_ACK ); + +VhostUserMsg msg = {hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled) · line 988
Quoted 10 lines
hw/virtio/vhost-user.c +10
-0+ .request = VHOST_USER_SET_CONFIG, + .flags = VHOST_USER_VERSION, + .size = config_len, + }; + +if (reply_supported) { + msg.flags |=VHOST_USER_NEED_REPLY_MASK ; + } + +if (config_len ==0 || config_len >VHOST_USER_PAYLOAD_SIZE ) {Same thing here:
config_len> sizeof(msg.payload.config)
Re: [Qemu-devel] [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config space
Quoted 58 lines · Michael S. Tsirkin
Quoted 18 lines · Stefan Hajnoczi
Quoted 4 lines · Changpeng Liu
hw/virtio/vhost-user.c +0
-0@@ -922,6 +931,91 @@ static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled)/* No-op as the receive channel is not dedicated to IOTLB messages. */ }hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled) · line 943
Quoted 10 lines
hw/virtio/vhost-user.c +10
-0+static int vhost_user_get_config (struct vhost_dev *dev,uint8_t *config, +size_t config_len) +{ +VhostUserMsg msg = { + .request =VHOST_USER_GET_CONFIG , + .flags =VHOST_USER_VERSION , + .size = config_len, + }; + +if (config_len ==0 || config_len >VHOST_USER_PAYLOAD_SIZE ) {
config_lenshould be limited to 256 bytes:Quoted 1 line
if (config_len == 0 || config_len > sizeof(msg.payload.config) {I would just limit it to a reasonable value, acceptable to both master and slave, not fail if it's bigger.
Quoted 33 lines
Quoted 14 lines
hw/virtio/vhost-user.c +14
-0+error_report ("bad config length" ); +return -1 ; + } + +if (vhost_user_write (dev, &msg,NULL ,0 ) <0 ) { +return -1 ; + } + +if (vhost_user_read (dev, &msg) <0 ) { +return -1 ; + } + +if (msg.request !=VHOST_USER_GET_CONFIG ) { + error_report("Received unexpected msg type. Expected %d received %d",hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled) · line 967
Quoted 10 lines
hw/virtio/vhost-user.c +10
-0+ VHOST_USER_GET_CONFIG, msg.request); +return -1 ; + } + +if (msg.size != config_len) { +error_report ("Received bad msg size." ); +return -1 ; + } + +memcpy (config, &msg.payload.config, config_len);There is some complexity here: different virtio devices use different amounts of config space. Devices may append new fields to the config space to support new features.
Therefore I think the simplest protocol is to always fetch the full 256-byte configuration space. This way the vhost-user slave process can implement feature bits that the master process does not know about.
Quoted 6 lines
Quoted 2 lines
In other words, I don't think the master process knows how much of the config space is used so it should always request 256 bytes.
Each device knows the max config space size.
vdev->config_len = config_size;
I see you're referring to the field that is set in:
void virtio_init(VirtIODevice *vdev, const char *name,
uint16_t device_id, size_t config_size)
How does this work for vhost-user where different slave programs may offer different config sizes?
The QEMU master process does not know the correct size ahead of time. The size depends on the vhost-user slave process. This is why I suggest using the full 256 bytes that the VIRTIO spec defines.
Re: [Qemu-devel] [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config space
Quoted 80 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Friday, October 20, 2017 6:01 PM
To: Michael S. Tsirkin <[email protected]>
Cc: Liu, Changpeng <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config spaceQuoted 3 lines · Michael S. Tsirkin
Quoted 2 lines · Stefan Hajnoczi
Review static void vhost_user_set_iotlb_callback(struct
Quoted 1 line · Changpeng Liu
(quoted diff) +0
-0@@ -922,6 +931,91 @@ static void vhost_user_set_iotlb_callback(struct
vhost_dev*dev, int enabled)Quoted 22 lines
Quoted 16 lines
hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled) · line 943
Quoted 13 lines
hw/virtio/vhost-user.c +10
-0/* No-op as the receive channel is not dedicated to IOTLB messages. */ } +static int vhost_user_get_config (struct vhost_dev *dev,uint8_t *config, +size_t config_len) +{ +VhostUserMsg msg = { + .request =VHOST_USER_GET_CONFIG , + .flags =VHOST_USER_VERSION , + .size = config_len, + }; + +if (config_len ==0 || config_len >VHOST_USER_PAYLOAD_SIZE ) {
config_lenshould be limited to 256 bytes:Quoted 1 line
if (config_len == 0 || config_len > sizeof(msg.payload.config) {I would just limit it to a reasonable value, acceptable to both master and slave, not fail if it's bigger.
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
hw/virtio/vhost-user.c +6
-0+error_report ("bad config length" ); +return -1 ; + } + +if (vhost_user_write (dev, &msg,NULL ,0 ) <0 ) { +return -1 ;Quoted 8 lines
hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled)
Quoted 8 lines
hw/virtio/vhost-user.c +8
-0+ } + +if (vhost_user_read (dev, &msg) <0 ) { +return -1 ; + } + +if (msg.request !=VHOST_USER_GET_CONFIG ) { + error_report("Received unexpected msg type. Expected %dreceived %d",
Quoted 19 lines
Quoted 19 lines
hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled) · line 967
Quoted 10 lines
hw/virtio/vhost-user.c +10
-0+ VHOST_USER_GET_CONFIG, msg.request); +return -1 ; + } + +if (msg.size != config_len) { +error_report ("Received bad msg size." ); +return -1 ; + } + +memcpy (config, &msg.payload.config, config_len);There is some complexity here: different virtio devices use different amounts of config space. Devices may append new fields to the config space to support new features.
Therefore I think the simplest protocol is to always fetch the full 256-byte configuration space. This way the vhost-user slave process can implement feature bits that the master process does not know about.
Quoted 6 lines
Quoted 2 lines
In other words, I don't think the master process knows how much of the config space is used so it should always request 256 bytes.
Each device knows the max config space size.
vdev->config_len = config_size;
Quoted 7 lines
I see you're referring to the field that is set in:
void virtio_init(VirtIODevice *vdev, const char *name,
uint16_tdevice_id,size_tconfig_size)How does this work for vhost-user where different slave programs may offer different config sizes?
Each Qemu vhost controller e.g: vhost-user-scsi-pci and vhost-user-blk-pci should has different char devices, so vhost-slave knows those messages are from vhost-scsi or vhost-blk, of course, each UNIX domain socket should be assigned by users with types: vhsot-scsi or vhost-blk.
Quoted 4 lines
The QEMU master process does not know the correct size ahead of time. The size depends on the vhost-user slave process. This is why I suggest using the full 256 bytes that the VIRTIO spec defines.
Re: [Qemu-devel] [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config space
Quoted 82 lines · Changpeng
Quoted 82 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Friday, October 20, 2017 6:01 PM
To: Michael S. Tsirkin <[email protected]>
Cc: Liu, Changpeng <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config spaceQuoted 3 lines · Michael S. Tsirkin
Quoted 2 lines · Stefan Hajnoczi
Review static void vhost_user_set_iotlb_callback(struct
Quoted 1 line · Changpeng Liu
(quoted diff) +0
-0@@ -922,6 +931,91 @@ static void vhost_user_set_iotlb_callback(struct
vhost_dev*dev, int enabled)Quoted 22 lines
Quoted 16 lines
hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled) · line 943
Quoted 13 lines
hw/virtio/vhost-user.c +10
-0/* No-op as the receive channel is not dedicated to IOTLB messages. */ } +static int vhost_user_get_config (struct vhost_dev *dev,uint8_t *config, +size_t config_len) +{ +VhostUserMsg msg = { + .request =VHOST_USER_GET_CONFIG , + .flags =VHOST_USER_VERSION , + .size = config_len, + }; + +if (config_len ==0 || config_len >VHOST_USER_PAYLOAD_SIZE ) {
config_lenshould be limited to 256 bytes:Quoted 1 line
if (config_len == 0 || config_len > sizeof(msg.payload.config) {I would just limit it to a reasonable value, acceptable to both master and slave, not fail if it's bigger.
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
hw/virtio/vhost-user.c +6
-0+error_report ("bad config length" ); +return -1 ; + } + +if (vhost_user_write (dev, &msg,NULL ,0 ) <0 ) { +return -1 ;Quoted 8 lines
hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled)
Quoted 8 lines
hw/virtio/vhost-user.c +8
-0+ } + +if (vhost_user_read (dev, &msg) <0 ) { +return -1 ; + } + +if (msg.request !=VHOST_USER_GET_CONFIG ) { + error_report("Received unexpected msg type. Expected %dreceived %d",
Quoted 19 lines
Quoted 19 lines
hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled) · line 967
Quoted 10 lines
hw/virtio/vhost-user.c +10
-0+ VHOST_USER_GET_CONFIG, msg.request); +return -1 ; + } + +if (msg.size != config_len) { +error_report ("Received bad msg size." ); +return -1 ; + } + +memcpy (config, &msg.payload.config, config_len);There is some complexity here: different virtio devices use different amounts of config space. Devices may append new fields to the config space to support new features.
Therefore I think the simplest protocol is to always fetch the full 256-byte configuration space. This way the vhost-user slave process can implement feature bits that the master process does not know about.
Quoted 6 lines
Quoted 2 lines
In other words, I don't think the master process knows how much of the config space is used so it should always request 256 bytes.
Each device knows the max config space size.
vdev->config_len = config_size;I see you're referring to the field that is set in:
Quoted 8 lines
Quoted 5 lines
void virtio_init(VirtIODevice *vdev, const char *name,
uint16_tdevice_id,size_tconfig_size)How does this work for vhost-user where different slave programs may offer different config sizes?
Each Qemu vhost controller e.g: vhost-user-scsi-pci and vhost-user-blk-pci should has different char devices, so vhost-slave knows those messages are from vhost-scsi or vhost-blk, of course, each UNIX domain socket should be assigned by users with types: vhsot-scsi or vhost-blk.
We're talking about different things. Here is an example illustrating my question:
vhost-user-blk slave A only knows about struct virtio_blk_config fields up to wce (VIRTIO 1.0). See
http://docs.oasis-open.org/virtio/virtio/v1.0/cs04/virtio-v1.0-cs04.html#x1-2070004.
vhost-user-blk slave B implements struct virtio_blk_config with the new num_queues field. See
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/virtio_blk.h#n56.
Slaves A and B use different struct virtio_blk_config sizes!
Which config size should the vhost-master use? There is currently no way to query the size from the slave.
What should slave programs do when the master requests configuration space data that is the wrong size?
I think the simplest answer is that the master always uses 256 bytes. Slaves also keep the full 256 bytes stored but their device implementation may access fewer bytes.
Quoted 3 lines
Quoted 3 lines
The QEMU master process does not know the correct size ahead of time. The size depends on the vhost-user slave process. This is why I suggest using the full 256 bytes that the VIRTIO spec defines.
Re: [Qemu-devel] [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config space
Quoted 126 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Tuesday, October 24, 2017 1:26 AM
To: Liu, Changpeng <[email protected]>
Cc: Michael S. Tsirkin <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config spaceQuoted 10 lines · Changpeng
Quoted 10 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Friday, October 20, 2017 6:01 PM
To: Michael S. Tsirkin <[email protected]>
Cc: Liu, Changpeng <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 1/4] vhost-user: add new vhost user messages tosupport
Quoted 8 lines
Quoted 8 lines
virtio config space
Quoted 3 lines · Michael S. Tsirkin
Quoted 2 lines · Stefan Hajnoczi
Review static void vhost_user_set_iotlb_callback(struct
Quoted 1 line · Changpeng Liu
(quoted diff) +0
-0@@ -922,6 +931,91 @@ static void vhost_user_set_iotlb_callback(struct
vhost_dev*dev, int enabled)Quoted 1 line
Quoted 1 line
Quoted 1 line
(quoted diff) +0
-0/* No-op as the receive channel is not dedicated to IOTLB messages.*/
Quoted 62 lines
Quoted 62 lines
Quoted 21 lines
Quoted 15 lines
hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled) · line 943
Quoted 12 lines
hw/virtio/vhost-user.c +10
-0} +static int vhost_user_get_config (struct vhost_dev *dev,uint8_t *config, +size_t config_len) +{ +VhostUserMsg msg = { + .request =VHOST_USER_GET_CONFIG , + .flags =VHOST_USER_VERSION , + .size = config_len, + }; + +if (config_len ==0 || config_len >VHOST_USER_PAYLOAD_SIZE ) {
config_lenshould be limited to 256 bytes:Quoted 1 line
if (config_len == 0 || config_len > sizeof(msg.payload.config) {I would just limit it to a reasonable value, acceptable to both master and slave, not fail if it's bigger.
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
hw/virtio/vhost-user.c +6
-0+error_report ("bad config length" ); +return -1 ; + } + +if (vhost_user_write (dev, &msg,NULL ,0 ) <0 ) { +return -1 ;Quoted 8 lines
hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled)
Quoted 8 lines
hw/virtio/vhost-user.c +8
-0+ } + +if (vhost_user_read (dev, &msg) <0 ) { +return -1 ; + } + +if (msg.request !=VHOST_USER_GET_CONFIG ) { + error_report("Received unexpected msg type. Expected %dreceived %d",
Quoted 25 lines
Quoted 15 lines
hw/virtio/vhost-user.c static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled) · line 967
Quoted 10 lines
hw/virtio/vhost-user.c +10
-0+ VHOST_USER_GET_CONFIG, msg.request); +return -1 ; + } + +if (msg.size != config_len) { +error_report ("Received bad msg size." ); +return -1 ; + } + +memcpy (config, &msg.payload.config, config_len);There is some complexity here: different virtio devices use different amounts of config space. Devices may append new fields to the config space to support new features.
Quoted 6 lines
Therefore I think the simplest protocol is to always fetch the full 256-byte configuration space. This way the vhost-user slave process can implement feature bits that the master process does not know about.
In other words, I don't think the master process knows how much of the config space is used so it should always request 256 bytes.
Each device knows the max config space size.
vdev->config_len = config_size;Quoted 8 lines
Quoted 7 lines
I see you're referring to the field that is set in:
void virtio_init(VirtIODevice *vdev, const char *name,
uint16_tdevice_id,size_tconfig_size)How does this work for vhost-user where different slave programs may offer different config sizes?
Each Qemu vhost controller e.g: vhost-user-scsi-pci and vhost-user-blk-pci
should has different char devices,
Quoted 1 line
so vhost-slave knows those messages are from vhost-scsi or vhost-blk, of
course, each UNIX domain socket
Quoted 1 line
should be assigned by users with types: vhsot-scsi or vhost-blk.
We're talking about different things. Here is an example illustrating my question:
vhost-user-blk slave A only knows about struct
virtio_blk_configfields up to wce (VIRTIO 1.0). See
http://docs.oasis-open.org/virtio/virtio/v1.0/cs04/virtio-v1.0-cs04.html#x1-
2070004.vhost-user-blk slave B implements struct
virtio_blk_configwith the newnum_queuesfield. See
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/u
api/linux/virtio_blk.h#n56.Slaves A and B use different struct
virtio_blk_configsizes!Which config size should the vhost-master use? There is currently no way to query the size from the slave.
Quoted 6 lines
What should slave programs do when the master requests configuration space data that is the wrong size?
I think the simplest answer is that the master always uses 256 bytes. Slaves also keep the full 256 bytes stored but their device implementation may access fewer bytes.
Yes, clear now. How about the following configuration:
struct vhost_dev_config {
unsigned int offset;
unsigned int size;
uint8_t config[256];
};The master always uses 256 Bytes, but with additional 2 parameters to locate detailed configuration fields, I think this combined Michael and your comments about this patch.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
The QEMU master process does not know the correct size ahead of time. The size depends on the vhost-user slave process. This is why I suggest using the full 256 bytes that the VIRTIO spec defines.
Re: [Qemu-devel] [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config space
Quoted 132 lines · Changpeng
Quoted 126 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Tuesday, October 24, 2017 1:26 AM
To: Liu, Changpeng <[email protected]>
Cc: Michael S. Tsirkin <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config spaceQuoted 10 lines · Changpeng
Quoted 10 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Friday, October 20, 2017 6:01 PM
To: Michael S. Tsirkin <[email protected]>
Cc: Liu, Changpeng <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 1/4] vhost-user: add new vhost user messages tosupport
Quoted 8 lines
Quoted 8 lines
virtio config space
Quoted 3 lines · Michael S. Tsirkin
Quoted 2 lines · Stefan Hajnoczi
Review static void vhost_user_set_iotlb_callback(struct
Quoted 1 line · Changpeng Liu
(quoted diff) +0
-0@@ -922,6 +931,91 @@ static void vhost_user_set_iotlb_callback(struct
vhost_dev*dev, int enabled)Quoted 1 line
Quoted 1 line
Quoted 1 line
(quoted diff) +0
-0/* No-op as the receive channel is not dedicated to IOTLB messages.*/
Quoted 62 lines
Quoted 62 lines
Quoted 21 lines
Quoted 15 lines
Review static void vhost_user_set_iotlb_callback(struct · line 943
Quoted 12 lines
(quoted diff) +10
-0} +static int vhost_user_get_config(struct vhost_dev *dev, uint8_t *config, + size_t config_len) +{ + VhostUserMsg msg = { + .request = VHOST_USER_GET_CONFIG, + .flags = VHOST_USER_VERSION, + .size = config_len, + }; + + if (config_len == 0 || config_len > VHOST_USER_PAYLOAD_SIZE) {
config_lenshould be limited to 256 bytes:Quoted 1 line
if (config_len == 0 || config_len > sizeof(msg.payload.config) {I would just limit it to a reasonable value, acceptable to both master and slave, not fail if it's bigger.
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
(quoted diff) +6
-0+ error_report("bad config length"); + return -1; + } + + if (vhost_user_write(dev, &msg, NULL, 0) < 0) { + return -1;Quoted 8 lines
Review static void vhost_user_set_iotlb_callback(struct · line 957
Quoted 8 lines
(quoted diff) +8
-0+ } + + if (vhost_user_read(dev, &msg) < 0) { + return -1; + } + + if (msg.request != VHOST_USER_GET_CONFIG) { + error_report("Received unexpected msg type. Expected %dreceived %d",
Quoted 25 lines
Quoted 15 lines
Review static void vhost_user_set_iotlb_callback(struct · line 967
Quoted 10 lines
(quoted diff) +10
-0+ VHOST_USER_GET_CONFIG, msg.request); + return -1; + } + + if (msg.size != config_len) { + error_report("Received bad msg size."); + return -1; + } + + memcpy(config, &msg.payload.config, config_len);There is some complexity here: different virtio devices use different amounts of config space. Devices may append new fields to the config space to support new features.
Quoted 6 lines
Therefore I think the simplest protocol is to always fetch the full 256-byte configuration space. This way the vhost-user slave process can implement feature bits that the master process does not know about.
In other words, I don't think the master process knows how much of the config space is used so it should always request 256 bytes.
Each device knows the max config space size.
vdev->config_len = config_size;Quoted 8 lines
Quoted 7 lines
I see you're referring to the field that is set in:
void virtio_init(VirtIODevice *vdev, const char *name,
uint16_tdevice_id,size_tconfig_size)How does this work for vhost-user where different slave programs may offer different config sizes?
Each Qemu vhost controller e.g: vhost-user-scsi-pci and vhost-user-blk-pci
should has different char devices,
Quoted 1 line
so vhost-slave knows those messages are from vhost-scsi or vhost-blk, of
course, each UNIX domain socket
Quoted 1 line
should be assigned by users with types: vhsot-scsi or vhost-blk.
We're talking about different things. Here is an example illustrating my question:
vhost-user-blk slave A only knows about struct
virtio_blk_configfields up to wce (VIRTIO 1.0). See
http://docs.oasis-open.org/virtio/virtio/v1.0/cs04/virtio-v1.0-cs04.html#x1-
2070004.vhost-user-blk slave B implements struct
virtio_blk_configwith the newnum_queuesfield. See
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/u
api/linux/virtio_blk.h#n56.Slaves A and B use different struct
virtio_blk_configsizes!Which config size should the vhost-master use? There is currently no way to query the size from the slave.
Quoted 6 lines
What should slave programs do when the master requests configuration space data that is the wrong size?
I think the simplest answer is that the master always uses 256 bytes. Slaves also keep the full 256 bytes stored but their device implementation may access fewer bytes.
Quoted 8 lines
Yes, clear now. How about the following configuration:
struct vhost_dev_config { unsigned int offset; unsigned int size; uint8_t config[256]; };The master always uses 256 Bytes, but with additional 2 parameters to locate detailed configuration fields, I think this combined Michael and your comments about this patch.
Yes, that's probably a good solution.
Stefan
Re: [Qemu-devel] [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config space
In reply to Changpeng LiuQuoted 8 lines · 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_SET_CONFIG_FDmessage is added as the event notifier in case virtio config space change in the I/O target.Signed-off-by Changpeng Liu <[email protected]>
I don't much like it that config is getting passed through.
IMO this makes managing things harder not easier.
How about specific messages about specific parts of config space that you want to get from the backend?
Quoted 348 lines
--- docs/interop/vhost-user.txt | 33 +++++++++++++ hw/virtio/vhost-user.c | 97 +++++++++++++++++++++++++++++++++++++++ hw/virtio/vhost.c | 63 +++++++++++++++++++++++++ include/hw/virtio/vhost-backend.h | 8 ++++ include/hw/virtio/vhost.h | 16 +++++++ 5 files changed, 217 insertions(+)docs/interop/vhost-user.txt +33
-0@@ -116,6 +116,10 @@ Depending on the request type, payload can be: - 3: IOTLB invalidate - 4: IOTLB access fail + * Virtio device config space + + 256 Bytes static virito device config space + In QEMU the vhost-user message is implemented with the following struct: typedef struct VhostUserMsg {@@ -129,6 +133,7 @@ typedef struct VhostUserMsg { VhostUserMemory memory; VhostUserLog log; struct vhost_iotlb_msg iotlb; + uint8_t config[256]; }; } QEMU_PACKED VhostUserMsg;@@ -596,6 +601,34 @@ 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 + Master payload: virtio device config space + + Submitted by the vhost-user master to fetch the contents of the virtio + device config space. 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 config space and also can be used for live migration on the + destination host. + +* VHOST_USER_SET_CONFIG_FD + Id: 26 + Equivalent ioctl: N/A + Master payload: N/A + + Sets the notifier file descriptor, which is passed as ancillary data. + Vhost-user slave uses the file descriptor to notify vhost-user master + when the virtio config space changed. The vhost-user master can read + the virtio config space to get the latest update. + Slave message types -------------------hw/virtio/vhost-user.c +97
-0@@ -26,6 +26,11 @@#define VHOST_MEMORY_MAX_NREGIONS 8#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,6 +70,9 @@ 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_SET_CONFIG_FD =26 , VHOST_USER_MAX } VhostUserRequest;@@ -109,6 +117,7 @@ typedef struct VhostUserMsg {VhostUserMemory memory;VhostUserLog log;struct vhost_iotlb_msg iotlb; +uint8_t config[VHOST_USER_MAX_CONFIG_SIZE ]; } payload; }QEMU_PACKED VhostUserMsg;@@ -922,6 +931,91 @@ static void vhost_user_set_iotlb_callback(struct vhost_dev *dev, int enabled)/* No-op as the receive channel is not dedicated to IOTLB messages. */ } +static int vhost_user_get_config (struct vhost_dev *dev,uint8_t *config, +size_t config_len) +{ +VhostUserMsg msg = { + .request =VHOST_USER_GET_CONFIG , + .flags =VHOST_USER_VERSION , + .size = config_len, + }; + +if (config_len ==0 || config_len >VHOST_USER_PAYLOAD_SIZE ) { +error_report ("bad config length" ); +return -1 ; + } + +if (vhost_user_write (dev, &msg,NULL ,0 ) <0 ) { +return -1 ; + } + +if (vhost_user_read (dev, &msg) <0 ) { +return -1 ; + } + +if (msg.request !=VHOST_USER_GET_CONFIG ) { +error_report ("Received unexpected msg type. Expected %d received %d" , +VHOST_USER_GET_CONFIG , msg.request); +return -1 ; + } + +if (msg.size != config_len) { +error_report ("Received bad msg size." ); +return -1 ; + } + +memcpy (config, &msg.payload.config, config_len); + +return 0 ; +} + +static int vhost_user_set_config (struct vhost_dev *dev,const uint8_t *config, +size_t config_len) +{ +bool reply_supported =virtio_has_feature (dev->protocol_features, +VHOST_USER_PROTOCOL_F_REPLY_ACK ); + +VhostUserMsg msg = { + .request =VHOST_USER_SET_CONFIG , + .flags =VHOST_USER_VERSION , + .size = config_len, + }; + +if (reply_supported) { + msg.flags |=VHOST_USER_NEED_REPLY_MASK ; + } + +if (config_len ==0 || config_len >VHOST_USER_PAYLOAD_SIZE ) { +error_report ("bad config length" ); +return -1 ; + } + +memcpy (&msg.payload.config, config, config_len); +if (vhost_user_write (dev, &msg,NULL ,0 ) <0 ) { +return -1 ; + } + +if (reply_supported) { +return process_message_reply (dev, &msg); + } + +return 0 ; +} + +static int vhost_user_set_config_fd (struct vhost_dev *dev,int fd) +{ +VhostUserMsg msg = { + .request =VHOST_USER_SET_CONFIG_FD , + .flags =VHOST_USER_VERSION , + }; + +if (vhost_user_write (dev, &msg, &fd,1 ) <0 ) { +return -1 ; + } + +return 0 ; +} +const VhostOps user_ops = { .backend_type =VHOST_BACKEND_TYPE_USER , .vhost_backend_init = vhost_user_init,@@ -948,4 +1042,7 @@ const VhostOps user_ops = { .vhost_net_set_mtu = vhost_user_net_set_mtu, .vhost_set_iotlb_callback = vhost_user_set_iotlb_callback, .vhost_send_device_iotlb_msg = vhost_user_send_device_iotlb_msg, + .vhost_get_config = vhost_user_get_config, + .vhost_set_config = vhost_user_set_config, + .vhost_set_config_fd = vhost_user_set_config_fd, };hw/virtio/vhost.c +63
-0@@ -1354,6 +1354,9 @@ void vhost_dev_cleanup(struct vhost_dev *hdev)for (i =0 ; i < hdev->nvqs; ++i) {vhost_virtqueue_cleanup (hdev->vqs + i); } +if (hdev->config_ops) { +event_notifier_cleanup (&hdev->config_notifier); + }if (hdev->mem) {/* those are only safe after successful init */ memory_listener_unregister (&hdev->memory_listener);@@ -1501,6 +1504,66 @@ void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits, } } +int vhost_dev_get_config (struct vhost_dev *hdev,uint8_t *config, +size_t config_len) +{ +assert (hdev->vhost_ops); + +if (hdev->vhost_ops->vhost_get_config) { +return hdev->vhost_ops->vhost_get_config (hdev, config, config_len); + } + +return 0 ; +} + +int vhost_dev_set_config (struct vhost_dev *hdev,const uint8_t *config, +size_t config_len) +{ +assert (hdev->vhost_ops); + +if (hdev->vhost_ops->vhost_set_config) { +return hdev->vhost_ops->vhost_set_config (hdev, config, config_len); + } + +return 0 ; +} + +static void vhost_dev_config_notifier_read (EventNotifier *n) +{ + struct vhost_dev *hdev = container_of(n, struct vhost_dev, + config_notifier); + +if (event_notifier_test_and_clear (n)) { +if (hdev->config_ops) { + hdev->config_ops->vhost_dev_config_notifier (hdev); + } + } +} + +int vhost_dev_set_config_notifier (struct vhost_dev *hdev, +const VhostDevConfigOps *ops) +{ +int r, fd; + +assert (hdev->vhost_ops); + + r =event_notifier_init (&hdev->config_notifier,0 ); +if (r <0 ) { +return r; + } + + hdev->config_ops = ops; +event_notifier_set_handler (&hdev->config_notifier, + vhost_dev_config_notifier_read); + +if (hdev->vhost_ops->vhost_set_config_fd) { + fd =event_notifier_get_fd (&hdev->config_notifier); +return hdev->vhost_ops->vhost_set_config_fd (hdev, fd); + } + +return 0 ; +} +/* Host notifiers must be enabled at this point. */ int vhost_dev_start (struct vhost_dev *hdev,VirtIODevice *vdev) {include/hw/virtio/vhost-backend.h +8
-0@@ -84,6 +84,11 @@ typedef void (*vhost_set_iotlb_callback_op)(struct vhost_dev *dev, int enabled);typedef int (*vhost_send_device_iotlb_msg_op )(struct vhost_dev *dev,struct vhost_iotlb_msg *imsg); +typedef int (*vhost_set_config_op )(struct vhost_dev *dev,const uint8_t *config, +size_t config_len); +typedef int (*vhost_get_config_op )(struct vhost_dev *dev,uint8_t *config, +size_t config_len); +typedef int (*vhost_set_config_fd_op )(struct vhost_dev *dev,int fd); typedef struct VhostOps { VhostBackendType backend_type;@@ -118,6 +123,9 @@ typedef struct VhostOps {vhost_vsock_set_running_op vhost_vsock_set_running;vhost_set_iotlb_callback_op vhost_set_iotlb_callback;vhost_send_device_iotlb_msg_op vhost_send_device_iotlb_msg; +vhost_get_config_op vhost_get_config; +vhost_set_config_op vhost_set_config; +vhost_set_config_fd_op vhost_set_config_fd; } VhostOps;extern const VhostOps user_ops;include/hw/virtio/vhost.h +16
-0@@ -46,6 +46,12 @@ struct vhost_iommu {QLIST_ENTRY (vhost_iommu) iommu_next; }; +typedef struct VhostDevConfigOps { +/* Vhost device config space changed callback +*/ +void (*vhost_dev_config_notifier)(struct vhost_dev *dev); +}VhostDevConfigOps ; +struct vhost_memory ;struct vhost_dev {VirtIODevice *vdev;@@ -76,6 +82,8 @@ struct vhost_dev {QLIST_ENTRY (vhost_dev) entry; QLIST_HEAD(, vhost_iommu) iommu_list;IOMMUNotifier n; +EventNotifier config_notifier; +const VhostDevConfigOps *config_ops; }; int vhost_dev_init(struct vhost_dev *hdev, void *opaque,@@ -106,4 +114,12 @@ int vhost_net_set_backend(struct vhost_dev *hdev, struct vhost_vring_file *file);int vhost_device_iotlb_miss (struct vhost_dev *dev,uint64_t iova,int write); +int vhost_dev_get_config (struct vhost_dev *dev,uint8_t *config, +size_t config_len); +int vhost_dev_set_config (struct vhost_dev *dev,const uint8_t *config, +size_t config_len); +/* notifier callback in case vhost device config space changed +*/ +int vhost_dev_set_config_notifier (struct vhost_dev *dev, +const VhostDevConfigOps *ops);#endif Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config space
Quoted 7 lines · Michael S. Tsirkin
Quoted 7 lines
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_SET_CONFIG_FDmessage is added as the event notifier in case virtio config space change in the I/O target.
Quoted 7 lines
Quoted 1 line
Signed-off-by Changpeng Liu <[email protected]>I don't much like it that config is getting passed through.
IMO this makes managing things harder not easier.
How about specific messages about specific parts of config space that you want to get from the backend?
In the case of virtio-blk that would be all of it. Do you have a case in mind where some part of the configuration space is owned by QEMU?
Paolo
Re: [Qemu-devel] [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config space
Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Michael S. Tsirkin
Quoted 8 lines
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_SET_CONFIG_FDmessage is added as the event notifier in case virtio config space change in the I/O target.Signed-off-by Changpeng Liu <[email protected]>I don't much like it that config is getting passed through.
IMO this makes managing things harder not easier.
Quoted 7 lines
Quoted 2 lines
How about specific messages about specific parts of config space that you want to get from the backend?
In the case of virtio-blk that would be all of it. Do you have a case in mind where some part of the configuration space is owned by QEMU?
Paolo
Yes. seg_max
Re: [Qemu-devel] [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config space
Quoted 17 lines · Michael S. Tsirkin
Quoted 16 lines · Paolo Bonzini
Quoted 14 lines · Michael S. Tsirkin
Quoted 8 lines
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_SET_CONFIG_FDmessage is added as the event notifier in case virtio config space change in the I/O target.Signed-off-by Changpeng Liu <[email protected]>I don't much like it that config is getting passed through.
IMO this makes managing things harder not easier.
How about specific messages about specific parts of config space that you want to get from the backend?
Quoted 6 lines
Quoted 4 lines
In the case of virtio-blk that would be all of it. Do you have a case in mind where some part of the configuration space is owned by QEMU?
Paolo
Yes.
seg_max
The seg_max limit is established by whoever reads buffers from the vring and passes them down to the lower layer. For vhost-blk that's the device server, not QEMU.
Paolo
Re: [Qemu-devel] [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config space
Quoted 23 lines · Paolo Bonzini
Quoted 22 lines · Michael S. Tsirkin
Quoted 20 lines · Paolo Bonzini
Quoted 7 lines · Michael S. Tsirkin
Quoted 7 lines
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_SET_CONFIG_FDmessage is added as the event notifier in case virtio config space change in the I/O target.Quoted 7 lines
Quoted 1 line
Signed-off-by Changpeng Liu <[email protected]>I don't much like it that config is getting passed through.
IMO this makes managing things harder not easier.
How about specific messages about specific parts of config space that you want to get from the backend?
In the case of virtio-blk that would be all of it. Do you have a case in mind where some part of the configuration space is owned by QEMU?
Paolo
Quoted 7 lines
Quoted 1 line
Yes.
seg_maxThe
seg_maxlimit is established by whoever reads buffers from the vring and passes them down to the lower layer. For vhost-blk that's the device server, not QEMU.Paolo
Good point. How about num_queues though?
Also why is there SET_CONFIG? Does not look like blk uses it.
And I wonder how do we do it for other devices.
E.g. for net there's a bit in the middle of the
config field that deals with migration.
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config space
Quoted 39 lines
-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Friday, October 20, 2017 8:28 AM
To: Paolo Bonzini <[email protected]>
Cc: Liu, Changpeng <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config spaceQuoted 4 lines · Paolo Bonzini
Quoted 3 lines · Michael S. Tsirkin
Quoted 2 lines · Paolo Bonzini
Quoted 1 line · Michael S. Tsirkin
Quoted 1 line
Add VHOST_USER_GET_CONFIG/VHOST_USER_SET_CONFIG messages
which can be
Quoted 21 lines
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
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_SET_CONFIG_FDmessage is added as the event notifier in case virtio config space change in the I/O target.Signed-off-by Changpeng Liu <[email protected]>I don't much like it that config is getting passed through.
IMO this makes managing things harder not easier.
Quoted 7 lines
Quoted 2 lines
How about specific messages about specific parts of config space that you want to get from the backend?
In the case of virtio-blk that would be all of it. Do you have a case in mind where some part of the configuration space is owned by QEMU?
Paolo
Yes.
seg_max
Quoted 7 lines
Quoted 5 lines
The
seg_maxlimit is established by whoever reads buffers from the vring and passes them down to the lower layer. For vhost-blk that's the device server, not QEMU.Paolo
Good point. How about
num_queuesthough?
num_queues is part of virtio_blk config, vhost-user slave can set it, and Qemu driver can rewrite it if user want less IO queues.
Quoted 2 lines
Also why is there
SET_CONFIG? Does not look like blk uses it.
Only one possible usage when disable write cache to vhost-user slave device.
Quoted 5 lines
And I wonder how do we do it for other devices.
E.g. for net there's a bit in the middle of the
config field that deals with migration.
Well, I'm okay to make those messages only valid for virtio block device, because it's enough for virtio block to be started with vhost-user slave target.
Quoted 4 lines
--
MST
Re: [Qemu-devel] [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config space
Quoted 43 lines · Changpeng
Quoted 43 lines
-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Friday, October 20, 2017 8:28 AM
To: Paolo Bonzini <[email protected]>
Cc: Liu, Changpeng <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config spaceQuoted 4 lines · Paolo Bonzini
Quoted 3 lines · Michael S. Tsirkin
Quoted 2 lines · Paolo Bonzini
Quoted 1 line · Michael S. Tsirkin
Quoted 1 line
Add VHOST_USER_GET_CONFIG/VHOST_USER_SET_CONFIG messages
which can be
Quoted 25 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 7 lines
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_SET_CONFIG_FDmessage is added as the event notifier in case virtio config space change in the I/O target.Signed-off-by Changpeng Liu <[email protected]>I don't much like it that config is getting passed through.
IMO this makes managing things harder not easier.
How about specific messages about specific parts of config space that you want to get from the backend?
Quoted 6 lines
Quoted 4 lines
In the case of virtio-blk that would be all of it. Do you have a case in mind where some part of the configuration space is owned by QEMU?
Paolo
Yes.
seg_maxThe
seg_maxlimit is established by whoever reads buffers from the vring and passes them down to the lower layer. For vhost-blk that's the device server, not QEMU.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Paolo
Good point. How about
num_queuesthough?
num_queuesis part ofvirtio_blkconfig, vhost-user slave can set it, and Qemu driver can rewrite it if user want less IO queues.
Fundamentally QEMU needs to support this # of queues for this device.
So whenever QEMU doesn't always expose config space as-is, need to document the exact semantics.
Also, does backend need to know?
Quoted 3 lines
Quoted 2 lines
Also why is there
SET_CONFIG? Does not look like blk uses it.Only one possible usage when disable write cache to vhost-user slave device.
Again need to add documentation what can be written.
Quoted 7 lines
Quoted 5 lines
And I wonder how do we do it for other devices.
E.g. for net there's a bit in the middle of the
config field that deals with migration.Well, I'm okay to make those messages only valid for virtio block device, because it's enough for virtio block to be started with vhost-user slave target.
OK but I'd rather make them at least somewhat generic so we can reuse them down the road. It looks like adding offset/size pair would solve most of the issues. Thoughts?
Quoted 4 lines
Quoted 4 lines
--
MST
Re: [Qemu-devel] [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config space
Quoted 60 lines
-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Friday, October 20, 2017 10:12 AM
To: Liu, Changpeng <[email protected]>
Cc: Paolo Bonzini <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config spaceQuoted 8 lines · Changpeng
Quoted 8 lines
-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Friday, October 20, 2017 8:28 AM
To: Paolo Bonzini <[email protected]>
Cc: Liu, Changpeng <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected];Harris,
Quoted 38 lines
Quoted 38 lines
James R <[email protected]>
Subject: Re: [PATCH v4 1/4] vhost-user: add new vhost user messages to support virtio config spaceQuoted 4 lines · Paolo Bonzini
Quoted 3 lines · Michael S. Tsirkin
Quoted 2 lines · Paolo Bonzini
Quoted 1 line · Michael S. Tsirkin
Quoted 1 line
Add VHOST_USER_GET_CONFIG/VHOST_USER_SET_CONFIG messages
which can be
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 6 lines
Quoted 6 lines
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_SET_CONFIG_FDmessage is added as the event notifier in case virtio config space change in the I/O target.Quoted 7 lines
Quoted 1 line
Signed-off-by Changpeng Liu <[email protected]>I don't much like it that config is getting passed through.
IMO this makes managing things harder not easier.
How about specific messages about specific parts of config space that you want to get from the backend?
In the case of virtio-blk that would be all of it. Do you have a case in mind where some part of the configuration space is owned by QEMU?
Paolo
Quoted 7 lines
Quoted 1 line
Yes.
seg_maxThe
seg_maxlimit is established by whoever reads buffers from the vring and passes them down to the lower layer. For vhost-blk that's the device server, not QEMU.Paolo
Good point. How about
num_queuesthough?
Quoted 8 lines
Quoted 2 lines
num_queuesis part ofvirtio_blkconfig, vhost-user slave can set it, and Qemu driver can rewrite it if user want less IO queues.Fundamentally QEMU needs to support this # of queues for this device.
So whenever QEMU doesn't always expose config space as-is, need to document the exact semantics.
Agreed, Qemu vhost block driver should always has a default value, so I also added the value as one of the parameters for vhost block driver.
Quoted 2 lines
Also, does backend need to know?
vhost-user slave does know how many queues are used, because vhost-user messages such as SET_VRING_CALL/KICK are related with queues. Here the idea is vhost-user slave provides the maximum io queues supported, and Qemu users can specify lower io queues.
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Also why is there
SET_CONFIG? Does not look like blk uses it.Only one possible usage when disable write cache to vhost-user slave device.
Again need to add documentation what can be written.
Agreed.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
And I wonder how do we do it for other devices.
E.g. for net there's a bit in the middle of the config field that deals with migration.
Quoted 7 lines
Quoted 1 line
Well, I'm okay to make those messages only valid for virtio block device, because
it's enough
Quoted 1 line
for virtio block to be started with vhost-user slave target.
OK but I'd rather make them at least somewhat generic so we can reuse them down the road. It looks like adding offset/size pair would solve most of the issues. Thoughts?
Do you mean SET_CONFIG message followed with offset/size to let vhost-user slave Know which field the master want to change? Yes, sounds good to me.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
--
MST
PATCH v4 2/4 vhost-user-blk: introduce a new vhost-user-blk host device
In reply to Changpeng LiuThis commit introduces a new vhost-user device for block, it uses a chardev to connect with the backend, same with Qemu virito-blk device, Guest OS still uses the virtio-blk frontend driver.
To use it, start Qemu with command line like this:
qemu-system-x86_64 \
-chardev socket,id=char0,path=/path/vhost.socket \
-device vhost-user-blk-pci,chardev=char0,num_queues=1, \
bootindex=2... \Users can use different parameters for num_queues and bootindex.
Different with exist Qemu virtio-blk host device, it makes more easy for users to implement their own I/O processing logic, such as all user space I/O stack against hardware block device. It uses the new vhost messages(VHOST_USER_GET_CONFIG) to get block virtio config information from backend process.
--- configure | 11 ++ hw/block/Makefile.objs | 3 + hw/block/vhost-user-blk.c | 360 +++++++++++++++++++++++++++++++++++++ hw/virtio/virtio-pci.c | 55 ++++++ hw/virtio/virtio-pci.h | 18 ++ include/hw/virtio/vhost-user-blk.h | 40 +++++ 6 files changed, 487 insertions(+) create mode 100644 hw/block/vhost-user-blk.c create mode 100644 include/hw/virtio/vhost-user-blk.h
configure +11 -0
@@ -318,6 +318,7 @@ tcg="yes" vhost_net="no" vhost_scsi="no" +vhost_user_blk="no" vhost_vsock="no" vhost_user="" kvm="no"
@@ -782,6 +783,7 @@ Linux) kvm="yes" vhost_net="yes" vhost_scsi="yes" + vhost_user_blk="yes" vhost_vsock="yes" QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QEMU_INCLUDES" supported_os="yes"
@@ -1139,6 +1141,10 @@ for opt do ;; --enable-vhost-scsi) vhost_scsi="yes" ;; + --disable-vhost-user-blk) vhost_user_blk="no" + ;; + --enable-vhost-user-blk) vhost_user_blk="yes" + ;; --disable-vhost-vsock) vhost_vsock="no" ;; --enable-vhost-vsock) vhost_vsock="yes"
@@ -1511,6 +1517,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-user-blk VM virtio-blk acceleration in user space spice spice rbd rados block device (rbd) libiscsi iscsi support
@@ -5417,6 +5424,7 @@ echo "posix_madvise $posix_madvise" echo "libcap-ng support $cap_ng" echo "vhost-net support $vhost_net" echo "vhost-scsi support $vhost_scsi" +echo "vhost-user-blk support $vhost_user_blk" echo "vhost-vsock support $vhost_vsock" echo "vhost-user support $vhost_user" echo "Trace backends $trace_backends"
@@ -5845,6 +5853,9 @@ fi if test "$vhost_scsi" = "yes" ; then echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak fi +if test "$vhost_user_blk" = "yes" -a "$vhost_user" = "yes"; then + echo "CONFIG_VHOST_USER_BLK=y" >> $config_host_mak +fi if test "$vhost_net" = "yes" -a "$vhost_user" = "yes"; then echo "CONFIG_VHOST_NET_USED=y" >> $config_host_mak fi
hw/block/Makefile.objs +3 -0
@@ -13,3 +13,6 @@ obj-$(CONFIG_SH4) += tc58128.o obj-$(CONFIG_VIRTIO) += virtio-blk.o obj-$(CONFIG_VIRTIO) += dataplane/ +ifeq ($(CONFIG_VIRTIO),y) +obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk.o +endif
hw/block/vhost-user-blk.c new file +360 -0
360 lines not on this page · raw message
hw/virtio/virtio-pci.c +55 -0
67 lines not on this page · raw message
hw/virtio/virtio-pci.h +18 -0
@@ -27,6 +27,9 @@#include "hw/virtio/virtio-gpu.h" #include "hw/virtio/virtio-crypto.h" #include "hw/virtio/vhost-user-scsi.h" +#ifdef CONFIG_VHOST_USER_BLK +#include "hw/virtio/vhost-user-blk.h" +#endif #ifdef CONFIG_VIRTFS #include "hw/9pfs/virtio-9p.h"
@@ -46,6 +49,7 @@ typedef struct VirtIOSerialPCI VirtIOSerialPCI;typedef struct VirtIONetPCI VirtIONetPCI ;typedef struct VHostSCSIPCI VHostSCSIPCI ;typedef struct VHostUserSCSIPCI VHostUserSCSIPCI ; +typedef struct VHostUserBlkPCI VHostUserBlkPCI ;typedef struct VirtIORngPCI VirtIORngPCI ;typedef struct VirtIOInputPCI VirtIOInputPCI ;typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI ;
@@ -244,6 +248,20 @@ struct VHostUserSCSIPCI {VHostUserSCSI vdev; }; +#ifdef CONFIG_VHOST_USER_BLK +/* +* vhost-user-blk-pci: This extends VirtioPCIProxy. +*/ +#define TYPE_VHOST_USER_BLK_PCI "vhost-user-blk-pci" +#define VHOST_USER_BLK_PCI (obj) \ + OBJECT_CHECK(VHostUserBlkPCI, (obj), TYPE_VHOST_USER_BLK_PCI) + +struct VHostUserBlkPCI { +VirtIOPCIProxy parent_obj; +VHostUserBlk vdev; +}; +#endif +/* * virtio-blk-pci: This extends VirtioPCIProxy. */
include/hw/virtio/vhost-user-blk.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* vhost-user-blk host device +* Copyright IBM, Corp. 2011 +* Copyright(C) 2017 Intel Corporation. +* +* Authors: +* Stefan Hajnoczi <[email protected]> +* Changpeng Liu <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2 or later. +* See the COPYING.LIB file in the top-level directory. +* +*/ + +#ifndef VHOST_USER_BLK_H +#define VHOST_USER_BLK_H + +#include "standard-headers/linux/virtio_blk.h" +#include "qemu-common.h" +#include "hw/qdev.h" +#include "hw/block/block.h" +#include "chardev/char-fe.h" +#include "hw/virtio/vhost.h" + +#define TYPE_VHOST_USER_BLK "vhost-user-blk" +#define VHOST_USER_BLK (obj) \ + OBJECT_CHECK(VHostUserBlk, (obj), TYPE_VHOST_USER_BLK) + +typedef struct VHostUserBlk { +VirtIODevice parent_obj; +CharBackend chardev; +int32_t bootindex; +uint64_t host_features; +struct virtio_blk_config blkcfg; +uint16_t num_queues; +uint32_t queue_size; +struct vhost_dev dev; +}VHostUserBlk ; + +#endif
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host device
Quoted 11 lines · Changpeng Liu
;; --enable-vhost-scsi) vhost_scsi="yes" ;;configure +4
-0+ --disable-vhost-user-blk) vhost_user_blk="no" + ;; + --enable-vhost-user-blk) vhost_user_blk="yes" + ;; --disable-vhost-vsock) vhost_vsock="no" ;; --enable-vhost-vsock) vhost_vsock="yes"
configure disabled with --disable-FEATURE, default is enabled if available: · line 1520
Quoted 4 lines
configure +1
-0@@ -1511,6 +1517,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-user-blk VM virtio-blk acceleration in user space
Please use default-configs instead of a new configure switch. See how CONFIG_VHOST_USER_SCSI is used in default-configs/pci.mak and default-configs/s390x-softmmu.mak.
hw/block/vhost-user-blk.c line 35
Quoted 8 lines
hw/block/vhost-user-blk.c new file +7
-0+static const int user_feature_bits[] = { +VIRTIO_BLK_F_SIZE_MAX , +VIRTIO_BLK_F_SEG_MAX , +VIRTIO_BLK_F_GEOMETRY , +VIRTIO_BLK_F_BLK_SIZE , +VIRTIO_BLK_F_TOPOLOGY , +VIRTIO_BLK_F_SCSI ,
Please omit VIRTIO_BLK_F_SCSI, it's a legacy option that is not anymore part of virtio 1.0.
hw/block/vhost-user-blk.c line 39
Quoted 4 lines
hw/block/vhost-user-blk.c new file +4
-0+VIRTIO_BLK_F_MQ , +VIRTIO_BLK_F_RO , +VIRTIO_BLK_F_FLUSH , + VIRTIO_BLK_F_BARRIER,
Same for VIRTIO_BLK_F_BARRIER.
Quoted 1 line
+
VIRTIO_BLK_F_WCE,
And VIRTIO_BLK_F_WCE is the same as VIRTIO_BLK_F_FLUSH, so it can be removed too. Please include VIRTIO_BLK_F_CONFIG_WCE instead, since you are supporting it in vhost_user_blk_set_config.
Quoted 6 lines
hw/block/vhost-user-blk.c new file +6
-0+VIRTIO_F_VERSION_1 , +VIRTIO_RING_F_INDIRECT_DESC , +VIRTIO_RING_F_EVENT_IDX , +VIRTIO_F_NOTIFY_ON_EMPTY , + VHOST_INVALID_FEATURE_BIT +};
hw/block/vhost-user-blk.c line 97
Quoted 10 lines
hw/block/vhost-user-blk.c new file +8
-0+static const TypeInfo vhost_user_blk_info = { + .name =TYPE_VHOST_USER_BLK , + .parent =TYPE_VIRTIO_DEVICE , + .instance_size =sizeof (VHostUserBlk), + .instance_init = vhost_user_blk_instance_init, + .class_init = vhost_user_blk_class_init, +}; +
There is some code duplication, so maybe it's worth introducing a common superclass like TYPE_VIRTIO_SCSI_COMMON. I'll let others comment on whether this is a requirement.
Paolo
Re: [Qemu-devel] [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host device
Quoted 24 lines
-----Original Message-----
From: Paolo Bonzini [mailto:[email protected]]
Sent: Thursday, October 19, 2017 7:33 PM
To: Liu, Changpeng <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host deviceconfigure disabled with --disable-FEATURE, default is enabled if
Quoted 11 lines · Changpeng Liu
;; --enable-vhost-scsi) vhost_scsi="yes" ;;configure +4
-0+ --disable-vhost-user-blk) vhost_user_blk="no" + ;; + --enable-vhost-user-blk) vhost_user_blk="yes" + ;; --disable-vhost-vsock) vhost_vsock="no" ;; --enable-vhost-vsock) vhost_vsock="yes"@@ -1511,6 +1517,7 @@ disabled with --disable-FEATURE, default is enabled ifavailable:
Quoted 8 lines
configure disabled with --disable-FEATURE, default is enabled if available: · line 1520
Quoted 4 lines
configure +1
-0cap-ng libcap-ng support attr attr and xattr support vhost-net vhost-net acceleration support + vhost-user-blk VM virtio-blk acceleration in user spacePlease use default-configs instead of a new configure switch. See how
CONFIG_VHOST_USER_SCSIis used in default-configs/pci.mak and default-configs/s390x-softmmu.mak.
Ok, thanks.
Quoted 10 lines
hw/block/vhost-user-blk.c line 35
Quoted 9 lines
hw/block/vhost-user-blk.c new file +7
-0+static const int user_feature_bits[] = { +VIRTIO_BLK_F_SIZE_MAX , +VIRTIO_BLK_F_SEG_MAX , +VIRTIO_BLK_F_GEOMETRY , +VIRTIO_BLK_F_BLK_SIZE , +VIRTIO_BLK_F_TOPOLOGY , +VIRTIO_BLK_F_SCSI ,
Quoted 2 lines
Please omit
VIRTIO_BLK_F_SCSI, it's a legacy option that is not anymore part of virtio 1.0.
ok
Quoted 6 lines
hw/block/vhost-user-blk.c line 39
Quoted 5 lines
hw/block/vhost-user-blk.c new file +4
-0+VIRTIO_BLK_F_MQ , +VIRTIO_BLK_F_RO , +VIRTIO_BLK_F_FLUSH , + VIRTIO_BLK_F_BARRIER,
Quoted 7 lines
Same for
VIRTIO_BLK_F_BARRIER.Quoted 1 line
+
VIRTIO_BLK_F_WCE,And
VIRTIO_BLK_F_WCEis the same asVIRTIO_BLK_F_FLUSH, so it can be removed too. Please includeVIRTIO_BLK_F_CONFIG_WCEinstead, since you are supporting it invhost_user_blk_set_config.
Ok.
Quoted 23 lines
Quoted 7 lines
hw/block/vhost-user-blk.c new file +6
-0+VIRTIO_F_VERSION_1 , +VIRTIO_RING_F_INDIRECT_DESC , +VIRTIO_RING_F_EVENT_IDX , +VIRTIO_F_NOTIFY_ON_EMPTY , + VHOST_INVALID_FEATURE_BIT +};hw/block/vhost-user-blk.c line 97
Quoted 10 lines
hw/block/vhost-user-blk.c new file +8
-0+static const TypeInfo vhost_user_blk_info = { + .name =TYPE_VHOST_USER_BLK , + .parent =TYPE_VIRTIO_DEVICE , + .instance_size =sizeof (VHostUserBlk), + .instance_init = vhost_user_blk_instance_init, + .class_init = vhost_user_blk_class_init, +}; +There is some code duplication, so maybe it's worth introducing a common superclass like
TYPE_VIRTIO_SCSI_COMMON. I'll let others comment on whether this is a requirement.Paolo
Re: [Qemu-devel] [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host device
In reply to Changpeng LiuQuoted 105 lines · Changpeng Liu
This commit introduces a new vhost-user device for block, it uses a chardev to connect with the backend, same with Qemu virito-blk device, Guest OS still uses the virtio-blk frontend driver.
To use it, start Qemu with command line like this:
qemu-system-x86_64 \ -chardev socket,id=char0,path=/path/vhost.socket \ -device vhost-user-blk-pci,chardev=char0,num_queues=1, \ bootindex=2... \Users can use different parameters for
num_queuesandbootindex.Different with exist Qemu virtio-blk host device, it makes more easy for users to implement their own I/O processing logic, such as all user space I/O stack against hardware block device. It uses the new vhost
messages(VHOST_USER_GET_CONFIG)to get block virtio config information from backend process.Signed-off-by Changpeng Liu <[email protected]>--- configure | 11 ++ hw/block/Makefile.objs | 3 + hw/block/vhost-user-blk.c | 360 +++++++++++++++++++++++++++++++++++++ hw/virtio/virtio-pci.c | 55 ++++++ hw/virtio/virtio-pci.h | 18 ++ include/hw/virtio/vhost-user-blk.h | 40 +++++ 6 files changed, 487 insertions(+) create mode 100644 hw/block/vhost-user-blk.c create mode 100644 include/hw/virtio/vhost-user-blk.hconfigure +11
-0@@ -318,6 +318,7 @@ tcg="yes" vhost_net="no" vhost_scsi="no" +vhost_user_blk="no" vhost_vsock="no" vhost_user="" kvm="no"@@ -782,6 +783,7 @@ Linux) kvm="yes" vhost_net="yes" vhost_scsi="yes" + vhost_user_blk="yes" vhost_vsock="yes" QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers $QEMU_INCLUDES" supported_os="yes"@@ -1139,6 +1141,10 @@ for opt do ;; --enable-vhost-scsi) vhost_scsi="yes" ;; + --disable-vhost-user-blk) vhost_user_blk="no" + ;; + --enable-vhost-user-blk) vhost_user_blk="yes" + ;; --disable-vhost-vsock) vhost_vsock="no" ;; --enable-vhost-vsock) vhost_vsock="yes"@@ -1511,6 +1517,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-user-blk VM virtio-blk acceleration in user space spice spice rbd rados block device (rbd) libiscsi iscsi support@@ -5417,6 +5424,7 @@ echo "posix_madvise $posix_madvise" echo "libcap-ng support $cap_ng" echo "vhost-net support $vhost_net" echo "vhost-scsi support $vhost_scsi" +echo "vhost-user-blk support $vhost_user_blk" echo "vhost-vsock support $vhost_vsock" echo "vhost-user support $vhost_user" echo "Trace backends $trace_backends"@@ -5845,6 +5853,9 @@ fi if test "$vhost_scsi" = "yes" ; then echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak fi +if test "$vhost_user_blk" = "yes" -a "$vhost_user" = "yes"; then + echo "CONFIG_VHOST_USER_BLK=y" >> $config_host_mak +fi if test "$vhost_net" = "yes" -a "$vhost_user" = "yes"; then echo "CONFIG_VHOST_NET_USED=y" >> $config_host_mak fihw/block/Makefile.objs +3
-0@@ -13,3 +13,6 @@ obj-$(CONFIG_SH4) += tc58128.o obj-$(CONFIG_VIRTIO) += virtio-blk.o obj-$(CONFIG_VIRTIO) += dataplane/ +ifeq ($(CONFIG_VIRTIO),y) +obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk.o +endifhw/block/vhost-user-blk.c new file +0
-0
hw/block/vhost-user-blk.c line 9
Quoted 9 lines
hw/block/vhost-user-blk.c new file +9
-0@@ -0,0 +1,360 @@ +/* +* vhost-user-blk host device +* +* Copyright IBM, Corp. 2011 +* Copyright(C) 2017 Intel Corporation. +* +* Authors: +* Stefan Hajnoczi <[email protected]> +* Changpeng Liu <[email protected]>
This gives the impression that IBM originally authored this code but little copied code is actually in this file. Feel free to put your own copyright and authorship information at the top and then add a statement like "Based on foo.c, Copyright IBM, Corp. 2011" instead. That way it's clear that this is new code that you wrote with reference to the original file you used as a starting point.
Quoted 18 lines
hw/block/vhost-user-blk.c new file +18
-0+static Property vhost_user_blk_properties[] = { +DEFINE_PROP_CHR ("chardev" , VHostUserBlk, chardev), +DEFINE_PROP_UINT16 ("num_queues" , VHostUserBlk, num_queues,1 ), +DEFINE_PROP_UINT32 ("queue_size" , VHostUserBlk, queue_size,128 ), +DEFINE_PROP_BIT64 ("f_size_max" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SIZE_MAX , true), +DEFINE_PROP_BIT64 ("f_sizemax" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SIZE_MAX , true), +DEFINE_PROP_BIT64 ("f_segmax" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SEG_MAX , true), +DEFINE_PROP_BIT64 ("f_geometry" , VHostUserBlk, host_features, +VIRTIO_BLK_F_GEOMETRY , true), +DEFINE_PROP_BIT64 ("f_readonly" , VHostUserBlk, host_features, +VIRTIO_BLK_F_RO , false), +DEFINE_PROP_BIT64 ("f_blocksize" , VHostUserBlk, host_features, +VIRTIO_BLK_F_BLK_SIZE , true), +DEFINE_PROP_BIT64 ("f_topology" , VHostUserBlk, host_features, +VIRTIO_BLK_F_TOPOLOGY , true),
hw/block/vhost-user-blk.c line 327
Quoted 10 lines
hw/block/vhost-user-blk.c new file +10
-0+DEFINE_PROP_BIT64 ("f_multiqueue" , VHostUserBlk, host_features, +VIRTIO_BLK_F_MQ , true), +DEFINE_PROP_BIT64 ("f_flush" , VHostUserBlk, host_features, +VIRTIO_BLK_F_FLUSH , true), +DEFINE_PROP_BIT64 ("f_barrier" , VHostUserBlk, host_features, +VIRTIO_BLK_F_BARRIER , false), +DEFINE_PROP_BIT64 ("f_scsi" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SCSI , false), +DEFINE_PROP_BIT64 ("f_wce" , VHostUserBlk, host_features, + VIRTIO_BLK_F_WCE, false),
Please explain how feature negotation works. The vhost-user slave advertises support features in the return value from VHOST_USER_GET_FEATURES. How does this additional feature mask work and why is it useful?
Re: [Qemu-devel] [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host device
Quoted 129 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Thursday, October 19, 2017 11:18 PM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host deviceQuoted 19 lines · Changpeng Liu
This commit introduces a new vhost-user device for block, it uses a chardev to connect with the backend, same with Qemu virito-blk device, Guest OS still uses the virtio-blk frontend driver.
To use it, start Qemu with command line like this:
qemu-system-x86_64 \ -chardev socket,id=char0,path=/path/vhost.socket \ -device vhost-user-blk-pci,chardev=char0,num_queues=1, \ bootindex=2... \Users can use different parameters for
num_queuesandbootindex.Different with exist Qemu virtio-blk host device, it makes more easy for users to implement their own I/O processing logic, such as all user space I/O stack against hardware block device. It uses the new vhost
messages(VHOST_USER_GET_CONFIG)to get block virtio config information from backend process.Quoted 5 lines
Signed-off-by Changpeng Liu <[email protected]>--- configure | 11 ++ hw/block/Makefile.objs | 3 + hw/block/vhost-user-blk.c | 360+++++++++++++++++++++++++++++++++++++
Quoted 20 lines
hw/virtio/virtio-pci.c | 55 ++++++ hw/virtio/virtio-pci.h | 18 ++ include/hw/virtio/vhost-user-blk.h | 40 +++++ 6 files changed, 487 insertions(+) create mode 100644 hw/block/vhost-user-blk.c create mode 100644 include/hw/virtio/vhost-user-blk.hconfigure +1
-0@@ -318,6 +318,7 @@ tcg="yes" vhost_net="no" vhost_scsi="no" +vhost_user_blk="no" vhost_vsock="no" vhost_user="" kvm="no"configure Linux) · line 788
Quoted 6 lines
configure +1
-0@@ -782,6 +783,7 @@ Linux) kvm="yes" vhost_net="yes" vhost_scsi="yes" + vhost_user_blk="yes" vhost_vsock="yes" QEMU_INCLUDES="-I\$(SRC_PATH)/linux-headers -I$(pwd)/linux-headers$QEMU_INCLUDES"
configure disabled with --disable-FEATURE, default is enabled if
Quoted 13 lines
configure +4
-0supported_os="yes"@@ -1139,6 +1141,10 @@ for opt do ;; --enable-vhost-scsi) vhost_scsi="yes" ;; + --disable-vhost-user-blk) vhost_user_blk="no" + ;; + --enable-vhost-user-blk) vhost_user_blk="yes" + ;; --disable-vhost-vsock) vhost_vsock="no" ;; --enable-vhost-vsock) vhost_vsock="yes"@@ -1511,6 +1517,7 @@ disabled with --disable-FEATURE, default is enabled ifavailable:
Quoted 50 lines
configure +5
-0cap-ng libcap-ng support attr attr and xattr support vhost-net vhost-net acceleration support + vhost-user-blk VM virtio-blk acceleration in user space spice spice rbd rados block device (rbd) libiscsi iscsi support@@ -5417,6 +5424,7 @@ echo "posix_madvise $posix_madvise" echo "libcap-ng support $cap_ng" echo "vhost-net support $vhost_net" echo "vhost-scsi support $vhost_scsi" +echo "vhost-user-blk support $vhost_user_blk" echo "vhost-vsock support $vhost_vsock" echo "vhost-user support $vhost_user" echo "Trace backends $trace_backends"@@ -5845,6 +5853,9 @@ fi if test "$vhost_scsi" = "yes" ; then echo "CONFIG_VHOST_SCSI=y" >> $config_host_mak fi +if test "$vhost_user_blk" = "yes" -a "$vhost_user" = "yes"; then + echo "CONFIG_VHOST_USER_BLK=y" >> $config_host_mak +fi if test "$vhost_net" = "yes" -a "$vhost_user" = "yes"; then echo "CONFIG_VHOST_NET_USED=y" >> $config_host_mak fihw/block/Makefile.objs +3
-0@@ -13,3 +13,6 @@ obj-$(CONFIG_SH4) += tc58128.o obj-$(CONFIG_VIRTIO) += virtio-blk.o obj-$(CONFIG_VIRTIO) += dataplane/ +ifeq ($(CONFIG_VIRTIO),y) +obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk.o +endifhw/block/vhost-user-blk.c new file +8
-0@@ -0,0 +1,360 @@ +/* +* vhost-user-blk host device +* +* Copyright IBM, Corp. 2011 +* Copyright(C) 2017 Intel Corporation. +* +* Authors: +* Stefan Hajnoczi <[email protected]>
Quoted 8 lines
hw/block/vhost-user-blk.c line 9
Quoted 1 line
hw/block/vhost-user-blk.c new file +1
-0+* Changpeng Liu <[email protected]> This gives the impression that IBM originally authored this code but little copied code is actually in this file. Feel free to put your own copyright and authorship information at the top and then add a statement like "Based on
foo.c, Copyright IBM, Corp. 2011" instead. That way it's clear that this is new code that you wrote with reference to the original file you used as a starting point.
Ok, will change it, thanks.
Quoted 30 lines
Quoted 19 lines
hw/block/vhost-user-blk.c new file +18
-0+static Property vhost_user_blk_properties[] = { +DEFINE_PROP_CHR ("chardev" , VHostUserBlk, chardev), +DEFINE_PROP_UINT16 ("num_queues" , VHostUserBlk, num_queues,1 ), +DEFINE_PROP_UINT32 ("queue_size" , VHostUserBlk, queue_size,128 ), +DEFINE_PROP_BIT64 ("f_size_max" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SIZE_MAX , true), +DEFINE_PROP_BIT64 ("f_sizemax" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SIZE_MAX , true), +DEFINE_PROP_BIT64 ("f_segmax" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SEG_MAX , true), +DEFINE_PROP_BIT64 ("f_geometry" , VHostUserBlk, host_features, +VIRTIO_BLK_F_GEOMETRY , true), +DEFINE_PROP_BIT64 ("f_readonly" , VHostUserBlk, host_features, +VIRTIO_BLK_F_RO , false), +DEFINE_PROP_BIT64 ("f_blocksize" , VHostUserBlk, host_features, +VIRTIO_BLK_F_BLK_SIZE , true), +DEFINE_PROP_BIT64 ("f_topology" , VHostUserBlk, host_features, +VIRTIO_BLK_F_TOPOLOGY , true),hw/block/vhost-user-blk.c line 327
Quoted 10 lines
hw/block/vhost-user-blk.c new file +10
-0+DEFINE_PROP_BIT64 ("f_multiqueue" , VHostUserBlk, host_features, +VIRTIO_BLK_F_MQ , true), +DEFINE_PROP_BIT64 ("f_flush" , VHostUserBlk, host_features, +VIRTIO_BLK_F_FLUSH , true), +DEFINE_PROP_BIT64 ("f_barrier" , VHostUserBlk, host_features, +VIRTIO_BLK_F_BARRIER , false), +DEFINE_PROP_BIT64 ("f_scsi" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SCSI , false), +DEFINE_PROP_BIT64 ("f_wce" , VHostUserBlk, host_features, + VIRTIO_BLK_F_WCE, false),
Quoted 4 lines
Please explain how feature negotation works. The vhost-user slave advertises support features in the return value from
VHOST_USER_GET_FEATURES. How does this additional feature mask work and why is it useful?
According to Paolo's previous comments, VIRTIO_BLK_F_WCE/ VIRTIO_BLK_F_SCSI/ VIRTIO_BLK_F_BARRIER should be removed. Here I added all the feature flags just want to avoid the case that vhost-user slave target can support but Qemu vhost block driver cannot support it.
Re: [Qemu-devel] [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host device
Quoted 29 lines · Changpeng
Quoted 29 lines
Quoted 28 lines
hw/block/vhost-user-blk.c new file +28
-0+static Property vhost_user_blk_properties[] = { +DEFINE_PROP_CHR ("chardev" , VHostUserBlk, chardev), +DEFINE_PROP_UINT16 ("num_queues" , VHostUserBlk, num_queues,1 ), +DEFINE_PROP_UINT32 ("queue_size" , VHostUserBlk, queue_size,128 ), +DEFINE_PROP_BIT64 ("f_size_max" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SIZE_MAX , true), +DEFINE_PROP_BIT64 ("f_sizemax" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SIZE_MAX , true), +DEFINE_PROP_BIT64 ("f_segmax" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SEG_MAX , true), +DEFINE_PROP_BIT64 ("f_geometry" , VHostUserBlk, host_features, +VIRTIO_BLK_F_GEOMETRY , true), +DEFINE_PROP_BIT64 ("f_readonly" , VHostUserBlk, host_features, +VIRTIO_BLK_F_RO , false), +DEFINE_PROP_BIT64 ("f_blocksize" , VHostUserBlk, host_features, +VIRTIO_BLK_F_BLK_SIZE , true), +DEFINE_PROP_BIT64 ("f_topology" , VHostUserBlk, host_features, +VIRTIO_BLK_F_TOPOLOGY , true), +DEFINE_PROP_BIT64 ("f_multiqueue" , VHostUserBlk, host_features, +VIRTIO_BLK_F_MQ , true), +DEFINE_PROP_BIT64 ("f_flush" , VHostUserBlk, host_features, +VIRTIO_BLK_F_FLUSH , true), +DEFINE_PROP_BIT64 ("f_barrier" , VHostUserBlk, host_features, +VIRTIO_BLK_F_BARRIER , false), +DEFINE_PROP_BIT64 ("f_scsi" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SCSI , false), +DEFINE_PROP_BIT64 ("f_wce" , VHostUserBlk, host_features, +VIRTIO_BLK_F_WCE , false),
Quoted 7 lines
Quoted 4 lines
Please explain how feature negotation works. The vhost-user slave advertises support features in the return value from
VHOST_USER_GET_FEATURES. How does this additional feature mask work and why is it useful?According to Paolo's previous comments, VIRTIO_BLK_F_WCE/ VIRTIO_BLK_F_SCSI/
VIRTIO_BLK_F_BARRIERshould be removed. Here I added all the feature flags just want to avoid the case that vhost-user slave target can support but Qemu vhost block driver cannot support it.
Please explain a bit more how these options can be used.
When I looked at the vhost code it seemed like the vhost slave can report any feature bits it wishes (even things QEMU doesn't know about). What is the purpose of override some of the feature bits on the QEMU command-line?
Stefan
Re: [Qemu-devel] [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host device
Quoted 51 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Friday, October 20, 2017 5:55 PM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host deviceQuoted 29 lines · Changpeng
Quoted 29 lines
Quoted 28 lines
hw/block/vhost-user-blk.c new file +28
-0+static Property vhost_user_blk_properties[] = { +DEFINE_PROP_CHR ("chardev" , VHostUserBlk, chardev), +DEFINE_PROP_UINT16 ("num_queues" , VHostUserBlk, num_queues,1 ), +DEFINE_PROP_UINT32 ("queue_size" , VHostUserBlk, queue_size,128 ), +DEFINE_PROP_BIT64 ("f_size_max" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SIZE_MAX , true), +DEFINE_PROP_BIT64 ("f_sizemax" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SIZE_MAX , true), +DEFINE_PROP_BIT64 ("f_segmax" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SEG_MAX , true), +DEFINE_PROP_BIT64 ("f_geometry" , VHostUserBlk, host_features, +VIRTIO_BLK_F_GEOMETRY , true), +DEFINE_PROP_BIT64 ("f_readonly" , VHostUserBlk, host_features, +VIRTIO_BLK_F_RO , false), +DEFINE_PROP_BIT64 ("f_blocksize" , VHostUserBlk, host_features, +VIRTIO_BLK_F_BLK_SIZE , true), +DEFINE_PROP_BIT64 ("f_topology" , VHostUserBlk, host_features, +VIRTIO_BLK_F_TOPOLOGY , true), +DEFINE_PROP_BIT64 ("f_multiqueue" , VHostUserBlk, host_features, +VIRTIO_BLK_F_MQ , true), +DEFINE_PROP_BIT64 ("f_flush" , VHostUserBlk, host_features, +VIRTIO_BLK_F_FLUSH , true), +DEFINE_PROP_BIT64 ("f_barrier" , VHostUserBlk, host_features, +VIRTIO_BLK_F_BARRIER , false), +DEFINE_PROP_BIT64 ("f_scsi" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SCSI , false), +DEFINE_PROP_BIT64 ("f_wce" , VHostUserBlk, host_features, +VIRTIO_BLK_F_WCE , false),Quoted 3 lines
Quoted 3 lines
Please explain how feature negotation works. The vhost-user slave advertises support features in the return value from
VHOST_USER_GET_FEATURES. How does this additional feature mask workand
Quoted 2 lines
Quoted 1 line
why is it useful?
According to Paolo's previous comments, VIRTIO_BLK_F_WCE/
VIRTIO_BLK_F_SCSI/
VIRTIO_BLK_F_BARRIERQuoted 1 line
should be removed. Here I added all the feature flags just want to avoid the
case that vhost-user slave target
Quoted 8 lines
Quoted 1 line
can support but Qemu vhost block driver cannot support it.
Please explain a bit more how these options can be used.
When I looked at the vhost code it seemed like the vhost slave can report any feature bits it wishes (even things QEMU doesn't know about). What is the purpose of override some of the feature bits on the QEMU command-line?
Hi Stefan,
Here I added a switch which can override vhost-slave's feature bits, for example, vhost-slave reported VIRTIO_BLK_F_RO, but Qemu vhost-master can disable it through command line when started the Qemu. Users don't need to change any vhost-slave's code to disable this feature, and this is also aligned with vhost-scsi and vhost-net's implementation.
Quoted 2 lines
Stefan
Re: [Qemu-devel] [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host device
Quoted 55 lines · Changpeng
Quoted 55 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Friday, October 20, 2017 5:55 PM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host deviceQuoted 29 lines · Changpeng
Quoted 29 lines
Quoted 28 lines
hw/block/vhost-user-blk.c new file +28
-0+static Property vhost_user_blk_properties[] = { +DEFINE_PROP_CHR ("chardev" , VHostUserBlk, chardev), +DEFINE_PROP_UINT16 ("num_queues" , VHostUserBlk, num_queues,1 ), +DEFINE_PROP_UINT32 ("queue_size" , VHostUserBlk, queue_size,128 ), +DEFINE_PROP_BIT64 ("f_size_max" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SIZE_MAX , true), +DEFINE_PROP_BIT64 ("f_sizemax" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SIZE_MAX , true), +DEFINE_PROP_BIT64 ("f_segmax" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SEG_MAX , true), +DEFINE_PROP_BIT64 ("f_geometry" , VHostUserBlk, host_features, +VIRTIO_BLK_F_GEOMETRY , true), +DEFINE_PROP_BIT64 ("f_readonly" , VHostUserBlk, host_features, +VIRTIO_BLK_F_RO , false), +DEFINE_PROP_BIT64 ("f_blocksize" , VHostUserBlk, host_features, +VIRTIO_BLK_F_BLK_SIZE , true), +DEFINE_PROP_BIT64 ("f_topology" , VHostUserBlk, host_features, +VIRTIO_BLK_F_TOPOLOGY , true), +DEFINE_PROP_BIT64 ("f_multiqueue" , VHostUserBlk, host_features, +VIRTIO_BLK_F_MQ , true), +DEFINE_PROP_BIT64 ("f_flush" , VHostUserBlk, host_features, +VIRTIO_BLK_F_FLUSH , true), +DEFINE_PROP_BIT64 ("f_barrier" , VHostUserBlk, host_features, +VIRTIO_BLK_F_BARRIER , false), +DEFINE_PROP_BIT64 ("f_scsi" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SCSI , false), +DEFINE_PROP_BIT64 ("f_wce" , VHostUserBlk, host_features, +VIRTIO_BLK_F_WCE , false),Quoted 3 lines
Quoted 3 lines
Please explain how feature negotation works. The vhost-user slave advertises support features in the return value from
VHOST_USER_GET_FEATURES. How does this additional feature mask workand
Quoted 2 lines
Quoted 1 line
why is it useful?
According to Paolo's previous comments, VIRTIO_BLK_F_WCE/
VIRTIO_BLK_F_SCSI/
VIRTIO_BLK_F_BARRIERQuoted 1 line
should be removed. Here I added all the feature flags just want to avoid the
case that vhost-user slave target
Quoted 1 line
can support but Qemu vhost block driver cannot support it.
Please explain a bit more how these options can be used.
Quoted 8 lines
Quoted 4 lines
When I looked at the vhost code it seemed like the vhost slave can report any feature bits it wishes (even things QEMU doesn't know about). What is the purpose of override some of the feature bits on the QEMU command-line?
Hi Stefan,
Here I added a switch which can override vhost-slave's feature bits, for example, vhost-slave reportedVIRTIO_BLK_F_RO, but Qemu vhost-master can disable it through command line when started the Qemu. Users don't need to change any vhost-slave's code to disable this feature, and this is also aligned with vhost-scsi and vhost-net's implementation.
Yes but I don't see these properties in virtio_blk_properties. Please make the names consistent at least when virtio-blk has them. I am pretty sure you don't want to expose e.g. _F_SCSI.
Quoted 1 line
Quoted 1 line
Stefan
Re: [Qemu-devel] [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host device
Quoted 79 lines
-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Monday, October 23, 2017 8:55 PM
To: Liu, Changpeng <[email protected]>
Cc: Stefan Hajnoczi <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host deviceQuoted 10 lines · Changpeng
Quoted 10 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Friday, October 20, 2017 5:55 PM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blkhost
Quoted 6 lines
Quoted 6 lines
device
Quoted 3 lines · Changpeng
Quoted 3 lines
Quoted 3 lines
hw/block/vhost-user-blk.c new file +3
-0+static Property vhost_user_blk_properties[] = { +DEFINE_PROP_CHR ("chardev" , VHostUserBlk, chardev), + DEFINE_PROP_UINT16("num_queues", VHostUserBlk, num_queues,1),
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
hw/block/vhost-user-blk.c new file +25
-0+DEFINE_PROP_UINT32 ("queue_size" , VHostUserBlk, queue_size,128 ), +DEFINE_PROP_BIT64 ("f_size_max" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SIZE_MAX , true), +DEFINE_PROP_BIT64 ("f_sizemax" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SIZE_MAX , true), +DEFINE_PROP_BIT64 ("f_segmax" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SEG_MAX , true), +DEFINE_PROP_BIT64 ("f_geometry" , VHostUserBlk, host_features, +VIRTIO_BLK_F_GEOMETRY , true), +DEFINE_PROP_BIT64 ("f_readonly" , VHostUserBlk, host_features, +VIRTIO_BLK_F_RO , false), +DEFINE_PROP_BIT64 ("f_blocksize" , VHostUserBlk, host_features, +VIRTIO_BLK_F_BLK_SIZE , true), +DEFINE_PROP_BIT64 ("f_topology" , VHostUserBlk, host_features, +VIRTIO_BLK_F_TOPOLOGY , true), +DEFINE_PROP_BIT64 ("f_multiqueue" , VHostUserBlk, host_features, +VIRTIO_BLK_F_MQ , true), +DEFINE_PROP_BIT64 ("f_flush" , VHostUserBlk, host_features, +VIRTIO_BLK_F_FLUSH , true), +DEFINE_PROP_BIT64 ("f_barrier" , VHostUserBlk, host_features, +VIRTIO_BLK_F_BARRIER , false), +DEFINE_PROP_BIT64 ("f_scsi" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SCSI , false), +DEFINE_PROP_BIT64 ("f_wce" , VHostUserBlk, host_features, + VIRTIO_BLK_F_WCE, false),Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Please explain how feature negotation works. The vhost-user slave advertises support features in the return value from
VHOST_USER_GET_FEATURES. How does this additional feature maskwork
Quoted 5 lines
Quoted 5 lines
and
Quoted 2 lines
Quoted 1 line
why is it useful?
According to Paolo's previous comments, VIRTIO_BLK_F_WCE/
VIRTIO_BLK_F_SCSI/
VIRTIO_BLK_F_BARRIERQuoted 1 line
should be removed. Here I added all the feature flags just want to avoid
the
Quoted 11 lines
Quoted 9 lines
case that vhost-user slave target
Quoted 1 line
can support but Qemu vhost block driver cannot support it.
Please explain a bit more how these options can be used.
When I looked at the vhost code it seemed like the vhost slave can report any feature bits it wishes (even things QEMU doesn't know about). What is the purpose of override some of the feature bits on the QEMU command-line?
Hi Stefan,
Here I added a switch which can override vhost-slave's feature bits, forexample, vhost-slave reported
VIRTIO_BLK_F_RO,
Quoted 8 lines
Quoted 1 line
but Qemu vhost-master can disable it through command line when started the
Qemu. Users don't need to change any
Quoted 1 line
vhost-slave's code to disable this feature, and this is also aligned with vhost-
scsi and vhost-net's implementation.
Yes but I don't see these properties in
virtio_blk_properties. Please make the names consistent at least when virtio-blk has them. I am pretty sure you don't want to expose e.g._F_SCSI.
Yes, I should remove F_SCSI/F_WCE/F_BARRIER features, Virtio-blk hardcoded 4 features: VIRTIO_BLK_F_SEG_MAX/VIRTIO_BLK_F_GEOMETRY/ VIRTIO_BLK_F_TOPOLOGY/VIRTIO_BLK_F_BLK_SIZE, and extra several configuration parameters for VIRTIO_BLK_F_CONFIG_WCE/VIRTIO_BLK_F_MQ, I can change those feature bits same as virtio-blk.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Stefan
Re: [Qemu-devel] [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host device
In reply to Liu, ChangpengQuoted 55 lines · Changpeng
Quoted 55 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Friday, October 20, 2017 5:55 PM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host deviceQuoted 29 lines · Changpeng
Quoted 29 lines
Quoted 28 lines
hw/block/vhost-user-blk.c new file +28
-0+static Property vhost_user_blk_properties[] = { +DEFINE_PROP_CHR ("chardev" , VHostUserBlk, chardev), +DEFINE_PROP_UINT16 ("num_queues" , VHostUserBlk, num_queues,1 ), +DEFINE_PROP_UINT32 ("queue_size" , VHostUserBlk, queue_size,128 ), +DEFINE_PROP_BIT64 ("f_size_max" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SIZE_MAX , true), +DEFINE_PROP_BIT64 ("f_sizemax" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SIZE_MAX , true), +DEFINE_PROP_BIT64 ("f_segmax" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SEG_MAX , true), +DEFINE_PROP_BIT64 ("f_geometry" , VHostUserBlk, host_features, +VIRTIO_BLK_F_GEOMETRY , true), +DEFINE_PROP_BIT64 ("f_readonly" , VHostUserBlk, host_features, +VIRTIO_BLK_F_RO , false), +DEFINE_PROP_BIT64 ("f_blocksize" , VHostUserBlk, host_features, +VIRTIO_BLK_F_BLK_SIZE , true), +DEFINE_PROP_BIT64 ("f_topology" , VHostUserBlk, host_features, +VIRTIO_BLK_F_TOPOLOGY , true), +DEFINE_PROP_BIT64 ("f_multiqueue" , VHostUserBlk, host_features, +VIRTIO_BLK_F_MQ , true), +DEFINE_PROP_BIT64 ("f_flush" , VHostUserBlk, host_features, +VIRTIO_BLK_F_FLUSH , true), +DEFINE_PROP_BIT64 ("f_barrier" , VHostUserBlk, host_features, +VIRTIO_BLK_F_BARRIER , false), +DEFINE_PROP_BIT64 ("f_scsi" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SCSI , false), +DEFINE_PROP_BIT64 ("f_wce" , VHostUserBlk, host_features, +VIRTIO_BLK_F_WCE , false),Quoted 3 lines
Quoted 3 lines
Please explain how feature negotation works. The vhost-user slave advertises support features in the return value from
VHOST_USER_GET_FEATURES. How does this additional feature mask workand
Quoted 2 lines
Quoted 1 line
why is it useful?
According to Paolo's previous comments, VIRTIO_BLK_F_WCE/
VIRTIO_BLK_F_SCSI/
VIRTIO_BLK_F_BARRIERQuoted 1 line
should be removed. Here I added all the feature flags just want to avoid the
case that vhost-user slave target
Quoted 1 line
can support but Qemu vhost block driver cannot support it.
Please explain a bit more how these options can be used.
Quoted 8 lines
Quoted 4 lines
When I looked at the vhost code it seemed like the vhost slave can report any feature bits it wishes (even things QEMU doesn't know about). What is the purpose of override some of the feature bits on the QEMU command-line?
Hi Stefan,
Here I added a switch which can override vhost-slave's feature bits, for example, vhost-slave reportedVIRTIO_BLK_F_RO, but Qemu vhost-master can disable it through command line when started the Qemu. Users don't need to change any vhost-slave's code to disable this feature, and this is also aligned with vhost-scsi and vhost-net's implementation.
You said vhost-master can disable features but the code doesn't seem to work that way:
+ /* Turn on pre-defined features */
+ features |= s->host_features;
If the use case isn't clear please remove these properties for now.
Stefan
Re: [Qemu-devel] [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host device
Quoted 87 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Tuesday, October 24, 2017 1:12 AM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host deviceQuoted 10 lines · Changpeng
Quoted 10 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Friday, October 20, 2017 5:55 PM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blkhost
Quoted 6 lines
Quoted 6 lines
device
Quoted 3 lines · Changpeng
Quoted 3 lines
Quoted 3 lines
hw/block/vhost-user-blk.c new file +3
-0+static Property vhost_user_blk_properties[] = { +DEFINE_PROP_CHR ("chardev" , VHostUserBlk, chardev), + DEFINE_PROP_UINT16("num_queues", VHostUserBlk, num_queues,1),
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
hw/block/vhost-user-blk.c new file +25
-0+DEFINE_PROP_UINT32 ("queue_size" , VHostUserBlk, queue_size,128 ), +DEFINE_PROP_BIT64 ("f_size_max" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SIZE_MAX , true), +DEFINE_PROP_BIT64 ("f_sizemax" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SIZE_MAX , true), +DEFINE_PROP_BIT64 ("f_segmax" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SEG_MAX , true), +DEFINE_PROP_BIT64 ("f_geometry" , VHostUserBlk, host_features, +VIRTIO_BLK_F_GEOMETRY , true), +DEFINE_PROP_BIT64 ("f_readonly" , VHostUserBlk, host_features, +VIRTIO_BLK_F_RO , false), +DEFINE_PROP_BIT64 ("f_blocksize" , VHostUserBlk, host_features, +VIRTIO_BLK_F_BLK_SIZE , true), +DEFINE_PROP_BIT64 ("f_topology" , VHostUserBlk, host_features, +VIRTIO_BLK_F_TOPOLOGY , true), +DEFINE_PROP_BIT64 ("f_multiqueue" , VHostUserBlk, host_features, +VIRTIO_BLK_F_MQ , true), +DEFINE_PROP_BIT64 ("f_flush" , VHostUserBlk, host_features, +VIRTIO_BLK_F_FLUSH , true), +DEFINE_PROP_BIT64 ("f_barrier" , VHostUserBlk, host_features, +VIRTIO_BLK_F_BARRIER , false), +DEFINE_PROP_BIT64 ("f_scsi" , VHostUserBlk, host_features, +VIRTIO_BLK_F_SCSI , false), +DEFINE_PROP_BIT64 ("f_wce" , VHostUserBlk, host_features, + VIRTIO_BLK_F_WCE, false),Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Please explain how feature negotation works. The vhost-user slave advertises support features in the return value from
VHOST_USER_GET_FEATURES. How does this additional feature maskwork
Quoted 5 lines
Quoted 5 lines
and
Quoted 2 lines
Quoted 1 line
why is it useful?
According to Paolo's previous comments, VIRTIO_BLK_F_WCE/
VIRTIO_BLK_F_SCSI/
VIRTIO_BLK_F_BARRIERQuoted 1 line
should be removed. Here I added all the feature flags just want to avoid
the
Quoted 11 lines
Quoted 9 lines
case that vhost-user slave target
Quoted 1 line
can support but Qemu vhost block driver cannot support it.
Please explain a bit more how these options can be used.
When I looked at the vhost code it seemed like the vhost slave can report any feature bits it wishes (even things QEMU doesn't know about). What is the purpose of override some of the feature bits on the QEMU command-line?
Hi Stefan,
Here I added a switch which can override vhost-slave's feature bits, forexample, vhost-slave reported
VIRTIO_BLK_F_RO,Quoted 1 line
but Qemu vhost-master can disable it through command line when started the
Qemu. Users don't need to change any
Quoted 1 line
vhost-slave's code to disable this feature, and this is also aligned with vhost-
scsi and vhost-net's implementation.
You said vhost-master can disable features but the code doesn't seem to work that way:
hw/block/vhost-user-blk.c line 196
Quoted 2 lines
hw/block/vhost-user-blk.c new file +2
-0+/* Turn on pre-defined features */ + features |= s->host_features;
User can append parameter when started Qemu: e.g: f_readonly=false to disable it.
Quoted 2 lines
If the use case isn't clear please remove these properties for now.
I can make it the same with virtio-blk, hardcoded the mandatory features, and put VIRTIO_BLK_F_MQ/VIRTIO_BLK_F_RO/VIRTIO_BLK_F_CONFIG_WCE configurable. Thoughts?
Quoted 2 lines
Stefan
Re: [Qemu-devel] [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host device
Quoted 82 lines · Changpeng
Quoted 82 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Tuesday, October 24, 2017 1:12 AM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host deviceQuoted 10 lines · Changpeng
Quoted 10 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Friday, October 20, 2017 5:55 PM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blkhost
Quoted 6 lines
Quoted 6 lines
device
Quoted 3 lines · Changpeng
Quoted 3 lines
Quoted 3 lines
(quoted diff) +3
-0+static Property vhost_user_blk_properties[] = { + DEFINE_PROP_CHR("chardev", VHostUserBlk, chardev), + DEFINE_PROP_UINT16("num_queues", VHostUserBlk, num_queues,1),
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
(quoted diff) +25
-0+ DEFINE_PROP_UINT32("queue_size", VHostUserBlk, queue_size, 128), + DEFINE_PROP_BIT64("f_size_max", VHostUserBlk, host_features, + VIRTIO_BLK_F_SIZE_MAX, true), + DEFINE_PROP_BIT64("f_sizemax", VHostUserBlk, host_features, + VIRTIO_BLK_F_SIZE_MAX, true), + DEFINE_PROP_BIT64("f_segmax", VHostUserBlk, host_features, + VIRTIO_BLK_F_SEG_MAX, true), + DEFINE_PROP_BIT64("f_geometry", VHostUserBlk, host_features, + VIRTIO_BLK_F_GEOMETRY, true), + DEFINE_PROP_BIT64("f_readonly", VHostUserBlk, host_features, + VIRTIO_BLK_F_RO, false), + DEFINE_PROP_BIT64("f_blocksize", VHostUserBlk, host_features, + VIRTIO_BLK_F_BLK_SIZE, true), + DEFINE_PROP_BIT64("f_topology", VHostUserBlk, host_features, + VIRTIO_BLK_F_TOPOLOGY, true), + DEFINE_PROP_BIT64("f_multiqueue", VHostUserBlk, host_features, + VIRTIO_BLK_F_MQ, true), + DEFINE_PROP_BIT64("f_flush", VHostUserBlk, host_features, + VIRTIO_BLK_F_FLUSH, true), + DEFINE_PROP_BIT64("f_barrier", VHostUserBlk, host_features, + VIRTIO_BLK_F_BARRIER, false), + DEFINE_PROP_BIT64("f_scsi", VHostUserBlk, host_features, + VIRTIO_BLK_F_SCSI, false), + DEFINE_PROP_BIT64("f_wce", VHostUserBlk, host_features, + VIRTIO_BLK_F_WCE, false),Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Please explain how feature negotation works. The vhost-user slave advertises support features in the return value from
VHOST_USER_GET_FEATURES. How does this additional feature maskwork
Quoted 5 lines
Quoted 5 lines
and
Quoted 2 lines
Quoted 1 line
why is it useful?
According to Paolo's previous comments, VIRTIO_BLK_F_WCE/
VIRTIO_BLK_F_SCSI/
VIRTIO_BLK_F_BARRIERQuoted 1 line
should be removed. Here I added all the feature flags just want to avoid
the
Quoted 11 lines
Quoted 9 lines
case that vhost-user slave target
Quoted 1 line
can support but Qemu vhost block driver cannot support it.
Please explain a bit more how these options can be used.
When I looked at the vhost code it seemed like the vhost slave can report any feature bits it wishes (even things QEMU doesn't know about). What is the purpose of override some of the feature bits on the QEMU command-line?
Hi Stefan,
Here I added a switch which can override vhost-slave's feature bits, forexample, vhost-slave reported
VIRTIO_BLK_F_RO,Quoted 1 line
but Qemu vhost-master can disable it through command line when started the
Qemu. Users don't need to change any
Quoted 1 line
vhost-slave's code to disable this feature, and this is also aligned with vhost-
Quoted 8 lines
Review
Quoted 7 lines
scsi and vhost-net's implementation.
You said vhost-master can disable features but the code doesn't seem to work that way:
(quoted diff) +2
-0+ /* Turn on pre-defined features */ + features |= s->host_features;User can append parameter when started Qemu: e.g: f_readonly=false to disable it.
No, f_readonly=false has no effect if the vhost slave replies with f_readonly to the VHOST_USER_GET_FEATURES message.
Take a look at the hw/virtio/vhost.c code:
uint64_t vhost_get_features(struct vhost_dev *hdev, const int *feature_bits,
uint64_t features)
{
const int *bit = feature_bits;
while (*bit != VHOST_INVALID_FEATURE_BIT) {
uint64_t bit_mask = (1ULL << *bit);
if (!(hdev->features & bit_mask)) {
features &= ~bit_mask;
}
bit++;
}
return features;
}If f_readonly=false then features |= s->host_features will not contain f_readonly but it doesn't matter because if hdev->features (this value comes from the vhost slave) has f_readonly we will not clear the bit!
So again, what is the purpose of the f_* properties? I don't understand the semantics, it seems useless.
Re: [Qemu-devel] [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host device
Quoted 130 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Tuesday, October 24, 2017 8:53 PM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host deviceQuoted 10 lines · Changpeng
Quoted 10 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Tuesday, October 24, 2017 1:12 AM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blkhost
Quoted 13 lines
Quoted 13 lines
device
Quoted 10 lines · Changpeng
Quoted 10 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Friday, October 20, 2017 5:55 PM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blkQuoted 7 lines
Quoted 7 lines
host
Quoted 6 lines
Quoted 6 lines
device
Quoted 3 lines · Changpeng
Quoted 3 lines
Quoted 3 lines
(quoted diff) +3
-0+static Property vhost_user_blk_properties[] = { + DEFINE_PROP_CHR("chardev", VHostUserBlk, chardev), + DEFINE_PROP_UINT16("num_queues", VHostUserBlk,
num_queues,Quoted 2 lines
Quoted 2 lines
1),
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ DEFINE_PROP_UINT32("queue_size", VHostUserBlk,
queue_size,128),
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
(quoted diff) +7
-0+ DEFINE_PROP_BIT64("f_size_max", VHostUserBlk, host_features, + VIRTIO_BLK_F_SIZE_MAX, true), + DEFINE_PROP_BIT64("f_sizemax", VHostUserBlk, host_features, + VIRTIO_BLK_F_SIZE_MAX, true), + DEFINE_PROP_BIT64("f_segmax", VHostUserBlk, host_features, + VIRTIO_BLK_F_SEG_MAX, true), + DEFINE_PROP_BIT64("f_geometry", VHostUserBlk, host_features,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+ VIRTIO_BLK_F_GEOMETRY, true), + DEFINE_PROP_BIT64("f_readonly", VHostUserBlk, host_features, + VIRTIO_BLK_F_RO, false), + DEFINE_PROP_BIT64("f_blocksize", VHostUserBlk, host_features, + VIRTIO_BLK_F_BLK_SIZE, true), + DEFINE_PROP_BIT64("f_topology", VHostUserBlk, host_features, + VIRTIO_BLK_F_TOPOLOGY, true), + DEFINE_PROP_BIT64("f_multiqueue", VHostUserBlk,
host_features,Quoted 25 lines
Quoted 25 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
(quoted diff) +9
-0+ VIRTIO_BLK_F_MQ, true), + DEFINE_PROP_BIT64("f_flush", VHostUserBlk, host_features, + VIRTIO_BLK_F_FLUSH, true), + DEFINE_PROP_BIT64("f_barrier", VHostUserBlk, host_features, + VIRTIO_BLK_F_BARRIER, false), + DEFINE_PROP_BIT64("f_scsi", VHostUserBlk, host_features, + VIRTIO_BLK_F_SCSI, false), + DEFINE_PROP_BIT64("f_wce", VHostUserBlk, host_features, + VIRTIO_BLK_F_WCE, false),Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Please explain how feature negotation works. The vhost-user slave advertises support features in the return value from
VHOST_USER_GET_FEATURES. How does this additional feature maskwork
Quoted 5 lines
Quoted 5 lines
and
Quoted 2 lines
Quoted 1 line
why is it useful?
According to Paolo's previous comments, VIRTIO_BLK_F_WCE/
VIRTIO_BLK_F_SCSI/
VIRTIO_BLK_F_BARRIERQuoted 1 line
should be removed. Here I added all the feature flags just want to avoid
the
Quoted 5 lines
Quoted 5 lines
case that vhost-user slave target
Quoted 1 line
can support but Qemu vhost block driver cannot support it.
Please explain a bit more how these options can be used.
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
When I looked at the vhost code it seemed like the vhost slave can report any feature bits it wishes (even things QEMU doesn't know about). What is the purpose of override some of the feature bits on the QEMU command-line?
Hi Stefan,
Here I added a switch which can override vhost-slave's feature bits, forexample, vhost-slave reported
VIRTIO_BLK_F_RO,Quoted 1 line
but Qemu vhost-master can disable it through command line when started
the
Quoted 2 lines
Quoted 2 lines
Qemu. Users don't need to change any
Quoted 1 line
vhost-slave's code to disable this feature, and this is also aligned with
vhost-
Quoted 8 lines
Review
Quoted 7 lines
scsi and vhost-net's implementation.
You said vhost-master can disable features but the code doesn't seem to work that way:
(quoted diff) +2
-0+ /* Turn on pre-defined features */ + features |= s->host_features;User can append parameter when started Qemu: e.g: f_readonly=false to
disable it.
No, f_readonly=false has no effect if the vhost slave replies with
f_readonlyto theVHOST_USER_GET_FEATURESmessage.Take a look at the
hw/virtio/vhost.ccode:uint64_t vhost_get_features(struct vhost_dev *hdev, const int *feature_bits, uint64_t features) { const int *bit = feature_bits; while (*bit != VHOST_INVALID_FEATURE_BIT) { uint64_t bit_mask = (1ULL << *bit); if (!(hdev->features & bit_mask)) { features &= ~bit_mask; } bit++; } return features; }
Quoted 6 lines
If f_readonly=false then features |=
s->host_featureswill not containf_readonlybut it doesn't matter because ifhdev->features(this value comes from the vhost slave) hasf_readonlywe will not clear the bit!So again, what is the purpose of the f_* properties? I don't understand the semantics, it seems useless.
Hi Stefan,
I hate this piece of code too, :). There are several feature definitions in VirtIODevice and vhost_dev, I printed the features in the function: vhost_user_blk_get_features, my test vhost-slave also provides RO feature, and I started Qemu with f_readonly=false:
static uint64_t vhost_user_blk_get_features(VirtIODevice *vdev,
uint64_t features, Error **errp)
{
VHostUserBlk *s = VHOST_USER_BLK(vdev);
uint64_t get_features;
/* Turn on pre-defined host features */
fprintf(stdout, "Features %"PRIx64"\n", features);
features |= s->host_features;
fprintf(stdout, "Turn On Predefined Features %"PRIx64"\n", features);
fprintf(stdout, "VHOST Features %"PRIx64"\n", s->dev.features);
get_features = vhost_get_features(&s->dev, user_feature_bits, features);
fprintf(stdout, "Get Features %"PRIx64"\n", get_features);
return get_features;
}Here is the result, RO feature is bit5:
Features 179000000, This is VirtIODevice->host_features.
Turn On Predefined Features 179001ed7, RO bit is masked here.
VHOST Features 141001466, vhost_dev-> features, you can see that RO bit is set here. Get Features 149001446, this is the final result, RO bit is masked finally.
Similar with vhost-scsi and vhost-net, I think this part of logic is correct.
Re: [Qemu-devel] [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host device
Quoted 160 lines · Changpeng
Quoted 130 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Tuesday, October 24, 2017 8:53 PM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blk host deviceQuoted 10 lines · Changpeng
Quoted 10 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Tuesday, October 24, 2017 1:12 AM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blkhost
Quoted 13 lines
Quoted 13 lines
device
Quoted 10 lines · Changpeng
Quoted 10 lines
-----Original Message-----
From: Stefan Hajnoczi [mailto:[email protected]]
Sent: Friday, October 20, 2017 5:55 PM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 2/4] vhost-user-blk: introduce a new vhost-user-blkQuoted 7 lines
Quoted 7 lines
host
Quoted 6 lines
Quoted 6 lines
device
Quoted 3 lines · Changpeng
Quoted 3 lines
Quoted 3 lines
(quoted diff) +3
-0+static Property vhost_user_blk_properties[] = { + DEFINE_PROP_CHR("chardev", VHostUserBlk, chardev), + DEFINE_PROP_UINT16("num_queues", VHostUserBlk,
num_queues,Quoted 2 lines
Quoted 2 lines
1),
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ DEFINE_PROP_UINT32("queue_size", VHostUserBlk,
queue_size,128),
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
(quoted diff) +7
-0+ DEFINE_PROP_BIT64("f_size_max", VHostUserBlk, host_features, + VIRTIO_BLK_F_SIZE_MAX, true), + DEFINE_PROP_BIT64("f_sizemax", VHostUserBlk, host_features, + VIRTIO_BLK_F_SIZE_MAX, true), + DEFINE_PROP_BIT64("f_segmax", VHostUserBlk, host_features, + VIRTIO_BLK_F_SEG_MAX, true), + DEFINE_PROP_BIT64("f_geometry", VHostUserBlk, host_features,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+ VIRTIO_BLK_F_GEOMETRY, true), + DEFINE_PROP_BIT64("f_readonly", VHostUserBlk, host_features, + VIRTIO_BLK_F_RO, false), + DEFINE_PROP_BIT64("f_blocksize", VHostUserBlk, host_features, + VIRTIO_BLK_F_BLK_SIZE, true), + DEFINE_PROP_BIT64("f_topology", VHostUserBlk, host_features, + VIRTIO_BLK_F_TOPOLOGY, true), + DEFINE_PROP_BIT64("f_multiqueue", VHostUserBlk,
host_features,Quoted 25 lines
Quoted 25 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
(quoted diff) +9
-0+ VIRTIO_BLK_F_MQ, true), + DEFINE_PROP_BIT64("f_flush", VHostUserBlk, host_features, + VIRTIO_BLK_F_FLUSH, true), + DEFINE_PROP_BIT64("f_barrier", VHostUserBlk, host_features, + VIRTIO_BLK_F_BARRIER, false), + DEFINE_PROP_BIT64("f_scsi", VHostUserBlk, host_features, + VIRTIO_BLK_F_SCSI, false), + DEFINE_PROP_BIT64("f_wce", VHostUserBlk, host_features, + VIRTIO_BLK_F_WCE, false),Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Please explain how feature negotation works. The vhost-user slave advertises support features in the return value from
VHOST_USER_GET_FEATURES. How does this additional feature maskwork
Quoted 5 lines
Quoted 5 lines
and
Quoted 2 lines
Quoted 1 line
why is it useful?
According to Paolo's previous comments, VIRTIO_BLK_F_WCE/
VIRTIO_BLK_F_SCSI/
VIRTIO_BLK_F_BARRIERQuoted 1 line
should be removed. Here I added all the feature flags just want to avoid
the
Quoted 5 lines
Quoted 5 lines
case that vhost-user slave target
Quoted 1 line
can support but Qemu vhost block driver cannot support it.
Please explain a bit more how these options can be used.
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
When I looked at the vhost code it seemed like the vhost slave can report any feature bits it wishes (even things QEMU doesn't know about). What is the purpose of override some of the feature bits on the QEMU command-line?
Hi Stefan,
Here I added a switch which can override vhost-slave's feature bits, forexample, vhost-slave reported
VIRTIO_BLK_F_RO,Quoted 1 line
but Qemu vhost-master can disable it through command line when started
the
Quoted 2 lines
Quoted 2 lines
Qemu. Users don't need to change any
Quoted 1 line
vhost-slave's code to disable this feature, and this is also aligned with
vhost-
Quoted 8 lines
Review
Quoted 7 lines
scsi and vhost-net's implementation.
You said vhost-master can disable features but the code doesn't seem to work that way:
(quoted diff) +2
-0+ /* Turn on pre-defined features */ + features |= s->host_features;User can append parameter when started Qemu: e.g: f_readonly=false to
disable it.
No, f_readonly=false has no effect if the vhost slave replies with
f_readonlyto theVHOST_USER_GET_FEATURESmessage.Take a look at the
hw/virtio/vhost.ccode:uint64_t vhost_get_features(struct vhost_dev *hdev, const int *feature_bits, uint64_t features) { const int *bit = feature_bits; while (*bit != VHOST_INVALID_FEATURE_BIT) { uint64_t bit_mask = (1ULL << *bit); if (!(hdev->features & bit_mask)) { features &= ~bit_mask; } bit++; } return features; }Quoted 6 lines
If f_readonly=false then features |=
s->host_featureswill not containf_readonlybut it doesn't matter because ifhdev->features(this value comes from the vhost slave) hasf_readonlywe will not clear the bit!So again, what is the purpose of the f_* properties? I don't understand the semantics, it seems useless.
Hi Stefan,
I hate this piece of code too, :). There are several feature definitions in VirtIODevice andvhost_dev, I printed the features in the function:vhost_user_blk_get_features, my test vhost-slave also provides RO feature, and I started Qemu with f_readonly=false:static
uint64_tvhost_user_blk_get_features(VirtIODevice *vdev,
uint64_tfeatures, Error **errp){ VHostUserBlk *s = VHOST_USER_BLK(vdev); uint64_t get_features; /* Turn on pre-defined host features */ fprintf(stdout, "Features %"PRIx64"\n", features); features |= s->host_features; fprintf(stdout, "Turn On Predefined Features %"PRIx64"\n", features); fprintf(stdout, "VHOST Features %"PRIx64"\n", s->dev.features); get_features = vhost_get_features(&s->dev, user_feature_bits, features); fprintf(stdout, "Get Features %"PRIx64"\n", get_features); return get_features; }
Quoted 7 lines
Here is the result, RO feature is bit5:
Features 179000000, This isVirtIODevice->host_features.
Turn On Predefined Features179001ed7, RO bit is masked here.
VHOST Features 141001466, vhost_dev-> features, you can see that RO bit is set here. Get Features 149001446, this is the final result, RO bit is masked finally.Similar with vhost-scsi and vhost-net, I think this part of logic is correct.
I see. I incorrectly thought vhost_dev->features is ORed at some stage.
This means that vhost slaves can only influence the feature bits in one
way: they can disable feature bits that QEMU knows about. Basically the feature bits are controlled by QEMU, not the slave.
Stefan
PATCH v4 3/4 contrib/libvhost-user: enable virtio config space messages
In reply to Changpeng LiuEnable VHOST_USER_GET_CONFIG/VHOST_USER_SET_CONFIG/VHOST_USER_SET_CONFIG_FD messages in libvhost-user library, users can implement their own I/O target based on the library. This enable the virtio config space delivered between Qemu host device and the I/O target, also event notifier is added in case of virtio config space changed.
--- contrib/libvhost-user/libvhost-user.c | 75 +++++++++++++++++++++++++++++++++++ contrib/libvhost-user/libvhost-user.h | 15 ++++++- 2 files changed, 89 insertions(+), 1 deletion(-)
contrib/libvhost-user/libvhost-user.c +75 -0
@@ -84,6 +84,9 @@ vu_request_to_string(unsigned int req)REQ (VHOST_USER_SET_SLAVE_REQ_FD ),REQ (VHOST_USER_IOTLB_MSG ),REQ (VHOST_USER_SET_VRING_ENDIAN ), +REQ (VHOST_USER_GET_CONFIG ), +REQ (VHOST_USER_SET_CONFIG ), +REQ (VHOST_USER_SET_CONFIG_FD ), REQ(VHOST_USER_MAX), };#undef REQ
@@ -798,6 +801,66 @@ vu_set_slave_req_fd(VuDev *dev, VhostUserMsg *vmsg) }static bool +vu_get_config (VuDev *dev,VhostUserMsg *vmsg) +{ +int ret =-1 ; + +if (dev->iface->get_config) { + ret = dev->iface->get_config (dev, vmsg->payload.config, vmsg->size); + } + +if (ret) { +/* resize to zero to indicate an error to master */ + vmsg->size =0 ; + } + +return true; +} + +static bool +vu_set_config (VuDev *dev,VhostUserMsg *vmsg) +{ +int ret =-1 ; +bool reply_supported = !!(dev->protocol_features & + (1ULL <<VHOST_USER_PROTOCOL_F_REPLY_ACK )); + +if (dev->iface->set_config) { + ret = dev->iface->set_config (dev, vmsg->payload.config, vmsg->size); + } + + vmsg->size =sizeof (vmsg->payload.u64); +if (!ret) { + vmsg->payload.u64 =0 ; + }else { +/* indicate an error in case reply supported */ + vmsg->payload.u64 =1 ; + } + +if (reply_supported) { +return true; + } + +return false; +} + +static bool +vu_set_config_fd (VuDev *dev,VhostUserMsg *vmsg) +{ +if (vmsg->fd_num !=1 ) { +vu_panic (dev,"Invalid config_fd message" ); +return false; + } + +if (dev->config_fd !=-1 ) { +close (dev->config_fd); + } + dev->config_fd = vmsg->fds[0 ]; +DPRINT ("Got config_fd: %d\n" , vmsg->fds[0 ]); + +return false; +} + +static bool vu_process_message (VuDev *dev,VhostUserMsg *vmsg) {int do_reply =0 ;
@@ -862,6 +925,12 @@ vu_process_message(VuDev *dev, VhostUserMsg *vmsg)return vu_set_vring_enable_exec (dev, vmsg);case VHOST_USER_SET_SLAVE_REQ_FD :return vu_set_slave_req_fd (dev, vmsg); +case VHOST_USER_GET_CONFIG : +return vu_get_config (dev, vmsg); +case VHOST_USER_SET_CONFIG : +return vu_set_config (dev, vmsg); +case VHOST_USER_SET_CONFIG_FD : +return vu_set_config_fd (dev, vmsg);case VHOST_USER_NONE :break ;default :
@@ -940,6 +1009,10 @@ vu_deinit(VuDev *dev) dev->slave_fd =-1 ; } +if (dev->config_fd !=-1 ) { +close (dev->config_fd); + } +if (dev->sock !=-1 ) {close (dev->sock); }
@@ -970,6 +1043,8 @@ vu_init(VuDev *dev, dev->iface = iface; dev->log_call_fd =-1 ; dev->slave_fd =-1 ; + dev->config_fd =-1 ; +for (i =0 ; i <VHOST_MAX_NR_VIRTQUEUE ; i++) { dev->vq[i] = (VuVirtq ) { .call_fd =-1 , .kick_fd =-1 , .err_fd =-1 ,
contrib/libvhost-user/libvhost-user.h +14 -1
@@ -30,6 +30,8 @@#define VHOST_MEMORY_MAX_NREGIONS 8 +#define VHOST_USER_MAX_CONFIG_SIZE 256 +enum VhostUserProtocolFeature {VHOST_USER_PROTOCOL_F_MQ =0 ,VHOST_USER_PROTOCOL_F_LOG_SHMFD =1 ,
@@ -38,7 +40,6 @@ enum VhostUserProtocolFeature {VHOST_USER_PROTOCOL_F_NET_MTU =4 ,VHOST_USER_PROTOCOL_F_SLAVE_REQ =5 ,VHOST_USER_PROTOCOL_F_CROSS_ENDIAN =6 , - VHOST_USER_PROTOCOL_F_MAX };
@@ -69,6 +70,9 @@ 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_SET_CONFIG_FD =26 , VHOST_USER_MAX } VhostUserRequest;
@@ -112,6 +116,7 @@ typedef struct VhostUserMsg {struct vhost_vring_addr addr;VhostUserMemory memory;VhostUserLog log; +uint8_t config[VHOST_USER_MAX_CONFIG_SIZE ]; } payload;int fds[VHOST_MEMORY_MAX_NREGIONS ];
@@ -140,6 +145,9 @@ typedef int (*vu_process_msg_cb) (VuDev *dev, VhostUserMsg *vmsg, int *do_reply);typedef void (*vu_queue_set_started_cb ) (VuDev *dev,int qidx,bool started);typedef bool (*vu_queue_is_processed_in_order_cb ) (VuDev *dev,int qidx); +typedef int (*vu_get_config_cb ) (VuDev *dev,uint8_t *config,size_t len); +typedef int (*vu_set_config_cb ) (VuDev *dev,const uint8_t *config, +size_t len); typedef struct VuDevIface { /* called by VHOST_USER_GET_FEATURES to get the features bitmask */
@@ -162,6 +170,10 @@ typedef struct VuDevIface {* on unmanaged exit/crash. */ vu_queue_is_processed_in_order_cb queue_is_processed_in_order; +/* get the config space of the device */ +vu_get_config_cb get_config; +/* set the config space of the device */ +vu_set_config_cb set_config; } VuDevIface;typedef void (*vu_queue_handler_cb ) (VuDev *dev,int qidx);
@@ -227,6 +239,7 @@ struct VuDev {VuVirtq vq[VHOST_MAX_NR_VIRTQUEUE ];int log_call_fd;int slave_fd; +int config_fd;uint64_t log_size;uint8_t *log_table;uint64_t features;
Signature · 1 line
1.9.3
PATCH v4 4/4 contrib/vhost-user-blk: introduce a vhost-user-blk sample application
In reply to Changpeng LiuThis commit introcudes a vhost-user-blk backend device, it uses UNIX domain socket to communicate with Qemu. The vhost-user-blk sample application should be used with Qemu vhost-user-blk-pci device.
To use it, complie with:
make vhost-user-blk
and start like this:
vhost-user-blk -b /dev/sdb -s /path/vhost.socket
--- .gitignore | 1 + Makefile | 3 + Makefile.objs | 1 + contrib/vhost-user-blk/Makefile.objs | 1 + contrib/vhost-user-blk/vhost-user-blk.c | 492 ++++++++++++++++++++++++++++++++ 5 files changed, 498 insertions(+) create mode 100644 contrib/vhost-user-blk/Makefile.objs create mode 100644 contrib/vhost-user-blk/vhost-user-blk.c
.gitignore +1 -0
@@ -53,6 +53,7 @@ /scsi/qemu-pr-helper /vscclient /vhost-user-scsi +/vhost-user-blk /fsdev/virtfs-proxy-helper *.tmp *.[1-9]
Makefile +3 -0
@@ -318,6 +318,7 @@ dummy := $(call unnest-vars,, \ ivshmem-server-obj-y \ libvhost-user-obj-y \ vhost-user-scsi-obj-y \ + vhost-user-blk-obj-y \ qga-vss-dll-obj-y \ block-obj-y \ block-obj-m \
@@ -534,6 +535,8 @@ ivshmem-server$(EXESUF): $(ivshmem-server-obj-y) $(COMMON_LDADDS) endif vhost-user-scsi$(EXESUF): $(vhost-user-scsi-obj-y) libvhost-user.a $(call LINK, $^) +vhost-user-blk$(EXESUF): $(vhost-user-blk-obj-y) libvhost-user.a + $(call LINK, $^) module_block.h: $(SRC_PATH)/scripts/modules/module_block.py config-host.mak $(call quiet-command,$(PYTHON) $< $@ \
Makefile.objs +1 -0
@@ -115,6 +115,7 @@ libvhost-user-obj-y = contrib/libvhost-user/ vhost-user-scsi.o-cflags := $(LIBISCSI_CFLAGS) vhost-user-scsi.o-libs := $(LIBISCSI_LIBS) vhost-user-scsi-obj-y = contrib/vhost-user-scsi/ +vhost-user-blk-obj-y = contrib/vhost-user-blk/ ###################################################################### trace-events-subdirs =
contrib/vhost-user-blk/Makefile.objs new file +1 -0
@@ -0,0 +1 @@ +vhost-user-blk-obj-y = vhost-user-blk.o
contrib/vhost-user-blk/vhost-user-blk.c new file +492 -0
492 lines not on this page · raw message
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH v4 4/4] contrib/vhost-user-blk: introduce a vhost-user-blk sample application
contrib/vhost-user-blk/vhost-user-blk.c line 167
Quoted 13 lines · Changpeng Liu
contrib/vhost-user-blk/vhost-user-blk.c new file +12
-0+} + +static void +vub_flush (VubReq *req) +{ +VubDev *vdev_blk = req->vdev_blk; + +if (vdev_blk->blk_fd) { +fsync (vdev_blk->blk_fd); + } +} +
No need to check the file descriptor---vub_readv and vub_writev aren't checking it either. Also please use fdatasync instead of fsync.
contrib/vhost-user-blk/vhost-user-blk.c line 317
Quoted 10 lines
contrib/vhost-user-blk/vhost-user-blk.c new file +10
-0+static uint64_t +vub_get_features (VuDev *dev) +{ +return 1ull <<VIRTIO_BLK_F_SIZE_MAX | +1ull <<VIRTIO_BLK_F_SEG_MAX | +1ull <<VIRTIO_BLK_F_TOPOLOGY | +1ull <<VIRTIO_BLK_F_BLK_SIZE | +1ull <<VIRTIO_F_VERSION_1 | +1ull <<VHOST_USER_F_PROTOCOL_FEATURES ; +}
VIRTIO_BLK_F_FLUSH is missing.
Thanks,
Paolo
Re: [Qemu-devel] [PATCH v4 4/4] contrib/vhost-user-blk: introduce a vhost-user-blk sample application
Quoted 13 lines
-----Original Message-----
From: Paolo Bonzini [mailto:[email protected]]
Sent: Thursday, October 19, 2017 7:44 PM
To: Liu, Changpeng <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Harris, James R <[email protected]>
Subject: Re: [PATCH v4 4/4] contrib/vhost-user-blk: introduce a vhost-user-blk sample applicationQuoted 1 line · Changpeng Liu
Quoted 15 lines
contrib/vhost-user-blk/vhost-user-blk.c line 167
Quoted 12 lines
contrib/vhost-user-blk/vhost-user-blk.c new file +12
-0+} + +static void +vub_flush (VubReq *req) +{ +VubDev *vdev_blk = req->vdev_blk; + +if (vdev_blk->blk_fd) { +fsync (vdev_blk->blk_fd); + } +} +No need to check the file descriptor---vub_readv and
vub_writevaren't checking it either. Also please use fdatasync instead of fsync.
Ok.
Quoted 13 lines
contrib/vhost-user-blk/vhost-user-blk.c line 317
Quoted 11 lines
contrib/vhost-user-blk/vhost-user-blk.c new file +10
-0+static uint64_t +vub_get_features (VuDev *dev) +{ +return 1ull <<VIRTIO_BLK_F_SIZE_MAX | +1ull <<VIRTIO_BLK_F_SEG_MAX | +1ull <<VIRTIO_BLK_F_TOPOLOGY | +1ull <<VIRTIO_BLK_F_BLK_SIZE | +1ull <<VIRTIO_F_VERSION_1 | +1ull <<VHOST_USER_F_PROTOCOL_FEATURES ; +}
VIRTIO_BLK_F_FLUSHis missing.
Yes, will add.
Quoted 4 lines
Thanks,
Paolo