Received: by 10.223.176.5 with SMTP id f5csp2989985wra; Mon, 5 Feb 2018 13:41:59 -0800 (PST) X-Google-Smtp-Source: AH8x226ntbT2I5uWGhFmuyIQcYYw/p8FhS3sCaYiF3x39RGq3x9PvS0kwEgD6Kff+85oKcVmURIE X-Received: by 2002:a17:902:48c8:: with SMTP id u8-v6mr200098plh.272.1517866919190; Mon, 05 Feb 2018 13:41:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517866919; cv=none; d=google.com; s=arc-20160816; b=BH71C+ndsP4v12rk4sB4WaNBgtA76yiN5tD6L7oAlUJFk85lkqGe02IWX9iPaDhpOs 8uZ23+kL5ZUJvIIcigym7+Z3biDiTAoiRXVDkAtB5gCnsxbA3BBKbZAZiyvwaErRDpJv i9DovTZWd/c9wtvpn7HfWl/FKU9WoOGSZQGylgQg7W7jrkZk1LYHmtLmMihPxpOpYpPK xPatDaXUMd0afvvtY7UKuVmSQSdG5Rj9SMjxH8tCrijSTP1oZS3T2xTU8LhKMjuEe9Gy 0U5HacQ8DsQ/6DnIzJ27pikjbWjhwqSlkTjmCTsfn0bCz4pl6fYBDoQxzwwx9ZTjvAtt zRjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=Zrkx8BX3da3Yt0/YU6V6f3LIDdMXj2JS9+u0pf34qQg=; b=g7ZoeHgWaWcirAoMx+LUszr5etJcBWdgd0sYvb4n+q8kYnqlYpLu3fO02m0vR0GBvb TtRP84eijve0HTYpow4tVv5xeTZxcgBqAfV+KUDIHv9EF69bOnahltBfqs9hBXa8NBz3 7Mw0Z0fV/AeoyApvGMoL3fFmTMw67RR0pj2DLkvBNA50ASwAlDzdApkIDSzBt2bXGhyi uUHLQ0caj5neJ7ZhbxvNLwVh7+J1hYZUl2jr3sUBYCGV7fya4cz0J4sx79QpXopCvMZg 9vv15k5AXcOwP5F1KQKyVGvrO2IyBp5ypgPIGWrzJtOAqykWrjY7twG5Kq5OiORTUJ/s 82Og== 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 98-v6si4887795pla.756.2018.02.05.13.41.45; Mon, 05 Feb 2018 13:41:59 -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 S1752543AbeBEVkl (ORCPT + 99 others); Mon, 5 Feb 2018 16:40:41 -0500 Received: from terminus.zytor.com ([65.50.211.136]:45547 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752489AbeBEVk3 (ORCPT ); Mon, 5 Feb 2018 16:40:29 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w15LSfxF028839; Mon, 5 Feb 2018 13:28:41 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w15LSfJF028833; Mon, 5 Feb 2018 13:28:41 -0800 Date: Mon, 5 Feb 2018 13:28:41 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Mathieu Desnoyers Message-ID: Cc: paulmck@linux.vnet.ibm.com, hpa@zytor.com, tglx@linutronix.de, linux@armlinux.org.uk, paulus@samba.org, parri.andrea@gmail.com, torvalds@linux-foundation.org, peterz@infradead.org, linux-kernel@vger.kernel.org, sehr@google.com, ahh@google.com, luto@kernel.org, avi@scylladb.com, mathieu.desnoyers@efficios.com, mingo@kernel.org, mpe@ellerman.id.au, will.deacon@arm.com, davejwatson@fb.com, benh@kernel.crashing.org, arnd@arndb.de, ghackmann@google.com, maged.michael@gmail.com, boqun.feng@gmail.com Reply-To: hpa@zytor.com, paulmck@linux.vnet.ibm.com, tglx@linutronix.de, sehr@google.com, linux-kernel@vger.kernel.org, peterz@infradead.org, torvalds@linux-foundation.org, parri.andrea@gmail.com, paulus@samba.org, linux@armlinux.org.uk, ahh@google.com, avi@scylladb.com, luto@kernel.org, mathieu.desnoyers@efficios.com, arnd@arndb.de, benh@kernel.crashing.org, will.deacon@arm.com, davejwatson@fb.com, mpe@ellerman.id.au, mingo@kernel.org, boqun.feng@gmail.com, maged.michael@gmail.com, ghackmann@google.com In-Reply-To: <20180129202020.8515-8-mathieu.desnoyers@efficios.com> References: <20180129202020.8515-8-mathieu.desnoyers@efficios.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:sched/urgent] lockin/x86: Implement sync_core_before_usermode() Git-Commit-ID: ac1ab12a3e6e878274e7107c8c6f326694a1c1f3 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: ac1ab12a3e6e878274e7107c8c6f326694a1c1f3 Gitweb: https://git.kernel.org/tip/ac1ab12a3e6e878274e7107c8c6f326694a1c1f3 Author: Mathieu Desnoyers AuthorDate: Mon, 29 Jan 2018 15:20:16 -0500 Committer: Ingo Molnar CommitDate: Mon, 5 Feb 2018 21:34:57 +0100 lockin/x86: Implement sync_core_before_usermode() 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: Thomas Gleixner Acked-by: Peter Zijlstra (Intel) Cc: Andrea Parri Cc: Andrew Hunter Cc: Andy Lutomirski Cc: Arnd Bergmann Cc: Avi Kivity Cc: Benjamin Herrenschmidt Cc: Boqun Feng Cc: Dave Watson Cc: David Sehr Cc: Greg Hackmann Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Maged Michael Cc: Michael Ellerman Cc: Paul E. McKenney Cc: Paul Mackerras Cc: Russell King Cc: Will Deacon Cc: linux-api@vger.kernel.org Cc: linux-arch@vger.kernel.org Link: http://lkml.kernel.org/r/20180129202020.8515-8-mathieu.desnoyers@efficios.com Signed-off-by: Ingo Molnar --- arch/x86/Kconfig | 1 + arch/x86/include/asm/sync_core.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 423e4b6..31030ad 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 0000000..c67caaf --- /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 */