linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Hector Martin <marcan@marcan.st>
To: Will Deacon <will@kernel.org>
Cc: Linux ARM <linux-arm-kernel@lists.infradead.org>,
	Marc Zyngier <maz@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Boqun Feng <boqun.feng@gmail.com>,
	Catalin Marinas <catalin.marinas@arm.com>
Subject: Re: LSE atomic op ordering is weaker than intended?
Date: Thu, 4 Mar 2021 04:37:31 +0900	[thread overview]
Message-ID: <0d194019-deb9-8d9b-823c-4226f2d2dce2@marcan.st> (raw)
In-Reply-To: <20210303184055.GA19891@willie-the-truck>

On 04/03/2021 03.40, Will Deacon wrote:
>> // ...stuff that needs to be ordered prior to the atomic here
>> ret = atomic_fetch_or_release(flags...)
>> if (condition on ret and unrelated stuff) {
>> 	writel(reg_send, ...) // includes pre-barrier
> 
> Looks you have a control dependency here, so I think that can be
> writel_relaxed() [with a comment!].

Wouldn't the control dependency be strictly on the *read* portion of the 
atomic, while I'm looking to order on the write part?

Though, actually, I omitted something; the unrelated stuff includes an 
atomic_read_acquire that will create order against the write-release 
portion of the atomic (not per the Linux cross-platform docs, but yes 
per ARMv8 B2.3.3) and *that* should be a suitable control dependency if 
I'm not mistaken.

>> writel_relaxed(reg_ack, ...)
> 
> Interesting, is there no MMIO read on the IRQ path?

There's a prior read, but that doesn't help here; the important part is 
that this writel (ACKing the hardware IPI) cannot move after the atomic 
op after it (figuring out which software IPIs it represents), because if 
it does we might ACK a subsequent IPI we're not about to handle.

>> dma_wmb() // need a post-barrier
>> atomic_fetch_andnot_acquire(flags...)
>> // ...stuff that needs to be ordered after the atomic here
> 
> This looks pretty dodgy to me as a later read could drift up before teh
> writel_relaxed().

That's fine, as long as those reads are ordered after the atomic fetch 
portion itself (which they should be since it's an _acquire).

AIUI the worst case ordering this can result in is:

- read portion of atomic
- the entire rest of the code (if it does no writes)
- writel_relaxed()
- write portion of atomic

That's fine: the result of the atomic read gives us license to run the 
rest of the code; the writel doesn't need to have happened. The 
important part is that the write portion of the atomic can't happen 
before the writel.

> If this is all to do with IPIs between CPUs and the "stuff that needs to be
> ordered <before/after> the atomic" is all normal, cacheable memory then I
> dont't think you need to worry about the outer-shareable domain at all. The
> only reason we have that in dma_*mb() is because the coherent DMA buffers
> might be non-cacheable to deal with non-coherent DMA.

What worried me is whether the order created by atomics on normal memory 
might not extend to MMIO ops on device memory, which are treated as 
outer-shareable (per D5.5.1).

I don't fully understand how the entire B2.3 section on ordering 
interacts across memory regions having different attributes. That 
section talks about a Common Shareability Domain, and also explicitly 
mentions only Normal memory locations, so I'm having a lot of trouble 
piecing together how MMIO ops are treated within the entire memory 
ordering framework (and all the litmus test stuff seems to assume 
everythign is IS...).

All the actual memory involved in everything but the writel() stuff is 
all normal cacheable memory; what I need to ensure is that I can 
transitively create memory ordering constraints between normal memory 
accesses through MMIO writes.

That is, that I can create two ordered sequences on two PEs:

(normal access 1; mmio write 1)
(mmio write 2; normal access 2)

Such that I can assert that at least one of the following orderings are 
true:

(normal access 1; normal access 2)
(as observed by the PEs)

or:

(mmio write 2; mmio write 1)
(as observed by the MMIO device)

But never this combination:

(normal access 2; normal access 1)
(mmio write 1; mmio write 2)

> But hack something together, and I'll look at your v3 to see what's going
> on.

Please do, hopefully the full code makes more sense.

-- 
Hector Martin (marcan@marcan.st)
Public Key: https://mrcn.st/pub

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-03-04  0:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-03 13:05 LSE atomic op ordering is weaker than intended? Hector Martin
2021-03-03 15:36 ` Will Deacon
2021-03-03 18:04   ` Hector Martin
2021-03-03 18:40     ` Will Deacon
2021-03-03 19:37       ` Hector Martin [this message]
2021-03-03 21:38         ` Will Deacon
2021-03-04  8:16           ` Hector Martin

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=0d194019-deb9-8d9b-823c-4226f2d2dce2@marcan.st \
    --to=marcan@marcan.st \
    --cc=boqun.feng@gmail.com \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=peterz@infradead.org \
    --cc=will@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).