All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/8] Virtio features acknowledged by guest
@ 2021-09-01  9:07 Maxim Davydov
  2021-09-01  9:07 ` [PATCH v1 1/8] qdev-properties: Add read-only 64 bit property Maxim Davydov
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Maxim Davydov @ 2021-09-01  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: den, mst, stefanha, fam, amit, kraxel, berrange, Maxim Davydov

In some situations (for instance, debug), we want to be able to see the
features that were confirmed by the guest. At the same time, we would like
to do this safely, without the possibility of setting bits of guest
features from the outside.

Maxim Davydov (8):
  qdev-properties: Add read-only 64 bit property
  virtio: Add tracking of the common virtio guest features
  virtio-gpu: Add tracking of the virtio guest feature bits
  virtio-serial: Add tracking of the virtio guest feature bits
  virtio-net: Add tracking of the virtio guest feature bits
  scsi: Add tracking of the acknowledged feature bits
  virtio-blk: Add tracking of the virtio guest feature bits
  virtio-balloon: Add tracking of the virtio guest feature bits

 hw/block/virtio-blk.c          |  20 ++++---
 hw/char/virtio-serial-bus.c    |   5 +-
 hw/core/qdev-properties.c      |  32 +++++++++++
 hw/display/vhost-user-gpu.c    |   3 +-
 hw/display/virtio-gpu.c        |   8 +--
 hw/net/virtio-net.c            | 118 +++++++++++++++++++++++++----------------
 hw/scsi/vhost-scsi.c           |   6 +--
 hw/scsi/vhost-user-scsi.c      |  18 +++----
 hw/scsi/virtio-scsi.c          |  10 ++--
 hw/virtio/virtio-balloon.c     |  20 ++++---
 hw/virtio/virtio.c             |   2 +-
 include/hw/qdev-properties.h   |   5 ++
 include/hw/virtio/virtio-gpu.h |  10 ++--
 include/hw/virtio/virtio.h     |  39 +++++++++-----
 14 files changed, 193 insertions(+), 103 deletions(-)

-- 
1.8.3.1



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v1 1/8] qdev-properties: Add read-only 64 bit property
  2021-09-01  9:07 [PATCH v1 0/8] Virtio features acknowledged by guest Maxim Davydov
@ 2021-09-01  9:07 ` Maxim Davydov
  2021-09-01  9:07 ` [PATCH v1 2/8] virtio: Add tracking of the common virtio guest features Maxim Davydov
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Maxim Davydov @ 2021-09-01  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: den, mst, stefanha, fam, amit, kraxel, berrange, Maxim Davydov

In some situations, we need a property that tracks the bit but
can't change it (for instance, guest features of virtio device).

Signed-off-by: Maxim Davydov <maxim.davydov@virtuozzo.com>
---
 hw/core/qdev-properties.c    | 32 ++++++++++++++++++++++++++++++++
 include/hw/qdev-properties.h |  5 +++++
 2 files changed, 37 insertions(+)

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 50f4094..d7b0436 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -231,6 +231,38 @@ const PropertyInfo qdev_prop_bit64 = {
     .set_default_value = set_default_value_bool,
 };
 
+/* Read-only Bit64 */
+
+static void prop_set_read_only_bit64(Object *obj, Visitor *v, const char *name,
+                                     void *opaque, Error **errp)
+{
+    return;
+}
+
+static uint64_t qdev_get_prop_read_only_mask64(Property *prop)
+{
+    assert(prop->info == &qdev_prop_read_only_bit64);
+    return 0x1ull << prop->bitnr;
+}
+
+static void prop_get_read_only_bit64(Object *obj, Visitor *v, const char *name,
+                                     void *opaque, Error **errp)
+{
+    Property *prop = opaque;
+    uint64_t *p = object_field_prop_ptr(obj, prop);
+    bool value = (*p & qdev_get_prop_read_only_mask64(prop)) != 0;
+
+    visit_type_bool(v, name, &value, errp);
+}
+
+const PropertyInfo qdev_prop_read_only_bit64 = {
+    .name  = "bool",
+    .description = "on/off",
+    .get   = prop_get_read_only_bit64,
+    .set   = prop_set_read_only_bit64,
+    .set_default_value = set_default_value_bool,
+};
+
 /* --- bool --- */
 
 static void get_bool(Object *obj, Visitor *v, const char *name, void *opaque,
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 0ef97d6..4c4bac7 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -46,6 +46,7 @@ struct PropertyInfo {
 
 extern const PropertyInfo qdev_prop_bit;
 extern const PropertyInfo qdev_prop_bit64;
+extern const PropertyInfo qdev_prop_read_only_bit64;
 extern const PropertyInfo qdev_prop_bool;
 extern const PropertyInfo qdev_prop_enum;
 extern const PropertyInfo qdev_prop_uint8;
@@ -102,6 +103,10 @@ extern const PropertyInfo qdev_prop_link;
                 .set_default = true,                         \
                 .defval.u    = (bool)_defval)
 
+#define DEFINE_PROP_READ_ONLY_BIT64(_name, _state, _field, _bit)            \
+    DEFINE_PROP(_name, _state, _field, qdev_prop_read_only_bit64, uint64_t, \
+                .bitnr = (_bit))
+
 #define PROP_ARRAY_LEN_PREFIX "len-"
 
 /**
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 2/8] virtio: Add tracking of the common virtio guest features
  2021-09-01  9:07 [PATCH v1 0/8] Virtio features acknowledged by guest Maxim Davydov
  2021-09-01  9:07 ` [PATCH v1 1/8] qdev-properties: Add read-only 64 bit property Maxim Davydov
@ 2021-09-01  9:07 ` Maxim Davydov
  2021-09-01  9:07 ` [PATCH v1 3/8] virtio-gpu: Add tracking of the virtio guest feature bits Maxim Davydov
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Maxim Davydov @ 2021-09-01  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: den, mst, stefanha, fam, amit, kraxel, berrange, Maxim Davydov

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 --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);
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 3/8] virtio-gpu: Add tracking of the virtio guest feature bits
  2021-09-01  9:07 [PATCH v1 0/8] Virtio features acknowledged by guest Maxim Davydov
  2021-09-01  9:07 ` [PATCH v1 1/8] qdev-properties: Add read-only 64 bit property Maxim Davydov
  2021-09-01  9:07 ` [PATCH v1 2/8] virtio: Add tracking of the common virtio guest features Maxim Davydov
@ 2021-09-01  9:07 ` Maxim Davydov
  2021-09-01  9:08 ` [PATCH v1 4/8] virtio-serial: " Maxim Davydov
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Maxim Davydov @ 2021-09-01  9:07 UTC (permalink / raw)
  To: qemu-devel; +Cc: den, mst, stefanha, fam, amit, kraxel, berrange, Maxim Davydov

Add tracking of the bits acknowledged by the guest

Signed-off-by: Maxim Davydov <maxim.davydov@virtuozzo.com>
---
 hw/display/vhost-user-gpu.c    |  3 ++-
 hw/display/virtio-gpu.c        |  8 +++++---
 include/hw/virtio/virtio-gpu.h | 10 +++++-----
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
index 49df56c..8248a70 100644
--- a/hw/display/vhost-user-gpu.c
+++ b/hw/display/vhost-user-gpu.c
@@ -566,7 +566,8 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error **errp)
 }
 
 static Property vhost_user_gpu_properties[] = {
-    VIRTIO_GPU_BASE_PROPERTIES(VhostUserGPU, parent_obj.conf),
+    VIRTIO_GPU_BASE_PROPERTIES(VhostUserGPU, parent_obj.conf,
+                               parent_obj.parent_obj.guest_features),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 990e71f..a1c52ac 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -1387,11 +1387,13 @@ static const VMStateDescription vmstate_virtio_gpu = {
 };
 
 static Property virtio_gpu_properties[] = {
-    VIRTIO_GPU_BASE_PROPERTIES(VirtIOGPU, parent_obj.conf),
+    VIRTIO_GPU_BASE_PROPERTIES(VirtIOGPU, parent_obj.conf,
+                               parent_obj.parent_obj.guest_features),
     DEFINE_PROP_SIZE("max_hostmem", VirtIOGPU, conf_max_hostmem,
                      256 * MiB),
-    DEFINE_PROP_BIT("blob", VirtIOGPU, parent_obj.conf.flags,
-                    VIRTIO_GPU_FLAG_BLOB_ENABLED, false),
+    DEFINE_VIRTIO_FEATURE_BIT("blob", VirtIOGPU, parent_obj.conf.flags,
+                              parent_obj.parent_obj.guest_features,
+                              VIRTIO_GPU_FLAG_BLOB_ENABLED, false),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 24c6628..948ef69 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -143,11 +143,11 @@ struct VirtIOGPUBaseClass {
     void (*gl_flushed)(VirtIOGPUBase *g);
 };
 
-#define VIRTIO_GPU_BASE_PROPERTIES(_state, _conf)                       \
-    DEFINE_PROP_UINT32("max_outputs", _state, _conf.max_outputs, 1),    \
-    DEFINE_PROP_BIT("edid", _state, _conf.flags, \
-                    VIRTIO_GPU_FLAG_EDID_ENABLED, true), \
-    DEFINE_PROP_UINT32("xres", _state, _conf.xres, 1024), \
+#define VIRTIO_GPU_BASE_PROPERTIES(_state, _conf, _guest_field)           \
+    DEFINE_PROP_UINT32("max_outputs", _state, _conf.max_outputs, 1),      \
+    DEFINE_VIRTIO_FEATURE_BIT("edid", _state, _conf.flags, _guest_field,  \
+                              VIRTIO_GPU_FLAG_EDID_ENABLED, true),        \
+    DEFINE_PROP_UINT32("xres", _state, _conf.xres, 1024),                 \
     DEFINE_PROP_UINT32("yres", _state, _conf.yres, 768)
 
 typedef struct VGPUDMABuf {
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 4/8] virtio-serial: Add tracking of the virtio guest feature bits
  2021-09-01  9:07 [PATCH v1 0/8] Virtio features acknowledged by guest Maxim Davydov
                   ` (2 preceding siblings ...)
  2021-09-01  9:07 ` [PATCH v1 3/8] virtio-gpu: Add tracking of the virtio guest feature bits Maxim Davydov
@ 2021-09-01  9:08 ` Maxim Davydov
  2021-09-01  9:08 ` [PATCH v1 5/8] virtio-net: " Maxim Davydov
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Maxim Davydov @ 2021-09-01  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: den, mst, stefanha, fam, amit, kraxel, berrange, Maxim Davydov

Add tracking of the VIRTIO_CONSOLE_F_EMERG_WRITE acknowledged by
the guest.

Signed-off-by: Maxim Davydov <maxim.davydov@virtuozzo.com>
---
 hw/char/virtio-serial-bus.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index dd6bc27..b5f9f42 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -1159,8 +1159,9 @@ static const VMStateDescription vmstate_virtio_console = {
 static Property virtio_serial_properties[] = {
     DEFINE_PROP_UINT32("max_ports", VirtIOSerial, serial.max_virtserial_ports,
                                                   31),
-    DEFINE_PROP_BIT64("emergency-write", VirtIOSerial, host_features,
-                      VIRTIO_CONSOLE_F_EMERG_WRITE, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("emergency-write", VirtIOSerial, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_CONSOLE_F_EMERG_WRITE, true),
     DEFINE_PROP_END_OF_LIST(),
 };
 
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 5/8] virtio-net: Add tracking of the virtio guest feature bits
  2021-09-01  9:07 [PATCH v1 0/8] Virtio features acknowledged by guest Maxim Davydov
                   ` (3 preceding siblings ...)
  2021-09-01  9:08 ` [PATCH v1 4/8] virtio-serial: " Maxim Davydov
@ 2021-09-01  9:08 ` Maxim Davydov
  2021-09-01  9:08 ` [PATCH v1 6/8] scsi: Add tracking of the acknowledged " Maxim Davydov
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Maxim Davydov @ 2021-09-01  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: den, mst, stefanha, fam, amit, kraxel, berrange, Maxim Davydov

Add tracking of the bits acknowledged by the guest

Signed-off-by: Maxim Davydov <maxim.davydov@virtuozzo.com>
---
 hw/net/virtio-net.c | 118 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 72 insertions(+), 46 deletions(-)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 16d20cd..2fd9171 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -3562,52 +3562,78 @@ static const VMStateDescription vmstate_virtio_net = {
 };
 
 static Property virtio_net_properties[] = {
-    DEFINE_PROP_BIT64("csum", VirtIONet, host_features,
-                    VIRTIO_NET_F_CSUM, true),
-    DEFINE_PROP_BIT64("guest_csum", VirtIONet, host_features,
-                    VIRTIO_NET_F_GUEST_CSUM, true),
-    DEFINE_PROP_BIT64("gso", VirtIONet, host_features, VIRTIO_NET_F_GSO, true),
-    DEFINE_PROP_BIT64("guest_tso4", VirtIONet, host_features,
-                    VIRTIO_NET_F_GUEST_TSO4, true),
-    DEFINE_PROP_BIT64("guest_tso6", VirtIONet, host_features,
-                    VIRTIO_NET_F_GUEST_TSO6, true),
-    DEFINE_PROP_BIT64("guest_ecn", VirtIONet, host_features,
-                    VIRTIO_NET_F_GUEST_ECN, true),
-    DEFINE_PROP_BIT64("guest_ufo", VirtIONet, host_features,
-                    VIRTIO_NET_F_GUEST_UFO, true),
-    DEFINE_PROP_BIT64("guest_announce", VirtIONet, host_features,
-                    VIRTIO_NET_F_GUEST_ANNOUNCE, true),
-    DEFINE_PROP_BIT64("host_tso4", VirtIONet, host_features,
-                    VIRTIO_NET_F_HOST_TSO4, true),
-    DEFINE_PROP_BIT64("host_tso6", VirtIONet, host_features,
-                    VIRTIO_NET_F_HOST_TSO6, true),
-    DEFINE_PROP_BIT64("host_ecn", VirtIONet, host_features,
-                    VIRTIO_NET_F_HOST_ECN, true),
-    DEFINE_PROP_BIT64("host_ufo", VirtIONet, host_features,
-                    VIRTIO_NET_F_HOST_UFO, true),
-    DEFINE_PROP_BIT64("mrg_rxbuf", VirtIONet, host_features,
-                    VIRTIO_NET_F_MRG_RXBUF, true),
-    DEFINE_PROP_BIT64("status", VirtIONet, host_features,
-                    VIRTIO_NET_F_STATUS, true),
-    DEFINE_PROP_BIT64("ctrl_vq", VirtIONet, host_features,
-                    VIRTIO_NET_F_CTRL_VQ, true),
-    DEFINE_PROP_BIT64("ctrl_rx", VirtIONet, host_features,
-                    VIRTIO_NET_F_CTRL_RX, true),
-    DEFINE_PROP_BIT64("ctrl_vlan", VirtIONet, host_features,
-                    VIRTIO_NET_F_CTRL_VLAN, true),
-    DEFINE_PROP_BIT64("ctrl_rx_extra", VirtIONet, host_features,
-                    VIRTIO_NET_F_CTRL_RX_EXTRA, true),
-    DEFINE_PROP_BIT64("ctrl_mac_addr", VirtIONet, host_features,
-                    VIRTIO_NET_F_CTRL_MAC_ADDR, true),
-    DEFINE_PROP_BIT64("ctrl_guest_offloads", VirtIONet, host_features,
-                    VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, true),
-    DEFINE_PROP_BIT64("mq", VirtIONet, host_features, VIRTIO_NET_F_MQ, false),
-    DEFINE_PROP_BIT64("rss", VirtIONet, host_features,
-                    VIRTIO_NET_F_RSS, false),
-    DEFINE_PROP_BIT64("hash", VirtIONet, host_features,
-                    VIRTIO_NET_F_HASH_REPORT, false),
-    DEFINE_PROP_BIT64("guest_rsc_ext", VirtIONet, host_features,
-                    VIRTIO_NET_F_RSC_EXT, false),
+    DEFINE_VIRTIO_FEATURE_BIT64("csum", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_CSUM, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("guest_csum", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_GUEST_CSUM, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("gso", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_GSO, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("guest_tso4", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_GUEST_TSO4, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("guest_tso6", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_GUEST_TSO6, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("guest_ecn", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_GUEST_ECN, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("guest_ufo", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_GUEST_UFO, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("guest_announce", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_GUEST_ANNOUNCE, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("host_tso4", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_HOST_TSO4, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("host_tso6", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_HOST_TSO6, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("host_ecn", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_HOST_ECN, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("host_ufo", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_HOST_UFO, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("mrg_rxbuf", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_MRG_RXBUF, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("status", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_STATUS, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("ctrl_vq", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_CTRL_VQ, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("ctrl_rx", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_CTRL_RX, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("ctrl_vlan", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_CTRL_VLAN, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("ctrl_rx_extra", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_CTRL_RX_EXTRA, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("ctrl_mac_addr", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_CTRL_MAC_ADDR, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("ctrl_guest_offloads", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("mq", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_MQ, false),
+    DEFINE_VIRTIO_FEATURE_BIT64("rss", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_RSS, false),
+    DEFINE_VIRTIO_FEATURE_BIT64("hash", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_HASH_REPORT, false),
+    DEFINE_VIRTIO_FEATURE_BIT64("guest_rsc_ext", VirtIONet, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_NET_F_RSC_EXT, false),
     DEFINE_PROP_UINT32("rsc_interval", VirtIONet, rsc_timeout,
                        VIRTIO_NET_RSC_DEFAULT_INTERVAL),
     DEFINE_NIC_PROPERTIES(VirtIONet, nic_conf),
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 6/8] scsi: Add tracking of the acknowledged feature bits
  2021-09-01  9:07 [PATCH v1 0/8] Virtio features acknowledged by guest Maxim Davydov
                   ` (4 preceding siblings ...)
  2021-09-01  9:08 ` [PATCH v1 5/8] virtio-net: " Maxim Davydov
@ 2021-09-01  9:08 ` Maxim Davydov
  2021-09-01  9:08 ` [PATCH v1 7/8] virtio-blk: Add tracking of the virtio guest " Maxim Davydov
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Maxim Davydov @ 2021-09-01  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: den, mst, stefanha, fam, amit, kraxel, berrange, Maxim Davydov

Add tracking of the VIRTIO_SCSI_F_HOTPLUG, VIRTIO_SCSI_F_CHANGE and
VIRTIO_SCSI_F_T10_PI bits acknowledged by the guest

Signed-off-by: Maxim Davydov <maxim.davydov@virtuozzo.com>
---
 hw/scsi/vhost-scsi.c      |  6 +++---
 hw/scsi/vhost-user-scsi.c | 18 +++++++++---------
 hw/scsi/virtio-scsi.c     | 10 ++++++----
 3 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c
index 8c611bf..4530295 100644
--- a/hw/scsi/vhost-scsi.c
+++ b/hw/scsi/vhost-scsi.c
@@ -277,9 +277,9 @@ static Property vhost_scsi_properties[] = {
     DEFINE_PROP_UINT32("max_sectors", VirtIOSCSICommon, conf.max_sectors,
                        0xFFFF),
     DEFINE_PROP_UINT32("cmd_per_lun", VirtIOSCSICommon, conf.cmd_per_lun, 128),
-    DEFINE_PROP_BIT64("t10_pi", VHostSCSICommon, host_features,
-                                                 VIRTIO_SCSI_F_T10_PI,
-                                                 false),
+    DEFINE_VIRTIO_FEATURE_BIT64("t10_pi", VHostSCSICommon,
+                                host_features, dev.acked_features,
+                                VIRTIO_SCSI_F_T10_PI, false),
     DEFINE_PROP_BOOL("migratable", VHostSCSICommon, migratable, false),
     DEFINE_PROP_END_OF_LIST(),
 };
diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c
index 1b2f7ee..40f885d 100644
--- a/hw/scsi/vhost-user-scsi.c
+++ b/hw/scsi/vhost-user-scsi.c
@@ -168,15 +168,15 @@ static Property vhost_user_scsi_properties[] = {
     DEFINE_PROP_UINT32("max_sectors", VirtIOSCSICommon, conf.max_sectors,
                        0xFFFF),
     DEFINE_PROP_UINT32("cmd_per_lun", VirtIOSCSICommon, conf.cmd_per_lun, 128),
-    DEFINE_PROP_BIT64("hotplug", VHostSCSICommon, host_features,
-                                                  VIRTIO_SCSI_F_HOTPLUG,
-                                                  true),
-    DEFINE_PROP_BIT64("param_change", VHostSCSICommon, host_features,
-                                                       VIRTIO_SCSI_F_CHANGE,
-                                                       true),
-    DEFINE_PROP_BIT64("t10_pi", VHostSCSICommon, host_features,
-                                                 VIRTIO_SCSI_F_T10_PI,
-                                                 false),
+    DEFINE_VIRTIO_FEATURE_BIT64("hotplug", VHostSCSICommon,
+                                host_features, dev.acked_features,
+                                VIRTIO_SCSI_F_HOTPLUG, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("param_change", VHostSCSICommon,
+                                host_features, dev.acked_features,
+                                VIRTIO_SCSI_F_CHANGE, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("t10_pi", VHostSCSICommon,
+                                host_features, dev.acked_features,
+                                VIRTIO_SCSI_F_T10_PI, false),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 6d80730..8f7dd14 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -1061,10 +1061,12 @@ static Property virtio_scsi_properties[] = {
                                                   0xFFFF),
     DEFINE_PROP_UINT32("cmd_per_lun", VirtIOSCSI, parent_obj.conf.cmd_per_lun,
                                                   128),
-    DEFINE_PROP_BIT("hotplug", VirtIOSCSI, host_features,
-                                           VIRTIO_SCSI_F_HOTPLUG, true),
-    DEFINE_PROP_BIT("param_change", VirtIOSCSI, host_features,
-                                                VIRTIO_SCSI_F_CHANGE, true),
+    DEFINE_VIRTIO_FEATURE_BIT("hotplug", VirtIOSCSI, host_features,
+                              parent_obj.parent_obj.guest_features,
+                              VIRTIO_SCSI_F_HOTPLUG, true),
+    DEFINE_VIRTIO_FEATURE_BIT("param_change", VirtIOSCSI, host_features,
+                              parent_obj.parent_obj.guest_features,
+                              VIRTIO_SCSI_F_CHANGE, true),
     DEFINE_PROP_LINK("iothread", VirtIOSCSI, parent_obj.conf.iothread,
                      TYPE_IOTHREAD, IOThread *),
     DEFINE_PROP_END_OF_LIST(),
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 7/8] virtio-blk: Add tracking of the virtio guest feature bits
  2021-09-01  9:07 [PATCH v1 0/8] Virtio features acknowledged by guest Maxim Davydov
                   ` (5 preceding siblings ...)
  2021-09-01  9:08 ` [PATCH v1 6/8] scsi: Add tracking of the acknowledged " Maxim Davydov
@ 2021-09-01  9:08 ` Maxim Davydov
  2021-09-01  9:08 ` [PATCH v1 8/8] virtio-balloon: " Maxim Davydov
  2021-09-02 12:34 ` [PATCH v1 0/8] Virtio features acknowledged by guest Stefan Hajnoczi
  8 siblings, 0 replies; 10+ messages in thread
From: Maxim Davydov @ 2021-09-01  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: den, mst, stefanha, fam, amit, kraxel, berrange, Maxim Davydov

Add tracking of the bits acknowledged by the guests

Signed-off-by: Maxim Davydov <maxim.davydov@virtuozzo.com>
---
 hw/block/virtio-blk.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index f139cd7..552b86c 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -1287,11 +1287,13 @@ static Property virtio_blk_properties[] = {
     DEFINE_BLOCK_ERROR_PROPERTIES(VirtIOBlock, conf.conf),
     DEFINE_BLOCK_CHS_PROPERTIES(VirtIOBlock, conf.conf),
     DEFINE_PROP_STRING("serial", VirtIOBlock, conf.serial),
-    DEFINE_PROP_BIT64("config-wce", VirtIOBlock, host_features,
-                      VIRTIO_BLK_F_CONFIG_WCE, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("config-wce", VirtIOBlock, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_BLK_F_CONFIG_WCE, true),
 #ifdef __linux__
-    DEFINE_PROP_BIT64("scsi", VirtIOBlock, host_features,
-                      VIRTIO_BLK_F_SCSI, false),
+    DEFINE_VIRTIO_FEATURE_BIT64("scsi", VirtIOBlock, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_BLK_F_SCSI, false),
 #endif
     DEFINE_PROP_BIT("request-merging", VirtIOBlock, conf.request_merging, 0,
                     true),
@@ -1301,12 +1303,14 @@ static Property virtio_blk_properties[] = {
     DEFINE_PROP_BOOL("seg-max-adjust", VirtIOBlock, conf.seg_max_adjust, true),
     DEFINE_PROP_LINK("iothread", VirtIOBlock, conf.iothread, TYPE_IOTHREAD,
                      IOThread *),
-    DEFINE_PROP_BIT64("discard", VirtIOBlock, host_features,
-                      VIRTIO_BLK_F_DISCARD, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("discard", VirtIOBlock, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_BLK_F_DISCARD, true),
     DEFINE_PROP_BOOL("report-discard-granularity", VirtIOBlock,
                      conf.report_discard_granularity, true),
-    DEFINE_PROP_BIT64("write-zeroes", VirtIOBlock, host_features,
-                      VIRTIO_BLK_F_WRITE_ZEROES, true),
+    DEFINE_VIRTIO_FEATURE_BIT64("write-zeroes", VirtIOBlock, host_features,
+                                parent_obj.guest_features,
+                                VIRTIO_BLK_F_WRITE_ZEROES, true),
     DEFINE_PROP_UINT32("max-discard-sectors", VirtIOBlock,
                        conf.max_discard_sectors, BDRV_REQUEST_MAX_SECTORS),
     DEFINE_PROP_UINT32("max-write-zeroes-sectors", VirtIOBlock,
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 8/8] virtio-balloon: Add tracking of the virtio guest feature bits
  2021-09-01  9:07 [PATCH v1 0/8] Virtio features acknowledged by guest Maxim Davydov
                   ` (6 preceding siblings ...)
  2021-09-01  9:08 ` [PATCH v1 7/8] virtio-blk: Add tracking of the virtio guest " Maxim Davydov
@ 2021-09-01  9:08 ` Maxim Davydov
  2021-09-02 12:34 ` [PATCH v1 0/8] Virtio features acknowledged by guest Stefan Hajnoczi
  8 siblings, 0 replies; 10+ messages in thread
From: Maxim Davydov @ 2021-09-01  9:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: den, mst, stefanha, fam, amit, kraxel, berrange, Maxim Davydov

Add tracking of the bits acknowledged by the guest

Signed-off-by: Maxim Davydov <maxim.davydov@virtuozzo.com>
---
 hw/virtio/virtio-balloon.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 4b5d9e5..61575b7 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -1029,14 +1029,18 @@ static const VMStateDescription vmstate_virtio_balloon = {
 };
 
 static Property virtio_balloon_properties[] = {
-    DEFINE_PROP_BIT("deflate-on-oom", VirtIOBalloon, host_features,
-                    VIRTIO_BALLOON_F_DEFLATE_ON_OOM, false),
-    DEFINE_PROP_BIT("free-page-hint", VirtIOBalloon, host_features,
-                    VIRTIO_BALLOON_F_FREE_PAGE_HINT, false),
-    DEFINE_PROP_BIT("page-poison", VirtIOBalloon, host_features,
-                    VIRTIO_BALLOON_F_PAGE_POISON, true),
-    DEFINE_PROP_BIT("free-page-reporting", VirtIOBalloon, host_features,
-                    VIRTIO_BALLOON_F_REPORTING, false),
+    DEFINE_VIRTIO_FEATURE_BIT("deflate-on-oom", VirtIOBalloon, host_features,
+                              parent_obj.guest_features,
+                              VIRTIO_BALLOON_F_DEFLATE_ON_OOM, false),
+    DEFINE_VIRTIO_FEATURE_BIT("free-page-hint", VirtIOBalloon, host_features,
+                              parent_obj.guest_features,
+                              VIRTIO_BALLOON_F_FREE_PAGE_HINT, false),
+    DEFINE_VIRTIO_FEATURE_BIT("page-poison", VirtIOBalloon, host_features,
+                              parent_obj.guest_features,
+                              VIRTIO_BALLOON_F_PAGE_POISON, true),
+    DEFINE_VIRTIO_FEATURE_BIT("free-page-reporting", VirtIOBalloon,
+                              host_features, parent_obj.guest_features,
+                              VIRTIO_BALLOON_F_REPORTING, false),
     /* QEMU 4.0 accidentally changed the config size even when free-page-hint
      * is disabled, resulting in QEMU 3.1 migration incompatibility.  This
      * property retains this quirk for QEMU 4.1 machine types.
-- 
1.8.3.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v1 0/8] Virtio features acknowledged by guest
  2021-09-01  9:07 [PATCH v1 0/8] Virtio features acknowledged by guest Maxim Davydov
                   ` (7 preceding siblings ...)
  2021-09-01  9:08 ` [PATCH v1 8/8] virtio-balloon: " Maxim Davydov
@ 2021-09-02 12:34 ` Stefan Hajnoczi
  8 siblings, 0 replies; 10+ messages in thread
From: Stefan Hajnoczi @ 2021-09-02 12:34 UTC (permalink / raw)
  To: Maxim Davydov
  Cc: fam, berrange, amit, mst, qemu-devel, kraxel, den, Jonah Palmer

[-- Attachment #1: Type: text/plain, Size: 2351 bytes --]

On Wed, Sep 01, 2021 at 12:07:56PM +0300, Maxim Davydov wrote:
> In some situations (for instance, debug), we want to be able to see the
> features that were confirmed by the guest. At the same time, we would like
> to do this safely, without the possibility of setting bits of guest
> features from the outside.
> 
> Maxim Davydov (8):
>   qdev-properties: Add read-only 64 bit property
>   virtio: Add tracking of the common virtio guest features
>   virtio-gpu: Add tracking of the virtio guest feature bits
>   virtio-serial: Add tracking of the virtio guest feature bits
>   virtio-net: Add tracking of the virtio guest feature bits
>   scsi: Add tracking of the acknowledged feature bits
>   virtio-blk: Add tracking of the virtio guest feature bits
>   virtio-balloon: Add tracking of the virtio guest feature bits
> 
>  hw/block/virtio-blk.c          |  20 ++++---
>  hw/char/virtio-serial-bus.c    |   5 +-
>  hw/core/qdev-properties.c      |  32 +++++++++++
>  hw/display/vhost-user-gpu.c    |   3 +-
>  hw/display/virtio-gpu.c        |   8 +--
>  hw/net/virtio-net.c            | 118 +++++++++++++++++++++++++----------------
>  hw/scsi/vhost-scsi.c           |   6 +--
>  hw/scsi/vhost-user-scsi.c      |  18 +++----
>  hw/scsi/virtio-scsi.c          |  10 ++--
>  hw/virtio/virtio-balloon.c     |  20 ++++---
>  hw/virtio/virtio.c             |   2 +-
>  include/hw/qdev-properties.h   |   5 ++
>  include/hw/virtio/virtio-gpu.h |  10 ++--
>  include/hw/virtio/virtio.h     |  39 +++++++++-----
>  14 files changed, 193 insertions(+), 103 deletions(-)

Hi Maxim,
The VIRTIO specification is designed to allow more than 64 feature bits.
Currently all feature bits fit into 64 bits but that may not be the case
in the future. Please use a representation that is capable of expanding
in the future.

The Linux guest drivers have a string sysfs attribute that is formatted
in binary ('0' and '1' characters). It's not easy for humans to read but
it is capable of growing in the future.

Also, please take a look at Jonah Palmer's patch series that adds
commands to introspect VIRTIO devices:
https://lore.kernel.org/qemu-devel/1626086137-16292-1-git-send-email-jonah.palmer@oracle.com/

I have CCed Jonah in case there is overlap between the two series that
you can work together on.

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-09-02 12:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01  9:07 [PATCH v1 0/8] Virtio features acknowledged by guest Maxim Davydov
2021-09-01  9:07 ` [PATCH v1 1/8] qdev-properties: Add read-only 64 bit property Maxim Davydov
2021-09-01  9:07 ` [PATCH v1 2/8] virtio: Add tracking of the common virtio guest features Maxim Davydov
2021-09-01  9:07 ` [PATCH v1 3/8] virtio-gpu: Add tracking of the virtio guest feature bits Maxim Davydov
2021-09-01  9:08 ` [PATCH v1 4/8] virtio-serial: " Maxim Davydov
2021-09-01  9:08 ` [PATCH v1 5/8] virtio-net: " Maxim Davydov
2021-09-01  9:08 ` [PATCH v1 6/8] scsi: Add tracking of the acknowledged " Maxim Davydov
2021-09-01  9:08 ` [PATCH v1 7/8] virtio-blk: Add tracking of the virtio guest " Maxim Davydov
2021-09-01  9:08 ` [PATCH v1 8/8] virtio-balloon: " Maxim Davydov
2021-09-02 12:34 ` [PATCH v1 0/8] Virtio features acknowledged by guest Stefan Hajnoczi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.