Skip to content

Commit ee8a84c

Browse files
compudjshuahkh
authored andcommitted
rseq/selftests: Fix Thumb mode build failure on arm32
Using ".arm .inst" for the arm signature introduces build issues for programs compiled in Thumb mode because the assembler stays in the arm mode for the rest of the inline assembly. Revert to using a ".word" to express the signature as data instead. The choice of signature is a valid trap instruction on arm32 little endian, where both code and data are little endian. ARMv6+ big endian (BE8) generates mixed endianness code vs data: little-endian code and big-endian data. The data value of the signature needs to have its byte order reversed to generate the trap instruction. Prior to ARMv6, -mbig-endian generates big-endian code and data (which match), so the endianness of the data representation of the signature should not be reversed. However, the choice between BE32 and BE8 is done by the linker, so we cannot know whether code and data endianness will be mixed before the linker is invoked. So rather than try to play tricks with the linker, the rseq signature is simply data (not a trap instruction) prior to ARMv6 on big endian. This is why the signature is expressed as data (.word) rather than as instruction (.inst) in assembler. Because a ".word" is used to emit the signature, it will be interpreted as a literal pool by a disassembler, not as an actual instruction. Considering that the signature is not meant to be executed except in scenarios where the program execution is completely bogus, this should not be an issue. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Acked-by: Will Deacon <will.deacon@arm.com> CC: Peter Zijlstra <peterz@infradead.org> CC: Thomas Gleixner <tglx@linutronix.de> CC: Joel Fernandes <joelaf@google.com> CC: Catalin Marinas <catalin.marinas@arm.com> CC: Dave Watson <davejwatson@fb.com> CC: Will Deacon <will.deacon@arm.com> CC: Shuah Khan <shuah@kernel.org> CC: Andi Kleen <andi@firstfloor.org> CC: linux-kselftest@vger.kernel.org CC: "H . Peter Anvin" <hpa@zytor.com> CC: Chris Lameter <cl@linux.com> CC: Russell King <linux@arm.linux.org.uk> CC: Michael Kerrisk <mtk.manpages@gmail.com> CC: "Paul E . McKenney" <paulmck@linux.vnet.ibm.com> CC: Paul Turner <pjt@google.com> CC: Boqun Feng <boqun.feng@gmail.com> CC: Josh Triplett <josh@joshtriplett.org> CC: Steven Rostedt <rostedt@goodmis.org> CC: Ben Maurer <bmaurer@fb.com> CC: linux-api@vger.kernel.org CC: Andy Lutomirski <luto@amacapital.net> CC: Andrew Morton <akpm@linux-foundation.org> CC: Linus Torvalds <torvalds@linux-foundation.org> CC: Carlos O'Donell <carlos@redhat.com> CC: Florian Weimer <fweimer@redhat.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent f4fb8a9 commit ee8a84c

1 file changed

Lines changed: 33 additions & 28 deletions

File tree

‎tools/testing/selftests/rseq/rseq-arm.h‎

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77

88
/*
9+
* - ARM little endian
10+
*
911
* RSEQ_SIG uses the udf A32 instruction with an uncommon immediate operand
1012
* value 0x5de3. This traps if user-space reaches this instruction by mistake,
1113
* and the uncommon operand ensures the kernel does not move the instruction
@@ -22,36 +24,40 @@
2224
* def3 udf #243 ; 0xf3
2325
* e7f5 b.n <7f5>
2426
*
25-
* pre-ARMv6 big endian code:
26-
* e7f5 b.n <7f5>
27-
* def3 udf #243 ; 0xf3
27+
* - ARMv6+ big endian (BE8):
2828
*
2929
* ARMv6+ -mbig-endian generates mixed endianness code vs data: little-endian
30-
* code and big-endian data. Ensure the RSEQ_SIG data signature matches code
31-
* endianness. Prior to ARMv6, -mbig-endian generates big-endian code and data
32-
* (which match), so there is no need to reverse the endianness of the data
33-
* representation of the signature. However, the choice between BE32 and BE8
34-
* is done by the linker, so we cannot know whether code and data endianness
35-
* will be mixed before the linker is invoked.
30+
* code and big-endian data. The data value of the signature needs to have its
31+
* byte order reversed to generate the trap instruction:
32+
*
33+
* Data: 0xf3def5e7
34+
*
35+
* Translates to this A32 instruction pattern:
36+
*
37+
* e7f5def3 udf #24035 ; 0x5de3
38+
*
39+
* Translates to this T16 instruction pattern:
40+
*
41+
* def3 udf #243 ; 0xf3
42+
* e7f5 b.n <7f5>
43+
*
44+
* - Prior to ARMv6 big endian (BE32):
45+
*
46+
* Prior to ARMv6, -mbig-endian generates big-endian code and data
47+
* (which match), so the endianness of the data representation of the
48+
* signature should not be reversed. However, the choice between BE32
49+
* and BE8 is done by the linker, so we cannot know whether code and
50+
* data endianness will be mixed before the linker is invoked. So rather
51+
* than try to play tricks with the linker, the rseq signature is simply
52+
* data (not a trap instruction) prior to ARMv6 on big endian. This is
53+
* why the signature is expressed as data (.word) rather than as
54+
* instruction (.inst) in assembler.
3655
*/
3756

38-
#define RSEQ_SIG_CODE 0xe7f5def3
39-
40-
#ifndef __ASSEMBLER__
41-
42-
#define RSEQ_SIG_DATA \
43-
({ \
44-
int sig; \
45-
asm volatile ("b 2f\n\t" \
46-
"1: .inst " __rseq_str(RSEQ_SIG_CODE) "\n\t" \
47-
"2:\n\t" \
48-
"ldr %[sig], 1b\n\t" \
49-
: [sig] "=r" (sig)); \
50-
sig; \
51-
})
52-
53-
#define RSEQ_SIG RSEQ_SIG_DATA
54-
57+
#ifdef __ARMEB__
58+
#define RSEQ_SIG 0xf3def5e7 /* udf #24035 ; 0x5de3 (ARMv6+) */
59+
#else
60+
#define RSEQ_SIG 0xe7f5def3 /* udf #24035 ; 0x5de3 */
5561
#endif
5662

5763
#define rseq_smp_mb() __asm__ __volatile__ ("dmb" ::: "memory", "cc")
@@ -125,8 +131,7 @@ do { \
125131
__rseq_str(table_label) ":\n\t" \
126132
".word " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \
127133
".word " __rseq_str(start_ip) ", 0x0, " __rseq_str(post_commit_offset) ", 0x0, " __rseq_str(abort_ip) ", 0x0\n\t" \
128-
".arm\n\t" \
129-
".inst " __rseq_str(RSEQ_SIG_CODE) "\n\t" \
134+
".word " __rseq_str(RSEQ_SIG) "\n\t" \
130135
__rseq_str(label) ":\n\t" \
131136
teardown \
132137
"b %l[" __rseq_str(abort_label) "]\n\t"

0 commit comments

Comments
 (0)