drm: Add panic handling
Subsystems (3)
cover drm: Add panic handling
This patchset adds a way for DRM drivers to display kernel messages during panic().
This version have lots of changes based on Daniel's review of the RFC where he proposed a different way of interacting with the driver.
I have used this script to run some tests on the rendering code:
https://gist.github.com/notro/4f42ec20e1be1d47c98fa749ca53c805
Noralf.
Noralf Trønnes (3):
drm: Add support for panic message output
drm/fb_cma_helper: Add panic handling
drm/simpledrm: Add panic handling
drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/drm_drv.c | 3 + drivers/gpu/drm/drm_fb_cma_helper.c | 10 + drivers/gpu/drm/drm_framebuffer.c | 108 +++++ drivers/gpu/drm/drm_internal.h | 4 + drivers/gpu/drm/drm_panic.c | 640 ++++++++++++++++++++++++++++++ drivers/gpu/drm/simpledrm/simpledrm_kms.c | 11 + include/drm/drm_framebuffer.h | 40 ++ 9 files changed, 818 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/drm_panic.c
--
2.8.2
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/3 drm: Add support for panic message output
This adds support for outputting kernel messages on panic(). A circular buffer is used to collect kernel messages. On panic() the notifier function loops over each DRM device and it's crtc's to find suitable framebuffers. On the next console->write(), the messages in the circular buffer are rendered on each of the recorded framebuffers.
Only atomic drivers are supported.
--- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/drm_drv.c | 3 + drivers/gpu/drm/drm_framebuffer.c | 108 +++++++ drivers/gpu/drm/drm_internal.h | 4 + drivers/gpu/drm/drm_panic.c | 640 ++++++++++++++++++++++++++++++++++++++ include/drm/drm_framebuffer.h | 40 +++ 7 files changed, 797 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/drm_panic.c
drivers/gpu/drm/Kconfig +1 -0
@@ -13,6 +13,7 @@ menuconfig DRM select I2C_ALGOBIT select DMA_SHARED_BUFFER select SYSFB + select FONT_SUPPORT help Kernel-level support for the Direct Rendering Infrastructure (DRI) introduced in XFree86 4.0. If you say Y here, you need to select
drivers/gpu/drm/Makefile +1 -1
@@ -13,7 +13,7 @@ drm-y := drm_auth.o drm_bufs.o drm_cache.o \ drm_trace_points.o drm_global.o drm_prime.o \ drm_rect.o drm_vma_manager.o drm_flip_work.o \ drm_modeset_lock.o drm_atomic.o drm_bridge.o \ - drm_framebuffer.o drm_connector.o drm_blend.o + drm_framebuffer.o drm_connector.o drm_blend.o drm_panic.o drm-$(CONFIG_COMPAT) += drm_ioc32.o drm-$(CONFIG_DRM_GEM_CMA_HELPER) += drm_gem_cma_helper.o
drivers/gpu/drm/drm_drv.c +3 -0
@@ -845,6 +845,8 @@ static int __init drm_core_init(void) goto err_p3; } +drm_panic_init (drm_debugfs_root); +DRM_INFO ("Initialized %s %d.%d.%d %s\n" ,CORE_NAME ,CORE_MAJOR ,CORE_MINOR ,CORE_PATCHLEVEL ,CORE_DATE );return 0 ;
@@ -860,6 +862,7 @@ err_p1: static void __exit drm_core_exit(void) { +drm_panic_exit (drm_debugfs_root);debugfs_remove (drm_debugfs_root);drm_sysfs_destroy ();
drivers/gpu/drm/drm_framebuffer.c +108 -0
117 lines not on this page · raw message
drivers/gpu/drm/drm_internal.h +4 -0
@@ -90,6 +90,10 @@ int drm_gem_open_ioctl(struct drm_device *dev, void *data,void drm_gem_open (struct drm_device *dev,struct drm_file *file_private);void drm_gem_release (struct drm_device *dev,struct drm_file *file_private); +/* drm_panic.c */ +void drm_panic_init (struct dentry *debugfs_root); +void drm_panic_exit (struct dentry *debugfs_root); +/* drm_debugfs.c */ #if defined(CONFIG_DEBUG_FS ) int drm_debugfs_init(struct drm_minor *minor, int minor_id,
drivers/gpu/drm/drm_panic.c new file +640 -0
640 lines not on this page · raw message
include/drm/drm_framebuffer.h +40 -0
@@ -90,6 +90,44 @@ struct drm_framebuffer_funcs { struct drm_file *file_priv, unsigned flags, unsigned color, struct drm_clip_rect *clips, unsigned num_clips); + +/** +* @panic_vmap: +* +* Optional callback for panic handling. +* +* For vmapping the selected framebuffer in a panic context. Must +* be super careful about locking (only trylocking allowed). +* +* RETURNS: +* +* NULL if it didn't work out, otherwise an opaque cookie which is +* passed to @panic_draw_xy. It can be anything: vmap area, structure +* with more details, just a few flags, ... +*/ +void *(*panic_vmap)(struct drm_framebuffer *fb); + +/** +* @panic_vunmap: +* +* Optional callback for cleaning up after panic testing. +* +* Crtc and plane locks are released after this callback has run. +* vmap is the cookie returned by @panic_vmap. +*/ +void (*panic_vunmap)(struct drm_framebuffer *fb,void *vmap); + +/** +* @panic_draw_xy: +* +* Optional callback for drawing pixels during panic. +* +* For drawing pixels onto a framebuffer prepared with @panic_vmap. +* vmap is the cookie returned by @panic_vmap. +* If it's not set, drm_framebuffer_panic_draw_xy() is used. +*/ +void (*panic_draw_xy)(struct drm_framebuffer *fb,void *vmap, +int x,int y,bool foreground); };/**
@@ -214,6 +252,8 @@ struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,void drm_framebuffer_remove (struct drm_framebuffer *fb);void drm_framebuffer_cleanup (struct drm_framebuffer *fb);void drm_framebuffer_unregister_private (struct drm_framebuffer *fb); +void drm_framebuffer_panic_draw_xy (struct drm_framebuffer *fb,void *vmap, +int x,int y,bool foreground);/** * drm_framebuffer_reference - incr the fb refcnt
Signature · 6 lines
2.8.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 1/3] drm: Add support for panic message output
Den 11.09.2016 20:47, skrev Noralf Trønnes:
Quoted 11 lines
This adds support for outputting kernel messages on
panic(). A circular buffer is used to collect kernel messages. Onpanic()the notifier function loops over each DRM device and it's crtc's to find suitable framebuffers. On the nextconsole->write(), the messages in the circular buffer are rendered on each of the recorded framebuffers.Only atomic drivers are supported.
Signed-off-by Noralf Trønnes <[email protected]>---
[...]
Quoted 1 line
drivers/gpu/drm/drm_panic.c +0
-0
[...]
drivers/gpu/drm/drm_panic.c line 300
Quoted 4 lines
drivers/gpu/drm/drm_panic.c +4
-0+static bool drm_panic_add_fb (struct drm_crtc *crtc,struct drm_plane *plane) +{ +unsigned int width =drm_rect_width (&plane->state->src) >>16 ; +unsigned int height =drm_rect_height (&plane->state->src) >>16 ;
I just tried this on vc4 (which uses fb_cma_helper) and width/height is zero. Additionally plane->state->visible is false.
Maybe something the driver should set?
If I work around that (use fb->width/height), then I get panic output on vc4 also in addition to simpledrm.
Noralf.
Quoted 390 lines
drivers/gpu/drm/drm_panic.c +340
-0+struct drm_framebuffer *fb = plane->fb; +const struct font_desc *font; +struct drm_panic_fb *pfb; +void *vmap; + +if (!width || !height || !fb || !fb->funcs || !fb->funcs->panic_vmap) +return false; + +/* only 8-bit wide fonts are supported */ + font =get_default_font (width, height,BIT (7 ),-1 ); +if (!font) { +drm_panic_log ("Couldn't get font\n" ); +return false; + } + + vmap = fb->funcs->panic_vmap (fb); +if (!vmap) { +drm_panic_log ("panic_vmap() returned NULL\n" ); +return false; + } + + pfb = &drm_panic_fbs[drm_panic_fbs_num++]; + pfb->plane = plane; + pfb->crtc = crtc; + pfb->fb = fb; + pfb->width = width; + pfb->height = height; + pfb->vmap = vmap; + pfb->font = font; + pfb->cols = pfb->width / font->width; + pfb->rows = pfb->height / font->height; + +drm_panic_log (" [FB:%d] %ux%u->%ux%u, %s, format=0x%08x\n" , + fb->base.id, pfb->width, pfb->height, pfb->cols, + pfb->rows, font->name, fb->pixel_format); + +return true; +} + +static void drm_panic_add (struct drm_device *drm) +{ +struct drm_plane *plane; +struct drm_crtc *crtc; + +if (!drm || !drm->driver || + !(drm->driver->driver_features &DRIVER_ATOMIC )) +return ; + +drm_panic_log ("%s on minor %d\n" , drm->driver->name, + drm->primary ? drm->primary->index :-1 ); + +drm_for_each_crtc (crtc, drm) { +drm_panic_log (" %s\n" , crtc->name); + +if (drm_panic_fbs_num >=DRM_PANIC_MAX_FBS ) +return ; + +if (!ww_mutex_trylock (&crtc->mutex.mutex)) +continue ; + +if (!crtc->enabled || !crtc->primary) + goto crtc_unlock; + +if (!crtc->state || !crtc->state->active) + goto crtc_unlock; + + plane = crtc->primary; +if (!ww_mutex_trylock (&plane->mutex.mutex)) + goto crtc_unlock; + +if (!plane->state || !plane->state->visible) + goto plane_unlock; + +if (drm_panic_add_fb (crtc, plane)) +continue ; + +plane_unlock: +ww_mutex_unlock (&plane->mutex.mutex); +crtc_unlock: +ww_mutex_unlock (&crtc->mutex.mutex); + } +} + +static int drm_panic_class_iter (struct device *dev,void *data) +{ +struct drm_minor *minor; + + minor =dev_get_drvdata (dev); + +if (minor && minor->type ==DRM_MINOR_PRIMARY ) +drm_panic_add (minor->dev); + +return 0 ; +} + +/* +* The panic() function makes sure that only one CPU is allowed to run it's +* code, but a new panic can be triggered during it's processing. +* +* Prior to calling the panic handlers, panic() calls smp_send_stop(). If +* that went well, there's only one CPU running, but this is no guarantee. +*/ +static int drm_panic_handler (struct notifier_block *this,unsigned long ev, +void *ptr) +{ +drm_panic_log ("%s\n" , __func__); + +/* +* TODO +* Maybe we need better protection here against reentrance in case +* panic_vmap() triggered a new panic. +*/ + +/* Nested panic */ +if (drm_panic_fbs_num) +return NOTIFY_DONE ; + +class_for_each_device (drm_class,NULL ,NULL , drm_panic_class_iter); + +if (drm_panic_fbs_num) + drm_panic_active = true; + +return NOTIFY_DONE ; +} + +static struct notifier_block drm_panic_block = { + .notifier_call = drm_panic_handler, +}; + +static void drm_panic_test (void ) +{ +/* simulate calling panic_notifier_list */ +drm_panic_handler (NULL ,0 ,NULL ); +} + +static void drm_panic_test_cleanup (void ) +{ +struct drm_panic_fb *pfb; +unsigned int i; + + drm_panic_active = false; + +for (i =0 ; i < drm_panic_fbs_num; i++) { + pfb = &drm_panic_fbs[i]; +if (pfb->fb->funcs->panic_vunmap) + pfb->fb->funcs->panic_vunmap (pfb->fb, pfb->vmap); +ww_mutex_unlock (&pfb->plane->mutex.mutex); +ww_mutex_unlock (&pfb->crtc->mutex.mutex); + } + + drm_panic_fbs_num =0 ; +memset (drm_panic_fbs,0 ,DRM_PANIC_MAX_FBS *sizeof (*drm_panic_fbs)); +} + +/* +* Partial replication of panic() for testing purposes. Some symbols are +* only available when builtin (they're not exported). +*/ +static void drm_panic_fake_panic (unsigned int level) +{ +#ifndef MODULE +int old_loglevel = console_loglevel; + +if (level >1 ) +local_irq_disable (); + +console_verbose (); + +if (level >2 ) +bust_spinlocks (1 ); + +pr_emerg ("Kernel panic - not syncing: FAKING=%u, oops_in_progress=%d\n" , + level, oops_in_progress); + +dump_stack (); +drm_panic_test (); + +if (level >2 ) +bust_spinlocks (0 ); + +console_flush_on_panic (); + +pr_emerg ("---[ end Kernel panic - not syncing: FAKING\n" ); + +if (level >1 ) +local_irq_enable (); + + console_loglevel = old_loglevel; + +#else /* MODULE */ + +if (level >1 ) +local_irq_disable (); + +pr_emerg ("Kernel panic - not syncing: FAKING=%u\n" , level); +dump_stack (); +drm_panic_test (); +pr_emerg ("---[ end Kernel panic - not syncing: FAKING\n" ); + +if (level >1 ) +local_irq_enable (); + +#endif /* MODULE */ + +drm_panic_test_cleanup (); +} + +static void drm_panic_clear_kmsgs (void ) +{ +console_lock (); +memset (drm_panic_kmsgs,0 ,DRM_PANIC_MAX_KMSGS ); + drm_panic_kmsgs_pos =0 ; +console_unlock (); +} + +/* +* Fake/simulate panic() at different levels: +* 1: only trigger panic handling internally +* 2: add local_irq_disable() +* 3: add bust_spinlocks(); +* +* Test rendering code: +* 100: clear kmsgs buffer +* 101: call panic handler for testing +* 102: cleanup after testing +* +* The real deal: +* 200: don't fake it, do call panic() +*/ +static ssize_t drm_panic_file_panic_write (struct file *file, +const char __user *user_buf, +size_t count,loff_t *ppos) +{ +unsigned long long val; +ssize_t ret =0 ; +char buf[24 ]; +size_t size; + + size =min (sizeof (buf) -1 , count); +if (copy_from_user (buf, user_buf, size)) +return -EFAULT ; + + buf[size] ='\0' ; + ret =kstrtoull (buf,0 , &val); +if (ret) +return ret; + +if (val && val <4 ) +drm_panic_fake_panic (val); +else if (val ==100 ) +drm_panic_clear_kmsgs (); +else if (val ==101 ) +drm_panic_test (); +else if (val ==102 ) +drm_panic_test_cleanup (); +else if (val ==200 ) +panic ("TESTING" ); +else +return -EINVAL ; + +return count; +} + +static const struct file_operations drm_panic_panic_ops = { + .write = drm_panic_file_panic_write, + .open = simple_open, + .llseek = default_llseek, +}; + +static int drm_panic_log_show (struct seq_file *m,void *v) +{ +size_t pos = log_pos; + +if (log_buf[0 ] =='\0' ) +return 0 ; + +if (!pos) { +seq_write (m, log_buf,DRM_PANIC_LOG_SIZE ); + }else if (log_buf[pos] =='\0' ) { +seq_write (m, log_buf, pos); + }else { +seq_write (m, log_buf + pos,DRM_PANIC_LOG_SIZE - pos); +seq_write (m, log_buf, pos); + } + +return 0 ; +} + +static int drm_panic_log_open (struct inode *inode,struct file *file) +{ +return single_open (file, drm_panic_log_show,NULL ); +} + +static const struct file_operations drm_panic_log_ops = { + .owner =THIS_MODULE , + .open = drm_panic_log_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static struct dentry *drm_panic_d_panic; +static struct dentry *drm_panic_d_log; + +void __init drm_panic_init (struct dentry *debugfs_root) +{ + drm_panic_kmsgs =kzalloc (DRM_PANIC_MAX_KMSGS ,GFP_KERNEL ); +if (!drm_panic_kmsgs) { +DRM_ERROR ("Failed to setup panic handler\n" ); +return ; + } + + drm_panic_d_panic =debugfs_create_file ("panic-test" ,0200 , + debugfs_root,NULL , + &drm_panic_panic_ops); + + drm_panic_d_log =debugfs_create_file ("panic-log" ,0444 , debugfs_root, +NULL , &drm_panic_log_ops); +if (!IS_ERR_OR_NULL (drm_panic_d_log)) + log_buf =kzalloc (DRM_PANIC_LOG_SIZE ,GFP_KERNEL ); + +register_console (&drm_panic_console); +atomic_notifier_chain_register (&panic_notifier_list, &drm_panic_block); +} + +void __exit drm_panic_exit(struct dentry *debugfs_root) +{ +if (!drm_panic_kmsgs) +return ; + +debugfs_remove (drm_panic_d_log); +debugfs_remove (drm_panic_d_panic); +kfree (log_buf); + log_buf =NULL ; + +atomic_notifier_chain_unregister (&panic_notifier_list, + &drm_panic_block); +unregister_console (&drm_panic_console); +kfree (drm_panic_kmsgs); +}include/drm/drm_framebuffer.h +38
-0@@ -90,6 +90,44 @@ struct drm_framebuffer_funcs { struct drm_file *file_priv, unsigned flags, unsigned color, struct drm_clip_rect *clips, unsigned num_clips); + +/** +* @panic_vmap: +* +* Optional callback for panic handling. +* +* For vmapping the selected framebuffer in a panic context. Must +* be super careful about locking (only trylocking allowed). +* +* RETURNS: +* +* NULL if it didn't work out, otherwise an opaque cookie which is +* passed to @panic_draw_xy. It can be anything: vmap area, structure +* with more details, just a few flags, ... +*/ +void *(*panic_vmap)(struct drm_framebuffer *fb); + +/** +* @panic_vunmap: +* +* Optional callback for cleaning up after panic testing. +* +* Crtc and plane locks are released after this callback has run. +* vmap is the cookie returned by @panic_vmap. +*/ +void (*panic_vunmap)(struct drm_framebuffer *fb,void *vmap); + +/** +* @panic_draw_xy: +* +* Optional callback for drawing pixels during panic. +* +* For drawing pixels onto a framebuffer prepared with @panic_vmap. +* vmap is the cookie returned by @panic_vmap. +* If it's not set, drm_framebuffer_panic_draw_xy() is used. +*/ +void (*panic_draw_xy)(struct drm_framebuffer *fb,void *vmap, +int x,int y,bool foreground); };/**
include/drm/drm_framebuffer.h struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev, · line 259
Quoted 8 lines
include/drm/drm_framebuffer.h +2
-0@@ -214,6 +252,8 @@ struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,void drm_framebuffer_remove (struct drm_framebuffer *fb);void drm_framebuffer_cleanup (struct drm_framebuffer *fb);void drm_framebuffer_unregister_private (struct drm_framebuffer *fb); +void drm_framebuffer_panic_draw_xy (struct drm_framebuffer *fb,void *vmap, +int x,int y,bool foreground);/** * drm_framebuffer_reference - incr the fb refcnt
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/3 drm/fb_cma_helper: Add panic handling
In reply to Noralf TrønnesThis enables panic message output for fb cma helper framebuffers.
--- drivers/gpu/drm/drm_fb_cma_helper.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/gpu/drm/drm_fb_cma_helper.c +10 -0
@@ -126,9 +126,19 @@ int drm_fb_cma_create_handle(struct drm_framebuffer *fb, }EXPORT_SYMBOL (drm_fb_cma_create_handle); +static void *drm_fb_cma_panic_vmap (struct drm_framebuffer *fb) +{ +struct drm_fb_cma *fb_cma =to_fb_cma (fb); +struct drm_gem_cma_object *cma_obj = fb_cma->obj[0 ]; + +/* A PRIME imported buffer will not have it's vaddr set. */ +return cma_obj ? cma_obj->vaddr :NULL ; +} +static struct drm_framebuffer_funcs drm_fb_cma_funcs = { .destroy = drm_fb_cma_destroy, .create_handle = drm_fb_cma_create_handle, + .panic_vmap = drm_fb_cma_panic_vmap, }; static struct drm_fb_cma *drm_fb_cma_alloc(struct drm_device *dev,
Signature · 6 lines
2.8.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/3] drm/fb_cma_helper: Add panic handling
Hi Noralf,
Thank you for the patch.
Quoted 12 lines · On Sunday 11 Sep 2016 20:47:41 Noralf Trønnes wrote:
This enables panic message output for fb cma helper framebuffers.
Signed-off-by Noralf Trønnes <[email protected]>--- drivers/gpu/drm/drm_fb_cma_helper.c | 10 ++++++++++ 1 file changed, 10 insertions(+)(quoted diff) +0
-0
b/drivers/gpu/drm/drm_fb_cma_helper.cindex 1fd6eac..2f1b012 100644
drivers/gpu/drm/drm_fb_cma_helper.c int drm_fb_cma_create_handle(struct drm_framebuffer · line 134
Quoted 9 lines
drivers/gpu/drm/drm_fb_cma_helper.c +6
-0@@ -126,9 +126,19 @@ int drm_fb_cma_create_handle(struct drm_framebuffer *fb, }EXPORT_SYMBOL (drm_fb_cma_create_handle); +static void *drm_fb_cma_panic_vmap (struct drm_framebuffer *fb) +{ +struct drm_fb_cma *fb_cma =to_fb_cma (fb); +struct drm_gem_cma_object *cma_obj = fb_cma->obj[0 ]; + +/* A PRIME imported buffer will not have it's vaddr set. */
Does this mean that, if the framebuffer that happens to be displayed when a panic occurs is imported, no message will be printed ? I understand how supporting such cases is difficult, but I'm wondering how we could proceed to ensure that a panic can be displayed in most (if not all) cases.
Similarly, it looks like your code only handles single-planar formats, but there's no explicit check for that in patch 1/3. The easiest fix is to reject multi-planar framebuffers, but that would again result in silent panics in some cases.
drivers/gpu/drm/drm_fb_cma_helper.c int drm_fb_cma_create_handle(struct drm_framebuffer *fb, · line 135
Quoted 1 line
drivers/gpu/drm/drm_fb_cma_helper.c +1
-0+return cma_obj ? cma_obj->vaddr :NULL ;
Can cma_obj be NULL here ? I thought that framebuffer objects were always created with at least one GEM object.
Quoted 9 lines
drivers/gpu/drm/drm_fb_cma_helper.c +3
-0+} +static struct drm_framebuffer_funcs drm_fb_cma_funcs = { .destroy = drm_fb_cma_destroy, .create_handle = drm_fb_cma_create_handle, + .panic_vmap = drm_fb_cma_panic_vmap, }; static struct drm_fb_cma *drm_fb_cma_alloc(struct drm_device *dev,
Signature · 8 lines
Regards, Laurent Pinchart _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/3] drm/fb_cma_helper: Add panic handling
Den 05.10.2016 15:22, skrev Laurent Pinchart:
Quoted 20 lines
Hi Noralf,
Thank you for the patch.
Quoted 15 lines · On Sunday 11 Sep 2016 20:47:41 Noralf Trønnes wrote:
This enables panic message output for fb cma helper framebuffers.
Signed-off-by Noralf Trønnes <[email protected]>--- drivers/gpu/drm/drm_fb_cma_helper.c | 10 ++++++++++ 1 file changed, 10 insertions(+)(quoted diff) +0
-0
b/drivers/gpu/drm/drm_fb_cma_helper.cindex 1fd6eac..2f1b012 100644drivers/gpu/drm/drm_fb_cma_helper.c +0
-0@@ -126,9 +126,19 @@ int drm_fb_cma_create_handle(struct drm_framebuffer *fb, }EXPORT_SYMBOL (drm_fb_cma_create_handle);
Quoted 10 lines
drivers/gpu/drm/drm_fb_cma_helper.c int drm_fb_cma_create_handle(struct drm_framebuffer *fb, · line 134
Quoted 6 lines
drivers/gpu/drm/drm_fb_cma_helper.c +6
-0+static void *drm_fb_cma_panic_vmap (struct drm_framebuffer *fb) +{ +struct drm_fb_cma *fb_cma =to_fb_cma (fb); +struct drm_gem_cma_object *cma_obj = fb_cma->obj[0 ]; + +/* A PRIME imported buffer will not have it's vaddr set. */ Does this mean that, if the framebuffer that happens to be displayed when a panic occurs is imported, no message will be printed ? I understand how supporting such cases is difficult, but I'm wondering how we could proceed to ensure that a panic can be displayed in most (if not all) cases.
If we can vmap all cma buffers, then it's simple:
- Add dma_buf_vmap() call to drm_gem_cma_prime_import_sg_table()
- Add dma_buf_vunmap() call to drm_gem_cma_free_object()
If not then it looks more complicated, since this is atomic context. There is dma_buf_kmap_atomic(), but there are no users. And drm_gem_prime_dmabuf_ops doesn't support .kmap_atomic either (returns NULL).
omapdrm is the only dma_buf provider I can find that actually uses kmap_atomic() instead of just returning NULL or relying on an existing virtual address. It has it's own .gem_prime_import/export functions to accomplish this.
Quoted 4 lines
Similarly, it looks like your code only handles single-planar formats, but there's no explicit check for that in patch 1/3. The easiest fix is to reject multi-planar framebuffers, but that would again result in silent panics in some cases.
That's correct if we talk about the default panic_draw_xy() function:drm_framebuffer_panic_draw_xy(). Most likely this function can be extended to support multi-planar formats, but Daniel said we could wait with that. And the driver can also implement it's own .panic_draw_xy() function.
Quoted 3 lines
drivers/gpu/drm/drm_fb_cma_helper.c int drm_fb_cma_create_handle(struct drm_framebuffer *fb, · line 135
Quoted 1 line
drivers/gpu/drm/drm_fb_cma_helper.c +1
-0+return cma_obj ? cma_obj->vaddr :NULL ;Can
cma_objbe NULL here ? I thought that framebuffer objects were always created with at least one GEM object.
I was trying to be very careful since a panic is about something gone very wrong. But in that case I should have checked that fb_cma isn't NULL also before dereferencing it.
Maybe I'm over the top paranoid :-)
Noralf.
Quoted 9 lines
drivers/gpu/drm/drm_fb_cma_helper.c int drm_fb_cma_create_handle(struct drm_framebuffer *fb, · line 144
Quoted 9 lines
drivers/gpu/drm/drm_fb_cma_helper.c +3
-0+} +static struct drm_framebuffer_funcs drm_fb_cma_funcs = { .destroy = drm_fb_cma_destroy, .create_handle = drm_fb_cma_create_handle, + .panic_vmap = drm_fb_cma_panic_vmap, }; static struct drm_fb_cma *drm_fb_cma_alloc(struct drm_device *dev,
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/3] drm/fb_cma_helper: Add panic handling
Quoted 42 lines · Noralf Trønnes
Den 05.10.2016 15:22, skrev Laurent Pinchart:
Quoted 20 lines
Hi Noralf,
Thank you for the patch.
Quoted 15 lines · On Sunday 11 Sep 2016 20:47:41 Noralf Trønnes wrote:
This enables panic message output for fb cma helper framebuffers.
Signed-off-by Noralf Trønnes <[email protected]>--- drivers/gpu/drm/drm_fb_cma_helper.c | 10 ++++++++++ 1 file changed, 10 insertions(+)(quoted diff) +0
-0
b/drivers/gpu/drm/drm_fb_cma_helper.cindex 1fd6eac..2f1b012 100644drivers/gpu/drm/drm_fb_cma_helper.c +0
-0@@ -126,9 +126,19 @@ int drm_fb_cma_create_handle(struct drm_framebuffer *fb, }EXPORT_SYMBOL (drm_fb_cma_create_handle);Quoted 10 lines
drivers/gpu/drm/drm_fb_cma_helper.c int drm_fb_cma_create_handle(struct drm_framebuffer *fb, · line 134
Quoted 6 lines
drivers/gpu/drm/drm_fb_cma_helper.c +6
-0+static void *drm_fb_cma_panic_vmap (struct drm_framebuffer *fb) +{ +struct drm_fb_cma *fb_cma =to_fb_cma (fb); +struct drm_gem_cma_object *cma_obj = fb_cma->obj[0 ]; + +/* A PRIME imported buffer will not have it's vaddr set. */ Does this mean that, if the framebuffer that happens to be displayed when a panic occurs is imported, no message will be printed ? I understand how supporting such cases is difficult, but I'm wondering how we could proceed to ensure that a panic can be displayed in most (if not all) cases.
If we can vmap all cma buffers, then it's simple:
- Adddma_buf_vmap()call todrm_gem_cma_prime_import_sg_table()
- Adddma_buf_vunmap()call todrm_gem_cma_free_object()If not then it looks more complicated, since this is atomic context. There is
dma_buf_kmap_atomic(), but there are no users. Anddrm_gem_prime_dmabuf_opsdoesn't support .kmap_atomic either (returns NULL).
Quoted 4 lines
omapdrm is the only
dma_bufprovider I can find that actually useskmap_atomic()instead of just returning NULL or relying on an existing virtual address. It has it's own .gem_prime_import/export functions to accomplish this.
dma_buf's kmap_atomic is a bit ill-defined, since atm it's not clear how to get the buffer pinned in the first place. Originally the plan was to use begin/end_cpu_access for this (which again can block, so not suitable for panic context). But that was kinda reused as the coherence control interface, and doesn't really pin anything. I guess we should probably just nuke the kmap interface part of dma_buf, the idea was to use that for ttm, but that never really happened.
Quoted 10 lines
Quoted 4 lines
Similarly, it looks like your code only handles single-planar formats, but there's no explicit check for that in patch 1/3. The easiest fix is to reject multi-planar framebuffers, but that would again result in silent panics in some cases.
That's correct if we talk about the default
panic_draw_xy()function:drm_framebuffer_panic_draw_xy(). Most likely this function can be extended to support multi-planar formats, but Daniel said we could wait with that. And the driver can also implement it's own .panic_draw_xy() function.
Quoted 8 lines
Quoted 3 lines
drivers/gpu/drm/drm_fb_cma_helper.c int drm_fb_cma_create_handle(struct drm_framebuffer *fb, · line 135
Quoted 1 line
drivers/gpu/drm/drm_fb_cma_helper.c +1
-0+return cma_obj ? cma_obj->vaddr :NULL ;Can
cma_objbe NULL here ? I thought that framebuffer objects were always created with at least one GEM object.I was trying to be very careful since a panic is about something gone very wrong. But in that case I should have checked that
fb_cmaisn't NULL also before dereferencing it.
Maybe I'm over the top paranoid :-)
Yeah I think this is a bit too much paranoia. I think you can remove these NULL checks here, it's truly impossible. Where we really need to be careful is with locking, both to make sure we exclusively use trylocks for everything, and that we do grab all the locks (to avoid disaster when the part that panicked is kms itself).
-Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 2/3] drm/fb_cma_helper: Add panic handling
Hi Daniel,
Quoted 48 lines · On Thursday 06 Oct 2016 11:12:40 Daniel Vetter wrote:
Quoted 42 lines · Noralf Trønnes
Den 05.10.2016 15:22, skrev Laurent Pinchart:
Quoted 19 lines · On Sunday 11 Sep 2016 20:47:41 Noralf Trønnes wrote:
Quoted 18 lines
This enables panic message output for fb cma helper framebuffers.
Signed-off-by Noralf Trønnes <[email protected]>---
drivers/gpu/drm/drm_fb_cma_helper.c | 10 ++++++++++ 1 file changed, 10 insertions(+)(quoted diff) +0
-0
b/drivers/gpu/drm/drm_fb_cma_helper.cindex 1fd6eac..2f1b012 100644drivers/gpu/drm/drm_fb_cma_helper.c +0
-0@@ -126,9 +126,19 @@ int drm_fb_cma_create_handle(struct
drm_framebuffer
*fb, }EXPORT_SYMBOL(drm_fb_cma_create_handle);Quoted 12 lines
drivers/gpu/drm/drm_fb_cma_helper.c int drm_fb_cma_create_handle(struct drm_framebuffer *fb, · line 134
Quoted 6 lines
drivers/gpu/drm/drm_fb_cma_helper.c +6
-0+static void *drm_fb_cma_panic_vmap (struct drm_framebuffer *fb) +{ +struct drm_fb_cma *fb_cma =to_fb_cma (fb); +struct drm_gem_cma_object *cma_obj = fb_cma->obj[0 ]; + +/* A PRIME imported buffer will not have it's vaddr set. */ Does this mean that, if the framebuffer that happens to be displayed when a panic occurs is imported, no message will be printed ? I understand how supporting such cases is difficult, but I'm wondering how we could proceed to ensure that a panic can be displayed in most (if not all) cases.
If we can vmap all cma buffers, then it's simple:
- Adddma_buf_vmap()call todrm_gem_cma_prime_import_sg_table()
- Adddma_buf_vunmap()call todrm_gem_cma_free_object()If not then it looks more complicated, since this is atomic context. There is
dma_buf_kmap_atomic(), but there are no users. Anddrm_gem_prime_dmabuf_opsdoesn't support .kmap_atomic either (returns NULL).Quoted 4 lines
omapdrm is the only
dma_bufprovider I can find that actually useskmap_atomic()instead of just returning NULL or relying on an existing virtual address. It has it's own .gem_prime_import/export functions to accomplish this.
Quoted 7 lines
dma_buf's
kmap_atomicis a bit ill-defined, since atm it's not clear how to get the buffer pinned in the first place. Originally the plan was to use begin/end_cpu_access for this (which again can block, so not suitable for panic context). But that was kinda reused as the coherence control interface, and doesn't really pin anything. I guess we should probably just nuke the kmap interface part ofdma_buf, the idea was to use that for ttm, but that never really happened.
I agree with you, and I'd go one step further: we need to define very precisely the semantics of the dmabuf operations. Drivers cache various information in different ways, making interoperability very fragile.
Quoted 25 lines
Quoted 15 lines
Quoted 4 lines
Similarly, it looks like your code only handles single-planar formats, but there's no explicit check for that in patch 1/3. The easiest fix is to reject multi-planar framebuffers, but that would again result in silent panics in some cases.
That's correct if we talk about the default
panic_draw_xy()function:drm_framebuffer_panic_draw_xy(). Most likely this function can be extended to support multi-planar formats, but Daniel said we could wait with that. And the driver can also implement it's own .panic_draw_xy() function.Quoted 4 lines
drivers/gpu/drm/drm_fb_cma_helper.c int drm_fb_cma_create_handle(struct drm_framebuffer *fb, · line 135
Quoted 1 line
drivers/gpu/drm/drm_fb_cma_helper.c +1
-0+return cma_obj ? cma_obj->vaddr :NULL ;Can
cma_objbe NULL here ? I thought that framebuffer objects were always created with at least one GEM object.Quoted 4 lines
I was trying to be very careful since a panic is about something gone very wrong. But in that case I should have checked that
fb_cmaisn't NULL also before dereferencing it.
Maybe I'm over the top paranoid :-)Yeah I think this is a bit too much paranoia. I think you can remove these NULL checks here, it's truly impossible. Where we really need to be careful is with locking, both to make sure we exclusively use trylocks for everything, and that we do grab all the locks (to avoid disaster when the part that panicked is kms itself).
Signature · 8 lines
Regards, Laurent Pinchart _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/3 drm/simpledrm: Add panic handling
In reply to Noralf TrønnesThis enables panic message output support in simpledrm.
--- drivers/gpu/drm/simpledrm/simpledrm_kms.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/gpu/drm/simpledrm/simpledrm_kms.c +11 -0
@@ -151,10 +151,21 @@ pr_info("%s\n", __func__);kfree (fb); } +static void *sdrm_panic_vmap (struct drm_framebuffer *fb) +{ +struct sdrm_device *sdrm = fb->dev->dev_private; + + fb->pixel_format = sdrm->hw->format; + fb->pitches[0 ] = sdrm->hw->stride; + +return sdrm->hw->map; +} +static const struct drm_framebuffer_funcs sdrm_fb_ops = { .create_handle = sdrm_fb_create_handle, .dirty = sdrm_fb_dirty, .destroy = sdrm_fb_destroy, + .panic_vmap = sdrm_panic_vmap, }; struct sdrm_fb *sdrm_fb_new(struct sdrm_bo *bo,
Signature · 6 lines
2.8.2 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Ping.
Den 11.09.2016 20:47, skrev Noralf Trønnes:
Quoted 28 lines
This patchset adds a way for DRM drivers to display kernel messages during
panic().This version have lots of changes based on Daniel's review of the RFC where he proposed a different way of interacting with the driver.
I have used this script to run some tests on the rendering code:
https://gist.github.com/notro/4f42ec20e1be1d47c98fa749ca53c805Noralf.
Noralf Trønnes (3):
drm: Add support for panic message output
drm/fb_cma_helper: Add panic handling
drm/simpledrm: Add panic handlingdrivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/drm_drv.c | 3 + drivers/gpu/drm/drm_fb_cma_helper.c | 10 + drivers/gpu/drm/drm_framebuffer.c | 108 +++++ drivers/gpu/drm/drm_internal.h | 4 + drivers/gpu/drm/drm_panic.c | 640 ++++++++++++++++++++++++++++++ drivers/gpu/drm/simpledrm/simpledrm_kms.c | 11 + include/drm/drm_framebuffer.h | 40 ++ 9 files changed, 818 insertions(+), 1 deletion(-)
Quoted 5 lines
create mode 100644
drivers/gpu/drm/drm_panic.c--
2.8.2
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Needs review from David Herrmann, pls keep him on cc for anything related to panic handling.
-Daniel
Quoted 44 lines · Noralf Trønnes
Ping.
Den 11.09.2016 20:47, skrev Noralf Trønnes:
Quoted 30 lines
This patchset adds a way for DRM drivers to display kernel messages during
panic().This version have lots of changes based on Daniel's review of the RFC where he proposed a different way of interacting with the driver.
I have used this script to run some tests on the rendering code:
https://gist.github.com/notro/4f42ec20e1be1d47c98fa749ca53c805Noralf.
Noralf Trønnes (3):
drm: Add support for panic message output
drm/fb_cma_helper: Add panic handling
drm/simpledrm: Add panic handlingdrivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/drm_drv.c | 3 + drivers/gpu/drm/drm_fb_cma_helper.c | 10 + drivers/gpu/drm/drm_framebuffer.c | 108 +++++ drivers/gpu/drm/drm_internal.h | 4 + drivers/gpu/drm/drm_panic.c | 640 ++++++++++++++++++++++++++++++ drivers/gpu/drm/simpledrm/simpledrm_kms.c | 11 + include/drm/drm_framebuffer.h | 40 ++ 9 files changed, 818 insertions(+), 1 deletion(-)Quoted 5 lines
create mode 100644
drivers/gpu/drm/drm_panic.c--
2.8.2_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel