<div dir="ltr"><pre><font size="2" style="font-family:arial,sans-serif">Reviewed-by: Josh Simonot <josh.simonot at <a href="http://gmail.com" target="_blank">gmail.com</a>></font></pre></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 16 Oct 2023 at 14:42, Gurchetan Singh <<a href="mailto:gurchetansingh@chromium.org">gurchetansingh@chromium.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This allows setting the debug name during CONTEXT_INIT.<br>
<br>
Signed-off-by: Gurchetan Singh <<a href="mailto:gurchetansingh@chromium.org" target="_blank">gurchetansingh@chromium.org</a>><br>
---<br>
drivers/gpu/drm/virtio/virtgpu_drv.h | 4 +++<br>
drivers/gpu/drm/virtio/virtgpu_ioctl.c | 38 ++++++++++++++++++++++----<br>
2 files changed, 36 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h<br>
index 96365a772f77..c0702d630e05 100644<br>
--- a/drivers/gpu/drm/virtio/virtgpu_drv.h<br>
+++ b/drivers/gpu/drm/virtio/virtgpu_drv.h<br>
@@ -58,6 +58,8 @@<br>
#define MAX_CAPSET_ID 63<br>
#define MAX_RINGS 64<br>
<br>
+#define DEBUG_NAME_MAX_LEN 64<br>
+<br>
struct virtio_gpu_object_params {<br>
unsigned long size;<br>
bool dumb;<br>
@@ -274,6 +276,8 @@ struct virtio_gpu_fpriv {<br>
uint64_t base_fence_ctx;<br>
uint64_t ring_idx_mask;<br>
struct mutex context_lock;<br>
+ char debug_name[DEBUG_NAME_MAX_LEN];<br>
+ char explicit_debug_name;<br>
};<br>
<br>
/* virtgpu_ioctl.c */<br>
diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c<br>
index 8d13b17c215b..4d6d44a4c899 100644<br>
--- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c<br>
+++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c<br>
@@ -42,12 +42,19 @@<br>
static void virtio_gpu_create_context_locked(struct virtio_gpu_device *vgdev,<br>
struct virtio_gpu_fpriv *vfpriv)<br>
{<br>
- char dbgname[TASK_COMM_LEN];<br>
+ if (vfpriv->explicit_debug_name) {<br>
+ virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id,<br>
+ vfpriv->context_init,<br>
+ strlen(vfpriv->debug_name),<br>
+ vfpriv->debug_name);<br>
+ } else {<br>
+ char dbgname[TASK_COMM_LEN];<br>
<br>
- get_task_comm(dbgname, current);<br>
- virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id,<br>
- vfpriv->context_init, strlen(dbgname),<br>
- dbgname);<br>
+ get_task_comm(dbgname, current);<br>
+ virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id,<br>
+ vfpriv->context_init, strlen(dbgname),<br>
+ dbgname);<br>
+ }<br>
<br>
vfpriv->context_created = true;<br>
}<br>
@@ -107,6 +114,9 @@ static int virtio_gpu_getparam_ioctl(struct drm_device *dev, void *data,<br>
case VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs:<br>
value = vgdev->capset_id_mask;<br>
break;<br>
+ case VIRTGPU_PARAM_EXPLICIT_DEBUG_NAME:<br>
+ value = vgdev->has_context_init ? 1 : 0;<br>
+ break;<br>
default:<br>
return -EINVAL;<br>
}<br>
@@ -580,7 +590,7 @@ static int virtio_gpu_context_init_ioctl(struct drm_device *dev,<br>
return -EINVAL;<br>
<br>
/* Number of unique parameters supported at this time. */<br>
- if (num_params > 3)<br>
+ if (num_params > 4)<br>
return -EINVAL;<br>
<br>
ctx_set_params = memdup_user(u64_to_user_ptr(args->ctx_set_params),<br>
@@ -642,6 +652,22 @@ static int virtio_gpu_context_init_ioctl(struct drm_device *dev,<br>
<br>
vfpriv->ring_idx_mask = value;<br>
break;<br>
+ case VIRTGPU_CONTEXT_PARAM_DEBUG_NAME:<br>
+ if (vfpriv->explicit_debug_name) {<br>
+ ret = -EINVAL;<br>
+ goto out_unlock;<br>
+ }<br>
+<br>
+ ret = strncpy_from_user(vfpriv->debug_name,<br>
+ (const char __user *)u64_to_user_ptr(value),<br>
+ DEBUG_NAME_MAX_LEN);<br>
+ if (ret < 0) {<br>
+ ret = -EFAULT;<br>
+ goto out_unlock;<br>
+ }<br>
+<br>
+ vfpriv->explicit_debug_name = true;<br>
+ break;<br>
default:<br>
ret = -EINVAL;<br>
goto out_unlock;<br>
-- <br>
2.42.0.655.g421f12c284-goog<br>
<br>
</blockquote></div>