Skip to contentSkip to conversation

x86: Address various objtool complaints

PATCH Applied Peter Zijlstra 5 participants 13 messages May 2, 2022 – May 30, 2022

Subsystems (3)
lore
Share & tools
lore

Peter Zijlstra

author maintainer
#0 lore raw

cover x86: Address various objtool complaints

Courtesy of 0-day:

fs/ntfs3/ntfs3.prelink.o: warning: objtool: ni_read_frame() falls through to next function ni_readpage_cmpr.cold()

vmlinux.o: warning: objtool: enter_from_user_mode+0x24: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_enter_from_user_mode+0x28: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_enter_from_user_mode_prepare+0x24: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: irqentry_enter_from_user_mode+0x24: call to __kcsan_check_access() leaves .noinstr.text section

vmlinux.o: warning: objtool: exit_to_user_mode+0x14: call to static_key_count.constprop.0() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_exit_to_user_mode+0x2d: call to static_key_count.constprop.0() leaves .noinstr.text section vmlinux.o: warning: objtool: irqentry_exit_to_user_mode+0x1b: call to static_key_count.constprop.0() leaves .noinstr.text section

author maintainer
#1 lore raw

PATCH 1/3 objtool: Mark __ubsan_handle_builtin_unreachable() as noreturn

fs/ntfs3/ntfs3.prelink.o: warning: objtool: ni_read_frame() falls through to next function ni_readpage_cmpr.cold()

That is in fact:

000000000000124a <ni_read_frame.cold>:

    124a:       44 89 e0                mov    %r12d,%eax
    124d:       0f b6 55 98             movzbl -0x68(%rbp),%edx
    1251:       48 c7 c7 00 00 00 00    mov    $0x0,%rdi        1254: R_X86_64_32S      .data+0x1380
    1258:       48 89 c6                mov    %rax,%rsi
    125b:       e8 00 00 00 00          call   1260 <ni_read_frame.cold+0x16>   125c: R_X86_64_PLT32    __ubsan_handle_shift_out_of_bounds-0x4
    1260:       48 8d 7d cc             lea    -0x34(%rbp),%rdi
    1264:       e8 00 00 00 00          call   1269 <ni_read_frame.cold+0x1f>   1265: R_X86_64_PLT32    __tsan_read4-0x4
    1269:       8b 45 cc                mov    -0x34(%rbp),%eax
    126c:       e9 00 00 00 00          jmp    1271 <ni_read_frame.cold+0x27>   126d: R_X86_64_PC32     .text+0x19109
    1271:       48 8b 75 a0             mov    -0x60(%rbp),%rsi
    1275:       48 63 d0                movslq %eax,%rdx
    1278:       48 c7 c7 00 00 00 00    mov    $0x0,%rdi        127b: R_X86_64_32S      .data+0x13a0
    127f:       89 45 88                mov    %eax,-0x78(%rbp)
    1282:       e8 00 00 00 00          call   1287 <ni_read_frame.cold+0x3d>   1283: R_X86_64_PLT32    __ubsan_handle_shift_out_of_bounds-0x4
    1287:       8b 45 88                mov    -0x78(%rbp),%eax
    128a:       e9 00 00 00 00          jmp    128f <ni_read_frame.cold+0x45>   128b: R_X86_64_PC32     .text+0x19098
    128f:       48 c7 c7 00 00 00 00    mov    $0x0,%rdi        1292: R_X86_64_32S      .data+0x11f0
    1296:       e8 00 00 00 00          call   129b <ni_readpage_cmpr.cold>     1297: R_X86_64_PLT32    __ubsan_handle_builtin_unreachable-0x4

000000000000129b <ni_readpage_cmpr.cold>:

Tell objtool that __ubsan_handle_builtin_unreachable() is a noreturn.

---
 tools/objtool/check.c |    1 +
 1 file changed, 1 insertion(+)
tools/objtool/check.c +1 -0
@@ -184,6 +184,7 @@ static bool __dead_end_function(struct o
 		"do_group_exit",
 		"stop_this_cpu",
 		"__invalid_creds",
+	       "__ubsan_handle_builtin_unreachable",
 	};
 
 	if (!func)
author maintainer
#2 lore raw

PATCH 2/3 x86/cpu: Elide KCSAN for cpu_has() and friends

In reply to Peter Zijlstra

vmlinux.o: warning: objtool: enter_from_user_mode+0x24: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_enter_from_user_mode+0x28: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_enter_from_user_mode_prepare+0x24: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: irqentry_enter_from_user_mode+0x24: call to __kcsan_check_access() leaves .noinstr.text section

---
 arch/x86/include/asm/cpufeature.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/cpufeature.h +1 -1
@@ -51,7 +51,7 @@ extern const char * const x86_power_flag
 extern const char * const x86_bug_flags[NBUGINTS*32];
 
 #define test_cpu_cap(c, bit)						\
-	 test_bit(bit, (unsigned long *)((c)->x86_capability))
+	 arch_test_bit(bit, (unsigned long *)((c)->x86_capability))
 
 /*
  * There are 32 bits/features in each mask word.  The high bits
Reviewed-by on v1 2/3
#3 lore raw

Re: [PATCH 2/3] x86/cpu: Elide KCSAN for cpu_has() and friends

Quoted 7 lines · Peter Zijlstra

vmlinux.o: warning: objtool: enter_from_user_mode+0x24: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_enter_from_user_mode+0x28: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_enter_from_user_mode_prepare+0x24: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: irqentry_enter_from_user_mode+0x24: call to __kcsan_check_access() leaves .noinstr.text section

And should fix the same issue for other sanitizers that get instrumented test_bit() via asm-generic/bitops/instrumented-*.h, not just KCSAN.

Quoted 17 lines
---
 arch/x86/include/asm/cpufeature.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/cpufeature.h +1 -1
@@ -51,7 +51,7 @@ extern const char * const x86_power_flag
 extern const char * const x86_bug_flags[NBUGINTS*32];
 
 #define test_cpu_cap(c, bit)						\
-	 test_bit(bit, (unsigned long *)((c)->x86_capability))
+	 arch_test_bit(bit, (unsigned long *)((c)->x86_capability))
 
 /*
  * There are 32 bits/features in each mask word.  The high bits
#4 lore raw

Re: [PATCH 2/3] x86/cpu: Elide KCSAN for cpu_has() and friends

In reply to Peter Zijlstra
Quoted 7 lines · Peter Zijlstra

vmlinux.o: warning: objtool: enter_from_user_mode+0x24: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_enter_from_user_mode+0x28: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_enter_from_user_mode_prepare+0x24: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: irqentry_enter_from_user_mode+0x24: call to __kcsan_check_access() leaves .noinstr.text section

An explanation about *why* this fixes it would help, as I have no idea from looking at the patch.

Quoted 17 lines
---
 arch/x86/include/asm/cpufeature.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/cpufeature.h +1 -1
@@ -51,7 +51,7 @@ extern const char * const x86_power_flag
 extern const char * const x86_bug_flags[NBUGINTS*32];
 
 #define test_cpu_cap(c, bit)						\
-	 test_bit(bit, (unsigned long *)((c)->x86_capability))
+	 arch_test_bit(bit, (unsigned long *)((c)->x86_capability))
 
 /*
  * There are 32 bits/features in each mask word.  The high bits
Signature · 1 line
Josh
#5 lore raw

Re: [PATCH 2/3] x86/cpu: Elide KCSAN for cpu_has() and friends

Quoted 11 lines · Josh Poimboeuf
Quoted 7 lines · Peter Zijlstra

vmlinux.o: warning: objtool: enter_from_user_mode+0x24: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_enter_from_user_mode+0x28: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_enter_from_user_mode_prepare+0x24: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: irqentry_enter_from_user_mode+0x24: call to __kcsan_check_access() leaves .noinstr.text section

An explanation about *why* this fixes it would help, as I have no idea from looking at the patch.

How about something like:

| As x86 uses the <asm-generic/bitops/instrumented-*.h> headers, the
| regular forms of all bitops are instrumented with explicit calls to
| KASAN and KCSAN checks. As these are explicit calls, these are not
| suppressed by the noinstr function attribute.
|
| This can result in calls to those check functions in noinstr code, which
| objtool warns about:
|
| vmlinux.o: warning: objtool: enter_from_user_mode+0x24: call to __kcsan_check_access() leaves .noinstr.text section
| vmlinux.o: warning: objtool: syscall_enter_from_user_mode+0x28: call to __kcsan_check_access() leaves .noinstr.text section
| vmlinux.o: warning: objtool: syscall_enter_from_user_mode_prepare+0x24: call to __kcsan_check_access() leaves .noinstr.text section
| vmlinux.o: warning: objtool: irqentry_enter_from_user_mode+0x24: call to __kcsan_check_access() leaves .noinstr.text section
|
| Prevent this by using the arch_*() bitops, which are the underlying
| bitops without explciit instrumentation.

Thanks,
Mark.

Quoted 22 lines
Quoted 18 lines
---
 arch/x86/include/asm/cpufeature.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/cpufeature.h +1 -1
@@ -51,7 +51,7 @@ extern const char * const x86_power_flag
 extern const char * const x86_bug_flags[NBUGINTS*32];
 
 #define test_cpu_cap(c, bit)						\
-	 test_bit(bit, (unsigned long *)((c)->x86_capability))
+	 arch_test_bit(bit, (unsigned long *)((c)->x86_capability))
 
 /*
  * There are 32 bits/features in each mask word.  The high bits
Signature · 1 line
Josh
merge bot Applied
#6 lore raw

[tip: objtool/urgent] x86/cpu: Elide KCSAN for cpu_has() and friends

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

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

Commit-ID:     a6a5eb269f6f3a2fe392f725a8d9052190c731e2
Gitweb:        https://git.kernel.org/tip/a6a5eb269f6f3a2fe392f725a8d9052190c731e2
Author:        Peter Zijlstra <[email protected]>
AuthorDate:    Mon, 02 May 2022 12:15:23 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Fri, 27 May 2022 12:34:43 +02:00

x86/cpu: Elide KCSAN for cpu_has() and friends

As x86 uses the <asm-generic/bitops/instrumented-*.h> headers, the regular forms of all bitops are instrumented with explicit calls to KASAN and KCSAN checks. As these are explicit calls, these are not suppressed by the noinstr function attribute.

This can result in calls to those check functions in noinstr code, which objtool warns about:

vmlinux.o: warning: objtool: enter_from_user_mode+0x24: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_enter_from_user_mode+0x28: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_enter_from_user_mode_prepare+0x24: call to __kcsan_check_access() leaves .noinstr.text section vmlinux.o: warning: objtool: irqentry_enter_from_user_mode+0x24: call to __kcsan_check_access() leaves .noinstr.text section

Prevent this by using the arch_*() bitops, which are the underlying bitops without explciit instrumentation.

---
 arch/x86/include/asm/cpufeature.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/include/asm/cpufeature.h +1 -1
index 66d3e3b..ea34cc3 100644
@@ -54,7 +54,7 @@ extern const char * const x86_power_flags[32];
 extern const char * const x86_bug_flags[NBUGINTS*32];
 
 #define test_cpu_cap(c, bit)						\
-	 test_bit(bit, (unsigned long *)((c)->x86_capability))
+	 arch_test_bit(bit, (unsigned long *)((c)->x86_capability))
 
 /*
  * There are 32 bits/features in each mask word.  The high bits
author maintainer
#7 lore raw

PATCH 3/3 jump_label,noinstr: Avoid instrumentation for JUMP_LABEL=n builds

In reply to Peter Zijlstra

When building x86_64 with JUMP_LABEL=n it's possible for instrumentation to sneak into noinstr:

vmlinux.o: warning: objtool: exit_to_user_mode+0x14: call to static_key_count.constprop.0() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_exit_to_user_mode+0x2d: call to static_key_count.constprop.0() leaves .noinstr.text section vmlinux.o: warning: objtool: irqentry_exit_to_user_mode+0x1b: call to static_key_count.constprop.0() leaves .noinstr.text section

---
 include/linux/jump_label.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/jump_label.h +2 -2
@@ -256,9 +256,9 @@ extern void static_key_disable_cpuslocke
 #include <linux/atomic.h>
 #include <linux/bug.h>
 
-static inline int static_key_count(struct static_key *key)
+static __always_inline int static_key_count(struct static_key *key)
 {
-	return atomic_read(&key->enabled);
+	return READ_ONCE_NOCHECK(&key->enabled.count);
 }
 
 static __always_inline void jump_label_init(void)
#8 lore raw

Re: [PATCH 3/3] jump_label,noinstr: Avoid instrumentation for JUMP_LABEL=n builds

Quoted 17 lines · Peter Zijlstra

When building x86_64 with JUMP_LABEL=n it's possible for instrumentation to sneak into noinstr:

vmlinux.o: warning: objtool: exit_to_user_mode+0x14: call to static_key_count.constprop.0() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_exit_to_user_mode+0x2d: call to static_key_count.constprop.0() leaves .noinstr.text section vmlinux.o: warning: objtool: irqentry_exit_to_user_mode+0x1b: call to static_key_count.constprop.0() leaves .noinstr.text section

---
 include/linux/jump_label.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

include/linux/jump_label.h extern void static_key_disable_cpuslocke · line 262

Quoted 9 lines
include/linux/jump_label.h +2 -2
@@ -256,9 +256,9 @@ extern void static_key_disable_cpuslocke
 #include <linux/atomic.h>
 #include <linux/bug.h>
 
-static inline int static_key_count(struct static_key *key)
+static __always_inline int static_key_count(struct static_key *key)
 {
-       return atomic_read(&key->enabled);
+       return READ_ONCE_NOCHECK(&key->enabled.count);
 }

Did arch_atomic_read() not work? Or should this also be unchecked in instrumented functions?

author maintainer
#9 lore raw

Re: [PATCH 3/3] jump_label,noinstr: Avoid instrumentation for JUMP_LABEL=n builds

Quoted 21 lines · Marco Elver
Quoted 20 lines · Peter Zijlstra

When building x86_64 with JUMP_LABEL=n it's possible for instrumentation to sneak into noinstr:

vmlinux.o: warning: objtool: exit_to_user_mode+0x14: call to static_key_count.constprop.0() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_exit_to_user_mode+0x2d: call to static_key_count.constprop.0() leaves .noinstr.text section vmlinux.o: warning: objtool: irqentry_exit_to_user_mode+0x1b: call to static_key_count.constprop.0() leaves .noinstr.text section

---
 include/linux/jump_label.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/jump_label.h +0 -0
@@ -256,9 +256,9 @@ extern void static_key_disable_cpuslocke
 #include <linux/atomic.h>
 #include <linux/bug.h>
 
Quoted 9 lines

include/linux/jump_label.h extern void static_key_disable_cpuslocke · line 262

Quoted 6 lines
include/linux/jump_label.h +2 -2
-static inline int static_key_count(struct static_key *key)
+static __always_inline int static_key_count(struct static_key *key)
 {
-       return atomic_read(&key->enabled);
+       return READ_ONCE_NOCHECK(&key->enabled.count);
 }

Did arch_atomic_read() not work? Or should this also be unchecked in instrumented functions?

Urgh, also I think the above is broken for me forgetting to remove the &.

I think arch_atomic_read() should work, lemme try.

author maintainer
#10 lore raw

PATCH v2 3/3 jump_label,noinstr: Avoid instrumentation for JUMP_LABEL=n builds

In reply to Peter Zijlstra

Subject: jump_label,noinstr: Avoid instrumentation for JUMP_LABEL=n builds
From: Peter Zijlstra <[email protected]>
Date: Mon May 2 12:30:20 CEST 2022

When building x86_64 with JUMP_LABEL=n it's possible for instrumentation to sneak into noinstr:

vmlinux.o: warning: objtool: exit_to_user_mode+0x14: call to static_key_count.constprop.0() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_exit_to_user_mode+0x2d: call to static_key_count.constprop.0() leaves .noinstr.text section vmlinux.o: warning: objtool: irqentry_exit_to_user_mode+0x1b: call to static_key_count.constprop.0() leaves .noinstr.text section

---
 include/linux/jump_label.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/jump_label.h +2 -2
@@ -256,9 +256,9 @@ extern void static_key_disable_cpuslocke
 #include <linux/atomic.h>
 #include <linux/bug.h>
 
-static inline int static_key_count(struct static_key *key)
+static __always_inline int static_key_count(struct static_key *key)
 {
-	return atomic_read(&key->enabled);
+	return arch_atomic_read(&key->enabled.count);
 }
 
 static __always_inline void jump_label_init(void)
#11 lore raw

Re: [PATCH v2 3/3] jump_label,noinstr: Avoid instrumentation for JUMP_LABEL=n builds

Quoted 21 lines · Peter Zijlstra

Subject: jump_label,noinstr: Avoid instrumentation for JUMP_LABEL=n builds
From: Peter Zijlstra <[email protected]>
Date: Mon May 2 12:30:20 CEST 2022

When building x86_64 with JUMP_LABEL=n it's possible for instrumentation to sneak into noinstr:

vmlinux.o: warning: objtool: exit_to_user_mode+0x14: call to static_key_count.constprop.0() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_exit_to_user_mode+0x2d: call to static_key_count.constprop.0() leaves .noinstr.text section vmlinux.o: warning: objtool: irqentry_exit_to_user_mode+0x1b: call to static_key_count.constprop.0() leaves .noinstr.text section

---
 include/linux/jump_label.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

include/linux/jump_label.h extern void static_key_disable_cpuslocke · line 261

Quoted 8 lines
include/linux/jump_label.h +2 -2
@@ -256,9 +256,9 @@ extern void static_key_disable_cpuslocke
 #include <linux/atomic.h>
 #include <linux/bug.h>
 
-static inline int static_key_count(struct static_key *key)
+static __always_inline int static_key_count(struct static_key *key)
 {
-	return atomic_read(&key->enabled);
+	return arch_atomic_read(&key->enabled.count);

Curious if this compiles - s/.count// ?

Quoted 3 lines
include/linux/jump_label.h +0 -0
 }
 
 static __always_inline void jump_label_init(void)
author maintainer
#12 lore raw

Re: [PATCH v2 3/3] jump_label,noinstr: Avoid instrumentation for JUMP_LABEL=n builds

Quoted 25 lines · Marco Elver
Quoted 24 lines · Peter Zijlstra

Subject: jump_label,noinstr: Avoid instrumentation for JUMP_LABEL=n builds
From: Peter Zijlstra <[email protected]>
Date: Mon May 2 12:30:20 CEST 2022

When building x86_64 with JUMP_LABEL=n it's possible for instrumentation to sneak into noinstr:

vmlinux.o: warning: objtool: exit_to_user_mode+0x14: call to static_key_count.constprop.0() leaves .noinstr.text section vmlinux.o: warning: objtool: syscall_exit_to_user_mode+0x2d: call to static_key_count.constprop.0() leaves .noinstr.text section vmlinux.o: warning: objtool: irqentry_exit_to_user_mode+0x1b: call to static_key_count.constprop.0() leaves .noinstr.text section

---
 include/linux/jump_label.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/jump_label.h +0 -0
@@ -256,9 +256,9 @@ extern void static_key_disable_cpuslocke
 #include <linux/atomic.h>
 #include <linux/bug.h>
 
Quoted 7 lines

include/linux/jump_label.h extern void static_key_disable_cpuslocke · line 261

Quoted 5 lines
include/linux/jump_label.h +2 -2
-static inline int static_key_count(struct static_key *key)
+static __always_inline int static_key_count(struct static_key *key)
 {
-	return atomic_read(&key->enabled);
+	return arch_atomic_read(&key->enabled.count);

Curious if this compiles - s/.count// ?

It does if you have JUMP_LABEL=y... (-:

*sigh*... how I about I go back to mowing the lawn and try again later...