Mesa (staging/21.2): panfrost: Fix leak of render node fd

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Aug 16 19:02:11 UTC 2021


Module: Mesa
Branch: staging/21.2
Commit: 4637f20a3491373a529a0cf8bcb3274839b9a6d2
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=4637f20a3491373a529a0cf8bcb3274839b9a6d2

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Thu Aug 12 17:39:15 2021 +0000

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 at collabora.com>
Cc: mesa-stable
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12346>
(cherry picked from commit 76377de99bf685ada1fbaf9fe38fb80d88d33aeb)

---

 .pick_status.json                   | 2 +-
 src/panfrost/lib/pan_props.c        | 2 +-
 src/panfrost/vulkan/panvk_device.c  | 2 --
 src/panfrost/vulkan/panvk_private.h | 1 -
 4 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 12f76dda1ca..8ef8b96575d 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -157,7 +157,7 @@
         "description": "panfrost: Fix leak of render node fd",
         "nominated": true,
         "nomination_type": 0,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": null
     },
diff --git a/src/panfrost/lib/pan_props.c b/src/panfrost/lib/pan_props.c
index 739ba980d83..08596cb3906 100644
--- a/src/panfrost/lib/pan_props.c
+++ b/src/panfrost/lib/pan_props.c
@@ -291,5 +291,5 @@ panfrost_close_device(struct panfrost_device *dev)
         pthread_mutex_destroy(&dev->bo_cache.lock);
         drmFreeVersion(dev->kernel_version);
         util_sparse_array_finish(&dev->bo_map);
-
+        close(dev->fd);
 }
diff --git a/src/panfrost/vulkan/panvk_device.c b/src/panfrost/vulkan/panvk_device.c
index 4a0dbd71675..e2f2bd7de1b 100644
--- a/src/panfrost/vulkan/panvk_device.c
+++ b/src/panfrost/vulkan/panvk_device.c
@@ -201,7 +201,6 @@ panvk_physical_device_finish(struct panvk_physical_device *device)
 
    panvk_meta_cleanup(device);
    panfrost_close_device(&device->pdev);
-   close(device->local_fd);
    if (device->master_fd != -1)
       close(device->master_fd);
 
@@ -297,7 +296,6 @@ panvk_physical_device_init(struct panvk_physical_device *device,
    }
 
    device->master_fd = master_fd;
-   device->local_fd = fd;
    device->pdev.debug = PAN_DBG_TRACE;
    panfrost_open_device(NULL, fd, &device->pdev);
 
diff --git a/src/panfrost/vulkan/panvk_private.h b/src/panfrost/vulkan/panvk_private.h
index b4e331fb6b9..e0b34133b5d 100644
--- a/src/panfrost/vulkan/panvk_private.h
+++ b/src/panfrost/vulkan/panvk_private.h
@@ -164,7 +164,6 @@ struct panvk_physical_device {
    struct wsi_device wsi_device;
    struct panvk_meta meta;
 
-   int local_fd;
    int master_fd;
 };
 



More information about the mesa-commit mailing list