vhost-user: Add memoryIsolation qdev property to vhost-user devices
RFC 1/1 vhost-user: Add memoryIsolation qdev property to vhost-user devices
In support of future work to add a memory isolation mode to vhost-user devices, a qdev property, "memory-isolation", is added to all vhost-user devices. This is simply a bool representing whether the mode is active or not.
Additionally, common property definitions for all children of vhost-user-base are consolidated. Those property definitions now occur when VHostUserBase is initialized
--- hw/block/vhost-user-blk.c | 1 + hw/display/vhost-user-gpu.c | 1 + hw/scsi/vhost-user-scsi.c | 1 + hw/virtio/vhost-user-base.c | 10 ++++++++++ hw/virtio/vhost-user-fs.c | 1 + hw/virtio/vhost-user-gpio.c | 4 ---- hw/virtio/vhost-user-i2c.c | 5 ----- hw/virtio/vhost-user-input.c | 5 ----- hw/virtio/vhost-user-rng.c | 5 ----- hw/virtio/vhost-user-rtc.c | 4 ---- hw/virtio/vhost-user-scmi.c | 1 + hw/virtio/vhost-user-snd.c | 1 - hw/virtio/vhost-user-spi.c | 5 ----- hw/virtio/vhost-user-test-device.c | 1 - hw/virtio/vhost-user-vsock.c | 1 + include/hw/virtio/vhost-user-base.h | 1 + include/hw/virtio/vhost-user-blk.h | 1 + include/hw/virtio/vhost-user-fs.h | 1 + include/hw/virtio/vhost-user-scmi.h | 1 + include/hw/virtio/vhost-user-vsock.h | 1 + include/hw/virtio/virtio-gpu.h | 1 + include/hw/virtio/virtio-scsi.h | 1 + 22 files changed, 23 insertions(+), 30 deletions(-)
hw/block/vhost-user-blk.c +1 -0
@@ -605,6 +605,7 @@ static const VMStateDescription vmstate_vhost_user_blk = {static const Property vhost_user_blk_properties[] = {DEFINE_PROP_CHR ("chardev" , VHostUserBlk, chardev), +DEFINE_PROP_BOOL ("memory-isolation" , VHostUserBlk, memoryIsolation, false),DEFINE_PROP_UINT16 ("num-queues" , VHostUserBlk, num_queues,VHOST_USER_BLK_AUTO_NUM_QUEUES ),DEFINE_PROP_UINT32 ("queue-size" , VHostUserBlk, queue_size,128 ),
hw/display/vhost-user-gpu.c +1 -0
@@ -664,6 +664,7 @@ static struct vhost_dev *vhost_user_gpu_get_vhost(VirtIODevice *vdev)static const Property vhost_user_gpu_properties[] = {VIRTIO_GPU_BASE_PROPERTIES (VhostUserGPU, parent_obj.conf), +DEFINE_PROP_BOOL ("memory-isolation" , VhostUserGPU, memoryIsolation, false), }; static void
hw/scsi/vhost-user-scsi.c +1 -0
@@ -347,6 +347,7 @@ static void vhost_user_scsi_unrealize(DeviceState *dev)static const Property vhost_user_scsi_properties[] = {DEFINE_PROP_CHR ("chardev" , VirtIOSCSICommon, conf.chardev), +DEFINE_PROP_BOOL ("memory-isolation" , VirtIOSCSICommon, conf.memoryIsolation, false),DEFINE_PROP_UINT32 ("boot_tpgt" , VirtIOSCSICommon, conf.boot_tpgt,0 ),DEFINE_PROP_UINT32 ("num_queues" , VirtIOSCSICommon, conf.num_queues,VIRTIO_SCSI_AUTO_NUM_QUEUES ),
hw/virtio/vhost-user-base.c +10 -0
@@ -353,9 +353,17 @@ static void vub_device_unrealize(DeviceState *dev)do_vhost_user_cleanup (vdev, vub); } +//Define common properties +static const Property vub_properties[] = { +DEFINE_PROP_BOOL ("memory-isolation" , VHostUserBase, memoryIsolation, false), +DEFINE_PROP_CHR ("chardev" , VHostUserBase, chardev) +}; + +static void vub_class_init (ObjectClass *klass,const void *data) {VirtioDeviceClass *vdc =VIRTIO_DEVICE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); vdc->realize = vub_device_realize; vdc->unrealize = vub_device_unrealize;
@@ -363,6 +371,8 @@ static void vub_class_init(ObjectClass *klass, const void *data) vdc->get_config = vub_get_config; vdc->set_config = vub_set_config; vdc->set_status = vub_set_status; + +device_class_set_props (dc, vub_properties); }static const TypeInfo vub_types[] = {
hw/virtio/vhost-user-fs.c +1 -0
@@ -409,6 +409,7 @@ static const VMStateDescription vuf_backend_vmstate = {static const Property vuf_properties[] = {DEFINE_PROP_CHR ("chardev" , VHostUserFS, conf.chardev), +DEFINE_PROP_BOOL ("memory-isolation" , VHostUserFS, conf.memoryIsolation, false),DEFINE_PROP_STRING ("tag" , VHostUserFS, conf.tag),DEFINE_PROP_UINT16 ("num-request-queues" , VHostUserFS, conf.num_request_queues,1 ),
hw/virtio/vhost-user-gpio.c +0 -4
@@ -14,9 +14,6 @@#include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/virtio_gpio.h" -static const Property vgpio_properties[] = { -DEFINE_PROP_CHR ("chardev" , VHostUserBase, chardev), -};static void vgpio_realize (DeviceState *dev,Error **errp) {
@@ -42,7 +39,6 @@ static void vu_gpio_class_init(ObjectClass *klass, const void *data)VHostUserBaseClass *vubc =VHOST_USER_BASE_CLASS (klass); dc->vmsd = &vu_gpio_vmstate; -device_class_set_props (dc, vgpio_properties);device_class_set_parent_realize (dc, vgpio_realize, &vubc->parent_realize);set_bit (DEVICE_CATEGORY_INPUT , dc->categories);
hw/virtio/vhost-user-i2c.c +0 -5
@@ -14,10 +14,6 @@#include "qemu/error-report.h" #include "standard-headers/linux/virtio_ids.h" -static const Property vi2c_properties[] = { -DEFINE_PROP_CHR ("chardev" , VHostUserBase, chardev), -}; -static void vi2c_realize (DeviceState *dev,Error **errp) {VHostUserBase *vub =VHOST_USER_BASE (dev);
@@ -42,7 +38,6 @@ static void vu_i2c_class_init(ObjectClass *klass, const void *data)VHostUserBaseClass *vubc =VHOST_USER_BASE_CLASS (klass); dc->vmsd = &vu_i2c_vmstate; -device_class_set_props (dc, vi2c_properties);device_class_set_parent_realize (dc, vi2c_realize, &vubc->parent_realize);set_bit (DEVICE_CATEGORY_INPUT , dc->categories);
hw/virtio/vhost-user-input.c +0 -5
@@ -7,10 +7,6 @@#include "qemu/osdep.h" #include "hw/virtio/virtio-input.h" -static const Property vinput_properties[] = { -DEFINE_PROP_CHR ("chardev" , VHostUserBase, chardev), -}; -static void vinput_realize (DeviceState *dev,Error **errp) {VHostUserBase *vub =VHOST_USER_BASE (dev);
@@ -36,7 +32,6 @@ static void vhost_input_class_init(ObjectClass *klass, const void *data)DeviceClass *dc =DEVICE_CLASS (klass); dc->vmsd = &vmstate_vhost_input; -device_class_set_props (dc, vinput_properties);device_class_set_parent_realize (dc, vinput_realize, &vubc->parent_realize);set_bit (DEVICE_CATEGORY_INPUT , dc->categories);
hw/virtio/vhost-user-rng.c +0 -5
@@ -20,10 +20,6 @@ static const VMStateDescription vu_rng_vmstate = { .unmigratable = 1, }; -static const Property vrng_properties[] = { -DEFINE_PROP_CHR ("chardev" , VHostUserBase, chardev), -}; -static void vu_rng_base_realize (DeviceState *dev,Error **errp) {VHostUserBase *vub =VHOST_USER_BASE (dev);
@@ -43,7 +39,6 @@ static void vu_rng_class_init(ObjectClass *klass, const void *data)VHostUserBaseClass *vubc =VHOST_USER_BASE_CLASS (klass); dc->vmsd = &vu_rng_vmstate; -device_class_set_props (dc, vrng_properties);device_class_set_parent_realize (dc, vu_rng_base_realize, &vubc->parent_realize);
hw/virtio/vhost-user-rtc.c +0 -4
@@ -19,9 +19,6 @@ static const VMStateDescription vu_rtc_vmstate = { .unmigratable = 1, }; -static const Property vrtc_properties[] = { -DEFINE_PROP_CHR ("chardev" , VHostUserBase, chardev), -};static void vu_rtc_base_realize (DeviceState *dev,Error **errp) {
@@ -42,7 +39,6 @@ static void vu_rtc_class_init(ObjectClass *klass, const void *data)VHostUserBaseClass *vubc =VHOST_USER_BASE_CLASS (klass); dc->vmsd = &vu_rtc_vmstate; -device_class_set_props (dc, vrtc_properties);device_class_set_parent_realize (dc, vu_rtc_base_realize, &vubc->parent_realize);
hw/virtio/vhost-user-scmi.c +1 -0
@@ -282,6 +282,7 @@ static const VMStateDescription vu_scmi_vmstate = {static const Property vu_scmi_properties[] = {DEFINE_PROP_CHR ("chardev" , VHostUserSCMI, chardev), +DEFINE_PROP_BOOL ("memory-isolation" , VHostUserSCMI, memoryIsolation, false), };static void vu_scmi_class_init (ObjectClass *klass,const void *data)
hw/virtio/vhost-user-snd.c +0 -1
@@ -34,7 +34,6 @@ static const VMStateDescription vu_snd_vmstate = { };static const Property vsnd_properties[] = { -DEFINE_PROP_CHR ("chardev" , VHostUserBase, chardev),DEFINE_PROP_BIT64 ("controls" , VHostUserBase, parent_obj.host_features,VIRTIO_SND_F_CTLS , false), };
hw/virtio/vhost-user-spi.c +0 -5
@@ -15,10 +15,6 @@#include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/virtio_spi.h" -static const Property vspi_properties[] = { -DEFINE_PROP_CHR ("chardev" , VHostUserBase, chardev), -}; -static void vspi_realize (DeviceState *dev,Error **errp) {VHostUserBase *vub =VHOST_USER_BASE (dev);
@@ -44,7 +40,6 @@ static void vu_spi_class_init(ObjectClass *klass, const void *data)VHostUserBaseClass *vubc =VHOST_USER_BASE_CLASS (klass); dc->vmsd = &vu_spi_vmstate; -device_class_set_props (dc, vspi_properties);device_class_set_parent_realize (dc, vspi_realize, &vubc->parent_realize);set_bit (DEVICE_CATEGORY_INPUT , dc->categories);
hw/virtio/vhost-user-test-device.c +0 -1
@@ -30,7 +30,6 @@ static const VMStateDescription vud_vmstate = { };static const Property vud_properties[] = { -DEFINE_PROP_CHR ("chardev" , VHostUserBase, chardev),DEFINE_PROP_UINT16 ("virtio-id" , VHostUserBase, virtio_id,0 ),DEFINE_PROP_UINT32 ("vq_size" , VHostUserBase, vq_size,64 ),DEFINE_PROP_UINT32 ("num_vqs" , VHostUserBase, num_vqs,1 ),
hw/virtio/vhost-user-vsock.c +1 -0
@@ -154,6 +154,7 @@ static void vuv_device_unrealize(DeviceState *dev)static const Property vuv_properties[] = {DEFINE_PROP_CHR ("chardev" , VHostUserVSock, conf.chardev), +DEFINE_PROP_BOOL ("memory-isolation" , VHostUserVSock, conf.memoryIsolation, false), };static void vuv_class_init (ObjectClass *klass,const void *data)
include/hw/virtio/vhost-user-base.h +1 -0
@@ -25,6 +25,7 @@ struct VHostUserBase {uint32_t num_vqs;uint32_t vq_size;/* can't exceed VIRTIO_QUEUE_MAX */ uint32_t config_size; +bool memoryIsolation;/* State tracking */ VhostUserState vhost_user;struct vhost_virtqueue *vhost_vq;
include/hw/virtio/vhost-user-blk.h +1 -0
@@ -30,6 +30,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(VHostUserBlk, VHOST_USER_BLK)struct VHostUserBlk {VirtIODevice parent_obj;CharFrontend chardev; +bool memoryIsolation;int32_t bootindex;struct virtio_blk_config blkcfg;uint16_t num_queues;
include/hw/virtio/vhost-user-fs.h +1 -0
@@ -28,6 +28,7 @@ typedef struct {char *tag;uint16_t num_request_queues;uint16_t queue_size; +bool memoryIsolation; } VHostUserFSConf;struct VHostUserFS {
include/hw/virtio/vhost-user-scmi.h +1 -0
@@ -19,6 +19,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(VHostUserSCMI, VHOST_USER_SCMI);struct VHostUserSCMI {VirtIODevice parent;CharFrontend chardev; +bool memoryIsolation;struct vhost_virtqueue *vhost_vqs;struct vhost_dev vhost_dev;VhostUserState vhost_user;
include/hw/virtio/vhost-user-vsock.h +1 -0
@@ -21,6 +21,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(VHostUserVSock, VHOST_USER_VSOCK)typedef struct {CharFrontend chardev; +bool memoryIsolation; }VHostUserVSockConf ;struct VHostUserVSock {
include/hw/virtio/virtio-gpu.h +1 -0
@@ -276,6 +276,7 @@ struct VhostUserGPU {CharFrontend vhost_chr;QemuDmaBuf *dmabuf[VIRTIO_GPU_MAX_SCANOUTS ];bool backend_blocked; +bool memoryIsolation; };#define MAX_SLOTS 4096
include/hw/virtio/virtio-scsi.h +1 -0
@@ -59,6 +59,7 @@ struct VirtIOSCSIConf {char *vhostfd;char *wwpn;CharFrontend chardev; +bool memoryIsolation;uint32_t boot_tpgt;IOThread *iothread;IOThreadVirtQueueMappingList *iothread_vq_mapping_list;
Signature · 1 line
2.43.0
hw/virtio/vhost-user-base.c static void vub_device_unrealize(DeviceState *dev) · line 358
Quoted 11 lines · ConKite
hw/virtio/vhost-user-base.c +3
-0@@ -353,9 +353,17 @@ static void vub_device_unrealize(DeviceState *dev)do_vhost_user_cleanup (vdev, vub); } +//Define common properties +static const Property vub_properties[] = { +DEFINE_PROP_BOOL ("memory-isolation" , VHostUserBase, memoryIsolation, false),
From docs/devel/style.rst:
- "We use traditional C-style /``*`` ``*``/ comments and avoid // comments."
- "Variables are lower_case_with_underscores". memoryIsolation -> memory_isolation.
You can run scripts/checkpatch.pl to catch many coding style issues. Here is a git-hook to automatically do that when you commit:
https://blog.vmsplice.net/2011/03/how-to-automatically-run-checkpatchpl.html
Quoted 15 lines
hw/virtio/vhost-user-gpio.c +0
-3@@ -14,9 +14,6 @@#include "standard-headers/linux/virtio_ids.h" #include "standard-headers/linux/virtio_gpio.h" -static const Property vgpio_properties[] = { -DEFINE_PROP_CHR ("chardev" , VHostUserBase, chardev), -};static void vgpio_realize (DeviceState *dev,Error **errp) {
hw/virtio/vhost-user-gpio.c static void vu_gpio_class_init(ObjectClass *klass, const void *data) · line 44
Quoted 7 lines
hw/virtio/vhost-user-gpio.c +0
-1@@ -42,7 +39,6 @@ static void vu_gpio_class_init(ObjectClass *klass, const void *data)VHostUserBaseClass *vubc =VHOST_USER_BASE_CLASS (klass); dc->vmsd = &vu_gpio_vmstate; -device_class_set_props (dc, vgpio_properties);device_class_set_parent_realize (dc, vgpio_realize, &vubc->parent_realize);set_bit (DEVICE_CATEGORY_INPUT , dc->categories);
Moving chardev into the base class is a nice refactoring in itself and its independent of introducing the memory-isolation property. Separating self-contained changes into their own commits makes it easier for reviewers to understand your patch series and it helps with backporting and bisection (e.g. which change caused the breakage:
introducing memory-isolation or moving chardev?).
I suggest splitting this commit into two commits:
1. Move chardev into the base class.
2. Add the memory-isolation property.