Commit 76f9764c authored by Chris Wilson's avatar Chris Wilson
Browse files

drm/i915: Introduce a vma.kref



Start introducing a kref on i915_vma in order to protect the vma unbind
(i915_gem_object_unbind) from a parallel destruction (i915_vma_parked).
Later, we will use the refcount to manage all access and turn i915_vma
into a first class container.

Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Imre Deak <imre.deak@intel.com>
Acked-by: default avatarImre Deak <imre.deak@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191222210256.2066451-2-chris@chris-wilson.co.uk
parent f5af1659
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -194,7 +194,7 @@ static void __i915_gem_free_objects(struct drm_i915_private *i915,
				GEM_BUG_ON(vma->obj != obj);
				spin_unlock(&obj->vma.lock);

				i915_vma_destroy(vma);
				__i915_vma_put(vma);

				spin_lock(&obj->vma.lock);
			}
+1 −2
Original line number Diff line number Diff line
@@ -1110,8 +1110,7 @@ static int __igt_write_huge(struct intel_context *ce,
out_vma_unpin:
	i915_vma_unpin(vma);
out_vma_close:
	i915_vma_destroy(vma);

	__i915_vma_put(vma);
	return err;
}

+2 −2
Original line number Diff line number Diff line
@@ -163,7 +163,7 @@ static int check_partial_mapping(struct drm_i915_gem_object *obj,
	kunmap(p);

out:
	i915_vma_destroy(vma);
	__i915_vma_put(vma);
	return err;
}

@@ -257,7 +257,7 @@ static int check_partial_mappings(struct drm_i915_gem_object *obj,
		if (err)
			return err;

		i915_vma_destroy(vma);
		__i915_vma_put(vma);

		if (igt_timeout(end_time,
				"%s: timed out after tiling=%d stride=%d\n",
+9 −18
Original line number Diff line number Diff line
@@ -136,7 +136,6 @@ try_again:
						       struct i915_vma,
						       obj_link))) {
		struct i915_address_space *vm = vma->vm;
		bool awake = false;

		list_move_tail(&vma->obj_link, &still_in_list);
		if (!i915_vma_is_bound(vma, I915_VMA_BIND_MASK))
@@ -147,26 +146,18 @@ try_again:
			break;

		/* Prevent vma being freed by i915_vma_parked as we unbind */
		if (intel_gt_pm_get_if_awake(vm->gt)) {
			awake = true;
		} else {
			if (i915_vma_is_closed(vma)) {
				spin_unlock(&obj->vma.lock);
				i915_vma_parked(vm->gt);
				goto err_vm;
			}
		}

		vma = __i915_vma_get(vma);
		spin_unlock(&obj->vma.lock);

		if (vma) {
			ret = -EBUSY;
			if (flags & I915_GEM_OBJECT_UNBIND_ACTIVE ||
			    !i915_vma_is_active(vma))
				ret = i915_vma_unbind(vma);

		if (awake)
			intel_gt_pm_put(vm->gt);
err_vm:
			__i915_vma_put(vma);
		}

		i915_vm_close(vm);
		spin_lock(&obj->vma.lock);
	}
+3 −2
Original line number Diff line number Diff line
@@ -534,7 +534,7 @@ void __i915_vm_close(struct i915_address_space *vm)

		atomic_and(~I915_VMA_PIN_MASK, &vma->flags);
		WARN_ON(__i915_vma_unbind(vma));
		i915_vma_destroy(vma);
		__i915_vma_put(vma);

		i915_gem_object_put(obj);
	}
@@ -1812,7 +1812,7 @@ static void gen6_ppgtt_cleanup(struct i915_address_space *vm)
{
	struct gen6_ppgtt *ppgtt = to_gen6_ppgtt(i915_vm_to_ppgtt(vm));

	i915_vma_destroy(ppgtt->vma);
	__i915_vma_put(ppgtt->vma);

	gen6_ppgtt_free_pd(ppgtt);
	free_scratch(vm);
@@ -1895,6 +1895,7 @@ static struct i915_vma *pd_vma_create(struct gen6_ppgtt *ppgtt, int size)

	i915_active_init(&vma->active, NULL, NULL);

	kref_init(&vma->ref);
	mutex_init(&vma->pages_mutex);
	vma->vm = i915_vm_get(&ggtt->vm);
	vma->ops = &pd_vma_ops;
Loading