KVM: x86: Add emulation of MSR_SMI_COUNT

"Linux Kernel Mailing List" <[email protected]>
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/52797bf9a875c4a30f846196386684e646e08a91
Commit:     52797bf9a875c4a30f846196386684e646e08a91
Parent:     431f5d4443964bcc58ac2e4c6fd8ace6dcd3a8d1
Refname:    refs/heads/master
Author:     Liran Alon <[email protected]>
AuthorDate: Wed Nov 15 13:43:14 2017 +0200
Committer:  Paolo Bonzini <[email protected]>
CommitDate: Thu Dec 14 09:26:44 2017 +0100

    KVM: x86: Add emulation of MSR_SMI_COUNT
    
    This MSR returns the number of #SMIs that occurred on CPU since
    boot.
    
    It was seen to be used frequently by ESXi guest.
    
    Patch adds a new vcpu-arch specific var called smi_count to
    save the number of #SMIs which occurred on CPU since boot.
    It is exposed as a read-only MSR to guest (causing #GP
    on wrmsr) in RDMSR/WRMSR emulation code.
    MSR_SMI_COUNT is also added to emulated_msrs[] to make sure
    user-space can save/restore it for migration purposes.
    
    Signed-off-by: Liran Alon <[email protected]>
    Suggested-by: Paolo Bonzini <[email protected]>
    Reviewed-by: Nikita Leshenko <[email protected]>
    Reviewed-by: Bhavesh Davda <[email protected]>
    Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
    Reviewed-by: Paolo Bonzini <[email protected]>
    Reviewed-by: David Hildenbrand <[email protected]>
    Signed-off-by: Radim Krčmář <[email protected]>
---
 arch/x86/include/asm/kvm_host.h |  1 +
 arch/x86/kvm/x86.c              | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 515db75081d1..340e3604dcc7 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -504,6 +504,7 @@ struct kvm_vcpu_arch {
 	int mp_state;
 	u64 ia32_misc_enable_msr;
 	u64 smbase;
+	u64 smi_count;
 	bool tpr_access_reporting;
 	u64 ia32_xss;
 
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index dd2e80ac49ff..7ea9a57b0684 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1039,6 +1039,7 @@ static u32 emulated_msrs[] = {
 	MSR_IA32_MCG_CTL,
 	MSR_IA32_MCG_EXT_CTL,
 	MSR_IA32_SMBASE,
+	MSR_SMI_COUNT,
 	MSR_PLATFORM_INFO,
 	MSR_MISC_FEATURES_ENABLES,
 };
@@ -2231,6 +2232,11 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 			return 1;
 		vcpu->arch.smbase = data;
 		break;
+	case MSR_SMI_COUNT:
+		if (!msr_info->host_initiated)
+			return 1;
+		vcpu->arch.smi_count = data;
+		break;
 	case MSR_KVM_WALL_CLOCK_NEW:
 	case MSR_KVM_WALL_CLOCK:
 		vcpu->kvm->arch.wall_clock = data;
@@ -2505,6 +2511,9 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
 			return 1;
 		msr_info->data = vcpu->arch.smbase;
 		break;
+	case MSR_SMI_COUNT:
+		msr_info->data = vcpu->arch.smi_count;
+		break;
 	case MSR_IA32_PERF_STATUS:
 		/* TSC increment by tick */
 		msr_info->data = 1000ULL;
@@ -6451,6 +6460,7 @@ static int inject_pending_event(struct kvm_vcpu *vcpu, bool req_int_win)
 		kvm_x86_ops->queue_exception(vcpu);
 	} else if (vcpu->arch.smi_pending && !is_smm(vcpu) && kvm_x86_ops->smi_allowed(vcpu)) {
 		vcpu->arch.smi_pending = false;
+		++vcpu->arch.smi_count;
 		enter_smm(vcpu);
 	} else if (vcpu->arch.nmi_pending && kvm_x86_ops->nmi_allowed(vcpu)) {
 		--vcpu->arch.nmi_pending;
@@ -7808,6 +7818,7 @@ void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
 	vcpu->arch.hflags = 0;
 
 	vcpu->arch.smi_pending = 0;
+	vcpu->arch.smi_count = 0;
 	atomic_set(&vcpu->arch.nmi_queued, 0);
 	vcpu->arch.nmi_pending = 0;
 	vcpu->arch.nmi_injected = false;
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.