Bug 86951 - arm speculation barrier incompatible with ARMv6 or earlier
Summary: arm speculation barrier incompatible with ARMv6 or earlier
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: assemble-failure
Depends on:
Blocks: 86772
  Show dependency treegraph
 
Reported: 2018-08-14 14:20 UTC by Richard Earnshaw
Modified: 2018-08-23 09:55 UTC (History)
0 users

See Also:
Host:
Target: arm
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-08-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Earnshaw 2018-08-14 14:20:49 UTC
The speculation_barrier_insn pattern uses DSB and ISB, but these instructions were only added in ARMv7.  Another approach is needed for older versions of the architecture.
Comment 1 Richard Earnshaw 2018-08-23 09:48:26 UTC
Author: rearnsha
Date: Thu Aug 23 09:47:34 2018
New Revision: 263806

URL: https://gcc.gnu.org/viewcvs?rev=263806&root=gcc&view=rev
Log:
PR target/86951 arm - Handle speculation barriers on pre-armv7 CPUs

The AArch32 instruction sets prior to Armv7 do not define the ISB and
DSB instructions that are needed to form a speculation barrier.  While
I do not know of any instances of cores based on those instruction
sets being vulnerable to speculative side channel attacks it is
possible to run code built for those ISAs on more recent hardware
where they would become vulnerable.

This patch works around this by using a library call added to libgcc.
That code can then take any platform-specific actions necessary to
ensure safety.

For the moment I've only handled two cases: the library code being
built for armv7 or later anyway and running on Linux.

On Linux we can handle this by calling the kernel function that will
flush a small amount of cache.  Such a sequence ends with a ISB+DSB
sequence if running on an Armv7 or later CPU.

gcc:

	PR target/86951
	* config/arm/arm-protos.h (arm_emit_speculation_barrier): New
	prototype.
	* config/arm/arm.c (speculation_barrier_libfunc): New static
	variable.
	(arm_init_libfuncs): Initialize it.
	(arm_emit_speculation_barrier): New function.
	* config/arm/arm.md (speculation_barrier): Call
	arm_emit_speculation_barrier for architectures that do not have 
	DSB or ISB.
	(speculation_barrier_insn): Only match on Armv7 or later.

libgcc:

	PR target/86951
	* config/arm/lib1funcs.asm (speculation_barrier): New function.
	* config/arm/t-arm (LIB1ASMFUNCS): Add it to list of functions
	to build.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/arm/arm-protos.h
    trunk/gcc/config/arm/arm.c
    trunk/gcc/config/arm/arm.md
    trunk/libgcc/ChangeLog
    trunk/libgcc/config/arm/lib1funcs.S
    trunk/libgcc/config/arm/t-arm
Comment 2 Richard Earnshaw 2018-08-23 09:55:46 UTC
Fixed