From dae04016ed35effcd4356c0df1f508891ec8f279 Mon Sep 17 00:00:00 2001 From: Bas Nieuwenhuizen Date: Sat, 29 Aug 2020 03:25:02 +0200 Subject: [PATCH] radv: Fix threading issue with submission refcounts. If decrement == 0 then: - it isn't safe to access the submission - even if it is, checking that the result of the atomic_sub is 0 doesn't given an unique owner anymore. So skip it. The submission always starts out with refcount >= 1, so first one to decrement to 0 still get dibs on executing it. Fixes: 4aa75bb3bdd "radv: Add wait-before-submit support for timelines." Reviewed-by: Samuel Pitoiset Part-of: (cherry picked from commit 6b75262941b55960e2f73d93f85020fa6c9c2d2f) --- .pick_status.json | 2 +- src/amd/vulkan/radv_device.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index f1b623cada4..b09828901d3 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2965,7 +2965,7 @@ "description": "radv: Fix threading issue with submission refcounts.", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "master_sha": null, "because_sha": "4aa75bb3bdd195d4715ee8fae51bfb0c0fcd823b" }, diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index 745ef636ae1..bb97cd86543 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -4312,6 +4312,12 @@ radv_queue_enqueue_submission(struct radv_deferred_queue_submission *submission, * submitted, but if the queue was empty, we decrement ourselves as there is no previous * submission. */ uint32_t decrement = submission->wait_semaphore_count - wait_cnt + (is_first ? 1 : 0); + + /* if decrement is zero, then we don't have a refcounted reference to the + * submission anymore, so it is not safe to access the submission. */ + if (!decrement) + return VK_SUCCESS; + return radv_queue_trigger_submission(submission, decrement, processing_list); }