Received: by 10.223.176.5 with SMTP id f5csp3382031wra; Mon, 29 Jan 2018 12:23:21 -0800 (PST) X-Google-Smtp-Source: AH8x22660p7bmMYiQjAYdaKZKJpCrSZtPnynkKZuVWLL38ifB3/yw/UsbVPiPg2JG784iX0ukmvI X-Received: by 2002:a17:902:900b:: with SMTP id a11-v6mr22707492plp.249.1517257400991; Mon, 29 Jan 2018 12:23:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517257400; cv=none; d=google.com; s=arc-20160816; b=M3OE4g272TzvpOhnLyyjFT8bmqS65kIPTMb1gRr77LhubhTyV7zWccHasHSqI16C09 wcEkJTGb1PiWrTJMpcrt2qxOEDLuOoIot8sBVcsPLNM4f3t13+MPjRf2HNrspztg1oG8 JWEc+pl4OsgfRA97c95rpAhsqc68FwfNDRiG3mpkJBc/TtM7wsJJS2tyRtZOmW22i3XE nggTDf3GPlRoI9KxtciXGC1Xcll3iJJy/g+aVvm1lgXe9Q24CdG+2h4PA/rocYmHsoWB 6wI22aYLGmTgHDHBNz7+Ncyg22f67J7PhI1DbnsgQhz0wKSq4KnrwhXCeclBulqwL7ne jd8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=weA+lwaBsV3L/SzPn4xeyRORfYcF72gPuzna7ncRNHc=; b=H8S06892dgrIi3AwjTErpQnUkltyg/MGFr6+iPejJWqHUDjdqeRwghvLCHaZoPeVaf qbluKTI+8iO7Ij8TIPbxL0FOwuvVuv6rH4RII+rOPjFOZbITNj3nzOLj2aXgUo4yKn+M ln5AH1sMwAh8M54RObb8B6f5z0TBCe2aS3YgCOItnSsiLl7WFa+nAnn+0dbZwZNI9RKJ cRw0F/IzI6un6mnCLLR068QOa1AXEClAfedU47k8swBwVbYEshF3n3WJFbZdWqv+Ux5L 3NjasBW+Sl5FSl7YOmIo+FOPvy9vIohYfm8GecRJ2yR3jukabHDPyor8Td9X74PJbBJ4 VuXQ== 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 e65si12751716pfg.255.2018.01.29.12.23.06; Mon, 29 Jan 2018 12:23:20 -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 S1754902AbeA2UWq (ORCPT + 99 others); Mon, 29 Jan 2018 15:22:46 -0500 Received: from mail.efficios.com ([167.114.142.141]:53423 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754811AbeA2UWf (ORCPT ); Mon, 29 Jan 2018 15:22:35 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 7C1803402EE; Mon, 29 Jan 2018 20:23:07 +0000 (UTC) Received: from mail.efficios.com ([127.0.0.1]) by localhost (evm-mail-1.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id y5P3Hvfk0Cj2; Mon, 29 Jan 2018 20:22:52 +0000 (UTC) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 4723C340305; Mon, 29 Jan 2018 20:22:41 +0000 (UTC) X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (evm-mail-1.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id xketf9VMIbIg; Mon, 29 Jan 2018 20:22:41 +0000 (UTC) Received: from thinkos.internal.efficios.com (192-222-157-41.qc.cable.ebox.net [192.222.157.41]) by mail.efficios.com (Postfix) with ESMTPSA id D36BA3402DE; Mon, 29 Jan 2018 20:22:40 +0000 (UTC) From: Mathieu Desnoyers To: Ingo Molnar , Peter Zijlstra , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Andy Lutomirski , "Paul E . McKenney" , Boqun Feng , Andrew Hunter , Maged Michael , Avi Kivity , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Dave Watson , "H . Peter Anvin" , Andrea Parri , Russell King , Greg Hackmann , Will Deacon , David Sehr , Linus Torvalds , x86@kernel.org, Mathieu Desnoyers , Arnd Bergmann , linux-arch@vger.kernel.org Subject: [PATCH for 4.16 v3 07/11] x86: Implement sync_core_before_usermode Date: Mon, 29 Jan 2018 15:20:16 -0500 Message-Id: <20180129202020.8515-8-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180129202020.8515-1-mathieu.desnoyers@efficios.com> References: <20180129202020.8515-1-mathieu.desnoyers@efficios.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ensure that a core serializing instruction is issued before returning to user-mode. x86 implements return to user-space through sysexit, sysrel, and sysretq, which are not core serializing. Signed-off-by: Mathieu Desnoyers Acked-by: Peter Zijlstra (Intel) CC: Thomas Gleixner CC: Andy Lutomirski CC: Paul E. McKenney CC: Boqun Feng CC: Andrew Hunter CC: Maged Michael CC: Avi Kivity CC: Benjamin Herrenschmidt CC: Paul Mackerras CC: Michael Ellerman CC: Dave Watson CC: Ingo Molnar CC: "H. Peter Anvin" CC: Andrea Parri CC: Russell King CC: Greg Hackmann CC: Will Deacon CC: David Sehr CC: Linus Torvalds CC: Arnd Bergmann CC: x86@kernel.org CC: linux-arch@vger.kernel.org --- Changes since v1: - Fix prototype of sync_core_before_usermode in generic code (missing return type). - Add linux/processor.h include to sched/core.c. - Add ARCH_HAS_SYNC_CORE_BEFORE_USERMODE to init/Kconfig. - Fix linux/processor.h ifdef to target CONFIG_ARCH_HAS_SYNC_CORE_BEFORE_USERMODE rather than ARCH_HAS_SYNC_CORE_BEFORE_USERMODE. - Move empty static inline in processor.h to generic patch. Changes since v2: - Introduce arch/x86/include/asm/sync_core.h - Don't sync_core when KPTI is enabled, and when invoked from irq and nmi context. - Note: v2 was reviewed by Thomas Gleixner, but changes were introduced since. --- arch/x86/Kconfig | 1 + arch/x86/include/asm/sync_core.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 arch/x86/include/asm/sync_core.h diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 20da391b5f32..0b44c8dd0e95 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -61,6 +61,7 @@ config X86 select ARCH_HAS_SG_CHAIN select ARCH_HAS_STRICT_KERNEL_RWX select ARCH_HAS_STRICT_MODULE_RWX + select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE select ARCH_HAS_UBSAN_SANITIZE_ALL select ARCH_HAS_ZONE_DEVICE if X86_64 select ARCH_HAVE_NMI_SAFE_CMPXCHG diff --git a/arch/x86/include/asm/sync_core.h b/arch/x86/include/asm/sync_core.h new file mode 100644 index 000000000000..c67caafd3381 --- /dev/null +++ b/arch/x86/include/asm/sync_core.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_SYNC_CORE_H +#define _ASM_X86_SYNC_CORE_H + +#include +#include +#include + +/* + * Ensure that a core serializing instruction is issued before returning + * to user-mode. x86 implements return to user-space through sysexit, + * sysrel, and sysretq, which are not core serializing. + */ +static inline void sync_core_before_usermode(void) +{ + /* With PTI, we unconditionally serialize before running user code. */ + if (static_cpu_has(X86_FEATURE_PTI)) + return; + /* + * Return from interrupt and NMI is done through iret, which is core + * serializing. + */ + if (in_irq() || in_nmi()) + return; + sync_core(); +} + +#endif /* _ASM_X86_SYNC_CORE_H */ -- 2.11.0