Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'x86-build-2024-09-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 build updates from Thomas Gleixner:
"Updates for KCOV instrumentation on x86:

- Prevent spurious KCOV coverage in common_interrupt()

- Fixup the KCOV Makefile directive which got stale due to a source
file rename

- Exclude stack unwinding from KCOV as it creates large amounts of
uninteresting coverage

- Provide a self test to validate that KCOV coverage of the interrupt
handling code starts not before preempt count got updated"

* tag 'x86-build-2024-09-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
x86: Ignore stack unwinding in KCOV
module: Fix KCOV-ignored file name
kcov: Add interrupt handling self test
x86/entry: Remove unwanted instrumentation in common_interrupt()

+57 -6
+6 -2
arch/x86/include/asm/hardirq.h
··· 69 69 #define local_softirq_pending_ref pcpu_hot.softirq_pending 70 70 71 71 #if IS_ENABLED(CONFIG_KVM_INTEL) 72 - static inline void kvm_set_cpu_l1tf_flush_l1d(void) 72 + /* 73 + * This function is called from noinstr interrupt contexts 74 + * and must be inlined to not get instrumentation. 75 + */ 76 + static __always_inline void kvm_set_cpu_l1tf_flush_l1d(void) 73 77 { 74 78 __this_cpu_write(irq_stat.kvm_cpu_l1tf_flush_l1d, 1); 75 79 } ··· 88 84 return __this_cpu_read(irq_stat.kvm_cpu_l1tf_flush_l1d); 89 85 } 90 86 #else /* !IS_ENABLED(CONFIG_KVM_INTEL) */ 91 - static inline void kvm_set_cpu_l1tf_flush_l1d(void) { } 87 + static __always_inline void kvm_set_cpu_l1tf_flush_l1d(void) { } 92 88 #endif /* IS_ENABLED(CONFIG_KVM_INTEL) */ 93 89 94 90 #endif /* _ASM_X86_HARDIRQ_H */
+3 -3
arch/x86/include/asm/idtentry.h
··· 212 212 irqentry_state_t state = irqentry_enter(regs); \ 213 213 u32 vector = (u32)(u8)error_code; \ 214 214 \ 215 + kvm_set_cpu_l1tf_flush_l1d(); \ 215 216 instrumentation_begin(); \ 216 - kvm_set_cpu_l1tf_flush_l1d(); \ 217 217 run_irq_on_irqstack_cond(__##func, regs, vector); \ 218 218 instrumentation_end(); \ 219 219 irqentry_exit(regs, state); \ ··· 250 250 \ 251 251 static __always_inline void instr_##func(struct pt_regs *regs) \ 252 252 { \ 253 - kvm_set_cpu_l1tf_flush_l1d(); \ 254 253 run_sysvec_on_irqstack_cond(__##func, regs); \ 255 254 } \ 256 255 \ ··· 257 258 { \ 258 259 irqentry_state_t state = irqentry_enter(regs); \ 259 260 \ 261 + kvm_set_cpu_l1tf_flush_l1d(); \ 260 262 instrumentation_begin(); \ 261 263 instr_##func (regs); \ 262 264 instrumentation_end(); \ ··· 288 288 static __always_inline void instr_##func(struct pt_regs *regs) \ 289 289 { \ 290 290 __irq_enter_raw(); \ 291 - kvm_set_cpu_l1tf_flush_l1d(); \ 292 291 __##func (regs); \ 293 292 __irq_exit_raw(); \ 294 293 } \ ··· 296 297 { \ 297 298 irqentry_state_t state = irqentry_enter(regs); \ 298 299 \ 300 + kvm_set_cpu_l1tf_flush_l1d(); \ 299 301 instrumentation_begin(); \ 300 302 instr_##func (regs); \ 301 303 instrumentation_end(); \
+8
arch/x86/kernel/Makefile
··· 35 35 # If instrumentation of the following files is enabled, boot hangs during 36 36 # first second. 37 37 KCOV_INSTRUMENT_head$(BITS).o := n 38 + # These are called from save_stack_trace() on debug paths, 39 + # and produce large amounts of uninteresting coverage. 40 + KCOV_INSTRUMENT_stacktrace.o := n 41 + KCOV_INSTRUMENT_dumpstack.o := n 42 + KCOV_INSTRUMENT_dumpstack_$(BITS).o := n 43 + KCOV_INSTRUMENT_unwind_orc.o := n 44 + KCOV_INSTRUMENT_unwind_frame.o := n 45 + KCOV_INSTRUMENT_unwind_guess.o := n 38 46 39 47 CFLAGS_irq.o := -I $(src)/../include/asm/trace 40 48
+31
kernel/kcov.c
··· 11 11 #include <linux/fs.h> 12 12 #include <linux/hashtable.h> 13 13 #include <linux/init.h> 14 + #include <linux/jiffies.h> 14 15 #include <linux/kmsan-checks.h> 15 16 #include <linux/mm.h> 16 17 #include <linux/preempt.h> ··· 1068 1067 } 1069 1068 EXPORT_SYMBOL(kcov_common_handle); 1070 1069 1070 + #ifdef CONFIG_KCOV_SELFTEST 1071 + static void __init selftest(void) 1072 + { 1073 + unsigned long start; 1074 + 1075 + pr_err("running self test\n"); 1076 + /* 1077 + * Test that interrupts don't produce spurious coverage. 1078 + * The coverage callback filters out interrupt code, but only 1079 + * after the handler updates preempt count. Some code periodically 1080 + * leaks out of that section and leads to spurious coverage. 1081 + * It's hard to call the actual interrupt handler directly, 1082 + * so we just loop here for a bit waiting for a timer interrupt. 1083 + * We set kcov_mode to enable tracing, but don't setup the area, 1084 + * so any attempt to trace will crash. Note: we must not call any 1085 + * potentially traced functions in this region. 1086 + */ 1087 + start = jiffies; 1088 + current->kcov_mode = KCOV_MODE_TRACE_PC; 1089 + while ((jiffies - start) * MSEC_PER_SEC / HZ < 300) 1090 + ; 1091 + current->kcov_mode = 0; 1092 + pr_err("done running self test\n"); 1093 + } 1094 + #endif 1095 + 1071 1096 static int __init kcov_init(void) 1072 1097 { 1073 1098 int cpu; ··· 1112 1085 * use of debugfs_create_file_unsafe() is actually safe here. 1113 1086 */ 1114 1087 debugfs_create_file_unsafe("kcov", 0600, NULL, NULL, &kcov_fops); 1088 + 1089 + #ifdef CONFIG_KCOV_SELFTEST 1090 + selftest(); 1091 + #endif 1115 1092 1116 1093 return 0; 1117 1094 }
+1 -1
kernel/module/Makefile
··· 5 5 6 6 # These are called from save_stack_trace() on slub debug path, 7 7 # and produce insane amounts of uninteresting coverage. 8 - KCOV_INSTRUMENT_module.o := n 8 + KCOV_INSTRUMENT_main.o := n 9 9 10 10 obj-y += main.o 11 11 obj-y += strict_rwx.o
+8
lib/Kconfig.debug
··· 2173 2173 soft interrupts. This specifies the size of those areas in the 2174 2174 number of unsigned long words. 2175 2175 2176 + config KCOV_SELFTEST 2177 + bool "Perform short selftests on boot" 2178 + depends on KCOV 2179 + help 2180 + Run short KCOV coverage collection selftests on boot. 2181 + On test failure, causes the kernel to panic. Recommended to be 2182 + enabled, ensuring critical functionality works as intended. 2183 + 2176 2184 menuconfig RUNTIME_TESTING_MENU 2177 2185 bool "Runtime Testing" 2178 2186 default y