From: linux@armlinux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: disallow ARM_THUMB for ARMv4 builds
Date: Sun, 18 Dec 2016 14:16:31 +0000 [thread overview]
Message-ID: <20161218141630.GP14217@n2100.armlinux.org.uk> (raw)
In-Reply-To: <CAKv+Gu_1zbAB45SQ=702_v3H=RetLFsgknmp52iTSV9M4GSqHg@mail.gmail.com>
On Sun, Dec 18, 2016 at 11:57:00AM +0000, Ard Biesheuvel wrote:
> On 16 December 2016 at 21:51, Arnd Bergmann <arnd@arndb.de> wrote:
> > On Friday, December 16, 2016 5:20:22 PM CET Ard Biesheuvel wrote:
> >>
> >> Can't we use the old
> >>
> >> tst lr, #1
> >> moveq pc, lr
> >> bx lr
> >>
> >> trick? (where bx lr needs to be emitted as a plain opcode to hide it
> >> from the assembler)
> >>
> >
> > Yes, that should work around the specific problem in theory, but back
> > when Jonas tried it, it still didn't work. There may also be other
> > problems in that configuration.
> >
>
> This should do the trick as well, I think:
>
> diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
> index 9f157e7c51e7..3bfb32010234 100644
> --- a/arch/arm/kernel/entry-armv.S
> +++ b/arch/arm/kernel/entry-armv.S
> @@ -835,7 +835,12 @@ ENDPROC(__switch_to)
>
> .macro usr_ret, reg
> #ifdef CONFIG_ARM_THUMB
> +#ifdef CONFIG_CPU_32v4
> + str \reg, [sp, #-4]!
> + ldr pc, [sp], #4
> +#else
> bx \reg
> +#endif
> #else
> ret \reg
> #endif
>
> with the added benefit that we don't clobber the N and Z flags. Of
> course, this will result in all CPUs using a non-optimal sequence if
> support for v4 is compiled in.
We don't clobber those flags anyway. bx doesn't change any of the flags.
'ret' devolves into either bx or a mov instruction. A mov instruction
without 's' does not change the flags either.
So there is no "added benefit". In fact, there's only detrimental
effects. str and ldr are going to be several cycles longer than the
plain mov.
In any case, the "CONFIG_CPU_32v4" alone doesn't hack it, we also have
CONFIG_CPU_32v3 to also consider.
In any case, I prefer the solution previously posted - to test bit 0 of
the PC, and select the instruction based on that. It'll take some
assembly level macros to handle all cases.
--
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
next prev parent reply other threads:[~2016-12-18 14:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-16 9:14 [PATCH] ARM: disallow ARM_THUMB for ARMv4 builds Arnd Bergmann
2016-12-16 17:20 ` Ard Biesheuvel
2016-12-16 21:51 ` Arnd Bergmann
2016-12-18 11:57 ` Ard Biesheuvel
2016-12-18 14:16 ` Russell King - ARM Linux [this message]
2016-12-18 15:04 ` Ard Biesheuvel
2016-12-18 23:40 ` Russell King - ARM Linux
2016-12-19 4:10 ` 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=20161218141630.GP14217@n2100.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--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