From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: ARC-Seal: i=1; a=rsa-sha256; t=1517130880; cv=none; d=google.com; s=arc-20160816; b=TS3Tx+eajIEdwhmrMBtF5I52/1pXIUE2sjoPGC2v2y9sS7qsRCLAW8O+u/AnYAZZoK jJeOT6JNM44NZs0+qe5VaXGLQYphcuBMn40IHZ6f4jHmPQiIXIPNbI0+5xSv4n9VShBO Pg4juw+pZ5o4AY9Ql4PNyBkYwkO7PyK0PiSAZl5gIcmceORGC0vQehGSOw+T+iVRK/ft OuHFZN1OYq6ObJaq+HlYb8buTG0wtK9vxE68E89CmD0kBPHlnVy5OitGM2TnleoYm0a8 IDEV+Kaj+6yZqDLTFB7u4qWfKt5ChL4XOea+UqLqEIlGlLxOvmCTMlByTK2rNvzVsTVf RjOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:sender:dkim-signature :arc-authentication-results; bh=B9X1AoIN5rYU8XhiV8byXKx0qvce12E0mDboBXM90+U=; b=kRpnOyllsEYo8vsOphZ9vk89Dt5q1VmG7GXLRr3YSigVlNUYuDtiai6DNmBPFXJ5YT LliUa6NzlEubLExSdtJpMAm9+nkQi2T+5JQm757y/serQfY+IDfFjl/3jYGsdJbK2MHb stDrfrrD8B/w0ac9hlUB+uxK2U3ibbISiXBraJTZcfSW1r93MlAsZ91bQMP6M3BiGG12 G2GPreCo2a7sk123ZqQIieg0P8CLbvs759OIqBvFj052uEXrslwHI0VRDVFapNcsNcR2 oJeNWYsN1C/yXL4Kv1ccX7YOWa4oX5zTBO0fQnDk4DudqNqSESqQpCsNbOj3LgG38Tu9 CTPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=H/+1P2J+; spf=pass (google.com: domain of mingo.kernel.org@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mingo.kernel.org@gmail.com Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=H/+1P2J+; spf=pass (google.com: domain of mingo.kernel.org@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mingo.kernel.org@gmail.com X-Google-Smtp-Source: AH8x227bMiD9HnokF5oIKnk9O1YwlM9jB3wh7GejmdwQYcGrfYb+6FMjoHZGO3aiA1KqxQgHpj5T4A== Sender: Ingo Molnar Date: Sun, 28 Jan 2018 10:14:37 +0100 From: Ingo Molnar To: Dan Williams Cc: tglx@linutronix.de, linux-arch@vger.kernel.org, Tom Lendacky , Andi Kleen , Kees Cook , kernel-hardening@lists.openwall.com, gregkh@linuxfoundation.org, x86@kernel.org, Ingo Molnar , Al Viro , "H. Peter Anvin" , torvalds@linux-foundation.org, alan@linux.intel.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 04/12] x86: introduce __uaccess_begin_nospec and ifence Message-ID: <20180128091437.4lbll5bev7mgdpug@gmail.com> References: <151703971300.26578.1185595719337719486.stgit@dwillia2-desk3.amr.corp.intel.com> <151703973427.26578.15693075353773519333.stgit@dwillia2-desk3.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <151703973427.26578.15693075353773519333.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: NeoMutt/20170609 (1.8.3) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1590732028739069125?= X-GMAIL-MSGID: =?utf-8?q?1590827030187814824?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: * Dan Williams wrote: > --- a/arch/x86/include/asm/uaccess.h > +++ b/arch/x86/include/asm/uaccess.h > @@ -124,6 +124,11 @@ extern int __get_user_bad(void); > > #define __uaccess_begin() stac() > #define __uaccess_end() clac() > +#define __uaccess_begin_nospec() \ > +({ \ > + stac(); \ > + ifence(); \ > +}) BTW., wouldn't it be better to switch the barrier order here, i.e. to do: ifence(); \ stac(); \ ? The reason is that stac()/clac() is usually paired, so there's a chance with short sequences that it would resolve with 'no externally visible changes to flags'. Also, there's many cases where flags are modified _inside_ the STAC/CLAC section, so grouping them together inside a speculation atom could be beneficial. The flip side is that if the MFENCE stalls the STAC that is ahead of it could be processed for 'free' - while it's always post barrier with my suggestion. But in any case it would be nice to see a discussion of this aspect in the changelog, even if the patch does not change. Thanks, Ingo