]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/gpuvm: take refcount on DRM device
authorAlice Ryhl <aliceryhl@google.com>
Thu, 16 Apr 2026 13:10:54 +0000 (13:10 +0000)
committerDanilo Krummrich <dakr@kernel.org>
Tue, 5 May 2026 10:49:41 +0000 (12:49 +0200)
Currently GPUVM relies on the owner implicitly holding a refcount to the
drm device, and it does not implicitly take a refcount on the drm
device. This design is error-prone, so take a refcount on the device.

Suggested-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Fixes: 546ca4d35dcc ("drm/gpuvm: convert WARN() to drm_WARN() variants")
Link: https://patch.msgid.link/20260416-gpuvm-drm-dev-get-v1-1-f3bc06571e73@google.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
drivers/gpu/drm/drm_gpuvm.c

index 44acfe4120d243bea70c6178a3ac7cb1583543a7..000e7910a8999ce7ac8dc7009e7119edec999e3f 100644 (file)
@@ -25,6 +25,7 @@
  *
  */
 
+#include <drm/drm_drv.h>
 #include <drm/drm_gpuvm.h>
 #include <drm/drm_print.h>
 
@@ -1117,6 +1118,7 @@ drm_gpuvm_init(struct drm_gpuvm *gpuvm, const char *name,
        gpuvm->drm = drm;
        gpuvm->r_obj = r_obj;
 
+       drm_dev_get(drm);
        drm_gem_object_get(r_obj);
 
        drm_gpuvm_warn_check_overflow(gpuvm, start_offset, range);
@@ -1160,13 +1162,15 @@ static void
 drm_gpuvm_free(struct kref *kref)
 {
        struct drm_gpuvm *gpuvm = container_of(kref, struct drm_gpuvm, kref);
+       struct drm_device *drm = gpuvm->drm;
 
        drm_gpuvm_fini(gpuvm);
 
-       if (drm_WARN_ON(gpuvm->drm, !gpuvm->ops->vm_free))
+       if (drm_WARN_ON(drm, !gpuvm->ops->vm_free))
                return;
 
        gpuvm->ops->vm_free(gpuvm);
+       drm_dev_put(drm);
 }
 
 /**