panfrost: Fix leak of render node fd
authorAlyssa Rosenzweig <alyssa@collabora.com>
Thu, 12 Aug 2021 17:39:15 +0000 (17:39 +0000)
committerMarge Bot <eric+marge@anholt.net>
Mon, 16 Aug 2021 16:08:10 +0000 (16:08 +0000)
commit76377de99bf685ada1fbaf9fe38fb80d88d33aeb
tree9fd85cf6d01b8de6d0de1e0f03289d02d5a9ef7c
parentdab97fe227739781652564504a27ff6ea08fb98e
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 <alyssa@collabora.com>
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12346>
src/panfrost/lib/pan_props.c
src/panfrost/vulkan/panvk_device.c
src/panfrost/vulkan/panvk_private.h