All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Andy Lutomirski <luto@kernel.org>, paulmck <paulmck@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Cc: "Russell King, ARM Linux" <linux@armlinux.org.uk>,
	x86 <x86@kernel.org>, linux-kernel <linux-kernel@vger.kernel.org>,
	Nicholas Piggin <npiggin@gmail.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	stable <stable@vger.kernel.org>
Subject: Re: [RFC please help] membarrier: Rewrite sync_core_before_usermode()
Date: Mon, 28 Dec 2020 16:09:39 -0500 (EST)	[thread overview]
Message-ID: <1670059472.3671.1609189779376.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <CALCETrVdcn2r2Jvd1=-bM=FQ8KbX4aH-v4ytdojL7r7Nb6k8YQ@mail.gmail.com>

----- On Dec 27, 2020, at 4:36 PM, Andy Lutomirski luto@kernel.org wrote:

[...]

>> You seem to have noticed odd cases on arm64 where this guarantee does not
>> match reality. Where exactly can we find this in the code, and which part
>> of the architecture manual can you point us to which supports your concern ?
>>
>> Based on the notes I have, use of `eret` on aarch64 guarantees a context
>> synchronizing
>> instruction when returning to user-space.
> 
> Based on my reading of the manual, ERET on ARM doesn't synchronize
> anything at all.  I can't find any evidence that it synchronizes data
> or instructions, and I've seen reports that the CPU will happily
> speculate right past it.

Reading [1] there appears to be 3 kind of context synchronization events:

- Taking an exception,
- Returning from an exception,
- ISB.

This other source [2] adds (search for Context synchronization operation):

- Exit from Debug state
- Executing a DCPS instruction
- Executing a DRPS instruction

"ERET" falls into the second kind of events, and AFAIU should be context
synchronizing. That was confirmed to me by Will Deacon when membarrier
sync-core was implemented for aarch64. If the architecture reference manuals
are wrong, is there an errata ?

As for the algorithm to use on ARMv8 to update instructions, see [2]
B2.3.4  Implication of caches for the application programmer
"Synchronization and coherency issues between data and instruction accesses"

Membarrier only takes care of making sure the "ISB" part of the algorithm can be
done easily and efficiently on multiprocessor systems.

Thanks,

Mathieu

[1] https://developer.arm.com/documentation/den0024/a/Memory-Ordering/Barriers/ISB-in-more-detail
[2] https://montcs.bloomu.edu/Information/ARMv8/ARMv8-A_Architecture_Reference_Manual_(Issue_A.a).pdf

-- 
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>, paulmck <paulmck@kernel.org>,
	 Peter Zijlstra <peterz@infradead.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
	Arnd Bergmann <arnd@arndb.de>, x86 <x86@kernel.org>,
	"Russell King, ARM Linux" <linux@armlinux.org.uk>,
	Nicholas Piggin <npiggin@gmail.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Will Deacon <will@kernel.org>, Paul Mackerras <paulus@samba.org>,
	stable <stable@vger.kernel.org>,
	linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>
Subject: Re: [RFC please help] membarrier: Rewrite sync_core_before_usermode()
Date: Mon, 28 Dec 2020 16:09:39 -0500 (EST)	[thread overview]
Message-ID: <1670059472.3671.1609189779376.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <CALCETrVdcn2r2Jvd1=-bM=FQ8KbX4aH-v4ytdojL7r7Nb6k8YQ@mail.gmail.com>

----- On Dec 27, 2020, at 4:36 PM, Andy Lutomirski luto@kernel.org wrote:

[...]

>> You seem to have noticed odd cases on arm64 where this guarantee does not
>> match reality. Where exactly can we find this in the code, and which part
>> of the architecture manual can you point us to which supports your concern ?
>>
>> Based on the notes I have, use of `eret` on aarch64 guarantees a context
>> synchronizing
>> instruction when returning to user-space.
> 
> Based on my reading of the manual, ERET on ARM doesn't synchronize
> anything at all.  I can't find any evidence that it synchronizes data
> or instructions, and I've seen reports that the CPU will happily
> speculate right past it.

Reading [1] there appears to be 3 kind of context synchronization events:

- Taking an exception,
- Returning from an exception,
- ISB.

This other source [2] adds (search for Context synchronization operation):

- Exit from Debug state
- Executing a DCPS instruction
- Executing a DRPS instruction

"ERET" falls into the second kind of events, and AFAIU should be context
synchronizing. That was confirmed to me by Will Deacon when membarrier
sync-core was implemented for aarch64. If the architecture reference manuals
are wrong, is there an errata ?

As for the algorithm to use on ARMv8 to update instructions, see [2]
B2.3.4  Implication of caches for the application programmer
"Synchronization and coherency issues between data and instruction accesses"

Membarrier only takes care of making sure the "ISB" part of the algorithm can be
done easily and efficiently on multiprocessor systems.

Thanks,

Mathieu

[1] https://developer.arm.com/documentation/den0024/a/Memory-Ordering/Barriers/ISB-in-more-detail
[2] https://montcs.bloomu.edu/Information/ARMv8/ARMv8-A_Architecture_Reference_Manual_(Issue_A.a).pdf

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

  parent reply	other threads:[~2020-12-28 23:03 UTC|newest]

