Skip to contentSkip to conversation

drm/ioctl: Add a ioctl to label GEM objects

PATCH Superseded Rohan Garg 4 participants 6 messages Sep 19, 2019 – Oct 8, 2019

Subsystems (2)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Rohan Garg

author
#0 lore raw

PATCH v2 1/1 drm/ioctl: Add a ioctl to label GEM objects

DRM_IOCTL_BO_SET_LABEL lets you label GEM objects, making it easier to debug issues in userspace applications.

Changes in v2:
- Hoist the IOCTL up into the drm_driver framework

---
 drivers/gpu/drm/drm_gem.c      | 64 ++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_internal.h |  4 +++
 drivers/gpu/drm/drm_ioctl.c    |  1 +
 include/drm/drm_drv.h          | 18 ++++++++++
 include/drm/drm_gem.h          |  7 ++++
 include/uapi/drm/drm.h         | 20 +++++++++++
 6 files changed, 114 insertions(+)
drivers/gpu/drm/drm_gem.c +64 -0
index 6854f5867d51..785ac561619a 100644
@@ -941,6 +941,65 @@ drm_gem_release(struct drm_device *dev, struct drm_file *file_private)
 	idr_destroy(&file_private->object_idr);
 }
 
+int drm_bo_set_label_ioctl(struct drm_device *dev, void *data,
+		       struct drm_file *file_priv)
+{
+	struct drm_label_object *args = data;
+
+	if (!args->len || !args->name)
+		return -EINVAL;
+
+	if (dev->driver->label)
+		return dev->driver->label(dev, args, file_priv);
+
+	return -EOPNOTSUPP;
+}
+
+/**
+ * drm_gem_label - label a given GEM object
+ * @dev: drm_device for the associated GEM object
+ * @data: drm_label_bo struct with a label, label length and any relevant flags
+ * @file_private: drm file-private structure to clean up
+ */
+
+int drm_gem_set_label(struct drm_device *dev, struct drm_label_object *args, struct drm_file *file_priv)
+{
+	struct drm_gem_object *gem_obj;
+	int err = 0;
+	char *label;
+
+	if (args->len > 0)
+		label = strndup_user(u64_to_user_ptr(args->name), args->len);
+
+	gem_obj = drm_gem_object_lookup(file_priv, args->handle);
+	if (!gem_obj) {
+		DRM_ERROR("Failed to look up GEM BO %d\n", args->handle);
+		err = -ENOENT;
+		goto err;
+	}
+
+	if ((args->len == 0 && args->name == NULL) || gem_obj->label) {
+		kfree(gem_obj->label);
+		gem_obj->label = NULL;
+	}
+
+	gem_obj->label = label;
+
+	drm_gem_object_put_unlocked(gem_obj);
+
+	if (IS_ERR(gem_obj->label)) {
+		err = PTR_ERR(gem_obj->label);
+		goto err;
+	}
+
+err:
+	if (err != 0)
+		args->flags = err;
+
+	return err;
+}
+
+
 /**
  * drm_gem_object_release - release GEM buffer object resources
  * @obj: GEM buffer object
@@ -958,6 +1017,11 @@ drm_gem_object_release(struct drm_gem_object *obj)
 
 	dma_resv_fini(&obj->_resv);
 	drm_gem_free_mmap_offset(obj);
+
+	if (obj->label) {
+		kfree(obj->label);
+		obj->label = NULL;
+	}
 }
 EXPORT_SYMBOL(drm_gem_object_release);
 
drivers/gpu/drm/drm_internal.h +4 -0
index 51a2055c8f18..8259622f9ab6 100644
@@ -137,6 +137,10 @@ int drm_gem_pin(struct drm_gem_object *obj);
 void drm_gem_unpin(struct drm_gem_object *obj);
 void *drm_gem_vmap(struct drm_gem_object *obj);
 void drm_gem_vunmap(struct drm_gem_object *obj, void *vaddr);
+int drm_bo_set_label_ioctl(struct drm_device *dev, void *data,
+			struct drm_file *file_priv);
+int drm_gem_set_label(struct drm_device *dev, struct drm_label_object *args,
+			struct drm_file *file_priv);
 
 /* drm_debugfs.c drm_debugfs_crc.c */
 #if defined(CONFIG_DEBUG_FS)
drivers/gpu/drm/drm_ioctl.c +1 -0
index f675a3bb2c88..079d1422f9c5 100644
@@ -709,6 +709,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_LIST_LESSEES, drm_mode_list_lessees_ioctl, DRM_MASTER),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GET_LEASE, drm_mode_get_lease_ioctl, DRM_MASTER),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_REVOKE_LEASE, drm_mode_revoke_lease_ioctl, DRM_MASTER),
+	DRM_IOCTL_DEF(DRM_IOCTL_BO_SET_LABEL, drm_bo_set_label_ioctl, DRM_RENDER_ALLOW),
 };
 
 #define DRM_CORE_IOCTL_COUNT	ARRAY_SIZE( drm_ioctls )
include/drm/drm_drv.h +18 -0
index 8976afe48c1c..f736ba1f42a6 100644
@@ -715,6 +715,24 @@ struct drm_driver {
 			    struct drm_device *dev,
 			    uint32_t handle);
 
+
+	/**
+	 * @label:
+	 *
+	 * This label's a buffer object.
+	 *
+	 * Called by the user via ioctl.
+	 *
+	 * The default implementation is drm_gem_label(). GEM based drivers
+	 * must not overwrite this.
+
+	 * Returns:
+	 *
+	 * Zero on success, negative errno on failure.
+	 */
+	int (*label)(struct drm_device *dev, struct drm_label_object *args,
+				struct drm_file *file_priv);
+
 	/**
 	 * @gem_vm_ops: Driver private ops for this object
 	 *
include/drm/drm_gem.h +7 -0
index 6aaba14f5972..f801c054e972 100644
@@ -237,6 +237,13 @@ struct drm_gem_object {
 	 */
 	int name;
 
+	/**
+	 * @label:
+	 *
+	 * Label for this object, should be a human readable string.
+	 */
+	char *label;
+
 	/**
 	 * @dma_buf:
 	 *
include/uapi/drm/drm.h +20 -0
index 8a5b2f8f8eb9..23b507f5c571 100644
@@ -626,6 +626,25 @@ struct drm_gem_open {
 	__u64 size;
 };
 
+/** struct drm_label_object - ioctl argument for labelling BOs.
+ *
+ * This label's a BO with a userspace label
+ *
+ */
+struct drm_label_object {
+	/** Handle for the object being labelled. */
+	__u32 handle;
+
+	/** Label and label length.
+	 *  length includes the trailing NULL.
+	 */
+	__u32 len;
+	__u64 name;
+
+	/** Flags */
+	int flags;
+};
+
 #define DRM_CAP_DUMB_BUFFER		0x1
 #define DRM_CAP_VBLANK_HIGH_CRTC	0x2
 #define DRM_CAP_DUMB_PREFERRED_DEPTH	0x3
@@ -946,6 +965,7 @@ extern "C" {
 #define DRM_IOCTL_SYNCOBJ_QUERY		DRM_IOWR(0xCB, struct drm_syncobj_timeline_array)
 #define DRM_IOCTL_SYNCOBJ_TRANSFER	DRM_IOWR(0xCC, struct drm_syncobj_transfer)
 #define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL	DRM_IOWR(0xCD, struct drm_syncobj_timeline_array)
+#define DRM_IOCTL_BO_SET_LABEL      DRM_IOWR(0xCE, struct drm_label_object)
 
 /**
  * Device specific ioctls should only be in their respective headers
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

Hi

Am 19.09.19 um 14:53 schrieb Rohan Garg:

Quoted 36 lines

DRM_IOCTL_BO_SET_LABEL lets you label GEM objects, making it easier to debug issues in userspace applications.

Changes in v2:
- Hoist the IOCTL up into the drm_driver framework

---
 drivers/gpu/drm/drm_gem.c      | 64 ++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_internal.h |  4 +++
 drivers/gpu/drm/drm_ioctl.c    |  1 +
 include/drm/drm_drv.h          | 18 ++++++++++
 include/drm/drm_gem.h          |  7 ++++
 include/uapi/drm/drm.h         | 20 +++++++++++
 6 files changed, 114 insertions(+)
drivers/gpu/drm/drm_gem.c +12 -0
index 6854f5867d51..785ac561619a 100644
@@ -941,6 +941,65 @@ drm_gem_release(struct drm_device *dev, struct drm_file *file_private)
 	idr_destroy(&file_private->object_idr);
 }
 
+int drm_bo_set_label_ioctl(struct drm_device *dev, void *data,
+		       struct drm_file *file_priv)
+{
+	struct drm_label_object *args = data;
+
+	if (!args->len || !args->name)
+		return -EINVAL;
+
+	if (dev->driver->label)
+		return dev->driver->label(dev, args, file_priv);
+
+	return -EOPNOTSUPP;

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 965

Quoted 10 lines
drivers/gpu/drm/drm_gem.c +10 -0
+}
+
+/**
+ * drm_gem_label - label a given GEM object
+ * @dev: drm_device for the associated GEM object
+ * @data: drm_label_bo struct with a label, label length and any relevant flags
+ * @file_private: drm file-private structure to clean up
+ */
+
+int drm_gem_set_label(struct drm_device *dev, struct drm_label_object *args, struct drm_file *file_priv)

I'd like to set labels for internal GEM objects. Could you split off the object update code into something that is easily callable from within drivers? Something like

// called by ioctl
int drm_gem_object_adopt_label(struct drm_gem_object *gem,
char *label)

  {
        // your object update code goes here

}

// called by drivers
int drm_gem_object_set_label(struct drm_gem_object *gem,
const char *label)

  {
	char* new_label = strdup(label)
	return drm_gem_object_adopt_label(gem, new_label);

}

We have debugfs support for TTM-based GEM objects at [1]. I think the label would be a welcome addition to the output.

Best regards
Thomas

[1]
https://cgit.freedesktop.org/drm/drm-tip/tree/drivers/gpu/drm/drm_gem_ttm_helper.c#n23

Quoted 165 lines
drivers/gpu/drm/drm_gem.c +42 -0
+{
+	struct drm_gem_object *gem_obj;
+	int err = 0;
+	char *label;
+
+	if (args->len > 0)
+		label = strndup_user(u64_to_user_ptr(args->name), args->len);
+
+	gem_obj = drm_gem_object_lookup(file_priv, args->handle);
+	if (!gem_obj) {
+		DRM_ERROR("Failed to look up GEM BO %d\n", args->handle);
+		err = -ENOENT;
+		goto err;
+	}
+
+	if ((args->len == 0 && args->name == NULL) || gem_obj->label) {
+		kfree(gem_obj->label);
+		gem_obj->label = NULL;
+	}
+
+	gem_obj->label = label;
+
+	drm_gem_object_put_unlocked(gem_obj);
+
+	if (IS_ERR(gem_obj->label)) {
+		err = PTR_ERR(gem_obj->label);
+		goto err;
+	}
+
+err:
+	if (err != 0)
+		args->flags = err;
+
+	return err;
+}
+
+
 /**
  * drm_gem_object_release - release GEM buffer object resources
  * @obj: GEM buffer object
@@ -958,6 +1017,11 @@ drm_gem_object_release(struct drm_gem_object *obj)
 
 	dma_resv_fini(&obj->_resv);
 	drm_gem_free_mmap_offset(obj);
+
+	if (obj->label) {
+		kfree(obj->label);
+		obj->label = NULL;
+	}
 }
 EXPORT_SYMBOL(drm_gem_object_release);
 
drivers/gpu/drm/drm_internal.h +4 -0
index 51a2055c8f18..8259622f9ab6 100644
@@ -137,6 +137,10 @@ int drm_gem_pin(struct drm_gem_object *obj);
 void drm_gem_unpin(struct drm_gem_object *obj);
 void *drm_gem_vmap(struct drm_gem_object *obj);
 void drm_gem_vunmap(struct drm_gem_object *obj, void *vaddr);
+int drm_bo_set_label_ioctl(struct drm_device *dev, void *data,
+			struct drm_file *file_priv);
+int drm_gem_set_label(struct drm_device *dev, struct drm_label_object *args,
+			struct drm_file *file_priv);
 
 /* drm_debugfs.c drm_debugfs_crc.c */
 #if defined(CONFIG_DEBUG_FS)
drivers/gpu/drm/drm_ioctl.c +1 -0
index f675a3bb2c88..079d1422f9c5 100644
@@ -709,6 +709,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_LIST_LESSEES, drm_mode_list_lessees_ioctl, DRM_MASTER),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GET_LEASE, drm_mode_get_lease_ioctl, DRM_MASTER),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_REVOKE_LEASE, drm_mode_revoke_lease_ioctl, DRM_MASTER),
+	DRM_IOCTL_DEF(DRM_IOCTL_BO_SET_LABEL, drm_bo_set_label_ioctl, DRM_RENDER_ALLOW),
 };
 
 #define DRM_CORE_IOCTL_COUNT	ARRAY_SIZE( drm_ioctls )
