]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117657: Enable test_opcache under TSAN (GH-129831)
authorSam Gross <colesbury@gmail.com>
Tue, 11 Feb 2025 21:53:08 +0000 (16:53 -0500)
committerGitHub <noreply@github.com>
Tue, 11 Feb 2025 21:53:08 +0000 (16:53 -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`

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

index 10b12cce1659315770ef642ec934a1928c29d9f0..51233724c8136fa81f339fd823b6afdfb9fe4cbf 100644 (file)
@@ -13,6 +13,7 @@ TSAN_TESTS = [
     'test_importlib',
     'test_io',
     'test_logging',
+    'test_opcache',
     'test_queue',
     'test_signal',
     'test_socket',
index f3c7fa6d906ad6e39e249e35d07f167b0f09142f..c3f57f47333a1f1b7283664395a574bc050d119e 100644 (file)
@@ -1612,7 +1612,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 f3238da8a642e497d6545cc330f75480a51153cb..59ea2e3331ff54693ebeba0a6e5cd83f92825f70 100644 (file)
@@ -1085,7 +1085,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);
     }
 }
 
@@ -1166,7 +1167,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 c2509cae7b9e9d384dc0ad684a99c68dbfe42455..e4cf2a76db35cc1b31de83498779c5ba0fafeccd 100644 (file)
@@ -49,5 +49,8 @@ race_top:rangeiter_next
 # gh-129748: test.test_free_threading.test_slots.TestSlots.test_object
 race_top:mi_block_set_nextx
 
+# 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