Thread overview: 97+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-27 18:28 [RFC please help] membarrier: Rewrite sync_core_before_usermode() Andy Lutomirski
2020-12-27 18:28 ` Andy Lutomirski
2020-12-27 18:28 ` Andy Lutomirski
2020-12-27 20:18 ` Mathieu Desnoyers
2020-12-27 20:18   ` Mathieu Desnoyers
2020-12-27 21:36   ` Andy Lutomirski
2020-12-27 21:36     ` Andy Lutomirski
2020-12-27 21:36     ` Andy Lutomirski
2020-12-28 10:25     ` Russell King - ARM Linux admin
2020-12-28 10:25       ` Russell King - ARM Linux admin
2020-12-28 10:25       ` Russell King - ARM Linux admin
2020-12-28 17:14       ` Andy Lutomirski
2020-12-28 17:14         ` Andy Lutomirski
2020-12-28 17:14         ` Andy Lutomirski
2020-12-28 17:23         ` Russell King - ARM Linux admin
2020-12-28 17:23           ` Russell King - ARM Linux admin
2020-12-28 17:23           ` Russell King - ARM Linux admin
2020-12-28 18:10           ` Andy Lutomirski
2020-12-28 18:10             ` Andy Lutomirski
2020-12-28 18:10             ` Andy Lutomirski
2020-12-28 18:29         ` Jann Horn
2020-12-28 18:29           ` Jann Horn
2020-12-28 18:29           ` Jann Horn
2020-12-28 18:50           ` Andy Lutomirski
2020-12-28 18:50             ` Andy Lutomirski
2020-12-28 18:50             ` Andy Lutomirski
2020-12-28 19:08           ` Russell King - ARM Linux admin
2020-12-28 19:08             ` Russell King - ARM Linux admin
2020-12-28 19:08             ` Russell King - ARM Linux admin
2020-12-28 19:44             ` Andy Lutomirski
2020-12-28 19:44               ` Andy Lutomirski
2020-12-28 19:44               ` Andy Lutomirski
2020-12-28 20:24               ` Russell King - ARM Linux admin
2020-12-28 20:24                 ` Russell King - ARM Linux admin
2020-12-28 20:24                 ` Russell King - ARM Linux admin
2020-12-28 20:40                 ` Mathieu Desnoyers
2020-12-28 20:40                   ` Mathieu Desnoyers
2020-12-28 20:32               ` Mathieu Desnoyers
2020-12-28 20:32                 ` Mathieu Desnoyers
2020-12-28 21:06                 ` Andy Lutomirski
2020-12-28 21:06                   ` Andy Lutomirski
2020-12-28 21:06                   ` Andy Lutomirski
2020-12-28 21:26                   ` Mathieu Desnoyers
2020-12-28 21:26                     ` Mathieu Desnoyers
2020-12-29  0:36                   ` Nicholas Piggin
2020-12-29  0:36                     ` Nicholas Piggin
2020-12-29  0:36                     ` Nicholas Piggin
2020-12-29  0:56                     ` Andy Lutomirski
2020-12-29  0:56                       ` Andy Lutomirski
2020-12-29  0:56                       ` Andy Lutomirski
2020-12-29  3:09                       ` Nicholas Piggin
2020-12-29  3:09                         ` Nicholas Piggin
2020-12-29  3:09                         ` Nicholas Piggin
2020-12-29 10:44                         ` Russell King - ARM Linux admin
2020-12-29 10:44                           ` Russell King - ARM Linux admin
2020-12-29 10:44                           ` Russell King - ARM Linux admin
2020-12-30  2:33                           ` Nicholas Piggin
2020-12-30  2:33                             ` Nicholas Piggin
2020-12-30  2:33                             ` Nicholas Piggin
2020-12-30 10:00                             ` Russell King - ARM Linux admin
2020-12-30 10:00                               ` Russell King - ARM Linux admin
2020-12-30 10:00                               ` Russell King - ARM Linux admin
2020-12-30 10:58                               ` Russell King - ARM Linux admin
2020-12-30 10:58                                 ` Russell King - ARM Linux admin
2020-12-30 10:58                                 ` Russell King - ARM Linux admin
2020-12-30 11:57                                 ` Nicholas Piggin
2020-12-30 11:57                                   ` Nicholas Piggin
2020-12-30 11:57                                   ` Nicholas Piggin
2020-12-28 21:09     ` Mathieu Desnoyers [this message]
2020-12-28 21:09       ` Mathieu Desnoyers
2020-12-29  0:30       ` Andy Lutomirski
2020-12-29  0:30         ` Andy Lutomirski
2020-12-29  0:30         ` Andy Lutomirski
2020-12-29  0:11 ` Nicholas Piggin
2020-12-29  0:11   ` Nicholas Piggin
2020-12-29  0:11   ` Nicholas Piggin
2020-12-29  0:36   ` Andy Lutomirski
2020-12-29  0:36     ` Andy Lutomirski
2020-12-29  0:36     ` Andy Lutomirski
2020-12-29  3:31     ` Nicholas Piggin
2020-12-29  3:31       ` Nicholas Piggin
2020-12-29  3:31       ` Nicholas Piggin
2021-01-01 18:33     ` David Laight
2021-01-01 18:33       ` David Laight
2021-01-01 18:33       ` David Laight
2021-01-05 13:26     ` Will Deacon
2021-01-05 13:26       ` Will Deacon
2021-01-05 13:26       ` Will Deacon
2021-01-05 16:20       ` Andy Lutomirski
2021-01-05 16:20         ` Andy Lutomirski
2021-01-05 16:20         ` Andy Lutomirski
2021-01-05 16:37         ` Peter Zijlstra
2021-01-05 16:37           ` Peter Zijlstra
2021-01-05 16:37           ` Peter Zijlstra
2021-01-05 22:41         ` Will Deacon
2021-01-05 22:41           ` Will Deacon
2021-01-05 22:41           ` Will Deacon

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=1670059472.3671.1609189779376.JavaMail.zimbra@efficios.com \
    --to=mathieu.desnoyers@efficios.com \
    --cc=arnd@arndb.de \
    --cc=benh@kernel.crashing.org \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=luto@kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    /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.