radv: allow the secure process to read and write from disk cache

This allows the secure process to read and write to the disk cache
via the parent process. This commit just adds the functionality
needed for the secure process, the following commit will add the
functionality for the parent process.

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
This commit is contained in:
Timothy Arceri
2019-07-31 13:50:52 +10:00
parent 5d25aee005
commit 5cd437b1ed

View File

@@ -243,6 +243,63 @@ radv_is_cache_disabled(struct radv_device *device)
return (device->instance->debug_flags & RADV_DEBUG_NO_CACHE); return (device->instance->debug_flags & RADV_DEBUG_NO_CACHE);
} }
/*
* Secure compiles cannot open files so we get the parent process to load the
* cache entry for us.
*/
static struct cache_entry *
radv_sc_read_from_disk_cache(struct radv_device *device, uint8_t *disk_sha1)
{
struct cache_entry *entry;
unsigned process = device->sc_state->secure_compile_thread_counter;
enum radv_secure_compile_type sc_type = RADV_SC_TYPE_READ_DISK_CACHE;
write(device->sc_state->secure_compile_processes[process].fd_secure_output,
&sc_type, sizeof(enum radv_secure_compile_type));
write(device->sc_state->secure_compile_processes[process].fd_secure_output,
disk_sha1, sizeof(uint8_t) * 20);
uint8_t found_cache_entry;
read(device->sc_state->secure_compile_processes[process].fd_secure_input,
&found_cache_entry, sizeof(uint8_t));
if (found_cache_entry) {
size_t entry_size;
read(device->sc_state->secure_compile_processes[process].fd_secure_input,
&entry_size, sizeof(size_t));
entry = malloc(entry_size);
read(device->sc_state->secure_compile_processes[process].fd_secure_input,
entry, entry_size);
return entry;
}
return NULL;
}
/*
* Secure compiles cannot open files so we get the parent process to write to
* the disk cache for us.
*/
static void
radv_sc_write_to_disk_cache(struct radv_device *device, uint8_t *disk_sha1,
struct cache_entry *entry)
{
unsigned process = device->sc_state->secure_compile_thread_counter;
enum radv_secure_compile_type sc_type = RADV_SC_TYPE_WRITE_DISK_CACHE;
write(device->sc_state->secure_compile_processes[process].fd_secure_output,
&sc_type, sizeof(enum radv_secure_compile_type));
write(device->sc_state->secure_compile_processes[process].fd_secure_output,
disk_sha1, sizeof(uint8_t) * 20);
uint32_t size = entry_size(entry);
write(device->sc_state->secure_compile_processes[process].fd_secure_output,
&size, sizeof(uint32_t));
write(device->sc_state->secure_compile_processes[process].fd_secure_output,
entry, size);
}
bool bool
radv_create_shader_variants_from_pipeline_cache(struct radv_device *device, radv_create_shader_variants_from_pipeline_cache(struct radv_device *device,
struct radv_pipeline_cache *cache, struct radv_pipeline_cache *cache,
@@ -275,9 +332,15 @@ radv_create_shader_variants_from_pipeline_cache(struct radv_device *device,
uint8_t disk_sha1[20]; uint8_t disk_sha1[20];
disk_cache_compute_key(device->physical_device->disk_cache, disk_cache_compute_key(device->physical_device->disk_cache,
sha1, 20, disk_sha1); sha1, 20, disk_sha1);
entry = (struct cache_entry *)
disk_cache_get(device->physical_device->disk_cache, if (radv_device_use_secure_compile(device->instance)) {
disk_sha1, NULL); entry = radv_sc_read_from_disk_cache(device, disk_sha1);
} else {
entry = (struct cache_entry *)
disk_cache_get(device->physical_device->disk_cache,
disk_sha1, NULL);
}
if (!entry) { if (!entry) {
pthread_mutex_unlock(&cache->mutex); pthread_mutex_unlock(&cache->mutex);
return false; return false;
@@ -402,8 +465,17 @@ radv_pipeline_cache_insert_shaders(struct radv_device *device,
uint8_t disk_sha1[20]; uint8_t disk_sha1[20];
disk_cache_compute_key(device->physical_device->disk_cache, sha1, 20, disk_cache_compute_key(device->physical_device->disk_cache, sha1, 20,
disk_sha1); disk_sha1);
disk_cache_put(device->physical_device->disk_cache,
disk_sha1, entry, entry_size(entry), NULL); /* Write the cache item out to the parent of this forked
* process.
*/
if (radv_device_use_secure_compile(device->instance)) {
radv_sc_write_to_disk_cache(device, disk_sha1, entry);
} else {
disk_cache_put(device->physical_device->disk_cache,
disk_sha1, entry, entry_size(entry),
NULL);
}
} }
if (device->instance->debug_flags & RADV_DEBUG_NO_MEMORY_CACHE && if (device->instance->debug_flags & RADV_DEBUG_NO_MEMORY_CACHE &&