On Fri, Nov 10, 2017 at 1:37 PM, Mathieu Desnoyers
<mathieu.desnoy...@efficios.com> wrote:
> Introduce an architecture function that ensures the current CPU
> issues a core serializing instruction before returning to usermode.
>
> This is needed to fix an existing core serialization bug on
> thread migration, and also needed by the membarrier "sync_core" command.
>
> Architectures defining the sync_core_before_usermode() static inline
> need to define ARCH_HAS_SYNC_CORE_BEFORE_USERMODE.
>
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoy...@efficios.com>
> CC: Peter Zijlstra <pet...@infradead.org>
> CC: Andy Lutomirski <l...@kernel.org>
> CC: Paul E. McKenney <paul...@linux.vnet.ibm.com>
> CC: Boqun Feng <boqun.f...@gmail.com>
> CC: Andrew Hunter <a...@google.com>
> CC: Maged Michael <maged.mich...@gmail.com>
> CC: Avi Kivity <a...@scylladb.com>
> CC: Benjamin Herrenschmidt <b...@kernel.crashing.org>
> CC: Paul Mackerras <pau...@samba.org>
> CC: Michael Ellerman <m...@ellerman.id.au>
> CC: Dave Watson <davejwat...@fb.com>
> CC: Thomas Gleixner <t...@linutronix.de>
> CC: Ingo Molnar <mi...@redhat.com>
> CC: "H. Peter Anvin" <h...@zytor.com>
> CC: Andrea Parri <parri.and...@gmail.com>
> CC: Russell King <li...@armlinux.org.uk>
> CC: Greg Hackmann <ghackm...@google.com>
> CC: Will Deacon <will.dea...@arm.com>
> CC: David Sehr <s...@google.com>
> CC: Linus Torvalds <torva...@linux-foundation.org>
> CC: x...@kernel.org
> CC: linux-a...@vger.kernel.org
> ---
>  arch/x86/Kconfig                 |  1 +
>  arch/x86/include/asm/processor.h | 10 ++++++++++
>  include/linux/processor.h        |  6 ++++++
>  3 files changed, 17 insertions(+)
>
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index 01f78c1d40b5..54fbb8960d94 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -62,6 +62,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/processor.h 
> b/arch/x86/include/asm/processor.h
> index bdac19ab2488..6ce996a7c730 100644
> --- a/arch/x86/include/asm/processor.h
> +++ b/arch/x86/include/asm/processor.h
> @@ -706,6 +706,16 @@ static inline void sync_core(void)
>  #endif
>  }
>
> +/*
> + * Ensure that a core serializing instruction is issued before returning
> + * to user-mode. x86 implements return to user-space through sysexit and
> + * sysretq, which are not core serializing.
> + */
> +static inline void sync_core_before_usermode(void)
> +{
> +       sync_core();
> +}

Make this if (!in_interrupt()) sync_core(); please.  We can optimize
it better later on.

Reply via email to