drm/msm: Add comm/cmdline override
Subsystems (5)
cover drm/msm: Add comm/cmdline override
From: Rob Clark <[email protected]>
Add a way to override comm/cmdline per-drm_file. This is useful for VM scenarios where the host process is just a proxy for the actual guest process.
Rob Clark (3):
drm/msm: Add support for pointer params drm/msm: Split out helper to get comm/cmdline drm/msm: Add a way to override processes comm/cmdline
drivers/gpu/drm/msm/adreno/adreno_gpu.c | 46 +++++++++++++++++++++++-- drivers/gpu/drm/msm/adreno/adreno_gpu.h | 4 +-- drivers/gpu/drm/msm/msm_drv.c | 8 ++--- drivers/gpu/drm/msm/msm_gpu.c | 39 ++++++++++++--------- drivers/gpu/drm/msm/msm_gpu.h | 10 ++++-- drivers/gpu/drm/msm/msm_rd.c | 5 +-- drivers/gpu/drm/msm/msm_submitqueue.c | 2 ++ include/uapi/drm/msm_drm.h | 4 +++ 8 files changed, 90 insertions(+), 28 deletions(-)
Signature · 1 line
2.35.1
PATCH 1/3 drm/msm: Add support for pointer params
From: Rob Clark <[email protected]>
The 64b value field is already suffient to hold a pointer instead of immediate, but we also need a length field.
--- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 12 ++++++++++-- drivers/gpu/drm/msm/adreno/adreno_gpu.h | 4 ++-- drivers/gpu/drm/msm/msm_drv.c | 8 ++++---- drivers/gpu/drm/msm/msm_gpu.h | 4 ++-- drivers/gpu/drm/msm/msm_rd.c | 5 +++-- include/uapi/drm/msm_drm.h | 2 ++ 6 files changed, 23 insertions(+), 12 deletions(-)
drivers/gpu/drm/msm/adreno/adreno_gpu.c +10 -2
@@ -229,10 +229,14 @@ adreno_iommu_create_address_space(struct msm_gpu *gpu, }int adreno_get_param (struct msm_gpu *gpu,struct msm_file_private *ctx, -uint32_t param,uint64_t *value) +uint32_t param,uint64_t *value,uint32_t *len) {struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu); +/* No pointer params yet */ +if (*len !=0 ) +return -EINVAL ; +switch (param) {case MSM_PARAM_GPU_ID : *value = adreno_gpu->info->revn;
@@ -284,8 +288,12 @@ int adreno_get_param(struct msm_gpu *gpu, struct msm_file_private *ctx, }int adreno_set_param (struct msm_gpu *gpu,struct msm_file_private *ctx, -uint32_t param,uint64_t value) +uint32_t param,uint64_t value,uint32_t len) { +/* No pointer params yet */ +if (len !=0 ) +return -EINVAL ; +switch (param) {case MSM_PARAM_SYSPROF :if (!capable (CAP_SYS_ADMIN ))
drivers/gpu/drm/msm/adreno/adreno_gpu.h +2 -2
@@ -281,9 +281,9 @@ static inline int adreno_is_a650_family(struct adreno_gpu *gpu) }int adreno_get_param (struct msm_gpu *gpu,struct msm_file_private *ctx, -uint32_t param,uint64_t *value); +uint32_t param,uint64_t *value,uint32_t *len);int adreno_set_param (struct msm_gpu *gpu,struct msm_file_private *ctx, -uint32_t param,uint64_t value); +uint32_t param,uint64_t value,uint32_t len);const struct firmware *adreno_request_fw (struct adreno_gpu *adreno_gpu,const char *fwname); struct drm_gem_object *adreno_fw_create_bo(struct msm_gpu *gpu,
drivers/gpu/drm/msm/msm_drv.c +4 -4
@@ -610,7 +610,7 @@ static int msm_ioctl_get_param(struct drm_device *dev, void *data,/* for now, we just have 3d pipe.. eventually this would need to * be more clever to dispatch to appropriate gpu module: */ -if (args->pipe !=MSM_PIPE_3D0 ) +if ((args->pipe !=MSM_PIPE_3D0 ) || (args->pad !=0 ))return -EINVAL ; gpu = priv->gpu;
@@ -619,7 +619,7 @@ static int msm_ioctl_get_param(struct drm_device *dev, void *data,return -ENXIO ;return gpu->funcs->get_param (gpu, file->driver_priv, - args->param, &args->value); + args->param, &args->value, &args->len); } static int msm_ioctl_set_param(struct drm_device *dev, void *data,
@@ -629,7 +629,7 @@ static int msm_ioctl_set_param(struct drm_device *dev, void *data,struct drm_msm_param *args = data;struct msm_gpu *gpu; -if (args->pipe !=MSM_PIPE_3D0 ) +if ((args->pipe !=MSM_PIPE_3D0 ) || (args->pad !=0 ))return -EINVAL ; gpu = priv->gpu;
@@ -638,7 +638,7 @@ static int msm_ioctl_set_param(struct drm_device *dev, void *data,return -ENXIO ;return gpu->funcs->set_param (gpu, file->driver_priv, - args->param, args->value); + args->param, args->value, args->len); } static int msm_ioctl_gem_new(struct drm_device *dev, void *data,
drivers/gpu/drm/msm/msm_gpu.h +2 -2
@@ -44,9 +44,9 @@ struct msm_gpu_config {*/ struct msm_gpu_funcs {int (*get_param)(struct msm_gpu *gpu,struct msm_file_private *ctx, -uint32_t param,uint64_t *value); +uint32_t param,uint64_t *value,uint32_t *len);int (*set_param)(struct msm_gpu *gpu,struct msm_file_private *ctx, -uint32_t param,uint64_t value); +uint32_t param,uint64_t value,uint32_t len);int (*hw_init)(struct msm_gpu *gpu);int (*pm_suspend)(struct msm_gpu *gpu);int (*pm_resume)(struct msm_gpu *gpu);
drivers/gpu/drm/msm/msm_rd.c +3 -2
@@ -180,6 +180,7 @@ static int rd_open(struct inode *inode, struct file *file)struct msm_gpu *gpu = priv->gpu;uint64_t val;uint32_t gpu_id; +uint32_t zero =0 ;int ret =0 ;if (!gpu)
@@ -200,12 +201,12 @@ static int rd_open(struct inode *inode, struct file *file)* * Note: These particular params do not require a context */ - gpu->funcs->get_param (gpu,NULL ,MSM_PARAM_GPU_ID , &val); + gpu->funcs->get_param (gpu,NULL ,MSM_PARAM_GPU_ID , &val, &zero); gpu_id = val;rd_write_section (rd,RD_GPU_ID , &gpu_id,sizeof (gpu_id)); - gpu->funcs->get_param (gpu,NULL ,MSM_PARAM_CHIP_ID , &val); + gpu->funcs->get_param (gpu,NULL ,MSM_PARAM_CHIP_ID , &val, &zero);rd_write_section (rd,RD_CHIP_ID , &val,sizeof (val)); out:
include/uapi/drm/msm_drm.h +2 -0
@@ -95,6 +95,8 @@ struct drm_msm_param {__u32 pipe;/* in, MSM_PIPE_x */ __u32 param;/* in, MSM_PARAM_x */ __u64 value;/* out (get_param) or in (set_param) */ +__u32 len;/* zero for non-pointer params */ +__u32 pad;/* must be zero */ };/*
Signature · 1 line
2.35.1
PATCH 2/3 drm/msm: Split out helper to get comm/cmdline
In reply to Rob ClarkFrom: Rob Clark <[email protected]>
Deduplicate this from fault_worker and recover_worker.
--- drivers/gpu/drm/msm/msm_gpu.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
drivers/gpu/drm/msm/msm_gpu.c +16 -16
@@ -362,6 +362,20 @@ find_submit(struct msm_ringbuffer *ring, uint32_t fence)static void retire_submits (struct msm_gpu *gpu); +static void get_comm_cmdline (struct msm_gem_submit *submit,char **comm,char **cmd) +{ +struct task_struct *task; + + task =get_pid_task (submit->pid,PIDTYPE_PID ); +if (!task) +return ; + + *comm =kstrdup (task->comm,GFP_KERNEL ); + *cmd =kstrdup_quotable_cmdline (task,GFP_KERNEL ); + +put_task_struct (task); +} +static void recover_worker (struct kthread_work *work) { struct msm_gpu *gpu = container_of(work, struct msm_gpu, recover_work);
@@ -378,18 +392,11 @@ static void recover_worker(struct kthread_work *work) submit =find_submit (cur_ring, cur_ring->memptrs->fence +1 );if (submit) { -struct task_struct *task; -/* Increment the fault counts */ submit->queue->faults++; submit->aspace->faults++; - task =get_pid_task (submit->pid,PIDTYPE_PID ); -if (task) { - comm =kstrdup (task->comm,GFP_KERNEL ); - cmd =kstrdup_quotable_cmdline (task,GFP_KERNEL ); -put_task_struct (task); - } +get_comm_cmdline (submit, &comm, &cmd);if (comm && cmd) { DRM_DEV_ERROR(dev->dev, "%s: offending task: %s (%s)\n",
@@ -478,14 +485,7 @@ static void fault_worker(struct kthread_work *work) goto resume_smmu;if (submit) { -struct task_struct *task; - - task =get_pid_task (submit->pid,PIDTYPE_PID ); -if (task) { - comm =kstrdup (task->comm,GFP_KERNEL ); - cmd =kstrdup_quotable_cmdline (task,GFP_KERNEL ); -put_task_struct (task); - } +get_comm_cmdline (submit, &comm, &cmd);/* * When we get GPU iova faults, we can get 1000s of them,
Signature · 1 line
2.35.1
PATCH 3/3 drm/msm: Add a way to override processes comm/cmdline
In reply to Rob ClarkFrom: Rob Clark <[email protected]>
In the cause of using the GPU via virtgpu, the host side process is really a sort of proxy, and not terribly interesting from the PoV of crash/fault logging. Add a way to override these per process so that we can see the guest process's name.
--- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 40 +++++++++++++++++++++++-- drivers/gpu/drm/msm/msm_gpu.c | 11 +++++-- drivers/gpu/drm/msm/msm_gpu.h | 6 ++++ drivers/gpu/drm/msm/msm_submitqueue.c | 2 ++ include/uapi/drm/msm_drm.h | 2 ++ 5 files changed, 56 insertions(+), 5 deletions(-)
drivers/gpu/drm/msm/adreno/adreno_gpu.c +37 -3
@@ -290,11 +290,45 @@ int adreno_get_param(struct msm_gpu *gpu, struct msm_file_private *ctx,int adreno_set_param (struct msm_gpu *gpu,struct msm_file_private *ctx,uint32_t param,uint64_t value,uint32_t len) { -/* No pointer params yet */ -if (len !=0 ) -return -EINVAL ; +switch (param) { +case MSM_PARAM_COMM : +case MSM_PARAM_CMDLINE : +/* kstrdup_quotable_cmdline() limits to PAGE_SIZE, so +* that should be a reasonable upper bound +*/ +if (len >PAGE_SIZE ) +return -EINVAL ; +break ; +default : +if (len !=0 ) +return -EINVAL ; + }switch (param) { +case MSM_PARAM_COMM : +case MSM_PARAM_CMDLINE : { +char *str, **paramp; + + str =kmalloc (len +1 ,GFP_KERNEL ); +if (copy_from_user (str,u64_to_user_ptr (value), len)) { +kfree (str); +return -EFAULT ; + } + +/* Ensure string is null terminated: */ + str[len] ='\0' ; + +if (param ==MSM_PARAM_COMM ) { + paramp = &ctx->comm; + }else { + paramp = &ctx->cmdline; + } + +kfree (*paramp); + *paramp = str; + +return 0 ; + }case MSM_PARAM_SYSPROF :if (!capable (CAP_SYS_ADMIN ))return -EPERM ;
drivers/gpu/drm/msm/msm_gpu.c +9 -2
@@ -364,14 +364,21 @@ static void retire_submits(struct msm_gpu *gpu);static void get_comm_cmdline (struct msm_gem_submit *submit,char **comm,char **cmd) { +struct msm_file_private *ctx = submit->queue->ctx;struct task_struct *task; + *comm =kstrdup (ctx->comm,GFP_KERNEL ); + *cmd =kstrdup (ctx->cmdline,GFP_KERNEL ); + task =get_pid_task (submit->pid,PIDTYPE_PID );if (!task)return ; - *comm =kstrdup (task->comm,GFP_KERNEL ); - *cmd =kstrdup_quotable_cmdline (task,GFP_KERNEL ); +if (!*comm) + *comm =kstrdup (task->comm,GFP_KERNEL ); + +if (!*cmd) + *cmd =kstrdup_quotable_cmdline (task,GFP_KERNEL );put_task_struct (task); }
drivers/gpu/drm/msm/msm_gpu.h +6 -0
@@ -355,6 +355,12 @@ struct msm_file_private {*/ int sysprof; +/** comm: Overridden task comm, see MSM_PARAM_COMM */ +char *comm; + +/** cmdline: Overridden task cmdline, see MSM_PARAM_CMDLINE */ +char *cmdline; +/** * elapsed: *
drivers/gpu/drm/msm/msm_submitqueue.c +2 -0
@@ -61,6 +61,8 @@ void __msm_file_private_destroy(struct kref *kref) }msm_gem_address_space_put (ctx->aspace); +kfree (ctx->comm); +kfree (ctx->cmdline);kfree (ctx); }
include/uapi/drm/msm_drm.h +2 -0
@@ -82,6 +82,8 @@ struct drm_msm_timespec {#define MSM_PARAM_FAULTS 0x09/* RO */ #define MSM_PARAM_SUSPENDS 0x0a/* RO */ #define MSM_PARAM_SYSPROF 0x0b/* WO: 1 preserves perfcntrs, 2 also disables suspend */ +#define MSM_PARAM_COMM 0x0c/* WO: override for task->comm */ +#define MSM_PARAM_CMDLINE 0x0d/* WO: override for task cmdline */ /* For backwards compat. The original support for preemption was based on * a single ring per priority level so # of priority levels equals the #
Signature · 1 line
2.35.1
Re: [PATCH 3/3] drm/msm: Add a way to override processes comm/cmdline
drivers/gpu/drm/msm/adreno/adreno_gpu.c int adreno_get_param(struct msm_gpu *gpu, struct msm_file_private *ctx, · line 312
Quoted 6 lines · Rob Clark
drivers/gpu/drm/msm/adreno/adreno_gpu.c +5
-0switch (param) { +case MSM_PARAM_COMM : +case MSM_PARAM_CMDLINE : { +char *str, **paramp; + + str =kmalloc (len +1 ,GFP_KERNEL );
if (!str)
return -ENOMEM;
Quoted 34 lines
drivers/gpu/drm/msm/adreno/adreno_gpu.c +19
-0+if (copy_from_user (str,u64_to_user_ptr (value), len)) { +kfree (str); +return -EFAULT ; + } + +/* Ensure string is null terminated: */ + str[len] ='\0' ; + +if (param ==MSM_PARAM_COMM ) { + paramp = &ctx->comm; + }else { + paramp = &ctx->cmdline; + } + +kfree (*paramp); + *paramp = str; + +return 0 ; + }case MSM_PARAM_SYSPROF :if (!capable (CAP_SYS_ADMIN ))return -EPERM ;drivers/gpu/drm/msm/msm_gpu.c +2
-0@@ -364,14 +364,21 @@ static void retire_submits(struct msm_gpu *gpu);static void get_comm_cmdline (struct msm_gem_submit *submit,char **comm,char **cmd) { +struct msm_file_private *ctx = submit->queue->ctx;struct task_struct *task; + *comm =kstrdup (ctx->comm,GFP_KERNEL );
drivers/gpu/drm/msm/msm_gpu.c static void retire_submits(struct msm_gpu *gpu); · line 378
Quoted 10 lines
drivers/gpu/drm/msm/msm_gpu.c +4
-2+ *cmd =kstrdup (ctx->cmdline,GFP_KERNEL ); + task =get_pid_task (submit->pid,PIDTYPE_PID );if (!task)return ; - *comm =kstrdup (task->comm,GFP_KERNEL ); - *cmd =kstrdup_quotable_cmdline (task,GFP_KERNEL ); +if (!*comm) + *comm =kstrdup (task->comm,GFP_KERNEL );
What?
If the first allocation failed, then this one is going to fail as well. Just return -ENOMEM. Or maybe this is meant to be checking for an empty string?
drivers/gpu/drm/msm/msm_gpu.c static void retire_submits(struct msm_gpu *gpu); · line 381
Quoted 3 lines
drivers/gpu/drm/msm/msm_gpu.c +3
-0+ +if (!*cmd) + *cmd =kstrdup_quotable_cmdline (task,GFP_KERNEL );
Same.
drivers/gpu/drm/msm/msm_gpu.c static void retire_submits(struct msm_gpu *gpu); · line 384
Quoted 3 lines
drivers/gpu/drm/msm/msm_gpu.c +0
-0put_task_struct (task); }
regards,
dan carpenter
Re: [PATCH 3/3] drm/msm: Add a way to override processes comm/cmdline
Quoted 59 lines · Dan Carpenter
drivers/gpu/drm/msm/adreno/adreno_gpu.c int adreno_get_param(struct msm_gpu *gpu, struct msm_file_private *ctx, · line 312
Quoted 6 lines · Rob Clark
switch (param) {drivers/gpu/drm/msm/adreno/adreno_gpu.c +5
-0+case MSM_PARAM_COMM : +case MSM_PARAM_CMDLINE : { +char *str, **paramp; + + str =kmalloc (len +1 ,GFP_KERNEL );if (!str)
return -ENOMEM;Quoted 34 lines
drivers/gpu/drm/msm/adreno/adreno_gpu.c +19
-0+if (copy_from_user (str,u64_to_user_ptr (value), len)) { +kfree (str); +return -EFAULT ; + } + +/* Ensure string is null terminated: */ + str[len] ='\0' ; + +if (param ==MSM_PARAM_COMM ) { + paramp = &ctx->comm; + }else { + paramp = &ctx->cmdline; + } + +kfree (*paramp); + *paramp = str; + +return 0 ; + }case MSM_PARAM_SYSPROF :if (!capable (CAP_SYS_ADMIN ))return -EPERM ;drivers/gpu/drm/msm/msm_gpu.c +2
-0@@ -364,14 +364,21 @@ static void retire_submits(struct msm_gpu *gpu);static void get_comm_cmdline (struct msm_gem_submit *submit,char **comm,char **cmd) { +struct msm_file_private *ctx = submit->queue->ctx;struct task_struct *task; + *comm =kstrdup (ctx->comm,GFP_KERNEL );drivers/gpu/drm/msm/msm_gpu.c static void retire_submits(struct msm_gpu *gpu); · line 378
Quoted 10 lines
drivers/gpu/drm/msm/msm_gpu.c +4
-2+ *cmd =kstrdup (ctx->cmdline,GFP_KERNEL ); + task =get_pid_task (submit->pid,PIDTYPE_PID );if (!task)return ; - *comm =kstrdup (task->comm,GFP_KERNEL ); - *cmd =kstrdup_quotable_cmdline (task,GFP_KERNEL ); +if (!*comm) + *comm =kstrdup (task->comm,GFP_KERNEL );What?
Quoted 3 lines
If the first allocation failed, then this one is going to fail as well. Just return
-ENOMEM. Or maybe this is meant to be checking for an empty string?
fwiw, if ctx->comm is NULL, the kstrdup() will return NULL, so this isn't intended to deal with OoM, but the case that comm and/or cmdline is not overridden.
BR,
-R
Quoted 14 lines
drivers/gpu/drm/msm/msm_gpu.c static void retire_submits(struct msm_gpu *gpu); · line 381
Quoted 4 lines
drivers/gpu/drm/msm/msm_gpu.c +3
-0+ +if (!*cmd) + *cmd =kstrdup_quotable_cmdline (task,GFP_KERNEL );Same.
drivers/gpu/drm/msm/msm_gpu.c static void retire_submits(struct msm_gpu *gpu); · line 384
Quoted 3 lines
drivers/gpu/drm/msm/msm_gpu.c +0
-0put_task_struct (task); }regards,
dan carpenter
Re: [PATCH 3/3] drm/msm: Add a way to override processes comm/cmdline
Quoted 25 lines · Rob Clark
Quoted 25 lines
Quoted 12 lines
drivers/gpu/drm/msm/msm_gpu.c +2
-0@@ -364,14 +364,21 @@ static void retire_submits(struct msm_gpu *gpu);static void get_comm_cmdline (struct msm_gem_submit *submit,char **comm,char **cmd) { +struct msm_file_private *ctx = submit->queue->ctx;struct task_struct *task; + *comm =kstrdup (ctx->comm,GFP_KERNEL );drivers/gpu/drm/msm/msm_gpu.c static void retire_submits(struct msm_gpu *gpu); · line 378
Quoted 10 lines
drivers/gpu/drm/msm/msm_gpu.c +4
-2+ *cmd =kstrdup (ctx->cmdline,GFP_KERNEL ); + task =get_pid_task (submit->pid,PIDTYPE_PID );if (!task)return ; - *comm =kstrdup (task->comm,GFP_KERNEL ); - *cmd =kstrdup_quotable_cmdline (task,GFP_KERNEL ); +if (!*comm) + *comm =kstrdup (task->comm,GFP_KERNEL );What?
Quoted 7 lines
Quoted 3 lines
If the first allocation failed, then this one is going to fail as well. Just return
-ENOMEM. Or maybe this is meant to be checking for an empty string?fwiw, if
ctx->commis NULL, thekstrdup()will return NULL, so this isn't intended to deal with OoM, but the case that comm and/or cmdline is not overridden.
Ah, I should have thought about that. Thanks!
regards,
dan carpenter
Re: [PATCH 3/3] drm/msm: Add a way to override processes comm/cmdline
Quoted 31 lines · Dan Carpenter
Quoted 29 lines · Rob Clark
Quoted 28 lines
Quoted 12 lines
drivers/gpu/drm/msm/msm_gpu.c +2
-0@@ -364,14 +364,21 @@ static void retire_submits(struct msm_gpu *gpu);static void get_comm_cmdline (struct msm_gem_submit *submit,char **comm,char **cmd) { +struct msm_file_private *ctx = submit->queue->ctx;struct task_struct *task; + *comm =kstrdup (ctx->comm,GFP_KERNEL );drivers/gpu/drm/msm/msm_gpu.c static void retire_submits(struct msm_gpu *gpu); · line 378
Quoted 10 lines
drivers/gpu/drm/msm/msm_gpu.c +4
-2+ *cmd =kstrdup (ctx->cmdline,GFP_KERNEL ); + task =get_pid_task (submit->pid,PIDTYPE_PID );if (!task)return ; - *comm =kstrdup (task->comm,GFP_KERNEL ); - *cmd =kstrdup_quotable_cmdline (task,GFP_KERNEL ); +if (!*comm) + *comm =kstrdup (task->comm,GFP_KERNEL );What?
If the first allocation failed, then this one is going to fail as well. Just return
-ENOMEM. Or maybe this is meant to be checking for an empty string?
Quoted 5 lines
Quoted 3 lines
fwiw, if
ctx->commis NULL, thekstrdup()will return NULL, so this isn't intended to deal with OoM, but the case that comm and/or cmdline is not overridden.Ah, I should have thought about that. Thanks!
np, I realized it was fairly non-obvious so I added a comment in v2 to hopefully make it more clear
BR,
-R
Quoted 3 lines
regards,
dan carpenter