* [PATCH] x86/retbleed: Add __x86_return_thunk alignment checks
@ 2023-05-15 14:07 Borislav Petkov
2023-05-15 14:14 ` Andrew Cooper
2023-05-17 10:30 ` [tip: x86/cpu] " tip-bot2 for Borislav Petkov (AMD)
0 siblings, 2 replies; 3+ messages in thread
From: Borislav Petkov @ 2023-05-15 14:07 UTC (permalink / raw)
To: X86 ML; +Cc: LKML, Andrew Cooper
From: "Borislav Petkov (AMD)" <bp@alien8.de>
Add a linker assertion and compute the 0xcc padding dynamically so that
__x86_return_thunk is always cacheline-aligned. Leave the SYM_START()
macro in as the untraining doesn't need ENDBR annotations anyway.
Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
---
arch/x86/kernel/vmlinux.lds.S | 4 ++++
arch/x86/lib/retpoline.S | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 25f155205770..03c885d3640f 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -508,4 +508,8 @@ INIT_PER_CPU(irq_stack_backing_store);
"fixed_percpu_data is not at start of per-cpu area");
#endif
+#ifdef CONFIG_RETHUNK
+. = ASSERT((__x86_return_thunk & 0x3f) == 0, "__x86_return_thunk not cacheline-aligned");
+#endif
+
#endif /* CONFIG_X86_64 */
diff --git a/arch/x86/lib/retpoline.S b/arch/x86/lib/retpoline.S
index b3b1e376dce8..3fd066d42ec0 100644
--- a/arch/x86/lib/retpoline.S
+++ b/arch/x86/lib/retpoline.S
@@ -143,7 +143,7 @@ SYM_CODE_END(__x86_indirect_jump_thunk_array)
* from re-poisioning the BTB prediction.
*/
.align 64
- .skip 63, 0xcc
+ .skip 64 - (__x86_return_thunk - zen_untrain_ret), 0xcc
SYM_START(zen_untrain_ret, SYM_L_GLOBAL, SYM_A_NONE)
ANNOTATE_NOENDBR
/*
--
2.35.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] x86/retbleed: Add __x86_return_thunk alignment checks
2023-05-15 14:07 [PATCH] x86/retbleed: Add __x86_return_thunk alignment checks Borislav Petkov
@ 2023-05-15 14:14 ` Andrew Cooper
2023-05-17 10:30 ` [tip: x86/cpu] " tip-bot2 for Borislav Petkov (AMD)
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Cooper @ 2023-05-15 14:14 UTC (permalink / raw)
To: Borislav Petkov, X86 ML; +Cc: LKML
On 15/05/2023 3:07 pm, Borislav Petkov wrote:
> diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
> index 25f155205770..03c885d3640f 100644
> --- a/arch/x86/kernel/vmlinux.lds.S
> +++ b/arch/x86/kernel/vmlinux.lds.S
> @@ -508,4 +508,8 @@ INIT_PER_CPU(irq_stack_backing_store);
> "fixed_percpu_data is not at start of per-cpu area");
> #endif
>
> +#ifdef CONFIG_RETHUNK
> +. = ASSERT((__x86_return_thunk & 0x3f) == 0, "__x86_return_thunk not cacheline-aligned");
Probably best to say 64b aligned. The safety property is to do with the
layout of the BTB, not of a cacheline.
FWIW,
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip: x86/cpu] x86/retbleed: Add __x86_return_thunk alignment checks
2023-05-15 14:07 [PATCH] x86/retbleed: Add __x86_return_thunk alignment checks Borislav Petkov
2023-05-15 14:14 ` Andrew Cooper
@ 2023-05-17 10:30 ` tip-bot2 for Borislav Petkov (AMD)
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Borislav Petkov (AMD) @ 2023-05-17 10:30 UTC (permalink / raw)
To: linux-tip-commits; +Cc: Andrew Cooper, Borislav Petkov (AMD), x86, linux-kernel
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: f220125b999b2c9694149c6bda2798d8096f47ed
Gitweb: https://git.kernel.org/tip/f220125b999b2c9694149c6bda2798d8096f47ed
Author: Borislav Petkov (AMD) <bp@alien8.de>
AuthorDate: Mon, 15 May 2023 16:07:26 +02:00
Committer: Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Wed, 17 May 2023 12:14:21 +02:00
x86/retbleed: Add __x86_return_thunk alignment checks
Add a linker assertion and compute the 0xcc padding dynamically so that
__x86_return_thunk is always cacheline-aligned. Leave the SYM_START()
macro in as the untraining doesn't need ENDBR annotations anyway.
Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Link: https://lore.kernel.org/r/20230515140726.28689-1-bp@alien8.de
---
arch/x86/kernel/vmlinux.lds.S | 4 ++++
arch/x86/lib/retpoline.S | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 25f1552..03c885d 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -508,4 +508,8 @@ INIT_PER_CPU(irq_stack_backing_store);
"fixed_percpu_data is not at start of per-cpu area");
#endif
+#ifdef CONFIG_RETHUNK
+. = ASSERT((__x86_return_thunk & 0x3f) == 0, "__x86_return_thunk not cacheline-aligned");
+#endif
+
#endif /* CONFIG_X86_64 */
diff --git a/arch/x86/lib/retpoline.S b/arch/x86/lib/retpoline.S
index b3b1e37..3fd066d 100644
--- a/arch/x86/lib/retpoline.S
+++ b/arch/x86/lib/retpoline.S
@@ -143,7 +143,7 @@ SYM_CODE_END(__x86_indirect_jump_thunk_array)
* from re-poisioning the BTB prediction.
*/
.align 64
- .skip 63, 0xcc
+ .skip 64 - (__x86_return_thunk - zen_untrain_ret), 0xcc
SYM_START(zen_untrain_ret, SYM_L_GLOBAL, SYM_A_NONE)
ANNOTATE_NOENDBR
/*
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-05-17 10:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-15 14:07 [PATCH] x86/retbleed: Add __x86_return_thunk alignment checks Borislav Petkov
2023-05-15 14:14 ` Andrew Cooper
2023-05-17 10:30 ` [tip: x86/cpu] " tip-bot2 for Borislav Petkov (AMD)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®