diff options
author | Alex Richardson <arichardson@FreeBSD.org> | 2021-02-18 10:25:10 +0000 |
---|---|---|
committer | Alex Richardson <arichardson@FreeBSD.org> | 2021-02-18 14:02:48 +0000 |
commit | fa2528ac643519072c498b483d0dcc1fa5d99bc1 (patch) | |
tree | 255d2d54811e94f63b72fe40c4a88b4f11978e9f /sys/ddb/db_ps.c | |
parent | df093aa9463b2121d8307fb91c4ba7cf17f4ea64 (diff) | |
download | src-fa2528ac643519072c498b483d0dcc1fa5d99bc1.tar.gz src-fa2528ac643519072c498b483d0dcc1fa5d99bc1.zip |
Use atomic loads/stores when updating td->td_state
KCSAN complains about racy accesses in the locking code. Those races are
fine since they are inside a TD_SET_RUNNING() loop that expects the value
to be changed by another CPU.
Use relaxed atomic stores/loads to indicate that this variable can be
written/read by multiple CPUs at the same time. This will also prevent
the compiler from doing unexpected re-ordering.
Reported by: GENERIC-KCSAN
Test Plan: KCSAN no longer complains, kernel still runs fine.
Reviewed By: markj, mjg (earlier version)
Differential Revision: https://reviews.freebsd.org/D28569
Diffstat (limited to 'sys/ddb/db_ps.c')
-rw-r--r-- | sys/ddb/db_ps.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/sys/ddb/db_ps.c b/sys/ddb/db_ps.c index 44b803299ee9..a5245528ca83 100644 --- a/sys/ddb/db_ps.c +++ b/sys/ddb/db_ps.c @@ -173,9 +173,9 @@ db_ps_proc(struct proc *p) */ rflag = sflag = dflag = lflag = wflag = 0; FOREACH_THREAD_IN_PROC(p, td) { - if (td->td_state == TDS_RUNNING || - td->td_state == TDS_RUNQ || - td->td_state == TDS_CAN_RUN) + if (TD_GET_STATE(td) == TDS_RUNNING || + TD_GET_STATE(td) == TDS_RUNQ || + TD_GET_STATE(td) == TDS_CAN_RUN) rflag++; if (TD_ON_LOCK(td)) lflag++; @@ -267,7 +267,7 @@ dumpthread(volatile struct proc *p, volatile struct thread *td, int all) if (all) { db_printf("%6d ", td->td_tid); - switch (td->td_state) { + switch (TD_GET_STATE(td)) { case TDS_RUNNING: snprintf(state, sizeof(state), "Run"); break; @@ -367,7 +367,7 @@ DB_SHOW_COMMAND(thread, db_show_thread) db_printf(" flags: %#x ", td->td_flags); db_printf(" pflags: %#x\n", td->td_pflags); db_printf(" state: "); - switch (td->td_state) { + switch (TD_GET_STATE(td)) { case TDS_INACTIVE: db_printf("INACTIVE\n"); break; @@ -413,7 +413,7 @@ DB_SHOW_COMMAND(thread, db_show_thread) db_printf("}\n"); break; default: - db_printf("??? (%#x)\n", td->td_state); + db_printf("??? (%#x)\n", TD_GET_STATE(td)); break; } if (TD_ON_LOCK(td)) |