mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-25 13:33:02 +08:00
Fail when handle cannot be obtain for an allocation
If a handle cannot be obtained, like PRIME_HANDLE_TO_FD, then properly check for the error and propagate it upwards. Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
ddd5dd99ef
commit
4dfdbd612d
@@ -37,20 +37,24 @@ std::string DrmAllocation::getAllocationInfoString() const {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
uint64_t DrmAllocation::peekInternalHandle(MemoryManager *memoryManager) {
|
||||
if (handles[0] != std::numeric_limits<uint32_t>::max()) {
|
||||
return handles[0];
|
||||
}
|
||||
handles[0] = static_cast<uint64_t>((static_cast<DrmMemoryManager *>(memoryManager))->obtainFdFromHandle(getBO()->peekHandle(), this->rootDeviceIndex));
|
||||
return handles[0];
|
||||
int DrmAllocation::peekInternalHandle(MemoryManager *memoryManager, uint64_t &handle) {
|
||||
return peekInternalHandle(memoryManager, 0u, handle);
|
||||
}
|
||||
|
||||
uint64_t DrmAllocation::peekInternalHandle(MemoryManager *memoryManager, uint32_t handleId) {
|
||||
if (handles[handleId] != std::numeric_limits<uint32_t>::max()) {
|
||||
return handles[handleId];
|
||||
int DrmAllocation::peekInternalHandle(MemoryManager *memoryManager, uint32_t handleId, uint64_t &handle) {
|
||||
if (handles[handleId] != std::numeric_limits<uint64_t>::max()) {
|
||||
handle = handles[handleId];
|
||||
return 0;
|
||||
}
|
||||
handles[handleId] = static_cast<uint64_t>((static_cast<DrmMemoryManager *>(memoryManager))->obtainFdFromHandle(getBufferObjectToModify(handleId)->peekHandle(), this->rootDeviceIndex));
|
||||
return handles[handleId];
|
||||
|
||||
int64_t ret = static_cast<int64_t>((static_cast<DrmMemoryManager *>(memoryManager))->obtainFdFromHandle(getBufferObjectToModify(handleId)->peekHandle(), this->rootDeviceIndex));
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
handle = handles[handleId] = ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DrmAllocation::setCachePolicy(CachePolicy memType) {
|
||||
|
||||
@@ -40,7 +40,7 @@ class DrmAllocation : public GraphicsAllocation {
|
||||
DrmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, BufferObject *bo, void *ptrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool pool, uint64_t canonizedGpuAddress)
|
||||
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, ptrIn, sizeIn, sharedHandle, pool, MemoryManager::maxOsContextCount, canonizedGpuAddress), bufferObjects(EngineLimits::maxHandleCount) {
|
||||
bufferObjects[0] = bo;
|
||||
handles.resize(EngineLimits::maxHandleCount, std::numeric_limits<uint32_t>::max());
|
||||
handles.resize(EngineLimits::maxHandleCount, std::numeric_limits<uint64_t>::max());
|
||||
}
|
||||
|
||||
DrmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, BufferObject *bo, void *ptrIn, uint64_t canonizedGpuAddress, size_t sizeIn, MemoryPool pool)
|
||||
@@ -49,7 +49,7 @@ class DrmAllocation : public GraphicsAllocation {
|
||||
DrmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, BufferObject *bo, void *ptrIn, uint64_t canonizedGpuAddress, size_t sizeIn, MemoryPool pool)
|
||||
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, ptrIn, canonizedGpuAddress, 0, sizeIn, pool, MemoryManager::maxOsContextCount), bufferObjects(EngineLimits::maxHandleCount) {
|
||||
bufferObjects[0] = bo;
|
||||
handles.resize(EngineLimits::maxHandleCount, std::numeric_limits<uint32_t>::max());
|
||||
handles.resize(EngineLimits::maxHandleCount, std::numeric_limits<uint64_t>::max());
|
||||
}
|
||||
|
||||
DrmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, BufferObjects &bos, void *ptrIn, uint64_t canonizedGpuAddress, size_t sizeIn, MemoryPool pool)
|
||||
@@ -58,7 +58,7 @@ class DrmAllocation : public GraphicsAllocation {
|
||||
DrmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, BufferObjects &bos, void *ptrIn, uint64_t canonizedGpuAddress, size_t sizeIn, MemoryPool pool)
|
||||
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, ptrIn, canonizedGpuAddress, 0, sizeIn, pool, MemoryManager::maxOsContextCount),
|
||||
bufferObjects(bos) {
|
||||
handles.resize(EngineLimits::maxHandleCount, std::numeric_limits<uint32_t>::max());
|
||||
handles.resize(EngineLimits::maxHandleCount, std::numeric_limits<uint64_t>::max());
|
||||
}
|
||||
|
||||
~DrmAllocation() override;
|
||||
@@ -74,7 +74,7 @@ class DrmAllocation : public GraphicsAllocation {
|
||||
const BufferObjects &getBOs() const {
|
||||
return this->bufferObjects;
|
||||
}
|
||||
BufferObject *&getBufferObjectToModify(uint32_t handleIndex) {
|
||||
MOCKABLE_VIRTUAL BufferObject *&getBufferObjectToModify(uint32_t handleIndex) {
|
||||
return bufferObjects[handleIndex];
|
||||
}
|
||||
|
||||
@@ -90,9 +90,9 @@ class DrmAllocation : public GraphicsAllocation {
|
||||
this->numHandles = numHandles;
|
||||
}
|
||||
|
||||
uint64_t peekInternalHandle(MemoryManager *memoryManager) override;
|
||||
int peekInternalHandle(MemoryManager *memoryManager, uint64_t &handle) override;
|
||||
|
||||
uint64_t peekInternalHandle(MemoryManager *memoryManager, uint32_t handleId) override;
|
||||
int peekInternalHandle(MemoryManager *memoryManager, uint32_t handleId, uint64_t &handle) override;
|
||||
|
||||
bool setCacheRegion(Drm *drm, CacheRegion regionIndex);
|
||||
bool setCacheAdvice(Drm *drm, size_t regionSize, CacheRegion regionIndex);
|
||||
|
||||
@@ -978,7 +978,11 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromExistingStorag
|
||||
properties.size = defaultAlloc->getUnderlyingBufferSize();
|
||||
properties.gpuAddress = castToUint64(ptr);
|
||||
|
||||
auto internalHandle = defaultAlloc->peekInternalHandle(this);
|
||||
uint64_t internalHandle = 0;
|
||||
int ret = defaultAlloc->peekInternalHandle(this, internalHandle);
|
||||
if (ret < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
return createUSMHostAllocationFromSharedHandle(static_cast<osHandle>(internalHandle), properties, true);
|
||||
} else {
|
||||
return allocateGraphicsMemoryWithProperties(properties, ptr);
|
||||
@@ -1114,7 +1118,10 @@ int DrmMemoryManager::obtainFdFromHandle(int boHandle, uint32_t rootDeviceIndex)
|
||||
openFd.flags = ioctlHelper->getFlagsForPrimeHandleToFd();
|
||||
openFd.handle = boHandle;
|
||||
|
||||
ioctlHelper->ioctl(DrmIoctl::PrimeHandleToFd, &openFd);
|
||||
int ret = ioctlHelper->ioctl(DrmIoctl::PrimeHandleToFd, &openFd);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return openFd.fileDescriptor;
|
||||
}
|
||||
|
||||
@@ -72,8 +72,9 @@ class WddmAllocation : public GraphicsAllocation {
|
||||
handles[handleIndex] = handle;
|
||||
}
|
||||
|
||||
uint64_t peekInternalHandle(MemoryManager *memoryManager) override {
|
||||
return ntSecureHandle;
|
||||
int peekInternalHandle(MemoryManager *memoryManager, uint64_t &handle) override {
|
||||
handle = ntSecureHandle;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t *getSharedHandleToModify() {
|
||||
|
||||
@@ -557,8 +557,10 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation
|
||||
for (auto handleId = 0u; handleId < gfxAllocation->getNumGmms(); handleId++) {
|
||||
delete gfxAllocation->getGmm(handleId);
|
||||
}
|
||||
if (input->peekInternalHandle(nullptr) != 0u) {
|
||||
[[maybe_unused]] auto status = SysCalls::closeHandle(reinterpret_cast<void *>(reinterpret_cast<uintptr_t *>(input->peekInternalHandle(nullptr))));
|
||||
uint64_t handle = 0;
|
||||
int ret = input->peekInternalHandle(nullptr, handle);
|
||||
if (ret == 0) {
|
||||
[[maybe_unused]] auto status = SysCalls::closeHandle(reinterpret_cast<void *>(reinterpret_cast<uintptr_t *>(handle)));
|
||||
DEBUG_BREAK_IF(!status);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user