summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Ekstrand <jason.ekstrand@intel.com>2017-02-24 16:36:00 -0800
committerJason Ekstrand <jason.ekstrand@intel.com>2017-04-14 17:41:07 -0700
commitd2d6cf6c8387ac06c8559027f57683a61b48671b (patch)
tree1eba30197717ab52f67adebee66e6eb117651a24
parent36f21017237ab536db74c84e0f778d3a58271c75 (diff)
anv: Add the pci_id into the shader cache UUID
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. Reviewed-by: Chad Versace <chadversary@chromium.org> Cc: mesa-stable@lists.freedesktop.org
-rw-r--r--src/intel/vulkan/anv_device.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index ee9c48fa73..8f4625ba00 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -34,6 +34,7 @@
#include "util/strtod.h"
#include "util/debug.h"
#include "util/build_id.h"
+#include "util/mesa-sha1.h"
#include "util/vk_util.h"
#include "genxml/gen7_pack.h"
@@ -97,17 +98,26 @@ anv_compute_heap_size(int fd, uint64_t *heap_size)
}
static bool
-anv_device_get_cache_uuid(void *uuid)
+anv_device_get_cache_uuid(void *uuid, uint16_t pci_id)
{
const struct build_id_note *note = build_id_find_nhdr("libvulkan_intel.so");
if (!note)
return false;
- unsigned len = build_id_length(note);
- if (len < VK_UUID_SIZE)
+ unsigned build_id_len = build_id_length(note);
+ if (build_id_len < 20) /* It should be a SHA-1 */
return false;
- memcpy(uuid, build_id_data(note), VK_UUID_SIZE);
+ struct mesa_sha1 sha1_ctx;
+ uint8_t sha1[20];
+ STATIC_ASSERT(VK_UUID_SIZE <= sizeof(sha1));
+
+ _mesa_sha1_init(&sha1_ctx);
+ _mesa_sha1_update(&sha1_ctx, build_id_data(note), build_id_len);
+ _mesa_sha1_update(&sha1_ctx, &pci_id, sizeof(pci_id));
+ _mesa_sha1_final(&sha1_ctx, sha1);
+
+ memcpy(uuid, sha1, VK_UUID_SIZE);
return true;
}
@@ -192,7 +202,7 @@ anv_physical_device_init(struct anv_physical_device *device,
if (result != VK_SUCCESS)
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;