Received: by 10.223.176.46 with SMTP id f43csp1128445wra; Sat, 20 Jan 2018 11:29:40 -0800 (PST) X-Google-Smtp-Source: AH8x227swaLOJ7nvNGC7Od0RRRH9gUqeTGv3IYnY+aIAcs0T4eZFGLy6jaR6fbRwaQ1HCitqj+Dh X-Received: by 10.101.83.195 with SMTP id z3mr2818009pgr.133.1516476580648; Sat, 20 Jan 2018 11:29:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516476580; cv=none; d=google.com; s=arc-20160816; b=at1IiNUBa6xuDntwIJ55MHLyuL2nJ2kaoxgR0wTb9kfqu/A6HqMA3RSdPMHkfwICrt cp6sNRcv/ZCTqXcjtSxTqeUQWiAIu8TF41oFdW7y5kmBO3UtlsPpB4G6oeFm/B+bZiQr FB4nghptezyPe0sMXscHByRh4EtxDhjN2wOGH9EtqJj0z7BYzLVnUGIhlXWQQphT3VMP o1593I13ViyDrn+74QIKcvY89yWZ/d3J94b1946ML2vUh5v8k+e3aMXMH9OKSSh36SMd 21TT21KFZ2FMTnh2fPj+i3irRZgFzquIEmfWuNsTSijnND6zxP4exVmsbIry8wFxdqCe ODqA== 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=cB+0f/8nQbtTpjmarM0FY5BRIuj/RLKxFSRKr//dBls=; b=xoDl98o9PqxvDDQLqF04Jvubyqbdnzn6eQGcFRajFX2ifTfDNzrDgME9Qh40e5+m4S 4CIDdf/3oNaw/z7EasUoTBM8Q4m8KW2wYZpnfN0x+csLtTLiIS9AJlDTDwBndBNsZ2i9 65NNnM560SSzgh9N/Sv+1cvwJnwS5lyNIeE1Xjz4qPtEfJGTnRCphoHD4J4vKIXrepBY b4iG98CDvn2KIMP8mvavy6QFlEqDDfMPq1+22BDT1PcGHHGRwjJcWziRrbEYooOLsZBp 2tS7+/3R4MdHLOq/LN99UyiBfLGLzHxHQmJLmrYSxpGlqsouy/9mvox8Bi0jxXOi7tuE UPow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=gjSiu/Ww; 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 s8si10368725pgp.682.2018.01.20.11.29.26; Sat, 20 Jan 2018 11:29:40 -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=gjSiu/Ww; 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 S1756697AbeATT2b (ORCPT + 99 others); Sat, 20 Jan 2018 14:28:31 -0500 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:16292 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756642AbeATT2M (ORCPT ); Sat, 20 Jan 2018 14:28:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1516476492; x=1548012492; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=cB+0f/8nQbtTpjmarM0FY5BRIuj/RLKxFSRKr//dBls=; b=gjSiu/WwwXw3DrDaQBPLIMtRDf0anb9UwohjlbMku0aMf72ikkF4okp1 PRgf4AgSp9uYPneKoXuTHT8rAdfVidXrFt9Elwj5cgHP3EWbOVMpjo/IS 7PPuoPV3O3yLlqvzHa8LmQZv6xTaF18yf69sv3hP4XU+E658UMF/D6WeI Q=; X-IronPort-AV: E=Sophos;i="5.46,387,1511827200"; d="scan'208";a="720491807" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-1d-37fd6b3d.us-east-1.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 20 Jan 2018 19:23:48 +0000 Received: from u54e1ad5160425a4b64ea.ant.amazon.com (iad1-ws-svc-lb91-vlan2.amazon.com [10.0.103.146]) by email-inbound-relay-1d-37fd6b3d.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id w0KJNOcA046474 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 20 Jan 2018 19:23:26 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 w0KJNLoM005250; Sat, 20 Jan 2018 20:23:22 +0100 Received: (from karahmed@localhost) by u54e1ad5160425a4b64ea.ant.amazon.com (8.15.2/8.15.2/Submit) id w0KJNJP1005248; Sat, 20 Jan 2018 20:23:19 +0100 From: KarimAllah Ahmed To: linux-kernel@vger.kernel.org Cc: KarimAllah Ahmed , Andi Kleen , Andrea Arcangeli , Andy Lutomirski , Arjan van de Ven , Ashok Raj , Asit Mallick , Borislav Petkov , Dan Williams , Dave Hansen , David Woodhouse , Greg Kroah-Hartman , "H . Peter Anvin" , Ingo Molnar , Janakarajan Natarajan , Joerg Roedel , Jun Nakajima , Laura Abbott , Linus Torvalds , Masami Hiramatsu , Paolo Bonzini , Peter Zijlstra , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Thomas Gleixner , Tim Chen , Tom Lendacky , kvm@vger.kernel.org, x86@kernel.org, Arjan Van De Ven Subject: [RFC 02/10] x86/kvm: Add IBPB support Date: Sat, 20 Jan 2018 20:22:53 +0100 Message-Id: <1516476182-5153-3-git-send-email-karahmed@amazon.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516476182-5153-1-git-send-email-karahmed@amazon.de> References: <1516476182-5153-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 From: Ashok Raj Add MSR passthrough for MSR_IA32_PRED_CMD and place branch predictor barriers on switching between VMs to avoid inter VM specte-v2 attacks. [peterz: rebase and changelog rewrite] [dwmw2: fixes] [karahmed: - vmx: expose PRED_CMD whenever it is available - svm: only pass through IBPB if it is available] 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: David Woodhouse Cc: Paolo Bonzini Signed-off-by: Ashok Raj Signed-off-by: Peter Zijlstra (Intel) Link: http://lkml.kernel.org/r/1515720739-43819-6-git-send-email-ashok.raj@intel.com Signed-off-by: David Woodhouse Signed-off-by: KarimAllah Ahmed --- arch/x86/kvm/svm.c | 14 ++++++++++++++ arch/x86/kvm/vmx.c | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 2744b973..cfdb9ab 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -529,6 +529,7 @@ struct svm_cpu_data { struct kvm_ldttss_desc *tss_desc; struct page *save_area; + struct vmcb *current_vmcb; }; static DEFINE_PER_CPU(struct svm_cpu_data *, svm_data); @@ -918,6 +919,9 @@ static void svm_vcpu_init_msrpm(u32 *msrpm) set_msr_interception(msrpm, direct_access_msrs[i].index, 1, 1); } + + if (boot_cpu_has(X86_FEATURE_AMD_PRED_CMD)) + set_msr_interception(msrpm, MSR_IA32_PRED_CMD, 1, 1); } static void add_msr_offset(u32 offset) @@ -1706,11 +1710,17 @@ static void svm_free_vcpu(struct kvm_vcpu *vcpu) __free_pages(virt_to_page(svm->nested.msrpm), MSRPM_ALLOC_ORDER); kvm_vcpu_uninit(vcpu); kmem_cache_free(kvm_vcpu_cache, svm); + /* + * The vmcb page can be recycled, causing a false negative in + * svm_vcpu_load(). So do a full IBPB now. + */ + indirect_branch_prediction_barrier(); } static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu) { struct vcpu_svm *svm = to_svm(vcpu); + struct svm_cpu_data *sd = per_cpu(svm_data, cpu); int i; if (unlikely(cpu != vcpu->cpu)) { @@ -1739,6 +1749,10 @@ static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu) if (static_cpu_has(X86_FEATURE_RDTSCP)) wrmsrl(MSR_TSC_AUX, svm->tsc_aux); + if (sd->current_vmcb != svm->vmcb) { + sd->current_vmcb = svm->vmcb; + indirect_branch_prediction_barrier(); + } avic_vcpu_load(vcpu, cpu); } diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index d1e25db..3b64de2 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2279,6 +2279,7 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu) if (per_cpu(current_vmcs, cpu) != vmx->loaded_vmcs->vmcs) { per_cpu(current_vmcs, cpu) = vmx->loaded_vmcs->vmcs; vmcs_load(vmx->loaded_vmcs->vmcs); + indirect_branch_prediction_barrier(); } if (!already_loaded) { @@ -6791,6 +6792,9 @@ static __init int hardware_setup(void) kvm_tsc_scaling_ratio_frac_bits = 48; } + if (boot_cpu_has(X86_FEATURE_SPEC_CTRL)) + vmx_disable_intercept_for_msr(MSR_IA32_PRED_CMD, false); + vmx_disable_intercept_for_msr(MSR_FS_BASE, false); vmx_disable_intercept_for_msr(MSR_GS_BASE, false); vmx_disable_intercept_for_msr(MSR_KERNEL_GS_BASE, true); -- 2.7.4