Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp484176yba; Mon, 1 Apr 2019 10:12:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxBTnXgARyWXMyGHA8hdRIyRq5Vc/XFfc9CtGNxHQA2+nq1Poor0zsT27VE2LWqvxTHk3p X-Received: by 2002:a17:902:2b8b:: with SMTP id l11mr66951164plb.18.1554138779808; Mon, 01 Apr 2019 10:12:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554138779; cv=none; d=google.com; s=arc-20160816; b=Lasdr+ZCLxdOflonmVe44Rsf8VMArQUrKiV/NVyffi2QB6szupFpgdj3z6uWFTahb3 w5XbBZu0jGuheUcb3SLVvlHz8/kB3IVZkuiDYHttSXIw5dCLBvrAkiMgf8tFoq7/F8rt MoIcxe1UMUBYlhjfbarHKG2NDCOvpprbwxAP6XfMRImFyoDSOcj3Uo30ijtWsOPma32/ gdgrxbOUdvv8c74TM6ZgLA86SP7qplkig7BxfXcvNmKo8K6MAz6se6q350TBJrRzF9Fy gvd9G1mlAx1lzigOWUk7rKdQhsYs8Ohl4wAW2+c/pEcz6BufTLkHUp33yjiDYlWA0NfH TXWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xe1/SOmRbvIpWBqaN00KFkr7/WyNBKqII4zD6YTnkV4=; b=hpLGt2a6eG8Hyr2EXqlyhdsG+DHOaHkEOs/K2gRHig2xPnPFMOtpTN71GC9lpIORsE bQoEJWSK4DDpj8IBuVXkk7p4Pcs4uwX9JvDjl7vTDbNxAq9mUOa3JTh5AV3O7TWAAdwO ORlkQosxCUoLe5lOIA1r81oYuMY0pC6aTZ8RaeVx0mhtcxjJxOQaQP3+Apt0OH960xVT rbo3XLViMfYBdSwErGFkdva+ReAx2O4HDS9mjYuLwK0SWyKQkrE7lUIqLIwCL/5Nb4mI vBM80IJ2vShBi7gNiZyxybJ6N0yvXokC96LtnMieH47scZ04Rgk/nBzBw3hfUe+v2VT/ 6stA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qOvO1pgM; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g10si9037019pgs.397.2019.04.01.10.12.44; Mon, 01 Apr 2019 10:12:59 -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; dkim=pass header.i=@kernel.org header.s=default header.b=qOvO1pgM; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728876AbfDARLm (ORCPT + 99 others); Mon, 1 Apr 2019 13:11:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:60500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730233AbfDARLj (ORCPT ); Mon, 1 Apr 2019 13:11:39 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9BA7221925; Mon, 1 Apr 2019 17:11:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554138698; bh=AYrrGb95n7yiVIrOSDQLUOtkrK8i5lgbqdvJokrf60U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qOvO1pgMc/iNNC5G0NU/FdC/DujU2L35okZAmjQ/IkFRgbIZrta4PAggB4dBYQx8R 8Fz3BNQOZiqSdN6gbiPftCduV5f57ZXA/GAvcK0my1NNB50ZHQKf0yl2cQRxGnsAUA QD4POG6ZTKUChJKNjmhPKRltvfT3fiJfc7klDmAE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoyao Li , Jim Mattson , Sean Christopherson , Paolo Bonzini Subject: [PATCH 5.0 143/146] KVM: x86: Emulate MSR_IA32_ARCH_CAPABILITIES on AMD hosts Date: Mon, 1 Apr 2019 19:02:35 +0200 Message-Id: <20190401170100.134243839@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401170048.449559024@linuxfoundation.org> References: <20190401170048.449559024@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sean Christopherson commit 0cf9135b773bf32fba9dd8e6699c1b331ee4b749 upstream. The CPUID flag ARCH_CAPABILITIES is unconditioinally exposed to host userspace for all x86 hosts, i.e. KVM advertises ARCH_CAPABILITIES regardless of hardware support under the pretense that KVM fully emulates MSR_IA32_ARCH_CAPABILITIES. Unfortunately, only VMX hosts handle accesses to MSR_IA32_ARCH_CAPABILITIES (despite KVM_GET_MSRS also reporting MSR_IA32_ARCH_CAPABILITIES for all hosts). Move the MSR_IA32_ARCH_CAPABILITIES handling to common x86 code so that it's emulated on AMD hosts. Fixes: 1eaafe91a0df4 ("kvm: x86: IA32_ARCH_CAPABILITIES is always supported") Cc: stable@vger.kernel.org Reported-by: Xiaoyao Li Cc: Jim Mattson Signed-off-by: Sean Christopherson Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/vmx/vmx.c | 13 ------------- arch/x86/kvm/vmx/vmx.h | 1 - arch/x86/kvm/x86.c | 12 ++++++++++++ 4 files changed, 13 insertions(+), 14 deletions(-) --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -570,6 +570,7 @@ struct kvm_vcpu_arch { bool tpr_access_reporting; u64 ia32_xss; u64 microcode_version; + u64 arch_capabilities; /* * Paging state of the vcpu --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1679,12 +1679,6 @@ static int vmx_get_msr(struct kvm_vcpu * msr_info->data = to_vmx(vcpu)->spec_ctrl; 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; @@ -1891,11 +1885,6 @@ static int vmx_set_msr(struct kvm_vcpu * 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)) @@ -4083,8 +4072,6 @@ static void vmx_vcpu_setup(struct vcpu_v ++vmx->nmsrs; } - vmx->arch_capabilities = kvm_get_arch_capabilities(); - vm_exit_controls_init(vmx, vmx_vmexit_ctrl()); /* 22.2.1, 20.8.1 */ --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -191,7 +191,6 @@ struct vcpu_vmx { u64 msr_guest_kernel_gs_base; #endif - u64 arch_capabilities; u64 spec_ctrl; u32 vm_entry_controls_shadow; --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2443,6 +2443,11 @@ int kvm_set_msr_common(struct kvm_vcpu * if (msr_info->host_initiated) vcpu->arch.microcode_version = data; break; + case MSR_IA32_ARCH_CAPABILITIES: + if (!msr_info->host_initiated) + return 1; + vcpu->arch.arch_capabilities = data; + break; case MSR_EFER: return set_efer(vcpu, data); case MSR_K7_HWCR: @@ -2747,6 +2752,12 @@ int kvm_get_msr_common(struct kvm_vcpu * case MSR_IA32_UCODE_REV: msr_info->data = vcpu->arch.microcode_version; break; + case MSR_IA32_ARCH_CAPABILITIES: + if (!msr_info->host_initiated && + !guest_cpuid_has(vcpu, X86_FEATURE_ARCH_CAPABILITIES)) + return 1; + msr_info->data = vcpu->arch.arch_capabilities; + break; case MSR_IA32_TSC: msr_info->data = kvm_scale_tsc(vcpu, rdtsc()) + vcpu->arch.tsc_offset; break; @@ -8725,6 +8736,7 @@ struct kvm_vcpu *kvm_arch_vcpu_create(st int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) { + vcpu->arch.arch_capabilities = kvm_get_arch_capabilities(); vcpu->arch.msr_platform_info = MSR_PLATFORM_INFO_CPUID_FAULT; kvm_vcpu_mtrr_init(vcpu); vcpu_load(vcpu);