Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754645AbeALKI2 (ORCPT + 1 other); Fri, 12 Jan 2018 05:08:28 -0500 Received: from merlin.infradead.org ([205.233.59.134]:47852 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751904AbeALKI0 (ORCPT ); Fri, 12 Jan 2018 05:08:26 -0500 Date: Fri, 12 Jan 2018 11:08:18 +0100 From: Peter Zijlstra To: Ashok Raj Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , Tim Chen , Andy Lutomirski , Linus Torvalds , Greg KH , Dave Hansen , Andrea Arcangeli , Andi Kleen , Arjan Van De Ven , David Woodhouse , Dan Williams , Paolo Bonzini , Jun Nakajima , Asit Mallick Subject: Re: [PATCH 5/5] x86/feature: Detect the x86 feature Indirect Branch Prediction Barrier Message-ID: <20180112100817.GR3040@hirez.programming.kicks-ass.net> References: <1515720739-43819-1-git-send-email-ashok.raj@intel.com> <1515720739-43819-6-git-send-email-ashok.raj@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1515720739-43819-6-git-send-email-ashok.raj@intel.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Thu, Jan 11, 2018 at 05:32:19PM -0800, Ashok Raj wrote: > @@ -1711,11 +1715,18 @@ 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 could be recycled, causing a false negative in svm_vcpu_load; > + * block speculative execution. > + */ > + if (boot_cpu_has(X86_FEATURE_PRED_CMD)) > + native_wrmsrl(MSR_IA32_PRED_CMD, FEATURE_SET_IBPB); > } > @@ -3837,6 +3839,12 @@ static void free_loaded_vmcs(struct loaded_vmcs *loaded_vmcs) > free_vmcs(loaded_vmcs->vmcs); > loaded_vmcs->vmcs = NULL; > WARN_ON(loaded_vmcs->shadow_vmcs != NULL); > + /* > + * The VMCS could be recycled, causing a false negative in vmx_vcpu_load > + * block speculative execution. > + */ > + if (boot_cpu_has(X86_FEATURE_SPEC_CTRL)) > + native_wrmsrl(MSR_IA32_PRED_CMD, FEATURE_SET_IBPB); > } Whitespace damage. Also, why not introduce a helper like: static inline flush_ibpb(void) { if (static_cpu_has(X86_FEATURE_SPEC_CTRL)) native_write_msr(MSR_IA32_PRED_CMD, FEATURE_SET_IBPB); } ?