From 6f7cfcb7d547825c78ce41e0a98c4d65e2831557 Mon Sep 17 00:00:00 2001 From: "Zhang, Winston" Date: Fri, 20 Dec 2024 18:43:15 +0000 Subject: [PATCH] [L0] Fixes potential overwrite in ZeEventPoolDesc.pNext When both counterbased and interruptbased events are enabled there is a ZeEventPoolDesc.pNext will get overwritten in getFreeSlotInExistingOrNewPool. This fixes that. Signed-off-by: Zhang, Winston --- source/adapters/level_zero/context.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/source/adapters/level_zero/context.cpp b/source/adapters/level_zero/context.cpp index 169c8ec097..08f4762b6d 100644 --- a/source/adapters/level_zero/context.cpp +++ b/source/adapters/level_zero/context.cpp @@ -533,6 +533,13 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool( if (*ZePool == nullptr) { ze_event_pool_counter_based_exp_desc_t counterBasedExt = { ZE_STRUCTURE_TYPE_COUNTER_BASED_EVENT_POOL_EXP_DESC, nullptr, 0}; + + ze_intel_event_sync_mode_exp_desc_t eventSyncMode = { + ZE_INTEL_STRUCTURE_TYPE_EVENT_SYNC_MODE_EXP_DESC, nullptr, 0}; + eventSyncMode.syncModeFlags = + ZE_INTEL_EVENT_SYNC_MODE_EXP_FLAG_LOW_POWER_WAIT | + ZE_INTEL_EVENT_SYNC_MODE_EXP_FLAG_SIGNAL_INTERRUPT; + ZeStruct ZeEventPoolDesc; ZeEventPoolDesc.count = MaxNumEventsPerPool; ZeEventPoolDesc.flags = 0; @@ -552,14 +559,11 @@ ur_result_t ur_context_handle_t_::getFreeSlotInExistingOrNewPool( } logger::debug("ze_event_pool_desc_t counter based flags set to: {}", counterBasedExt.flags); + if (InterruptBasedEventEnabled) { + counterBasedExt.pNext = &eventSyncMode; + } ZeEventPoolDesc.pNext = &counterBasedExt; - } - if (InterruptBasedEventEnabled) { - ze_intel_event_sync_mode_exp_desc_t eventSyncMode = { - ZE_INTEL_STRUCTURE_TYPE_EVENT_SYNC_MODE_EXP_DESC, nullptr, 0}; - eventSyncMode.syncModeFlags = - ZE_INTEL_EVENT_SYNC_MODE_EXP_FLAG_LOW_POWER_WAIT | - ZE_INTEL_EVENT_SYNC_MODE_EXP_FLAG_SIGNAL_INTERRUPT; + } else if (InterruptBasedEventEnabled) { ZeEventPoolDesc.pNext = &eventSyncMode; }