From nobody Wed Mar 12 12:54:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1741265645608941.1406339470437; Thu, 6 Mar 2025 04:54:05 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 575821955; Thu, 6 Mar 2025 07:54:04 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E01B917FD; Thu, 6 Mar 2025 07:53:29 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 652791784; Thu, 6 Mar 2025 07:51:53 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 7DDCE1784 for ; Thu, 6 Mar 2025 07:51:52 -0500 (EST) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-632-geKSmL2JMdePfDaNUM109Q-1; Thu, 06 Mar 2025 07:51:50 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E5918180AF72 for ; Thu, 6 Mar 2025 12:51:49 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.44.22.12]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B4932180AF7B; Thu, 6 Mar 2025 12:51:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741265512; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j6KTnrVjkqQf1NMAYMzZdcIUYItTOUFeS71F2T0dbUk=; b=OPREt14WmfIGi3FMJYE6IJD2/OL47v74NIxQkaIVK3TOMgineEs/VTXLYH3Z7M2W3Br/hG qWpjfmgQ9td1VPuBG8S0+QArSCvrfVTYlvQJAjVF79Y5pm3NPft002RYN8NdsZv7y1oCgF +HXAqqf7JhYUeIhi8WDzU7h02geuNhs= X-MC-Unique: geKSmL2JMdePfDaNUM109Q-1 X-Mimecast-MFC-AGG-ID: geKSmL2JMdePfDaNUM109Q_1741265510 From: Anthony Harivel To: devel@lists.libvirt.org Subject: [PATCH v4 1/1] qemu: Add support for RAPL MSRs feature Date: Thu, 6 Mar 2025 13:51:36 +0100 Message-ID: <20250306125136.372504-2-aharivel@redhat.com> In-Reply-To: <20250306125136.372504-1-aharivel@redhat.com> References: <20250306125136.372504-1-aharivel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 8Ys6VbzFTwUQY0zFUFVukGf8HKm_vNzaZyZu9QrUAAo_1741265510 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-MailFrom: aharivel@redhat.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 Message-ID-Hash: T674GYJL7LH3XTBAG6VMOOSWS4VC4ZZB X-Message-ID-Hash: T674GYJL7LH3XTBAG6VMOOSWS4VC4ZZB X-Mailman-Approved-At: Thu, 06 Mar 2025 12:53:27 -0500 CC: aharivel@redhat.com X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1741265649675019100 Content-Type: text/plain; charset="utf-8"; x-default="true" Add the support in libvirt to activate the RAPL feature in QEMU. This feature is activated with -accel kvm,rapl=3Dtrue,path=3D/path/sock.sock in QEMU. The feature is activated in libvirt with the following XML configuration: [...] [...] See: https://gitlab.com/qemu-project/qemu/-/commit/0418f90809aea5b375c859e7= 44c8e8610e9be446 Signed-off-by: Anthony Harivel --- 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. + @@ -2141,8 +2142,22 @@ are: poll-control Decrease IO completion latency by introducing a grace pe= riod 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)` =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D =20 + ``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 extern= al + daemon to retrieve host MSRs. QEMU provides a helper, + ``qemu-vmsr-helper``, which can be used for this purpose. This dedic= ated + helper is not managed by libvirt and must be running on the host bef= ore + any guest with this feature enabled can boot. + + Libvirt does not handle socket security regarding Mandatory Access C= ontrol + (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. =20 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", ); =20 VIR_ENUM_IMPL(virDomainXen, @@ -16847,6 +16848,11 @@ virDomainFeaturesKVMDefParse(virDomainDef *def, return -1; } } + + /* rapl feature should parse socket property */ + if (feature =3D=3D VIR_DOMAIN_KVM_RAPL && value =3D=3D VIR_TRISTAT= E_SWITCH_ON) { + def->kvm_features->rapl_helper_socket =3D virXMLPropString(fea= t, "socket"); + } } =20 def->features[VIR_DOMAIN_FEATURE_KVM] =3D 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] !=3D 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; =20 + case VIR_DOMAIN_KVM_RAPL: + if (def->kvm_features->features[j] !=3D VIR_TRISTATE_S= WITCH_ABSENT) { + virBufferAsprintf(&childBuf, "<%s state=3D'%s'", + virDomainKVMTypeToString(j), + virTristateSwitchTypeToString(de= f->kvm_features->features[j])); + + virBufferEscapeString(&childBuf, " socket=3D'%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, =20 VIR_DOMAIN_KVM_LAST } virDomainKVM; @@ -2447,6 +2448,7 @@ struct _virDomainFeatureKVM { int features[VIR_DOMAIN_KVM_LAST]; =20 unsigned int dirty_ring_size; /* size of dirty ring for each vCPU, no = units */ + char *rapl_helper_socket; /* rapl helper socket */ }; =20 typedef struct _virDomainFeatureTCG virDomainFeatureTCG; diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index 824da9d0662f..f44106222c31 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -8162,6 +8162,16 @@ + + + + + + + + + + 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; =20 + 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] =3D=3D = VIR_TRISTATE_SWITCH_ON) { virBufferAsprintf(&buf, ",dirty-ring-size=3D%d", def->kvm_feat= ures->dirty_ring_size); } + + if (def->features[VIR_DOMAIN_FEATURE_KVM] =3D=3D VIR_TRISTATE_SWIT= CH_ON && + def->kvm_features->features[VIR_DOMAIN_KVM_RAPL] =3D=3D VIR_TR= ISTATE_SWITCH_ON) { + virBufferAsprintf(&buf, ",rapl=3Dtrue,rapl-helper-socket=3D"); + virQEMUBuildBufferEscapeComma(&buf, def->kvm_features->rapl_he= lper_socket); + } break; =20 case VIR_DOMAIN_VIRT_HVF: diff --git a/tests/qemuxmlconfdata/kvm-features-off.xml b/tests/qemuxmlconf= data/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 @@ + 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=3D/var/lib/libvirt/qemu/domain--1-QEMUGue= st1/.config \ -S \ -object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/va= r/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \ -machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram,acpi= =3Don \ --accel kvm,dirty-ring-size=3D4096 \ +-accel kvm,dirty-ring-size=3D4096,rapl=3Dtrue,rapl-helper-socket=3D/run/qe= mu-vmsr-helper.sock \ -cpu host,migratable=3Doff,kvm=3Doff,kvm-hint-dedicated=3Don,kvm-poll-cont= rol=3Don \ -m size=3D219136k \ -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 @@ + --=20 2.48.1