Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp565953yba; Wed, 3 Apr 2019 14:34:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJzwDPSRKX7SkCfj0wPHBpeN4OisUA/Eu90afYoMLQceJidAyxSTsUjuHgDKkXMqbZhrBe X-Received: by 2002:a17:902:e48f:: with SMTP id cj15mr2360771plb.256.1554327279250; Wed, 03 Apr 2019 14:34:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554327279; cv=none; d=google.com; s=arc-20160816; b=yhsEdORCjGyTeFRuEgE0MsxLagkbzgCOwgEpHoOwpMRNkcv2HLFqIju5FkYeYbBYMm 2zGO/rngKIZWrSWoo1Ryxenq40lc2p8Z2PWxCHiP3FdO6pCYFFI+Qh+haI5PjJbETVue mjyoLVbbIU2R86tUSNln2fUk+E0QoVZJ1kIqxmC7JQFqSQrOQDCRpcfcwKhdscpKFz9E QriJXerlgJoPSlxsRrOqXilewM5+593pldGOFcnr2DoHbxBvvc3Eu86v9t82jbyxTV+p KUdJn+D2SZj+ezn/wVm4oN0U6VxqnPanpI1MGFOrk8whhcBRboVk3EUICYzU7AiDBHE+ zRCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=QNGVBgZBcaJJN2oVshiMKTen8SBtdtMDwffprZDneRE=; b=fpYfLkb69tGs6tzUR5sV0ZlzPJG+uoc0mcDjOrpOj34gz4JUuJ9o5WtRGHqO6TnVNw vC3w6CjWY07JxIGiOHEmknQPBjx7NcJyxs7RrpS1+dg1YfC9kVW4cMwMf29zzjOA7O/D ZBLn9WcSraWZ68K4R+ic8jBIdr3/zok6bSyHV1KzXM1W1XTGs0AnOi1hlus3SHqIMFIl HhCfWMusXEnZ4zYY6f3lchULIJnnCpn9m6AU8Yzx82JTJ40zYDhbwg/7ML/uHIbJknCQ i55z399U9keHx3kfrQZM0YuDYW5PwBu2L1QG/STm1x9ua001pvHaF8ZRob4R2jeU4o78 Efrg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g34si14715527pld.115.2019.04.03.14.34.24; Wed, 03 Apr 2019 14:34:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728624AbfDCVdT (ORCPT + 99 others); Wed, 3 Apr 2019 17:33:19 -0400 Received: from mga05.intel.com ([192.55.52.43]:37312 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726151AbfDCVaS (ORCPT ); Wed, 3 Apr 2019 17:30:18 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Apr 2019 14:30:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,306,1549958400"; d="scan'208";a="334754253" Received: from romley-ivt3.sc.intel.com ([172.25.110.60]) by fmsmga005.fm.intel.com with ESMTP; 03 Apr 2019 14:30:11 -0700 From: Fenghua Yu To: "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "H Peter Anvin" , "Dave Hansen" , "Paolo Bonzini" , "Ashok Raj" , "Peter Zijlstra" , "Kalle Valo" , "Xiaoyao Li " , "Michael Chan" , "Ravi V Shankar" Cc: "linux-kernel" , "x86" , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, kvm@vger.kernel.org, Xiaoyao Li , Fenghua Yu Subject: [PATCH v6 11/20] kvm/x86: Emulate MSR IA32_CORE_CAPABILITY Date: Wed, 3 Apr 2019 14:21:57 -0700 Message-Id: <1554326526-172295-12-git-send-email-fenghua.yu@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1554326526-172295-1-git-send-email-fenghua.yu@intel.com> References: <1554326526-172295-1-git-send-email-fenghua.yu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiaoyao Li MSR IA32_CORE_CAPABILITY is a feature-enumerating MSR, bit 5 of which reports the capability of enabling detection of split locks (will be supported on future processors based on Tremont microarchitecture and later). CPUID.(EAX=7H,ECX=0):EDX[30] will enumerate the presence of the IA32_CORE_CAPABILITY MSR. Please check the latest Intel 64 and IA-32 Architectures Software Developer's Manual for more detailed information on the MSR and the split lock bit. Since MSR_IA32_CORE_CAPABILITY is a feature-enumerating MSR, emulate it in software regardless of host's capability. What we need to do is to set the right value of it to report the capability of guest. In this patch, just set the guest's core_capability as 0, because we haven't added support of the features it indicates to guest. It's for bisectability. Signed-off-by: Xiaoyao Li Signed-off-by: Fenghua Yu Acked-by: Paolo Bonzini --- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/cpuid.c | 6 ++++++ arch/x86/kvm/x86.c | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 159b5988292f..e28626f6a2e0 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -570,6 +570,7 @@ struct kvm_vcpu_arch { u64 ia32_xss; u64 microcode_version; u64 arch_capabilities; + u64 core_capability; /* * Paging state of the vcpu @@ -1527,6 +1528,7 @@ int kvm_pv_send_ipi(struct kvm *kvm, unsigned long ipi_bitmap_low, unsigned long icr, int op_64_bit); u64 kvm_get_arch_capabilities(void); +u64 kvm_get_core_capability(void); void kvm_define_shared_msr(unsigned index, u32 msr); int kvm_set_shared_msr(unsigned index, u64 val, u64 mask); diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index fd3951638ae4..4a2f7892ea31 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -505,6 +505,12 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, * if the host doesn't support it. */ entry->edx |= F(ARCH_CAPABILITIES); + /* + * Since we emulate MSR IA32_CORE_CAPABILITY in + * software, we can always enable it for guest + * regardless of host's capability. + */ + entry->edx |= F(CORE_CAPABILITY); } else { entry->ebx = 0; entry->ecx = 0; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 099b851dabaf..4459115eb0ec 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1159,6 +1159,7 @@ static u32 emulated_msrs[] = { MSR_IA32_TSC_ADJUST, MSR_IA32_TSCDEADLINE, MSR_IA32_ARCH_CAPABILITIES, + MSR_IA32_CORE_CAPABILITY, MSR_IA32_MISC_ENABLE, MSR_IA32_MCG_STATUS, MSR_IA32_MCG_CTL, @@ -1198,6 +1199,7 @@ static u32 msr_based_features[] = { MSR_F10H_DECFG, MSR_IA32_UCODE_REV, + MSR_IA32_CORE_CAPABILITY, MSR_IA32_ARCH_CAPABILITIES, }; @@ -1225,9 +1227,18 @@ u64 kvm_get_arch_capabilities(void) } EXPORT_SYMBOL_GPL(kvm_get_arch_capabilities); +u64 kvm_get_core_capability(void) +{ + return 0; +} +EXPORT_SYMBOL_GPL(kvm_get_core_capability); + static int kvm_get_msr_feature(struct kvm_msr_entry *msr) { switch (msr->index) { + case MSR_IA32_CORE_CAPABILITY: + msr->data = kvm_get_core_capability(); + break; case MSR_IA32_ARCH_CAPABILITIES: msr->data = kvm_get_arch_capabilities(); break; @@ -2451,6 +2462,12 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) break; case MSR_EFER: return set_efer(vcpu, data); + case MSR_IA32_CORE_CAPABILITY: + if (!msr_info->host_initiated) + return 1; + + vcpu->arch.core_capability = data; + break; case MSR_K7_HWCR: data &= ~(u64)0x40; /* ignore flush filter disable */ data &= ~(u64)0x100; /* ignore ignne emulation enable */ @@ -2762,6 +2779,12 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) case MSR_IA32_TSC: msr_info->data = kvm_scale_tsc(vcpu, rdtsc()) + vcpu->arch.tsc_offset; break; + case MSR_IA32_CORE_CAPABILITY: + if (!msr_info->host_initiated && + !guest_cpuid_has(vcpu, X86_FEATURE_CORE_CAPABILITY)) + return 1; + msr_info->data = vcpu->arch.core_capability; + break; case MSR_MTRRcap: case 0x200 ... 0x2ff: return kvm_mtrr_get_msr(vcpu, msr_info->index, &msr_info->data); @@ -8762,6 +8785,7 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) { vcpu->arch.arch_capabilities = kvm_get_arch_capabilities(); + vcpu->arch.core_capability = kvm_get_core_capability(); vcpu->arch.msr_platform_info = MSR_PLATFORM_INFO_CPUID_FAULT; kvm_vcpu_mtrr_init(vcpu); vcpu_load(vcpu); -- 2.19.1