Skip to content

[vm] TSAN data race in Function::SetInstructionsSafe #49194

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

Closed
dcharkes opened this issue Jun 7, 2022 · 2 comments
Closed

[vm] TSAN data race in Function::SetInstructionsSafe #49194

dcharkes opened this issue Jun 7, 2022 · 2 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. gardening

Comments

@dcharkes
Copy link
Contributor

dcharkes commented Jun 7, 2022

There are new test failures on Fixing typo in comment...Revert "Modify dartdev language-server to call the server snapshot".

The tests

vm/cc/IsolateSpawn_FileUri Crash (expected Pass)
vm/cc/IsolateSpawn_PackageUri Crash (expected Pass)

are failing on configurations

dartk-tsan-linux-release-x64
WARNING: ThreadSanitizer: data race (pid=25679)
  Write of size 8 at 0x7f6ee164f6c8 by main thread:
    #0 void dart::Object::StoreNonPointer<unsigned long, unsigned long>(unsigned long const*, unsigned long) const ../../out/ReleaseTSANX64/../../runtime/vm/object.h:742:35 (run_vm_tests+0x46b0f21)
    #1 dart::Function::SetInstructionsSafe(dart::Code const&) const ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/object.cc:7124:3 (run_vm_tests+0x46b0f21)
    #2 dart::Function::SetInstructions(dart::Code const&) const ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/object.cc:7118:5 (run_vm_tests+0x46b0f21)
    #3 dart::Function::AttachCode(dart::Code const&) const ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/object.cc:7133:3 (run_vm_tests+0x46b0df1)
    #4 dart::CompileParsedFunctionHelper::FinalizeCompilation(dart::compiler::Assembler*, dart::FlowGraphCompiler*, dart::FlowGraph*) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/compiler/jit/compiler.cc:461:14 (run_vm_tests+0x48838a9)
    #5 dart::CompileParsedFunctionHelper::Compile(dart::CompilationPipeline*)::$_0::operator()() const ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/compiler/jit/compiler.cc:588:15 (run_vm_tests+0x4887594)
    #6 dart::LambdaCallable<dart::CompileParsedFunctionHelper::Compile(dart::CompilationPipeline*)::$_0>::Call() ../../out/ReleaseTSANX64/../../runtime/vm/isolate.h:133:17 (run_vm_tests+0x4887594)
    #7 dart::IsolateGroup::RunWithStoppedMutatorsCallable(dart::Callable*, dart::Callable*, bool) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/isolate.cc:2934:31 (run_vm_tests+0x45fcc86)
    #8 void dart::IsolateGroup::RunWithStoppedMutators<dart::CompileParsedFunctionHelper::Compile(dart::CompilationPipeline*)::$_0>(dart::CompileParsedFunctionHelper::Compile(dart::CompilationPipeline*)::$_0, bool) ../../out/ReleaseTSANX64/../../runtime/vm/isolate.h:652:5 (run_vm_tests+0x4884957)
    #9 dart::CompileParsedFunctionHelper::Compile(dart::CompilationPipeline*) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/compiler/jit/compiler.cc:625:36 (run_vm_tests+0x4884957)
    #10 dart::CompileFunctionHelper(dart::CompilationPipeline*, dart::Function const&, bool, long) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/compiler/jit/compiler.cc:712:46 (run_vm_tests+0x4885341)
    #11 dart::Compiler::CompileFunction(dart::Thread*, dart::Function const&) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/compiler/jit/compiler.cc:842:10 (run_vm_tests+0x4884d79)
    #12 dart::Function::EnsureHasCode() const ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/object.cc:10148:28 (run_vm_tests+0x46c1f2f)
    #13 dart::DRT_HelperCompileFunction(dart::Isolate*, dart::Thread*, dart::Zone*, dart::NativeArguments) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/compiler/jit/compiler.cc:223:12 (run_vm_tests+0x48830f3)
    #14 dart::DRT_CompileFunction(dart::NativeArguments) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/compiler/jit/compiler.cc:209:1 (run_vm_tests+0x48830f3)
    #15 <null> <null> (memfd:dart-codespace (deleted)+0x2639)
    #16 dart::DartEntry::InvokeFunction(dart::Function const&, dart::Array const&, dart::Array const&, unsigned long) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/dart_entry.cc:145:10 (run_vm_tests+0x4592f14)
    #17 dart::Library::Invoke(dart::String const&, dart::Array const&, dart::Array const&, bool, bool) const ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/object.cc:13671:10 (run_vm_tests+0x46d62d4)
    #18 Dart_Invoke ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/dart_api_impl.cc:4671:16 (run_vm_tests+0x4f6da8f)
    #19 dart::IsolateSpawn(char const*) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/isolate_test.cc:86:12 (run_vm_tests+0x40e97b3)
    #20 dart::Dart_TestHelperIsolateSpawn_FileUri(dart::Thread*) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/isolate_test.cc:99:3 (run_vm_tests+0x40e9b33)
    #21 dart::Dart_TestIsolateSpawn_FileUri() ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/isolate_test.cc:98:1 (run_vm_tests+0x40e9b33)
    #22 dart::TestCase::Run() ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/bin/run_vm_tests.cc:52:3 (run_vm_tests+0x3ff42ac)
    #23 dart::TestCaseBase::RunTest() ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/bin/run_vm_tests.cc:64:11 (run_vm_tests+0x3ff4481)
    #24 dart::TestCaseBase::RunAll() ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/unit_test.cc:86:13 (run_vm_tests+0x424c388)
    #25 dart::Main(int, char const**) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/bin/run_vm_tests.cc:396:3 (run_vm_tests+0x3ff4a79)
    #26 main ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/bin/run_vm_tests.cc:427:29 (run_vm_tests+0x3ff463e)

  Previous read of size 8 at 0x7f6ee164f6c8 by thread T7 (mutexes: write M0):
    #0 dart::Function::EntryPointOf(dart::FunctionPtr) ../../out/ReleaseTSANX64/../../runtime/vm/object.h:2899:31 (run_vm_tests+0x45f13e1)
    #1 dart::IsolateGroup::ScheduleThreadLocked(dart::MonitorLocker*, dart::Thread*, bool, bool, bool) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/isolate.cc:620:7 (run_vm_tests+0x45f13e1)
    #2 dart::IsolateGroup::ScheduleThread(bool) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/isolate.cc:712:10 (run_vm_tests+0x45f1853)
    #3 dart::Thread::EnterIsolateGroupAsHelper(dart::IsolateGroup*, dart::Thread::TaskKind, bool) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/thread.cc:356:35 (run_vm_tests+0x485baba)
    #4 dart::SpawnIsolateTask::FailedSpawn(char const*, bool) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/lib/isolate.cc:871:27 (run_vm_tests+0x45018b2)
    #5 dart::SpawnIsolateTask::RunLightweight(char const*) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/lib/isolate.cc:677:7 (run_vm_tests+0x450173f)
    #6 dart::SpawnIsolateTask::Run() ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/lib/isolate.cc:639:7 (run_vm_tests+0x450142f)
    #7 dart::ThreadPool::WorkerLoop(dart::ThreadPool::Worker*) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/thread_pool.cc:158:15 (run_vm_tests+0x48628ea)
    #8 dart::ThreadPool::Worker::Main(unsigned long) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/thread_pool.cc:330:9 (run_vm_tests+0x48631ce)
    #9 dart::ThreadStart(void*) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/os_thread_linux.cc:154:5 (run_vm_tests+0x4762e0d)

  Location is global '??' at 0x7f6ee1600000 (memfd:dart-oldspace (deleted)+0x4f6c8)

  Mutex M0 (0x7b1c00000310) created at:
    #0 pthread_mutex_init ../staging/llvm_build/tools/clang/stage2-bins/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/../staging/llvm_build/tools/clang/stage2-bins/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1316:3 (run_vm_tests+0x3f7472f)
    #1 dart::Monitor::Monitor() ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/os_thread_linux.cc:372:12 (run_vm_tests+0x4763416)
    #2 dart::ThreadRegistry::ThreadRegistry() ../../out/ReleaseTSANX64/../../runtime/vm/thread_registry.h:25:22 (run_vm_tests+0x45ef3a1)
    #3 dart::IsolateGroup::IsolateGroup(std::__2::shared_ptr<dart::IsolateGroupSource>, void*, dart::ObjectStore*, Dart_IsolateFlags) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/isolate.cc:349:28 (run_vm_tests+0x45ef3a1)
    #4 dart::IsolateGroup::IsolateGroup(std::__2::shared_ptr<dart::IsolateGroupSource>, void*, Dart_IsolateFlags) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/isolate.cc:409:7 (run_vm_tests+0x45efd4d)
    #5 Dart_CreateIsolateGroup ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/dart_api_impl.cc:1391:20 (run_vm_tests+0x4f4a442)
    #6 dart::TestCase::CreateIsolate(unsigned char const*, long, unsigned char const*, char const*, void*, void*) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/unit_test.cc:121:15 (run_vm_tests+0x424c6bd)
    #7 dart::TestCase::CreateTestIsolate(char const*, void*, void*) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/unit_test.cc:142:10 (run_vm_tests+0x424c6bd)
    #8 dart::TestIsolateScope::TestIsolateScope() ../../out/ReleaseTSANX64/../../runtime/vm/unit_test.h:441:43 (run_vm_tests+0x40e99c5)
    #9 dart::Dart_TestIsolateSpawn_FileUri() ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/isolate_test.cc:98:1 (run_vm_tests+0x40e99c5)
    #10 dart::TestCase::Run() ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/bin/run_vm_tests.cc:52:3 (run_vm_tests+0x3ff42ac)
    #11 dart::TestCaseBase::RunTest() ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/bin/run_vm_tests.cc:64:11 (run_vm_tests+0x3ff4481)
    #12 dart::TestCaseBase::RunAll() ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/unit_test.cc:86:13 (run_vm_tests+0x424c388)
    #13 dart::Main(int, char const**) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/bin/run_vm_tests.cc:396:3 (run_vm_tests+0x3ff4a79)
    #14 main ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/bin/run_vm_tests.cc:427:29 (run_vm_tests+0x3ff463e)

  Thread T7 'DartWorker' (tid=25773, running) created by main thread at:
    #0 pthread_create ../staging/llvm_build/tools/clang/stage2-bins/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/../staging/llvm_build/tools/clang/stage2-bins/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:1022:3 (run_vm_tests+0x3f72f4d)
    #1 dart::OSThread::Start(char const*, void (*)(unsigned long), unsigned long) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/os_thread_linux.cc:173:12 (run_vm_tests+0x4762cac)
    #2 dart::ThreadPool::Worker::StartThread() ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/thread_pool.cc:296:16 (run_vm_tests+0x4861fad)
    #3 dart::ThreadPool::RunImpl(std::__2::unique_ptr<dart::ThreadPool::Task, std::__2::default_delete<dart::ThreadPool::Task> >) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/thread_pool.cc:94:17 (run_vm_tests+0x4861fad)
    #4 bool dart::ThreadPool::Run<dart::SpawnIsolateTask, dart::Isolate*&, std::__2::unique_ptr<dart::IsolateSpawnState, std::__2::default_delete<dart::IsolateSpawnState> > >(dart::Isolate*&, std::__2::unique_ptr<dart::IsolateSpawnState, std::__2::default_delete<dart::IsolateSpawnState> >&&) ../../out/ReleaseTSANX64/../../runtime/vm/thread_pool.h:46:12 (run_vm_tests+0x44fe96d)
    #5 dart::DN_HelperIsolate_spawnFunction(dart::Isolate*, dart::Thread*, dart::Zone*, dart::NativeArguments*) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/lib/isolate.cc:962:36 (run_vm_tests+0x44fe96d)
    #6 dart::BootstrapNatives::DN_Isolate_spawnFunction(dart::Thread*, dart::Zone*, dart::NativeArguments*) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/lib/isolate.cc:908:1 (run_vm_tests+0x44fe96d)
    #7 dart::NativeEntry::BootstrapNativeCallWrapper(_Dart_NativeArguments*, void (*)(_Dart_NativeArguments*)) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/native_entry.cc:140:37 (run_vm_tests+0x4662c67)
    #8 <null> <null> (memfd:dart-codespace (deleted)+0x27aa)
    #9 dart::DartEntry::InvokeFunction(dart::Function const&, dart::Array const&, dart::Array const&, unsigned long) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/dart_entry.cc:145:10 (run_vm_tests+0x4592f14)
    #10 dart::Library::Invoke(dart::String const&, dart::Array const&, dart::Array const&, bool, bool) const ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/object.cc:13671:10 (run_vm_tests+0x46d62d4)
    #11 Dart_Invoke ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/dart_api_impl.cc:4671:16 (run_vm_tests+0x4f6da8f)
    #12 dart::IsolateSpawn(char const*) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/isolate_test.cc:86:12 (run_vm_tests+0x40e97b3)
    #13 dart::Dart_TestHelperIsolateSpawn_FileUri(dart::Thread*) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/isolate_test.cc:99:3 (run_vm_tests+0x40e9b33)
    #14 dart::Dart_TestIsolateSpawn_FileUri() ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/isolate_test.cc:98:1 (run_vm_tests+0x40e9b33)
    #15 dart::TestCase::Run() ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/bin/run_vm_tests.cc:52:3 (run_vm_tests+0x3ff42ac)
    #16 dart::TestCaseBase::RunTest() ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/bin/run_vm_tests.cc:64:11 (run_vm_tests+0x3ff4481)
    #17 dart::TestCaseBase::RunAll() ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/vm/unit_test.cc:86:13 (run_vm_tests+0x424c388)
    #18 dart::Main(int, char const**) ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/bin/run_vm_tests.cc:396:3 (run_vm_tests+0x3ff4a79)
    #19 main ../../out/ReleaseTSANX64/../../out/ReleaseTSANX64/../../runtime/bin/run_vm_tests.cc:427:29 (run_vm_tests+0x3ff463e)

SUMMARY: ThreadSanitizer: data race ../../out/ReleaseTSANX64/../../runtime/vm/object.h:742:35 in void dart::Object::StoreNonPointer<unsigned long, unsigned long>(unsigned long const*, unsigned long) const
==================
ThreadSanitizer: reported 1 warnings

full log

I don't see an obvious commit, I'll bisect locally.

@dcharkes dcharkes added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. gardening labels Jun 7, 2022
@dcharkes
Copy link
Contributor Author

dcharkes commented Jun 7, 2022

b3544c4 does not trigget the TSAN issue, 3d1c991 does.

The commit does not contain any VM changes, maybe there is a code path in the VM now exercised that wasn't before by the kernel changes.

@alexmarkov
Copy link
Contributor

This TSAN error is probably flaky and caused by using the new async/async* implementation (b3544c4). The data race itself looks benign (cannot cause any real problems on currently supported architectures); relaxed atomic for UntaggedFunction::entry_point_ will probably fix the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. gardening
Projects
None yet
Development

No branches or pull requests

2 participants