All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Andy Lutomirski <luto@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	linux-api <linux-api@vger.kernel.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Boqun Feng <boqun.feng@gmail.com>, Andrew Hunter <ahh@google.com>,
	maged michael <maged.michael@gmail.com>,
	Avi Kivity <avi@scylladb.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Dave Watson <davejwatson@fb.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Andrea Parri <parri.andrea@gmail.com>,
	"Russell King, ARM Linux" <linux@armlinux.org.uk>,
	Greg Hackmann <ghackmann@google.com>,
	Will Deacon <will.deacon@arm.com>,
	David
Subject: Re: [PATCH for 4.16 07/11] x86: Implement sync_core_before_usermode (v3)
Date: Wed, 17 Jan 2018 23:25:32 +0000 (UTC)	[thread overview]
Message-ID: <80094124.4887.1516231532603.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <CALCETrV2Cve1sW=UXHgjTWMKfsiwY5QdeaBnQRZGfpELLKry+A@mail.gmail.com>

----- On Jan 17, 2018, at 1:13 PM, Andy Lutomirski luto@kernel.org wrote:

> On Wed, Jan 17, 2018 at 10:10 AM, Mathieu Desnoyers
> <mathieu.desnoyers@efficios.com> wrote:
>> ----- On Jan 17, 2018, at 12:53 PM, Andy Lutomirski luto@kernel.org wrote:
>>
>>> On Wed, Jan 17, 2018 at 8:54 AM, Mathieu Desnoyers
>>> <mathieu.desnoyers@efficios.com> wrote:
>>>> 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 <mathieu.desnoyers@efficios.com>
>>>> Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
>>>> CC: Peter Zijlstra <peterz@infradead.org>
>>>> CC: Andy Lutomirski <luto@kernel.org>
>>>> CC: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
>>>> CC: Boqun Feng <boqun.feng@gmail.com>
>>>> CC: Andrew Hunter <ahh@google.com>
>>>> CC: Maged Michael <maged.michael@gmail.com>
>>>> CC: Avi Kivity <avi@scylladb.com>
>>>> CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
>>>> CC: Paul Mackerras <paulus@samba.org>
>>>> CC: Michael Ellerman <mpe@ellerman.id.au>
>>>> CC: Dave Watson <davejwatson@fb.com>
>>>> CC: Ingo Molnar <mingo@redhat.com>
>>>> CC: "H. Peter Anvin" <hpa@zytor.com>
>>>> CC: Andrea Parri <parri.andrea@gmail.com>
>>>> CC: Russell King <linux@armlinux.org.uk>
>>>> CC: Greg Hackmann <ghackmann@google.com>
>>>> CC: Will Deacon <will.deacon@arm.com>
>>>> CC: David Sehr <sehr@google.com>
>>>> CC: Linus Torvalds <torvalds@linux-foundation.org>
>>>> 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.
>>>> ---
>>>>  arch/x86/Kconfig                 |  1 +
>>>>  arch/x86/include/asm/processor.h | 10 ++++++++++
>>>>  2 files changed, 11 insertions(+)
>>>>
>>>> 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/processor.h b/arch/x86/include/asm/processor.h
>>>> index d3a67fba200a..3257d34dbb40 100644
>>>> --- a/arch/x86/include/asm/processor.h
>>>> +++ b/arch/x86/include/asm/processor.h
>>>> @@ -722,6 +722,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,
>>>> + * 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;
>>
>> One issue I'm facing with this change is header dependency:
>> sync_core_before_usermode() is currently implemented in
>> arch/x86/include/asm/processor.h, but arch/x86/include/asm/cpufeature.h
>> is needed for static_cpu_has, and it happens to include
>> asm/processor.h.
>>
>> I'm facing a similar issue for adding a (in_irq() || in_nmi()) check.
>>
>> Should we move sync_core_before_usermode() to a different header, and if
>> so, any suggestion ?
> 
> tlbflush.h, maybe?

Core serialization seems to be unrelated to TLB flushing though.

I'm considering to create those new header files:

include/asm-generic/sync_core.h (empty function)
arch/x86/include/asm/sync_core.h

for the sync_core_before_usermode() static inlines. Any better idea ?

Thanks,

Mathieu


> 
>>
>> Thanks,
>>
>> Mathieu
>>
>>
>>
>>>
>>>> +       sync_core();
>>>> +}
>>>
>>> --Andy
>>
>> --
>> Mathieu Desnoyers
>> EfficiOS Inc.
> > http://www.efficios.com

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

