Skip to content

Commit ad4f8ee

Browse files
melveringomolnar
authored andcommitted
kcsan: Address missing case with KCSAN_REPORT_VALUE_CHANGE_ONLY
Even with KCSAN_REPORT_VALUE_CHANGE_ONLY, KCSAN still reports data races between reads and watchpointed writes, even if the writes wrote values already present. This commit causes KCSAN to unconditionally skip reporting in this case. Signed-off-by: Marco Elver <elver@google.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent f1bc962 commit ad4f8ee

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

‎kernel/kcsan/report.c‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,25 @@ static bool rate_limit_report(unsigned long frame1, unsigned long frame2)
130130
* Special rules to skip reporting.
131131
*/
132132
static bool
133-
skip_report(int access_type, bool value_change, unsigned long top_frame)
133+
skip_report(bool value_change, unsigned long top_frame)
134134
{
135-
const bool is_write = (access_type & KCSAN_ACCESS_WRITE) != 0;
136-
137-
if (IS_ENABLED(CONFIG_KCSAN_REPORT_VALUE_CHANGE_ONLY) && is_write &&
138-
!value_change) {
135+
/*
136+
* The first call to skip_report always has value_change==true, since we
137+
* cannot know the value written of an instrumented access. For the 2nd
138+
* call there are 6 cases with CONFIG_KCSAN_REPORT_VALUE_CHANGE_ONLY:
139+
*
140+
* 1. read watchpoint, conflicting write (value_change==true): report;
141+
* 2. read watchpoint, conflicting write (value_change==false): skip;
142+
* 3. write watchpoint, conflicting write (value_change==true): report;
143+
* 4. write watchpoint, conflicting write (value_change==false): skip;
144+
* 5. write watchpoint, conflicting read (value_change==false): skip;
145+
* 6. write watchpoint, conflicting read (value_change==true): impossible;
146+
*
147+
* Cases 1-4 are intuitive and expected; case 5 ensures we do not report
148+
* data races where the write may have rewritten the same value; and
149+
* case 6 is simply impossible.
150+
*/
151+
if (IS_ENABLED(CONFIG_KCSAN_REPORT_VALUE_CHANGE_ONLY) && !value_change) {
139152
/*
140153
* The access is a write, but the data value did not change.
141154
*
@@ -228,7 +241,7 @@ static bool print_report(const volatile void *ptr, size_t size, int access_type,
228241
/*
229242
* Must check report filter rules before starting to print.
230243
*/
231-
if (skip_report(access_type, true, stack_entries[skipnr]))
244+
if (skip_report(true, stack_entries[skipnr]))
232245
return false;
233246

234247
if (type == KCSAN_REPORT_RACE_SIGNAL) {
@@ -237,7 +250,7 @@ static bool print_report(const volatile void *ptr, size_t size, int access_type,
237250
other_frame = other_info.stack_entries[other_skipnr];
238251

239252
/* @value_change is only known for the other thread */
240-
if (skip_report(other_info.access_type, value_change, other_frame))
253+
if (skip_report(value_change, other_frame))
241254
return false;
242255
}
243256

0 commit comments

Comments
 (0)