-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-121368: Fix seq lock memory ordering in _PyType_Lookup #121388
Conversation
After running all repros I had for several hours I confirm this change solves the issue. |
The `_PySeqLock_EndRead` function needs an acquire fence to ensure that the load of the sequence happens after any loads within the read side critical section. The acquire on the final sequence load isn't sufficent (or necessary).
9a68c4c
to
a408e64
Compare
Here's the relevant portion of a Rust seqlock implementation for reference: |
I've added a model for the C11 model check here: https://github.com/colesbury/c11-model-checker/blob/cpython-models/test/seqlock.c (Turns out we need the release fence too) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Python/lock.c
Outdated
if (_Py_atomic_load_uint32_acquire(&seqlock->sequence) == previous) { | ||
// gh-121368: We need an explicit acquire fence here to ensure that | ||
// this load of the sequence number is not reordered before any loads | ||
// withing the read lock. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withing -> within?
Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
…onGH-121388) The `_PySeqLock_EndRead` function needs an acquire fence to ensure that the load of the sequence happens after any loads within the read side critical section. The missing fence can trigger bugs on macOS arm64. Additionally, we need a release fence in `_PySeqLock_LockWrite` to ensure that the sequence update is visible before any modifications to the cache entry. (cherry picked from commit 1d3cf79) Co-authored-by: Sam Gross <[email protected]>
GH-121505 is a backport of this pull request to the 3.13 branch. |
…121388) (#121505) The `_PySeqLock_EndRead` function needs an acquire fence to ensure that the load of the sequence happens after any loads within the read side critical section. The missing fence can trigger bugs on macOS arm64. Additionally, we need a release fence in `_PySeqLock_LockWrite` to ensure that the sequence update is visible before any modifications to the cache entry. (cherry picked from commit 1d3cf79) Co-authored-by: Sam Gross <[email protected]>
…on#121388) The `_PySeqLock_EndRead` function needs an acquire fence to ensure that the load of the sequence happens after any loads within the read side critical section. The missing fence can trigger bugs on macOS arm64. Additionally, we need a release fence in `_PySeqLock_LockWrite` to ensure that the sequence update is visible before any modifications to the cache entry.
…on#121388) The `_PySeqLock_EndRead` function needs an acquire fence to ensure that the load of the sequence happens after any loads within the read side critical section. The missing fence can trigger bugs on macOS arm64. Additionally, we need a release fence in `_PySeqLock_LockWrite` to ensure that the sequence update is visible before any modifications to the cache entry.
The
_PySeqLock_EndRead
function needs an acquire fence to ensure thatthe load of the sequence happens after any loads within the read side
critical section. The missing fence can trigger bugs on macOS arm64.
Additionally, we need a release fence in
_PySeqLock_LockWrite
toensure that the sequence update is visible before any modifications to
the cache entry.
Also fix up the return types of a few seqlock functions.