I am not sure if it is OK to post question here about KVM-QEMU, but since it is related to Intel's PMU, I would like to try here to get help.
I am using KVM-QEMU in Intel platform.
And I am wondering how is the PMC/PMU being virtualized in KVM?
My understanding of vPMC is as follows.
Since PMU is a shared physical resource, so hypervisor shall context save/restore VM's PMC configurations and counters during VMExit/VMEnter.
When VMEnter, the VM's PMC context is restored to physical CPU, and let it run. When VMExit, the PMC context is saved, and host context is loaded to CPU (perf context switch in Linux kernel).
But in my testing, I got confused.
(In my host Linux, the MSR of IA32_PERF_FIXed_CTRL is set to 0xb0)
First of all, in a launched VM, I 'wrmsr IA32_PERF_FIXed_CTRL 0x0b', to enable FIXed_CTR0 in VM.
Then, I logged the MSR of IA32_PERF_FIXed_CTRL on VMExit, and found FIXed_CTR0 is not enabled.
I think it may be when VMExit happens, it is already in the host context, so the MSR of IA32_PERF_FIXed_CTRL is the one of host, not the VM's.
But the question comes: Is my vPMC understanding correct or NOT? If it is correct, and when and where the VM's MSR is being restored to CPU during VMEnter???