Skip to content

Commit

Permalink
drm/vc4: bo: Fix drmm_mutex_init memory hog
Browse files Browse the repository at this point in the history
[ Upstream commit 07a2975 ]

Commit 374146c ("drm/vc4: Switch to drmm_mutex_init") converted,
among other functions, vc4_create_object() to use drmm_mutex_init().

However, that function is used to allocate a BO, and therefore the
mutex needs to be freed much sooner than when the DRM device is removed
from the system.

For each buffer allocation we thus end up allocating a small structure
as part of the DRM-managed mechanism that is never freed, eventually
leading us to no longer having any free memory anymore.

Let's switch back to mutex_init/mutex_destroy to deal with it properly.

Fixes: 374146c ("drm/vc4: Switch to drmm_mutex_init")
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Link: https://patchwork.freedesktop.org/patch/msgid/20230112091243.490799-1-maxime@cerno.tech
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
mripard authored and gregkh committed Feb 1, 2023
1 parent 86e1955 commit be960b0
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/gpu/drm/vc4/vc4_bo.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ static void vc4_bo_destroy(struct vc4_bo *bo)
bo->validated_shader = NULL;
}

mutex_destroy(&bo->madv_lock);
drm_gem_dma_free(&bo->base);
}

Expand Down Expand Up @@ -406,9 +407,7 @@ struct drm_gem_object *vc4_create_object(struct drm_device *dev, size_t size)
bo->madv = VC4_MADV_WILLNEED;
refcount_set(&bo->usecnt, 0);

ret = drmm_mutex_init(dev, &bo->madv_lock);
if (ret)
return ERR_PTR(ret);
mutex_init(&bo->madv_lock);

mutex_lock(&vc4->bo_lock);
bo->label = VC4_BO_TYPE_KERNEL;
Expand Down

0 comments on commit be960b0

Please sign in to comment.