Re: [RFC PATCH for 4.15 05/10] x86: Introduce sync_core_before_usermode

From: Mathieu Desnoyers
Date: Fri Nov 10 2017 - 17:39:15 EST


----- On Nov 10, 2017, at 5:36 PM, Andy Lutomirski luto@xxxxxxxxxxxxxx wrote:

>> On Nov 10, 2017, at 2:20 PM, Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
>> wrote:
>>
>> ----- On Nov 10, 2017, at 5:02 PM, Andy Lutomirski luto@xxxxxxxxxx wrote:
>>
>>> On Fri, Nov 10, 2017 at 1:37 PM, Mathieu Desnoyers
>>> <mathieu.desnoyers@xxxxxxxxxxxx> 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.desnoyers@xxxxxxxxxxxx>
>>>> CC: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
>>>> CC: Andy Lutomirski <luto@xxxxxxxxxx>
>>>> CC: Paul E. McKenney <paulmck@xxxxxxxxxxxxxxxxxx>
>>>> CC: Boqun Feng <boqun.feng@xxxxxxxxx>
>>>> CC: Andrew Hunter <ahh@xxxxxxxxxx>
>>>> CC: Maged Michael <maged.michael@xxxxxxxxx>
>>>> CC: Avi Kivity <avi@xxxxxxxxxxxx>
>>>> CC: Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx>
>>>> CC: Paul Mackerras <paulus@xxxxxxxxx>
>>>> CC: Michael Ellerman <mpe@xxxxxxxxxxxxxx>
>>>> CC: Dave Watson <davejwatson@xxxxxx>
>>>> CC: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
>>>> CC: Ingo Molnar <mingo@xxxxxxxxxx>
>>>> CC: "H. Peter Anvin" <hpa@xxxxxxxxx>
>>>> CC: Andrea Parri <parri.andrea@xxxxxxxxx>
>>>> CC: Russell King <linux@xxxxxxxxxxxxxxx>
>>>> CC: Greg Hackmann <ghackmann@xxxxxxxxxx>
>>>> CC: Will Deacon <will.deacon@xxxxxxx>
>>>> CC: David Sehr <sehr@xxxxxxxxxx>
>>>> CC: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
>>>> CC: x86@xxxxxxxxxx
>>>> CC: linux-arch@xxxxxxxxxxxxxxx
>>>> ---
>>>> 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.
>>
>> Sure, done. It will be part of the next version of that patch.
>>
>> Thanks!
>
> Hmm. Can you also cc stable and make sure it applies by itself?

Do you mean merging both this patch and the fix into a single patch ?

>
>>
>> Mathieu
>>
>>
>> --
>> Mathieu Desnoyers
>> EfficiOS Inc.
>> http://www.efficios.com
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-api" in
>> the body of a message to majordomo@xxxxxxxxxxxxxxx
> > More majordomo info at http://vger.kernel.org/majordomo-info.html

--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com