include/drm/drm_drv.h +18 -0
index 8976afe48c1c..f736ba1f42a6 100644
@@ -715,6 +715,24 @@ struct drm_driver {
 			    struct drm_device *dev,
 			    uint32_t handle);
 
+
+	/**
+	 * @label:
+	 *
+	 * This label's a buffer object.
+	 *
+	 * Called by the user via ioctl.
+	 *
+	 * The default implementation is drm_gem_label(). GEM based drivers
+	 * must not overwrite this.
+
+	 * Returns:
+	 *
+	 * Zero on success, negative errno on failure.
+	 */
+	int (*label)(struct drm_device *dev, struct drm_label_object *args,
+				struct drm_file *file_priv);
+
 	/**
 	 * @gem_vm_ops: Driver private ops for this object
 	 *
include/drm/drm_gem.h +7 -0
index 6aaba14f5972..f801c054e972 100644
@@ -237,6 +237,13 @@ struct drm_gem_object {
 	 */
 	int name;
 
+	/**
+	 * @label:
+	 *
+	 * Label for this object, should be a human readable string.
+	 */
+	char *label;
+
 	/**
 	 * @dma_buf:
 	 *
include/uapi/drm/drm.h +20 -0
index 8a5b2f8f8eb9..23b507f5c571 100644
@@ -626,6 +626,25 @@ struct drm_gem_open {
 	__u64 size;
 };
 
+/** struct drm_label_object - ioctl argument for labelling BOs.
+ *
+ * This label's a BO with a userspace label
+ *
+ */
+struct drm_label_object {
+	/** Handle for the object being labelled. */
+	__u32 handle;
+
+	/** Label and label length.
+	 *  length includes the trailing NULL.
+	 */
+	__u32 len;
+	__u64 name;
+
+	/** Flags */
+	int flags;
+};
+
 #define DRM_CAP_DUMB_BUFFER		0x1
 #define DRM_CAP_VBLANK_HIGH_CRTC	0x2
 #define DRM_CAP_DUMB_PREFERRED_DEPTH	0x3
@@ -946,6 +965,7 @@ extern "C" {
 #define DRM_IOCTL_SYNCOBJ_QUERY		DRM_IOWR(0xCB, struct drm_syncobj_timeline_array)
 #define DRM_IOCTL_SYNCOBJ_TRANSFER	DRM_IOWR(0xCC, struct drm_syncobj_transfer)
 #define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL	DRM_IOWR(0xCD, struct drm_syncobj_timeline_array)
+#define DRM_IOCTL_BO_SET_LABEL      DRM_IOWR(0xCE, struct drm_label_object)
 
 /**
  * Device specific ioctls should only be in their respective headers
Signature · 5 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG Nürnberg)

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author
#2 lore raw

Hi

Quoted 67 lines · On jueves, 19 de septiembre de 2019 16:02:57 (CEST) Thomas Zimmermann wrote:

Hi

Am 19.09.19 um 14:53 schrieb Rohan Garg:

Quoted 49 lines

DRM_IOCTL_BO_SET_LABEL lets you label GEM objects, making it easier to debug issues in userspace applications.

Changes in v2:
- Hoist the IOCTL up into the drm_driver framework

---

 drivers/gpu/drm/drm_gem.c      | 64 ++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_internal.h |  4 +++
 drivers/gpu/drm/drm_ioctl.c    |  1 +
 include/drm/drm_drv.h          | 18 ++++++++++
 include/drm/drm_gem.h          |  7 ++++
 include/uapi/drm/drm.h         | 20 +++++++++++
 6 files changed, 114 insertions(+)
drivers/gpu/drm/drm_gem.c +0 -0
index 6854f5867d51..785ac561619a 100644
@@ -941,6 +941,65 @@ drm_gem_release(struct drm_device *dev, struct

drm_file *file_private)>

drivers/gpu/drm/drm_gem.c +18 -0
 	idr_destroy(&file_private->object_idr);
 
 }
 
+int drm_bo_set_label_ioctl(struct drm_device *dev, void *data,
+		       struct drm_file *file_priv)
+{
+	struct drm_label_object *args = data;
+
+	if (!args->len || !args->name)
+		return -EINVAL;
+
+	if (dev->driver->label)
+		return dev->driver->label(dev, args, file_priv);
+
+	return -EOPNOTSUPP;
+}
+
+/**
+ * drm_gem_label - label a given GEM object
+ * @dev: drm_device for the associated GEM object
+ * @data: drm_label_bo struct with a label, label length and any relevant

flags + * @file_private: drm file-private structure to clean up
+ */

drivers/gpu/drm/drm_gem.c +2 -0
+
+int drm_gem_set_label(struct drm_device *dev, struct drm_label_object
Quoted 1 line

*args, struct drm_file *file_priv)

I'd like to set labels for internal GEM objects. Could you split off the object update code into something that is easily callable from within drivers? Something like

// called by ioctl
int drm_gem_object_adopt_label(struct drm_gem_object *gem,
char *label)

  {
        // your object update code goes here

}

// called by drivers
int drm_gem_object_set_label(struct drm_gem_object *gem,
const char *label)

Quoted 9 lines
  {
	char* new_label = strdup(label)
	return drm_gem_object_adopt_label(gem, new_label);

}

We have debugfs support for TTM-based GEM objects at [1]. I think the label would be a welcome addition to the output.

Ack, I'll address this in v3.

Cheers
Rohan Garg

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
In reply to Rohan Garg
Quoted 21 lines · Rohan Garg

DRM_IOCTL_BO_SET_LABEL lets you label GEM objects, making it easier to debug issues in userspace applications.

Changes in v2:
- Hoist the IOCTL up into the drm_driver framework

---
 drivers/gpu/drm/drm_gem.c      | 64 ++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_internal.h |  4 +++
 drivers/gpu/drm/drm_ioctl.c    |  1 +
 include/drm/drm_drv.h          | 18 ++++++++++
 include/drm/drm_gem.h          |  7 ++++
 include/uapi/drm/drm.h         | 20 +++++++++++
 6 files changed, 114 insertions(+)
drivers/gpu/drm/drm_gem.c +0 -0
index 6854f5867d51..785ac561619a 100644

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 945

Quoted 5 lines
drivers/gpu/drm/drm_gem.c +2 -0
@@ -941,6 +941,65 @@ drm_gem_release(struct drm_device *dev, struct drm_file *file_private)
 	idr_destroy(&file_private->object_idr);
 }
 
