Received: by 10.223.185.116 with SMTP id b49csp378696wrg; Tue, 20 Feb 2018 00:32:26 -0800 (PST) X-Google-Smtp-Source: AH8x224YDb9CKzrJUCdwtA3M9Bxc4zBkzi3yZX6rFraz87P4kUu1unV5rAwi0+lInNEDxEvkPRsz X-Received: by 10.99.39.1 with SMTP id n1mr14329700pgn.155.1519115546627; Tue, 20 Feb 2018 00:32:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519115546; cv=none; d=google.com; s=arc-20160816; b=liPsCQXjVdgO8857FRlJlCnI4jFbanbS5i+AHR33NQ/H0ZB6HGYwZzfihLziDcKoy+ UCO0DbdM4JzeD2OJfNNi4umJwbU4wZoUppZSWsgfq8lWzx8KUUEOVIIRuBbw8eUxcdmf mijrmsyj9Ct8TpXdFEqtq2Txu1WiVjGS22ObqBoN92l7xeQghU8VZm9pCscDxpbtI+mU mP+YP4gCi11KDmCUetSoJz2v8x0c9q876GryORoA1AUPNSEglOigK8X9oWdU1LbokYko ybPWaeYZv2Q/1Zl4fEopRDNM/lFeFXl16d9/L9rhLmltvoYR2V5AnqBZDICb4FToOWIl LbwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=adzRZBQbJt9daxmoiGDgTKPXZxzqA/h/k5ms8j7Q2Bc=; b=c1qq72HZDF3SEKeYe1bRGK/qo0DfxlKCa4BjBhBPYsn9DHKnzRIBfszyJQ7B7XhNcf 51ECXYv2xCB5BPcQEmqsEgZMozC5yWzwS2+DbxAjooBRFQIZu6qeVIIRflkLPmCjXjig UHhCr3DBTTjj7gHRF4/Ijz6OyczhJkW3rI/Zjjy4LiiTD7kge/fD2THhOJ7ki20ZUgM/ x125YrIIUHp33q7LJC0VwKgQ6dHMUKSbXPsAOq9JazoS5zSr1a86O03qMT3delaSHfnT v+TU7TRNUtOfe7zlism0ibFqgYTLtRzIzIC4EI4GUayJY0xOLuclABHKLuWeQBa398T7 8CYg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y21si4663770pfk.28.2018.02.20.00.32.09; Tue, 20 Feb 2018 00:32:26 -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; 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 S1751012AbeBTIba (ORCPT + 99 others); Tue, 20 Feb 2018 03:31:30 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:60736 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750703AbeBTIb2 (ORCPT ); Tue, 20 Feb 2018 03:31:28 -0500 Received: from [37.80.9.43] by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1eo3HI-00025Q-59; Tue, 20 Feb 2018 09:27:56 +0100 Date: Tue, 20 Feb 2018 09:31:29 +0100 (CET) From: Thomas Gleixner To: David Woodhouse cc: karahmed@amazon.de, x86@kernel.org, kvm@vger.kernel.org, torvalds@linux-foundation.org, pbonzini@redhat.com, linux-kernel@vger.kernel.org, bp@alien8.de, peterz@infradead.org, jmattson@google.com, rkrcmar@redhat.com, arjan.van.de.ven@intel.com, dave.hansen@intel.com, mingo@kernel.org Subject: Re: [PATCH v3 2/4] x86/speculation: Support "Enhanced IBRS" on future CPUs In-Reply-To: <1519037457-7643-3-git-send-email-dwmw@amazon.co.uk> Message-ID: References: <1519037457-7643-1-git-send-email-dwmw@amazon.co.uk> <1519037457-7643-3-git-send-email-dwmw@amazon.co.uk> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 19 Feb 2018, David Woodhouse wrote: > diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h > index 0995c6a..34cbce3 100644 > --- a/arch/x86/include/asm/nospec-branch.h > +++ b/arch/x86/include/asm/nospec-branch.h > @@ -141,9 +141,16 @@ enum spectre_v2_mitigation { > SPECTRE_V2_RETPOLINE_MINIMAL_AMD, > SPECTRE_V2_RETPOLINE_GENERIC, > SPECTRE_V2_RETPOLINE_AMD, > - SPECTRE_V2_IBRS, > + SPECTRE_V2_IBRS_ALL, > }; > > +extern enum spectre_v2_mitigation spectre_v2_enabled; > + > +static inline bool spectre_v2_ibrs_all(void) > +{ > + return spectre_v2_enabled == SPECTRE_V2_IBRS_ALL; > +} > + > extern char __indirect_thunk_start[]; > extern char __indirect_thunk_end[]; > > diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c > index bfca937..505c467 100644 > --- a/arch/x86/kernel/cpu/bugs.c > +++ b/arch/x86/kernel/cpu/bugs.c > @@ -88,12 +88,14 @@ static const char *spectre_v2_strings[] = { > [SPECTRE_V2_RETPOLINE_MINIMAL_AMD] = "Vulnerable: Minimal AMD ASM retpoline", > [SPECTRE_V2_RETPOLINE_GENERIC] = "Mitigation: Full generic retpoline", > [SPECTRE_V2_RETPOLINE_AMD] = "Mitigation: Full AMD retpoline", > + [SPECTRE_V2_IBRS_ALL] = "Mitigation: Enhanced IBRS", > }; > > #undef pr_fmt > #define pr_fmt(fmt) "Spectre V2 : " fmt > > -static enum spectre_v2_mitigation spectre_v2_enabled = SPECTRE_V2_NONE; > +enum spectre_v2_mitigation spectre_v2_enabled = SPECTRE_V2_NONE; > +EXPORT_SYMBOL_GPL(spectre_v2_enabled); > > #ifdef RETPOLINE > static bool spectre_v2_bad_module; > @@ -237,6 +239,16 @@ static void __init spectre_v2_select_mitigation(void) > > case SPECTRE_V2_CMD_FORCE: > case SPECTRE_V2_CMD_AUTO: > + if (boot_cpu_has(X86_FEATURE_ARCH_CAPABILITIES)) { > + u64 ia32_cap = 0; > + > + rdmsrl(MSR_IA32_ARCH_CAPABILITIES, ia32_cap); > + if (ia32_cap & ARCH_CAP_IBRS_ALL) { Hmm. We already read the MSR in cpu/common.c to check for the RDCL_NO bit. Shouldn't we just read it once and set a feature bit for IBRS_ALL? > + mode = SPECTRE_V2_IBRS_ALL; > + wrmsrl(MSR_IA32_SPEC_CTRL, SPEC_CTRL_IBRS); > + goto ibrs_all; > + } > + } > if (IS_ENABLED(CONFIG_RETPOLINE)) > goto retpoline_auto; > break; > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index 3dec126..5dfeb11 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -3387,13 +3387,14 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > > vmx->spec_ctrl = data; > > - if (!data) > + if (!data && !spectre_v2_ibrs_all()) > break; > > /* > * For non-nested: > * When it's written (to non-zero) for the first time, pass > - * it through. > + * it through unless we have IBRS_ALL and it should just be > + * set for ever. A non zero write is going to disable the intercept only when IBRS_ALL is on. The comment says is should be set forever, i.e. not changeable by the guest. So the condition should be: if (!data || spectre_v2_ibrs_all()) break; Hmm? > * > * For nested: > * The handling of the MSR bitmap for L2 guests is done in > @@ -9451,7 +9452,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu) > * is no need to worry about the conditional branch over the wrmsr > * being speculatively taken. > */ > - if (vmx->spec_ctrl) > + if (!spectre_v2_ibrs_all() && vmx->spec_ctrl) > wrmsrl(MSR_IA32_SPEC_CTRL, vmx->spec_ctrl); Which matches the code here. Thanks, tglx