drm/i915: export error state to string conversion
Subsystems (2)
PATCH 1/4 drm/i915: export error state to string conversion
In preparation for accessing error state from sysfs, export error state to string conversion function. Also tuck buffer error handling inside the function.
--- drivers/gpu/drm/i915/i915_debugfs.c | 24 ++++++++---------------- drivers/gpu/drm/i915/i915_drv.h | 7 +++++++ 2 files changed, 15 insertions(+), 16 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +8 -16
@@ -739,15 +739,8 @@ static void i915_ring_error_state(struct drm_i915_error_state_buf *m,err_printf (m," ring->tail: 0x%08x\n" , error->cpu_ring_tail[ring]); } -struct i915_error_state_file_priv { -struct drm_device *dev; -struct drm_i915_error_state *error; -}; - - -static int i915_error_state (struct i915_error_state_file_priv *error_priv, -struct drm_i915_error_state_buf *m) - +int i915_error_state_to_str (struct drm_i915_error_state_buf *m, +const struct i915_error_state_file_priv *error_priv) {struct drm_device *dev = error_priv->dev;drm_i915_private_t *dev_priv = dev->dev_private;
@@ -757,7 +750,7 @@ static int i915_error_state(struct i915_error_state_file_priv *error_priv,if (!error) {err_printf (m,"no error state collected\n" ); -return 0 ; + goto out; } err_printf(m, "Time: %ld s %ld us\n", error->time.tv_sec,
@@ -867,6 +860,10 @@ static int i915_error_state(struct i915_error_state_file_priv *error_priv,if (error->display)intel_display_print_error_state (m, dev, error->display); +out: +if (m->bytes ==0 && m->err) +return m->err; +return 0 ; }
@@ -960,15 +957,10 @@ static ssize_t i915_error_state_read(struct file *file, char __user *userbuf, error_str.start = *pos; - ret =i915_error_state (error_priv, &error_str); + ret =i915_error_state_to_str (&error_str, error_priv);if (ret) goto out; -if (error_str.bytes ==0 && error_str.err) { - ret = error_str.err; - goto out; - } - ret_count =simple_read_from_buffer (userbuf, count, &tmp_pos, error_str.buf, error_str.bytes);
drivers/gpu/drm/i915/i915_drv.h +7 -0
@@ -857,6 +857,11 @@ struct drm_i915_error_state_buf {loff_t pos; }; +struct i915_error_state_file_priv { +struct drm_device *dev; +struct drm_i915_error_state *error; +}; +struct i915_gpu_error {/* For hangcheck timer */ #define DRM_I915_HANGCHECK_PERIOD 1500/* in ms */
@@ -1850,6 +1855,8 @@ int i915_debugfs_init(struct drm_minor *minor);void i915_debugfs_cleanup (struct drm_minor *minor); __printf(2, 3)void i915_error_printf (struct drm_i915_error_state_buf *e,const char *f, ...); +int i915_error_state_to_str (struct drm_i915_error_state_buf *estr, +const struct i915_error_state_file_priv *error);/* i915_suspend.c */ extern int i915_save_state (struct drm_device *dev);
Signature · 1 line
1.7.9.5
PATCH 2/4 drm/i915: export error state ref handling
In preparation for sysfs error state access,
export ref error state ref counting interface.
--- drivers/gpu/drm/i915/i915_debugfs.c | 31 ++++++++++++++++++++++--------- drivers/gpu/drm/i915/i915_drv.h | 3 +++ 2 files changed, 25 insertions(+), 9 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +22 -9
@@ -889,12 +889,30 @@ i915_error_state_write(struct file *filp,return cnt; } +void i915_error_state_get (struct drm_device *dev, +struct i915_error_state_file_priv *error_priv) +{ +struct drm_i915_private *dev_priv = dev->dev_private; +unsigned long flags; + +spin_lock_irqsave (&dev_priv->gpu_error.lock, flags); + error_priv->error = dev_priv->gpu_error.first_error; +if (error_priv->error) +kref_get (&error_priv->error->ref); +spin_unlock_irqrestore (&dev_priv->gpu_error.lock, flags); + +} + +void i915_error_state_put (struct i915_error_state_file_priv *error_priv) +{ +if (error_priv->error) +kref_put (&error_priv->error->ref, i915_error_state_free); +} +static int i915_error_state_open (struct inode *inode,struct file *file) {struct drm_device *dev = inode->i_private; -drm_i915_private_t *dev_priv = dev->dev_private;struct i915_error_state_file_priv *error_priv; -unsigned long flags; error_priv =kzalloc (sizeof (*error_priv),GFP_KERNEL );if (!error_priv)
@@ -902,11 +920,7 @@ static int i915_error_state_open(struct inode *inode, struct file *file) error_priv->dev = dev; -spin_lock_irqsave (&dev_priv->gpu_error.lock, flags); - error_priv->error = dev_priv->gpu_error.first_error; -if (error_priv->error) -kref_get (&error_priv->error->ref); -spin_unlock_irqrestore (&dev_priv->gpu_error.lock, flags); +i915_error_state_get (dev, error_priv); file->private_data = error_priv;
@@ -917,8 +931,7 @@ static int i915_error_state_release(struct inode *inode, struct file *file) {struct i915_error_state_file_priv *error_priv = file->private_data; -if (error_priv->error) -kref_put (&error_priv->error->ref, i915_error_state_free); +i915_error_state_put (error_priv);kfree (error_priv);return 0 ;
drivers/gpu/drm/i915/i915_drv.h +3 -0
@@ -1857,6 +1857,9 @@ __printf(2, 3)void i915_error_printf (struct drm_i915_error_state_buf *e,const char *f, ...);int i915_error_state_to_str (struct drm_i915_error_state_buf *estr,const struct i915_error_state_file_priv *error); +void i915_error_state_get (struct drm_device *dev, +struct i915_error_state_file_priv *error_priv); +void i915_error_state_put (struct i915_error_state_file_priv *error_priv);/* i915_suspend.c */ extern int i915_save_state (struct drm_device *dev);
Signature · 1 line
1.7.9.5
PATCH 3/4 drm/i915: introduce i915_error_state_buf_init
In reply to Mika KuoppalaMake function for struct i915_error_state_buf initialization and export it, for sysfs and debugfs.
--- drivers/gpu/drm/i915/i915_debugfs.c | 50 +++++++++++++++++++++-------------- drivers/gpu/drm/i915/i915_drv.h | 7 +++++ 2 files changed, 37 insertions(+), 20 deletions(-)
drivers/gpu/drm/i915/i915_debugfs.c +30 -20
@@ -937,38 +937,48 @@ static int i915_error_state_release(struct inode *inode, struct file *file)return 0 ; } -static ssize_t i915_error_state_read (struct file *file,char __user *userbuf, -size_t count,loff_t *pos) +int i915_error_state_buf_init (struct drm_i915_error_state_buf *ebuf, +size_t count,loff_t pos) { -struct i915_error_state_file_priv *error_priv = file->private_data; -struct drm_i915_error_state_buf error_str; -loff_t tmp_pos =0 ; -ssize_t ret_count =0 ; -int ret =0 ; - -memset (&error_str,0 ,sizeof (error_str)); +memset (ebuf,0 ,sizeof (*ebuf));/* We need to have enough room to store any i915_error_state printf * so that we can move it to start position. */ - error_str.size = count +1 >PAGE_SIZE ? count +1 :PAGE_SIZE ; - error_str.buf =kmalloc (error_str.size, + ebuf->size = count +1 >PAGE_SIZE ? count +1 :PAGE_SIZE ; + ebuf->buf =kmalloc (ebuf->size,GFP_TEMPORARY | __GFP_NORETRY | __GFP_NOWARN); -if (error_str.buf ==NULL ) { - error_str.size =PAGE_SIZE ; - error_str.buf =kmalloc (error_str.size,GFP_TEMPORARY ); +if (ebuf->buf ==NULL ) { + ebuf->size =PAGE_SIZE ; + ebuf->buf =kmalloc (ebuf->size,GFP_TEMPORARY ); } -if (error_str.buf ==NULL ) { - error_str.size =128 ; - error_str.buf =kmalloc (error_str.size,GFP_TEMPORARY ); +if (ebuf->buf ==NULL ) { + ebuf->size =128 ; + ebuf->buf =kmalloc (ebuf->size,GFP_TEMPORARY ); } -if (error_str.buf ==NULL ) +if (ebuf->buf ==NULL )return -ENOMEM ; - error_str.start = *pos; + ebuf->start = pos; + +return 0 ; +} + +static ssize_t i915_error_state_read (struct file *file,char __user *userbuf, +size_t count,loff_t *pos) +{ +struct i915_error_state_file_priv *error_priv = file->private_data; +struct drm_i915_error_state_buf error_str; +loff_t tmp_pos =0 ; +ssize_t ret_count =0 ; +int ret; + + ret =i915_error_state_buf_init (&error_str, count, *pos); +if (ret) +return ret; ret =i915_error_state_to_str (&error_str, error_priv);if (ret)
@@ -983,7 +993,7 @@ static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,else *pos = error_str.start + ret_count; out: -kfree (error_str.buf); +i915_error_state_buf_release (&error_str);return ret ?: ret_count; }
drivers/gpu/drm/i915/i915_drv.h +7 -0
@@ -1860,6 +1860,13 @@ int i915_error_state_to_str(struct drm_i915_error_state_buf *estr,void i915_error_state_get (struct drm_device *dev,struct i915_error_state_file_priv *error_priv);void i915_error_state_put (struct i915_error_state_file_priv *error_priv); +int i915_error_state_buf_init (struct drm_i915_error_state_buf *eb, +size_t count,loff_t pos); +static inline void i915_error_state_buf_release ( +struct drm_i915_error_state_buf *eb) +{ +kfree (eb->buf); +}/* i915_suspend.c */ extern int i915_save_state (struct drm_device *dev);
Signature · 1 line
1.7.9.5
PATCH 4/4 drm/i915: add i915_error_state sysfs entry
In reply to Mika KuoppalaAs getting error state doesn't anymore require big kmallocs, make error state accessible also from sysfs.
--- drivers/gpu/drm/i915/i915_sysfs.c | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
drivers/gpu/drm/i915/i915_sysfs.c +49 -0
@@ -409,6 +409,49 @@ static const struct attribute *gen6_attrs[] = { NULL, }; +static ssize_t error_state_read (struct file *filp,struct kobject *kobj, +struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ + + struct device *kdev = container_of(kobj, struct device, kobj); + struct drm_minor *minor = container_of(kdev, struct drm_minor, kdev); +struct drm_device *dev = minor->dev; +struct i915_error_state_file_priv error_priv; +struct drm_i915_error_state_buf error_str; +ssize_t ret_count =0 ; +int ret; + +memset (&error_priv,0 ,sizeof (error_priv)); + + ret =i915_error_state_buf_init (&error_str, count, off); +if (ret) +return ret; + + error_priv.dev = dev; +i915_error_state_get (dev, &error_priv); + + ret =i915_error_state_to_str (&error_str, &error_priv); +if (ret) + goto out; + + ret_count = count < error_str.bytes ? count : error_str.bytes; + +memcpy (buf, error_str.buf, ret_count); +out: +i915_error_state_buf_release (&error_str); +i915_error_state_put (&error_priv); + +return ret ?: ret_count; +} + +static struct bin_attribute error_state_attr = { + .attr.name ="i915_error_state" , + .attr.mode =0444 , + .size =0 , + .read = error_state_read, +}; +void i915_setup_sysfs (struct drm_device *dev) {int ret;
@@ -432,10 +475,16 @@ void i915_setup_sysfs(struct drm_device *dev)if (ret)DRM_ERROR ("gen6 sysfs setup failed\n" ); } + + ret =sysfs_create_bin_file (&dev->primary->kdev.kobj, + &error_state_attr); +if (ret) +DRM_ERROR ("error_state sysfs setup failed\n" ); }void i915_teardown_sysfs (struct drm_device *dev) { +sysfs_remove_bin_file (&dev->primary->kdev.kobj, &error_state_attr);sysfs_remove_files (&dev->primary->kdev.kobj, gen6_attrs);device_remove_bin_file (&dev->primary->kdev, &dpf_attrs);#ifdef CONFIG_PM
Signature · 1 line
1.7.9.5
Re: [PATCH 4/4] drm/i915: add i915_error_state sysfs entry
Quoted 5 lines · Mika Kuoppala
As getting error state doesn't anymore require big kmallocs, make error state accessible also from sysfs.
Suggested-by Daniel Vetter <[email protected]>Signed-off-by Mika Kuoppala <[email protected]>
Don't forget the ability to clear an error-state in order to capture a fresh one.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Re: [PATCH 4/4] drm/i915: add i915_error_state sysfs entry
In reply to Mika KuoppalaQuoted 46 lines · Mika Kuoppala
As getting error state doesn't anymore require big kmallocs, make error state accessible also from sysfs.
Suggested-by Daniel Vetter <[email protected]>Signed-off-by Mika Kuoppala <[email protected]>--- drivers/gpu/drm/i915/i915_sysfs.c | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)drivers/gpu/drm/i915/i915_sysfs.c +29
-0@@ -409,6 +409,49 @@ static const struct attribute *gen6_attrs[] = { NULL, }; +static ssize_t error_state_read (struct file *filp,struct kobject *kobj, +struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ + + struct device *kdev = container_of(kobj, struct device, kobj); + struct drm_minor *minor = container_of(kdev, struct drm_minor, kdev); +struct drm_device *dev = minor->dev; +struct i915_error_state_file_priv error_priv; +struct drm_i915_error_state_buf error_str; +ssize_t ret_count =0 ; +int ret; + +memset (&error_priv,0 ,sizeof (error_priv)); + + ret =i915_error_state_buf_init (&error_str, count, off); +if (ret) +return ret; + + error_priv.dev = dev; +i915_error_state_get (dev, &error_priv); + + ret =i915_error_state_to_str (&error_str, &error_priv); +if (ret) + goto out; + + ret_count = count < error_str.bytes ? count : error_str.bytes; + +memcpy (buf, error_str.buf, ret_count);
drivers/gpu/drm/i915/i915_sysfs.c static const struct attribute *gen6_attrs[] = { · line 450
Quoted 10 lines
drivers/gpu/drm/i915/i915_sysfs.c +10
-0+out: +i915_error_state_buf_release (&error_str); +i915_error_state_put (&error_priv); + +return ret ?: ret_count; +} + +static struct bin_attribute error_state_attr = { + .attr.name ="i915_error_state" , + .attr.mode =0444 ,
Error state could easily leak sensitive information, so I think we should only allow root to read it. Also maybe a new name for it, i915_ is kinda meh ... I vote for gpu_error_state.
-Daniel
Quoted 31 lines
drivers/gpu/drm/i915/i915_sysfs.c +10
-0+ .size = 0, + .read = error_state_read, +}; +void i915_setup_sysfs (struct drm_device *dev) {int ret;@@ -432,10 +475,16 @@ void i915_setup_sysfs(struct drm_device *dev)if (ret)DRM_ERROR ("gen6 sysfs setup failed\n" ); } + + ret =sysfs_create_bin_file (&dev->primary->kdev.kobj, + &error_state_attr); +if (ret) +DRM_ERROR ("error_state sysfs setup failed\n" ); }void i915_teardown_sysfs (struct drm_device *dev) { +sysfs_remove_bin_file (&dev->primary->kdev.kobj, &error_state_attr);sysfs_remove_files (&dev->primary->kdev.kobj, gen6_attrs);device_remove_bin_file (&dev->primary->kdev, &dpf_attrs);#ifdef CONFIG_PM Signature · 6 lines
1.7.9.5 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
PATCH 4/4 drm/i915: add error_state sysfs entry
In reply to Mika KuoppalaAs getting error state doesn't anymore require big kmallocs, make error state accessible also from sysfs.
v2: - error state clearing (Chris Wilson)
- user hint, proper access mode bits and name (Daniel Vetter)
--- drivers/gpu/drm/i915/i915_irq.c | 3 +- drivers/gpu/drm/i915/i915_sysfs.c | 71 +++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_irq.c +1 -2
@@ -1881,8 +1881,7 @@ static void i915_capture_error_state(struct drm_device *dev) }DRM_INFO ("capturing error event; look for more information in " -"/sys/kernel/debug/dri/%d/i915_error_state\n" , - dev->primary->index); +"/sys/class/drm/card%d/error_state\n" , dev->primary->index);kref_init (&error->ref); error->eir =I915_READ (EIR );
drivers/gpu/drm/i915/i915_sysfs.c +71 -0
87 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH 4/4] drm/i915: add error_state sysfs entry
Quoted 31 lines · Mika Kuoppala
As getting error state doesn't anymore require big kmallocs, make error state accessible also from sysfs.
v2: - error state clearing (Chris Wilson)
- user hint, proper access mode bits and name (Daniel Vetter)Suggested-by Daniel Vetter <[email protected]>Signed-off-by Mika Kuoppala <[email protected]>---
drivers/gpu/drm/i915/i915_sysfs.c +22
-0+static ssize_t error_state_read (struct file *filp,struct kobject *kobj, +struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ + + struct device *kdev = container_of(kobj, struct device, kobj); + struct drm_minor *minor = container_of(kdev, struct drm_minor, kdev); +struct drm_device *dev = minor->dev; +struct i915_error_state_file_priv error_priv; +struct drm_i915_error_state_buf error_str; +ssize_t ret_count =0 ; +int ret; + +memset (&error_priv,0 ,sizeof (error_priv)); + + ret =i915_error_state_buf_init (&error_str, count, off); +if (ret) +return ret; + + error_priv.dev = dev; +i915_error_state_get (dev, &error_priv); +
drivers/gpu/drm/i915/i915_sysfs.c static const struct attribute *gen6_attrs[] = { · line 443
Quoted 10 lines
drivers/gpu/drm/i915/i915_sysfs.c +10
-0+ ret =i915_error_state_to_str (&error_str, &error_priv); +if (ret) + goto out; + + ret_count = count < error_str.bytes ? count : error_str.bytes; + +memcpy (buf, error_str.buf, ret_count); +out: +i915_error_state_buf_release (&error_str); +i915_error_state_put (&error_priv);
Not quite oniony enough.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
PATCH 4/4 drm/i915: add error_state sysfs entry
As getting error state doesn't anymore require big kmallocs, make error state accessible also from sysfs.
v2: - error state clearing (Chris Wilson)
- user hint, proper access mode bits and name (Daniel Vetter)
v3: release resources in proper order (Chris Wilson)
--- drivers/gpu/drm/i915/i915_irq.c | 3 +- drivers/gpu/drm/i915/i915_sysfs.c | 71 +++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_irq.c +1 -2
@@ -1881,8 +1881,7 @@ static void i915_capture_error_state(struct drm_device *dev) }DRM_INFO ("capturing error event; look for more information in " -"/sys/kernel/debug/dri/%d/i915_error_state\n" , - dev->primary->index); +"/sys/class/drm/card%d/error_state\n" , dev->primary->index);kref_init (&error->ref); error->eir =I915_READ (EIR );
drivers/gpu/drm/i915/i915_sysfs.c +71 -0
87 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH 4/4] drm/i915: add error_state sysfs entry
Quoted 10 lines · Mika Kuoppala
As getting error state doesn't anymore require big kmallocs, make error state accessible also from sysfs.
v2: - error state clearing (Chris Wilson)
- user hint, proper access mode bits and name (Daniel Vetter)v3: release resources in proper order (Chris Wilson)
Suggested-by Daniel Vetter <[email protected]>Signed-off-by Mika Kuoppala <[email protected]>
I am happy overall here. We could take the plunge and use this as an excuse to move all the error-state string handling into a new file, which would be useful for when we pull the hangcheck mechanism out of i915_irq.c.
Perhaps the more pressing bikeshed is that after years of i915_error_state, I'm tired of the name and think that the 'state' was just redundant, so perhaps '/sys/class/drm/card0/error' is a nice minimalist and modern looking name.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Re: [PATCH 4/4] drm/i915: add error_state sysfs entry
Quoted 17 lines · Chris Wilson
Quoted 10 lines · Mika Kuoppala
As getting error state doesn't anymore require big kmallocs, make error state accessible also from sysfs.
v2: - error state clearing (Chris Wilson)
- user hint, proper access mode bits and name (Daniel Vetter)v3: release resources in proper order (Chris Wilson)
Suggested-by Daniel Vetter <[email protected]>Signed-off-by Mika Kuoppala <[email protected]>I am happy overall here. We could take the plunge and use this as an excuse to move all the error-state string handling into a new file, which would be useful for when we pull the hangcheck mechanism out of
i915_irq.c.
Quoted 4 lines
Perhaps the more pressing bikeshed is that after years of
i915_error_state, I'm tired of the name and think that the 'state' was just redundant, so perhaps '/sys/class/drm/card0/error' is a nice minimalist and modern looking name.
Series merged with this bikeshed applied and your r-b from irc added.
Thanks, Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch