[PATCH v2 4/5] KVM: VMX: Add get/set residency msrs logic

From: Wanpeng Li
Date: Tue Jun 11 2019 - 03:39:04 EST


From: Wanpeng Li <wanpengli@xxxxxxxxxxx>

Add logic to get/set the residency msrs. Then current idle
power-state residency statistics can be consult by guest, and
be save/restore during live migration.

Cc: Paolo Bonzini <pbonzini@xxxxxxxxxx>
Cc: Radim KrÄmÃÅ <rkrcmar@xxxxxxxxxx>
Signed-off-by: Wanpeng Li <wanpengli@xxxxxxxxxxx>
---
arch/x86/kvm/vmx/vmx.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 2ebaa90..852f51e 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -1715,6 +1715,9 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
case MSR_IA32_FEATURE_CONTROL:
msr_info->data = vmx->msr_ia32_feature_control;
break;
+ case MSR_CORE_C3_RESIDENCY ... MSR_CORE_C7_RESIDENCY:
+ msr_info->data = kvm_residency_read(vcpu, msr_info->index);
+ break;
case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC:
if (!nested_vmx_allowed(vcpu))
return 1;
@@ -1928,6 +1931,11 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
if (msr_info->host_initiated && data == 0)
vmx_leave_nested(vcpu);
break;
+ case MSR_CORE_C3_RESIDENCY ... MSR_CORE_C7_RESIDENCY:
+ if (!msr_info->host_initiated)
+ return 1;
+ kvm_residency_write(vcpu, msr_info->index, data);
+ break;
case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC:
if (!msr_info->host_initiated)
return 1; /* they are read-only */
--
2.7.4