[Mesa-stable] [PATCH] anv: Add the pci_id into the shader cache UUID

Jason Ekstrand jason at jlekstrand.net
Sat Feb 25 01:15:56 UTC 2017


This prevents a user from using a cache created on one hardware
generation on a different one.  Of course, with Intel hardware, this
requires moving their drive from one machine to another but it's still
possible and we should prevent it.
---
 src/intel/vulkan/anv_device.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index f80a36a..ec02d3f 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -31,6 +31,7 @@
 #include <fcntl.h>
 
 #include "anv_private.h"
+#include "util/mesa-sha1.h"
 #include "util/strtod.h"
 #include "util/debug.h"
 
@@ -70,15 +71,24 @@ anv_get_function_timestamp(void *ptr, uint32_t* timestamp)
 }
 
 static bool
-anv_device_get_cache_uuid(void *uuid)
+anv_device_get_cache_uuid(void *uuid, uint16_t pci_id)
 {
    uint32_t timestamp;
 
-   memset(uuid, 0, VK_UUID_SIZE);
    if (!anv_get_function_timestamp(anv_device_get_cache_uuid, &timestamp))
       return false;
 
-   snprintf(uuid, VK_UUID_SIZE, "anv-%d", timestamp);
+   uint8_t sha1[20];
+   struct mesa_sha1 *sha1_ctx = _mesa_sha1_init();
+   if (sha1_ctx == NULL)
+      return false;
+
+   _mesa_sha1_update(sha1_ctx, &timestamp, sizeof(timestamp));
+   _mesa_sha1_update(sha1_ctx, &pci_id, sizeof(pci_id));
+   _mesa_sha1_final(sha1_ctx, sha1);
+
+   memcpy(uuid, sha1, VK_UUID_SIZE);
+
    return true;
 }
 
@@ -163,7 +173,7 @@ anv_physical_device_init(struct anv_physical_device *device,
       goto fail;
    }
 
-   if (!anv_device_get_cache_uuid(device->uuid)) {
+   if (!anv_device_get_cache_uuid(device->uuid, device->chipset_id)) {
       result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
                          "cannot generate UUID");
       goto fail;
-- 
2.5.0.400.gff86faf



More information about the mesa-stable mailing list