From: Dave.Martin@arm.com (Dave Martin)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: zImage: add DSB and ISB barriers after relocating code
Date: Mon, 2 Jun 2014 10:53:31 +0100 [thread overview]
Message-ID: <20140602095324.GA3855@e103592.cambridge.arm.com> (raw)
In-Reply-To: <537EB8F2.3090401@gmail.com>
On Thu, May 22, 2014 at 07:56:50PM -0700, Marc Carino wrote:
> Hi Nicolas,
>
> > Beware... This statement isn't true in most cases.
>
> Ah, yes - I do have to reword that bit. (Per the booting document, the
> I-cache can either be on or off upon entry, correct?)
>
> > Are you sure of that? When the MMU is off, memory access is strongly
> > ordered. I'm wondering if instruction prefetching applies in that
> > case.
>
> I'm unable to find a statement in the ARM architecture reference manual
> (ARM ARM) supporting the need for the DSB, so upon second glance I think
> I'll eliminate it.
I believe you won't find a statement in the ARM ARM supporting the view
that you _don't_ need a DSB either :)
I believe you need it. DSB is the only operation that can serialise
program order against the D-side for abitrary code.
Strongly-ordered memory on the D-side guarantees that D-side operations
cannot occur out of order with respect to this CPU, but there is still
no guarantee about how that relates to the I-side, even with ISB.
> Anyway, you are correct. While the MMU is off, data accesses are
> assigned the strongly-ordered memory type. However for instruction
> fetches, memory is assigned the Normal memory type (B3.2.1). Further,
> the architecture allows for prefetching of instructions within the
> current and subsequent 4K page from the currently-executing program
> counter (B3.2.3).
>
> Furthermore, I've encountered the "self-modifying code" example within
> the ARM ARM, which implies that a pipeline flush is needed after
> performing stores memory that is a part of the instruction stream.
>
> Another interesting tidbit is that there id no specification of
> coherency order between data and instructions for _any_ memory type
> (A3.9.3). It is expected that the programmer to insert an ISB to ensure
> instruction fetches are synced-up with the most-recent view of memory.
>
> > Also, is this a problem that you actually experienced in practice?
>
> Yes.
>
> > Are you sure those CP15 accesses are fine on all the CPU variants
> > that may execute this code? Officially we still support back to
> > ARMv4 implementations.
>
> No. I suppose I would have to leverage a lookup table scheme as is done
> with the cache maintenance operations in order for this patch to be
> portable?
How is what we're trying to achieve here different from the operation
that needs to be done in between decompressing the kernel and jumping
to it? Can't we just call cache_clean_flush?
Except that a possibly-redundant flush of the D-cache will be done,
this should do exactly the right thing.
This code is hairy to get right ... it would be better not to fragment
it unnecessarily.
Cheers
---Dave
next prev parent reply other threads:[~2014-06-02 9:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-23 1:27 [PATCH] ARM: zImage: add DSB and ISB barriers after relocating code Marc Carino
2014-05-23 2:11 ` Nicolas Pitre
2014-05-23 2:56 ` Marc Carino
2014-05-23 3:15 ` Nicolas Pitre
2014-05-27 17:15 ` Marc Carino
2014-06-02 9:53 ` Dave Martin [this message]
2014-07-18 17:32 ` Marc C
2014-07-18 18:08 ` Nicolas Pitre
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=20140602095324.GA3855@e103592.cambridge.arm.com \
--to=dave.martin@arm.com \
--cc=linux-arm-kernel@lists.infradead.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