WARNING: multiple messages have this Message-ID (diff)
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Andy Lutomirski <luto@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	linux-api <linux-api@vger.kernel.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Boqun Feng <boqun.feng@gmail.com>, Andrew Hunter <ahh@google.com>,
	maged michael <maged.michael@gmail.com>,
	Avi Kivity <avi@scylladb.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Dave Watson <davejwatson@fb.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Andrea Parri <parri.andrea@gmail.com>,
	"Russell King, ARM Linux" <linux@armlinux.org.uk>,
	Greg Hackmann <ghackmann@google.com>,
	Will Deacon <will.deacon@arm.com>, David Sehr <sehr@google.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	x86 <x86@kernel.org>, linux-arch <linux-arch@vger.kernel.org>
Subject: Re: [PATCH for 4.16 07/11] x86: Implement sync_core_before_usermode (v3)
Date: Wed, 17 Jan 2018 23:25:32 +0000 (UTC)	[thread overview]
Message-ID: <80094124.4887.1516231532603.JavaMail.zimbra@efficios.com> (raw)
Message-ID: <20180117232532.1PAWszJYGBG1sEw1aBVBkHWmcIiqrpig_J5Ydalqrig@z> (raw)
In-Reply-To: <CALCETrV2Cve1sW=UXHgjTWMKfsiwY5QdeaBnQRZGfpELLKry+A@mail.gmail.com>

----- On Jan 17, 2018, at 1:13 PM, Andy Lutomirski luto@kernel.org wrote:

> On Wed, Jan 17, 2018 at 10:10 AM, Mathieu Desnoyers
> <mathieu.desnoyers@efficios.com> wrote:
>> ----- On Jan 17, 2018, at 12:53 PM, Andy Lutomirski luto@kernel.org wrote:
>>
>>> On Wed, Jan 17, 2018 at 8:54 AM, Mathieu Desnoyers
>>> <mathieu.desnoyers@efficios.com> wrote:
>>>> 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 <mathieu.desnoyers@efficios.com>
>>>> Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
>>>> CC: Peter Zijlstra <peterz@infradead.org>
>>>> CC: Andy Lutomirski <luto@kernel.org>
>>>> CC: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
>>>> CC: Boqun Feng <boqun.feng@gmail.com>
>>>> CC: Andrew Hunter <ahh@google.com>
>>>> CC: Maged Michael <maged.michael@gmail.com>
>>>> CC: Avi Kivity <avi@scylladb.com>
>>>> CC: Benjamin Herrenschmidt <benh@kernel.crashing.org>
>>>> CC: Paul Mackerras <paulus@samba.org>
>>>> CC: Michael Ellerman <mpe@ellerman.id.au>
>>>> CC: Dave Watson <davejwatson@fb.com>
>>>> CC: Ingo Molnar <mingo@redhat.com>
>>>> CC: "H. Peter Anvin" <hpa@zytor.com>
>>>> CC: Andrea Parri <parri.andrea@gmail.com>
>>>> CC: Russell King <linux@armlinux.org.uk>
>>>> CC: Greg Hackmann <ghackmann@google.com>
>>>> CC: Will Deacon <will.deacon@arm.com>
>>>> CC: David Sehr <sehr@google.com>
>>>> CC: Linus Torvalds <torvalds@linux-foundation.org>
>>>> 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.
>>>> ---
>>>>  arch/x86/Kconfig                 |  1 +
>>>>  arch/x86/include/asm/processor.h | 10 ++++++++++
>>>>  2 files changed, 11 insertions(+)
>>>>
>>>> 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/processor.h b/arch/x86/include/asm/processor.h
>>>> index d3a67fba200a..3257d34dbb40 100644
>>>> --- a/arch/x86/include/asm/processor.h
>>>> +++ b/arch/x86/include/asm/processor.h
>>>> @@ -722,6 +722,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,
>>>> + * 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;
>>
>> One issue I'm facing with this change is header dependency:
>> sync_core_before_usermode() is currently implemented in
>> arch/x86/include/asm/processor.h, but arch/x86/include/asm/cpufeature.h
>> is needed for static_cpu_has, and it happens to include
>> asm/processor.h.
>>
>> I'm facing a similar issue for adding a (in_irq() || in_nmi()) check.
>>
>> Should we move sync_core_before_usermode() to a different header, and if
>> so, any suggestion ?
> 
> tlbflush.h, maybe?

Core serialization seems to be unrelated to TLB flushing though.

I'm considering to create those new header files:

include/asm-generic/sync_core.h (empty function)
arch/x86/include/asm/sync_core.h

for the sync_core_before_usermode() static inlines. Any better idea ?

Thanks,

Mathieu


