linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] [v2] objtool warning fixes
@ 2023-02-15 13:00 Arnd Bergmann
  2023-02-15 13:00 ` [PATCH 1/3] [v2] kasan: mark addr_has_metadata __always_inline Arnd Bergmann
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Arnd Bergmann @ 2023-02-15 13:00 UTC (permalink / raw)
  To: Andrew Morton, Josh Poimboeuf, Peter Zijlstra
  Cc: Arnd Bergmann, Alexander Potapenko, Andrey Konovalov,
	Andrey Ryabinin, Dmitry Vyukov, Kuan-Ying Lee, Marco Elver,
	Vincenzo Frascino, kasan-dev, linux-mm, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

These are three of the easier fixes for objtool warnings around
kasan/kmsan/kcsan. I dropped one patch since Peter had come up
with a better fix, and adjusted the changelog text based on
feedback.

Link: https://lore.kernel.org/all/20230208164011.2287122-1-arnd@kernel.org/

Arnd Bergmann (3):
  [v2] kasan: mark addr_has_metadata __always_inline
  [v2] kmsan: disable ftrace in kmsan core code
  [v2] objtool: add UACCESS exceptions for __tsan_volatile_read/write

 mm/kasan/kasan.h      | 4 ++--
 mm/kmsan/Makefile     | 8 +++++++-
 tools/objtool/check.c | 2 ++
 3 files changed, 11 insertions(+), 3 deletions(-)

Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
Cc: Marco Elver <elver@google.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: kasan-dev@googlegroups.com
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org

-- 
2.39.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] [v2] kasan: mark addr_has_metadata __always_inline
  2023-02-15 13:00 [PATCH 0/3] [v2] objtool warning fixes Arnd Bergmann
@ 2023-02-15 13:00 ` Arnd Bergmann
  2023-02-15 13:00 ` [PATCH 2/3] [v2] kmsan: disable ftrace in kmsan core code Arnd Bergmann
  2023-02-15 13:00 ` [PATCH 3/3] [v2] objtool: add UACCESS exceptions for __tsan_volatile_read/write Arnd Bergmann
  2 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2023-02-15 13:00 UTC (permalink / raw)
  To: Andrew Morton, Josh Poimboeuf, Peter Zijlstra
  Cc: Arnd Bergmann, Alexander Potapenko, Andrey Konovalov,
	Andrey Ryabinin, Dmitry Vyukov, Kuan-Ying Lee, Marco Elver,
	Vincenzo Frascino, kasan-dev, linux-mm, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

When the compiler decides not to inline this function, objtool
complains about incorrect UACCESS state:

mm/kasan/generic.o: warning: objtool: __asan_load2+0x11: call to addr_has_metadata() with UACCESS enabled

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Marco Elver <elver@google.com>
Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
v2: fix objdump/objtool typo
---
 mm/kasan/kasan.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
index 3231314e071f..9377b0789edc 100644
--- a/mm/kasan/kasan.h
+++ b/mm/kasan/kasan.h
@@ -297,7 +297,7 @@ static inline const void *kasan_shadow_to_mem(const void *shadow_addr)
 		<< KASAN_SHADOW_SCALE_SHIFT);
 }
 
