From d5ec2fa52f9bfbc96a0d56a149b6c85f1e4e3b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Wed, 24 Jan 2024 08:54:47 -0800 Subject: [PATCH] anv: Fix calculation of syncs required in Xe KMD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit num_syncs was being incremented by one if 'utrace_submit != NULL' but a sync was only being set if also 'util_dynarray_num_elements(&utrace_submit->batch_bos) == 0'. This mismatch could cause application to abort due to 'assert(count == num_syncs)'. Signed-off-by: José Roberto de Souza Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/vulkan/xe/anv_batch_chain.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/intel/vulkan/xe/anv_batch_chain.c b/src/intel/vulkan/xe/anv_batch_chain.c index 22ccaa4763a..5c9fed16ccb 100644 --- a/src/intel/vulkan/xe/anv_batch_chain.c +++ b/src/intel/vulkan/xe/anv_batch_chain.c @@ -114,9 +114,15 @@ xe_exec_process_syncs(struct anv_queue *queue, struct drm_xe_sync **ret, uint32_t *ret_count) { struct anv_device *device = queue->device; - uint32_t num_syncs = wait_count + signal_count + extra_sync_count + - (utrace_submit ? 1 : 0) + - ((queue->sync && !is_companion_rcs_queue) ? 1 : 0); + /* Signal the utrace sync only if it doesn't have a batch. Otherwise the + * it's the utrace batch that should signal its own sync. + */ + const bool has_utrace_sync = utrace_submit && + util_dynarray_num_elements(&utrace_submit->batch_bos, struct anv_bo *) == 0; + const uint32_t num_syncs = wait_count + signal_count + extra_sync_count + + (has_utrace_sync ? 1 : 0) + + ((queue->sync && !is_companion_rcs_queue) ? 1 : 0); + if (!num_syncs) return VK_SUCCESS; @@ -128,12 +134,7 @@ xe_exec_process_syncs(struct anv_queue *queue, uint32_t count = 0; - /* Signal the utrace sync only if it doesn't have a batch. Otherwise the - * it's the utrace batch that should signal its own sync. - */ - if (utrace_submit && - util_dynarray_num_elements(&utrace_submit->batch_bos, - struct anv_bo *) == 0) { + if (has_utrace_sync) { struct drm_xe_sync *xe_sync = &xe_syncs[count++]; xe_exec_fill_sync(xe_sync, utrace_submit->sync, 0, TYPE_SIGNAL);