From 48054d2306fed2a2a53d8e5dba9c1aa7ef138ed5 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Sat, 1 Jun 2024 16:51:55 +0200 Subject: [PATCH] [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 --- Python/qsbr.c | 3 ++- Tools/tsan/suppressions_free_threading.txt | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Python/qsbr.c b/Python/qsbr.c index 9cbce9044e2941..a7321154a62ffc 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 27568c34e1689e..dbb0aacb7ed9cd 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