From: marc.ceeeee@gmail.com (Marc Carino)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: zImage: add DSB and ISB barriers after relocating code
Date: Thu, 22 May 2014 18:27:52 -0700 [thread overview]
Message-ID: <1400808472-401-1-git-send-email-marc.ceeeee@gmail.com> (raw)
The zImage loader will relocate the image if it determines that
decompression will overwrite its current location. Since the act
of relocation is basically a form of code self-modification, we
need to ensure that the CPU fetches the updated instruction stream.
Since cache maintenance is skipped during the relocation phase (the
MMUs and caches are off), we need to execute both a data sync
and instruction sync barrier prior to jumping to the relocated code.
Skipping the barriers can result in execution of stale prefetched
code, leading to hangs or an UNDEFINED INSTRUCTION exception.
Signed-off-by: Marc Carino <marc.ceeeee@gmail.com>
---
arch/arm/boot/compressed/head.S | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index 066b034..df067ca 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -400,8 +400,16 @@ dtb_check_done:
add sp, sp, r6
#endif
+ /*
+ * Perform cache maintenance if caches were enabled earlier.
+ * Otherwise, execute data and instruction barriers prior to
+ * jumping to the newly-written code.
+ */
tst r4, #1
bleq cache_clean_flush
+ movne r0, #0
+ mcrne p15, 0, r0, c7, c10, 4 @ DSB
+ mcrne p15, 0, r0, c7, c5, 4 @ ISB
adr r0, BSYM(restart)
add r0, r0, r6
--
1.8.1.3
next reply other threads:[~2014-05-23 1:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-23 1:27 Marc Carino [this message]
2014-05-23 2:11 ` [PATCH] ARM: zImage: add DSB and ISB barriers after relocating code 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
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=1400808472-401-1-git-send-email-marc.ceeeee@gmail.com \
--to=marc.ceeeee@gmail.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