summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-01 14:51:55 (GMT)
committerGitHub <noreply@github.com>2024-06-01 14:51:55 (GMT)
commit48054d2306fed2a2a53d8e5dba9c1aa7ef138ed5 (patch)
tree459c3f111aeef9718d9d1fe919c26d48e514636c
parent48f3378d6c620e99f17679ee11982a57640d3bb4 (diff)
downloadcpython-48054d2306fed2a2a53d8e5dba9c1aa7ef138ed5.zip
cpython-48054d2306fed2a2a53d8e5dba9c1aa7ef138ed5.tar.gz
cpython-48054d2306fed2a2a53d8e5dba9c1aa7ef138ed5.tar.bz2
[3.13] gh-117657: Fix TSAN race in QSBR assertion (GH-119887) (#119904)
Due to a limitation in TSAN, all reads from `PyThreadState.state` must be atomic to avoid reported races. (cherry picked from commit 90ec19fd33e2452902b9788d4821f1fbf6542304) Co-authored-by: Sam Gross <colesbury@gmail.com>
-rw-r--r--Python/qsbr.c3
-rw-r--r--Tools/tsan/suppressions_free_threading.txt2
2 files changed, 2 insertions, 3 deletions
diff --git a/Python/qsbr.c b/Python/qsbr.c
index 9cbce90..a732115 100644
--- a/Python/qsbr.c
+++ b/Python/qsbr.c
@@ -160,7 +160,8 @@ qsbr_poll_scan(struct _qsbr_shared *shared)
bool
_Py_qsbr_poll(struct _qsbr_thread_state *qsbr, uint64_t goal)
{
- assert(_PyThreadState_GET()->state == _Py_THREAD_ATTACHED);
+ assert(_Py_atomic_load_int_relaxed(&_PyThreadState_GET()->state) == _Py_THREAD_ATTACHED);
+
if (_Py_qbsr_goal_reached(qsbr, goal)) {
return true;
}
diff --git a/Tools/tsan/suppressions_free_threading.txt b/Tools/tsan/suppressions_free_threading.txt
index 27568c3..dbb0aac 100644
--- a/Tools/tsan/suppressions_free_threading.txt
+++ b/Tools/tsan/suppressions_free_threading.txt
@@ -76,8 +76,6 @@ race_top:_PyFrame_GetCode
race_top:_PyFrame_Initialize
race_top:PyInterpreterState_ThreadHead
race_top:_PyObject_TryGetInstanceAttribute
-race_top:_Py_qsbr_unregister
-race_top:_Py_qsbr_poll
race_top:PyThreadState_Next
race_top:Py_TYPE
race_top:PyUnstable_InterpreterFrame_GetLine