From: Wanpeng Li <wanpen...@tencent.com>

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 <pbonz...@redhat.com>
Cc: Radim Krčmář <rkrc...@redhat.com>
Signed-off-by: Wanpeng Li <wanpen...@tencent.com>
---
 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

Reply via email to