History

drm/msm: Add a way to override processes comm/cmdline

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. v2: Handle kmalloc failure, add comment to explain kstrdup returns NULL if passed NULL [Dan Carpenter]

Rob Clark committed 4 years ago

Commit d4726d71 parent 39ba0c05 files · +60 −5Browse files

Unified · Split

5 files
  1. drivers/gpu/drm/msm/adreno/adreno_gpu.c +40 −3
  2. drivers/gpu/drm/msm/msm_gpu.c +10 −2
  3. drivers/gpu/drm/msm/msm_gpu.h +6 −0
  4. drivers/gpu/drm/msm/msm_submitqueue.c +2 −0
  5. include/uapi/drm/msm_drm.h +2 −0
drivers/gpu/drm/msm/adreno/adreno_gpu.c+40−3
@@ -290,11 +290,48 @@ int adreno_get_param(struct msm_gpu *gpu, struct msm_file_private *ctx, · 289 unmodified lines
290290 int adreno_set_param(struct msm_gpu *gpu, struct msm_file_private *ctx,
291291 uint32_t param, uint64_t value, uint32_t len)
292292 {
293− /* No pointer params yet */
294− if (len != 0)
295− return -EINVAL;
293+ switch (param) {
294+ case MSM_PARAM_COMM:
295+ case MSM_PARAM_CMDLINE:
296+ /* kstrdup_quotable_cmdline() limits to PAGE_SIZE, so
297+ * that should be a reasonable upper bound
298+ */
299+ if (len > PAGE_SIZE)
300+ return -EINVAL;
301+ break;
302+ default:
303+ if (len != 0)
304+ return -EINVAL;
305+ }
296306
297307 switch (param) {
308+ case MSM_PARAM_COMM:
309+ case MSM_PARAM_CMDLINE: {
310+ char *str, **paramp;
311+
312+ str = kmalloc(len + 1, GFP_KERNEL);
313+ if (!str)
314+ return -ENOMEM;
315+
316+ if (copy_from_user(str, u64_to_user_ptr(value), len)) {
317+ kfree(str);
318+ return -EFAULT;
319+ }
320+
321+ /* Ensure string is null terminated: */
322+ str[len] = '\0';
323+
324+ if (param == MSM_PARAM_COMM) {
325+ paramp = &ctx->comm;
326+ } else {
327+ paramp = &ctx->cmdline;
328+ }
329+
330+ kfree(*paramp);
331+ *paramp = str;
332+
333+ return 0;
334+ }
298335 case MSM_PARAM_SYSPROF:
299336 if (!capable(CAP_SYS_ADMIN))
300337 return -EPERM;
drivers/gpu/drm/msm/msm_gpu.c+10−2
@@ -353,14 +353,22 @@ static void retire_submits(struct msm_gpu *gpu); · 352 unmodified lines
353353
354354 static void get_comm_cmdline(struct msm_gem_submit *submit, char **comm, char **cmd)
355355 {
356+ struct msm_file_private *ctx = submit->queue->ctx;
356357 struct task_struct *task;
357358
359+ /* Note that kstrdup will return NULL if argument is NULL: */
360+ *comm = kstrdup(ctx->comm, GFP_KERNEL);
361+ *cmd = kstrdup(ctx->cmdline, GFP_KERNEL);
362+
358363 task = get_pid_task(submit->pid, PIDTYPE_PID);
359364 if (!task)
360365 return;
361366
362− *comm = kstrdup(task->comm, GFP_KERNEL);
363− *cmd = kstrdup_quotable_cmdline(task, GFP_KERNEL);
367+ if (!*comm)
368+ *comm = kstrdup(task->comm, GFP_KERNEL);
369+
370+ if (!*cmd)
371+ *cmd = kstrdup_quotable_cmdline(task, GFP_KERNEL);
364372
365373 put_task_struct(task);
366374 }
drivers/gpu/drm/msm/msm_gpu.h+6−0
@@ -355,6 +355,12 @@ struct msm_file_private { · 354 unmodified lines
355355 */
356356 int sysprof;
357357
358+ /** comm: Overridden task comm, see MSM_PARAM_COMM */
359+ char *comm;
360+
361+ /** cmdline: Overridden task cmdline, see MSM_PARAM_CMDLINE */
362+ char *cmdline;
363+
358364 /**
359365 * entities:
360366 *
drivers/gpu/drm/msm/msm_submitqueue.c+2−0
@@ -61,6 +61,8 @@ void __msm_file_private_destroy(struct kref *kref) · 60 unmodified lines
6161 }
6262
6363 msm_gem_address_space_put(ctx->aspace);
64+ kfree(ctx->comm);
65+ kfree(ctx->cmdline);
6466 kfree(ctx);
6567 }
6668
include/uapi/drm/msm_drm.h+2−0
@@ -82,6 +82,8 @@ struct drm_msm_timespec { · 81 unmodified lines
8282 #define MSM_PARAM_FAULTS 0x09 /* RO */
8383 #define MSM_PARAM_SUSPENDS 0x0a /* RO */
8484 #define MSM_PARAM_SYSPROF 0x0b /* WO: 1 preserves perfcntrs, 2 also disables suspend */
85+#define MSM_PARAM_COMM 0x0c /* WO: override for task->comm */
86+#define MSM_PARAM_CMDLINE 0x0d /* WO: override for task cmdline */
8587
8688 /* For backwards compat. The original support for preemption was based on
8789 * a single ring per priority level so # of priority levels equals the #