Skip to contentSkip to conversation

objtool: Fixes

PATCH Applied Peter Zijlstra 3 participants 13 messages Apr 8, 2022 – Apr 19, 2022

Subsystems (6)
lore
Share & tools
lore

Peter Zijlstra

author maintainer
#0 lore raw

cover objtool: Fixes

Fix various objtool whinges:

lib/strnlen_user.o: warning: objtool: strnlen_user()+0x33: call to do_strnlen_user() with UACCESS enabled lib/strncpy_from_user.o: warning: objtool: strncpy_from_user()+0x33: call to do_strncpy_from_user() with UACCESS enabled

vmlinux.o: warning: objtool: pvh_start_xen()+0x0: unreachable vmlinux.o: warning: objtool: start_secondary()+0x10e: unreachable vmlinux.o: warning: objtool: asm_exc_xen_unknown_trap()+0x16: unreachable instruction

author maintainer
#1 lore raw

PATCH 1/4 lib/strn*,objtool: Enforce user_access_begin() rules

Apparently GCC can fail to inline a 'static inline' single caller function:

lib/strnlen_user.o: warning: objtool: strnlen_user()+0x33: call to do_strnlen_user() with UACCESS enabled lib/strncpy_from_user.o: warning: objtool: strncpy_from_user()+0x33: call to do_strncpy_from_user() with UACCESS enabled

---
 lib/strncpy_from_user.c |    2 +-
 lib/strnlen_user.c      |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
lib/strncpy_from_user.c +1 -1
@@ -25,7 +25,7 @@
  * hit it), 'max' is the address space maximum (and we return
  * -EFAULT if we hit it).
  */
