From 5d18d740d889a71701c1e584a7c54c4ad838b2be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hyman=20Huang=28=E9=BB=84=E5=8B=87=29?= Date: Tue, 23 Nov 2021 09:36:58 -0500 Subject: [PATCH] qemu: support dirty ring feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dirty ring feature was introduced in qemu-6.1.0, this patch add the corresponding feature named 'dirty-ring', which enable dirty ring feature when starting VM. To enable the feature, the following XML needs to be added to the guest's domain description: If property "state=on", property "size" must be specified, which should be power of 2 and range in [1024, 65526]. Signed-off-by: Hyman Huang(黄勇) Signed-off-by: Michal Privoznik Reviewed-by: Michal Privoznik --- docs/formatdomain.rst | 18 ++++---- docs/schemas/domaincommon.rng | 10 +++++ src/conf/domain_conf.c | 45 +++++++++++++++++++ src/conf/domain_conf.h | 3 ++ src/qemu/qemu_command.c | 3 ++ tests/qemuxml2argvdata/kvm-features-off.xml | 1 + tests/qemuxml2argvdata/kvm-features.xml | 1 + tests/qemuxml2xmloutdata/kvm-features-off.xml | 1 + tests/qemuxml2xmloutdata/kvm-features.xml | 1 + 9 files changed, 75 insertions(+), 8 deletions(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 98eb7b7481..097796df72 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -1843,6 +1843,7 @@ Hypervisors may allow certain CPU / machine features to be toggled on/off. + @@ -1928,14 +1929,15 @@ are: ``kvm`` Various features to change the behavior of the KVM hypervisor. - ============== ============================================================================ ======= ============================ - Feature Description Value Since - ============== ============================================================================ ======= ============================ - hidden Hide the KVM hypervisor from standard MSR based discovery on, off :since:`1.2.8 (QEMU 2.1.0)` - hint-dedicated Allows a guest to enable optimizations when running on dedicated vCPUs on, off :since:`5.7.0 (QEMU 2.12.0)` - poll-control Decrease IO completion latency by introducing a grace period of busy waiting on, off :since:`6.10.0 (QEMU 4.2)` - pv-ipi Paravirtualized send IPIs on, off :since:`7.10.0 (QEMU 3.1)` - ============== ============================================================================ ======= ============================ + ============== ============================================================================ ====================================================== ============================ + Feature Description Value Since + ============== ============================================================================ ====================================================== ============================ + hidden Hide the KVM hypervisor from standard MSR based discovery on, off :since:`1.2.8 (QEMU 2.1.0)` + hint-dedicated Allows a guest to enable optimizations when running on dedicated vCPUs on, off :since:`5.7.0 (QEMU 2.12.0)` + poll-control Decrease IO completion latency by introducing a grace period of busy waiting on, off :since:`6.10.0 (QEMU 4.2)` + pv-ipi Paravirtualized send IPIs on, off :since:`7.10.0 (QEMU 3.1)` + dirty-ring Enable dirty ring feature on, off; size - must be power of 2, range [1024,65536] :since:`8.0.0 (QEMU 6.1)` + ============== ============================================================================ ====================================================== ============================ ``xen`` Various features to change the behavior of the Xen hypervisor. diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index ce51e95895..736cb35d4e 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -7225,6 +7225,16 @@ + + + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 07cbfa24bc..cd87057524 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -206,6 +206,7 @@ VIR_ENUM_IMPL(virDomainKVM, "hint-dedicated", "poll-control", "pv-ipi", + "dirty-ring", ); VIR_ENUM_IMPL(virDomainXen, @@ -17556,6 +17557,25 @@ virDomainFeaturesKVMDefParse(virDomainDef *def, kvm->features[feature] = value; + /* dirty ring feature should parse size property */ + if (feature == VIR_DOMAIN_KVM_DIRTY_RING && + value == VIR_TRISTATE_SWITCH_ON) { + + if (virXMLPropUInt(node, "size", 0, VIR_XML_PROP_REQUIRED, + &kvm->dirty_ring_size) < 0) { + return -1; + } + + if (!VIR_IS_POW2(kvm->dirty_ring_size) || + kvm->dirty_ring_size < 1024 || + kvm->dirty_ring_size > 65536) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("dirty ring must be power of 2 and ranges [1024, 65536]")); + + return -1; + } + } + node = xmlNextElementSibling(node); } @@ -21809,6 +21829,7 @@ virDomainDefFeaturesCheckABIStability(virDomainDef *src, case VIR_DOMAIN_KVM_DEDICATED: case VIR_DOMAIN_KVM_POLLCONTROL: case VIR_DOMAIN_KVM_PVIPI: + case VIR_DOMAIN_KVM_DIRTY_RING: if (src->kvm_features->features[i] != dst->kvm_features->features[i]) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("State of KVM feature '%s' differs: " @@ -21825,6 +21846,16 @@ virDomainDefFeaturesCheckABIStability(virDomainDef *src, break; } } + + if (src->kvm_features->dirty_ring_size != dst->kvm_features->dirty_ring_size) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("dirty ring size of KVM feature '%s' differs: " + "source: '%d', destination: '%d'"), + virDomainKVMTypeToString(i), + src->kvm_features->dirty_ring_size, + dst->kvm_features->dirty_ring_size); + return false; + } } /* smm */ @@ -27886,6 +27917,20 @@ virDomainDefFormatFeatures(virBuffer *buf, def->kvm_features->features[j])); break; + case VIR_DOMAIN_KVM_DIRTY_RING: + if (def->kvm_features->features[j] != VIR_TRISTATE_SWITCH_ABSENT) { + virBufferAsprintf(&childBuf, "<%s state='%s'", + virDomainKVMTypeToString(j), + virTristateSwitchTypeToString(def->kvm_features->features[j])); + if (def->kvm_features->dirty_ring_size > 0) { + virBufferAsprintf(&childBuf, " size='%d'/>\n", + def->kvm_features->dirty_ring_size); + } else { + virBufferAddLit(&childBuf, "/>\n"); + } + } + break; + case VIR_DOMAIN_KVM_LAST: break; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 5613d621bb..a3d2f5c7dc 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2085,6 +2085,7 @@ typedef enum { VIR_DOMAIN_KVM_DEDICATED, VIR_DOMAIN_KVM_POLLCONTROL, VIR_DOMAIN_KVM_PVIPI, + VIR_DOMAIN_KVM_DIRTY_RING, VIR_DOMAIN_KVM_LAST } virDomainKVM; @@ -2266,6 +2267,8 @@ VIR_ENUM_DECL(virDomainIBS); typedef struct _virDomainFeatureKVM virDomainFeatureKVM; struct _virDomainFeatureKVM { int features[VIR_DOMAIN_KVM_LAST]; + + unsigned int dirty_ring_size; /* size of dirty ring for each vCPU, no units */ }; typedef struct _virDomainFeatureTCG virDomainFeatureTCG; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 7cdec9f910..65e7d77a07 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6784,6 +6784,9 @@ qemuBuildCpuCommandLine(virCommand *cmd, virBufferAddLit(&buf, ",kvm-pv-ipi=off"); break; + case VIR_DOMAIN_KVM_DIRTY_RING: + break; + case VIR_DOMAIN_KVM_LAST: break; } diff --git a/tests/qemuxml2argvdata/kvm-features-off.xml b/tests/qemuxml2argvdata/kvm-features-off.xml index a1004a206b..fb7cbaf061 100644 --- a/tests/qemuxml2argvdata/kvm-features-off.xml +++ b/tests/qemuxml2argvdata/kvm-features-off.xml @@ -15,6 +15,7 @@ + diff --git a/tests/qemuxml2argvdata/kvm-features.xml b/tests/qemuxml2argvdata/kvm-features.xml index 51229a6c37..900431c4ff 100644 --- a/tests/qemuxml2argvdata/kvm-features.xml +++ b/tests/qemuxml2argvdata/kvm-features.xml @@ -15,6 +15,7 @@ + diff --git a/tests/qemuxml2xmloutdata/kvm-features-off.xml b/tests/qemuxml2xmloutdata/kvm-features-off.xml index 52a0ef0065..7ee6525cd9 100644 --- a/tests/qemuxml2xmloutdata/kvm-features-off.xml +++ b/tests/qemuxml2xmloutdata/kvm-features-off.xml @@ -15,6 +15,7 @@ + diff --git a/tests/qemuxml2xmloutdata/kvm-features.xml b/tests/qemuxml2xmloutdata/kvm-features.xml index 72e66fcbf5..8ce3a2b987 100644 --- a/tests/qemuxml2xmloutdata/kvm-features.xml +++ b/tests/qemuxml2xmloutdata/kvm-features.xml @@ -15,6 +15,7 @@ +