drm/i915/fbdev: lock the fbdev obj before vma pin
authorjsg <jsg@openbsd.org>
Fri, 31 Mar 2023 01:39:50 +0000 (01:39 +0000)
committerjsg <jsg@openbsd.org>
Fri, 31 Mar 2023 01:39:50 +0000 (01:39 +0000)
From Tejas Upadhyay
9595d71b2a274fe365240b53ce5d03c071c3e6e0 in linux-6.1.y/6.1.22
ed00eba03474adbf525ff03d69705d8c78b76456 in mainline linux

sys/dev/pci/drm/i915/display/intel_fbdev.c

index de32600..e994153 100644 (file)
@@ -212,6 +212,7 @@ static int intelfb_create(struct drm_fb_helper *helper,
        bool prealloc = false;
        void __iomem *vaddr;
        struct drm_i915_gem_object *obj;
+       struct i915_gem_ww_ctx ww;
        int ret;
 
        mutex_lock(&ifbdev->hpd_lock);
@@ -293,13 +294,24 @@ static int intelfb_create(struct drm_fb_helper *helper,
                info->fix.smem_len = vma->size;
        }
 
-       vaddr = i915_vma_pin_iomap(vma);
-       if (IS_ERR(vaddr)) {
-               drm_err(&dev_priv->drm,
-                       "Failed to remap framebuffer into virtual memory (%pe)\n", vaddr);
-               ret = PTR_ERR(vaddr);
-               goto out_unpin;
+       for_i915_gem_ww(&ww, ret, false) {
+               ret = i915_gem_object_lock(vma->obj, &ww);
+
+               if (ret)
+                       continue;
+
+               vaddr = i915_vma_pin_iomap(vma);
+               if (IS_ERR(vaddr)) {
+                       drm_err(&dev_priv->drm,
+                               "Failed to remap framebuffer into virtual memory (%pe)\n", vaddr);
+                       ret = PTR_ERR(vaddr);
+                       continue;
+               }
        }
+
+       if (ret)
+               goto out_unpin;
+
        info->screen_base = vaddr;
        info->screen_size = vma->size;