Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH v2 0/1] target/i386: Add support for KVM APERF/MPERF passthrough
@ 2026-06-02 14:03 Anderson Nascimento
  2026-06-02 14:03 ` [PATCH v2 1/1] " Anderson Nascimento
  0 siblings, 1 reply; 5+ messages in thread
From: Anderson Nascimento @ 2026-06-02 14:03 UTC (permalink / raw)
  To: qemu-devel, kvm, pbonzini, zhao1.liu, mtosatti; +Cc: Anderson Nascimento

Hello,

I have implemented support for exposing and enabling APERF/MPERF
MSR passthrough for x86 QEMU guests when running on KVM.

As of last year, the Linux kernel supports providing a capability
to disable APERF/MPERF read intercepts [1]. However, there is
currently no native way in QEMU to instruct KVM to activate this
capability or expose the feature bit cleanly via CPUID.

My patch introduces the `aperfmperf` feature flag via `FEAT_6_ECX`
(CPUID.06H:ECX[bit 0]). It ties into the existing power management
framework, so when a user enables power management via
`-overcommit cpu-pm=on` and passes `+aperfmperf` to the CPU, QEMU
requests KVM to drop the MSR intercepts.

For testing, I passed the feature via Libvirt XML like so:

    <qemu:arg value="-overcommit"/>
    <qemu:arg value="cpu-pm=on"/>
    <qemu:arg value="-cpu"/>
    <qemu:arg value="host,+aperfmperf,+invtsc"/>

A FreeBSD 16 guest is successfully able to read the changing
values of the MSRs directly without exiting to the hypervisor:

root@freebsd16development:/home/user # cpucontrol -i 6 /dev/cpuctl0
cpuid level 0x6: 0x00000004 0x00000000 0x00000001 0x00000000
root@freebsd16development:/home/user # cpucontrol -m 0xe7 /dev/cpuctl0
MSR 0xe7: 0x00007fdf 0x22480f90
root@freebsd16development:/home/user # cpucontrol -m 0xe7 /dev/cpuctl0
MSR 0xe7: 0x00007fdf 0x2b8b48b0
root@freebsd16development:/home/user # cpucontrol -m 0xe8 /dev/cpuctl0
MSR 0xe8: 0x000050de 0x49270831
root@freebsd16development:/home/user # cpucontrol -m 0xe8 /dev/cpuctl0
MSR 0xe8: 0x000050de 0x4ad66ae6
root@freebsd16development:/home/user #

Based-on: QEMU v11.0.50 (commit 5611a9268d)

v1 -> v2 changelog:
  - Add migration flags

Anderson Nascimento (1):
  target/i386: Add support for KVM APERF/MPERF passthrough

 target/i386/cpu.c     | 18 +++++++++++++++++-
 target/i386/cpu.h     |  2 ++
 target/i386/kvm/kvm.c |  5 ++++-
 3 files changed, 23 insertions(+), 2 deletions(-)

-- 
2.54.0


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

end of thread, other threads:[~2026-07-23  8:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-02 14:03 [PATCH v2 0/1] target/i386: Add support for KVM APERF/MPERF passthrough Anderson Nascimento
2026-06-02 14:03 ` [PATCH v2 1/1] " Anderson Nascimento
2026-06-26  0:50   ` Anderson Nascimento
2026-07-15 15:59     ` Anderson Nascimento
2026-07-23  8:48   ` Zhao Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox