diff mbox series

[v1,2/8] virtio: Add tracking of the common virtio guest features

Message ID 20210901090804.7139-3-maxim.davydov@virtuozzo.com (mailing list archive)
State New, archived
Headers show
Series Virtio features acknowledged by guest | expand

Commit Message

Maxim Davydov Sept. 1, 2021, 9:07 a.m. UTC
It implements common virtio features via macros that, by defining
the virtio guest feature bit and the virtio host feature bit, allow
you to checks acknowledged virtio features by the guest.

Signed-off-by: Maxim Davydov <maxim.davydov@virtuozzo.com>
---
 hw/virtio/virtio.c         |  2 +-
 include/hw/virtio/virtio.h | 39 ++++++++++++++++++++++++++-------------
 2 files changed, 27 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 874377f..5f113c7 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -3717,7 +3717,7 @@  static void virtio_device_instance_finalize(Object *obj)
 }
 
 static Property virtio_properties[] = {
-    DEFINE_VIRTIO_COMMON_FEATURES(VirtIODevice, host_features),
+    DEFINE_VIRTIO_COMMON_FEATURES(VirtIODevice, host_features, guest_features),
     DEFINE_PROP_BOOL("use-started", VirtIODevice, use_started, true),
     DEFINE_PROP_BOOL("use-disabled-flag", VirtIODevice, use_disabled_flag, true),
     DEFINE_PROP_BOOL("x-disable-legacy-check", VirtIODevice,
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 8bab9cf..50f334c 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -277,19 +277,32 @@  typedef struct virtio_input_conf virtio_input_conf;
 typedef struct VirtIOSCSIConf VirtIOSCSIConf;
 typedef struct VirtIORNGConf VirtIORNGConf;
 
-#define DEFINE_VIRTIO_COMMON_FEATURES(_state, _field) \
-    DEFINE_PROP_BIT64("indirect_desc", _state, _field,    \
-                      VIRTIO_RING_F_INDIRECT_DESC, true), \
-    DEFINE_PROP_BIT64("event_idx", _state, _field,        \
-                      VIRTIO_RING_F_EVENT_IDX, true),     \
-    DEFINE_PROP_BIT64("notify_on_empty", _state, _field,  \
-                      VIRTIO_F_NOTIFY_ON_EMPTY, true), \
-    DEFINE_PROP_BIT64("any_layout", _state, _field, \
-                      VIRTIO_F_ANY_LAYOUT, true), \
-    DEFINE_PROP_BIT64("iommu_platform", _state, _field, \
-                      VIRTIO_F_IOMMU_PLATFORM, false), \
-    DEFINE_PROP_BIT64("packed", _state, _field, \
-                      VIRTIO_F_RING_PACKED, false)
+#define DEFINE_VIRTIO_FEATURE_BIT(_name, _state, _host_field, _guest_field,    \
+                                  _bit, _defval)                               \
+    DEFINE_PROP_BIT(_name, _state, _host_field, _bit, _defval),                \
+    DEFINE_PROP_READ_ONLY_BIT64("acknowledged_by_guest_" _name, _state,        \
+                                _guest_field, _bit)
+
+#define DEFINE_VIRTIO_FEATURE_BIT64(_name, _state, _host_field, _guest_field,  \
+                                    _bit, _defval)                             \
+    DEFINE_PROP_BIT64(_name, _state, _host_field, _bit, _defval),              \
+    DEFINE_PROP_READ_ONLY_BIT64("acknowledged_by_guest_" _name, _state,        \
+                                _guest_field, _bit)
+
+#define DEFINE_VIRTIO_COMMON_FEATURES(_state, _host_field, _guest_field)       \
+    DEFINE_VIRTIO_FEATURE_BIT64("indirect_desc", _state, _host_field,          \
+                                _guest_field, VIRTIO_RING_F_INDIRECT_DESC,     \
+                                true),                                         \
+    DEFINE_VIRTIO_FEATURE_BIT64("event_idx", _state, _host_field,              \
+                                _guest_field, VIRTIO_RING_F_EVENT_IDX, true),  \
+    DEFINE_VIRTIO_FEATURE_BIT64("notify_on_empty", _state, _host_field,        \
+                                _guest_field, VIRTIO_F_NOTIFY_ON_EMPTY, true), \
+    DEFINE_VIRTIO_FEATURE_BIT64("any_layout", _state, _host_field,             \
+                                _guest_field, VIRTIO_F_ANY_LAYOUT, true),      \
+    DEFINE_VIRTIO_FEATURE_BIT64("iommu_platform", _state, _host_field,         \
+                                _guest_field, VIRTIO_F_IOMMU_PLATFORM, false), \
+    DEFINE_VIRTIO_FEATURE_BIT64("packed", _state, _host_field,                 \
+                                _guest_field,  VIRTIO_F_RING_PACKED, false)
 
 hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n);
 bool virtio_queue_enabled_legacy(VirtIODevice *vdev, int n);