drm/uapi: add explicit virtgpu context debug name

There are two problems with the current method of determining the
virtio-gpu debug name.

1) TASK_COMM_LEN is defined to be 16 bytes only, and this is a
   Linux kernel idiom (see PR_SET_NAME + PR_GET_NAME). Though,
   Android/FreeBSD get around this via setprogname(..)/getprogname(..)
   in libc.

   On Android, names longer than 16 bytes are common.  For example,
   one often encounters a program like "com.android.systemui".

   The virtio-gpu spec allows the debug name to be up to 64 bytes, so
   ideally userspace should be able to set debug names up to 64 bytes.

2) The current implementation determines the debug name using whatever
   task initiated virtgpu.  This is could be a "RenderThread" of a
   larger program, when we actually want to propagate the debug name
   of the program.

To fix these issues, add a new CONTEXT_INIT param that allows userspace
to set the debug name when creating a context.

It takes a null-terminated C-string as the param value. The length of the
string (excluding the terminator) **should** be <= 64 bytes.  Otherwise,
the debug_name will be truncated to 64 bytes.

Link to open-source userspace:
https://android-review.googlesource.com/c/platform/hardware/google/gfxstream/+/2787176

Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Josh Simonot <josh.simonot@gmail.com>
Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20231018181727.772-2-gurchetansingh@chromium.org
This commit is contained in:
Gurchetan Singh 2023-10-18 11:17:27 -07:00 committed by Dmitry Osipenko
parent e417825609
commit 7add80126b
3 changed files with 37 additions and 6 deletions

View File

@ -58,6 +58,9 @@
#define MAX_CAPSET_ID 63 #define MAX_CAPSET_ID 63
#define MAX_RINGS 64 #define MAX_RINGS 64
/* See virtio_gpu_ctx_create. One additional character for NULL terminator. */
#define DEBUG_NAME_MAX_LEN 65
struct virtio_gpu_object_params { struct virtio_gpu_object_params {
unsigned long size; unsigned long size;
bool dumb; bool dumb;
@ -274,6 +277,8 @@ struct virtio_gpu_fpriv {
uint64_t base_fence_ctx; uint64_t base_fence_ctx;
uint64_t ring_idx_mask; uint64_t ring_idx_mask;
struct mutex context_lock; struct mutex context_lock;
char debug_name[DEBUG_NAME_MAX_LEN];
bool explicit_debug_name;
}; };
/* virtgpu_ioctl.c */ /* virtgpu_ioctl.c */

View File

@ -42,12 +42,19 @@
static void virtio_gpu_create_context_locked(struct virtio_gpu_device *vgdev, static void virtio_gpu_create_context_locked(struct virtio_gpu_device *vgdev,
struct virtio_gpu_fpriv *vfpriv) struct virtio_gpu_fpriv *vfpriv)
{ {
char dbgname[TASK_COMM_LEN]; if (vfpriv->explicit_debug_name) {
virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id,
vfpriv->context_init,
strlen(vfpriv->debug_name),
vfpriv->debug_name);
} else {
char dbgname[TASK_COMM_LEN];
get_task_comm(dbgname, current); get_task_comm(dbgname, current);
virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id, virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id,
vfpriv->context_init, strlen(dbgname), vfpriv->context_init, strlen(dbgname),
dbgname); dbgname);
}
vfpriv->context_created = true; vfpriv->context_created = true;
} }
@ -107,6 +114,9 @@ static int virtio_gpu_getparam_ioctl(struct drm_device *dev, void *data,
case VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs: case VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs:
value = vgdev->capset_id_mask; value = vgdev->capset_id_mask;
break; break;
case VIRTGPU_PARAM_EXPLICIT_DEBUG_NAME:
value = vgdev->has_context_init ? 1 : 0;
break;
default: default:
return -EINVAL; return -EINVAL;
} }
@ -580,7 +590,7 @@ static int virtio_gpu_context_init_ioctl(struct drm_device *dev,
return -EINVAL; return -EINVAL;
/* Number of unique parameters supported at this time. */ /* Number of unique parameters supported at this time. */
if (num_params > 3) if (num_params > 4)
return -EINVAL; return -EINVAL;
ctx_set_params = memdup_user(u64_to_user_ptr(args->ctx_set_params), ctx_set_params = memdup_user(u64_to_user_ptr(args->ctx_set_params),
@ -642,6 +652,20 @@ static int virtio_gpu_context_init_ioctl(struct drm_device *dev,
vfpriv->ring_idx_mask = value; vfpriv->ring_idx_mask = value;
break; break;
case VIRTGPU_CONTEXT_PARAM_DEBUG_NAME:
if (vfpriv->explicit_debug_name) {
ret = -EINVAL;
goto out_unlock;
}
ret = strncpy_from_user(vfpriv->debug_name,
u64_to_user_ptr(value),
DEBUG_NAME_MAX_LEN - 1);
if (ret < 0)
goto out_unlock;
vfpriv->explicit_debug_name = true;
break;
default: default:
ret = -EINVAL; ret = -EINVAL;
goto out_unlock; goto out_unlock;

View File

@ -97,6 +97,7 @@ struct drm_virtgpu_execbuffer {
#define VIRTGPU_PARAM_CROSS_DEVICE 5 /* Cross virtio-device resource sharing */ #define VIRTGPU_PARAM_CROSS_DEVICE 5 /* Cross virtio-device resource sharing */
#define VIRTGPU_PARAM_CONTEXT_INIT 6 /* DRM_VIRTGPU_CONTEXT_INIT */ #define VIRTGPU_PARAM_CONTEXT_INIT 6 /* DRM_VIRTGPU_CONTEXT_INIT */
#define VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs 7 /* Bitmask of supported capability set ids */ #define VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs 7 /* Bitmask of supported capability set ids */
#define VIRTGPU_PARAM_EXPLICIT_DEBUG_NAME 8 /* Ability to set debug name from userspace */
struct drm_virtgpu_getparam { struct drm_virtgpu_getparam {
__u64 param; __u64 param;
@ -198,6 +199,7 @@ struct drm_virtgpu_resource_create_blob {
#define VIRTGPU_CONTEXT_PARAM_CAPSET_ID 0x0001 #define VIRTGPU_CONTEXT_PARAM_CAPSET_ID 0x0001
#define VIRTGPU_CONTEXT_PARAM_NUM_RINGS 0x0002 #define VIRTGPU_CONTEXT_PARAM_NUM_RINGS 0x0002
#define VIRTGPU_CONTEXT_PARAM_POLL_RINGS_MASK 0x0003 #define VIRTGPU_CONTEXT_PARAM_POLL_RINGS_MASK 0x0003
#define VIRTGPU_CONTEXT_PARAM_DEBUG_NAME 0x0004
struct drm_virtgpu_context_set_param { struct drm_virtgpu_context_set_param {
__u64 param; __u64 param;
__u64 value; __u64 value;