From b020f66d3913edac2dd863277eaf3399e8f68c3e Mon Sep 17 00:00:00 2001 From: Tony Tye Date: Sat, 14 Oct 2023 02:31:24 +0000 Subject: [PATCH] Prevent accessing packets outside intercept queue When the intecept queue copies packets from the proxy queue to the wrapped queue, it should not attempt to copy packets that are outside the proxy queue. This could happen if the user of the proxy queue advances the write pointer beyond the number of free slots and the packet rewriter reduces the number of packets. Change-Id: Id02f5df8aee0ed7269f4de813731d507cf2126b3 --- runtime/hsa-runtime/core/runtime/intercept_queue.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/runtime/hsa-runtime/core/runtime/intercept_queue.cpp b/runtime/hsa-runtime/core/runtime/intercept_queue.cpp index a6ba722b49..0d1c2a70e2 100644 --- a/runtime/hsa-runtime/core/runtime/intercept_queue.cpp +++ b/runtime/hsa-runtime/core/runtime/intercept_queue.cpp @@ -302,6 +302,13 @@ void InterceptQueue::StoreRelaxed(hsa_signal_value_t value) { // Loop over valid packets and process. uint64_t end = LoadWriteIndexAcquire(); + + // Can only process packets that are occupying slots in the queue buffer. No + // need to add a barrier packet to ensure the extra packets are processed as + // the producer must ring the doorbell once the extra packets are made valid. + if (end > next_packet_ + amd_queue_.hsa_queue.size) + end = next_packet_ + amd_queue_.hsa_queue.size; + uint64_t i = next_packet_; while (i < end) { if (!ring[i & mask].IsValid()) break;