* [PATCH v2 0/2] arm64: BTI cleanups
@ 2021-12-07 18:01 Mark Brown
2021-12-07 18:01 ` [PATCH v2 1/2] arm64: Add macro version of the BTI instruction Mark Brown
2021-12-07 18:01 ` [PATCH v2 2/2] arm64: Unconditionally override SYM_FUNC macros Mark Brown
0 siblings, 2 replies; 5+ messages in thread
From: Mark Brown @ 2021-12-07 18:01 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon
Cc: Mark Rutland, Ard Biesheuvel, linux-arm-kernel, Mark Brown
This patch series brings together a few cleanups for the assembly
portions of the in kernel BTI support.
v2:
- Pull in the assembler macro for BTI proposed by Mark Rutland.
- Unconditionally override the SYM_FUNC macros.
Mark Brown (2):
arm64: Add macro version of the BTI instruction
arm64: Unconditionally override SYM_FUNC macros
arch/arm64/crypto/aes-modes.S | 10 +++++-----
arch/arm64/include/asm/assembler.h | 18 ++++++++++++++++++
arch/arm64/include/asm/linkage.h | 23 ++++++++++++-----------
arch/arm64/kernel/entry-ftrace.S | 4 ----
arch/arm64/lib/kasan_sw_tags.S | 2 --
5 files changed, 35 insertions(+), 22 deletions(-)
base-commit: 0fcfb00b28c0b7884635dacf38e46d60bf3d4eb1
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] arm64: Add macro version of the BTI instruction
2021-12-07 18:01 [PATCH v2 0/2] arm64: BTI cleanups Mark Brown
@ 2021-12-07 18:01 ` Mark Brown
2021-12-07 19:02 ` Ard Biesheuvel
2021-12-07 18:01 ` [PATCH v2 2/2] arm64: Unconditionally override SYM_FUNC macros Mark Brown
1 sibling, 1 reply; 5+ messages in thread
From: Mark Brown @ 2021-12-07 18:01 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon
Cc: Mark Rutland, Ard Biesheuvel, linux-arm-kernel, Mark Brown
BTI is only available from v8.5 so we need to encode it using HINT in
generic code and for older toolchains. Add an assembler macro written
by Mark Rutland which lets us use the mnemonic and update the existing
users.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
arch/arm64/crypto/aes-modes.S | 10 +++++-----
arch/arm64/include/asm/assembler.h | 18 ++++++++++++++++++
arch/arm64/include/asm/linkage.h | 7 +------
3 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/arch/arm64/crypto/aes-modes.S b/arch/arm64/crypto/aes-modes.S
index b495de22bb38..ff01f0167ba2 100644
--- a/arch/arm64/crypto/aes-modes.S
+++ b/arch/arm64/crypto/aes-modes.S
@@ -363,15 +363,15 @@ ST5( mov v4.16b, vctr.16b )
adr x16, 1f
sub x16, x16, x12, lsl #3
br x16
- hint 34 // bti c
+ bti c
mov v0.d[0], vctr.d[0]
- hint 34 // bti c
+ bti c
mov v1.d[0], vctr.d[0]
- hint 34 // bti c
+ bti c
mov v2.d[0], vctr.d[0]
- hint 34 // bti c
+ bti c
mov v3.d[0], vctr.d[0]
-ST5( hint 34 )
+ST5( bti c )
ST5( mov v4.d[0], vctr.d[0] )
1: b 2f
.previous
diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
index 136d13f3d6e9..87f296198366 100644
--- a/arch/arm64/include/asm/assembler.h
+++ b/arch/arm64/include/asm/assembler.h
@@ -790,6 +790,24 @@ alternative_endif
.Lnoyield_\@:
.endm
+/*
+ * Branch Target Identifier (BTI)
+ */
+ .macro bti, targets
+ .equ .L__bti_targets_c, 1
+ .equ .L__bti_targets_j, 2
+ .equ .L__bti_targets_jc,3
+ .if .L__bti_targets_\targets == .L__bti_targets_c
+ hint #34
+ .elseif .L__bti_targets_\targets == .L__bti_targets_j
+ hint #36
+ .elseif .L__bti_targets_\targets == .L__bti_targets_jc
+ hint #38
+ .else
+ .error "Unsupported BTI targets '\targets\()'"
+ .endif
+ .endm
+
/*
* This macro emits a program property note section identifying
* architecture features which require special handling, mainly for
diff --git a/arch/arm64/include/asm/linkage.h b/arch/arm64/include/asm/linkage.h
index 9906541a6861..c5d0c11d7709 100644
--- a/arch/arm64/include/asm/linkage.h
+++ b/arch/arm64/include/asm/linkage.h
@@ -6,12 +6,7 @@
#if defined(CONFIG_ARM64_BTI_KERNEL) && defined(__aarch64__)
-/*
- * Since current versions of gas reject the BTI instruction unless we
- * set the architecture version to v8.5 we use the hint instruction
- * instead.
- */
-#define BTI_C hint 34 ;
+#define BTI_C bti c ;
/*
* When using in-kernel BTI we need to ensure that PCS-conformant assembly
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] arm64: Unconditionally override SYM_FUNC macros
2021-12-07 18:01 [PATCH v2 0/2] arm64: BTI cleanups Mark Brown
2021-12-07 18:01 ` [PATCH v2 1/2] arm64: Add macro version of the BTI instruction Mark Brown
@ 2021-12-07 18:01 ` Mark Brown
1 sibling, 0 replies; 5+ messages in thread
From: Mark Brown @ 2021-12-07 18:01 UTC (permalink / raw)
To: Catalin Marinas, Will Deacon
Cc: Mark Rutland, Ard Biesheuvel, linux-arm-kernel, Mark Brown
Currently we only override the SYM_FUNC macros when we need to insert
BTI C into them. Since we now unconditionally provide the BTI_C macro
used to do that let's always override them, that way any issues with our
overrides it'll show up more consistently.
Since this means that we now have an unconditional definition of BTI_C
update the other users to remove the ifdefs around usage, making them
look a bit neater.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
arch/arm64/include/asm/linkage.h | 16 +++++++++++-----
arch/arm64/kernel/entry-ftrace.S | 4 ----
arch/arm64/lib/kasan_sw_tags.S | 2 --
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/arch/arm64/include/asm/linkage.h b/arch/arm64/include/asm/linkage.h
index c5d0c11d7709..1cfa8bb33edd 100644
--- a/arch/arm64/include/asm/linkage.h
+++ b/arch/arm64/include/asm/linkage.h
@@ -8,10 +8,18 @@
#define BTI_C bti c ;
+#else
+
+#define BTI_C
+
+#endif
+
/*
- * When using in-kernel BTI we need to ensure that PCS-conformant assembly
- * functions have suitable annotations. Override SYM_FUNC_START to insert
- * a BTI landing pad at the start of everything.
+ * When using in-kernel BTI we need to ensure that PCS-conformant
+ * assembly functions have suitable annotations. Override
+ * SYM_FUNC_START to insert a BTI landing pad at the start of
+ * everything, the override is done unconditionally so we're more
+ * likely to notice any drift from the overridden definitions.
*/
#define SYM_FUNC_START(name) \
SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN) \
@@ -37,8 +45,6 @@
SYM_START(name, SYM_L_WEAK, SYM_A_NONE) \
BTI_C
-#endif
-
/*
* Annotate a function as position independent, i.e., safe to be called before
* the kernel virtual mapping is activated.
diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
index 8cf970d219f5..46a2de864794 100644
--- a/arch/arm64/kernel/entry-ftrace.S
+++ b/arch/arm64/kernel/entry-ftrace.S
@@ -77,17 +77,13 @@
.endm
SYM_CODE_START(ftrace_regs_caller)
-#ifdef BTI_C
BTI_C
-#endif
ftrace_regs_entry 1
b ftrace_common
SYM_CODE_END(ftrace_regs_caller)
SYM_CODE_START(ftrace_caller)
-#ifdef BTI_C
BTI_C
-#endif
ftrace_regs_entry 0
b ftrace_common
SYM_CODE_END(ftrace_caller)
diff --git a/arch/arm64/lib/kasan_sw_tags.S b/arch/arm64/lib/kasan_sw_tags.S
index 5b04464c045e..a6d6fa2f761e 100644
--- a/arch/arm64/lib/kasan_sw_tags.S
+++ b/arch/arm64/lib/kasan_sw_tags.S
@@ -38,9 +38,7 @@
* incremented by 256 prior to return).
*/
SYM_CODE_START(__hwasan_tag_mismatch)
-#ifdef BTI_C
BTI_C
-#endif
add x29, sp, #232
stp x2, x3, [sp, #8 * 2]
stp x4, x5, [sp, #8 * 4]
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] arm64: Add macro version of the BTI instruction
2021-12-07 18:01 ` [PATCH v2 1/2] arm64: Add macro version of the BTI instruction Mark Brown
@ 2021-12-07 19:02 ` Ard Biesheuvel
2021-12-08 13:37 ` Mark Brown
0 siblings, 1 reply; 5+ messages in thread
From: Ard Biesheuvel @ 2021-12-07 19:02 UTC (permalink / raw)
To: Mark Brown; +Cc: Catalin Marinas, Will Deacon, Mark Rutland, Linux ARM
On Tue, 7 Dec 2021 at 19:02, Mark Brown <broonie@kernel.org> wrote:
>
> BTI is only available from v8.5 so we need to encode it using HINT in
> generic code and for older toolchains. Add an assembler macro written
> by Mark Rutland which lets us use the mnemonic and update the existing
> users.
>
> Suggested-by: Mark Rutland <mark.rutland@arm.com>
> Signed-off-by: Mark Brown <broonie@kernel.org>
> ---
> arch/arm64/crypto/aes-modes.S | 10 +++++-----
> arch/arm64/include/asm/assembler.h | 18 ++++++++++++++++++
> arch/arm64/include/asm/linkage.h | 7 +------
> 3 files changed, 24 insertions(+), 11 deletions(-)
>
> diff --git a/arch/arm64/crypto/aes-modes.S b/arch/arm64/crypto/aes-modes.S
> index b495de22bb38..ff01f0167ba2 100644
> --- a/arch/arm64/crypto/aes-modes.S
> +++ b/arch/arm64/crypto/aes-modes.S
> @@ -363,15 +363,15 @@ ST5( mov v4.16b, vctr.16b )
> adr x16, 1f
> sub x16, x16, x12, lsl #3
> br x16
> - hint 34 // bti c
> + bti c
> mov v0.d[0], vctr.d[0]
> - hint 34 // bti c
> + bti c
> mov v1.d[0], vctr.d[0]
> - hint 34 // bti c
> + bti c
> mov v2.d[0], vctr.d[0]
> - hint 34 // bti c
> + bti c
> mov v3.d[0], vctr.d[0]
> -ST5( hint 34 )
> +ST5( bti c )
> ST5( mov v4.d[0], vctr.d[0] )
> 1: b 2f
> .previous
> diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
> index 136d13f3d6e9..87f296198366 100644
> --- a/arch/arm64/include/asm/assembler.h
> +++ b/arch/arm64/include/asm/assembler.h
> @@ -790,6 +790,24 @@ alternative_endif
> .Lnoyield_\@:
> .endm
>
> +/*
> + * Branch Target Identifier (BTI)
> + */
> + .macro bti, targets
> + .equ .L__bti_targets_c, 1
> + .equ .L__bti_targets_j, 2
> + .equ .L__bti_targets_jc,3
Can't we make these 34/36/38, respectively, and just do
hint #.Lbti_targets_\targets
here?
> + .if .L__bti_targets_\targets == .L__bti_targets_c
> + hint #34
> + .elseif .L__bti_targets_\targets == .L__bti_targets_j
> + hint #36
> + .elseif .L__bti_targets_\targets == .L__bti_targets_jc
> + hint #38
> + .else
> + .error "Unsupported BTI targets '\targets\()'"
> + .endif
> + .endm
> +
> /*
> * This macro emits a program property note section identifying
> * architecture features which require special handling, mainly for
> diff --git a/arch/arm64/include/asm/linkage.h b/arch/arm64/include/asm/linkage.h
> index 9906541a6861..c5d0c11d7709 100644
> --- a/arch/arm64/include/asm/linkage.h
> +++ b/arch/arm64/include/asm/linkage.h
> @@ -6,12 +6,7 @@
>
> #if defined(CONFIG_ARM64_BTI_KERNEL) && defined(__aarch64__)
>
> -/*
> - * Since current versions of gas reject the BTI instruction unless we
> - * set the architecture version to v8.5 we use the hint instruction
> - * instead.
> - */
> -#define BTI_C hint 34 ;
> +#define BTI_C bti c ;
>
> /*
> * When using in-kernel BTI we need to ensure that PCS-conformant assembly
> --
> 2.30.2
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] arm64: Add macro version of the BTI instruction
2021-12-07 19:02 ` Ard Biesheuvel
@ 2021-12-08 13:37 ` Mark Brown
0 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2021-12-08 13:37 UTC (permalink / raw)
To: Ard Biesheuvel; +Cc: Catalin Marinas, Will Deacon, Mark Rutland, Linux ARM
[-- Attachment #1.1: Type: text/plain, Size: 428 bytes --]
On Tue, Dec 07, 2021 at 08:02:16PM +0100, Ard Biesheuvel wrote:
> Can't we make these 34/36/38, respectively, and just do
>
> hint #.Lbti_targets_\targets
>
> here?
That works, the only downside is that it generates more hostile error
messages if you typo the argument, eg:
<instantiation>:4:7: error: immediate must be an integer in range [0, 127].
hint #.L__bti_targets_d
I don't really mind either way.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
[-- Attachment #2: Type: text/plain, Size: 176 bytes --]
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-12-08 13:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-12-07 18:01 [PATCH v2 0/2] arm64: BTI cleanups Mark Brown
2021-12-07 18:01 ` [PATCH v2 1/2] arm64: Add macro version of the BTI instruction Mark Brown
2021-12-07 19:02 ` Ard Biesheuvel
2021-12-08 13:37 ` Mark Brown
2021-12-07 18:01 ` [PATCH v2 2/2] arm64: Unconditionally override SYM_FUNC macros Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).