summaryrefslogtreecommitdiffstats
path: root/Objects/typeobject.c
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2024-07-08 18:52:07 (GMT)
committerGitHub <noreply@github.com>2024-07-08 18:52:07 (GMT)
commit1d3cf79a501a93a7a488fc75d4db3060c5ee7d1a (patch)
tree2e2f59a0d466ee4abccae054281be060c578e094 /Objects/typeobject.c
parent31873bea471020ca5deaf735d9acb0f1abeb1d3c (diff)
downloadcpython-1d3cf79a501a93a7a488fc75d4db3060c5ee7d1a.zip
cpython-1d3cf79a501a93a7a488fc75d4db3060c5ee7d1a.tar.gz
cpython-1d3cf79a501a93a7a488fc75d4db3060c5ee7d1a.tar.bz2
gh-121368: Fix seq lock memory ordering in _PyType_Lookup (#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.
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r--Objects/typeobject.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 447e561..df895bc 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -5387,7 +5387,7 @@ _PyType_LookupRef(PyTypeObject *type, PyObject *name)
#ifdef Py_GIL_DISABLED
// synchronize-with other writing threads by doing an acquire load on the sequence
while (1) {
- int sequence = _PySeqLock_BeginRead(&entry->sequence);
+ uint32_t sequence = _PySeqLock_BeginRead(&entry->sequence);
uint32_t entry_version = _Py_atomic_load_uint32_relaxed(&entry->version);
uint32_t type_version = _Py_atomic_load_uint32_acquire(&type->tp_version_tag);
if (entry_version == type_version &&