Mesa (staging/20.1): radv: Handle mmap failures.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Jun 24 20:44:03 UTC 2020
Module: Mesa
Branch: staging/20.1
Commit: c7332f7a782471c038eb3c129329d45e88d9ef98
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=c7332f7a782471c038eb3c129329d45e88d9ef98
Author: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Date: Sat Jun 20 21:12:01 2020 +0200
radv: Handle mmap failures.
Which can happen if we have to many mmaps active in the process.
CC: <mesa-stable at lists.freedesktop.org>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
(cherry picked from commit a5cb88eea45c02eb398117b2c52f1ef1626e2204)
---
.pick_status.json | 2 +-
src/amd/vulkan/radv_descriptor_set.c | 34 +++++++++++++++++++++++++---------
src/amd/vulkan/radv_device.c | 18 +++++++++++++++---
src/amd/vulkan/radv_shader.c | 17 +++++++++++++++++
4 files changed, 58 insertions(+), 13 deletions(-)
diff --git a/.pick_status.json b/.pick_status.json
index 114fe583ecd..dbc80cc12d3 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -31,7 +31,7 @@
"description": "radv: Handle mmap failures.",
"nominated": true,
"nomination_type": 0,
- "resolution": 0,
+ "resolution": 1,
"master_sha": null,
"because_sha": null
},
diff --git a/src/amd/vulkan/radv_descriptor_set.c b/src/amd/vulkan/radv_descriptor_set.c
index 126176a9706..6564a2aee38 100644
--- a/src/amd/vulkan/radv_descriptor_set.c
+++ b/src/amd/vulkan/radv_descriptor_set.c
@@ -615,6 +615,22 @@ radv_descriptor_set_destroy(struct radv_device *device,
vk_free2(&device->alloc, NULL, set);
}
+static void radv_destroy_descriptor_pool(struct radv_device *device,
+ const VkAllocationCallbacks *pAllocator,
+ struct radv_descriptor_pool *pool)
+{
+ if (!pool->host_memory_base) {
+ for(int i = 0; i < pool->entry_count; ++i) {
+ radv_descriptor_set_destroy(device, pool, pool->entries[i].set, false);
+ }
+ }
+
+ if (pool->bo)
+ device->ws->buffer_destroy(pool->bo);
+
+ vk_free2(&device->alloc, pAllocator, pool);
+}
+
VkResult radv_CreateDescriptorPool(
VkDevice _device,
const VkDescriptorPoolCreateInfo* pCreateInfo,
@@ -704,7 +720,15 @@ VkResult radv_CreateDescriptorPool(
RADEON_FLAG_READ_ONLY |
RADEON_FLAG_32BIT,
RADV_BO_PRIORITY_DESCRIPTOR);
+ if (!pool->bo) {
+ radv_destroy_descriptor_pool(device, pAllocator, pool);
+ return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
+ }
pool->mapped_ptr = (uint8_t*)device->ws->buffer_map(pool->bo);
+ if (!pool->mapped_ptr) {
+ radv_destroy_descriptor_pool(device, pAllocator, pool);
+ return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
+ }
}
pool->size = bo_size;
pool->max_entry_count = pCreateInfo->maxSets;
@@ -724,15 +748,7 @@ void radv_DestroyDescriptorPool(
if (!pool)
return;
- if (!pool->host_memory_base) {
- for(int i = 0; i < pool->entry_count; ++i) {
- radv_descriptor_set_destroy(device, pool, pool->entries[i].set, false);
- }
- }
-
- if (pool->bo)
- device->ws->buffer_destroy(pool->bo);
- vk_free2(&device->alloc, pAllocator, pool);
+ radv_destroy_descriptor_pool(device, pAllocator, pool);
}
VkResult radv_ResetDescriptorPool(
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index 9cfcbe6c23b..e43b1ccf36b 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -3965,6 +3965,8 @@ radv_get_preamble_cs(struct radv_queue *queue,
if (descriptor_bo != queue->descriptor_bo) {
uint32_t *map = (uint32_t*)queue->device->ws->buffer_map(descriptor_bo);
+ if (!map)
+ goto fail;
if (scratch_bo) {
uint64_t scratch_va = radv_buffer_get_va(scratch_bo);
@@ -6218,7 +6220,13 @@ radv_SignalSemaphore(VkDevice _device,
return VK_SUCCESS;
}
-
+static void radv_destroy_event(struct radv_device *device,
+ const VkAllocationCallbacks* pAllocator,
+ struct radv_event *event)
+{
+ device->ws->buffer_destroy(event->bo);
+ vk_free2(&device->alloc, pAllocator, event);
+}
VkResult radv_CreateEvent(
VkDevice _device,
@@ -6244,6 +6252,10 @@ VkResult radv_CreateEvent(
}
event->map = (uint64_t*)device->ws->buffer_map(event->bo);
+ if (!event->map) {
+ radv_destroy_event(device, pAllocator, event);
+ return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
+ }
*pEvent = radv_event_to_handle(event);
@@ -6260,8 +6272,8 @@ void radv_DestroyEvent(
if (!event)
return;
- device->ws->buffer_destroy(event->bo);
- vk_free2(&device->alloc, pAllocator, event);
+
+ radv_destroy_event(device, pAllocator, event);
}
VkResult radv_GetEventStatus(
diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c
index 36a7b5f5511..3a3ddaa2215 100644
--- a/src/amd/vulkan/radv_shader.c
+++ b/src/amd/vulkan/radv_shader.c
@@ -662,7 +662,18 @@ radv_alloc_shader_memory(struct radv_device *device,
(device->physical_device->rad_info.cpdma_prefetch_writes_memory ?
0 : RADEON_FLAG_READ_ONLY),
RADV_BO_PRIORITY_SHADER);
+ if (!slab->bo) {
+ free(slab);
+ return NULL;
+ }
+
slab->ptr = (char*)device->ws->buffer_map(slab->bo);
+ if (!slab->ptr) {
+ device->ws->buffer_destroy(slab->bo);
+ free(slab);
+ return NULL;
+ }
+
list_inithead(&slab->shaders);
mtx_lock(&device->shader_slab_mutex);
@@ -1006,6 +1017,12 @@ radv_shader_variant_create(struct radv_device *device,
}
void *dest_ptr = radv_alloc_shader_memory(device, variant);
+ if (!dest_ptr) {
+ if (binary->type == RADV_BINARY_TYPE_RTLD)
+ ac_rtld_close(&rtld_binary);
+ free(variant);
+ return NULL;
+ }
if (binary->type == RADV_BINARY_TYPE_RTLD) {
struct radv_shader_binary_rtld* bin = (struct radv_shader_binary_rtld *)binary;
More information about the mesa-commit
mailing list