> 
>>
>> Thanks,
>>
>> Mathieu
>>
>>
>>
>>>
>>>> +       sync_core();
>>>> +}
>>>
>>> --Andy
>>
>> --
>> Mathieu Desnoyers
>> EfficiOS Inc.
> > http://www.efficios.com

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

  reply	other threads:[~2018-01-17 23:25 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-17 16:54 [PATCH for 4.16 00/11] membarrier updates for 4.16 Mathieu Desnoyers
2018-01-17 16:54 ` Mathieu Desnoyers
     [not found] ` <20180117165458.13330-1-mathieu.desnoyers-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2018-01-17 16:54   ` [PATCH for 4.16 01/11] membarrier: selftest: Test private expedited cmd (v2) Mathieu Desnoyers
2018-01-17 16:54     ` [Linux-kselftest-mirror] " Mathieu Desnoyers
2018-01-17 16:54     ` mathieu.desnoyers
2018-01-17 16:54     ` Mathieu Desnoyers
2018-01-17 16:54   ` [PATCH for 4.16 06/11] Introduce sync_core_before_usermode Mathieu Desnoyers
2018-01-17 16:54     ` Mathieu Desnoyers
2018-01-17 16:54 ` [PATCH for 4.16 02/11] powerpc: membarrier: Skip memory barrier in switch_mm() (v7) Mathieu Desnoyers
2018-01-17 16:54   ` Mathieu Desnoyers
2018-01-17 16:54 ` [PATCH for 4.16 03/11] membarrier: Document scheduler barrier requirements (v5) Mathieu Desnoyers
2018-01-17 16:54   ` Mathieu Desnoyers
2018-01-17 16:54 ` [PATCH for 4.16 04/11] membarrier: provide GLOBAL_EXPEDITED command (v3) Mathieu Desnoyers
2018-01-17 16:54   ` Mathieu Desnoyers
2018-01-17 16:54 ` [PATCH for 4.16 05/11] membarrier: selftest: Test global expedited cmd (v2) Mathieu Desnoyers
2018-01-17 16:54   ` [Linux-kselftest-mirror] " Mathieu Desnoyers
2018-01-17 16:54   ` mathieu.desnoyers
2018-01-17 16:54   ` Mathieu Desnoyers
2018-01-17 16:54 ` [PATCH for 4.16 07/11] x86: Implement sync_core_before_usermode (v3) Mathieu Desnoyers
2018-01-17 16:54   ` Mathieu Desnoyers
2018-01-17 17:53   ` Andy Lutomirski
2018-01-17 17:53     ` Andy Lutomirski
2018-01-17 18:10     ` Mathieu Desnoyers
2018-01-17 18:10       ` Mathieu Desnoyers
     [not found]       ` <712464074.4666.1516212636860.JavaMail.zimbra-vg+e7yoeK/dWk0Htik3J/w@public.gmane.org>
2018-01-17 18:13         ` Andy Lutomirski
2018-01-17 18:13           ` Andy Lutomirski
2018-01-17 23:25           ` Mathieu Desnoyers [this message]
2018-01-17 23:25             ` Mathieu Desnoyers
2018-01-17 23:37             ` Andy Lutomirski
2018-01-17 23:37               ` Andy Lutomirski
2018-01-17 16:54 ` [PATCH for 4.16 08/11] membarrier: Provide core serializing command Mathieu Desnoyers
2018-01-17 16:54   ` Mathieu Desnoyers
2018-01-17 16:54 ` [PATCH for 4.16 09/11] membarrier: x86: Provide core serializing command (v4) Mathieu Desnoyers
2018-01-17 16:54   ` Mathieu Desnoyers
2018-01-17 16:54 ` [PATCH for 4.16 10/11] membarrier: arm64: Provide core serializing command Mathieu Desnoyers
2018-01-17 16:54   ` Mathieu Desnoyers
2018-01-17 16:54 ` [PATCH for 4.16 11/11] membarrier: selftest: Test private expedited sync core cmd Mathieu Desnoyers
2018-01-17 16:54   ` [Linux-kselftest-mirror] " Mathieu Desnoyers
2018-01-17 16:54   ` mathieu.desnoyers
2018-01-17 16:54   ` Mathieu Desnoyers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=80094124.4887.1516231532603.JavaMail.zimbra@efficios.com \
    --to=mathieu.desnoyers@efficios.com \
    --cc=ahh@google.com \
    --cc=avi@scylladb.com \
    --cc=benh@kernel.crashing.org \
    --cc=boqun.feng@gmail.com \
    --cc=davejwatson@fb.com \
    --cc=ghackmann@google.com \
    --cc=hpa@zytor.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=luto@kernel.org \
    --cc=maged.michael@gmail.com \
    --cc=mingo@redhat.com \
    --cc=mpe@ellerman.id.au \
    --cc=parri.andrea@gmail.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.