Received: by 10.223.176.46 with SMTP id f43csp2099242wra; Sun, 21 Jan 2018 11:15:06 -0800 (PST) X-Google-Smtp-Source: AH8x224g8gV8EI7YU9nHOQX6eH0HI7lYNJhuz0NhBNLk7GwJoc5wORlWkd7UkC1mErywFXKkpDW7 X-Received: by 2002:a17:902:8:: with SMTP id 8-v6mr2269850pla.415.1516562105942; Sun, 21 Jan 2018 11:15:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516562105; cv=none; d=google.com; s=arc-20160816; b=IeYOn1hkSGFGwAX5LlckaHjKW8r5Eiwa0scQsppraodHKkWp48BxClZKP9b3+muYZ1 P0m8uoDSnuiwcfuRw0/JJTdOP2pybrmsBbYTBunJ9wt7GdErFUFjALRwGIUwg3uGNIBT MUb9v3rBd/4TkJtl2+vz62GhtuPDiMI7F1QYNTMj9kP40m3YKxbPZXGob8tXGk7HMpLU Qjn1wh7WBiMiFX9UZ71GBA/BsuvgWshkmu7hN2dOlIb+vzgPznp2o2dGQZYmrHYwNtGa 97RpHbgwk7nYbuDuwUlB4CYrIP7+sLTfc6mczjPMbEk5YpDRyOB2wQOjsfNPt0VVtsyC uDIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature:arc-authentication-results; bh=9YTcagmC9rvdtyK7f0b9eJLJL7Nn2g0Qhbodz9AsN4Q=; b=lwrASUVW/cpnmFJm7Y5PV3ZRX3wSuFEc9wTRo5pA4mVrzIwfAH3RIxosl+EY7mJFae KKMmQCqd1NxsW1dX+7aTqMdOwSver3FTKhxW8ztR2YzTi4oOf30NOh3Cd7KFHfu0OR+M 3BwSUQR59R7Q0lgjWeaDvwz+0CpfETKMdHIomZTUjeBTwv5/Lv21mBpVNDZhTutoiAVK 8IbwHrhlQgKgbfqZk+6NgD/Hx+qTAU3prywoNF7C5EkVJR4j+jXc4oh8XhAwjysacNX2 n1moJ6OGSZh6ZvUrQCuVbGCgMSKRO6Xhj33DTmooFEhS4Cv6DWE9wOP/FyYSlwFSVDZQ hrBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=GlvYHgaY; 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 f6si14081327pfg.125.2018.01.21.11.14.50; Sun, 21 Jan 2018 11:15:05 -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=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=GlvYHgaY; 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 S1751318AbeAUTOY (ORCPT + 99 others); Sun, 21 Jan 2018 14:14:24 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:33256 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750945AbeAUTOW (ORCPT ); Sun, 21 Jan 2018 14:14:22 -0500 Received: by mail-pg0-f65.google.com with SMTP id u1so5387985pgr.0 for ; Sun, 21 Jan 2018 11:14:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=9YTcagmC9rvdtyK7f0b9eJLJL7Nn2g0Qhbodz9AsN4Q=; b=GlvYHgaYTa3v88EIg+lYPhLqDIsxEYke2EiepC1OjfNn9HKdObrw7rVR406G+k5E2J AZ67vIeaGzKGGww76Wlo7DT/xAHEUM6HS3DMfc4BTG2L9cZur3kC3F+vske2ogwgkuac 3MrgGQjGPrOLf2HdO1sDhMOo6T8XT1W/jnh9Ks7ae0IJgSIaLk1obAvxrpetLraYzKhN 8qG33vfMRZLR7EjGF+YQJsQuvkAsgY8WCde8Y+5d2zNDhZAO//pEjkp5sDnoDzOyGHdS Ip77cq2bnEGc3LU1okXSWg91P2dpIsdU2Qcr5WVZtOOONFnGEL7uUa7F+JDH3wC9Zu3i nR8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=9YTcagmC9rvdtyK7f0b9eJLJL7Nn2g0Qhbodz9AsN4Q=; b=pUjgqqHbNhJ23wIMjS13DXBPtG0I8aaG3mxezSfwAHgEeuWZs+SYrhBe95KkWz3nqs vXXdlZOnUd+gofDKbQfsDFtWEka6k6APnxPSHkIu4qdcGsXimtDartW/ZlxrCAxozMVs NkkF5yVeSCOSguR3T5DfGi2JLQlAU4mKQMiuxsJwadgpRiX6XDwSNA25IQNfancrDn23 QWyDKL9YDLSg/W8fFijhwlB4aEw0BpknQ7FE257EXmwW1y21VDKDOPAPOHKiY3sj/4h1 JbqgzngVjo/ukspx1QQQu1gw1vFJS6lVE/CLWopOHM7jyli8fezQu3MKQSYBMNEOJAZM +92w== X-Gm-Message-State: AKwxytfrmIobv/ioG6qPiiuwYM2CzqzNiyGoyT76HjclT+77HzgmB1Sn 8GCjHY+sokC83bef26DM3R7x9w== X-Received: by 10.98.205.72 with SMTP id o69mr3591898pfg.104.1516562061838; Sun, 21 Jan 2018 11:14:21 -0800 (PST) Received: from ?IPv6:2600:1010:b016:785c:6d08:d017:904:ef7d? ([2600:1010:b016:785c:6d08:d017:904:ef7d]) by smtp.gmail.com with ESMTPSA id h74sm29856197pfh.28.2018.01.21.11.14.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Jan 2018 11:14:20 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (1.0) Subject: Re: [RFC 09/10] x86/enter: Create macros to restrict/unrestrict Indirect Branch Speculation From: Andy Lutomirski X-Mailer: iPhone Mail (15C202) In-Reply-To: <1516476182-5153-10-git-send-email-karahmed@amazon.de> Date: Sun, 21 Jan 2018 11:14:19 -0800 Cc: linux-kernel@vger.kernel.org, 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_Kr=C4=8Dm=C3=A1=C5=99?= , Thomas Gleixner , Tim Chen , Tom Lendacky , kvm@vger.kernel.org, x86@kernel.org, Arjan Van De Ven Content-Transfer-Encoding: quoted-printable Message-Id: <243BE571-AF73-44B3-8D17-193F9E07686A@amacapital.net> References: <1516476182-5153-1-git-send-email-karahmed@amazon.de> <1516476182-5153-10-git-send-email-karahmed@amazon.de> To: KarimAllah Ahmed Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Jan 20, 2018, at 11:23 AM, KarimAllah Ahmed wrote:= >=20 > From: Tim Chen >=20 > Create macros to control Indirect Branch Speculation. >=20 > Name them so they reflect what they are actually doing. > The macros are used to restrict and unrestrict the indirect branch specula= tion. > They do not *disable* (or *enable*) indirect branch speculation. A trip ba= ck to > user-space after *restricting* speculation would still affect the BTB. >=20 > Quoting from a commit by Tim Chen: >=20 > """ > If IBRS is set, near returns and near indirect jumps/calls will not all= ow > their predicted target address to be controlled by code that executed i= n a > less privileged prediction mode *BEFORE* the IBRS mode was last written= with > a value of 1 or on another logical processor so long as all Return Stac= k > Buffer (RSB) entries from the previous less privileged prediction mode a= re > overwritten. >=20 > Thus a near indirect jump/call/return may be affected by code in a less= > privileged prediction mode that executed *AFTER* IBRS mode was last wri= tten > with a value of 1. > """ >=20 > [ tglx: Changed macro names and rewrote changelog ] > [ karahmed: changed macro names *again* and rewrote changelog ] >=20 > Signed-off-by: Tim Chen > Signed-off-by: Thomas Gleixner > Signed-off-by: KarimAllah Ahmed > Cc: Andrea Arcangeli > Cc: Andi Kleen > Cc: Peter Zijlstra > Cc: Greg KH > Cc: Dave Hansen > Cc: Andy Lutomirski > Cc: Paolo Bonzini > Cc: Dan Williams > Cc: Arjan Van De Ven > Cc: Linus Torvalds > Cc: David Woodhouse > Cc: Ashok Raj > Link: https://lkml.kernel.org/r/3aab341725ee6a9aafd3141387453b45d788d61a.1= 515542293.git.tim.c.chen@linux.intel.com > Signed-off-by: David Woodhouse > --- > arch/x86/entry/calling.h | 73 ++++++++++++++++++++++++++++++++++++++++++++= ++++ > 1 file changed, 73 insertions(+) >=20 > diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h > index 3f48f69..5aafb51 100644 > --- a/arch/x86/entry/calling.h > +++ b/arch/x86/entry/calling.h > @@ -6,6 +6,8 @@ > #include > #include > #include > +#include > +#include >=20 > /* >=20 > @@ -349,3 +351,74 @@ For 32-bit we have the following conventions - kernel= is built with > .Lafter_call_\@: > #endif > .endm > + > +/* > + * IBRS related macros > + */ > +.macro PUSH_MSR_REGS > + pushq %rax > + pushq %rcx > + pushq %rdx > +.endm > + > +.macro POP_MSR_REGS > + popq %rdx > + popq %rcx > + popq %rax > +.endm > + > +.macro WRMSR_ASM msr_nr:req edx_val:req eax_val:req > + movl \msr_nr, %ecx > + movl \edx_val, %edx > + movl \eax_val, %eax > + wrmsr > +.endm > + > +.macro RESTRICT_IB_SPEC > + ALTERNATIVE "jmp .Lskip_\@", "", X86_FEATURE_IBRS > + PUSH_MSR_REGS > + WRMSR_ASM $MSR_IA32_SPEC_CTRL, $0, $SPEC_CTRL_IBRS > + POP_MSR_REGS > +.Lskip_\@: > +.endm > + > +.macro UNRESTRICT_IB_SPEC > + ALTERNATIVE "jmp .Lskip_\@", "", X86_FEATURE_IBRS > + PUSH_MSR_REGS > + WRMSR_ASM $MSR_IA32_SPEC_CTRL, $0, $0 I think you should be writing 2, not 0, since I'm reasonably confident that w= e want STIBP on. Can you explain why you're writing 0? Also, holy cow, there are so many macros here. And a meta question: why are there so many submitters of the same series?=