+int drm_bo_set_label_ioctl(struct drm_device *dev, void *data,
+		       struct drm_file *file_priv)

Perhaps call this drm_gem_set_label_ioctl() so that it's consistent with the other GEM related IOCTLs?

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 947

Quoted 2 lines
drivers/gpu/drm/drm_gem.c +2 -0
+{
+	struct drm_label_object *args = data;

Similarly, perhaps make this struct drm_gem_set_label for consistency.

Quoted 8 lines
drivers/gpu/drm/drm_gem.c +8 -0
+
+	if (!args->len || !args->name)
+		return -EINVAL;
+
+	if (dev->driver->label)
+		return dev->driver->label(dev, args, file_priv);
+
+	return -EOPNOTSUPP;

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 965

Quoted 10 lines
drivers/gpu/drm/drm_gem.c +10 -0
+}
+
+/**
+ * drm_gem_label - label a given GEM object
+ * @dev: drm_device for the associated GEM object
+ * @data: drm_label_bo struct with a label, label length and any relevant flags
+ * @file_private: drm file-private structure to clean up
+ */
+
+int drm_gem_set_label(struct drm_device *dev, struct drm_label_object *args, struct drm_file *file_priv)

Function name doesn't match the kerneldoc.

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 976

Quoted 11 lines
drivers/gpu/drm/drm_gem.c +11 -0
+{
+	struct drm_gem_object *gem_obj;
+	int err = 0;
+	char *label;
+
+	if (args->len > 0)
+		label = strndup_user(u64_to_user_ptr(args->name), args->len);
+
+	gem_obj = drm_gem_object_lookup(file_priv, args->handle);
+	if (!gem_obj) {
+		DRM_ERROR("Failed to look up GEM BO %d\n", args->handle);

People could abuse this to spam the system logs with these error messages. Better make this DRM_DEBUG() or leave it out completely.

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 978

Quoted 2 lines
drivers/gpu/drm/drm_gem.c +2 -0
+		err = -ENOENT;
+		goto err;

I think you're leaking the label string here.

Quoted 5 lines
drivers/gpu/drm/drm_gem.c +5 -0
+	}
+
+	if ((args->len == 0 && args->name == NULL) || gem_obj->label) {
+		kfree(gem_obj->label);
+		gem_obj->label = NULL;

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 993

Quoted 10 lines
drivers/gpu/drm/drm_gem.c +10 -0
+	}
+
+	gem_obj->label = label;
+
+	drm_gem_object_put_unlocked(gem_obj);
+
+	if (IS_ERR(gem_obj->label)) {
+		err = PTR_ERR(gem_obj->label);
+		goto err;
+	}

Why don't you check for this earlier? That seems suboptimal because now you've got some error value in gem_obj->label that you're going to have to special case at every step of the way.

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 997

Quoted 4 lines
drivers/gpu/drm/drm_gem.c +4 -0
+
+err:
+	if (err != 0)
+		args->flags = err;

Why the flags? We typically just return the error...

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 999

Quoted 2 lines
drivers/gpu/drm/drm_gem.c +2 -0
+
+	return err;

... like here.

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 1000

Quoted 1 line
drivers/gpu/drm/drm_gem.c +1 -0
+}

Do we want to export this so that drivers can use it?

Quoted 22 lines
drivers/gpu/drm/drm_gem.c +7 -0
+
+
 /**
  * drm_gem_object_release - release GEM buffer object resources
  * @obj: GEM buffer object
@@ -958,6 +1017,11 @@ drm_gem_object_release(struct drm_gem_object *obj)
 
 	dma_resv_fini(&obj->_resv);
 	drm_gem_free_mmap_offset(obj);
+
+	if (obj->label) {
+		kfree(obj->label);
+		obj->label = NULL;
+	}
 }
 EXPORT_SYMBOL(drm_gem_object_release);
 
drivers/gpu/drm/drm_internal.h +0 -0
index 51a2055c8f18..8259622f9ab6 100644

drivers/gpu/drm/drm_internal.h int drm_gem_pin(struct drm_gem_object *obj); · line 143

Quoted 7 lines
drivers/gpu/drm/drm_internal.h +4 -0
@@ -137,6 +137,10 @@ int drm_gem_pin(struct drm_gem_object *obj);
 void drm_gem_unpin(struct drm_gem_object *obj);
 void *drm_gem_vmap(struct drm_gem_object *obj);
 void drm_gem_vunmap(struct drm_gem_object *obj, void *vaddr);
+int drm_bo_set_label_ioctl(struct drm_device *dev, void *data,
+			struct drm_file *file_priv);
+int drm_gem_set_label(struct drm_device *dev, struct drm_label_object *args,
+			struct drm_file *file_priv);

This one seems to be unused now.

Quoted 24 lines
drivers/gpu/drm/drm_internal.h +0 -0
 /* drm_debugfs.c drm_debugfs_crc.c */
 #if defined(CONFIG_DEBUG_FS)
drivers/gpu/drm/drm_ioctl.c +1 -0
index f675a3bb2c88..079d1422f9c5 100644
@@ -709,6 +709,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_LIST_LESSEES, drm_mode_list_lessees_ioctl, DRM_MASTER),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_GET_LEASE, drm_mode_get_lease_ioctl, DRM_MASTER),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_REVOKE_LEASE, drm_mode_revoke_lease_ioctl, DRM_MASTER),
+	DRM_IOCTL_DEF(DRM_IOCTL_BO_SET_LABEL, drm_bo_set_label_ioctl, DRM_RENDER_ALLOW),
 };
 
 #define DRM_CORE_IOCTL_COUNT	ARRAY_SIZE( drm_ioctls )
include/drm/drm_drv.h +1 -0
index 8976afe48c1c..f736ba1f42a6 100644
@@ -715,6 +715,24 @@ struct drm_driver {
 			    struct drm_device *dev,
 			    uint32_t handle);
 
+

include/drm/drm_drv.h struct drm_driver { · line 728

Quoted 10 lines
include/drm/drm_drv.h +10 -0
+	/**
+	 * @label:
+	 *
+	 * This label's a buffer object.
+	 *
+	 * Called by the user via ioctl.
+	 *
+	 * The default implementation is drm_gem_label(). GEM based drivers
+	 * must not overwrite this.
+

Spurious blank line.

include/drm/drm_drv.h struct drm_driver { · line 734

Quoted 6 lines
include/drm/drm_drv.h +6 -0
+	 * Returns:
+	 *
+	 * Zero on success, negative errno on failure.
+	 */
+	int (*label)(struct drm_device *dev, struct drm_label_object *args,
+				struct drm_file *file_priv);

If I understand correctly, you use this so that non-GEM drivers can use this IOCTL to label their non-GEM objects. Do you think that's really useful? I mean they've already got quite a bit of special code to deal with their objects, so singling out this IOCTL seems a bit odd.

Then again, I guess it doesn't really hurt since GEM-based drivers will always use the standard implementation.

Quoted 31 lines
include/drm/drm_drv.h +1 -0
+
 	/**
 	 * @gem_vm_ops: Driver private ops for this object
 	 *
include/drm/drm_gem.h +7 -0
index 6aaba14f5972..f801c054e972 100644
@@ -237,6 +237,13 @@ struct drm_gem_object {
 	 */
 	int name;
 
+	/**
+	 * @label:
+	 *
+	 * Label for this object, should be a human readable string.
+	 */
+	char *label;
+
 	/**
 	 * @dma_buf:
 	 *
include/uapi/drm/drm.h +1 -0
index 8a5b2f8f8eb9..23b507f5c571 100644
@@ -626,6 +626,25 @@ struct drm_gem_open {
 	__u64 size;
 };
 
+/** struct drm_label_object - ioctl argument for labelling BOs.

include/uapi/drm/drm.h struct drm_gem_open { · line 639

Quoted 10 lines
include/uapi/drm/drm.h +10 -0
+ *
+ * This label's a BO with a userspace label
+ *
+ */
+struct drm_label_object {
+	/** Handle for the object being labelled. */
+	__u32 handle;
+
+	/** Label and label length.
+	 *  length includes the trailing NULL.

Nit: I think you mean "trailing NUL". Also, the parameter is called len below, so the comment here should match.

Thierry

Quoted 26 lines
include/uapi/drm/drm.h +9 -0
+	 */
+	__u32 len;
+	__u64 name;
+
+	/** Flags */
+	int flags;
+};
+
 #define DRM_CAP_DUMB_BUFFER		0x1
 #define DRM_CAP_VBLANK_HIGH_CRTC	0x2
 #define DRM_CAP_DUMB_PREFERRED_DEPTH	0x3
@@ -946,6 +965,7 @@ extern "C" {
 #define DRM_IOCTL_SYNCOBJ_QUERY		DRM_IOWR(0xCB, struct drm_syncobj_timeline_array)
 #define DRM_IOCTL_SYNCOBJ_TRANSFER	DRM_IOWR(0xCC, struct drm_syncobj_transfer)
 #define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL	DRM_IOWR(0xCD, struct drm_syncobj_timeline_array)
+#define DRM_IOCTL_BO_SET_LABEL      DRM_IOWR(0xCE, struct drm_label_object)
 
 /**
  * Device specific ioctls should only be in their respective headers
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author
#4 lore raw
Quoted 160 lines · On viernes, 20 de septiembre de 2019 17:25:10 (CEST) Thierry Reding wrote:
Quoted 23 lines · Rohan Garg

DRM_IOCTL_BO_SET_LABEL lets you label GEM objects, making it easier to debug issues in userspace applications.

Changes in v2:
- Hoist the IOCTL up into the drm_driver framework

---

 drivers/gpu/drm/drm_gem.c      | 64 ++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_internal.h |  4 +++
 drivers/gpu/drm/drm_ioctl.c    |  1 +
 include/drm/drm_drv.h          | 18 ++++++++++
 include/drm/drm_gem.h          |  7 ++++
 include/uapi/drm/drm.h         | 20 +++++++++++
 6 files changed, 114 insertions(+)
drivers/gpu/drm/drm_gem.c +0 -0
index 6854f5867d51..785ac561619a 100644
@@ -941,6 +941,65 @@ drm_gem_release(struct drm_device *dev, struct

drm_file *file_private)>

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 945

Quoted 6 lines
drivers/gpu/drm/drm_gem.c +2 -0
 	idr_destroy(&file_private->object_idr);
 
 }
 
+int drm_bo_set_label_ioctl(struct drm_device *dev, void *data,
+		       struct drm_file *file_priv)

Perhaps call this drm_gem_set_label_ioctl() so that it's consistent with the other GEM related IOCTLs?

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 947

Quoted 2 lines
drivers/gpu/drm/drm_gem.c +2 -0
+{
+	struct drm_label_object *args = data;

Similarly, perhaps make this struct drm_gem_set_label for consistency.

Quoted 18 lines
drivers/gpu/drm/drm_gem.c +14 -0
+
+	if (!args->len || !args->name)
+		return -EINVAL;
+
+	if (dev->driver->label)
+		return dev->driver->label(dev, args, file_priv);
+
+	return -EOPNOTSUPP;
+}
+
+/**
+ * drm_gem_label - label a given GEM object
+ * @dev: drm_device for the associated GEM object
+ * @data: drm_label_bo struct with a label, label length and any relevant

flags + * @file_private: drm file-private structure to clean up
+ */

drivers/gpu/drm/drm_gem.c +2 -0
+
+int drm_gem_set_label(struct drm_device *dev, struct drm_label_object
Quoted 1 line

*args, struct drm_file *file_priv)

Function name doesn't match the kerneldoc.

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private)

Quoted 7 lines
drivers/gpu/drm/drm_gem.c +7 -0
+{
+	struct drm_gem_object *gem_obj;
+	int err = 0;
+	char *label;
+
+	if (args->len > 0)
+		label = strndup_user(u64_to_user_ptr(args->name), args-

len);

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private)

Quoted 4 lines
drivers/gpu/drm/drm_gem.c +4 -0
+
+	gem_obj = drm_gem_object_lookup(file_priv, args->handle);
+	if (!gem_obj) {
+		DRM_ERROR("Failed to look up GEM BO %d\n", args-

handle);

People could abuse this to spam the system logs with these error messages. Better make this DRM_DEBUG() or leave it out completely.

drivers/gpu/drm/drm_gem.c

Quoted 2 lines
drivers/gpu/drm/drm_gem.c +2 -0
+		err = -ENOENT;
+		goto err;

I think you're leaking the label string here.

Quoted 5 lines
drivers/gpu/drm/drm_gem.c +5 -0
+	}
+
+	if ((args->len == 0 && args->name == NULL) || gem_obj->label) {
+		kfree(gem_obj->label);
+		gem_obj->label = NULL;

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 993

Quoted 10 lines
drivers/gpu/drm/drm_gem.c +10 -0
+	}
+
+	gem_obj->label = label;
+
+	drm_gem_object_put_unlocked(gem_obj);
+
+	if (IS_ERR(gem_obj->label)) {
+		err = PTR_ERR(gem_obj->label);
+		goto err;
+	}

Why don't you check for this earlier? That seems suboptimal because now you've got some error value in gem_obj->label that you're going to have to special case at every step of the way.

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 997

Quoted 4 lines
drivers/gpu/drm/drm_gem.c +4 -0
+
+err:
+	if (err != 0)
+		args->flags = err;

Why the flags? We typically just return the error...

drivers/gpu/drm/drm_gem.c

Quoted 2 lines
drivers/gpu/drm/drm_gem.c +2 -0
+
+	return err;

... like here.

Quoted 1 line

+}

Do we want to export this so that drivers can use it?

Quoted 27 lines
drivers/gpu/drm/drm_gem.c +7 -0
+
+
 
 /**
 
  * drm_gem_object_release - release GEM buffer object resources
  * @obj: GEM buffer object
@@ -958,6 +1017,11 @@ drm_gem_object_release(struct drm_gem_object *obj)
 
 	dma_resv_fini(&obj->_resv);
 	drm_gem_free_mmap_offset(obj);
 
+
+	if (obj->label) {
+		kfree(obj->label);
+		obj->label = NULL;
+	}
 
 }

EXPORT_SYMBOL(drm_gem_object_release);

(quoted diff) +0 -0

b/drivers/gpu/drm/drm_internal.h index 51a2055c8f18..8259622f9ab6 100644

drivers/gpu/drm/drm_internal.h int drm_gem_pin(struct drm_gem_object *obj); · line 145

Quoted 9 lines
drivers/gpu/drm/drm_internal.h +3 -0
@@ -137,6 +137,10 @@ int drm_gem_pin(struct drm_gem_object *obj);
 
 void drm_gem_unpin(struct drm_gem_object *obj);
 void *drm_gem_vmap(struct drm_gem_object *obj);
 void drm_gem_vunmap(struct drm_gem_object *obj, void *vaddr);
 
+int drm_bo_set_label_ioctl(struct drm_device *dev, void *data,
+			struct drm_file *file_priv);
+int drm_gem_set_label(struct drm_device *dev, struct drm_label_object
 *args, +			struct drm_file *file_priv);

This one seems to be unused now.

Quoted 3 lines

/* drm_debugfs.c drm_debugfs_crc.c */
#if defined(CONFIG_DEBUG_FS)

Quoted 7 lines

drivers/gpu/drm/drm_ioctl.c static const struct drm_ioctl_desc drm_ioctls[] = { · line 710

Quoted 7 lines
drivers/gpu/drm/drm_ioctl.c +0 -0
index f675a3bb2c88..079d1422f9c5 100644
@@ -709,6 +709,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_LIST_LESSEES, 

drm_mode_list_lessees_ioctl,

Quoted 3 lines

drivers/gpu/drm/drm_ioctl.c static const struct drm_ioctl_desc drm_ioctls[] = { · line 713

Quoted 3 lines
drivers/gpu/drm/drm_ioctl.c +0 -0
 	DRM_MASTER), DRM_IOCTL_DEF(DRM_IOCTL_MODE_GET_LEASE,
 	drm_mode_get_lease_ioctl, DRM_MASTER),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_REVOKE_LEASE, 

drm_mode_revoke_lease_ioctl,

Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/drm_ioctl.c +1 -0
 	DRM_MASTER),> 
+	DRM_IOCTL_DEF(DRM_IOCTL_BO_SET_LABEL, drm_bo_set_label_ioctl,

DRM_RENDER_ALLOW),>
};

#define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )

include/drm/drm_drv.h +0 -0
index 8976afe48c1c..f736ba1f42a6 100644
@@ -715,6 +715,24 @@ struct drm_driver {
 
 			    struct drm_device *dev,
 			    uint32_t handle);
 
Quoted 9 lines

