anv: fix uninitialized variable access
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Thu, 9 Jul 2020 15:12:17 +0000 (18:12 +0300)
committerMarge Bot <eric+marge@anholt.net>
Fri, 10 Jul 2020 17:54:35 +0000 (17:54 +0000)
Found with valgrind :

  ==415016== Conditional jump or move depends on uninitialised value(s)
  ==415016==    at 0x513C22B: anv_cache_lock (anv_pipeline_cache.c:346)
  ==415016==    by 0x513C2A0: anv_pipeline_cache_search (anv_pipeline_cache.c:364)
  ==415016==    by 0x50E7C88: lookup_blorp_shader (anv_blorp.c:38)
  ==415016==    by 0x5D20A98: blorp_params_get_clear_kernel (blorp_clear.c:60)
  ==415016==    by 0x5D23EFD: blorp_ccs_ambiguate (blorp_clear.c:1358)
  ==415016==    by 0x50EDE25: anv_image_ccs_op (anv_blorp.c:1882)
  ==415016==    by 0x555D92F: transition_color_buffer (genX_cmd_buffer.c:1179)
  ==415016==    by 0x5598B71: cmd_buffer_begin_subpass (genX_cmd_buffer.c:5060)
  ==415016==    by 0x559AB00: gen9_CmdBeginRenderPass (genX_cmd_buffer.c:5772)
  ==415016==    by 0x11DACE: begin_render_pass (vr-test.c:375)
  ==415016==    by 0x11DF55: set_state (vr-test.c:529)
  ==415016==    by 0x11F7A1: clear (vr-test.c:1228)

v2: Don't break external sync feature

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Acked-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Ivan Briano <ivan.briano@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5823>

src/intel/vulkan/anv_device.c
src/intel/vulkan/anv_pipeline_cache.c
src/intel/vulkan/anv_private.h

index f25d89a916573cb6c9e1df069434c6c7da63adf5..f6b41b79de651a4bc4c738bcffa76f9e903e909c 100644 (file)
@@ -2983,7 +2983,8 @@ VkResult anv_CreateDevice(
    if (result != VK_SUCCESS)
       goto fail_clear_value_bo;
 
-   anv_pipeline_cache_init(&device->default_pipeline_cache, device, true);
+   anv_pipeline_cache_init(&device->default_pipeline_cache, device,
+                           true /* cache_enabled */, false /* external_sync */);
 
    anv_device_init_blorp(device);
 
index 2c6ecb7fbc9ce0519716543c1a92f5667036d036..ac2326c66487fc4d83ba9b094b57a2ece16478b2 100644 (file)
@@ -280,11 +280,13 @@ sha1_compare_func(const void *sha1_a, const void *sha1_b)
 void
 anv_pipeline_cache_init(struct anv_pipeline_cache *cache,
                         struct anv_device *device,
-                        bool cache_enabled)
+                        bool cache_enabled,
+                        bool external_sync)
 {
    vk_object_base_init(&device->vk, &cache->base,
                        VK_OBJECT_TYPE_PIPELINE_CACHE);
    cache->device = device;
+   cache->external_sync = external_sync;
    pthread_mutex_init(&cache->mutex, NULL);
 
    if (cache_enabled) {
@@ -538,11 +540,9 @@ VkResult anv_CreatePipelineCache(
    if (cache == NULL)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
-   cache->external_sync =
-      (pCreateInfo->flags & VK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT_EXT);
-
    anv_pipeline_cache_init(cache, device,
-                           device->physical->instance->pipeline_cache_enabled);
+                           device->physical->instance->pipeline_cache_enabled,
+                           pCreateInfo->flags & VK_PIPELINE_CACHE_CREATE_EXTERNALLY_SYNCHRONIZED_BIT_EXT);
 
    if (pCreateInfo->initialDataSize > 0)
       anv_pipeline_cache_load(cache,
index e31e6a6579e601355fd9fc33c0eef5e166abe289..9500b41deadcc0afd39351d191a4afc7c4a86a5e 100644 (file)
@@ -1253,7 +1253,8 @@ struct anv_pipeline_bind_map;
 
 void anv_pipeline_cache_init(struct anv_pipeline_cache *cache,
                              struct anv_device *device,
-                             bool cache_enabled);
+                             bool cache_enabled,
+                             bool external_sync);
 void anv_pipeline_cache_finish(struct anv_pipeline_cache *cache);
 
 struct anv_shader_bin *