Received: by 10.223.176.5 with SMTP id f5csp160069wra; Tue, 30 Jan 2018 09:30:20 -0800 (PST) X-Google-Smtp-Source: AH8x224GVOR99EYaE0MS0rf3VC9wunugpV+pPTwBadH+PhDesEly1c3yjBkHGWnHaULBoDoox5dF X-Received: by 10.99.165.28 with SMTP id n28mr25129055pgf.103.1517333420418; Tue, 30 Jan 2018 09:30:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517333420; cv=none; d=google.com; s=arc-20160816; b=KuAF6uuTmKGCNJ9CocWMEz7LG+iWW1rKT+4+qQX/gFug5rK3L1oEtw6jRw44S/ofr7 dnJUC0NrqMXrroa4XQLmFVbJQcVRPFFsg4UR8/mQlUahTltEKnkdzF34JXgJB6sErCku TrB/kQRtz9QGWkG3+A2GjjM9Fyfgjkm5pVk862t4gGl6BqHuSkCKYJwlp0MeKOgoSio9 8iu6rgHHF4GoikHRciDJxmh2Wm9757SKZVBBFsc0ozl8DAjD2qGb7VjaQYglyoiToymv +4aoQY//3JTEkX2ixh/jI998JuylXDeur0MtmK/NI/Fswn2me0OrOU71FIJ/FBOlu0pX Crqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=x39Kf93wnx46yOngE/jdvF7h4kRnPhzmGu8lBmaKxFU=; b=nYs7K7LYOV3dTHiiDxuzOX4Ej5FRlt8Cf/YfmmlxaemNxivr5cMDcFRGb2gLGHdaJU /fvWfLG/CFYuQY7UIGWtxjF7srUVwcBg8+srudf4fZcKROIfgvdcizSAOsSb39+AIvYI t09DbMcNKVPT3+IQHRQ8IK7sdFidaEuljZ5Tx9U98ZEBorNmoSd8C5Vp4Exe3oAexMqu S9sZg2HbArRUBd8L2pduGth5ZUd4YIPqNtfpaMK9fQNc99wAoPsHYrUJ9VPt1UeFaCxL i6z48QjwzOg0zRdmgxgvaUzVrITtnZBlnTOjX49y4avprl4riP/S/Qo8iYY4IqsIm8Qa mqjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=DJ+gqClb; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m9si270348pfh.319.2018.01.30.09.30.04; Tue, 30 Jan 2018 09:30:20 -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=@google.com header.s=20161025 header.b=DJ+gqClb; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753338AbeA3Qdr (ORCPT + 99 others); Tue, 30 Jan 2018 11:33:47 -0500 Received: from mail-it0-f67.google.com ([209.85.214.67]:34731 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751805AbeA3Qdp (ORCPT ); Tue, 30 Jan 2018 11:33:45 -0500 Received: by mail-it0-f67.google.com with SMTP id m11so3085279iti.1 for ; Tue, 30 Jan 2018 08:33:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=x39Kf93wnx46yOngE/jdvF7h4kRnPhzmGu8lBmaKxFU=; b=DJ+gqClb0NI/xc3A1lM6+VoPXzLt5svncqulBXrLbwyRMX5Isb4n9YqSRrMkIvPGVS b4jIBAJLhEd5Z61v0JCAS71c90Bqc2jy/X/Drhxy96NufVlUCue9Nj/JMaFyjckvV7Be VZkZbscUzN8rN/xNrl04KfIHJ5oT3F2HSYyLy+YNmCrpjQEEpVnuYPb1fV5ag64cDK9l ho6EwgSVhyz6tRANOY17gnhGyO/yCzyumgCkW5s6mHtv8fwu/XMBav4IRIU/1l5Jx3PZ 9nv8XBaz5f/tMR1Rp37FCQM9Tt+cqEdVUOyWGgbl7J14MnMflTwq5RY+bkkqEXg/KWeC R7Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=x39Kf93wnx46yOngE/jdvF7h4kRnPhzmGu8lBmaKxFU=; b=KK6m4BvLPFZ58OK53TjMmr6H2oH5bROsjh54c0bfWPvJGFx8kqmbVQveRHsQTXjS8P X1BdN1pfrI4wjX8Zl+0R7TsiurMzLkiT2p3NOkr7Hin/mxDxCCv4YeN+UVBhxods8n3/ tkgiR/wWbvOnDuyemOHGuZf22shgP6J8C/f2MBVs2/aW/DLzaXRliOLqvg+S/qWzm3rg G5K6PQbtsUX7ZAai6XUoEELYCCyQJeKg77l2QbtgcbHsDUZOeXMv9NBn4eeOAKtMfQVB YxISx5oz00wrugybAw+ErbAah8QeQa2MQw9FxOXAAHP/yPBTujUF6GKY4D5eU9CZPI6h SKAA== X-Gm-Message-State: AKwxytdB36IFgMTBsnIeg+/Pm4+5ky4Vx4YJzBuNY+cbsSKGeDQWqAjy FYuYVlBeID7AaEd2A9/UqAAbyDlsAAJu2mxS+pBU8g== X-Received: by 10.36.28.20 with SMTP id c20mr32950711itc.142.1517330024972; Tue, 30 Jan 2018 08:33:44 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.128.7 with HTTP; Tue, 30 Jan 2018 08:33:44 -0800 (PST) In-Reply-To: <6dc02278-7004-1794-3705-69c8cad86be4@oracle.com> References: <20180109120311.27565-10-pbonzini@redhat.com> <6dc02278-7004-1794-3705-69c8cad86be4@oracle.com> From: Jim Mattson Date: Tue, 30 Jan 2018 08:33:44 -0800 Message-ID: Subject: Re: [9/8] KVM: x86: limit MSR_IA32_SPEC_CTRL access based on CPUID availability To: Mihai Carabas Cc: Paolo Bonzini , LKML , kvm list , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Liran Alon , Anthony Liguori , Tom Lendacky , David Woodhouse , Borislav Petkov , "the arch/x86 maintainers" , Konrad Rzeszutek Wilk Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org All MSR intercepts are enabled by default, so I don't think this patch does anything at all, unless I'm missing some context. On Tue, Jan 30, 2018 at 5:21 AM, Mihai Carabas wrote: > Hello Paolo, > > I've back ported this patch on 4.1, after adding the per-vcpu MSR bitmap. > Also enabled the SPEC_CTRL_MSR intercept if qemu instructed so [1]. > > Reviewed-by: Mihai Carabas > > [1] > +++ b/arch/x86/kvm/vmx.c > @@ -8391,6 +8391,16 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm > *kvm, unsigned int id) > vmx_disable_intercept_for_msr(msr_bitmap, MSR_IA32_PRED_CMD, > MSR_TYPE_R | MSR_TYPE_W); > vmx_disable_intercept_for_msr(msr_bitmap, MSR_IA32_BNDCFGS, > MSR_TYPE_R | MSR_TYPE_W); > > + /* > + * If the physical CPU or the vCPU of this VM doesn't > + * support SPEC_CTRL feature, catch each access to it. > + */ > + if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) || > + !guest_cpuid_has_spec_ctrl(&vmx->vcpu)) > + vmx_enable_intercept_for_msr( > + msr_bitmap, > + MSR_IA32_SPEC_CTRL, > + MSR_TYPE_R | MSR_TYPE_W); > > /* > * If PML is turned on, failure on enabling PML just results in > failure > > > > On 09.01.2018 14:03, Paolo Bonzini wrote: >> >> MSR_IA32_SPEC_CTRL is not available unless CPU[7,0].EDX[26] is 1. >> Check that against host CPUID or guest CPUID, respectively for >> host-initiated and guest-initiated accesses. >> >> Suggested-by: Jim Mattson >> Signed-off-by: Paolo Bonzini >> --- >> This is for after X86_FEATURE_SPEC_CTRL is added to Linux, but >> I still wanted to ack Jim's improvement. >> >> arch/x86/kvm/svm.c | 8 ++++++++ >> arch/x86/kvm/vmx.c | 8 ++++++++ >> 2 files changed, 16 insertions(+) >> >> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c >> index 97126c2bd663..3a646580d7c5 100644 >> --- a/arch/x86/kvm/svm.c >> +++ b/arch/x86/kvm/svm.c >> @@ -3648,6 +3648,10 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, >> struct msr_data *msr_info) >> msr_info->data = svm->nested.vm_cr_msr; >> break; >> case MSR_IA32_SPEC_CTRL: >> + if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) || >> + (!msr_info->host_initiated && >> + !guest_cpuid_has(vcpu, >> X86_FEATURE_SPEC_CTRL))) >> + return 1; >> msr_info->data = svm->spec_ctrl; >> break; >> case MSR_IA32_UCODE_REV: >> @@ -3806,6 +3810,10 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, >> struct msr_data *msr) >> vcpu_unimpl(vcpu, "unimplemented wrmsr: 0x%x data >> 0x%llx\n", ecx, data); >> break; >> case MSR_IA32_SPEC_CTRL: >> + if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) || >> + (!msr_info->host_initiated && >> + !guest_cpuid_has(vcpu, >> X86_FEATURE_SPEC_CTRL))) >> + return 1; >> svm->spec_ctrl = data; >> break; >> case MSR_IA32_APICBASE: >> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c >> index 49b4a2d61603..42bc7ee293e4 100644 >> --- a/arch/x86/kvm/vmx.c >> +++ b/arch/x86/kvm/vmx.c >> @@ -3368,6 +3368,10 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, >> struct msr_data *msr_info) >> msr_info->data = guest_read_tsc(vcpu); >> break; >> case MSR_IA32_SPEC_CTRL: >> + if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) || >> + (!msr_info->host_initiated && >> + !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL))) >> + return 1; >> msr_info->data = to_vmx(vcpu)->spec_ctrl; >> break; >> case MSR_IA32_SYSENTER_CS: >> @@ -3510,6 +3514,10 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, >> struct msr_data *msr_info) >> kvm_write_tsc(vcpu, msr_info); >> break; >> case MSR_IA32_SPEC_CTRL: >> + if (!static_cpu_has(X86_FEATURE_SPEC_CTRL) || >> + (!msr_info->host_initiated && >> + !guest_cpuid_has(vcpu, X86_FEATURE_SPEC_CTRL))) >> + return 1; >> to_vmx(vcpu)->spec_ctrl = data; >> break; >> case MSR_IA32_CR_PAT: >> >