From 054b7e8f4a8ca7e58a93ed295b20738f297eabfc Mon Sep 17 00:00:00 2001 From: Julian Brown Date: Mon, 14 Oct 2024 17:28:27 -0400 Subject: [PATCH] Fix uninitialised vars in memory-pool setup in offload runtime This patch fixes a bug in the AMDGPU offload plugin during initialisation of memory pools. The function preAllocateDeviceMemoryPool is called (only) from a location where memory pool metadata structures have already been enumerated and initialised (in initImpl, by calling initMemoryPools). But it then calls retrieveMemoryPools *again*, but does not go on to initialise the newly-created duplicate metadata properly before using it, meaning some fields (Segment, GlobalFlags) are left with uninitialised data. That can lead to unpredictable behaviour. The fix is just to remove the "retrieval", i.e. allocation, of duplicate pool metadata. Change-Id: I7cd7e46c0f2c655a8007299595c553f33451ccb1 --- offload/plugins-nextgen/amdgpu/src/rtl.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/offload/plugins-nextgen/amdgpu/src/rtl.cpp b/offload/plugins-nextgen/amdgpu/src/rtl.cpp index bbc90279e24afb..544f036259e269 100644 --- a/offload/plugins-nextgen/amdgpu/src/rtl.cpp +++ b/offload/plugins-nextgen/amdgpu/src/rtl.cpp @@ -4096,9 +4096,6 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy { /// Allocate and zero initialize a small memory pool from the coarse grained /// device memory of each device. Error preAllocateDeviceMemoryPool() { - Error Err = retrieveAllMemoryPools(); - if (Err) - return Plugin::error("Unable to retieve all memmory pools"); void *DevPtr; for (AMDGPUMemoryPoolTy *MemoryPool : AllMemoryPools) { @@ -4109,7 +4106,7 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy { DevPtr = nullptr; size_t PreAllocSize = hsa_utils::PER_DEVICE_PREALLOC_SIZE; - Err = MemoryPool->allocate(PreAllocSize, &DevPtr); + Error Err = MemoryPool->allocate(PreAllocSize, &DevPtr); if (Err) return Plugin::error("Device memory pool preallocation failed");