AnsweredAssumed Answered

Driver closes file descriptors opened by other API calls

Question asked by ta1qm0v on Sep 6, 2016

I'm currently running a program on a APU under Linux on top of Mono (C# code). The APU is:

- Carrizo (rev 4) APU

- Linux Ubuntu 16.04

- AMD driver: 16.50_amdgpu-pro_326352


The issue I'm getting is that Mono is throwing a managed exception because the AMD driver is closing a file descriptor Mono is using which should not have been closed.


I was able to get the call stack when the AMD driver is closing the file descriptor opened by Mono:

#0  close () at ../sysdeps/unix/syscall-template.S:84

#1  0x00007fffe19067be in Pal::Linux::GpuMemory::~GpuMemory() () from /opt/amdgpu-pro/lib/x86_64-linux-gnu/

#2  0x00007fffe1ec0516 in vk::Memory::Free(vk::Device*) () from /opt/amdgpu-pro/lib/x86_64-linux-gnu/

#3  0x00007fffe1ec43c6 in vk::SwapChain::Destroy() () from /opt/amdgpu-pro/lib/x86_64-linux-gnu/

#4  0x00007fffe141a062 in unique_objects::DestroySwapchainKHR (device=0x2618dd0, swapchain=0x27ab180, pAllocator=0x0)

    at /home/amd/local/GitHub/Vulkan-LoaderAndValidationLayers/dbuild/layers/unique_objects.cpp:2063

#5  0x00007fffe0f4f374 in swapchain::DestroySwapchainKHR (device=0x2618dd0, swapchain=0x18, pAllocator=0x0)

    at /home/amd/local/GitHub/Vulkan-LoaderAndValidationLayers/layers/swapchain.cpp:1981

#6  0x00007fffe0afe709 in core_validation::DestroySwapchainKHR (device=0x2618dd0, swapchain=0x18, pAllocator=0x0)

    at /home/amd/local/GitHub/Vulkan-LoaderAndValidationLayers/layers/core_validation.cpp:10875

#7  0x00007fffe026d2a9 in object_tracker::DestroySwapchainKHR (device=0x2618dd0, swapchain=0x18, pAllocator=0x0)

    at /home/amd/local/GitHub/Vulkan-LoaderAndValidationLayers/layers/object_tracker.cpp:3401

#8  0x00007fffe2474b06 in vkDestroySwapchainKHR (device=0x2618dd0, swapchain=0x18, pAllocator=0x0)

    at /home/amd/local/GitHub/Vulkan-LoaderAndValidationLayers/loader/wsi.c:453


I've attached the strace output of the execution. The file descriptor being closed is #23. It is initially open toward the end of the strace by mono to open /dev/urandom. But it is closed 3 times by the AMD driver, the first time successfully, then with failure. And when Mono tries to read from it later, it fails of course (last line of the trace).


It is as if the AMD driver is closing the file descriptor without resetting some internal value and later if the file descriptor is open without checking if it did open it, it will close it.


This happens regardless of using OpenGL or Vulkan as the backend graphic API (although here I used the Vulkan backend).