]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/gpu/drm/drm_info.c
drm: fix send_vblank_event use-after-free error
[mirror_ubuntu-bionic-kernel.git] / drivers / gpu / drm / drm_info.c
CommitLineData
955b12de
BG
1/**
2 * \file drm_info.c
3 * DRM info file implementations
4 *
5 * \author Ben Gamari <bgamari@gmail.com>
6 */
7
8/*
9 * Created: Sun Dec 21 13:09:50 2008 by bgamari@gmail.com
10 *
11 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
12 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
13 * Copyright 2008 Ben Gamari <bgamari@gmail.com>
14 * All Rights Reserved.
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of this software and associated documentation files (the "Software"),
18 * to deal in the Software without restriction, including without limitation
19 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
20 * and/or sell copies of the Software, and to permit persons to whom the
21 * Software is furnished to do so, subject to the following conditions:
22 *
23 * The above copyright notice and this permission notice (including the next
24 * paragraph) shall be included in all copies or substantial portions of the
25 * Software.
26 *
27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
31 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
32 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33 * OTHER DEALINGS IN THE SOFTWARE.
34 */
35
36#include <linux/seq_file.h>
760285e7 37#include <drm/drmP.h>
d9fc9413
DV
38#include <drm/drm_gem.h>
39
43fc884e 40#include "drm_internal.h"
ba8286fa 41#include "drm_legacy.h"
955b12de
BG
42
43/**
44 * Called when "/proc/dri/.../name" is read.
45 *
46 * Prints the device name together with the bus id if available.
47 */
48int drm_name_info(struct seq_file *m, void *data)
49{
50 struct drm_info_node *node = (struct drm_info_node *) m->private;
51 struct drm_minor *minor = node->minor;
52 struct drm_device *dev = minor->dev;
53 struct drm_master *master = minor->master;
955b12de
BG
54 if (!master)
55 return 0;
56
8410ea3b
DA
57 if (master->unique) {
58 seq_printf(m, "%s %s %s\n",
9de1b51f 59 dev->driver->name,
8410ea3b 60 dev_name(dev->dev), master->unique);
955b12de 61 } else {
8410ea3b 62 seq_printf(m, "%s %s\n",
9de1b51f 63 dev->driver->name, dev_name(dev->dev));
955b12de 64 }
955b12de
BG
65 return 0;
66}
67
955b12de
BG
68/**
69 * Called when "/proc/dri/.../clients" is read.
70 *
71 */
72int drm_clients_info(struct seq_file *m, void *data)
73{
74 struct drm_info_node *node = (struct drm_info_node *) m->private;
75 struct drm_device *dev = node->minor->dev;
76 struct drm_file *priv;
77
50d47cb3
CW
78 seq_printf(m,
79 "%20s %5s %3s master a %5s %10s\n",
80 "command",
81 "pid",
82 "dev",
83 "uid",
84 "magic");
85
86 /* dev->filelist is sorted youngest first, but we want to present
87 * oldest first (i.e. kernel, servers, clients), so walk backwardss.
88 */
1d2ac403 89 mutex_lock(&dev->filelist_mutex);
50d47cb3
CW
90 list_for_each_entry_reverse(priv, &dev->filelist, lhead) {
91 struct task_struct *task;
92
93 rcu_read_lock(); /* locks pid_task()->comm */
94 task = pid_task(priv->pid, PIDTYPE_PID);
95 seq_printf(m, "%20s %5d %3d %c %c %5d %10u\n",
96 task ? task->comm : "<unknown>",
5fce5e0b 97 pid_vnr(priv->pid),
50d47cb3
CW
98 priv->minor->index,
99 priv->is_master ? 'y' : 'n',
100 priv->authenticated ? 'y' : 'n',
5fce5e0b 101 from_kuid_munged(seq_user_ns(m), priv->uid),
5952fba5 102 priv->magic);
50d47cb3 103 rcu_read_unlock();
955b12de 104 }
1d2ac403 105 mutex_unlock(&dev->filelist_mutex);
955b12de
BG
106 return 0;
107}
108
b375de0b 109static int drm_gem_one_name_info(int id, void *ptr, void *data)
955b12de
BG
110{
111 struct drm_gem_object *obj = ptr;
112 struct seq_file *m = data;
113
955b12de
BG
114 seq_printf(m, "%6d %8zd %7d %8d\n",
115 obj->name, obj->size,
a8e11d1c 116 obj->handle_count,
955b12de
BG
117 atomic_read(&obj->refcount.refcount));
118 return 0;
119}
120
121int drm_gem_name_info(struct seq_file *m, void *data)
122{
123 struct drm_info_node *node = (struct drm_info_node *) m->private;
124 struct drm_device *dev = node->minor->dev;
125
126 seq_printf(m, " name size handles refcount\n");
90254ac0 127
cd4f013f 128 mutex_lock(&dev->object_name_lock);
955b12de 129 idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m);
cd4f013f 130 mutex_unlock(&dev->object_name_lock);
90254ac0 131
955b12de
BG
132 return 0;
133}