x86/retpoline: change RETPOLINE into CONFIG_RETPOLINE
diff mbox series

Message ID 20181231234253.2724-1-namit@vmware.com
State New
Headers show
Series
  • x86/retpoline: change RETPOLINE into CONFIG_RETPOLINE
Related show

Commit Message

Nadav Amit Dec. 31, 2018, 11:42 p.m. UTC
A recent enhancement intentionally fails the kernel build if the
compiler does not support retpolines and CONFIG_RETPOLINE is set.

However, the patch that introduced it did not change RETPOLINE macro
references into CONFIG_RETPOLINE ones. As a result, indirect branches
that are used by init functions are not kept (i.e., they use
retpolines), and modules that do not use retpolines are marked as
retpoline-safe.

Fix it be changing RETPOLINE into CONFIG_RETPOLINE.

Fixes: 4cd24de3a098 ("x86/retpoline: Make CONFIG_RETPOLINE depend on compiler support")
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Zhenzhong Duan <zhenzhong.duan@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: David Woodhouse <dwmw@amazon.co.uk>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: stable@vger.kernel.org
Signed-off-by: Nadav Amit <namit@vmware.com>
---
 arch/x86/kernel/cpu/bugs.c   | 2 +-
 include/linux/compiler-gcc.h | 2 +-
 include/linux/module.h       | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

Comments

Zhenzhong Duan Jan. 2, 2019, 1:17 a.m. UTC | #1
On 2019/1/1 7:42, Nadav Amit wrote:
> A recent enhancement intentionally fails the kernel build if the
> compiler does not support retpolines and CONFIG_RETPOLINE is set.
>
> However, the patch that introduced it did not change RETPOLINE macro
> references into CONFIG_RETPOLINE ones. As a result, indirect branches
> that are used by init functions are not kept (i.e., they use
> retpolines), and modules that do not use retpolines are marked as
> retpoline-safe.
>
> Fix it be changing RETPOLINE into CONFIG_RETPOLINE.
>
> Fixes: 4cd24de3a098 ("x86/retpoline: Make CONFIG_RETPOLINE depend on compiler support")
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Zhenzhong Duan <zhenzhong.duan@oracle.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: David Woodhouse <dwmw@amazon.co.uk>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Nadav Amit <namit@vmware.com>
> ---
>   arch/x86/kernel/cpu/bugs.c   | 2 +-
>   include/linux/compiler-gcc.h | 2 +-
>   include/linux/module.h       | 2 +-
>   3 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
> index 8654b8b0c848..1de0f4170178 100644
> --- a/arch/x86/kernel/cpu/bugs.c
> +++ b/arch/x86/kernel/cpu/bugs.c
> @@ -215,7 +215,7 @@ static enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init =
>   static enum spectre_v2_user_mitigation spectre_v2_user __ro_after_init =
>   	SPECTRE_V2_USER_NONE;
>   
> -#ifdef RETPOLINE
> +#ifdef CONFIG_RETPOLINE
>   static bool spectre_v2_bad_module;
>   
>   bool retpoline_module_ok(bool has_retpoline)
> diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
> index 2010493e1040..977ddf2774f9 100644
> --- a/include/linux/compiler-gcc.h
> +++ b/include/linux/compiler-gcc.h
> @@ -68,7 +68,7 @@
>    */
>   #define uninitialized_var(x) x = x
>   
> -#ifdef RETPOLINE
> +#ifdef CONFIG_RETPOLINE
>   #define __noretpoline __attribute__((__indirect_branch__("keep")))
>   #endif
>   
> diff --git a/include/linux/module.h b/include/linux/module.h
> index fce6b4335e36..0c575f51fe57 100644
> --- a/include/linux/module.h
> +++ b/include/linux/module.h
> @@ -817,7 +817,7 @@ static inline void module_bug_finalize(const Elf_Ehdr *hdr,
>   static inline void module_bug_cleanup(struct module *mod) {}
>   #endif	/* CONFIG_GENERIC_BUG */
>   
> -#ifdef RETPOLINE
> +#ifdef CONFIG_RETPOLINE
>   extern bool retpoline_module_ok(bool has_retpoline);
>   #else
>   static inline bool retpoline_module_ok(bool has_retpoline)

Someone sent a similar patch last month, see below link,  you missed the 
change in scripts/mod/modpost.c

https://lkml.org/lkml/2018/12/10/540

But you patch description is more clear.
Nadav Amit Jan. 2, 2019, 5:23 p.m. UTC | #2
> On Jan 1, 2019, at 5:17 PM, Zhenzhong Duan <zhenzhong.duan@oracle.com> wrote:
> 
> 
> On 2019/1/1 7:42, Nadav Amit wrote:
>> A recent enhancement intentionally fails the kernel build if the
>> compiler does not support retpolines and CONFIG_RETPOLINE is set.
>> 
>> However, the patch that introduced it did not change RETPOLINE macro
>> references into CONFIG_RETPOLINE ones. As a result, indirect branches
>> that are used by init functions are not kept (i.e., they use
>> retpolines), and modules that do not use retpolines are marked as
>> retpoline-safe.
>> 
>> Fix it be changing RETPOLINE into CONFIG_RETPOLINE.
>> 
>> Fixes: 4cd24de3a098 ("x86/retpoline: Make CONFIG_RETPOLINE depend on compiler support")
>> Cc: Peter Zijlstra <peterz@infradead.org>
>> Cc: Zhenzhong Duan <zhenzhong.duan@oracle.com>
>> Cc: Thomas Gleixner <tglx@linutronix.de>
>> Cc: David Woodhouse <dwmw@amazon.co.uk>
>> Cc: Andy Lutomirski <luto@kernel.org>
>> Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Nadav Amit <namit@vmware.com>
>> ---
>>  arch/x86/kernel/cpu/bugs.c   | 2 +-
>>  include/linux/compiler-gcc.h | 2 +-
>>  include/linux/module.h       | 2 +-
>>  3 files changed, 3 insertions(+), 3 deletions(-)
>> 
>> diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
>> index 8654b8b0c848..1de0f4170178 100644
>> --- a/arch/x86/kernel/cpu/bugs.c
>> +++ b/arch/x86/kernel/cpu/bugs.c
>> @@ -215,7 +215,7 @@ static enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init =
>>  static enum spectre_v2_user_mitigation spectre_v2_user __ro_after_init =
>>  	SPECTRE_V2_USER_NONE;
>>  -#ifdef RETPOLINE
>> +#ifdef CONFIG_RETPOLINE
>>  static bool spectre_v2_bad_module;
>>    bool retpoline_module_ok(bool has_retpoline)
>> diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
>> index 2010493e1040..977ddf2774f9 100644
>> --- a/include/linux/compiler-gcc.h
>> +++ b/include/linux/compiler-gcc.h
>> @@ -68,7 +68,7 @@
>>   */
>>  #define uninitialized_var(x) x = x
>>  -#ifdef RETPOLINE
>> +#ifdef CONFIG_RETPOLINE
>>  #define __noretpoline __attribute__((__indirect_branch__("keep")))
>>  #endif
>>  diff --git a/include/linux/module.h b/include/linux/module.h
>> index fce6b4335e36..0c575f51fe57 100644
>> --- a/include/linux/module.h
>> +++ b/include/linux/module.h
>> @@ -817,7 +817,7 @@ static inline void module_bug_finalize(const Elf_Ehdr *hdr,
>>  static inline void module_bug_cleanup(struct module *mod) {}
>>  #endif	/* CONFIG_GENERIC_BUG */
>>  -#ifdef RETPOLINE
>> +#ifdef CONFIG_RETPOLINE
>>  extern bool retpoline_module_ok(bool has_retpoline);
>>  #else
>>  static inline bool retpoline_module_ok(bool has_retpoline)
> 
> Someone sent a similar patch last month, see below link,  you missed the change in scripts/mod/modpost.c

Indeed. I missed this patch since it wasn’t on tip (and Google wasn’t
helpful either).

I wonder why it has still not been applied.
Zhenzhong Duan Jan. 3, 2019, 2:07 a.m. UTC | #3
On 2019/1/3 1:23, Nadav Amit wrote:
>> On Jan 1, 2019, at 5:17 PM, Zhenzhong Duan <zhenzhong.duan@oracle.com> wrote:
>>
>>
>> On 2019/1/1 7:42, Nadav Amit wrote:
>>> A recent enhancement intentionally fails the kernel build if the
>>> compiler does not support retpolines and CONFIG_RETPOLINE is set.
>>>
>>> However, the patch that introduced it did not change RETPOLINE macro
>>> references into CONFIG_RETPOLINE ones. As a result, indirect branches
>>> that are used by init functions are not kept (i.e., they use
>>> retpolines), and modules that do not use retpolines are marked as
>>> retpoline-safe.
>>>
>>> Fix it be changing RETPOLINE into CONFIG_RETPOLINE.
>>>
>>> Fixes: 4cd24de3a098 ("x86/retpoline: Make CONFIG_RETPOLINE depend on compiler support")
>>> Cc: Peter Zijlstra <peterz@infradead.org>
>>> Cc: Zhenzhong Duan <zhenzhong.duan@oracle.com>
>>> Cc: Thomas Gleixner <tglx@linutronix.de>
>>> Cc: David Woodhouse <dwmw@amazon.co.uk>
>>> Cc: Andy Lutomirski <luto@kernel.org>
>>> Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
>>> Cc: stable@vger.kernel.org
>>> Signed-off-by: Nadav Amit <namit@vmware.com>
>>> ---
>>>   arch/x86/kernel/cpu/bugs.c   | 2 +-
>>>   include/linux/compiler-gcc.h | 2 +-
>>>   include/linux/module.h       | 2 +-
>>>   3 files changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
>>> index 8654b8b0c848..1de0f4170178 100644
>>> --- a/arch/x86/kernel/cpu/bugs.c
>>> +++ b/arch/x86/kernel/cpu/bugs.c
>>> @@ -215,7 +215,7 @@ static enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init =
>>>   static enum spectre_v2_user_mitigation spectre_v2_user __ro_after_init =
>>>   	SPECTRE_V2_USER_NONE;
>>>   -#ifdef RETPOLINE
>>> +#ifdef CONFIG_RETPOLINE
>>>   static bool spectre_v2_bad_module;
>>>     bool retpoline_module_ok(bool has_retpoline)
>>> diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
>>> index 2010493e1040..977ddf2774f9 100644
>>> --- a/include/linux/compiler-gcc.h
>>> +++ b/include/linux/compiler-gcc.h
>>> @@ -68,7 +68,7 @@
>>>    */
>>>   #define uninitialized_var(x) x = x
>>>   -#ifdef RETPOLINE
>>> +#ifdef CONFIG_RETPOLINE
>>>   #define __noretpoline __attribute__((__indirect_branch__("keep")))
>>>   #endif
>>>   diff --git a/include/linux/module.h b/include/linux/module.h
>>> index fce6b4335e36..0c575f51fe57 100644
>>> --- a/include/linux/module.h
>>> +++ b/include/linux/module.h
>>> @@ -817,7 +817,7 @@ static inline void module_bug_finalize(const Elf_Ehdr *hdr,
>>>   static inline void module_bug_cleanup(struct module *mod) {}
>>>   #endif	/* CONFIG_GENERIC_BUG */
>>>   -#ifdef RETPOLINE
>>> +#ifdef CONFIG_RETPOLINE
>>>   extern bool retpoline_module_ok(bool has_retpoline);
>>>   #else
>>>   static inline bool retpoline_module_ok(bool has_retpoline)
>> Someone sent a similar patch last month, see below link,  you missed the change in scripts/mod/modpost.c
> Indeed. I missed this patch since it wasn’t on tip (and Google wasn’t
> helpful either).
>
> I wonder why it has still not been applied.


See https://lkml.org/lkml/2018/12/21/244

Patch
diff mbox series

diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 8654b8b0c848..1de0f4170178 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -215,7 +215,7 @@  static enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init =
 static enum spectre_v2_user_mitigation spectre_v2_user __ro_after_init =
 	SPECTRE_V2_USER_NONE;
 
-#ifdef RETPOLINE
+#ifdef CONFIG_RETPOLINE
 static bool spectre_v2_bad_module;
 
 bool retpoline_module_ok(bool has_retpoline)
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 2010493e1040..977ddf2774f9 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -68,7 +68,7 @@ 
  */
 #define uninitialized_var(x) x = x
 
-#ifdef RETPOLINE
+#ifdef CONFIG_RETPOLINE
 #define __noretpoline __attribute__((__indirect_branch__("keep")))
 #endif
 
diff --git a/include/linux/module.h b/include/linux/module.h
index fce6b4335e36..0c575f51fe57 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -817,7 +817,7 @@  static inline void module_bug_finalize(const Elf_Ehdr *hdr,
 static inline void module_bug_cleanup(struct module *mod) {}
 #endif	/* CONFIG_GENERIC_BUG */
 
-#ifdef RETPOLINE
+#ifdef CONFIG_RETPOLINE
 extern bool retpoline_module_ok(bool has_retpoline);
 #else
 static inline bool retpoline_module_ok(bool has_retpoline)