[Bf-blender-cvs] [a3df65d] master: Fix T47008: OSL Memory Corruption (Use after free)

Sergey Sharybin noreply at git.blender.org
Sun Jan 3 14:37:10 CET 2016


Commit: a3df65dea819309496447a26ddf4d7dbe0c3203a
Author: Sergey Sharybin
Date:   Sun Jan 3 18:28:33 2016 +0500
Branches: master
https://developer.blender.org/rBa3df65dea819309496447a26ddf4d7dbe0c3203a

Fix T47008: OSL Memory Corruption (Use after free)

The issue was caused by OSL using TLS which is required to be freed before the
Cycles session is freed. This is quite tricky to do in Cycles because different
render session are sharing the same task scheduler, so when one session is being
freed TLS might need to be active still.

In order to solve this, we are now doing JIT optimization ahead of the time
which ensures either TLS of JIT is freed before the render on multi-core system
or freed on OSLRenderSession destroy on single-core system.

This might increase synchronization time due to JIT of unused function, but
that we can solve later with some smart idea,

===================================================================

M	intern/cycles/render/osl.cpp

===================================================================

diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp
index 4933ed6..e5842c7 100644
--- a/intern/cycles/render/osl.cpp
+++ b/intern/cycles/render/osl.cpp
@@ -125,11 +125,21 @@ void OSLShaderManager::device_update(Device *device, DeviceScene *dscene, Scene
 
 	device_update_common(device, dscene, scene, progress);
 
-	/* greedyjit test
 	{
+		/* Perform greedyjit optimization.
+		 *
+		 * This might waste time on optimizing gorups which are never actually
+		 * used, but this prevents OSL from allocating data on TLS at render
+		 * time.
+		 *
+		 * This is much better for us because this way we aren't required to
+		 * stop task scheduler threads to make sure all TLS is clean and don't
+		 * have issues with TLS data free accessing freed memory if task scheduler
+		 * is being freed after the Session is freed.
+		 */
 		thread_scoped_lock lock(ss_shared_mutex);
 		ss->optimize_all_groups();
-	}*/
+	}
 }
 
 void OSLShaderManager::device_free(Device *device, DeviceScene *dscene, Scene *scene)
@@ -195,7 +205,7 @@ void OSLShaderManager::shading_system_init()
 		ss_shared->attribute("lockgeom", 1);
 		ss_shared->attribute("commonspace", "world");
 		ss_shared->attribute("searchpath:shader", path_get("shader"));
-		//ss_shared->attribute("greedyjit", 1);
+		ss_shared->attribute("greedyjit", 1);
 
 		VLOG(1) << "Using shader search path: " << path_get("shader");




More information about the Bf-blender-cvs mailing list