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 run.
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 at 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: where is VM's PMU MSR being saved in host, and when and where the VM's MSR is being restored to CPU during VMEnter???
I came across some of the related information on this topic that it may provide some hints for your case: