Skip to content

Commit 248591f

Browse files
melverPeter Zijlstra
authored andcommitted
kcsan: Make KCSAN compatible with new IRQ state tracking
The new IRQ state tracking code does not honor lockdep_off(), and as such we should again permit tracing by using non-raw functions in core.c. Update the lockdep_off() comment in report.c, to reflect the fact there is still a potential risk of deadlock due to using printk() from scheduler code. Suggested-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Marco Elver <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Ingo Molnar <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent e1bcad6 commit 248591f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

kernel/kcsan/core.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,7 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type)
397397
}
398398

399399
if (!kcsan_interrupt_watcher)
400-
/* Use raw to avoid lockdep recursion via IRQ flags tracing. */
401-
raw_local_irq_save(irq_flags);
400+
local_irq_save(irq_flags);
402401

403402
watchpoint = insert_watchpoint((unsigned long)ptr, size, is_write);
404403
if (watchpoint == NULL) {
@@ -539,7 +538,7 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type)
539538
kcsan_counter_dec(KCSAN_COUNTER_USED_WATCHPOINTS);
540539
out_unlock:
541540
if (!kcsan_interrupt_watcher)
542-
raw_local_irq_restore(irq_flags);
541+
local_irq_restore(irq_flags);
543542
out:
544543
user_access_restore(ua_flags);
545544
}

kernel/kcsan/report.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,11 @@ void kcsan_report(const volatile void *ptr, size_t size, int access_type,
606606
goto out;
607607

608608
/*
609-
* With TRACE_IRQFLAGS, lockdep's IRQ trace state becomes corrupted if
610-
* we do not turn off lockdep here; this could happen due to recursion
611-
* into lockdep via KCSAN if we detect a race in utilities used by
612-
* lockdep.
609+
* Because we may generate reports when we're in scheduler code, the use
610+
* of printk() could deadlock. Until such time that all printing code
611+
* called in print_report() is scheduler-safe, accept the risk, and just
612+
* get our message out. As such, also disable lockdep to hide the
613+
* warning, and avoid disabling lockdep for the rest of the kernel.
613614
*/
614615
lockdep_off();
615616

0 commit comments

Comments
 (0)