]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
drm/xe: Add ref counting for xe_file
authorUmesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Thu, 18 Jul 2024 21:05:46 +0000 (14:05 -0700)
committerLucas De Marchi <lucas.demarchi@intel.com>
Fri, 19 Jul 2024 07:31:08 +0000 (00:31 -0700)
Add ref counting for xe_file.

v2:
- Add kernel doc for exported functions (Matt)
- Instead of xe_file_destroy, export the get/put helpers (Lucas)

v3: Fixup the kernel-doc format and description (Matt, Lucas)

Signed-off-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240718210548.3580382-3-umesh.nerlige.ramappa@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
drivers/gpu/drm/xe/xe_device.c
drivers/gpu/drm/xe/xe_device.h
drivers/gpu/drm/xe/xe_device_types.h

index 0a7478d1ee63c989c7af358c383d3a64fe47323b..50c302cf3249db391a23f6747a95c8ec514aff94 100644 (file)
@@ -90,11 +90,14 @@ static int xe_file_open(struct drm_device *dev, struct drm_file *file)
        spin_unlock(&xe->clients.lock);
 
        file->driver_priv = xef;
+       kref_init(&xef->refcount);
+
        return 0;
 }
 
-static void xe_file_destroy(struct xe_file *xef)
+static void xe_file_destroy(struct kref *ref)
 {
+       struct xe_file *xef = container_of(ref, struct xe_file, refcount);
        struct xe_device *xe = xef->xe;
 
        xa_destroy(&xef->exec_queue.xa);
@@ -110,6 +113,32 @@ static void xe_file_destroy(struct xe_file *xef)
        kfree(xef);
 }
 
+/**
+ * xe_file_get() - Take a reference to the xe file object
+ * @xef: Pointer to the xe file
+ *
+ * Anyone with a pointer to xef must take a reference to the xe file
+ * object using this call.
+ *
+ * Return: xe file pointer
+ */
+struct xe_file *xe_file_get(struct xe_file *xef)
+{
+       kref_get(&xef->refcount);
+       return xef;
+}
+
+/**
+ * xe_file_put() - Drop a reference to the xe file object
+ * @xef: Pointer to the xe file
+ *
+ * Used to drop reference to the xef object
+ */
+void xe_file_put(struct xe_file *xef)
+{
+       kref_put(&xef->refcount, xe_file_destroy);
+}
+
 static void xe_file_close(struct drm_device *dev, struct drm_file *file)
 {
        struct xe_file *xef = file->driver_priv;
@@ -132,7 +161,7 @@ static void xe_file_close(struct drm_device *dev, struct drm_file *file)
                xe_vm_close_and_put(vm);
        mutex_unlock(&xef->vm.lock);
 
-       xe_file_destroy(xef);
+       xe_file_put(xef);
 }
 
 static const struct drm_ioctl_desc xe_ioctls[] = {
index 0a2a3e7fd40265bf2f9a100ff6dcb12357f9b21d..533ccfb2567a2c320699cc1136dfaa4d4a45dce4 100644 (file)
@@ -171,4 +171,7 @@ static inline bool xe_device_wedged(struct xe_device *xe)
 
 void xe_device_declare_wedged(struct xe_device *xe);
 
+struct xe_file *xe_file_get(struct xe_file *xef);
+void xe_file_put(struct xe_file *xef);
+
 #endif
index 8e81ade7279bab3ea0de0bbf96dcaabccf5017f9..36252d5b1663d916e34dd11f4cf2eacb645e023b 100644 (file)
@@ -581,6 +581,9 @@ struct xe_file {
 
        /** @client: drm client */
        struct xe_drm_client *client;
+
+       /** @refcount: ref count of this xe file */
+       struct kref refcount;
 };
 
 #endif