History

kcsan: Distinguish kcsan_report() calls

Currently kcsan_report() is used to handle three distinct cases: * The caller hit a watchpoint when attempting an access. Some information regarding the caller and access are recorded, but no output is produced. * A caller which previously setup a watchpoint detected that the watchpoint has been hit, and possibly detected a change to the location in memory being watched. This may result in output reporting the interaction between this caller and the caller which hit the watchpoint. * A caller detected a change to a modification to a memory location which wasn't detected by a watchpoint, for which there is no information on the other thread. This may result in output reporting the unexpected change. ... depending on the specific case the caller has distinct pieces of information available, but the prototype of kcsan_report() has to handle all three cases. This means that in some cases we pass redundant information, and in others we don't pass all the information we could pass. This also means that the report code has to demux these three cases. So that we can pass some additional information while also simplifying the callers and report code, add separate kcsan_report_*() functions for the distinct cases, updating callers accordingly. As the watchpoint_idx is unused in the case of kcsan_report_unknown_origin(), this passes a dummy value into kcsan_report(). Subsequent patches will refactor the report code to avoid this. There should be no functional change as a result of this patch.

Mark Rutland committed 5 years ago

Commit 793c2571 parent 6f2d9813 files · +33 −15Browse files

Unified · Split

3 files
  1. kernel/kcsan/core.c +4 −8
  2. kernel/kcsan/kcsan.h +6 −4
  3. kernel/kcsan/report.c +23 −3
kernel/kcsan/core.c+4−8
@@ -380,9 +380,7 @@ static noinline void kcsan_found_watchpoint(const volatile void *ptr, · 379 unmodified lines
380380
381381 if (consumed) {
382382 kcsan_save_irqtrace(current);
383− kcsan_report(ptr, size, type, KCSAN_VALUE_CHANGE_MAYBE,
384− KCSAN_REPORT_CONSUMED_WATCHPOINT,
385− watchpoint - watchpoints);
383+ kcsan_report_set_info(ptr, size, type, watchpoint - watchpoints);
386384 kcsan_restore_irqtrace(current);
387385 } else {
388386 /*
@@ -558,8 +556,8 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type) · 169 unmodified lines
558556 if (is_assert && value_change == KCSAN_VALUE_CHANGE_TRUE)
559557 atomic_long_inc(&kcsan_counters[KCSAN_COUNTER_ASSERT_FAILURES]);
560558
561− kcsan_report(ptr, size, type, value_change, KCSAN_REPORT_RACE_SIGNAL,
562− watchpoint - watchpoints);
559+ kcsan_report_known_origin(ptr, size, type, value_change,
560+ watchpoint - watchpoints);
563561 } else if (value_change == KCSAN_VALUE_CHANGE_TRUE) {
564562 /* Inferring a race, since the value should not have changed. */
565563
@@ -568,9 +566,7 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type) · 2 unmodified lines
568566 atomic_long_inc(&kcsan_counters[KCSAN_COUNTER_ASSERT_FAILURES]);
569567
570568 if (IS_ENABLED(CONFIG_KCSAN_REPORT_RACE_UNKNOWN_ORIGIN) || is_assert)
571− kcsan_report(ptr, size, type, KCSAN_VALUE_CHANGE_TRUE,
572− KCSAN_REPORT_RACE_UNKNOWN_ORIGIN,
573− watchpoint - watchpoints);
569+ kcsan_report_unknown_origin(ptr, size, type);
574570 }
575571
576572 /*
kernel/kcsan/kcsan.h+6−4
@@ -136,10 +136,12 @@ enum kcsan_report_type { · 135 unmodified lines
136136 };
137137
138138 /*
139− * Print a race report from thread that encountered the race.
139+ * Notify the report code that a race occurred.
140140 */
141−extern void kcsan_report(const volatile void *ptr, size_t size, int access_type,
142− enum kcsan_value_change value_change,
143− enum kcsan_report_type type, int watchpoint_idx);
141+void kcsan_report_set_info(const volatile void *ptr, size_t size, int access_type,
142+ int watchpoint_idx);
143+void kcsan_report_known_origin(const volatile void *ptr, size_t size, int access_type,
144+ enum kcsan_value_change value_change, int watchpoint_idx);
145+void kcsan_report_unknown_origin(const volatile void *ptr, size_t size, int access_type);
144146
145147 #endif /* _KERNEL_KCSAN_KCSAN_H */
kernel/kcsan/report.c+23−3
@@ -598,9 +598,9 @@ static noinline bool prepare_report(unsigned long *flags, · 597 unmodified lines
598598 }
599599 }
600600
601−void kcsan_report(const volatile void *ptr, size_t size, int access_type,
602− enum kcsan_value_change value_change,
603− enum kcsan_report_type type, int watchpoint_idx)
601+static void kcsan_report(const volatile void *ptr, size_t size, int access_type,
602+ enum kcsan_value_change value_change,
603+ enum kcsan_report_type type, int watchpoint_idx)
604604 {
605605 unsigned long flags = 0;
606606 const struct access_info ai = {
@@ -645,3 +645,23 @@ void kcsan_report(const volatile void *ptr, size_t size, int access_type, · 38 unmodified lines
645645 out:
646646 kcsan_enable_current();
647647 }
648+
649+void kcsan_report_set_info(const volatile void *ptr, size_t size, int access_type,
650+ int watchpoint_idx)
651+{
652+ kcsan_report(ptr, size, access_type, KCSAN_VALUE_CHANGE_MAYBE,
653+ KCSAN_REPORT_CONSUMED_WATCHPOINT, watchpoint_idx);
654+}
655+
656+void kcsan_report_known_origin(const volatile void *ptr, size_t size, int access_type,
657+ enum kcsan_value_change value_change, int watchpoint_idx)
658+{
659+ kcsan_report(ptr, size, access_type, value_change,
660+ KCSAN_REPORT_RACE_SIGNAL, watchpoint_idx);
661+}
662+
663+void kcsan_report_unknown_origin(const volatile void *ptr, size_t size, int access_type)
664+{
665+ kcsan_report(ptr, size, access_type, KCSAN_VALUE_CHANGE_TRUE,
666+ KCSAN_REPORT_RACE_UNKNOWN_ORIGIN, 0);
667+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t