Add two Kconfig options for global dataflow instrumentation control:

- CONFIG_KCOV_DATAFLOW_INSTRUMENT_ALL: instruments all kernel objects
  with dataflow tracing by default (mirrors CONFIG_KCOV_INSTRUMENT_ALL).
  Individual files can opt out with: KCOV_DATAFLOW_file.o := n

- CONFIG_KCOV_DATAFLOW_NO_INLINE: adds -fno-inline to instrumented files
  for complete argument visibility (default y). Setting to n allows
  global enablement without stack overflow or BUILD_BUG_ON failures.

Overhead with INSTRUMENT_ALL (NO_INLINE=n, KASAN baseline):
  .text: +9.5%, .data: +44%, boot: +71%, syscall: +133%
Comparable to KASAN (+100-200%) and acceptable for fuzzing kernels.

rust/Makefile: opt out core.o from dataflow (same as KCOV_INSTRUMENT).

Signed-off-by: Yunseong Kim <[email protected]>
---
 lib/Kconfig.debug | 23 ++++++++++++++++++++++-
 rust/Makefile     |  1 +
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index abd1a94589aa..3b952b6361a8 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2261,7 +2261,6 @@ config KCOV_SELFTEST
          On test failure, causes the kernel to panic. Recommended to be
          enabled, ensuring critical functionality works as intended.
 
-
 config KCOV_DATAFLOW_ARGS
        bool "Enable KCOV dataflow: function argument capture"
        depends on KCOV
@@ -2283,6 +2282,28 @@ config KCOV_DATAFLOW_RET
          metadata, recording individual field values at runtime.
          Enable per-module with: KCOV_DATAFLOW_file.o := y in the Makefile.
          Requires clang with -fsanitize-coverage=dataflow-ret support.
+
+config KCOV_DATAFLOW_INSTRUMENT_ALL
+       bool "Instrument all code with KCOV dataflow by default"
+       depends on KCOV_DATAFLOW_ARGS || KCOV_DATAFLOW_RET
+       help
+         If enabled, all kernel objects are compiled with dataflow
+         instrumentation (like CONFIG_KCOV_INSTRUMENT_ALL for basic KCOV).
+         Individual files can opt out with: KCOV_DATAFLOW_file.o := n
+         Increases compile time and binary size significantly.
+         Suitable for fuzzing and security auditing kernels.
+
+config KCOV_DATAFLOW_NO_INLINE
+       bool "Disable inlining for dataflow-instrumented files"
+       depends on KCOV_DATAFLOW_ARGS || KCOV_DATAFLOW_RET
+       default y
+       help
+         Adds -fno-inline to dataflow-instrumented files for complete
+         argument visibility. Without this, inlined functions will not
+         have their arguments captured individually.
+         Disabling allows global enablement with lower overhead at the
+         cost of missing inlined function traces.
+
 config DEBUG_AID_FOR_SYZBOT
        bool "Additional debug code for syzbot"
        default n
diff --git a/rust/Makefile b/rust/Makefile
index b9e9f512cec3..d122a65226dc 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -656,6 +656,7 @@ ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)),)
 $(obj)/core.o: scripts/target.json
 endif
 KCOV_INSTRUMENT_core.o := n
+KCOV_DATAFLOW_core.o := n
 
 $(obj)/compiler_builtins.o: private skip_gendwarfksyms = 1
 $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'

-- 
2.43.0


Reply via email to