Skip to content

gh-117657: Fix TSAN race in QSBR assertion - #119887

Merged
colesbury merged 2 commits into
python:mainfrom
colesbury:gh-117657-qsbr
Jun 1, 2024
Merged

colesbury merged 2 commits into
python:mainfrom
colesbury:gh-117657-qsbr

Conversation

@colesbury

@colesbury colesbury commented May 31, 2024 •

Copy link
Copy Markdown
Contributor

Due to a limitation of TSAN, all reads from PyThreadState.state must be atomic to avoid reported races.

Due to a limitation in TSAN, all reads from PyThreadState.state must be
atomic to avoid reported races.
@colesbury
colesbury merged commit 90ec19f into python:main Jun 1, 2024
@miss-islington-app

Copy link
Copy Markdown

Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@colesbury
colesbury deleted the gh-117657-qsbr branch June 1, 2024 14:04
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 1, 2024
Due to a limitation in TSAN, all reads from `PyThreadState.state` must be
atomic to avoid reported races.
(cherry picked from commit 90ec19f)

Co-authored-by: Sam Gross <colesbury@gmail.com>
@bedevere-app

bedevere-app Bot commented Jun 1, 2024

Copy link
Copy Markdown

GH-119904 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Jun 1, 2024
colesbury added a commit that referenced this pull request Jun 1, 2024
Due to a limitation in TSAN, all reads from `PyThreadState.state` must be
atomic to avoid reported races.
(cherry picked from commit 90ec19f)

Co-authored-by: Sam Gross <colesbury@gmail.com>
@wiggin15

wiggin15 commented Jun 1, 2024

Copy link
Copy Markdown
Contributor

Don't we want to use the FT_ATOMIC_LOAD_* macro from pycore_pyatomic_ft_wrappers.h to avoid affecting the GIL code?

@colesbury

Copy link
Copy Markdown
Contributor Author

No:

  • it's in qsbr.c, which is only used in the free-threaded build.
  • it's in an assertion (so debug only)
  • using the FT_* macros in places where there's no performance reason to do so tends to make code harder to read without sufficient benefit
barneygale pushed a commit to barneygale/cpython that referenced this pull request Jun 5, 2024
Due to a limitation in TSAN, all reads from `PyThreadState.state` must be
atomic to avoid reported races.
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
Due to a limitation in TSAN, all reads from `PyThreadState.state` must be
atomic to avoid reported races.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants