drm/i915: Sanitize GEM shrinker init and clean-up
authorImre Deak <imre.deak@intel.com>
Tue, 19 Jan 2016 13:26:28 +0000 (15:26 +0200)
committerImre Deak <imre.deak@intel.com>
Wed, 27 Jan 2016 15:43:14 +0000 (17:43 +0200)
Factor out the common GEM shrinker clean-up code and call the shrinker
init function from the same function from where the corresponding
shrinker clean-up function is called. Also add sanity checking to the
shrinker and OOM registration calls.

Signed-off-by: Imre Deak <imre.deak@intel.com>
Reviewed-by: David Weinehall <david.weinehall@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1453209992-25995-4-git-send-email-imre.deak@intel.com
drivers/gpu/drm/i915/i915_dma.c
drivers/gpu/drm/i915/i915_drv.h
drivers/gpu/drm/i915/i915_gem.c
drivers/gpu/drm/i915/i915_gem_shrinker.c

index 5caea9e97fcf28ba4e93196148f43e988e4267d0..adc5fe728bc52e249910a445fc89e525a8b0be32 100644 (file)
@@ -1035,6 +1035,7 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
        intel_opregion_setup(dev);
 
        i915_gem_load(dev);
+       i915_gem_shrinker_init(dev_priv);
 
        /* On the 945G/GM, the chipset reports the MSI capability on the
         * integrated graphics even though the support isn't actually there
@@ -1098,8 +1099,7 @@ out_power_well:
        intel_power_domains_fini(dev_priv);
        drm_vblank_cleanup(dev);
 out_gem_unload:
-       WARN_ON(unregister_oom_notifier(&dev_priv->mm.oom_notifier));
-       unregister_shrinker(&dev_priv->mm.shrinker);
+       i915_gem_shrinker_cleanup(dev_priv);
 
        if (dev->pdev->msi_enabled)
                pci_disable_msi(dev->pdev);
@@ -1152,8 +1152,7 @@ int i915_driver_unload(struct drm_device *dev)
 
        i915_teardown_sysfs(dev);
 
-       WARN_ON(unregister_oom_notifier(&dev_priv->mm.oom_notifier));
-       unregister_shrinker(&dev_priv->mm.shrinker);
+       i915_gem_shrinker_cleanup(dev_priv);
 
        io_mapping_free(dev_priv->gtt.mappable);
        arch_phys_wc_del(dev_priv->gtt.mtrr);
index 211af534e5d0a36a941f1ecf310caa731d4b4416..abfb8c9e5a8c71910915006e59dbad9f5ec2ac9d 100644 (file)
@@ -3261,6 +3261,7 @@ unsigned long i915_gem_shrink(struct drm_i915_private *dev_priv,
 #define I915_SHRINK_ACTIVE 0x8
 unsigned long i915_gem_shrink_all(struct drm_i915_private *dev_priv);
 void i915_gem_shrinker_init(struct drm_i915_private *dev_priv);
+void i915_gem_shrinker_cleanup(struct drm_i915_private *dev_priv);
 
 
 /* i915_gem_tiling.c */
index 371bbb28c4713c52dc3a1ebed72ea344559697ae..7ce76c24a5c6cfc0378e71e9ae4636f4d9af6066 100644 (file)
@@ -5100,8 +5100,6 @@ i915_gem_load(struct drm_device *dev)
 
        dev_priv->mm.interruptible = true;
 
-       i915_gem_shrinker_init(dev_priv);
-
        mutex_init(&dev_priv->fb_tracking.lock);
 }
 
index 16da9c1422ccfa14a71714ac37f3a97609cbc4ac..58c1e592bbdb6718a3abfadc99d785be4b28e5ef 100644 (file)
@@ -367,8 +367,20 @@ void i915_gem_shrinker_init(struct drm_i915_private *dev_priv)
        dev_priv->mm.shrinker.scan_objects = i915_gem_shrinker_scan;
        dev_priv->mm.shrinker.count_objects = i915_gem_shrinker_count;
        dev_priv->mm.shrinker.seeks = DEFAULT_SEEKS;
-       register_shrinker(&dev_priv->mm.shrinker);
+       WARN_ON(register_shrinker(&dev_priv->mm.shrinker));
 
        dev_priv->mm.oom_notifier.notifier_call = i915_gem_shrinker_oom;
-       register_oom_notifier(&dev_priv->mm.oom_notifier);
+       WARN_ON(register_oom_notifier(&dev_priv->mm.oom_notifier));
+}
+
+/**
+ * i915_gem_shrinker_cleanup - Clean up i915 shrinker
+ * @dev_priv: i915 device
+ *
+ * This function unregisters the i915 shrinker and OOM handler.
+ */
+void i915_gem_shrinker_cleanup(struct drm_i915_private *dev_priv)
+{
+       WARN_ON(unregister_oom_notifier(&dev_priv->mm.oom_notifier));
+       unregister_shrinker(&dev_priv->mm.shrinker);
 }