From dd61f54171a7ffa0e0591dd51d42ab7ec40c171b Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Thu, 14 Sep 2023 13:55:00 +0000 Subject: [PATCH] Fix hsa_amd_vmem_get_access to accept offset pointers Modify hsa_amd_vmem_get_access to handle pointers that are within VA range of an existing memory mapping Change-Id: I9f806ec39f6e9a33da8d86dd65d9a472438fa8ed --- runtime/hsa-runtime/core/runtime/runtime.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/runtime/hsa-runtime/core/runtime/runtime.cpp b/runtime/hsa-runtime/core/runtime/runtime.cpp index 8d7b133957..3c9967eab0 100644 --- a/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -2771,13 +2771,20 @@ hsa_status_t Runtime::VMemorySetAccess(void* va, size_t size, hsa_status_t Runtime::VMemoryGetAccess(const void* va, hsa_access_permission_t* perms, hsa_agent_t agent_handle) { *perms = HSA_ACCESS_PERMISSION_NONE; + bool mappedHandleFound = false; ScopedAcquire lock(&memory_lock_); - auto mappedHandleIt = mapped_handle_map_.find(va); - if (mappedHandleIt == mapped_handle_map_.end()) { - return HSA_STATUS_ERROR_INVALID_ALLOCATION; + auto mappedHandleIt = mapped_handle_map_.upper_bound(va); + if (mappedHandleIt != mapped_handle_map_.begin()) { + mappedHandleIt--; + if ((mappedHandleIt->first <= va) && + reinterpret_cast(va) <= + (reinterpret_cast(mappedHandleIt->first) + mappedHandleIt->second.size)) { + mappedHandleFound = true; + } } + if (!mappedHandleFound) return HSA_STATUS_ERROR_INVALID_ALLOCATION; Agent* agent = Agent::Convert(agent_handle); if (agent == NULL || !agent->IsValid() || agent->device_type() != core::Agent::kAmdGpuDevice)