From 63c3bafab748434ba025f2d3f45518b3ccb79cff Mon Sep 17 00:00:00 2001 From: Tony Tye Date: Fri, 13 Oct 2023 20:44:07 +0000 Subject: [PATCH] Support intercept queue with multiple packet rewriters If an intercept queue is created and multiple packet rewriters are registered, and if one of the rewriters invokes the packet writer multiple times, then on returning from the packet writer the packet rewriter index needs to be restored. Otherwise the next packet writer call will start with an index of 0 which will be decremented and result in out of bounds vector access. Change-Id: Icb3f6a81ea04f1f7b91551b974a1f48c4f32db60 [ROCm/ROCR-Runtime commit: b64a845105bead9bf6c6bc501cdf522617f86e78] --- .../runtime/hsa-runtime/core/runtime/intercept_queue.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/intercept_queue.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/intercept_queue.cpp index fe98e4bbf1..a6ba722b49 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/intercept_queue.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/intercept_queue.cpp @@ -167,9 +167,13 @@ bool InterceptQueue::HandleAsyncDoorbell(hsa_signal_value_t value, void* arg) { } void InterceptQueue::PacketWriter(const void* pkts, uint64_t pkt_count) { - Cursor.interceptor_index--; + assert(Cursor.interceptor_index > 0 && + "Packet intercept error: final submit handler must not call PacketWritter.\n"); + --Cursor.interceptor_index; auto& handler = Cursor.queue->interceptors[Cursor.interceptor_index]; handler.first(pkts, pkt_count, Cursor.pkt_index, handler.second, PacketWriter); + // Restore index as the same rewrite handler may call the PacketWriter more than once. + ++Cursor.interceptor_index; } void InterceptQueue::Submit(const void* pkts, uint64_t pkt_count, uint64_t user_pkt_index,