Skip to contentSkip to conversation

drm/exynos: fix kernel panic issue at drm releasing

PATCH Superseded Inki Dae 3 participants 7 messages Dec 24, 2015 – Jan 5, 2016

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Inki Dae

author maintainer
#0 lore raw

PATCH 1/1 drm/exynos: fix kernel panic issue at drm releasing

This patch fixes a kernel panic issue which happened when drm driver is closed while modetest.

This issue could be reproduced easily by launching modetest with page flip repeatedly.

The reason is that invalid drm_file object could be accessed by send_vblank_event function when finishing page flip if the drm_file object was removed by drm_release and there was a pended page flip event which was already committed to hardware.

So this patch makes the pended page flip event to be cancelled by preclose callback which is called at front of drm_release function.

---
 drivers/gpu/drm/exynos/exynos_drm_crtc.c | 10 ++++++++++
 drivers/gpu/drm/exynos/exynos_drm_crtc.h |  3 +++
 drivers/gpu/drm/exynos/exynos_drm_drv.c  |  5 +++++
 3 files changed, 18 insertions(+)
drivers/gpu/drm/exynos/exynos_drm_crtc.c +10 -0
index 81cfff5..57619b8 100644
@@ -235,3 +235,13 @@ void exynos_drm_crtc_te_handler(struct drm_crtc *crtc)
 	if (exynos_crtc->ops->te_handler)
 		exynos_crtc->ops->te_handler(exynos_crtc);
 }
