Received: by 10.223.176.5 with SMTP id f5csp3287640wra; Thu, 1 Feb 2018 14:02:41 -0800 (PST) X-Google-Smtp-Source: AH8x226XEQRcHrW4mDe2oyufdNezp0I0BLNOc2T29TPOoJpGvHV/IV9dikUqCcxcomwTu7wPBOwc X-Received: by 2002:a17:902:a607:: with SMTP id u7-v6mr17449052plq.71.1517522561084; Thu, 01 Feb 2018 14:02:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517522561; cv=none; d=google.com; s=arc-20160816; b=DlkrKV9Pj8Pj6gBKzonMYnmy6t3YrLwEltRJfPilHHsljdrk9rCJUMMomFUttzKGVi H5WfI0kJ9QdHJ0Pd9Va9aWJK2TsjrL6prtfxmHTDiv5hCGYiZVh8hU8FXBVnI9HhNjDm 5hk+5/oaHUfzFBAZWxHT4CZnH0j+Nu5VWCvd2/pgoWtGCDxmK+FDuPX9bp6DT0ZTj0p7 ITmhHkcxBMwZ/hkb/p6pfKOG3Se542QFLxofTQobOgVJkWKMsEutYh6XjZijX0TZ/tQq ptgsl2jGGpZJWOHaZFrY7TEo+ymW9/XLOASDRsyYJ8KJM25OsRW1hC98ll4Yny4s8gIW lJ0g== 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:dkim-signature:arc-authentication-results; bh=rr3xxiqWxK3fY39F8ntKIhgel65VP5z4GgXsRxCa6Uc=; b=aH4/igbffuECUFJO6NDd28YKxUkyUZOMaD0ztsH+uqggksFa5dQnHdh1sT/TOFq7Cm fgEeCi1J4sDN02F1vS7ukV6xwL2oYE583neXwTlJ6sQw81TlL/0kWhJOjuQE00AAy8c6 +hA/Pjqxj4etXFqmCrshpC4PqPcMHgPhBgevOH6bPaoW3nuqGtnDcy7QoGGYE4CQoJGC etJuudYifm94oM+kbCY0sRnz4lAPNLucshxQNKE/+oNFpA+5IklldjLy0LPWlrj3ZIno SAN4iiuxWGhnP/elCjcsKDlsTBRqZkcwlnaNEx9iPgFAueBW1gAqoWErWbvDmB/p8ZLs OFsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=j3AGdOcu; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a31-v6si439771pla.500.2018.02.01.14.02.26; Thu, 01 Feb 2018 14:02:41 -0800 (PST) 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; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=j3AGdOcu; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752187AbeBAWAu (ORCPT + 99 others); Thu, 1 Feb 2018 17:00:50 -0500 Received: from smtp-fw-6002.amazon.com ([52.95.49.90]:24095 "EHLO smtp-fw-6002.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751824AbeBAWAO (ORCPT ); Thu, 1 Feb 2018 17:00:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1517522414; x=1549058414; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=rr3xxiqWxK3fY39F8ntKIhgel65VP5z4GgXsRxCa6Uc=; b=j3AGdOcuNlDvbwcUJwrIOiLAIQXrwif6GQKMC5Oa3C62x/Prfg9+ohnh jb1CQ7deXlYF9j0IsTL5EuSZ7SZiuyfwwosfQ0XDUc7IfuyGYt3+YJ56v n1fhk5VgdUm5qugnab6iKvztpxT5b2Z4xbC6si2lKS6nK2H3fc5wyrGOh Q=; X-IronPort-AV: E=Sophos;i="5.46,444,1511827200"; d="scan'208";a="330213004" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1e-c7c08562.us-east-1.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 01 Feb 2018 22:00:13 +0000 Received: from u54e1ad5160425a4b64ea.ant.amazon.com (iad1-ws-svc-lb91-vlan2.amazon.com [10.0.103.146]) by email-inbound-relay-1e-c7c08562.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id w11M02Ax010142 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 1 Feb 2018 22:00:04 GMT Received: from u54e1ad5160425a4b64ea.ant.amazon.com (localhost [127.0.0.1]) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id w11M00bZ018759; Thu, 1 Feb 2018 23:00:00 +0100 Received: (from karahmed@localhost) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Submit) id w11LxxPF018756; Thu, 1 Feb 2018 22:59:59 +0100 From: KarimAllah Ahmed To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: KarimAllah Ahmed , Asit Mallick , Dave Hansen , Arjan Van De Ven , Tim Chen , Linus Torvalds , Andrea Arcangeli , Andi Kleen , Thomas Gleixner , Dan Williams , Jun Nakajima , Andy Lutomirski , Greg KH , Paolo Bonzini , Ashok Raj , David Woodhouse Subject: [PATCH v6 3/5] KVM: VMX: Emulate MSR_IA32_ARCH_CAPABILITIES Date: Thu, 1 Feb 2018 22:59:44 +0100 Message-Id: <1517522386-18410-4-git-send-email-karahmed@amazon.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517522386-18410-1-git-send-email-karahmed@amazon.de> References: <1517522386-18410-1-git-send-email-karahmed@amazon.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Intel processors use MSR_IA32_ARCH_CAPABILITIES MSR to indicate RDCL_NO (bit 0) and IBRS_ALL (bit 1). This is a read-only MSR. By default the contents will come directly from the hardware, but user-space can still override it. [dwmw2: The bit in kvm_cpuid_7_0_edx_x86_features can be unconditional] Cc: Asit Mallick Cc: Dave Hansen Cc: Arjan Van De Ven Cc: Tim Chen Cc: Linus Torvalds Cc: Andrea Arcangeli Cc: Andi Kleen Cc: Thomas Gleixner Cc: Dan Williams Cc: Jun Nakajima Cc: Andy Lutomirski Cc: Greg KH Cc: Paolo Bonzini Cc: Ashok Raj Reviewed-by: Paolo Bonzini Signed-off-by: KarimAllah Ahmed Signed-off-by: David Woodhouse --- arch/x86/kvm/cpuid.c | 2 +- arch/x86/kvm/vmx.c | 15 +++++++++++++++ arch/x86/kvm/x86.c | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 033004d..1909635 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -394,7 +394,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, /* cpuid 7.0.edx*/ const u32 kvm_cpuid_7_0_edx_x86_features = - F(AVX512_4VNNIW) | F(AVX512_4FMAPS); + F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(ARCH_CAPABILITIES); /* all calls to cpuid_count() should be made on the same cpu */ get_cpu(); diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 263eb1f..b13314a 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -593,6 +593,8 @@ struct vcpu_vmx { u64 msr_guest_kernel_gs_base; #endif + u64 arch_capabilities; + u32 vm_entry_controls_shadow; u32 vm_exit_controls_shadow; u32 secondary_exec_control; @@ -3262,6 +3264,12 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) case MSR_IA32_TSC: msr_info->data = guest_read_tsc(vcpu); break; + case MSR_IA32_ARCH_CAPABILITIES: + if (!msr_info->host_initiated && + !guest_cpuid_has(vcpu, X86_FEATURE_ARCH_CAPABILITIES)) + return 1; + msr_info->data = to_vmx(vcpu)->arch_capabilities; + break; case MSR_IA32_SYSENTER_CS: msr_info->data = vmcs_read32(GUEST_SYSENTER_CS); break; @@ -3397,6 +3405,11 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) vmx_disable_intercept_for_msr(vmx->vmcs01.msr_bitmap, MSR_IA32_PRED_CMD, MSR_TYPE_W); break; + case MSR_IA32_ARCH_CAPABILITIES: + if (!msr_info->host_initiated) + return 1; + vmx->arch_capabilities = data; + break; case MSR_IA32_CR_PAT: if (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_PAT) { if (!kvm_mtrr_valid(vcpu, MSR_IA32_CR_PAT, data)) @@ -5659,6 +5672,8 @@ static void vmx_vcpu_setup(struct vcpu_vmx *vmx) ++vmx->nmsrs; } + if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES)) + rdmsrl(MSR_IA32_ARCH_CAPABILITIES, vmx->arch_capabilities); vm_exit_controls_init(vmx, vmcs_config.vmexit_ctrl); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c53298d..4ec142e 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1009,6 +1009,7 @@ static u32 msrs_to_save[] = { #endif MSR_IA32_TSC, MSR_IA32_CR_PAT, MSR_VM_HSAVE_PA, MSR_IA32_FEATURE_CONTROL, MSR_IA32_BNDCFGS, MSR_TSC_AUX, + MSR_IA32_ARCH_CAPABILITIES }; static unsigned num_msrs_to_save; -- 2.7.4