-static inline bool addr_has_metadata(const void *addr)
+static __always_inline bool addr_has_metadata(const void *addr)
 {
 	return (kasan_reset_tag(addr) >=
 		kasan_shadow_to_mem((void *)KASAN_SHADOW_START));
@@ -316,7 +316,7 @@ bool kasan_check_range(unsigned long addr, size_t size, bool write,
 
 #else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */
 
-static inline bool addr_has_metadata(const void *addr)
+static __always_inline bool addr_has_metadata(const void *addr)
 {
 	return (is_vmalloc_addr(addr) || virt_addr_valid(addr));
 }
-- 
2.39.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] [v2] kmsan: disable ftrace in kmsan core code
  2023-02-15 13:00 [PATCH 0/3] [v2] objtool warning fixes Arnd Bergmann
  2023-02-15 13:00 ` [PATCH 1/3] [v2] kasan: mark addr_has_metadata __always_inline Arnd Bergmann
@ 2023-02-15 13:00 ` Arnd Bergmann
  2023-02-15 13:00 ` [PATCH 3/3] [v2] objtool: add UACCESS exceptions for __tsan_volatile_read/write Arnd Bergmann
  2 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2023-02-15 13:00 UTC (permalink / raw)
  To: Andrew Morton, Josh Poimboeuf, Peter Zijlstra
  Cc: Arnd Bergmann, Alexander Potapenko, Andrey Konovalov,
	Andrey Ryabinin, Dmitry Vyukov, Kuan-Ying Lee, Marco Elver,
	Vincenzo Frascino, kasan-dev, linux-mm, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

objtool warns about some suspicous code inside of kmsan:

vmlinux.o: warning: objtool: __msan_metadata_ptr_for_load_n+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: __msan_metadata_ptr_for_store_n+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: __msan_metadata_ptr_for_load_1+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: __msan_metadata_ptr_for_store_1+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: __msan_metadata_ptr_for_load_2+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: __msan_metadata_ptr_for_store_2+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: __msan_metadata_ptr_for_load_4+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: __msan_metadata_ptr_for_store_4+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: __msan_metadata_ptr_for_load_8+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: __msan_metadata_ptr_for_store_8+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: __msan_instrument_asm_store+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: __msan_chain_origin+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: __msan_poison_alloca+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: __msan_warning+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: __msan_get_context_state+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: kmsan_copy_to_user+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: kmsan_unpoison_memory+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: kmsan_unpoison_entry_regs+0x4: call to __fentry__() with UACCESS enabled
vmlinux.o: warning: objtool: kmsan_report+0x4: call to __fentry__() with UACCESS enabled

The Makefile contained a line to turn off ftrace for the entire directory,
but this does not work. Replace it with individual lines, matching the
approach in kasan.

Fixes: f80be4571b19 ("kmsan: add KMSAN runtime core")
Acked-by: Alexander Potapenko <glider@google.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
v2: remove the old "CFLAGS_REMOVE.o = $(CC_FLAGS_FTRACE)" line
---
 mm/kmsan/Makefile | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mm/kmsan/Makefile b/mm/kmsan/Makefile
index 98eab2856626..91cfdde642d1 100644
--- a/mm/kmsan/Makefile
+++ b/mm/kmsan/Makefile
@@ -14,7 +14,13 @@ CC_FLAGS_KMSAN_RUNTIME := -fno-stack-protector
 CC_FLAGS_KMSAN_RUNTIME += $(call cc-option,-fno-conserve-stack)
 CC_FLAGS_KMSAN_RUNTIME += -DDISABLE_BRANCH_PROFILING
 
-CFLAGS_REMOVE.o = $(CC_FLAGS_FTRACE)
+# Disable ftrace to avoid recursion.
+CFLAGS_REMOVE_core.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_hooks.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_init.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_instrumentation.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_shadow.o = $(CC_FLAGS_FTRACE)
 
 CFLAGS_core.o := $(CC_FLAGS_KMSAN_RUNTIME)
 CFLAGS_hooks.o := $(CC_FLAGS_KMSAN_RUNTIME)
-- 
2.39.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] [v2] objtool: add UACCESS exceptions for __tsan_volatile_read/write
  2023-02-15 13:00 [PATCH 0/3] [v2] objtool warning fixes Arnd Bergmann
  2023-02-15 13:00 ` [PATCH 1/3] [v2] kasan: mark addr_has_metadata __always_inline Arnd Bergmann
  2023-02-15 13:00 ` [PATCH 2/3] [v2] kmsan: disable ftrace in kmsan core code Arnd Bergmann
@ 2023-02-15 13:00 ` Arnd Bergmann
  2 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2023-02-15 13:00 UTC (permalink / raw)
  To: Andrew Morton, Josh Poimboeuf, Peter Zijlstra
  Cc: Arnd Bergmann, Alexander Potapenko, Andrey Konovalov,
	Andrey Ryabinin, Dmitry Vyukov, Kuan-Ying Lee, Marco Elver,
	Vincenzo Frascino, kasan-dev, linux-mm, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

A lot of the tsan helpers are already excempt from the UACCESS warnings,
but some more functions were added that need the same thing:

kernel/kcsan/core.o: warning: objtool: __tsan_volatile_read16+0x0: call to __tsan_unaligned_read16() with UACCESS enabled
kernel/kcsan/core.o: warning: objtool: __tsan_volatile_write16+0x0: call to __tsan_unaligned_write16() with UACCESS enabled
vmlinux.o: warning: objtool: __tsan_unaligned_volatile_read16+0x4: call to __tsan_unaligned_read16() with UACCESS enabled
vmlinux.o: warning: objtool: __tsan_unaligned_volatile_write16+0x4: call to __tsan_unaligned_write16() with UACCESS enabled

As Marco points out, these functions don't even call each other
explicitly but instead gcc (but not clang) notices the functions
being identical and turns one symbol into a direct branch to the
other.

Fixes: 75d75b7a4d54 ("kcsan: Support distinguishing volatile accesses")
Acked-by: Marco Elver <elver@google.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 tools/objtool/check.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index b0b467d9608a..da52ce861cc2 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -1237,6 +1237,8 @@ static const char *uaccess_safe_builtin[] = {
 	"__tsan_atomic64_compare_exchange_val",
 	"__tsan_atomic_thread_fence",
 	"__tsan_atomic_signal_fence",
+	"__tsan_unaligned_read16",
+	"__tsan_unaligned_write16",
 	/* KCOV */
 	"write_comp_data",
 	"check_kcov_mode",
-- 
2.39.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-02-15 13:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-15 13:00 [PATCH 0/3] [v2] objtool warning fixes Arnd Bergmann
2023-02-15 13:00 ` [PATCH 1/3] [v2] kasan: mark addr_has_metadata __always_inline Arnd Bergmann
2023-02-15 13:00 ` [PATCH 2/3] [v2] kmsan: disable ftrace in kmsan core code Arnd Bergmann
2023-02-15 13:00 ` [PATCH 3/3] [v2] objtool: add UACCESS exceptions for __tsan_volatile_read/write Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox