]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-117657: Enable test_opcache under TSAN (GH-129831) (GH-130597)
authorSam Gross <colesbury@gmail.com>
Wed, 26 Feb 2025 18:59:59 +0000 (13:59 -0500)
committerGitHub <noreply@github.com>
Wed, 26 Feb 2025 18:59:59 +0000 (13:59 -0500)
Fix a few thread-safety bugs to enable test_opcache when run with TSAN:

 * Use relaxed atomics when clearing `ht->_spec_cache.getitem`
   (gh-115999)
 * Add temporary suppression for type slot modifications (gh-127266)
 * Use atomic load when reading `*dictptr`

(cherry picked from commit f151d271591ec525eaf01fa7b128e575374888b9)

Lib/test/libregrtest/tsan.py
Objects/object.c
Objects/typeobject.c
Tools/tsan/suppressions_free_threading.txt

index 822ac0f4044d9e86acafef60c50ce8bd4718ca59..0c0ab20fa0b04ae56d0c89b8c9fd762d128c1dec 100644 (file)
@@ -13,6 +13,7 @@ TSAN_TESTS = [
     'test_importlib',
     'test_io',
     'test_logging',
+    'test_opcache',
     'test_queue',
     'test_signal',
     'test_socket',
index c0ce4291eb73354059472653a834af61644c11f7..0539bcbb462132de99381fdbd3bbc5035c6772cb 100644 (file)
@@ -1584,7 +1584,7 @@ _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method)
     else {
         PyObject **dictptr = _PyObject_ComputedDictPointer(obj);
         if (dictptr != NULL) {
-            dict = *dictptr;
+            dict = FT_ATOMIC_LOAD_PTR_ACQUIRE(*dictptr);
         }
         else {
             dict = NULL;
index c84841070555d13993d6bb862240e0dfba7521a6..6e8064540e51795eb2eeadf894b72b98edb347e8 100644 (file)
@@ -1043,7 +1043,8 @@ type_modified_unlocked(PyTypeObject *type)
     if (PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
         // This field *must* be invalidated if the type is modified (see the
         // comment on struct _specialization_cache):
-        ((PyHeapTypeObject *)type)->_spec_cache.getitem = NULL;
+        FT_ATOMIC_STORE_PTR_RELAXED(
+            ((PyHeapTypeObject *)type)->_spec_cache.getitem, NULL);
     }
 }
 
@@ -1119,7 +1120,8 @@ type_mro_modified(PyTypeObject *type, PyObject *bases) {
     if (PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
         // This field *must* be invalidated if the type is modified (see the
         // comment on struct _specialization_cache):
-        ((PyHeapTypeObject *)type)->_spec_cache.getitem = NULL;
+        FT_ATOMIC_STORE_PTR_RELAXED(
+            ((PyHeapTypeObject *)type)->_spec_cache.getitem, NULL);
     }
 }
 
index 6add088daef76ebc07b994e2dd69ab1c5bd61648..5ba0a81ac71c3d30195b56c8d53eb60a3d86d0f5 100644 (file)
@@ -47,5 +47,8 @@ race_top:PyThreadState_Clear
 # Only seen on macOS, sample: https://gist.github.com/aisk/dda53f5d494a4556c35dde1fce03259c
 race_top:set_default_allocator_unlocked
 
+# gh-127266: type slot updates are not thread-safe (test_opcache.test_load_attr_method_lazy_dict)
+race_top:update_one_slot
+
 # https://gist.github.com/mpage/6962e8870606cfc960e159b407a0cb40
 thread:pthread_create