All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kcov: add __no_sanitize_coverage to fix noinstr for all architectures
@ 2021-05-25 17:58 Marco Elver
  2021-05-25 18:25 ` Miguel Ojeda
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Marco Elver @ 2021-05-25 17:58 UTC (permalink / raw)
  To: elver
  Cc: linux-kernel, nathan, ndesaulniers, ojeda, keescook, akpm, will,
	ardb, luc.vanoostenryck, nivedita, masahiroy, peterz,
	samitolvanen, arnd, clang-built-linux, Dmitry Vyukov,
	Mark Rutland

Until now no compiler supported an attribute to disable coverage
instrumentation as used by KCOV.

To work around this limitation on x86, noinstr functions have their
coverage instrumentation turned into nops by objtool. However, this
solution doesn't scale automatically to other architectures, such as
arm64, which are migrating to use the generic entry code.

Clang [1] and GCC [2] have added support for the attribute recently.
[1] https://github.com/llvm/llvm-project/commit/280333021e9550d80f5c1152a34e33e81df1e178
[2] https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=cec4d4a6782c9bd8d071839c50a239c49caca689

Add __no_sanitize_coverage for both compilers, and add it to noinstr.

Signed-off-by: Marco Elver <elver@google.com>
---
 include/linux/compiler-clang.h | 6 ++++++
 include/linux/compiler-gcc.h   | 6 ++++++
 include/linux/compiler_types.h | 2 +-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
index adbe76b203e2..370565f4cfde 100644
--- a/include/linux/compiler-clang.h
+++ b/include/linux/compiler-clang.h
@@ -45,6 +45,12 @@
 #define __no_sanitize_undefined
 #endif
 
+#if defined(CONFIG_KCOV) && CONFIG_CLANG_VERSION >= 130000
+#define __no_sanitize_coverage __attribute__((no_sanitize("coverage")))
+#else
+#define __no_sanitize_coverage
+#endif
+
 /*
  * Not all versions of clang implement the type-generic versions
  * of the builtin overflow checkers. Fortunately, clang implements
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 5d97ef738a57..cb9217fc60af 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -122,6 +122,12 @@
 #define __no_sanitize_undefined
 #endif
 
+#if defined(CONFIG_KCOV) && __has_attribute(__no_sanitize_coverage__)
+#define __no_sanitize_coverage __attribute__((no_sanitize_coverage))
+#else
+#define __no_sanitize_coverage
+#endif
+
 #if GCC_VERSION >= 50100
 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
 #endif
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index d29bda7f6ebd..cc2bee7f0977 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -210,7 +210,7 @@ struct ftrace_likely_data {
 /* Section for code which can't be instrumented at all */
 #define noinstr								\
 	noinline notrace __attribute((__section__(".noinstr.text")))	\
-	__no_kcsan __no_sanitize_address
+	__no_kcsan __no_sanitize_address __no_sanitize_coverage
 
 #endif /* __KERNEL__ */
 
-- 
2.31.1.818.g46aad6cb9e-goog


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

end of thread, other threads:[~2021-05-26 18:13 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-25 17:58 [PATCH] kcov: add __no_sanitize_coverage to fix noinstr for all architectures Marco Elver
2021-05-25 18:25 ` Miguel Ojeda
2021-05-25 19:12   ` Marco Elver
2021-05-26  1:53     ` Miguel Ojeda
2021-05-26  6:25       ` Marco Elver
2021-05-26 12:38         ` Marco Elver
2021-05-26 18:12           ` Miguel Ojeda
2021-05-25 22:22 ` kernel test robot
2021-05-25 22:22   ` kernel test robot
2021-05-25 22:29   ` Marco Elver
2021-05-25 22:29     ` Marco Elver
2021-05-26  8:11     ` [kbuild-all] " Rong Chen
2021-05-26  8:11       ` Rong Chen
2021-05-25 23:21 ` kernel test robot
2021-05-25 23:21   ` kernel test robot
2021-05-26  8:19 ` Peter Zijlstra

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.