Skip to contentSkip to conversation

x86 bugfixes for LTO

PATCH Applied Arnd Bergmann 7 participants 14 messages Feb 2, 2018 – Feb 13, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover x86 bugfixes for LTO

Here are three bugfixes for x86 that I needed to get LTO-enabled kernels to build reliably. I'm not sure abouto that first one though.

None of these are urgent, as they don't show up in mainline kernels and they don't indicate serious problems.

Arnd Bergmann (3):
x86: dumpstack: avoid uninitialized variable
x86: fix swsusp_arch_resume prototype
x86: error_inject: make just_return_func globally visible

 arch/x86/kernel/dumpstack.c   | 2 +-
 arch/x86/lib/error-inject.c   | 1 +
 arch/x86/power/hibernate_32.c | 2 +-
 arch/x86/power/hibernate_64.c | 2 +-
 include/linux/suspend.h       | 2 ++
 kernel/power/power.h          | 3 ---
 6 files changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
2.9.0
#1 lore raw

PATCH 1/3 x86: dumpstack: avoid uninitlized variable

In some configurations, 'partial' does not get initialized, as shown by this gcc-8 warning:

arch/x86/kernel/dumpstack.c: In function 'show_trace_log_lvl':
arch/x86/kernel/dumpstack.c:156:4: error: 'partial' may be used uninitialized in this function [-Werror=maybe-uninitialized]

    show_regs_if_on_stack(&stack_info, regs, partial);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This initializes it to false, to get the previous behavior in this case.

a9cdbe72c4e8 ("x86/dumpstack: Fix partial register dumps")

---
 arch/x86/kernel/dumpstack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/dumpstack.c +1 -1
index afbecff161d1..a2d8a3908670 100644
@@ -109,7 +109,7 @@ void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
 	struct stack_info stack_info = {0};
 	unsigned long visit_mask = 0;
 	int graph_idx = 0;
-	bool partial;
+	bool partial = false;
 
 	printk("%sCall Trace:\n", log_lvl);
 
Signature · 1 line
2.9.0
#2 lore raw

PATCH 2/3 x86: fix swsusp_arch_resume prototype

The declaration for swsusp_arch_resume marks it as 'asmlinkage', but the definition in x86-32 does not, and it fails to include the header with the declaration. This leads to a warning when building with link-time-optimizations:

kernel/power/power.h:108:23: error: type of 'swsusp_arch_resume' does not match original declaration [-Werror=lto-type-mismatch]

 extern asmlinkage int swsusp_arch_resume(void);
                       ^

arch/x86/power/hibernate_32.c:148:0: note: 'swsusp_arch_resume' was previously declared here
int swsusp_arch_resume(void)

This moves the declaration into a globally visible header file and fixes up both x86 definitions to match it.

---
 arch/x86/power/hibernate_32.c | 2 +-
 arch/x86/power/hibernate_64.c | 2 +-
 include/linux/suspend.h       | 2 ++
 kernel/power/power.h          | 3 ---
 4 files changed, 4 insertions(+), 5 deletions(-)
arch/x86/power/hibernate_32.c +1 -1
index c35fdb585c68..afc4ed7b1578 100644
@@ -145,7 +145,7 @@ static inline void resume_init_first_level_page_table(pgd_t *pg_dir)
 #endif
 }
 
-int swsusp_arch_resume(void)
+asmlinkage int swsusp_arch_resume(void)
 {
 	int error;
 
arch/x86/power/hibernate_64.c +1 -1
index f910c514438f..0ef5e5204968 100644
@@ -174,7 +174,7 @@ static int relocate_restore_code(void)
 	return 0;
 }
 
-int swsusp_arch_resume(void)
+asmlinkage int swsusp_arch_resume(void)
 {
 	int error;
 
include/linux/suspend.h +2 -0
index cc22a24516d6..440b62f7502e 100644
@@ -384,6 +384,8 @@ extern int swsusp_page_is_forbidden(struct page *);
 extern void swsusp_set_page_free(struct page *);
 extern void swsusp_unset_page_free(struct page *);
 extern unsigned long get_safe_page(gfp_t gfp_mask);
+extern asmlinkage int swsusp_arch_suspend(void);
+extern asmlinkage int swsusp_arch_resume(void);
 
 extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
 extern int hibernate(void);
kernel/power/power.h +0 -3
index f29cd178df90..9e58bdc8a562 100644
@@ -104,9 +104,6 @@ extern int in_suspend;
 extern dev_t swsusp_resume_device;
 extern sector_t swsusp_resume_block;
 
-extern asmlinkage int swsusp_arch_suspend(void);
-extern asmlinkage int swsusp_arch_resume(void);
-
 extern int create_basic_memory_bitmaps(void);
 extern void free_basic_memory_bitmaps(void);
 extern int hibernate_preallocate_memory(void);
Signature · 1 line
2.9.0
#3 lore raw

[tip:x86/urgent] x86/power: Fix swsusp_arch_resume prototype

x86/power: Fix swsusp_arch_resume prototype
Commit-ID:  328008a72d38b5bde6491e463405c34a81a65d3e
Gitweb:     https://git.kernel.org/tip/328008a72d38b5bde6491e463405c34a81a65d3e
Author:     Arnd Bergmann <[email protected]>
AuthorDate: Fri, 2 Feb 2018 15:56:18 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 2 Feb 2018 23:33:50 +0100

x86/power: Fix swsusp_arch_resume prototype

The declaration for swsusp_arch_resume marks it as 'asmlinkage', but the definition in x86-32 does not, and it fails to include the header with the declaration. This leads to a warning when building with link-time-optimizations:

kernel/power/power.h:108:23: error: type of 'swsusp_arch_resume' does not match original declaration [-Werror=lto-type-mismatch]

 extern asmlinkage int swsusp_arch_resume(void);
                       ^

arch/x86/power/hibernate_32.c:148:0: note: 'swsusp_arch_resume' was previously declared here
int swsusp_arch_resume(void)

This moves the declaration into a globally visible header file and fixes up both x86 definitions to match it.

---
 arch/x86/power/hibernate_32.c | 2 +-
 arch/x86/power/hibernate_64.c | 2 +-
 include/linux/suspend.h       | 2 ++
 kernel/power/power.h          | 3 ---
 4 files changed, 4 insertions(+), 5 deletions(-)
arch/x86/power/hibernate_32.c +1 -1
index c35fdb5..afc4ed7 100644
@@ -145,7 +145,7 @@ static inline void resume_init_first_level_page_table(pgd_t *pg_dir)
 #endif
 }
 
-int swsusp_arch_resume(void)
+asmlinkage int swsusp_arch_resume(void)
 {
 	int error;
 
arch/x86/power/hibernate_64.c +1 -1
index f910c51..0ef5e520 100644
@@ -174,7 +174,7 @@ out:
 	return 0;
 }
 
-int swsusp_arch_resume(void)
+asmlinkage int swsusp_arch_resume(void)
 {
 	int error;
 
include/linux/suspend.h +2 -0
index cc22a24..440b62f 100644
@@ -384,6 +384,8 @@ extern int swsusp_page_is_forbidden(struct page *);
 extern void swsusp_set_page_free(struct page *);
 extern void swsusp_unset_page_free(struct page *);
 extern unsigned long get_safe_page(gfp_t gfp_mask);
+extern asmlinkage int swsusp_arch_suspend(void);
+extern asmlinkage int swsusp_arch_resume(void);
 
 extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
 extern int hibernate(void);
kernel/power/power.h +0 -3
index f29cd17..9e58bdc 100644
@@ -104,9 +104,6 @@ extern int in_suspend;
 extern dev_t swsusp_resume_device;
 extern sector_t swsusp_resume_block;
 
-extern asmlinkage int swsusp_arch_suspend(void);
-extern asmlinkage int swsusp_arch_resume(void);
-
 extern int create_basic_memory_bitmaps(void);
 extern void free_basic_memory_bitmaps(void);
 extern int hibernate_preallocate_memory(void);
#4 lore raw

Re: [PATCH 2/3] x86: fix swsusp_arch_resume prototype

In reply to Arnd Bergmann
Quoted 67 lines · CET Arnd Bergmann

The declaration for swsusp_arch_resume marks it as 'asmlinkage', but the definition in x86-32 does not, and it fails to include the header with the declaration. This leads to a warning when building with link-time-optimizations:

kernel/power/power.h:108:23: error: type of 'swsusp_arch_resume' does not match original declaration [-Werror=lto-type-mismatch]

 extern asmlinkage int swsusp_arch_resume(void);
                       ^

arch/x86/power/hibernate_32.c:148:0: note: 'swsusp_arch_resume' was previously declared here
int swsusp_arch_resume(void)

This moves the declaration into a globally visible header file and fixes up both x86 definitions to match it.

---
 arch/x86/power/hibernate_32.c | 2 +-
 arch/x86/power/hibernate_64.c | 2 +-
 include/linux/suspend.h       | 2 ++
 kernel/power/power.h          | 3 ---
 4 files changed, 4 insertions(+), 5 deletions(-)
arch/x86/power/hibernate_32.c +1 -1
index c35fdb585c68..afc4ed7b1578 100644
@@ -145,7 +145,7 @@ static inline void resume_init_first_level_page_table(pgd_t *pg_dir)
 #endif
 }
 
-int swsusp_arch_resume(void)
+asmlinkage int swsusp_arch_resume(void)
 {
 	int error;
 
arch/x86/power/hibernate_64.c +1 -1
index f910c514438f..0ef5e5204968 100644
@@ -174,7 +174,7 @@ static int relocate_restore_code(void)
 	return 0;
 }
 
-int swsusp_arch_resume(void)
+asmlinkage int swsusp_arch_resume(void)
 {
 	int error;
 
include/linux/suspend.h +2 -0
index cc22a24516d6..440b62f7502e 100644
@@ -384,6 +384,8 @@ extern int swsusp_page_is_forbidden(struct page *);
 extern void swsusp_set_page_free(struct page *);
 extern void swsusp_unset_page_free(struct page *);
 extern unsigned long get_safe_page(gfp_t gfp_mask);
+extern asmlinkage int swsusp_arch_suspend(void);
+extern asmlinkage int swsusp_arch_resume(void);
 
 extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
 extern int hibernate(void);
kernel/power/power.h +0 -0
index f29cd178df90..9e58bdc8a562 100644

kernel/power/power.h extern int in_suspend; · line 109

Quoted 9 lines
kernel/power/power.h +0 -3
@@ -104,9 +104,6 @@ extern int in_suspend;
 extern dev_t swsusp_resume_device;
 extern sector_t swsusp_resume_block;
 
-extern asmlinkage int swsusp_arch_suspend(void);
-extern asmlinkage int swsusp_arch_resume(void);
-
 extern int create_basic_memory_bitmaps(void);
 extern void free_basic_memory_bitmaps(void);
 extern int hibernate_preallocate_memory(void);

Applied, thanks!

#5 lore raw

PATCH 3/3 x86: error_inject: make just_return_func globally visible

In reply to Arnd Bergmann

With link time optimizations enabled, I get a link failure:

./ccLbOEHX.ltrans19.ltrans.o: In function `override_function_with_return':
<artificial>:(.text+0x7f3): undefined reference to `just_return_func'

Marking the symbol .globl makes it work as expected.

Fixes 540adea3809f ("error-injection: Separate error-injection from kprobe")
---
 arch/x86/lib/error-inject.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/lib/error-inject.c +1 -0
index 7b881d03d0dd..3cdf06128d13 100644
@@ -7,6 +7,7 @@ asmlinkage void just_return_func(void);
 
 asm(
 	".type just_return_func, @function\n"
+	".globl just_return_func\n"
 	"just_return_func:\n"
 	"	ret\n"
 	".size just_return_func, .-just_return_func\n"
Signature · 1 line
2.9.0
Acked-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] x86: error_inject: make just_return_func globally visible

Quoted 6 lines · On Fri, 2 Feb 2018 15:56:19 +0100 Arnd Bergmann <[email protected]> wrote:

With link time optimizations enabled, I get a link failure:

./ccLbOEHX.ltrans19.ltrans.o: In function `override_function_with_return':
<artificial>:(.text+0x7f3): undefined reference to `just_return_func'

Marking the symbol .globl makes it work as expected.

Good catch!

Thank you!

Quoted 22 lines
Fixes 540adea3809f ("error-injection: Separate error-injection from kprobe")
---
 arch/x86/lib/error-inject.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/lib/error-inject.c +1 -0
index 7b881d03d0dd..3cdf06128d13 100644
@@ -7,6 +7,7 @@ asmlinkage void just_return_func(void);
 
 asm(
 	".type just_return_func, @function\n"
+	".globl just_return_func\n"
 	"just_return_func:\n"
 	"	ret\n"
 	".size just_return_func, .-just_return_func\n"
Signature · 1 line
2.9.0
Signature · 1 line
Masami Hiramatsu <[email protected]>
#7 lore raw

[tip:x86/urgent] x86/error_inject: Make just_return_func() globally visible

In reply to Arnd Bergmann
x86/error_inject: Make just_return_func() globally visible
Commit-ID:  01684e72f16727e6ae0aeb1392f478e11ec5b8f7
Gitweb:     https://git.kernel.org/tip/01684e72f16727e6ae0aeb1392f478e11ec5b8f7
Author:     Arnd Bergmann <[email protected]>
AuthorDate: Fri, 2 Feb 2018 15:56:19 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 13 Feb 2018 14:33:35 +0100

x86/error_inject: Make just_return_func() globally visible

With link time optimizations enabled, I get a link failure:

./ccLbOEHX.ltrans19.ltrans.o: In function `override_function_with_return':
<artificial>:(.text+0x7f3): undefined reference to `just_return_func'

Marking the symbol .globl makes it work as expected.

Cc Alexei Starovoitov <[email protected]>
Cc Josef Bacik <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Nicolas Pitre <[email protected]>
Cc Peter Zijlstra <[email protected]>
Fixes 540adea3809f ("error-injection: Separate error-injection from kprobe")
---
 arch/x86/lib/error-inject.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/lib/error-inject.c +1 -0
index 7b881d0..3cdf061 100644
@@ -7,6 +7,7 @@ asmlinkage void just_return_func(void);
 
 asm(
 	".type just_return_func, @function\n"
+	".globl just_return_func\n"
 	"just_return_func:\n"
 	"	ret\n"
 	".size just_return_func, .-just_return_func\n"
#8 lore raw

[tip:x86/urgent] x86/dumpstack: Avoid uninitlized variable

In reply to Arnd Bergmann
x86/dumpstack: Avoid uninitlized variable
Commit-ID:  ebfc15019cfa72496c674ffcb0b8ef10790dcddc
Gitweb:     https://git.kernel.org/tip/ebfc15019cfa72496c674ffcb0b8ef10790dcddc
Author:     Arnd Bergmann <[email protected]>
AuthorDate: Fri, 2 Feb 2018 15:56:17 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 2 Feb 2018 23:33:50 +0100

x86/dumpstack: Avoid uninitlized variable

In some configurations, 'partial' does not get initialized, as shown by this gcc-8 warning:

arch/x86/kernel/dumpstack.c: In function 'show_trace_log_lvl':
arch/x86/kernel/dumpstack.c:156:4: error: 'partial' may be used uninitialized in this function [-Werror=maybe-uninitialized]

    show_regs_if_on_stack(&stack_info, regs, partial);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This initializes it to false, to get the previous behavior in this case.

Fixes a9cdbe72c4e8 ("x86/dumpstack: Fix partial register dumps")
Cc Andi Kleen <[email protected]>
Cc Nicolas Pitre <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Vlastimil Babka <[email protected]>
---
 arch/x86/kernel/dumpstack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/dumpstack.c +1 -1
index afbecff..a2d8a39 100644
@@ -109,7 +109,7 @@ void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
 	struct stack_info stack_info = {0};
 	unsigned long visit_mask = 0;
 	int graph_idx = 0;
-	bool partial;
+	bool partial = false;
 
 	printk("%sCall Trace:\n", log_lvl);
 
#9 lore raw

Re: [tip:x86/urgent] x86/dumpstack: Avoid uninitlized variable

Quoted 12 lines · tip-bot for Arnd Bergmann
Commit-ID:  ebfc15019cfa72496c674ffcb0b8ef10790dcddc
Gitweb:     https://git.kernel.org/tip/ebfc15019cfa72496c674ffcb0b8ef10790dcddc
Author:     Arnd Bergmann <[email protected]>
AuthorDate: Fri, 2 Feb 2018 15:56:17 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 2 Feb 2018 23:33:50 +0100

x86/dumpstack: Avoid uninitlized variable

In some configurations, 'partial' does not get initialized, as shown by this gcc-8 warning:

Quoted 8 lines

arch/x86/kernel/dumpstack.c: In function 'show_trace_log_lvl':
arch/x86/kernel/dumpstack.c:156:4: error: 'partial' may be used uninitialized in this function [-Werror=maybe-uninitialized]

    show_regs_if_on_stack(&stack_info, regs, partial);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This initializes it to false, to get the previous behavior in this case.

Fixes a9cdbe72c4e8 ("x86/dumpstack: Fix partial register dumps")

I just noticed my annotation got lost when I sent the patch. I originally meant to ask Josh to double-check whether it should be 'false' or 'true' here, or if we maybe need a larger change.

Josh, could you take a look? Unfortunately I did not really understand your original commit, so I don't know what the safe choice is here in those cases in which 'partial' is uninitialized.

Arnd

#10 lore raw

Re: [tip:x86/urgent] x86/dumpstack: Avoid uninitlized variable

Quoted 24 lines · Arnd Bergmann
Quoted 12 lines · tip-bot for Arnd Bergmann
Commit-ID:  ebfc15019cfa72496c674ffcb0b8ef10790dcddc
Gitweb:     https://git.kernel.org/tip/ebfc15019cfa72496c674ffcb0b8ef10790dcddc
Author:     Arnd Bergmann <[email protected]>
AuthorDate: Fri, 2 Feb 2018 15:56:17 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 2 Feb 2018 23:33:50 +0100

x86/dumpstack: Avoid uninitlized variable

In some configurations, 'partial' does not get initialized, as shown by this gcc-8 warning:

Quoted 8 lines

arch/x86/kernel/dumpstack.c: In function 'show_trace_log_lvl':
arch/x86/kernel/dumpstack.c:156:4: error: 'partial' may be used uninitialized in this function [-Werror=maybe-uninitialized]

    show_regs_if_on_stack(&stack_info, regs, partial);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This initializes it to false, to get the previous behavior in this case.

Fixes a9cdbe72c4e8 ("x86/dumpstack: Fix partial register dumps")
Quoted 7 lines

I just noticed my annotation got lost when I sent the patch. I originally meant to ask Josh to double-check whether it should be 'false' or 'true' here, or if we maybe need a larger change.

Josh, could you take a look? Unfortunately I did not really understand your original commit, so I don't know what the safe choice is here in those cases in which 'partial' is uninitialized.

I think it doesn't matter, it seems to be a false positive warning.

The 'partial' variable is only used when 'regs' is non-NULL, and 'regs' is only set in unwind_get_entry_regs() after 'partial' gets initialized.

Signature · 1 line
Josh
#11 lore raw

Re: [tip:x86/urgent] x86/dumpstack: Avoid uninitlized variable

Quoted 29 lines · Josh Poimboeuf
Quoted 28 lines · Arnd Bergmann
Quoted 12 lines · tip-bot for Arnd Bergmann
Commit-ID:  ebfc15019cfa72496c674ffcb0b8ef10790dcddc
Gitweb:     https://git.kernel.org/tip/ebfc15019cfa72496c674ffcb0b8ef10790dcddc
Author:     Arnd Bergmann <[email protected]>
AuthorDate: Fri, 2 Feb 2018 15:56:17 +0100
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Fri, 2 Feb 2018 23:33:50 +0100

x86/dumpstack: Avoid uninitlized variable

In some configurations, 'partial' does not get initialized, as shown by this gcc-8 warning:

Quoted 8 lines

arch/x86/kernel/dumpstack.c: In function 'show_trace_log_lvl':
arch/x86/kernel/dumpstack.c:156:4: error: 'partial' may be used uninitialized in this function [-Werror=maybe-uninitialized]

    show_regs_if_on_stack(&stack_info, regs, partial);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This initializes it to false, to get the previous behavior in this case.

Fixes a9cdbe72c4e8 ("x86/dumpstack: Fix partial register dumps")

I just noticed my annotation got lost when I sent the patch. I originally meant to ask Josh to double-check whether it should be 'false' or 'true' here, or if we maybe need a larger change.

Quoted 8 lines
Quoted 3 lines

Josh, could you take a look? Unfortunately I did not really understand your original commit, so I don't know what the safe choice is here in those cases in which 'partial' is uninitialized.

I think it doesn't matter, it seems to be a false positive warning.

The 'partial' variable is only used when 'regs' is non-NULL, and 'regs' is only set in unwind_get_entry_regs() after 'partial' gets initialized.

Right, got it now. So my patch is correct either way, just the description could have been better.

Arnd

#12 lore raw
In reply to Arnd Bergmann

Quoting Arnd Bergmann (2018-02-02 14:54:28)

Quoted 3 lines

Here are three bugfixes for x86 that I needed to get LTO-enabled kernels to build reliably. I'm not sure abouto that first one though.

Is there a howto on how to build LTO kernels? I tried Andi's lto-415-2 branch, but linking fails with lots of arcane PIE-vs-PIC errors. We are wanting to investigate how we can use LTO to reduce our (i915.ko) module size (by e.g. supporting a subset of chipsets).
-Chris

#13 lore raw
Quoted 9 lines · Chris Wilson

Quoting Arnd Bergmann (2018-02-02 14:54:28)

Quoted 3 lines

Here are three bugfixes for x86 that I needed to get LTO-enabled kernels to build reliably. I'm not sure abouto that first one though.

Is there a howto on how to build LTO kernels? I tried Andi's lto-415-2 branch, but linking fails with lots of arcane PIE-vs-PIC errors. We are wanting to investigate how we can use LTO to reduce our (i915.ko) module size (by e.g. supporting a subset of chipsets).

What are the errors? Kernel shouldn't use PIE or PIC

-Andi