drm/armada: use a private mutex to protect priv->linear
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Tue, 24 Nov 2015 09:00:36 +0000 (10:00 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Sat, 5 Dec 2015 21:44:07 +0000 (21:44 +0000)
Reusing the Big DRM Lock just leaks, and the few things left that
dev->struct_mutex protected are very well contained - it's just the
linear drm_mm manager.

With this armada is completely struct_mutex free!

v2: Convert things properly and also take the lock in
armada_gem_free_object, and remove the stale comment (Russell).

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
drivers/gpu/drm/armada/armada_debugfs.c
drivers/gpu/drm/armada/armada_drm.h
drivers/gpu/drm/armada/armada_drv.c
drivers/gpu/drm/armada/armada_gem.c

index 471e45627f1e9d05c8d4ced672b60fcc9ac28a38..d4f7ab0a30d479ecb1a7db5cbbbfc4a96933bf1f 100644 (file)
@@ -21,9 +21,9 @@ static int armada_debugfs_gem_linear_show(struct seq_file *m, void *data)
        struct armada_private *priv = dev->dev_private;
        int ret;
 
-       mutex_lock(&dev->struct_mutex);
+       mutex_lock(&priv->linear_lock);
        ret = drm_mm_dump_table(m, &priv->linear);
-       mutex_unlock(&dev->struct_mutex);
+       mutex_unlock(&priv->linear_lock);
 
        return ret;
 }
index 4df6f2af2b21056854e961f703c6f524aeab0c4b..3b2bb6128d403f9db917eb68d583b05fe0121f0e 100644 (file)
@@ -57,7 +57,8 @@ struct armada_private {
        DECLARE_KFIFO(fb_unref, struct drm_framebuffer *, 8);
        struct drm_fb_helper    *fbdev;
        struct armada_crtc      *dcrtc[2];
-       struct drm_mm           linear;
+       struct drm_mm           linear; /* protected by linear_lock */
+       struct mutex            linear_lock;
        struct drm_property     *csc_yuv_prop;
        struct drm_property     *csc_rgb_prop;
        struct drm_property     *colorkey_prop;
index 3f1396e673dde448c86099c948ab065a27ec28cb..f7f47cb71db4ae5dccb8e5cd559ab230b705245a 100644 (file)
@@ -101,6 +101,7 @@ static int armada_drm_load(struct drm_device *dev, unsigned long flags)
        dev->mode_config.preferred_depth = 24;
        dev->mode_config.funcs = &armada_drm_mode_config_funcs;
        drm_mm_init(&priv->linear, mem->start, resource_size(mem));
+       mutex_init(&priv->linear_lock);
 
        ret = component_bind_all(dev->dev, dev);
        if (ret)
index e3a86b96af2a6760c1dcf8e0a89f061859499f92..6e731db31aa49c9c65e9f6eebd3b789ca4daa78b 100644 (file)
@@ -46,22 +46,26 @@ static size_t roundup_gem_size(size_t size)
        return roundup(size, PAGE_SIZE);
 }
 
-/* dev->struct_mutex is held here */
 void armada_gem_free_object(struct drm_gem_object *obj)
 {
        struct armada_gem_object *dobj = drm_to_armada_gem(obj);
+       struct armada_private *priv = obj->dev->dev_private;
 
        DRM_DEBUG_DRIVER("release obj %p\n", dobj);
 
        drm_gem_free_mmap_offset(&dobj->obj);
 
+       might_lock(&priv->linear_lock);
+
        if (dobj->page) {
                /* page backed memory */
                unsigned int order = get_order(dobj->obj.size);
                __free_pages(dobj->page, order);
        } else if (dobj->linear) {
                /* linear backed memory */
+               mutex_lock(&priv->linear_lock);
                drm_mm_remove_node(dobj->linear);
+               mutex_unlock(&priv->linear_lock);
                kfree(dobj->linear);
                if (dobj->addr)
                        iounmap(dobj->addr);
@@ -144,10 +148,10 @@ armada_gem_linear_back(struct drm_device *dev, struct armada_gem_object *obj)
                if (!node)
                        return -ENOSPC;
 
-               mutex_lock(&dev->struct_mutex);
+               mutex_lock(&priv->linear_lock);
                ret = drm_mm_insert_node(&priv->linear, node, size, align,
                                         DRM_MM_SEARCH_DEFAULT);
-               mutex_unlock(&dev->struct_mutex);
+               mutex_unlock(&priv->linear_lock);
                if (ret) {
                        kfree(node);
                        return ret;
@@ -158,9 +162,9 @@ armada_gem_linear_back(struct drm_device *dev, struct armada_gem_object *obj)
                /* Ensure that the memory we're returning is cleared. */
                ptr = ioremap_wc(obj->linear->start, size);
                if (!ptr) {
-                       mutex_lock(&dev->struct_mutex);
+                       mutex_lock(&priv->linear_lock);
                        drm_mm_remove_node(obj->linear);
-                       mutex_unlock(&dev->struct_mutex);
+                       mutex_unlock(&priv->linear_lock);
                        kfree(obj->linear);
                        obj->linear = NULL;
                        return -ENOMEM;