From b816d10802c0daa082477cd221d7c0bf6e2a1ecc Mon Sep 17 00:00:00 2001 From: Shadi Dashmiz <94885391+shadidashmiz@users.noreply.github.com> Date: Tue, 27 Jan 2026 15:25:14 -0500 Subject: [PATCH] Fix for pntr attri query from a peer device (#2722) * Fix for pntr attri query from a peer device Signed-off-by: sdashmiz * SWDEV-577116 : Fix qeury on peer device - if access is disabled query should return error. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Signed-off-by: sdashmiz Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- projects/clr/hipamd/src/hip_memory.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/projects/clr/hipamd/src/hip_memory.cpp b/projects/clr/hipamd/src/hip_memory.cpp index 5cde1a41ca..c297724217 100644 --- a/projects/clr/hipamd/src/hip_memory.cpp +++ b/projects/clr/hipamd/src/hip_memory.cpp @@ -3604,7 +3604,8 @@ hipError_t ihipPointerGetAttributes(void* data, hipPointer_attribute attribute, } case HIP_POINTER_ATTRIBUTE_DEVICE_POINTER: { if (memObj) { - device::Memory* devMem = memObj->getDeviceMemory(*hip::getCurrentDevice()->devices()[0]); + amd::Device* currentDevice = hip::getCurrentDevice()->devices()[0]; + device::Memory* devMem = memObj->getDeviceMemory(*currentDevice); // getDeviceMemory can fail, hence validate the sanity of the mem obtained if (nullptr == devMem) { @@ -3612,6 +3613,16 @@ hipError_t ihipPointerGetAttributes(void* data, hipPointer_attribute attribute, "getDeviceMemory for ptr failed : %p", ptr); return hipErrorMemoryAllocation; } + + // Check if this is a cross-device access without peer access enabled + const std::vector& memDevices = memObj->getContext().devices(); + if (memDevices.size() == 1 && memDevices[0] != currentDevice) { + device::Memory* origDevMem = memObj->getDeviceMemory(*memDevices[0]); + if (origDevMem != nullptr && !origDevMem->getAllowedPeerAccess()) { + return hipErrorInvalidValue; + } + } + *reinterpret_cast(data) = reinterpret_cast(devMem->virtualAddress() + offset); } else {