Module: Mesa
Branch: main
Commit: 279d08a18a3ad52c0636674ba0aed65368cfe01d
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=279d08a18a3ad52c0636674ba0aed65368cfe01d

Author: Michael Tretter <[email protected]>
Date:   Mon Jun 19 12:19:00 2023 +0200

panfrost: remove BO from cache before closing GEM

If the GEM is closed before setting the BO in the sparse array to zero,
a newly allocated GEM may be associated with a stale BO that is left in
the cache reusing an old BO.

Zero the BO before closing the GEM to make sure that the BO is removed
from the cache and won't be associated with a different GEM.

Signed-off-by: Michael Tretter <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23744>

---

 src/panfrost/lib/pan_bo.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/panfrost/lib/pan_bo.c b/src/panfrost/lib/pan_bo.c
index 5b686c95424..0466ac1164f 100644
--- a/src/panfrost/lib/pan_bo.c
+++ b/src/panfrost/lib/pan_bo.c
@@ -93,16 +93,17 @@ static void
 panfrost_bo_free(struct panfrost_bo *bo)
 {
    struct drm_gem_close gem_close = {.handle = bo->gem_handle};
+   int fd = bo->dev->fd;
    int ret;
 
-   ret = drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
+   /* BO will be freed with the sparse array, but zero to indicate free */
+   memset(bo, 0, sizeof(*bo));
+
+   ret = drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
    if (ret) {
       fprintf(stderr, "DRM_IOCTL_GEM_CLOSE failed: %m\n");
       assert(0);
    }
-
-   /* BO will be freed with the sparse array, but zero to indicate free */
-   memset(bo, 0, sizeof(*bo));
 }
 
 /* Returns true if the BO is ready, false otherwise.

Reply via email to