+
+void exynos_drm_crtc_cancel_page_flip(struct drm_crtc *crtc)
+{
+	struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
+	unsigned long flags;
+
+	spin_lock_irqsave(&crtc->dev->event_lock, flags);
+	exynos_crtc->event = NULL;
+	spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
+}
drivers/gpu/drm/exynos/exynos_drm_crtc.h +3 -0
index 6a581a8..b4def6e 100644
@@ -40,4 +40,7 @@ int exynos_drm_crtc_get_pipe_from_type(struct drm_device *drm_dev,
  */
 void exynos_drm_crtc_te_handler(struct drm_crtc *crtc);
 
+/* This function cancels a page flip request. */
+void exynos_drm_crtc_cancel_page_flip(struct drm_crtc *crtc);
+
 #endif
drivers/gpu/drm/exynos/exynos_drm_drv.c +5 -0
index 9756797a..57c0e7d 100644
@@ -330,7 +330,12 @@ err_file_priv_free:
 static void exynos_drm_preclose(struct drm_device *dev,
 					struct drm_file *file)
 {
+	struct drm_crtc *crtc;
+
 	exynos_drm_subdrv_close(dev, file);
+
+	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
+		exynos_drm_crtc_cancel_page_flip(crtc);
 }
 
 static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw

Hi Inki,

drivers/gpu/drm/exynos/exynos_drm_crtc.c void exynos_drm_crtc_te_handler(struct drm_crtc *crtc) · line 247

Quoted 9 lines · Inki Dae
drivers/gpu/drm/exynos/exynos_drm_crtc.c +9 -0
+void exynos_drm_crtc_cancel_page_flip(struct drm_crtc *crtc)
+{
+       struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
+       unsigned long flags;
+
+       spin_lock_irqsave(&crtc->dev->event_lock, flags);
+       exynos_crtc->event = NULL;
+       spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
+}

This will leak the event and event space; you should call event->base.destroy() here. With that fixed:

Cheers,
Daniel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

author maintainer
#2 lore raw

Hi Daniel,

2015년 12월 24일 22:32에 Daniel Stone 이(가) 쓴 글:

Quoted 15 lines

Hi Inki,

drivers/gpu/drm/exynos/exynos_drm_crtc.c void exynos_drm_crtc_te_handler(struct drm_crtc *crtc) · line 247

Quoted 9 lines · Inki Dae
drivers/gpu/drm/exynos/exynos_drm_crtc.c +9 -0
+void exynos_drm_crtc_cancel_page_flip(struct drm_crtc *crtc)
+{
+       struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
+       unsigned long flags;
+
+       spin_lock_irqsave(&crtc->dev->event_lock, flags);
+       exynos_crtc->event = NULL;
+       spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
+}

This will leak the event and event space; you should call event->base.destroy() here. With that fixed:

Right. we don't use exynos specific page flip function anymore which managed the event as a list so that the event objects can be freed by postclose callback. Anyway, would it be better for event->base.destory() to be called between spin lock/unlock?

Thanks,
Inki Dae

Quoted 10 lines

Cheers,
Daniel
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

Hi Inki,

Quoted 15 lines · Inki Dae

2015년 12월 24일 22:32에 Daniel Stone 이(가) 쓴 글:

Quoted 5 lines · Inki Dae
Quoted 4 lines
drivers/gpu/drm/exynos/exynos_drm_crtc.c +4 -0
+void exynos_drm_crtc_cancel_page_flip(struct drm_crtc *crtc)
+{
+       struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
+       unsigned long flags;
Quoted 8 lines

drivers/gpu/drm/exynos/exynos_drm_crtc.c void exynos_drm_crtc_te_handler(struct drm_crtc *crtc) · line 247

Quoted 5 lines
drivers/gpu/drm/exynos/exynos_drm_crtc.c +5 -0
+
+       spin_lock_irqsave(&crtc->dev->event_lock, flags);
+       exynos_crtc->event = NULL;
+       spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
+}

This will leak the event and event space; you should call event->base.destroy() here. With that fixed:

Quoted 2 lines

Right. we don't use exynos specific page flip function anymore which managed the event as a list so that the event objects can be freed by postclose callback. Anyway, would it be better for event->base.destory() to be called between spin lock/unlock?

You must increment event->base.file_priv->event_space (see drm_atomic.c:destroy_vblank_event), as well as calling event->base.destroy (see drm_fops.c:drm_read) underneath event_lock, yes.

Cheers,
Daniel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

author maintainer
#4 lore raw

Hi Daniel,

2016년 01월 05일 05:24에 Daniel Stone 이(가) 쓴 글:

Quoted 18 lines

Hi Inki,

Quoted 15 lines · Inki Dae

2015년 12월 24일 22:32에 Daniel Stone 이(가) 쓴 글:

Quoted 13 lines · Inki Dae

drivers/gpu/drm/exynos/exynos_drm_crtc.c void exynos_drm_crtc_te_handler(struct drm_crtc *crtc) · line 247

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_crtc.c +9 -0
+void exynos_drm_crtc_cancel_page_flip(struct drm_crtc *crtc)
+{
+       struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
+       unsigned long flags;
+
+       spin_lock_irqsave(&crtc->dev->event_lock, flags);
+       exynos_crtc->event = NULL;
+       spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
+}

This will leak the event and event space; you should call event->base.destroy() here. With that fixed:

Quoted 5 lines
Quoted 2 lines

Right. we don't use exynos specific page flip function anymore which managed the event as a list so that the event objects can be freed by postclose callback. Anyway, would it be better for event->base.destory() to be called between spin lock/unlock?

You must increment event->base.file_priv->event_space (see drm_atomic.c:destroy_vblank_event), as well as calling

Reasonable to me. Seems other DRM drivers don't increment event_space.

Quoted 2 lines

event->base.destroy (see drm_fops.c:drm_read) underneath event_lock, yes.

In addition, only event objects belonging to the request process should be destroyed.

Thanks,
Inki Dae

Quoted 9 lines

Cheers,
Daniel
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw
Quoted 27 lines · Inki Dae

Hi Daniel,

2016년 01월 05일 05:24에 Daniel Stone 이(가) 쓴 글:

Quoted 18 lines

Hi Inki,

Quoted 15 lines · Inki Dae

2015년 12월 24일 22:32에 Daniel Stone 이(가) 쓴 글:

Quoted 13 lines · Inki Dae

drivers/gpu/drm/exynos/exynos_drm_crtc.c void exynos_drm_crtc_te_handler(struct drm_crtc *crtc) · line 247

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_crtc.c +9 -0
+void exynos_drm_crtc_cancel_page_flip(struct drm_crtc *crtc)
+{
+       struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
+       unsigned long flags;
+
+       spin_lock_irqsave(&crtc->dev->event_lock, flags);
+       exynos_crtc->event = NULL;
+       spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
+}

This will leak the event and event space; you should call event->base.destroy() here. With that fixed:

Quoted 5 lines
Quoted 2 lines

Right. we don't use exynos specific page flip function anymore which managed the event as a list so that the event objects can be freed by postclose callback. Anyway, would it be better for event->base.destory() to be called between spin lock/unlock?

You must increment event->base.file_priv->event_space (see drm_atomic.c:destroy_vblank_event), as well as calling

Quoted 6 lines

Reasonable to me. Seems other DRM drivers don't increment event_space.

Quoted 2 lines

event->base.destroy (see drm_fops.c:drm_read) underneath event_lock, yes.

In addition, only event objects belonging to the request process should be destroyed.

Just random comment out of the far left field, but robclark had a bunch of patches to clean up all that event alloc/cleanup code a bit and extract it into core functions. Might be good to ping him on irc to figure out where that series is and whether you could take it over.

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
author maintainer
#6 lore raw

+ Rob Clark,

Hi Daniel and Rob,

2016년 01월 05일 20:08에 Daniel Vetter 이(가) 쓴 글:

Quoted 33 lines · Inki Dae
Quoted 32 lines

Hi Daniel,

2016년 01월 05일 05:24에 Daniel Stone 이(가) 쓴 글:

Quoted 18 lines

Hi Inki,

Quoted 15 lines · Inki Dae

2015년 12월 24일 22:32에 Daniel Stone 이(가) 쓴 글:

Quoted 13 lines · Inki Dae

drivers/gpu/drm/exynos/exynos_drm_crtc.c void exynos_drm_crtc_te_handler(struct drm_crtc *crtc) · line 247

Quoted 9 lines
drivers/gpu/drm/exynos/exynos_drm_crtc.c +9 -0
+void exynos_drm_crtc_cancel_page_flip(struct drm_crtc *crtc)
+{
+       struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc);
+       unsigned long flags;
+
+       spin_lock_irqsave(&crtc->dev->event_lock, flags);
+       exynos_crtc->event = NULL;
+       spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
+}

This will leak the event and event space; you should call event->base.destroy() here. With that fixed:

Quoted 5 lines
Quoted 2 lines

Right. we don't use exynos specific page flip function anymore which managed the event as a list so that the event objects can be freed by postclose callback. Anyway, would it be better for event->base.destory() to be called between spin lock/unlock?

You must increment event->base.file_priv->event_space (see drm_atomic.c:destroy_vblank_event), as well as calling

Reasonable to me. Seems other DRM drivers don't increment event_space.

Quoted 2 lines

event->base.destroy (see drm_fops.c:drm_read) underneath event_lock, yes.

Quoted 6 lines
Quoted 1 line

In addition, only event objects belonging to the request process should be destroyed.

Just random comment out of the far left field, but robclark had a bunch of patches to clean up all that event alloc/cleanup code a bit and extract it into core functions. Might be good to ping him on irc to figure out where that series is and whether you could take it over.

Good news. I'll try to ping him on irc.

To Rob,
Can you let me know where your bunch of patches are? I'd like to look into the patches. I'd planned to have pull request so that this patch can go to 4.4. As you had already relevant patch set maybe, we would need to check whether my patch can be replaced with your patch set or there is any corner case.

Thanks,
Inki Dae

Quoted 3 lines

Cheers, Daniel