# --- T2-COPYRIGHT-BEGIN --- # t2/package/*/openshadinglanguage/hotfix-threadsafe.patch # Copyright (C) 2025 The T2 SDE Project # SPDX-License-Identifier: GPL-2.0 or patched project license # --- T2-COPYRIGHT-END --- From 233a54a05679cdaeade79a26f13f8c6188984931 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 9 Oct 2025 21:34:32 +0200 Subject: [PATCH] fix: LLVM_Util::supports_isa is not thread-safe (#2029) The supports_isa() function might be called from threads, and prior to this change it might have added entries to the global sCpuFeatures variable. This happened when detect_cpu_features() is called with TargetISA::UNKNOWN and the code was looking for the best ISA. This could lead to situation when the host CPU is ARM, and the probing happens for AVX512. This change ensures that the supports_isa() accesses sCpuFeatures in the read-only manner. This was originally noticed as unreliable OSL render tests in Blender reported at https://projects.blender.org/blender/blender/issues/147642 Signed-off-by: Sergey Sharybin --- src/liboslexec/llvm_util.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/liboslexec/llvm_util.cpp b/src/liboslexec/llvm_util.cpp index f9b1296d6..2d9525675 100644 --- a/src/liboslexec/llvm_util.cpp +++ b/src/liboslexec/llvm_util.cpp @@ -1443,7 +1443,16 @@ LLVM_Util::supports_isa(TargetISA target) continue; } OSL_DEV_ONLY(std::cout << "Testing for cpu feature:" << f << std::endl); - if (sCpuFeatures[f] == false) { + // The required CPU feature for the specified target might not be in + // the sCpuFeatures. This happens, for example, when the code is probing + // the best target ISA when the requested one is UNKNOWN. In this case + // it is possible that this function is called for the TargetISA::AVX512 + // on an ARM CPU. + // This function might be called from multiple threads, so it is important + // to keep the access to sCpuFeatures read-only. + const auto cpu_feature_it = sCpuFeatures.find(f); + if (cpu_feature_it == sCpuFeatures.end() + || cpu_feature_it->second == false) { OSL_DEV_ONLY(std::cout << "MISSING cpu feature:" << f << std::endl); return false; }