Commit 4f256d82 authored by Daniel Vetter's avatar Daniel Vetter

drm/i915: Fix fbdev unload sequence

First thing we need to do is unregister the fbdev instance, but we
can't just go ahead and kfree it. That must wait until the hotplug and
polling work are stopped, since they can race with the with the
teardown. That means we need to split up the fbdev teardown into the
unregister part and the cleanup part.

I originally suspected that this was broken in one of the unload
shuffles, but on closer inspection the oldest sequence I've dug out
also gets this wrong. Just not quite so badly.

I've run drv_module_reload a few hundred times and it's rock solid
compared to insta-death beforehand. This bug seems to have been
uncovered by

commit 88be58be
Author: Daniel Vetter <daniel.vetter@ffwll.ch>
Date:   Thu Jul 6 15:00:19 2017 +0200

    drm/i915/fbdev: Always forward hotplug events

But the effect of that seems to only be to increase the race window
enough to make it blow up easier. I'm not exactly clear on what's
going on there ...

v2: Fix whitespace and use fetch_and_zero (Chris).

Testcase: igt/drv_module_reload
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=101791
Cc: martin.peres@free.fr
Cc: chris@chris-wilson.co.uk
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20170714224656.6431-2-daniel.vetter@ffwll.ch
parent 49d70aea
...@@ -1241,6 +1241,7 @@ static void i915_driver_register(struct drm_i915_private *dev_priv) ...@@ -1241,6 +1241,7 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)
*/ */
static void i915_driver_unregister(struct drm_i915_private *dev_priv) static void i915_driver_unregister(struct drm_i915_private *dev_priv)
{ {
intel_fbdev_unregister(dev_priv);
intel_audio_deinit(dev_priv); intel_audio_deinit(dev_priv);
intel_gpu_ips_teardown(); intel_gpu_ips_teardown();
...@@ -1374,8 +1375,6 @@ void i915_driver_unload(struct drm_device *dev) ...@@ -1374,8 +1375,6 @@ void i915_driver_unload(struct drm_device *dev)
struct drm_i915_private *dev_priv = to_i915(dev); struct drm_i915_private *dev_priv = to_i915(dev);
struct pci_dev *pdev = dev_priv->drm.pdev; struct pci_dev *pdev = dev_priv->drm.pdev;
intel_fbdev_fini(dev);
if (i915_gem_suspend(dev_priv)) if (i915_gem_suspend(dev_priv))
DRM_ERROR("failed to idle hardware; continuing to unload!\n"); DRM_ERROR("failed to idle hardware; continuing to unload!\n");
......
...@@ -15796,6 +15796,9 @@ void intel_modeset_cleanup(struct drm_device *dev) ...@@ -15796,6 +15796,9 @@ void intel_modeset_cleanup(struct drm_device *dev)
*/ */
drm_kms_helper_poll_fini(dev); drm_kms_helper_poll_fini(dev);
/* poll work can call into fbdev, hence clean that up afterwards */
intel_fbdev_fini(dev_priv);
intel_unregister_dsm_handler(); intel_unregister_dsm_handler();
intel_fbc_global_disable(dev_priv); intel_fbc_global_disable(dev_priv);
......
...@@ -1597,7 +1597,8 @@ void intel_hpd_poll_init(struct drm_i915_private *dev_priv); ...@@ -1597,7 +1597,8 @@ void intel_hpd_poll_init(struct drm_i915_private *dev_priv);
#ifdef CONFIG_DRM_FBDEV_EMULATION #ifdef CONFIG_DRM_FBDEV_EMULATION
extern int intel_fbdev_init(struct drm_device *dev); extern int intel_fbdev_init(struct drm_device *dev);
extern void intel_fbdev_initial_config_async(struct drm_device *dev); extern void intel_fbdev_initial_config_async(struct drm_device *dev);
extern void intel_fbdev_fini(struct drm_device *dev); extern void intel_fbdev_unregister(struct drm_i915_private *dev_priv);
extern void intel_fbdev_fini(struct drm_i915_private *dev_priv);
extern void intel_fbdev_set_suspend(struct drm_device *dev, int state, bool synchronous); extern void intel_fbdev_set_suspend(struct drm_device *dev, int state, bool synchronous);
extern void intel_fbdev_output_poll_changed(struct drm_device *dev); extern void intel_fbdev_output_poll_changed(struct drm_device *dev);
extern void intel_fbdev_restore_mode(struct drm_device *dev); extern void intel_fbdev_restore_mode(struct drm_device *dev);
...@@ -1611,7 +1612,11 @@ static inline void intel_fbdev_initial_config_async(struct drm_device *dev) ...@@ -1611,7 +1612,11 @@ static inline void intel_fbdev_initial_config_async(struct drm_device *dev)
{ {
} }
static inline void intel_fbdev_fini(struct drm_device *dev) static inline void intel_fbdev_unregister(struct drm_i915_private *dev_priv)
{
}
static inline void intel_fbdev_fini(struct drm_i915_private *dev_priv)
{ {
} }
......
...@@ -531,8 +531,6 @@ static void intel_fbdev_destroy(struct intel_fbdev *ifbdev) ...@@ -531,8 +531,6 @@ static void intel_fbdev_destroy(struct intel_fbdev *ifbdev)
* trying to rectify all the possible error paths leading here. * trying to rectify all the possible error paths leading here.
*/ */
drm_fb_helper_unregister_fbi(&ifbdev->helper);
drm_fb_helper_fini(&ifbdev->helper); drm_fb_helper_fini(&ifbdev->helper);
if (ifbdev->vma) { if (ifbdev->vma) {
...@@ -720,8 +718,10 @@ static void intel_fbdev_initial_config(void *data, async_cookie_t cookie) ...@@ -720,8 +718,10 @@ static void intel_fbdev_initial_config(void *data, async_cookie_t cookie)
/* Due to peculiar init order wrt to hpd handling this is separate. */ /* Due to peculiar init order wrt to hpd handling this is separate. */
if (drm_fb_helper_initial_config(&ifbdev->helper, if (drm_fb_helper_initial_config(&ifbdev->helper,
ifbdev->preferred_bpp)) ifbdev->preferred_bpp)) {
intel_fbdev_fini(ifbdev->helper.dev); intel_fbdev_unregister(to_i915(ifbdev->helper.dev));
intel_fbdev_fini(to_i915(ifbdev->helper.dev));
}
} }
void intel_fbdev_initial_config_async(struct drm_device *dev) void intel_fbdev_initial_config_async(struct drm_device *dev)
...@@ -744,9 +744,8 @@ static void intel_fbdev_sync(struct intel_fbdev *ifbdev) ...@@ -744,9 +744,8 @@ static void intel_fbdev_sync(struct intel_fbdev *ifbdev)
ifbdev->cookie = 0; ifbdev->cookie = 0;
} }
void intel_fbdev_fini(struct drm_device *dev) void intel_fbdev_unregister(struct drm_i915_private *dev_priv)
{ {
struct drm_i915_private *dev_priv = to_i915(dev);
struct intel_fbdev *ifbdev = dev_priv->fbdev; struct intel_fbdev *ifbdev = dev_priv->fbdev;
if (!ifbdev) if (!ifbdev)
...@@ -756,8 +755,17 @@ void intel_fbdev_fini(struct drm_device *dev) ...@@ -756,8 +755,17 @@ void intel_fbdev_fini(struct drm_device *dev)
if (!current_is_async()) if (!current_is_async())
intel_fbdev_sync(ifbdev); intel_fbdev_sync(ifbdev);
drm_fb_helper_unregister_fbi(&ifbdev->helper);
}
void intel_fbdev_fini(struct drm_i915_private *dev_priv)
{
struct intel_fbdev *ifbdev = fetch_and_zero(&dev_priv->fbdev);
if (!ifbdev)
return;
intel_fbdev_destroy(ifbdev); intel_fbdev_destroy(ifbdev);
dev_priv->fbdev = NULL;
} }
void intel_fbdev_set_suspend(struct drm_device *dev, int state, bool synchronous) void intel_fbdev_set_suspend(struct drm_device *dev, int state, bool synchronous)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment