[PATCH v4 0/1] add RAPL feature in libvirt

Hi, The enhancement in this new version based on last feedback are: * add more documentation on limitation of the feature * no more double check of the vmsr socket, once is enough * virQEMUBuildBufferEscapeComma() is used for user input Path Because there is no garantie at the moment that the helper will be one day managed by libvirt, I decided not adding any preparation about this to avoid any confusion but add more documentation. If the helper is managed in libvirt, the patch introducing it will also add the necessary API like mention on the previous review (i.e mode='unmanaged'). Thanks Anthony Anthony Harivel (1): qemu: Add support for RAPL MSRs feature docs/formatdomain.rst | 15 +++++++++++++++ src/conf/domain_conf.c | 18 ++++++++++++++++++ src/conf/domain_conf.h | 2 ++ src/conf/schemas/domaincommon.rng | 10 ++++++++++ src/qemu/qemu_command.c | 9 +++++++++ tests/qemuxmlconfdata/kvm-features-off.xml | 1 + .../kvm-features.x86_64-latest.args | 2 +- tests/qemuxmlconfdata/kvm-features.xml | 1 + 8 files changed, 57 insertions(+), 1 deletion(-) -- 2.48.1

Add the support in libvirt to activate the RAPL feature in QEMU. This feature is activated with -accel kvm,rapl=true,path=/path/sock.sock in QEMU. The feature is activated in libvirt with the following XML configuration: <kvm> [...] <rapl state ='on' socket='/run/qemu-vmsr-helper.sock'/> [...] </kvm> See: https://gitlab.com/qemu-project/qemu/-/commit/0418f90809aea5b375c859e744c8e8... Signed-off-by: Anthony Harivel <aharivel@redhat.com> --- docs/formatdomain.rst | 15 +++++++++++++++ src/conf/domain_conf.c | 18 ++++++++++++++++++ src/conf/domain_conf.h | 2 ++ src/conf/schemas/domaincommon.rng | 10 ++++++++++ src/qemu/qemu_command.c | 9 +++++++++ tests/qemuxmlconfdata/kvm-features-off.xml | 1 + .../kvm-features.x86_64-latest.args | 2 +- tests/qemuxmlconfdata/kvm-features.xml | 1 + 8 files changed, 57 insertions(+), 1 deletion(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index cbe378e61d13..ffde3b880808 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -2022,6 +2022,7 @@ Hypervisors may allow certain CPU / machine features to be toggled on/off. <poll-control state='on'/> <pv-ipi state='off'/> <dirty-ring state='on' size='4096'/> + <rapl state ='on' socket='/run/qemu-vmsr-helper.sock'/> </kvm> <xen> <e820_host state='on'/> @@ -2141,8 +2142,22 @@ are: 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)` + rapl Enable rapl feature on, off; socket - rapl helper socket :since:`11.1.0 (QEMU 9.1)` ============== ============================================================================ ====================================================== ============================ + ``rapl`` + The RAPL feature enables a subset of Model-Specific Registers (MSRs) + within the guest, specifically dedicated to Intel's Running Average Power + Limit (RAPL). This feature requires a socket connection to an external + daemon to retrieve host MSRs. QEMU provides a helper, + ``qemu-vmsr-helper``, which can be used for this purpose. This dedicated + helper is not managed by libvirt and must be running on the host before + any guest with this feature enabled can boot. + + Libvirt does not handle socket security regarding Mandatory Access Control + (MAC) or Discretionary Access Control (DAC). Only one helper daemon is + needed per host, even when multiple guests are present. + ``xen`` Various features to change the behavior of the Xen hypervisor. diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 04da31f2dd2b..d687075803d6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -224,6 +224,7 @@ VIR_ENUM_IMPL(virDomainKVM, "poll-control", "pv-ipi", "dirty-ring", + "rapl", ); VIR_ENUM_IMPL(virDomainXen, @@ -16847,6 +16848,11 @@ virDomainFeaturesKVMDefParse(virDomainDef *def, return -1; } } + + /* rapl feature should parse socket property */ + if (feature == VIR_DOMAIN_KVM_RAPL && value == VIR_TRISTATE_SWITCH_ON) { + def->kvm_features->rapl_helper_socket = virXMLPropString(feat, "socket"); + } } def->features[VIR_DOMAIN_FEATURE_KVM] = VIR_TRISTATE_SWITCH_ON; @@ -21310,6 +21316,7 @@ virDomainDefFeaturesCheckABIStability(virDomainDef *src, case VIR_DOMAIN_KVM_POLLCONTROL: case VIR_DOMAIN_KVM_PVIPI: case VIR_DOMAIN_KVM_DIRTY_RING: + case VIR_DOMAIN_KVM_RAPL: if (src->kvm_features->features[i] != dst->kvm_features->features[i]) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("State of KVM feature '%1$s' differs: source: '%2$s', destination: '%3$s'"), @@ -28097,6 +28104,17 @@ virDomainDefFormatFeatures(virBuffer *buf, } break; + case VIR_DOMAIN_KVM_RAPL: + if (def->kvm_features->features[j] != VIR_TRISTATE_SWITCH_ABSENT) { + virBufferAsprintf(&childBuf, "<%s state='%s'", + virDomainKVMTypeToString(j), + virTristateSwitchTypeToString(def->kvm_features->features[j])); + + virBufferEscapeString(&childBuf, " socket='%s'", def->kvm_features->rapl_helper_socket); + 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 1fcc3fdb9890..e7b69474fe02 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2241,6 +2241,7 @@ typedef enum { VIR_DOMAIN_KVM_POLLCONTROL, VIR_DOMAIN_KVM_PVIPI, VIR_DOMAIN_KVM_DIRTY_RING, + VIR_DOMAIN_KVM_RAPL, VIR_DOMAIN_KVM_LAST } virDomainKVM; @@ -2447,6 +2448,7 @@ struct _virDomainFeatureKVM { int features[VIR_DOMAIN_KVM_LAST]; unsigned int dirty_ring_size; /* size of dirty ring for each vCPU, no units */ + char *rapl_helper_socket; /* rapl helper socket */ }; typedef struct _virDomainFeatureTCG virDomainFeatureTCG; diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng index 824da9d0662f..f44106222c31 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -8162,6 +8162,16 @@ </optional> </element> </optional> + <optional> + <element name="rapl"> + <ref name="featurestate"/> + <optional> + <attribute name="socket"> + <ref name="absFilePath"/> + </attribute> + </optional> + </element> + </optional> </interleave> </element> </define> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 0ad73af33597..4f99fb57b2fa 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6437,6 +6437,9 @@ qemuBuildCpuCommandLine(virCommand *cmd, case VIR_DOMAIN_KVM_DIRTY_RING: break; + case VIR_DOMAIN_KVM_RAPL: + break; + case VIR_DOMAIN_KVM_LAST: break; } @@ -7062,6 +7065,12 @@ qemuBuildAccelCommandLine(virCommand *cmd, def->kvm_features->features[VIR_DOMAIN_KVM_DIRTY_RING] == VIR_TRISTATE_SWITCH_ON) { virBufferAsprintf(&buf, ",dirty-ring-size=%d", def->kvm_features->dirty_ring_size); } + + if (def->features[VIR_DOMAIN_FEATURE_KVM] == VIR_TRISTATE_SWITCH_ON && + def->kvm_features->features[VIR_DOMAIN_KVM_RAPL] == VIR_TRISTATE_SWITCH_ON) { + virBufferAsprintf(&buf, ",rapl=true,rapl-helper-socket="); + virQEMUBuildBufferEscapeComma(&buf, def->kvm_features->rapl_helper_socket); + } break; case VIR_DOMAIN_VIRT_HVF: diff --git a/tests/qemuxmlconfdata/kvm-features-off.xml b/tests/qemuxmlconfdata/kvm-features-off.xml index 3cd4ff18f283..3e8dbea4b177 100644 --- a/tests/qemuxmlconfdata/kvm-features-off.xml +++ b/tests/qemuxmlconfdata/kvm-features-off.xml @@ -16,6 +16,7 @@ <poll-control state='off'/> <pv-ipi state='off'/> <dirty-ring state='off'/> + <rapl state='off'/> </kvm> </features> <cpu mode='host-passthrough' check='none' migratable='off'/> diff --git a/tests/qemuxmlconfdata/kvm-features.x86_64-latest.args b/tests/qemuxmlconfdata/kvm-features.x86_64-latest.args index 955db67eb4b7..2dd613ab338d 100644 --- a/tests/qemuxmlconfdata/kvm-features.x86_64-latest.args +++ b/tests/qemuxmlconfdata/kvm-features.x86_64-latest.args @@ -11,7 +11,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ -S \ -object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \ -machine pc,usb=off,dump-guest-core=off,memory-backend=pc.ram,acpi=on \ --accel kvm,dirty-ring-size=4096 \ +-accel kvm,dirty-ring-size=4096,rapl=true,rapl-helper-socket=/run/qemu-vmsr-helper.sock \ -cpu host,migratable=off,kvm=off,kvm-hint-dedicated=on,kvm-poll-control=on \ -m size=219136k \ -object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \ diff --git a/tests/qemuxmlconfdata/kvm-features.xml b/tests/qemuxmlconfdata/kvm-features.xml index 78091064b109..ee601e06de75 100644 --- a/tests/qemuxmlconfdata/kvm-features.xml +++ b/tests/qemuxmlconfdata/kvm-features.xml @@ -16,6 +16,7 @@ <poll-control state='on'/> <pv-ipi state='on'/> <dirty-ring state='on' size='4096'/> + <rapl state='on' socket='/run/qemu-vmsr-helper.sock'/> </kvm> </features> <cpu mode='host-passthrough' check='none' migratable='off'/> -- 2.48.1

On Thu, 6 Mar 2025 13:51:35 +0100 Anthony Harivel <aharivel@redhat.com> wrote:
Hi,
The enhancement in this new version based on last feedback are:
* add more documentation on limitation of the feature * no more double check of the vmsr socket, once is enough * virQEMUBuildBufferEscapeComma() is used for user input Path
Because there is no garantie at the moment that the helper will be one day managed by libvirt, I decided not adding any preparation about this to avoid any confusion but add more documentation.
If the helper is managed in libvirt, the patch introducing it will also add the necessary API like mention on the previous review (i.e mode='unmanaged').
I'd prefer wait till QEMU side is refactored to a more maintainable design (which would include CLI changes). So that libvirt won't have to maintain both current (which should be deprecated/removed) and to be CLI interface.
Thanks Anthony
Anthony Harivel (1): qemu: Add support for RAPL MSRs feature
docs/formatdomain.rst | 15 +++++++++++++++ src/conf/domain_conf.c | 18 ++++++++++++++++++ src/conf/domain_conf.h | 2 ++ src/conf/schemas/domaincommon.rng | 10 ++++++++++ src/qemu/qemu_command.c | 9 +++++++++ tests/qemuxmlconfdata/kvm-features-off.xml | 1 + .../kvm-features.x86_64-latest.args | 2 +- tests/qemuxmlconfdata/kvm-features.xml | 1 + 8 files changed, 57 insertions(+), 1 deletion(-)
participants (2)
-
Anthony Harivel
-
Igor Mammedov