drm/i915/gt: Onion unwind for scratch page allocation failure
authorChris Wilson <chris@chris-wilson.co.uk>
Mon, 19 Oct 2020 08:34:44 +0000 (09:34 +0100)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Wed, 21 Oct 2020 12:32:25 +0000 (08:32 -0400)
In switching to using objects for our ppGTT scratch pages, care was not
taken to avoid trying to unref NULL objects on failure. And for gen6
ppGTT, it appears we forgot entirely to unwind after a partial allocation
failure.

Fixes: 89351925a477 ("drm/i915/gt: Switch to object allocations for page directories")
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20201019083444.1286-1-chris@chris-wilson.co.uk
(cherry picked from commit fa812ce96a46efc27cae4dcad866aaee9cb25d28)
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/i915/gt/gen6_ppgtt.c
drivers/gpu/drm/i915/gt/gen8_ppgtt.c

index fd0d24d..c30adc0 100644 (file)
@@ -239,18 +239,24 @@ static int gen6_ppgtt_init_scratch(struct gen6_ppgtt *ppgtt)
                               I915_CACHE_NONE, PTE_READ_ONLY);
 
        vm->scratch[1] = vm->alloc_pt_dma(vm, I915_GTT_PAGE_SIZE_4K);
-       if (IS_ERR(vm->scratch[1]))
-               return PTR_ERR(vm->scratch[1]);
+       if (IS_ERR(vm->scratch[1])) {
+               ret = PTR_ERR(vm->scratch[1]);
+               goto err_scratch0;
+       }
 
        ret = pin_pt_dma(vm, vm->scratch[1]);
-       if (ret) {
-               i915_gem_object_put(vm->scratch[1]);
-               return ret;
-       }
+       if (ret)
+               goto err_scratch1;
 
        fill32_px(vm->scratch[1], vm->scratch[0]->encode);
 
        return 0;
+
+err_scratch1:
+       i915_gem_object_put(vm->scratch[1]);
+err_scratch0:
+       i915_gem_object_put(vm->scratch[0]);
+       return ret;
 }
 
 static void gen6_ppgtt_free_pd(struct gen6_ppgtt *ppgtt)
index eb64f47..38c7069 100644 (file)
@@ -604,7 +604,8 @@ static int gen8_init_scratch(struct i915_address_space *vm)
        return 0;
 
 free_scratch:
-       free_scratch(vm);
+       while (i--)
+               i915_gem_object_put(vm->scratch[i]);
        return -ENOMEM;
 }