From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: pcpu: ensure __my_cpu_offset cannot be re-ordered across barrier()
Date: Tue, 4 Jun 2013 18:15:06 +0100 [thread overview]
Message-ID: <20130604171506.GZ27516@mudshark.cambridge.arm.com> (raw)
In-Reply-To: <20130604103953.GL27516@mudshark.cambridge.arm.com>
On Tue, Jun 04, 2013 at 11:39:53AM +0100, Will Deacon wrote:
> However, if you instead add a dependency on something that already lives in a
> register, like __builtin_return_address, you get:
>
> c001cd44: e92d4010 push {r4, lr}
> c001cd48: ee1dcf90 mrc 15, 0, ip, cr13, cr0, {4}
> c001cd4c: e790410c ldr r4, [r0, ip, lsl #2]
> c001cd50: ee1dcf90 mrc 15, 0, ip, cr13, cr0, {4}
> c001cd54: e791110c ldr r1, [r1, ip, lsl #2]
> c001cd58: e792210c ldr r2, [r2, ip, lsl #2]
> c001cd5c: ee1d3f90 mrc 15, 0, r3, cr13, cr0, {4}
> c001cd60: e7903103 ldr r3, [r0, r3, lsl #2]
> c001cd64: e0840001 add r0, r4, r1
> c001cd68: e0800002 add r0, r0, r2
> c001cd6c: e0800003 add r0, r0, r3
> c001cd70: e8bd8010 pop {r4, pc}
Actually, I've managed to improve this further using sp instead (see diff
below), which also prevents GCC from moving the lr into other registers for
no reason. The code generated for your test is:
c001cda4: ee1d3f90 mrc 15, 0, r3, cr13, cr0, {4}
c001cda8: e790c103 ldr ip, [r0, r3, lsl #2]
c001cdac: ee1d3f90 mrc 15, 0, r3, cr13, cr0, {4}
c001cdb0: e7911103 ldr r1, [r1, r3, lsl #2]
c001cdb4: e7922103 ldr r2, [r2, r3, lsl #2]
c001cdb8: ee1d3f90 mrc 15, 0, r3, cr13, cr0, {4}
c001cdbc: e7903103 ldr r3, [r0, r3, lsl #2]
c001cdc0: e08c0001 add r0, ip, r1
c001cdc4: e0800002 add r0, r0, r2
c001cdc8: e0800003 add r0, r0, r3
c001cdcc: e12fff1e bx lr
I spoke to the tools guys and they'll look into why the original patch
didn't work, since that could have wider implications on our use of
barrier().
Will
--->8
diff --git a/arch/arm/include/asm/percpu.h b/arch/arm/include/asm/percpu.h
index 968c0a1..209e650 100644
--- a/arch/arm/include/asm/percpu.h
+++ b/arch/arm/include/asm/percpu.h
@@ -30,8 +30,15 @@ static inline void set_my_cpu_offset(unsigned long off)
static inline unsigned long __my_cpu_offset(void)
{
unsigned long off;
- /* Read TPIDRPRW */
- asm("mrc p15, 0, %0, c13, c0, 4" : "=r" (off) : : "memory");
+ register unsigned long *sp asm ("sp");
+
+ /*
+ * Read TPIDRPRW.
+ * We want to allow caching the value, so avoid using volatile and
+ * instead use a fake stack read to hazard against barrier().
+ */
+ asm("mrc p15, 0, %0, c13, c0, 4" : "=r" (off) : "Q" (*sp));
+
return off;
}
#define __my_cpu_offset __my_cpu_offset()
next prev parent reply other threads:[~2013-06-04 17:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-03 16:53 [PATCH] ARM: pcpu: ensure __my_cpu_offset cannot be re-ordered across barrier() Will Deacon
2013-06-03 19:33 ` Nicolas Pitre
2013-06-04 10:39 ` Will Deacon
2013-06-04 17:15 ` Will Deacon [this message]
2013-06-04 17:39 ` Nicolas Pitre
2013-06-05 9:59 ` 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=20130604171506.GZ27516@mudshark.cambridge.arm.com \
--to=will.deacon@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