virtio-blk: advertise F_WCE (F_FLUSH) if F_CONFIG_WCE is advertised
authorEvgeny Yakovlev <wrfsh@yandex-team.ru>
Tue, 5 Nov 2019 18:22:17 +0000 (21:22 +0300)
committerStefan Hajnoczi <stefanha@redhat.com>
Fri, 13 Dec 2019 11:22:06 +0000 (11:22 +0000)
Virtio spec 1.1 (and earlier), 5.2.5.2 Driver Requirements: Device
Initialization:

"Devices SHOULD always offer VIRTIO_BLK_F_FLUSH, and MUST offer it if
they offer VIRTIO_BLK_F_CONFIG_WCE"

Currently F_CONFIG_WCE and F_WCE are not connected to each other.
Qemu will advertise F_CONFIG_WCE if config-wce argument is
set for virtio-blk device. And F_WCE is advertised only if
underlying block backend actually has it's caching enabled.

Fix this by advertising F_WCE if F_CONFIG_WCE is also advertised.

To preserve backwards compatibility with newer machine types make this
behaviour governed by "x-enable-wce-if-config-wce" virtio-blk-device
property and introduce hw_compat_4_2 with new property being off by
default for all machine types <= 4.2 (but don't introduce 4.3
machine type itself yet).

Signed-off-by: Evgeny Yakovlev <wrfsh@yandex-team.ru>
Message-Id: <1572978137-189218-1-git-send-email-wrfsh@yandex-team.ru>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
hw/arm/virt.c
hw/block/virtio-blk.c
hw/core/machine.c
hw/i386/pc_piix.c
hw/i386/pc_q35.c
hw/ppc/spapr.c
hw/s390x/s390-virtio-ccw.c
include/hw/boards.h
include/hw/virtio/virtio-blk.h

index d4bedc2607121d6288e582b1d522aea950c11eaa..bf4b1cbfb8680d2eb8e54a09bc9e5a83681e88b4 100644 (file)
@@ -2149,6 +2149,7 @@ type_init(machvirt_machine_init);
 
 static void virt_machine_4_2_options(MachineClass *mc)
 {
+    compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len);
 }
 DEFINE_VIRT_MACHINE_AS_LATEST(4, 2)
 
index 4c357d2928ff1cfe94a601c93ffaf044aba2b6ac..d62e6377c27d0761d9e99452ef4e18ed656161be 100644 (file)
@@ -991,7 +991,9 @@ static uint64_t virtio_blk_get_features(VirtIODevice *vdev, uint64_t features,
         virtio_add_feature(&features, VIRTIO_BLK_F_SCSI);
     }
 
-    if (blk_enable_write_cache(s->blk)) {
+    if (blk_enable_write_cache(s->blk) ||
+        (s->conf.x_enable_wce_if_config_wce &&
+         virtio_has_feature(features, VIRTIO_BLK_F_CONFIG_WCE))) {
         virtio_add_feature(&features, VIRTIO_BLK_F_WCE);
     }
     if (blk_is_read_only(s->blk)) {
@@ -1270,6 +1272,8 @@ static Property virtio_blk_properties[] = {
                        conf.max_discard_sectors, BDRV_REQUEST_MAX_SECTORS),
     DEFINE_PROP_UINT32("max-write-zeroes-sectors", VirtIOBlock,
                        conf.max_write_zeroes_sectors, BDRV_REQUEST_MAX_SECTORS),
+    DEFINE_PROP_BOOL("x-enable-wce-if-config-wce", VirtIOBlock,
+                     conf.x_enable_wce_if_config_wce, true),
     DEFINE_PROP_END_OF_LIST(),
 };
 
index 1689ad3bf8afd18f0e774ed41a8d4944b4224b22..023548b4f3d0b74bd1f36366a243ccbf34323ea2 100644 (file)
 #include "hw/pci/pci.h"
 #include "hw/mem/nvdimm.h"
 
+GlobalProperty hw_compat_4_2[] = {
+    { "virtio-blk-device", "x-enable-wce-if-config-wce", "off" },
+};
+const size_t hw_compat_4_2_len = G_N_ELEMENTS(hw_compat_4_2);
+
 GlobalProperty hw_compat_4_1[] = {
     { "virtio-pci", "x-pcie-flr-init", "off" },
 };
index 1bd70d1abbc434edb8b5ca69ee5d14bf189bcf9a..87aced0742ec3ac9b8414f00c8f25569573d3d9b 100644 (file)
@@ -431,6 +431,7 @@ static void pc_i440fx_4_2_machine_options(MachineClass *m)
     m->alias = "pc";
     m->is_default = 1;
     pcmc->default_cpu_version = 1;
+    compat_props_add(m->compat_props, hw_compat_4_2, hw_compat_4_2_len);
 }
 
 DEFINE_I440FX_MACHINE(v4_2, "pc-i440fx-4.2", NULL,
index 385e5cffb1673426ef32abed622e5f6c4cc77aa3..2608cd00623c872cc1df6bd0c9c8caa96af503cc 100644 (file)
@@ -354,6 +354,7 @@ static void pc_q35_4_2_machine_options(MachineClass *m)
     pc_q35_machine_options(m);
     m->alias = "q35";
     pcmc->default_cpu_version = 1;
+    compat_props_add(m->compat_props, hw_compat_4_2, hw_compat_4_2_len);
 }
 
 DEFINE_Q35_MACHINE(v4_2, "pc-q35-4.2", NULL,
index e076f6023c73208738dba2e7403b3c0e3666b44a..2ca92f21481988779fe79fa1bec665d87d87a2e9 100644 (file)
@@ -4496,7 +4496,7 @@ static const TypeInfo spapr_machine_info = {
  */
 static void spapr_machine_4_2_class_options(MachineClass *mc)
 {
-    /* Defaults for the latest behaviour inherited from the base class */
+    compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len);
 }
 
 DEFINE_SPAPR_MACHINE(4_2, "4.2", true);
index d3edeef0ad924af160eb83ea6724ba9c20ba7c08..cb5fe4c84d873d997523d721589d4a5d6e68e1a9 100644 (file)
@@ -645,6 +645,7 @@ static void ccw_machine_4_2_instance_options(MachineState *machine)
 
 static void ccw_machine_4_2_class_options(MachineClass *mc)
 {
+    compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len);
 }
 DEFINE_CCW_MACHINE(4_2, "4.2", true);
 
index de45087f34cb767d56b5393b3e3ad4ff5786a1ac..24cbeecbaeccde20b12e0932168bfbc9465fe8f8 100644 (file)
@@ -329,6 +329,9 @@ struct MachineState {
     } \
     type_init(machine_initfn##_register_types)
 
+extern GlobalProperty hw_compat_4_2[];
+extern const size_t hw_compat_4_2_len;
+
 extern GlobalProperty hw_compat_4_1[];
 extern const size_t hw_compat_4_1_len;
 
index cddcfbebe913f52b951b60d5f2de1189d56d844c..9c19f5b6340eba934f539707246f993fbbf65d8f 100644 (file)
@@ -40,6 +40,7 @@ struct VirtIOBlkConf
     uint16_t queue_size;
     uint32_t max_discard_sectors;
     uint32_t max_write_zeroes_sectors;
+    bool x_enable_wce_if_config_wce;
 };
 
 struct VirtIOBlockDataPlane;