include/drm/drm_drv.h struct drm_driver {

Quoted 9 lines
include/drm/drm_drv.h +9 -0
+
+	/**
+	 * @label:
+	 *
+	 * This label's a buffer object.
+	 *
+	 * Called by the user via ioctl.
+	 *
+	 * The default implementation is drm_gem_label(). GEM based 

drivers

Quoted 5 lines

include/drm/drm_drv.h struct drm_driver { · line 729

Quoted 2 lines
include/drm/drm_drv.h +2 -0
+	 * must not overwrite this.
+

Spurious blank line.

Ack to all the above. I'll address these in v3!

Quoted 5 lines

include/drm/drm_drv.h struct drm_driver {

Quoted 5 lines
include/drm/drm_drv.h +5 -0
+	 * Returns:
+	 *
+	 * Zero on success, negative errno on failure.
+	 */
+	int (*label)(struct drm_device *dev, struct drm_label_object 

*args,

Quoted 10 lines

include/drm/drm_drv.h struct drm_driver { · line 735

Quoted 1 line
include/drm/drm_drv.h +1 -0
+				struct drm_file *file_priv);

If I understand correctly, you use this so that non-GEM drivers can use this IOCTL to label their non-GEM objects. Do you think that's really useful? I mean they've already got quite a bit of special code to deal with their objects, so singling out this IOCTL seems a bit odd.

Then again, I guess it doesn't really hurt since GEM-based drivers will always use the standard implementation.

Please refer to Thomas Zimmermann's reply earlier in this thread. This was also specifically requested as part of the v1 review of this patch.

Quoted 40 lines
Quoted 40 lines
include/drm/drm_drv.h +1 -0
+
 
 	/**
include/drm/drm_drv.h +0 -0
 	 * @gem_vm_ops: Driver private ops for this object
 	 *
include/drm/drm_gem.h +7 -0
index 6aaba14f5972..f801c054e972 100644
@@ -237,6 +237,13 @@ struct drm_gem_object {
 
 	 */
 
 	int name;
 
+	/**
+	 * @label:
+	 *
+	 * Label for this object, should be a human readable string.
+	 */
+	char *label;
+
 
include/drm/drm_gem.h +0 -0
 	/**
 
 	 * @dma_buf:
 	 *
include/uapi/drm/drm.h +0 -0
index 8a5b2f8f8eb9..23b507f5c571 100644
@@ -626,6 +626,25 @@ struct drm_gem_open {
 
 	__u64 size;
 
 };
 
Quoted 15 lines

include/uapi/drm/drm.h struct drm_gem_open { · line 639

Quoted 11 lines
include/uapi/drm/drm.h +11 -0
+/** struct drm_label_object - ioctl argument for labelling BOs.
+ *
+ * This label's a BO with a userspace label
+ *
+ */
+struct drm_label_object {
+	/** Handle for the object being labelled. */
+	__u32 handle;
+
+	/** Label and label length.
+	 *  length includes the trailing NULL.

Nit: I think you mean "trailing NUL". Also, the parameter is called len below, so the comment here should match.

Ack.

Thanks for the review!

Cheers
Rohan Garg

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw
Quoted 220 lines · Rohan Garg
Quoted 160 lines · On viernes, 20 de septiembre de 2019 17:25:10 (CEST) Thierry Reding wrote:
Quoted 23 lines · Rohan Garg

DRM_IOCTL_BO_SET_LABEL lets you label GEM objects, making it easier to debug issues in userspace applications.

Changes in v2:
- Hoist the IOCTL up into the drm_driver framework

---

 drivers/gpu/drm/drm_gem.c      | 64 ++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_internal.h |  4 +++
 drivers/gpu/drm/drm_ioctl.c    |  1 +
 include/drm/drm_drv.h          | 18 ++++++++++
 include/drm/drm_gem.h          |  7 ++++
 include/uapi/drm/drm.h         | 20 +++++++++++
 6 files changed, 114 insertions(+)
drivers/gpu/drm/drm_gem.c +0 -0
index 6854f5867d51..785ac561619a 100644
@@ -941,6 +941,65 @@ drm_gem_release(struct drm_device *dev, struct

drm_file *file_private)>

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 945

Quoted 6 lines
drivers/gpu/drm/drm_gem.c +2 -0
 	idr_destroy(&file_private->object_idr);
 
 }
 
+int drm_bo_set_label_ioctl(struct drm_device *dev, void *data,
+		       struct drm_file *file_priv)

Perhaps call this drm_gem_set_label_ioctl() so that it's consistent with the other GEM related IOCTLs?

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 947

Quoted 2 lines
drivers/gpu/drm/drm_gem.c +2 -0
+{
+	struct drm_label_object *args = data;

Similarly, perhaps make this struct drm_gem_set_label for consistency.

Quoted 18 lines
drivers/gpu/drm/drm_gem.c +14 -0
+
+	if (!args->len || !args->name)
+		return -EINVAL;
+
+	if (dev->driver->label)
+		return dev->driver->label(dev, args, file_priv);
+
+	return -EOPNOTSUPP;
+}
+
+/**
+ * drm_gem_label - label a given GEM object
+ * @dev: drm_device for the associated GEM object
+ * @data: drm_label_bo struct with a label, label length and any relevant

flags + * @file_private: drm file-private structure to clean up
+ */

drivers/gpu/drm/drm_gem.c +2 -0
+
+int drm_gem_set_label(struct drm_device *dev, struct drm_label_object
Quoted 1 line

*args, struct drm_file *file_priv)

Function name doesn't match the kerneldoc.

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private)

Quoted 7 lines
drivers/gpu/drm/drm_gem.c +7 -0
+{
+	struct drm_gem_object *gem_obj;
+	int err = 0;
+	char *label;
+
+	if (args->len > 0)
+		label = strndup_user(u64_to_user_ptr(args->name), args-

len);

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private)

Quoted 4 lines
drivers/gpu/drm/drm_gem.c +4 -0
+
+	gem_obj = drm_gem_object_lookup(file_priv, args->handle);
+	if (!gem_obj) {
+		DRM_ERROR("Failed to look up GEM BO %d\n", args-

handle);

People could abuse this to spam the system logs with these error messages. Better make this DRM_DEBUG() or leave it out completely.

drivers/gpu/drm/drm_gem.c

Quoted 2 lines
drivers/gpu/drm/drm_gem.c +2 -0
+		err = -ENOENT;
+		goto err;

I think you're leaking the label string here.

Quoted 5 lines
drivers/gpu/drm/drm_gem.c +5 -0
+	}
+
+	if ((args->len == 0 && args->name == NULL) || gem_obj->label) {
+		kfree(gem_obj->label);
+		gem_obj->label = NULL;

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 993

Quoted 10 lines
drivers/gpu/drm/drm_gem.c +10 -0
+	}
+
+	gem_obj->label = label;
+
+	drm_gem_object_put_unlocked(gem_obj);
+
+	if (IS_ERR(gem_obj->label)) {
+		err = PTR_ERR(gem_obj->label);
+		goto err;
+	}

Why don't you check for this earlier? That seems suboptimal because now you've got some error value in gem_obj->label that you're going to have to special case at every step of the way.

drivers/gpu/drm/drm_gem.c drm_gem_release(struct drm_device *dev, struct drm_file *file_private) · line 997

Quoted 4 lines
drivers/gpu/drm/drm_gem.c +4 -0
+
+err:
+	if (err != 0)
+		args->flags = err;

Why the flags? We typically just return the error...

drivers/gpu/drm/drm_gem.c

Quoted 2 lines
drivers/gpu/drm/drm_gem.c +2 -0
+
+	return err;

... like here.

Quoted 1 line

+}

Do we want to export this so that drivers can use it?

Quoted 27 lines
drivers/gpu/drm/drm_gem.c +7 -0
+
+
 
 /**
 
  * drm_gem_object_release - release GEM buffer object resources
  * @obj: GEM buffer object
@@ -958,6 +1017,11 @@ drm_gem_object_release(struct drm_gem_object *obj)
 
 	dma_resv_fini(&obj->_resv);
 	drm_gem_free_mmap_offset(obj);
 
+
+	if (obj->label) {
+		kfree(obj->label);
+		obj->label = NULL;
+	}
 
 }

EXPORT_SYMBOL(drm_gem_object_release);

(quoted diff) +0 -0

b/drivers/gpu/drm/drm_internal.h index 51a2055c8f18..8259622f9ab6 100644

drivers/gpu/drm/drm_internal.h int drm_gem_pin(struct drm_gem_object *obj); · line 145

Quoted 9 lines
drivers/gpu/drm/drm_internal.h +3 -0
@@ -137,6 +137,10 @@ int drm_gem_pin(struct drm_gem_object *obj);
 
 void drm_gem_unpin(struct drm_gem_object *obj);
 void *drm_gem_vmap(struct drm_gem_object *obj);
 void drm_gem_vunmap(struct drm_gem_object *obj, void *vaddr);
 
+int drm_bo_set_label_ioctl(struct drm_device *dev, void *data,
+			struct drm_file *file_priv);
+int drm_gem_set_label(struct drm_device *dev, struct drm_label_object
 *args, +			struct drm_file *file_priv);

This one seems to be unused now.

Quoted 3 lines

/* drm_debugfs.c drm_debugfs_crc.c */
#if defined(CONFIG_DEBUG_FS)

Quoted 7 lines

drivers/gpu/drm/drm_ioctl.c static const struct drm_ioctl_desc drm_ioctls[] = { · line 710

Quoted 7 lines
drivers/gpu/drm/drm_ioctl.c +0 -0
index f675a3bb2c88..079d1422f9c5 100644
@@ -709,6 +709,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_LIST_LESSEES, 

drm_mode_list_lessees_ioctl,

Quoted 3 lines

drivers/gpu/drm/drm_ioctl.c static const struct drm_ioctl_desc drm_ioctls[] = { · line 713

Quoted 3 lines
drivers/gpu/drm/drm_ioctl.c +0 -0
 	DRM_MASTER), DRM_IOCTL_DEF(DRM_IOCTL_MODE_GET_LEASE,
 	drm_mode_get_lease_ioctl, DRM_MASTER),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_REVOKE_LEASE, 

drm_mode_revoke_lease_ioctl,

Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/drm_ioctl.c +1 -0
 	DRM_MASTER),> 
+	DRM_IOCTL_DEF(DRM_IOCTL_BO_SET_LABEL, drm_bo_set_label_ioctl,

DRM_RENDER_ALLOW),>
};

#define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )

include/drm/drm_drv.h +0 -0
index 8976afe48c1c..f736ba1f42a6 100644
@@ -715,6 +715,24 @@ struct drm_driver {
 
 			    struct drm_device *dev,
 			    uint32_t handle);
 
Quoted 9 lines

include/drm/drm_drv.h struct drm_driver {

Quoted 9 lines
include/drm/drm_drv.h +9 -0
+
+	/**
+	 * @label:
+	 *
+	 * This label's a buffer object.
+	 *
+	 * Called by the user via ioctl.
+	 *
+	 * The default implementation is drm_gem_label(). GEM based 

drivers

Quoted 5 lines

include/drm/drm_drv.h struct drm_driver { · line 729

Quoted 2 lines
include/drm/drm_drv.h +2 -0
+	 * must not overwrite this.
+

Spurious blank line.

Ack to all the above. I'll address these in v3!

Quoted 5 lines

include/drm/drm_drv.h struct drm_driver {

Quoted 5 lines
include/drm/drm_drv.h +5 -0
+	 * Returns:
+	 *
+	 * Zero on success, negative errno on failure.
+	 */
+	int (*label)(struct drm_device *dev, struct drm_label_object 

*args,

Quoted 7 lines

include/drm/drm_drv.h struct drm_driver { · line 735

Quoted 1 line
include/drm/drm_drv.h +1 -0
+				struct drm_file *file_priv);

If I understand correctly, you use this so that non-GEM drivers can use this IOCTL to label their non-GEM objects. Do you think that's really useful? I mean they've already got quite a bit of special code to deal with their objects, so singling out this IOCTL seems a bit odd.

Quoted 6 lines
Quoted 3 lines

Then again, I guess it doesn't really hurt since GEM-based drivers will always use the standard implementation.

Please refer to Thomas Zimmermann's reply earlier in this thread. This was also specifically requested as part of the v1 review of this patch.

Imo ditch this. There's a grant total of 1 non-gem driver, and that one uses 0 of the other gem related sharing infrastructure. I don't expect any new non-gem driver to get merged, ever (we're merging ttm and gem internally, which was really the only reason).

And if vmwgfx wants to label objects, they can do that through their own ioctl.
-Daniel

Quoted 70 lines
Quoted 41 lines
Quoted 41 lines
include/drm/drm_drv.h +1 -0
+
 
 	/**
include/drm/drm_drv.h +0 -0
 	 * @gem_vm_ops: Driver private ops for this object
 	 *
include/drm/drm_gem.h +7 -0
index 6aaba14f5972..f801c054e972 100644
@@ -237,6 +237,13 @@ struct drm_gem_object {
 
 	 */
 
 	int name;
 
+	/**
+	 * @label:
+	 *
+	 * Label for this object, should be a human readable string.
+	 */
+	char *label;
+
 
include/drm/drm_gem.h +0 -0
 	/**
 
 	 * @dma_buf:
 	 *
include/uapi/drm/drm.h +0 -0
index 8a5b2f8f8eb9..23b507f5c571 100644
@@ -626,6 +626,25 @@ struct drm_gem_open {
 
 	__u64 size;
 
 };
 
Quoted 15 lines

include/uapi/drm/drm.h struct drm_gem_open { · line 639

Quoted 11 lines
include/uapi/drm/drm.h +11 -0
+/** struct drm_label_object - ioctl argument for labelling BOs.
+ *
+ * This label's a BO with a userspace label
+ *
+ */
+struct drm_label_object {
+	/** Handle for the object being labelled. */
+	__u32 handle;
+
+	/** Label and label length.
+	 *  length includes the trailing NULL.

Nit: I think you mean "trailing NUL". Also, the parameter is called len below, so the comment here should match.

Ack.

Thanks for the review!

Cheers
Rohan Garg

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel