Commit 49d69528 authored by Alyssa Rosenzweig's avatar Alyssa Rosenzweig 💜
Browse files

panfrost: Fix leak of render node fd

Transfer ownership of the render node fd to the panfrost_device (minor
change to panvk), and then close the file descriptor for the render node
bound to the panfrost_device when destroying the panfrost_device. Of all
the users of panfrost_open_device, panvk is the only one that correctly
closed the fd before. Accordingly, this fixes an fd leak in the Gallium
driver (and performance counter utilities).

This fix still applies to the Gallium driver when renderonly is in use--
although renderonly closes its own fd, the fd is _duplicated_ in
panfrost_drm_winsys.c, so renderonly and panfrost must _both_ close
their respective fd to fix the leak.

This fixes a crash when running dEQP-EGL for more than two hours.
dEQP-EGL creates a new screen for every test case and then immediately
destroys it. If destroying a screen leaks the fd, this causes the number
of open file descriptors to increase monotonically until the process
ends. This will eventually hit the system limit for number of open files
and abort the process.

This bug was identified while attempting to run the OpenGL ES
conformance tests via cts-runner, and then confirmed with `lsof`. With
the fix, the number of file descriptors reported by `lsof | wc -l` is
now constant while running dEQP-EGL as expected.
Signed-off-by: Alyssa Rosenzweig's avatarAlyssa Rosenzweig <>
Cc: mesa-stable
parent 688d11e4
Pipeline #380206 waiting for manual action with stages
...@@ -291,5 +291,5 @@ panfrost_close_device(struct panfrost_device *dev) ...@@ -291,5 +291,5 @@ panfrost_close_device(struct panfrost_device *dev)
pthread_mutex_destroy(&dev->bo_cache.lock); pthread_mutex_destroy(&dev->bo_cache.lock);
drmFreeVersion(dev->kernel_version); drmFreeVersion(dev->kernel_version);
util_sparse_array_finish(&dev->bo_map); util_sparse_array_finish(&dev->bo_map);
} }
...@@ -201,7 +201,6 @@ panvk_physical_device_finish(struct panvk_physical_device *device) ...@@ -201,7 +201,6 @@ panvk_physical_device_finish(struct panvk_physical_device *device)
panvk_meta_cleanup(device); panvk_meta_cleanup(device);
panfrost_close_device(&device->pdev); panfrost_close_device(&device->pdev);
if (device->master_fd != -1) if (device->master_fd != -1)
close(device->master_fd); close(device->master_fd);
...@@ -297,7 +296,6 @@ panvk_physical_device_init(struct panvk_physical_device *device, ...@@ -297,7 +296,6 @@ panvk_physical_device_init(struct panvk_physical_device *device,
} }
device->master_fd = master_fd; device->master_fd = master_fd;
device->local_fd = fd;
device->pdev.debug = PAN_DBG_TRACE; device->pdev.debug = PAN_DBG_TRACE;
panfrost_open_device(NULL, fd, &device->pdev); panfrost_open_device(NULL, fd, &device->pdev);
...@@ -169,7 +169,6 @@ struct panvk_physical_device { ...@@ -169,7 +169,6 @@ struct panvk_physical_device {
struct wsi_device wsi_device; struct wsi_device wsi_device;
struct panvk_meta meta; struct panvk_meta meta;
int local_fd;
int master_fd; int master_fd;
}; };
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment