[RFC,01/17] x86/alternative: Unconditional custom return thunk

Message ID 20230809072200.450404700@infradead.org
State New
Headers
Series Fix up the recent SRSO patches |

Commit Message

Peter Zijlstra Aug. 9, 2023, 7:12 a.m. UTC
  There is infrastructure to rewrite return thunks to point to any
random thunk one desires, unwrap that from CALL_THUNKS, which up to
now was the sole user of that.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 arch/x86/include/asm/nospec-branch.h |    4 ----
 arch/x86/kernel/alternative.c        |    2 --
 2 files changed, 6 deletions(-)
  

Comments

Nikolay Borisov Aug. 9, 2023, 9:31 a.m. UTC | #1
On 9.08.23 г. 10:12 ч., Peter Zijlstra wrote:
> There is infrastructure to rewrite return thunks to point to any
> random thunk one desires, unwrap that from CALL_THUNKS, which up to
> now was the sole user of that.
> 
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
>   arch/x86/include/asm/nospec-branch.h |    4 ----
>   arch/x86/kernel/alternative.c        |    2 --
>   2 files changed, 6 deletions(-)
> 
> --- a/arch/x86/include/asm/nospec-branch.h
> +++ b/arch/x86/include/asm/nospec-branch.h
> @@ -347,11 +347,7 @@ extern void srso_untrain_ret(void);
>   extern void srso_untrain_ret_alias(void);
>   extern void entry_ibpb(void);
>   
> -#ifdef CONFIG_CALL_THUNKS
>   extern void (*x86_return_thunk)(void);
> -#else
> -#define x86_return_thunk	(&__x86_return_thunk)
> -#endif
>   
>   #ifdef CONFIG_CALL_DEPTH_TRACKING
>   extern void __x86_return_skl(void);
> --- a/arch/x86/kernel/alternative.c
> +++ b/arch/x86/kernel/alternative.c
> @@ -698,9 +698,7 @@ void __init_or_module noinline apply_ret
>   
>   #ifdef CONFIG_RETHUNK
>   
> -#ifdef CONFIG_CALL_THUNKS
>   void (*x86_return_thunk)(void) __ro_after_init = &__x86_return_thunk;
> -#endif
>   
>   /*
>    * Rewrite the compiler generated return thunk tail-calls.
> 
> 


Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>
  
Borislav Petkov Aug. 10, 2023, 11:37 a.m. UTC | #2
On Wed, Aug 09, 2023 at 09:12:19AM +0200, Peter Zijlstra wrote:

Please add a verb to the subject:

"Make the custom return thunk unconditional"

or so.

> There is infrastructure to rewrite return thunks to point to any
> random thunk one desires, unwrap that from CALL_THUNKS, which up to
> now was the sole user of that.

And yes, provided we can do the thing in the next patch which makes
sense to me, ack.
  

Patch

--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -347,11 +347,7 @@  extern void srso_untrain_ret(void);
 extern void srso_untrain_ret_alias(void);
 extern void entry_ibpb(void);
 
-#ifdef CONFIG_CALL_THUNKS
 extern void (*x86_return_thunk)(void);
-#else
-#define x86_return_thunk	(&__x86_return_thunk)
-#endif
 
 #ifdef CONFIG_CALL_DEPTH_TRACKING
 extern void __x86_return_skl(void);
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -698,9 +698,7 @@  void __init_or_module noinline apply_ret
 
 #ifdef CONFIG_RETHUNK
 
-#ifdef CONFIG_CALL_THUNKS
 void (*x86_return_thunk)(void) __ro_after_init = &__x86_return_thunk;
-#endif
 
 /*
  * Rewrite the compiler generated return thunk tail-calls.