-static inline long do_strncpy_from_user(char *dst, const char __user *src,
+static __always_inline long do_strncpy_from_user(char *dst, const char __user *src,
 					unsigned long count, unsigned long max)
 {
 	const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
lib/strnlen_user.c +1 -1
@@ -20,7 +20,7 @@
  * if it fits in a aligned 'long'. The caller needs to check
  * the return value against "> max".
  */
-static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
+static __always_inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
 {
 	const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
 	unsigned long align, res = 0;
#2 lore raw

Re: [PATCH 1/4] lib/strn*,objtool: Enforce user_access_begin() rules

Quoted 8 lines · Peter Zijlstra

Apparently GCC can fail to inline a 'static inline' single caller function:

lib/strnlen_user.o: warning: objtool: strnlen_user()+0x33: call to do_strnlen_user() with UACCESS enabled lib/strncpy_from_user.o: warning: objtool: strncpy_from_user()+0x33: call to do_strncpy_from_user() with UACCESS enabled

Presumably because of

ifdef CONFIG_DEBUG_SECTION_MISMATCH KBUILD_CFLAGS += -fno-inline-functions-called-once endif

which I've been wanting to remove since its only true purpose seems to be creating countless __always_inline patches...

Signature · 1 line
Josh
merge bot Applied
#3 lore raw

[tip: x86/urgent] lib/strn*,objtool: Enforce user_access_begin() rules

In reply to Peter Zijlstra
The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     226d44acf6dfe71c9df5804b82364e93cf908b53
Gitweb:        https://git.kernel.org/tip/226d44acf6dfe71c9df5804b82364e93cf908b53
Author:        Peter Zijlstra <[email protected]>
AuthorDate:    Fri, 08 Apr 2022 11:45:53 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Tue, 19 Apr 2022 21:58:47 +02:00

lib/strn*,objtool: Enforce user_access_begin() rules

Apparently GCC can fail to inline a 'static inline' single caller function:

lib/strnlen_user.o: warning: objtool: strnlen_user()+0x33: call to do_strnlen_user() with UACCESS enabled lib/strncpy_from_user.o: warning: objtool: strncpy_from_user()+0x33: call to do_strncpy_from_user() with UACCESS enabled

---
 lib/strncpy_from_user.c | 2 +-
 lib/strnlen_user.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
lib/strncpy_from_user.c +1 -1
index 08fc72d..6432b8c 100644
@@ -25,7 +25,7 @@
  * hit it), 'max' is the address space maximum (and we return
  * -EFAULT if we hit it).
  */
-static inline long do_strncpy_from_user(char *dst, const char __user *src,
+static __always_inline long do_strncpy_from_user(char *dst, const char __user *src,
 					unsigned long count, unsigned long max)
 {
 	const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
lib/strnlen_user.c +1 -1
index bffa0eb..feeb935 100644
@@ -20,7 +20,7 @@
  * if it fits in a aligned 'long'. The caller needs to check
  * the return value against "> max".
  */
-static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
+static __always_inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
 {
 	const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
 	unsigned long align, res = 0;
author maintainer
#4 lore raw

PATCH 2/4 x86,xen,objtool: Add UNWIND hint

In reply to Peter Zijlstra

SYM_CODE_START*() doesn't get auto-validated and needs an UNWIND hint to get checked, add one.

vmlinux.o: warning: objtool: pvh_start_xen()+0x0: unreachable

---
 arch/x86/platform/pvh/head.S |    1 +
 1 file changed, 1 insertion(+)
arch/x86/platform/pvh/head.S +1 -0
@@ -50,6 +50,7 @@
 #define PVH_DS_SEL		(PVH_GDT_ENTRY_DS * 8)
 
 SYM_CODE_START_LOCAL(pvh_start_xen)
+	UNWIND_HINT_EMPTY
 	cld
 
 	lgdt (_pa(gdt))
merge bot Applied
#5 lore raw

[tip: x86/urgent] x86,xen,objtool: Add UNWIND hint

The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     2730d3c14a85617c177337f2e2af2108bf82c4ca
Gitweb:        https://git.kernel.org/tip/2730d3c14a85617c177337f2e2af2108bf82c4ca
Author:        Peter Zijlstra <[email protected]>
AuthorDate:    Fri, 08 Apr 2022 11:45:54 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Tue, 19 Apr 2022 21:58:47 +02:00

x86,xen,objtool: Add UNWIND hint

SYM_CODE_START*() doesn't get auto-validated and needs an UNWIND hint to get checked, add one.

vmlinux.o: warning: objtool: pvh_start_xen()+0x0: unreachable

---
 arch/x86/platform/pvh/head.S | 1 +
 1 file changed, 1 insertion(+)
arch/x86/platform/pvh/head.S +1 -0
index 72c1e42..7fe564e 100644
@@ -50,6 +50,7 @@
 #define PVH_DS_SEL		(PVH_GDT_ENTRY_DS * 8)
 
 SYM_CODE_START_LOCAL(pvh_start_xen)
+	UNWIND_HINT_EMPTY
 	cld
 
 	lgdt (_pa(gdt))
author maintainer
#6 lore raw

PATCH 3/4 x86,objtool: Mark cpu_startup_entry() __noreturn

In reply to Peter Zijlstra

GCC-8 isn't clever enough to figure out that cpu_start_entry() is a noreturn while objtool is. This results in code after the call in start_secondary(). Give GCC a hand so that they all agree on things.

vmlinux.o: warning: objtool: start_secondary()+0x10e: unreachable

---
 include/linux/cpu.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/cpu.h +1 -1
@@ -167,7 +167,7 @@ static inline int suspend_disable_second
 static inline void suspend_enable_secondary_cpus(void) { }
 #endif /* !CONFIG_PM_SLEEP_SMP */
 
-void cpu_startup_entry(enum cpuhp_state state);
+void __noreturn cpu_startup_entry(enum cpuhp_state state);
 
 void cpu_idle_poll_ctrl(bool enable);
 
#7 lore raw

Re: [PATCH 3/4] x86,objtool: Mark cpu_startup_entry() __noreturn

Quoted 15 lines · Peter Zijlstra

GCC-8 isn't clever enough to figure out that cpu_start_entry() is a noreturn while objtool is. This results in code after the call in start_secondary(). Give GCC a hand so that they all agree on things.

vmlinux.o: warning: objtool: start_secondary()+0x10e: unreachable

---
 include/linux/cpu.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

include/linux/cpu.h static inline int suspend_disable_second · line 172

Quoted 7 lines
include/linux/cpu.h +1 -1
@@ -167,7 +167,7 @@ static inline int suspend_disable_second
 static inline void suspend_enable_secondary_cpus(void) { }
 #endif /* !CONFIG_PM_SLEEP_SMP */
 
-void cpu_startup_entry(enum cpuhp_state state);
+void __noreturn cpu_startup_entry(enum cpuhp_state state);
 
 void cpu_idle_poll_ctrl(bool enable);

I just ran into this:

init/main.o: warning: objtool: rest_init() falls through to next function kernel_init()

so we need this as well:

tools/objtool/check.c +1 -0
index 565fec451d69..fab2235599a0 100644
@@ -184,6 +184,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
                "do_group_exit",
                "stop_this_cpu",
                "__invalid_creds",
+               "cpu_startup_entry",
        };
 
        if (!func)
#8 lore raw

Re: [PATCH 3/4] x86,objtool: Mark cpu_startup_entry() __noreturn

In reply to Peter Zijlstra
Quoted 15 lines · Peter Zijlstra

GCC-8 isn't clever enough to figure out that cpu_start_entry() is a noreturn while objtool is. This results in code after the call in start_secondary(). Give GCC a hand so that they all agree on things.

vmlinux.o: warning: objtool: start_secondary()+0x10e: unreachable

---
 include/linux/cpu.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

include/linux/cpu.h static inline int suspend_disable_second · line 172

Quoted 7 lines
include/linux/cpu.h +1 -1
@@ -167,7 +167,7 @@ static inline int suspend_disable_second
 static inline void suspend_enable_secondary_cpus(void) { }
 #endif /* !CONFIG_PM_SLEEP_SMP */
 
-void cpu_startup_entry(enum cpuhp_state state);
+void __noreturn cpu_startup_entry(enum cpuhp_state state);
 
 void cpu_idle_poll_ctrl(bool enable);

Also needs added to the objtool noreturn list.

Signature · 1 line
Josh
merge bot Applied
#9 lore raw

[tip: x86/urgent] x86,objtool: Mark cpu_startup_entry() __noreturn

In reply to Peter Zijlstra
The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     d4e5268a08b211b536fed29beb24271ecd85187e
Gitweb:        https://git.kernel.org/tip/d4e5268a08b211b536fed29beb24271ecd85187e
Author:        Peter Zijlstra <[email protected]>
AuthorDate:    Fri, 08 Apr 2022 11:45:55 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Tue, 19 Apr 2022 21:58:48 +02:00

x86,objtool: Mark cpu_startup_entry() __noreturn

GCC-8 isn't clever enough to figure out that cpu_start_entry() is a noreturn while objtool is. This results in code after the call in start_secondary(). Give GCC a hand so that they all agree on things.

vmlinux.o: warning: objtool: start_secondary()+0x10e: unreachable

---
 include/linux/cpu.h   | 2 +-
 tools/objtool/check.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
include/linux/cpu.h +1 -1
index 9cf51e4..54dc2f9 100644
@@ -167,7 +167,7 @@ static inline int suspend_disable_secondary_cpus(void) { return 0; }
 static inline void suspend_enable_secondary_cpus(void) { }
 #endif /* !CONFIG_PM_SLEEP_SMP */
 
-void cpu_startup_entry(enum cpuhp_state state);
+void __noreturn cpu_startup_entry(enum cpuhp_state state);
 
 void cpu_idle_poll_ctrl(bool enable);
 
tools/objtool/check.c +1 -0
index bd0c2c8..e3a675d 100644
@@ -184,6 +184,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
 		"do_group_exit",
 		"stop_this_cpu",
 		"__invalid_creds",
+               "cpu_startup_entry",
 	};
 
 	if (!func)
author maintainer
#10 lore raw

PATCH 4/4 x86,objtool: Explicitly mark idtentry_body()s tail REACHABLE

In reply to Peter Zijlstra

Objtool can figure out that some \cfunc()s are noreturn and then complains about certain instances having unreachable tails:

vmlinux.o: warning: objtool: asm_exc_xen_unknown_trap()+0x16: unreachable instruction

---
 arch/x86/entry/entry_64.S |    3 +++
 1 file changed, 3 insertions(+)
arch/x86/entry/entry_64.S +3 -0
@@ -337,6 +337,9 @@ SYM_CODE_END(ret_from_fork)
 
 	call	\cfunc
 
+	/* For some configurations \cfunc ends up being a noreturn. */
+	REACHABLE
+
 	jmp	error_return
 .endm
 
merge bot Applied
#11 lore raw

[tip: x86/urgent] x86,objtool: Explicitly mark idtentry_body()s tail REACHABLE

The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     d66e9d50ea5cd76b2c4875c758efad665283d7ad
Gitweb:        https://git.kernel.org/tip/d66e9d50ea5cd76b2c4875c758efad665283d7ad
Author:        Peter Zijlstra <[email protected]>
AuthorDate:    Fri, 08 Apr 2022 11:45:56 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Tue, 19 Apr 2022 21:58:48 +02:00

x86,objtool: Explicitly mark idtentry_body()s tail REACHABLE

Objtool can figure out that some \cfunc()s are noreturn and then complains about certain instances having unreachable tails:

vmlinux.o: warning: objtool: asm_exc_xen_unknown_trap()+0x16: unreachable instruction

---
 arch/x86/entry/entry_64.S | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/entry/entry_64.S +3 -0
index 4faac48..73d9585 100644
@@ -337,6 +337,9 @@ SYM_CODE_END(ret_from_fork)
 
 	call	\cfunc
 
+	/* For some configurations \cfunc ends up being a noreturn. */
+	REACHABLE
+
 	jmp	error_return
 .endm
 
Acked-by on the v1 series
#12 lore raw
In reply to Peter Zijlstra
Quoted 8 lines · Peter Zijlstra

Fix various objtool whinges:

lib/strnlen_user.o: warning: objtool: strnlen_user()+0x33: call to do_strnlen_user() with UACCESS enabled lib/strncpy_from_user.o: warning: objtool: strncpy_from_user()+0x33: call to do_strncpy_from_user() with UACCESS enabled

vmlinux.o: warning: objtool: pvh_start_xen()+0x0: unreachable vmlinux.o: warning: objtool: start_secondary()+0x10e: unreachable vmlinux.o: warning: objtool: asm_exc_xen_unknown_trap()+0x16: unreachable instruction

Signature · 1 line
Josh