Received: by 10.223.185.116 with SMTP id b49csp2402914wrg; Mon, 12 Feb 2018 09:01:04 -0800 (PST) X-Google-Smtp-Source: AH8x225nX0R2zJxGPkjxqIh7oFduQR26qFldLcjSlPrrjLf//cvkYUHPQyh0puJlB70txwZRrALU X-Received: by 10.98.159.200 with SMTP id v69mr12134907pfk.236.1518454863960; Mon, 12 Feb 2018 09:01:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518454863; cv=none; d=google.com; s=arc-20160816; b=yc3M9J4sFvoj4i1Y6bAeWUFlkEXM//gQvocErwfiv4ey/+PJPQbM/430AVVwEiny17 90jNtD62HQGmVhLROOIuSNuu70vSJ5KAezNIQEKg/KGS+nwKwuEEr17OUcVmaDhkKCZF piKAJ1weXFC4SOy9zwtrPF1Mz9k1Zec05P8FNt3JpyONjOfGye4o0CebtulyLOl5GKiS 0YmkxTRN7ij1pXi+l2KqM0V+D617tjlw0l1wFWnUREkCcEKnHGWCx6AcWC36hydXN2bY c+Z0HdwWNuYAvksDnPUXlDkKuvm6MTkgRmsxnkCG1iZ80tndtQ2Tm6ZTgu9CNruHs+bP 1niQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=L1FjIkO1W3jV39TIYwT66qGLsD07i3/JzhDH+LeKk8s=; b=LSaLuOeFPFQjxoNPB8qHbMBJAEK9YJmKq0NuY09MKidSsoygjQChut9BgvVodtIKWh Qv9YFyuYWBbcT+kNgtGGceJMaZKabtuGF3govmUxyV+jhP8KxhqQhA2i1k78ADXKQRE8 yMUxK04j7xLzRba2Ay0dny/aTwNaeiKKWcitkKYtZ41rDxgrEJ4PZfoO51/C6wWdqjD8 qldlUihLbubxA8vHDjiI7aM4/kEtgcZVjnp0E51+u/emPEhIqZXQODVWJ0hOwCUegn6s +j4chYAhugWLtfR4iQ+Kv6kbpJvMKNBWHjJysAQ6GC9VwvtgYJnWwfWlBQRspGlpuS/j +aZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=ICMi97UP; 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 z22si1198501pfa.255.2018.02.12.09.00.46; Mon, 12 Feb 2018 09:01:03 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=ICMi97UP; 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 S1752929AbeBLQ6z (ORCPT + 99 others); Mon, 12 Feb 2018 11:58:55 -0500 Received: from merlin.infradead.org ([205.233.59.134]:48552 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750912AbeBLQ6w (ORCPT ); Mon, 12 Feb 2018 11:58:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=L1FjIkO1W3jV39TIYwT66qGLsD07i3/JzhDH+LeKk8s=; b=ICMi97UPPIr4qA8HSEw+RZZxg IzvlUxjs6xnS38ZaeEe1qf0CMQnBQVkQYWx6+usQBlMa7hkUKt+zwcxDVrGL16zzCZpiyPWa+Y3q3 NDAUWkexYj2pGH4LzcKWkZ11Hx9MB8EjyqnKtKhmuUQ10ueaJmz//VRI9muunTc+ORPPxemX9P/z7 csXMcWlh9BPMSkj5A2zWkSkdKaSYUdTtuXLC6dnTmbqfoicBmHDNMVRdiUV7Ue4CxuM0/kWFXGC10 bWMw88jmRx+QgyjRxwV5LBwtAzJU0TEGI2g+UIuH5MUE2RF1epLaly95Zc8rMzEFsiWAPZH6icTai h1dboHudg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1elHR8-0004Aq-4g; Mon, 12 Feb 2018 16:58:38 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id C1DFB201FB4E0; Mon, 12 Feb 2018 17:58:35 +0100 (CET) Date: Mon, 12 Feb 2018 17:58:35 +0100 From: Peter Zijlstra To: Dave Hansen Cc: Ingo Molnar , hpa@zytor.com, tglx@linutronix.de, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, dwmw@amazon.co.uk, linux-tip-commits@vger.kernel.org, Borislav Petkov , Arjan van de Ven Subject: Re: [tip:x86/pti] x86/speculation: Use IBRS if available before calling into firmware Message-ID: <20180212165835.GO25181@hirez.programming.kicks-ass.net> References: <1518362359-1005-1-git-send-email-dwmw@amazon.co.uk> <20180212102211.cdrrqqd4hdw7xu5y@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 12, 2018 at 08:13:31AM -0800, Dave Hansen wrote: > On 02/12/2018 02:22 AM, Ingo Molnar wrote: > >> +static inline void firmware_restrict_branch_speculation_end(void) > >> +{ > >> + alternative_msr_write(MSR_IA32_SPEC_CTRL, 0, > >> + X86_FEATURE_USE_IBRS_FW); > > BTW., there's a detail that only occurred to me today, this enabling/disabling > > sequence is not NMI safe, and it might be called from NMI context: > > FWIW, Tim Chen and I talked about this a bunch. We ended up just > saving/restoring the MSR verbatim in the NMI handler the same way we do > CR3, stashing it in a high general-purpose-register (r%12?). That costs > a RDMSR (at least) and an WRMSR (which you can optimize out). We have a > patch for that somewhere if anybody wants it. I would really rather not do that on the NMI path.. And if we _have_ to, please keep a software shadow of that MSR state, such that we can avoid touching that MSR 99% of the time.